Skip to content

cli: select the remote connection record and provider once, before authentication #4858

Open

Description

@thymikee

Follow-up from the second review of #4846 (#4846 (comment), second finding). Not fixed in #4846.

Purpose

A command that materializes a remote connection can check one provider at admission and then use a different connection record at materialization, because the effective state directory changes between the two steps.

Repro from the review:

  1. Connect session ci in state directory B with a profile whose stateDir is B and leaseProvider is limrun.
  2. Change that profile's provider to cloud. Connect ci in directory A with --state-dir A. Leave the B record in place.
  3. Run AGENT_DEVICE_STATE_DIR=A agent-device apps --session ci with no Limrun plugin and no token.

Defaults come from the A record, but the profile's stateDir replaces the environment default during the merge (src/cli.ts around lines 399-415 and 839-849). Admission checks cloud from A and the auth step returns UNAUTHORIZED. With auth available, materialization reads the Limrun record in B and refuses it only afterward (src/cli/commands/connection-runtime.ts 57-88, 186-192).

Required behavior

The provider and the record that materialization will use are selected once, before authentication, from the effective state directory and session. That selection is passed into materialization. The stored provider takes precedence over the profile fallback (#4846 already gives admission and materialization one shared precedence helper).

Completion conditions

  • A test with two state directories and a profile edited between connects: admission, authentication and materialization all use the same record; a missing plugin for that record reports the install command before any authentication.
  • No second read of the state directory default between admission and materialization.

Activity

  1. added this to the 0.22 - lean core milestone on Nov 20, 2026
  2. apex-sentinel-staging commented on Nov 20, 2026

    @apex-sentinel-staging

    Apex Sentinel · Issue review

    Suggested label: bug

    The issue reports that a remote CLI command can check one provider at admission while materialization later reads a different record because the effective state directory changes, with concrete repro steps and a required fix for selecting provider and record once before authentication.

    Required sections

    • Steps to reproduce
    • Expected and actual behavior (missing)
    • Version or environment (missing)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions