Repository navigation
fix(cli): show session-target remedies for attach failures - #198345
SunnyShu0925 wants to merge 1 commit into
Conversation
resolveSessionTarget threw plain Errors, so the root CLI renderer hid attach remedies (ambiguity table, not-found hints, URL conflict, connection recovery) behind the generic doctor message while tui showed them. Throw ExpectedCliError at the remedy sites; messages, exit codes, and JSON output stay unchanged.
|
🦞👀 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 changesThis PR makes attach failures display the session resolver’s existing recovery instructions. Example: Run openclaw attach "https://gw.example/dashboard/main/movies-a1166b81" --url wss://other.example.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR repairs a current, documented CLI error-reporting defect with a focused change and convincing terminal evidence; no actionable code defect was found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe shared CLI session-target resolver accepts session references and Gateway options, calls Gateway resolution when needed, and returns a resolved session or an error consumed by attach, TUI, and session imports. flowchart TD
A[CLI target and options] --> B[Session target resolver]
B --> C[Gateway transport]
C --> B
B --> D[Resolved session]
B --> E[Expected CLI error]
E --> F[Root terminal renderer]
Technical reviewBest possible solution: Keep the focused owner-side ExpectedCliError conversion and land it once the required CI gate passes. Do we have a high-confidence way to reproduce the issue? Yes: the current-main resolver, attach caller, and root renderer establish the failure path, and the contributor supplies matching before/after terminal output; this read-only review ran no target code. Is this the best way to solve the issue? The patch restores the documented contract at the existing error producer, preserves messages and unexpected-error handling, and avoids broadening the root renderer’s whitelist. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1904c27817b7. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +7, Tests -4. Total +3 across 3 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:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 Reviewed November 13, 2026, 11:06 AM ET / 16:06 UTC. |
|
Thanks for the work here. We're closing this one along with the other open per-command |
What Problem This Solves
An operator who points
openclaw attachat a short session reference gets no actionable output.openclaw attach "https://gw.example/dashboard/main/movies-a1166b81" --url wss://other.exampleprints only[openclaw] The CLI command failed.plusFor help, run openclaw doctor.— the remedy the resolver already composed ("pass one target: use either the session URL or --url, not both") never reaches the terminal, and the doctor hint sends the operator to the wrong next step. The same collapse hides the formatted ambiguity table for a colliding prefix, theNo session foundhint, and the gateway-unreachable / stored-device-auth recovery lines.resolveSessionTargetinsrc/cli/session-target.tsraises its operator remedies as plainErrors.attachawaits it directly, so they bubble to the root CLI renderer, which prints the message only for expected CLI errors and a narrow show-reason whitelist that does not includeattach.throwExpectedCliError/ExpectedCliErrorowner insrc/cli/expected-cli-error.ts, message text verbatim.src/cli/session-target.ts(+16/−9) — six returned remedy errors and three thrown remedy errors now carryhumanOutput. Regression assertions folded into the existing cases insrc/cli/session-ref.test.tsandsrc/cli/session-target.test.ts(net −4 test lines, no new test file).formatCliJsonFailurealready kept the message),openclaw tuioutput, and the internal-invariant error atsession-target.ts:199("Gateway returned a session without a consistent agent identity.") which stays a plainErrorbecause it names a branch that should not happen.Why This Change Was Made
The session-target owner already writes these remedies for one purpose — telling the operator what to do next — and one of its two consumers honours that contract while the other discards it.
src/cli/tui-cli.ts:96-105catches around the sameresolveSessionTargetcall and prints the formatted message;src/cli/attach-cli.ts:103awaits it unwrapped, so the identical remedy is visible undertuiand invisible underattachfor the same input. That asymmetry is the strongest signal this is a missed site rather than a deliberate choice, and it is the same reasoning accepted in the merged dns CLI fix #192127 and the hooks CLI fix #190366, which adopted exactly this per-site shape.Alternatives considered and rejected: adding
attachto the renderer's show-reason whitelist would print raw reasons for every attach failure including unforeseen internal errors, a larger blast radius than one guard needs. Putting the conversion in theattachaction instead would leave the second consumer (and any future one) re-deriving the contract that the owner already owns. ConstructingExpectedCliErrorinline at each of the sixshapeTargetErrorreturn sites would triplicate the long remedy templates in a three-field constructor call, so those sites share one local factory over the owner class; the three throw sites callthrowExpectedCliErrordirectly.User Impact
Operators running
openclaw attachwith an ambiguous short reference, a mistyped reference, a conflicting URL and--url, or an unreachable gateway now see the remedy — including the already-formatted candidate table and thesessions listhint — instead of a generic failure and a doctor pointer. Successful and JSON-mode invocations are untouched, and every affected path still exits 1.Evidence
origin/main5bdadab2c73, owner file reverted)14a4ec8219f)attach <session URL> --url wss://other.examplepass one target: use either the session URL or --url, not both(exit 1)attach <ref> --urlto a port nothing listens onCould not reach gateway wss://127.0.0.1:18307. Check whether the gateway is down and whether its tailnet or SSH tunnel is reachable.(exit 1)tuiwith the same two inputs (control)Live runs use the shipped source entry (
node --import ./scripts/tsx.mjs src/entry.ts …) withOPENCLAW_STATE_DIRandOPENCLAW_CONFIG_PATHon a scratch directory holding a minimal config, so no real state or config is touched; the unreachable cells hit a genuine TCP refusal on loopback port 18307 (nothing listening) and travel the realcallGatewaytransport, with no mocks. All eight runs exit 1, and the twotuicontrol outputs diff byte-identical between base and head.After (this head), conflict cell:
Before (same command,
origin/mainversion of the owner file):After, unreachable cell (real
ECONNREFUSED, remedy plus the transport detail the operator needs):The ambiguity table is the remedy most worth keeping visible, and it is a multi-line block, so the renderer branch matters: expected CLI errors print
humanOutputverbatim including newlines. It is pinned at the owner boundary instead —src/cli/session-ref.test.ts"prints bounded ambiguity candidates without listing or describing" asserts the candidate rows and thePass a longer referenceline arrive inside anExpectedCliError.Unit invariant, same tests with the owner file swapped (mutation = full production revert, restored by recorded sha256): on base the plain errors carry
messagebut nohumanOutput, so the class pins fail while all 29 message-text assertions pass on both sides — proof the messages are byte-identical and only the envelope changed.Consumers of the owner file were run, not reasoned about: every importer of
src/cli/session-target.js(attach-cli.action.test.ts,sessions-import.test.ts, the doctor config preflight process test,run-main.bare-root.test.ts,run-main.command-dispatch.test.ts) — 132 tests green on this head.attach-cli.action.test.tsalready assertederror instanceof Errorplus verbatimmessageon the ambiguity case, andExpectedCliErrorextendsError, so that existing contract stayed green without edit.Open PR collision check (submission-day sweep, 2026-11-13): scanned the changed-file lists of the 60 most recent open PRs for
src/cli/session-target.ts,session-ref.ts,attach-cli.ts,expected-cli-error.tsand the two test files — zero hits. Keyword searches (session reference is ambiguous,attach session target,session-target,ExpectedCliError) left #175714 as the only open PR touchingsrc/cli/attach-cli.ts; it changes grant-expiry range validation there and shares no hunk with this owner-side change, and #190362's session-target test lives undersrc/gateway/, not here. Gate 2.5: nothing in the last 14 days contradicts per-siteExpectedCliErrorconversion — #192127 and #190366 established it, #196710 (merged three days ago) uses the same shape, and #197508 only threads the signal through. The defect is still present on currentorigin/main.What was not tested: local lint and typecheck lanes. The repo wrappers reject this worktree's symlinked install ("Declaration input escapes checkout"), consistent with the sibling CLI PRs, so lint and types are left to CI on this head; the change is confined to one module and the error owner's public constructor.
openclaw attachwas not proven end to end against a live gateway with two genuinely colliding session prefixes — that path needs a running gateway and a real prefix collision, so the ambiguity cell is pinned at the owner boundary rather than through the shipped entry.