Skip to content

fix(cli): run a command that takes no session while a leased connection is active - #4839

Merged
thymikee merged 1 commit into
mainfrom
fix/auth-leased-session-requirement
Nov 20, 2026
Merged

thymikee merged 1 commit into
mainfrom
fix/auth-leased-session-requirement

Conversation

@thymikee

@thymikee thymikee commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

With a leased connection saved as the machine's active connection, agent-device auth login, auth status and auth logout failed with REMOTE_SESSION_REQUIRED. The command could not satisfy the demand: auth does not accept --session, and it does not read AGENT_DEVICE_SESSION.

Cause: every command read the active connection's defaults, except a hand-kept list. auth was not on it, so the #3931 refusal fired for a command that runs on no connection.

Fix: a command that cannot take a session reads no connection. The rule replaces four entries of the list (daemon, plugins, device, proxy), which it covers, and also covers auth and web. Commands that take a session are unchanged: an unnamed command on a leased connection is still refused.

Before / after

With a leased connection active:

$ agent-device auth status
# before
Error (INVALID_ARGS): A leased remote connection needs its session named: pass --session <name> or set AGENT_DEVICE_SESSION.
# after
Not authenticated.

$ agent-device snapshot        # unchanged
Error (INVALID_ARGS): A leased remote connection needs its session named: ...

Validation

  • pnpm check:affected --run --head 314ce9f5c0: passed, exactCommit=true.
  • New test in cli-leased-session.test.ts: auth status runs beside an active leased connection, with and without AGENT_DEVICE_SESSION, while snapshot is still refused. It fails without the fix.
  • Independent review: no findings.
  • src/cli.ts stays at the 1,000-line cap.
  • No device run: CLI option resolution only, no device-facing change.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff Turn on auto-fix

@github-actions

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.47 MB 6.47 MB -2.1 kB
Package (unpacked) 6.47 MB 6.47 MB -2.1 kB
Package (download) 1.97 MB 1.97 MB -626 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 28.8 ms 23.7 ms -5.1 ms
CLI --help 61.4 ms 52.0 ms -9.4 ms

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 314ce9f

No open findings.

Reviewed with this repository's own Sentinel configuration (faa3c82ec103).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@thymikee

Copy link
Copy Markdown
Member Author

This PR is ready: at 314ce9f the fix is correct, and the shared session-support predicate now lets auth and web run on a leased connection without a session. Not blocking, and fine to take or leave: the leased-sessions help paragraph in src/commands/schema/cli-help.ts says every command names its session, which is slightly broader than the behavior now; shouldResolveRemoteAuth and REMOTE_MATERIALIZATION_DEFERRED_COMMANDS in src/cli.ts are still hand-kept lists of session-less commands and could derive from isFlagSupportedForCommand('session', command) in a follow-up; and the test in src/__tests__/cli-leased-session.test.ts covers auth status but has no web doctor case. No conflicts. The Coverage job is failing, but its log shows passing test output and expected stderr with no failure marker, and the diff touches only the CLI option-resolution route, so the failure looks unrelated or flaky. Not verified here: the new test and the suites were not run, and the PR body's check:affected run could not be confirmed. A re-run of Coverage should settle it, and it needs to go green, or be shown unrelated, before this merges.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 20, 2026
@thymikee
thymikee merged commit 357e0d4 into main Nov 20, 2026
23 of 24 checks passed
@thymikee
thymikee deleted the fix/auth-leased-session-requirement branch November 20, 2026 18:34
thymikee pushed a commit that referenced this pull request Nov 21, 2026
…#4879)

A command that cannot take a session runs on no remote connection. The CLI
already derived that for reading the active connection (#4839), but the
leased-session guard, the remote-auth check, and the materialization check
kept their own rules. Two bugs followed for `auth`:

- `auth status --remote-config <profile>` started a local daemon, leased a
  device on it, and saved the profile as the active connection.
- With a profile that names a lease provider, `auth status --remote-config`
  failed with REMOTE_SESSION_REQUIRED, and `auth` rejects `--session`.

All four checks now read one predicate. The explicit lists keep only the
commands that differ for another reason: `connection status` sends no
request, and the connection-lifecycle commands materialize the connection
themselves. The leased-sessions help and the remote-proxy, device-clouds,
and commands docs now limit the session requirement to commands that take a
session, and the leased-session test covers `web doctor`.

Closes #4850

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant