Skip to content

fix(cli): surface the attach session-target conflict - #196710

Merged
obviyus merged 4 commits into
openclaw:mainfrom
wangmiao0668000666:fix/attach-session-target-error
Nov 10, 2026
Merged

obviyus merged 4 commits into
openclaw:mainfrom
wangmiao0668000666:fix/attach-session-target-error

Conversation

@wangmiao0668000666

@wangmiao0668000666 wangmiao0668000666 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw attach <target> --session <id> throws a plain Error for the mutually-exclusive target/session conflict. Because it is not an ExpectedCliError, formatCliFailureLines treats it as unexpected and prints only:

[openclaw] The CLI command failed.
[openclaw] For help, run `openclaw doctor`.

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.ts validated the positional target / --session exclusivity with a bare Error, which the CLI failure handler classifies as unexpected and replaces with the generic line. Throwing ExpectedCliError (via throwExpectedCliError in src/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 an ExpectedCliError.

Evidence

Shipped packaged launcher proof (built dist)

Proven through the packaged CLI launcher — a fresh dist build of this branch (node dist/entry.js, OpenClaw 2026.10.9), run under Node 24.22.1 with an isolated HOME. The built dist/attach-cli-DcxArFP_.mjs imports throwExpectedCliError from ./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.

# BASE (this branch with the attach guard reverted to a bare throw, rebuilt into dist):
$ node dist/entry.js attach agent:main:spawn --session agent:main:spawn
[openclaw] The CLI command failed.
[openclaw] For help, run `openclaw doctor`.
exit 1

# HEAD (this branch, shipped packaged launcher):
$ node dist/entry.js attach agent:main:spawn --session agent:main:spawn
pass one session target: use either the positional target or --session
exit 1

Same dist build; only the attach-guard throw differs between the two chunk variants. Head dist attach-cli chunk sha256 14c825f09d7a15214c20db05b1a5df30a45282a99c2bf719084e440710f19db7.

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 ExpectedCliError in src/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 plain Error, not an ExpectedCliError; on this head it passes.

  • Baseline (RED): throw new Error(...) → test FAILs (Error not ExpectedCliError)
  • Head (GREEN): throwExpectedCliError(...) → 16/16 tests in attach-cli.action.test.ts pass; 15 existing tests unaffected

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.
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Nov 10, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Display the existing explanation when attach receives both a positional target and --session.

Example: Run openclaw attach main --session abc.

  • Before: Prints a generic command failure and Doctor hint; exits 1.
  • After: Prints “pass one session target: use either the positional target or --session”; exits 1.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A complete, minimal diagnostic repair supported by packaged-entry-point proof and a focused regression case.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The current-head collaborator report exercises the built attach CLI in secretless Docker with isolated HOME and a local Gateway, showing the specific conflict message and exit 1 against main's generic output, with unchanged control scenarios.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Conflicting session selectors produce a generic failure that hides how to correct the command.
Reason: The change restores an actionable diagnostic for an already documented restriction without introducing new behavior or configuration.

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
Reviewed head: 1a8e743bba4b66804656a6992b1990ca714dcdf8

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Attach positional-target conflict keeps the original intent (055a2dc: The session-URL continuation feature added positional targeting and rejected combining it with --session.)
  • Action settlement and malformed-grant test assertions keeps the original intent (98813c2: Shutdown coverage tracks outstanding actions through settlement; subsequent malformed-grant coverage protects revocation. The compacted assertions retain both contracts.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +3, Tests 0. Total +3 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 4 1 +3
Tests 1 7 7 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 11 8 +3

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A conflicting invocation hides its actionable argument error, with limited impact on the advanced attach CLI workflow.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-11-10T15:07:46.368Z sha d118426 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-10T15:53:41.167Z sha d118426 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-10T17:12:51.823Z sha d118426 :: needs maintainer review before merge. :: none

Reviewed November 10, 2026, 12:43 PM ET / 17:43 UTC (Revision 4).

@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 10, 2026
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 10, 2026
@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

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).

openclaw attach main --session abc

  • main 47b0ce4: The CLI command failed. For help, run openclaw doctor., exit 1
  • this PR 1a8e743: pass one session target: use either the positional target or --session (same text as main), exit 1

Controls, identical on both trees:

  • attach --session agent:main:main --print-config: grant JSON, exit 0
  • attach main --print-config (target alone, fails while resolving): generic failure line, exit 1
  • attach --print-config --url ws://127.0.0.1:1 (unreachable Gateway): generic failure line, exit 1

@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 10, 2026
@obviyus
obviyus merged commit cd6abdb into openclaw:main Nov 10, 2026
108 checks passed
@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Landed in cd6abdb. Thanks @wangmiao0668000666. attach now shows the real session-target conflict.

@wangmiao0668000666
wangmiao0668000666 deleted the fix/attach-session-target-error branch November 11, 2026 00:50
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 11, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants