Skip to content

fix(chat): pin queued input to a claude attach pane's job, and read a name before debug options - #2119

Merged
devswha merged 2 commits into
mainfrom
fix/claude-attach-followups
Oct 28, 2026
Merged

devswha merged 2 commits into
mainfrom
fix/claude-attach-followups

Conversation

@devswha

@devswha devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Part of #1876 (Claude Code attach follow-ups), after #2099.

Changes

  • Queued-input pinning (item 4): claudeForegroundSession found no session for a claude attach client, 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.
  • A name with debug options after it (item 6): 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 code backgroundSessionVerbIndex returns 0 for attach first whatever follows, and the dispatcher hands only the argument after attach to the attach handler; debug options and --setting-sources are read globally. Any other argument after the name still keeps the terminal (2.1.308's handling of those is unknown).
  • Bounded job state (item 5): backgroundJobTranscript read jobs/<id>/state.json with a plain readFile: no size cap, and a FIFO there blocked the lookup. It now uses readSmallFile (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)

  • "Session moved to …" (item 1): in 2.1.311 it is printed only on the wake path: a job whose worker is gone is respawned (pct) and the client attaches to the new daemon handle (state.daemonShort). The respawn rewrites the same job's state.json (daemonShort, and sessionId/resumeSessionId when it resumes another conversation), which claudeJobSession already reads, so the pane follows the job's current session. Read from the bundled code, not exercised live.
  • Caching the parsed state (item 2): each poll reads at most 256 KiB through the bounded reader; a stat-keyed cache would save one small read and adds a staleness question (inode reuse, as the fix(chat): follow a Claude Code /branch to the transcript it goes on in #2099 review showed), so it is left out.
  • Windows stores (item 3) and the partial job schema check (item 7) need signals Claude does not give; unchanged.

Verification

  • Real surface: .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.311 claude attach gamma --debug against a real claude --bg job (isolated CLAUDE_CONFIG_DIR), then reads claudeForegroundSession on herdr's pane.process_info and /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 fast on 9818bb7: 7792 pass, 0 fail; server/claude-session.contract.test.ts 17 pass; server/pending-input.contract.test.ts 100 pass (before the rebase).
  • Reviews: omo-native-code-reviewer PASS (four LOW; the missing -d --verbose case is added), Codex Sol 6.1 Fast xhigh PASS with no findings.
  • REMOTE_BUNDLE_VERSION: a server change the remote bundle carries; the release PR raises it (now 38) when the release guards ask.

…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
@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 817f238 and 9818bb7.

Files selected for processing: 3
  • changelog.d/claude-attach-followups.md
  • server/claude-store.test.ts
  • server/claude-store.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

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.

@devswha
devswha merged commit 6f9b80f into main Oct 28, 2026
19 checks passed
@devswha
devswha deleted the fix/claude-attach-followups branch October 28, 2026 01:45
devswha added a commit that referenced this pull request Oct 28, 2026
… 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant