fix(cli): make session close accept --session and be idempotent - #420
Open
ankitranjan7 wants to merge 1 commit into
Open
fix(cli): make session close accept --session and be idempotent#420ankitranjan7 wants to merge 1 commit into
ankitranjan7 wants to merge 1 commit into
Conversation
`webcmd session close --session <id>` errored with SESSION_SELECTOR_POSITION
and suggested `webcmd --session <id> session close`, which then failed with
`missing required argument 'session-id'` — the suggested command could not
work, because `session close` takes the id as a positional.
- `session close` now takes `[session-id]` and falls back to the root
`--session` selector; with neither, it names both forms.
- The argv preprocessor rewrites `--session <id>` into the positional for
`session close` instead of throwing a broken suggestion.
- Closing an unknown / already-reaped Session returns
`{ ok: true, closed: false, alreadyClosed: true, session }` with exit 0.
A malformed selector stays INVALID_SESSION_SELECTOR / exit 2.
- The daemon now keeps the CliError code on unhandled command errors, so
SESSION_NOT_FOUND survives the wire instead of arriving as BROWSER_COMMAND.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
🟠 Maintainer review suggested — low confidenceThe automated review could not reach a fully supported conclusion. This review is advisory and does not block merging. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
webcmd session close --session session_abctold you to runwebcmd --session session_abc session close— and that command then failed withmissing required argument 'session-id'. The suggestion was impossible to satisfy:--sessionis a root selector everywhere in the CLI exceptsession close, where the id is a positional. A contestant in a recent eval burned three turns on that loop and never closed its session.What changed
session closetakes[session-id](optional) and falls back to the root--sessionselector. With neither, it errors naming both forms.rejectMisplacedSessionSelectorArgvis command-aware: forsession closeit rewrites--session <id>into the positional instead of throwing a suggestion that cannot work. Every other command keeps the existing SESSION_SELECTOR_POSITION error.session closeis idempotent — an unknown / already-reaped / already-closed Session returns{ ok: true, closed: false, alreadyClosed: true, session }and exit 0.InvalidSessionSelectorError(badid) still exits 2; every other failure still propagates.src/daemon/server.tskept no error code on unhandled command errors, soSESSION_NOT_FOUNDarrived at the client as a genericBROWSER_COMMANDwith only a message. The code is now preserved on the wire, which is what the idempotency check branches on.--forceis untouched.Before / After
Before (on
main):After (real output, isolated HOME):
Real Session, closed twice, then with
--force— all exit 0:Tests
src/cli-argv-preprocess.test.ts:--session,--session=, and--profile xprefixed forms all rewrite tosession close <id>; a valueless--sessionis dropped so the command reports both accepted forms.src/cli.test.ts: missing Session closes idempotently; root--sessionselector is accepted;badidstill throws INVALID_SESSION_SELECTOR exit 2.tests/e2e/management.test.ts: five tests that RUN the CLI — the suggestion round-trip (both spellings, asserting no usage error), unknown id idempotent, real Session closed twice,badidexit 2, and the no-id error text.npm run typecheck,npx vitest run --project unit(154 files, 2707 passed),npm run buildall green. The new e2e tests pass;management.test.ts > list shows all registered commandsfails in this worktree onmaintoo (fixture-plugin install), unrelated to this change.🤖 Generated with Claude Code