Repository navigation
fix(cli): surface the attach session-target conflict - #196710
Conversation
Passing both a positional target and --session threw a plain Error, so formatCliFailureLines treated it as unexpected and printed only "[openclaw] The CLI command failed." with the actionable reason swallowed. Throw ExpectedCliError so the reason is shown. Test asserts the conflict surfaces as an ExpectedCliError.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesDisplay the existing explanation when attach receives both a positional target and --session. Example: Run openclaw attach main --session abc.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a current CLI diagnostic defect with a focused change and no actionable findings; pending CI remains the normal merge gate. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe attach command validates session-selection arguments before loading config or requesting a Gateway grant; the shared CLI failure renderer turns its rejection into terminal output. flowchart TD
A[CLI arguments] --> B[Attach argument guard]
B --> C[Expected CLI error]
C --> D[Shared failure renderer]
D --> E[Actionable terminal output]
B --> F[Valid request continues to Gateway]
Technical reviewBest possible solution: Merge the existing-helper fix once the normal checks pass. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the bare Error and generic renderer path; supplied packaged-CLI before/after output confirms the failure without executing target code during this review. Is this the best way to solve the issue? The patch uses the existing expected-error owner at the rejecting guard, preserving the documented exclusivity rule, wording, and exit behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 47b0ce478c81. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +3, Tests 0. Total +3 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)Reviewed November 10, 2026, 12:43 PM ET / 17:43 UTC (Revision 4). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Proof on the built CLI (node 24.22.1, secretless Docker, isolated HOME, local Gateway). Branch merged with current main; the allocation file is removed and the test change is net 0 lines (+7/-7).
Controls, identical on both trees:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in cd6abdb. Thanks @wangmiao0668000666. attach now shows the real session-target conflict. |
fix(cli): surface the attach session-target conflict openclaw attach <target> --session <id> threw a plain Error for the target and session conflict, so the CLI showed only the generic "The CLI command failed." line. The existing message is now thrown as an expected CLI error, so users see "pass one session target: use either the positional target or --session". The text is unchanged and the exit code stays 1. Evidence: the built CLI on Node 24.22.1 in secretless Docker with an isolated HOME and a local Gateway. openclaw attach main --session abc printed the generic failure line on main and the existing conflict message with this change, exit 1 on both. --session alone with --print-config, an unreachable Gateway and a target alone behave the same on both. Details: openclaw#196710 (comment). Thanks @wangmiao0668000666. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
openclaw attach <target> --session <id>throws a plainErrorfor the mutually-exclusive target/session conflict. Because it is not anExpectedCliError,formatCliFailureLinestreats it as unexpected and prints only:The actionable reason ("pass one session target: use either the positional target or --session") is swallowed.
User Impact
The conflict reason is now printed instead of the generic failure line, with the same exit code 1. No new wording; the reason the CLI already produced is surfaced.
Why This Change Was Made
attach-cli.tsvalidated the positional target /--sessionexclusivity with a bareError, which the CLI failure handler classifies as unexpected and replaces with the generic line. ThrowingExpectedCliError(viathrowExpectedCliErrorinsrc/cli/expected-cli-error.ts) routes it to the expected-output branch that prints the reason. Same shape as existing CLI error-surfacing fixes (#196081, #196382).What Changed
src/cli/attach-cli.ts:throw new Error(...)→throwExpectedCliError(...)for the target/session conflict.src/cli/attach-cli.action.test.ts: new test asserting the conflict surfaces as anExpectedCliError.Evidence
Shipped packaged launcher proof (built dist)
Proven through the packaged CLI launcher — a fresh
distbuild of this branch (node dist/entry.js, OpenClaw 2026.10.9), run under Node 24.22.1 with an isolatedHOME. The builtdist/attach-cli-DcxArFP_.mjsimportsthrowExpectedCliErrorfrom./expected-cli-error-Dj3va_oa.mjs(the compiled equivalent of this PR's source change). No gateway connection is reached — the argument conflict is rejected before config load, session resolution, or grant creation.Same dist build; only the attach-guard throw differs between the two chunk variants. Head dist
attach-clichunk sha25614c825f09d7a15214c20db05b1a5df30a45282a99c2bf719084e440710f19db7.The same before/after behavior is reproducible through the source shipped entry (
node --import ./scripts/tsx.mjs src/entry.ts attach agent:main:spawn --session agent:main:spawn), matching the built dist output byte-for-byte.RED -> GREEN
The conflict case is covered by a new regression test
surfaces the positional/session conflict as an ExpectedCliErrorinsrc/cli/attach-cli.action.test.ts. On the current-main baseline (production WITHOUT the fix, test WITH the assertion) the test fails — the rejection is a plainError, not anExpectedCliError; on this head it passes.throw new Error(...)→ test FAILs (ErrornotExpectedCliError)throwExpectedCliError(...)→ 16/16 tests inattach-cli.action.test.tspass; 15 existing tests unaffected