Repository navigation
fix(chat): pin queued input to a claude attach pane's job, and read a name before debug options - #2119
Conversation
…e before debug options, and bound the job state a /resume reads claudeForegroundSession found no session for an attach client, which keeps no PID record, so queued input was not pinned there: it now takes the session of the job the client opened. Claude reads debug options and --setting-sources after an attach name and still opens the job by name; the server read any argument there as no name. backgroundJobTranscript read state.json with a plain readFile: no size cap, and a FIFO there blocked. Part of #1876
… attach name (omo review)
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 8 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Merging 9818bb7: omo-native-code-reviewer and Codex both pass this head, and the required checks are green. CodeRabbit did not review this head. This touches queued input, so both reviewers checked it as such. The pin only refuses a send when a known session changes; it never redirects input. Codex's MEDIUM (separate debug values) and a pre-existing gap (an unreadable job state counts as compatible) go to a follow-up issue. |
… Claude session that can no longer be told (#2241) Follow-ups from the merge pass's reviews of #2126 and #2119. Each fix has a regression test that fails on main and passes here. ## Changes ### Claude transcript (#2130, items 1-2), `server/claude-store.ts` - **A branch's continuation stays in its project.** Once a `/branch` file is verified in the reported transcript's project, its `continued-in` continuation C is taken from beside it (`<project B>/C.jsonl`) before C is looked up by cwd or across projects. Before, an earlier cwd's project that also held a C was shown instead. The plain follow (no verified branch) keeps its cwd order unchanged, with a control test. - **Records are parsed before they are classified.** `branchedFrom`, `continuedInSession` and `backgroundJobTranscript` no longer pre-filter lines on the literal text `"type"` / `"type":"continued-in"`. A key written with escapes (`"\u0074ype"`) or a space after the colon is the same key. So an escaped first user record decides the branch check, an escaped newer turn after `continued-in` keeps the transcript, and spaced background-job records are still followed. ### `claude attach` queued input (#2125, items 1-2) - **Separate debug values** (`server/claude-store.ts`, `onlyDebugOptions`): `-d`/`--debug` after a name no longer consume the next argument. I checked this against the real Claude Code 2.1.311 in a temp `CLAUDE_CONFIG_DIR` with one job named `release`: - `claude attach release`, `… --debug`, `… --debug=api` → `Session aaaa1111 · release` (the name is looked up) - `claude attach release -d api,hooks`, `… --debug api` → `warning: extra arguments ignored: …`, `No job matching 'release'`, `A name must be the only argument.` So those now give `byName: false`, and the pane keeps its terminal. - **A known Claude session that can no longer be read is refused** (`server/core/pending.ts`, `pendingContext`). When a pending message's identity holds a Claude session (from the PID record or the attach job's state) and the current read names none, the pane is read once more. If it still names none, the message is held with `pending_target_changed` before anything is typed. Before, `samePendingIdentity` let `known → null` through, so a message queued for session A could be typed into B. - A momentary failed read (a record being rewritten) recovers on the second read. - After this delivery's own paste, an unknown read does not refuse, so a transient read cannot leave the row uncertain. A different known session there is still refused, as before. - `samePendingIdentity` itself is unchanged, so launch-bound first messages (`learn`/`targetChanged`) still tolerate a transient unknown. ## Tests - `server/claude-store.test.ts`: - the continuation beside the branch vs. the same id under an earlier cwd, plus a control for the plain follow; - an escaped first record; - an escaped newer turn after `continued-in`; - spaced background-job records; - `-d api,hooks` and `--debug api` in the keeps-terminal list, with `-d`, `--debug` and `--debug=api` alone as controls. - `server/core/pending.test.ts`: the test process stands in for a `claude attach <job>` client, with a real job state in a temp store. - Control: the send passes the identity check. - Control: one read that misses the session is read again and passes. - Once `state.json` is torn, Send now answers `pending_target_changed`, types no text or Enter, and the row stays held. - With the re-read removed, the test fails at the one-miss step. - `bun test server/claude-store.test.ts server/core/pending.test.ts server/pending-input.test.ts server/pending-input.contract.test.ts`: 267 pass, 2 skip (macOS only), 0 fail. `bun run check fast` is green. ## Reviews - **Codex Sol 6.1 (fast, xhigh):** round 1 found 3 MEDIUM, all fixed: - the unknown-session refusal after the paste; - the beside-first lookup changing the plain follow; - the literal prefilters in the other two transcript readers. The final round on the fixes returned APPROVE with no new findings. - **omo-native-code-reviewer:** round 1 found a HIGH in the #2125 test (two Send now presses with the same `resend_generation` replay the first reply) and 2 MEDIUM (a transient unknown read at the end of a turn; the refusal after the paste). All are fixed, and the delta re-review returned APPROVE. Its remaining LOW notes: - no test pins the `!pasted` condition; - several Claude processes in the foreground, or a foreground that never settles, still hold the message. That fails safe. ## Not in this PR (LOW, recorded here only) - #2130 item 3 (omo LOW): every cached branch check reads and hashes the branch head again, which costs a few ms synchronously for deep chains with large first messages. - #2130 item 4 (omo LOW): `forgetClaudeSessionFile` clears only that path, so intermediate chain files stay cached until eviction. Neither changes what the user sees, so per the follow-up bar they get no issue of their own. Closes #2125 Closes #2130
Part of #1876 (Claude Code attach follow-ups), after #2099.
Changes
claudeForegroundSessionfound no session for aclaude attachclient, which keeps no PID record, so a queued message was not pinned to the conversation it was typed for. It now takes the session of the job the client opened (claudeAttachSession), as Chat already does.claude attach <name> --debug(and-d [value],--debug=…,-d2e,--debug-to-stderr,--setting-sources <value>) is read as a name, as Claude reads it. In Claude Code 2.1.311's bundled codebackgroundSessionVerbIndexreturns 0 forattachfirst whatever follows, and the dispatcher hands only the argument afterattachto the attach handler; debug options and--setting-sourcesare read globally. Any other argument after the name still keeps the terminal (2.1.308's handling of those is unknown).backgroundJobTranscriptreadjobs/<id>/state.jsonwith a plainreadFile: no size cap, and a FIFO there blocked the lookup. It now usesreadSmallFile(256 KiB, non-blocking, no links); a state that cannot be read so does not agree, and the continuation's own transcript is kept.Left documented (no change)
pct) and the client attaches to the new daemon handle (state.daemonShort). The respawn rewrites the same job'sstate.json(daemonShort, andsessionId/resumeSessionIdwhen it resumes another conversation), whichclaudeJobSessionalready reads, so the pane follows the job's current session. Read from the bundled code, not exercised live.Verification
.omo/run/qa-attach.ts(local) starts an isolated herdr session (bun run check run) and an Ovis server on port 0, runs real Claude Code 2.1.311claude attach gamma --debugagainst a realclaude --bgjob (isolatedCLAUDE_CONFIG_DIR), then readsclaudeForegroundSessionon herdr'spane.process_infoand/api/pane/conversation. Before: queued-input session null, Chat on scrollback (FAIL). After: the job's session, Chat shows the job's reply (PASS).server/claude-store.test.ts: the attach-argument, queued-input pin and bounded/FIFO state cases fail on fix(chat): follow a Claude Code /branch to the transcript it goes on in #2099's code and pass here.bun run check faston 9818bb7: 7792 pass, 0 fail;server/claude-session.contract.test.ts17 pass;server/pending-input.contract.test.ts100 pass (before the rebase).-d --verbosecase is added), Codex Sol 6.1 Fast xhigh PASS with no findings.