Repository navigation
fix(cli): agent run refuses an --adapter that differs from the token file - #2099
Conversation
…file `--adapter` chose the CLI only at first-run bootstrap; once a token file existed, the record's adapter ran and a different flag was dropped without a word, so switching an agent from Claude to Codex kept running Claude (#2098). The run now exits 1 with the binding, the token path and the remedy for each path: `detach --force` and a re-bootstrap for a foreground run, `agent config --adapter` for a daemon-managed seat. The option help no longer says the flag is ignored. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_013geJsV4RJMujdvpf3JV2Cv
cli/src changed, so the published version must rise ("Source changed ⇒
version bumped").
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_013geJsV4RJMujdvpf3JV2Cv
lilyshen0722
left a comment
There was a problem hiding this comment.
Vera — verification gate, head 98921416
CLEARED. Base e968b39e, current with main.
The refusal is in the right place and normalises the way the layer below does
- Placement. The guard sits after the bootstrap branch and before
getAdapterand the spawn (cli/src/commands/agent.js:2746). A genuine first run still bootstraps with--adapterapplied asadapterOverride, so there is no false refusal on the path the flag was built for; andbootstrapAgentRecordFromEnvthrows on an unknown adapter or one absent from PATH, so a bootstrap cannot succeed into an immediate refusal. - Normalisation matches the consumer, which is the part I check hardest here. The predicate trims and lowercases both sides, and
daemon-supervisor.js:207readsrow.runtime.adapter.trim().toLowerCase(). The two agree, so--adapter Codexagainst acodexbinding is a match rather than a refusal — the test "a matching --adapter runs, whatever its case" pins exactly that. This repo has shipped two defects from a refusal predicate that normalised differently from the layer acting on the value; this one does not. - Both named remedies exist and do what the message says.
detach <name>carries--force(:2826,:2828), andconfig <name>carries--adapter(:3026,:3028) — which writes through the API and updates the local token file, so a subsequentrun --adapter <new>passes the guard. The daemon applies a registry change on its next pass (daemon-supervisor.js:209,adapterChanged). Preferring--forcein the foreground remedy is right: plaindetachalso uninstalls from the pod, which is not what "switch adapters" should cost.
Mutations reproduce exactly as reported
| mutation | result |
|---|---|
A — wiring off (if (false) in the run handler) |
1 of 6 fails: "a mismatched --adapter exits 1 with the remedy before anything runs" |
B — comparison off (if (true) return { ok: true }) |
2 of 6 fail: that one plus "a mismatched --adapter refuses and names the binding and both remedies" |
So the wiring and the predicate are separately witnessed, which is what makes the pair worth having rather than one end-to-end arm.
Version and suites
main0.1.86 → head 0.1.87, bumped inpackage.jsonand in both places the lockfile records it. Registrylatestis0.1.86and0.1.87is unpublished, so the publish comparison resolves topublish.cli: 56 suites, 1051 passed, 10 skipped, 0 failed, at this exact head.
One residual, checked and not reachable
The message names the agent via record.agentName while the path comes from tokenFile(name). For a token file lacking agentName the message would read 'undefined' is bound to … and hand over commonly agent detach undefined --force — a wrong instruction in the one place a reader is most likely to paste it verbatim.
I censused all three saveAgentToken writers (:2575 attach, :2737 bootstrap, :3053 config) and every one carries agentName, so this is not reachable through any supported path — it needs a hand-edited or foreign token file. Stated rather than filed: name is already in scope, is what the user typed, and is what the path is keyed on, so using it would remove the only way the two can disagree.
Gate review on #2102: since #2099 (cli 0.1.87) a later --adapter against a token file bound to another adapter is refused, so 'add --adapter codex to run Codex' taught a refusal after the first run. Say the first run binds the CLI, and name the two ways to switch later, matching the CLI's own error text. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018ajWuL8XiGBSHWiurjqm7B
Fixes #2098.
commonly agent run <name> --adapter Xonly ever chose the CLI at first-run bootstrap. Once~/.commonly/tokens/<name>.jsonexists, the record's adapter runs and a different--adapterwas dropped without a word, so switching an agent from Claude to Codex kept running Claude and looked like Codex misbehaving. Growth measured it on prod with two throwaway agents (CLI 0.1.85).What changes (
cli/src/commands/agent.js):checkRunAdapterRequest({ record, requestedAdapter, tokenPath }), a pure check: no flag → run; same adapter (case- and whitespace-insensitive) → run; different adapter → refuse with a message naming the bound adapter, the token path, and the remedy for each path. A record with no adapter is left to the existing "Unknown adapter" error.runaction calls it after the token file is loaded (or bootstrapped) and exits 1 on a refusal, before anything is spawned. The token file is not edited.Two corrections to the issue's proposed remedy, from reading the code:
commonly agent detach <name>also uninstalls the agent from its pod on the backend and needs a user login. For "switch CLIs", the local-only form is right, so the message sayscommonly agent detach <name> --force, then re-run with the Connect-page env exports and--adapter codex.commonly agent config <name> --adapter codexpatches the registry, anddaemon-supervisor.jsapplies it on its next pass (updates the record, returnschanged, the child restarts). A foregroundagent runnever reads the registry, which is why it needs the first form. The message names both.Not changed: the flag does not rewrite the token file. No fleet launch command passes
--adaptertoagent run(0 of the launchd plists and seat scripts on the operator host), so the refusal changes no live seat's behaviour.Version: cli 0.1.86 → 0.1.87 (package.json + both lockfile fields).
Tests (
cli/__tests__/run-adapter-mismatch.test.mjs, 6): the pure check (no flag, matching, matching with case/space, mismatch names binding + token path + both remedies and never suggests a baredetach, no-adapter record) and the wiring: the realagent runaction built byregisterAgent, run against a token file in a throwaway home, withprocess.exitmocked to throw. The mismatch exits 1 with the remedy on stderr and leaves the token file untouched. A help-text assertion pins the corrected description.if (false && !adapterRequest.ok)): exactly the wiring test fails, 5 pass.bound === requested→true): exactly the two mismatch tests fail, 4 pass.clisuite at the pre-rebase tree: 56 suites, 1046 passed, 10 skipped.eslint src/commands/agent.jsclean.Gate: Vera.
🤖 Generated with Claude Code
https://claude.ai/code/session_013geJsV4RJMujdvpf3JV2Cv