Skip to content

fix(chat): check a queued Claude message's session right before its paste and its Enter (#2279) - #2318

Merged
devswha merged 3 commits into
mainfrom
fix/claude-switch-queued
Oct 29, 2026
Merged

devswha merged 3 commits into
mainfrom
fix/claude-switch-queued

Conversation

@devswha

@devswha devswha commented Oct 29, 2026

Copy link
Copy Markdown
Owner

A queued Claude Code message is pinned to the conversation (session) Claude named when it was queued. /clear, /resume or a claude attach job switch that session inside the same process, so the foreground PID stays the same. Before this PR:

So a switch in those windows could paste the message, and Enter it, into the other conversation.

Changes (server/core/pending.ts)

  • stillInFront checks the pinned Claude session too. It reads what herdr has in front (PID check), then the pinned session from Claude's own records, then what herdr has in front again (PID check). The session lookup gets one re-read, for a record caught mid-rewrite. The second foreground read is there because a Claude process that leaves the front while its records are read is still alive and still names the pinned session. This check is the last await before the paste and the last await of every pendingContext, so it also runs right before Enter. Non-Claude agents and messages with no pinned session behave as before.
  • An unknown session after the delivery's own paste no longer gets Enter. The fix(chat): follow-ups from the claude attach queued-input review (#2119) #2125 rule (known before, unknown now) now applies after the paste too. The session is read once more, and if it is still unknown the row is left uncertain (submit_changed), with no Enter. This replaces fix(chat): keep a /branch's continuation in its project, and refuse a Claude session that can no longer be told #2241's deliberate tolerance, as the issue proposes.

Outcomes:

  • A switch before the paste holds the row with pending_target_changed, and nothing is typed.
  • A switch after the paste leaves the row uncertain, with no Enter.
  • One transient unreadable read still delivers normally.

Tests

  • server/core/pending-identity-race.test.ts: 12 new deterministic cases on the real pending-delivery path, with herdr's transport mocked and no sleeps.
    • The pane switches from session A to session B, or to an unreadable session, during the input-box read, during the paste, and during the screen read before Enter.
    • Another Claude process replaces A during the last session lookup, both before the paste and before Enter.
    • Controls cover one transient miss.
    • One row pins the window that is left (below).
    • On main (010a44d), 8 of them fail. Both earlier heads of this PR fail the cases their reviews found. All pass here.
  • server/pending-input.contract.test.ts: the fix(chat): follow-ups from the claude attach queued-input review (#2119) #2125 control "commits a message whose hookless Claude session cannot be read only after its own paste is in" now expects the new behaviour: the row is uncertain, and only the paste is written, without the Enter.
  • Local runs: bun run check fast passed. The pending-input contract suite passed 103 of 103 and typecheck was clean, both on this head.

Reviews

Both reviewers saw every round, and each round's findings were reproduced with a failing test before they were fixed.

  • Round 1 (f697ef6):
    • omo: BLOCK. H1: the new test broke bun run typecheck. H2: a session switch during the reads after the session check before Enter still got Enter.
    • Codex Sol 6.1 fast xhigh: BLOCK. HIGH: the same as H2. MEDIUM: a PID read after the new session check let a switch reach the paste.
    • Fixed in 9377fab. One combined check now reads the session after herdr's answer.
  • Round 2 (9377fab):
    • omo: APPROVE.
    • Codex: BLOCK, HIGH: a Claude process replaced while its session record was being read, but still alive, passed the check. Fixed in 5837045 with the second foreground read.
  • Round 3 (5837045, this head): omo APPROVE and Codex APPROVE, both with no findings. Codex also checked unpinned and null-PID behaviour and first-message delivery.

Known limit

herdr cannot compare and write in one step, so some read is always last. A same-process session switch during the final foreground read before the paste still gets the paste. The check before Enter then withholds the Enter and leaves the row uncertain. The test row "the process read that closes the last check before the paste" pins this. On main, that window was several herdr calls plus a screen read.

Not in this PR (LOW, recorded here only)

  • A Claude whose PID record is unreadable twice in a row right after the paste leaves an otherwise correct send uncertain, with no Enter. This fails safe: the user checks the terminal, and nothing goes to the wrong conversation. One re-read covers a record being rewritten. How often this happens in real use is not measured.
  • The race cases pick their switch points by counting herdr reads, as the rest of that file does. The "after check" row sees only herdr calls made through the paneProcessInfo and paneRead stubs, not clientSnapshot. omo noted both as optional.
  • The JSDoc of stillInFront describes the process check. The session part is described in the comment inside the function.

Closes #2279

…aste and its Enter (#2279)

The last check before the paste compared only the foreground PID, and
/clear, /resume or a claude attach job switch Claude's session inside the
same process. The session is now read again right before the paste (one
re-read for a record caught mid-rewrite), so a switch during the input-box
or catalog reads holds the message unsent.

After the paste, a session that cannot be read is read once more before
Enter; if it stays unknown the row is left uncertain without the Enter,
instead of committing the paste in a session that cannot be told. This
replaces #2241's tolerance of an unknown read after its own paste.
…its paste and its Enter (#2279)

Review of the first commit found that the session check before Enter was
followed by more herdr reads that compared only the PID, so a session
switch during the screen read still got Enter, and the PID read after the
new pre-paste session check could let a switch reach the paste.

stillInFront now checks the pinned Claude session too, after herdr names
what is in front, and nothing is read from herdr after it before the write.
It closes every pendingContext (so also the check before Enter) and is the
last check before the paste. The new race test's rows are typed as
string[] so typecheck passes.
…sage's session is read (#2279)

Re-review found that reading Claude's session last opened its own window:
a Claude process that left the front while its records were read, still
alive, still names the pinned session, so the paste or Enter went to the
process that replaced it. stillInFront now reads the foreground, then the
pinned session, then the foreground again. A session switch during that
last herdr read is the one window left, as herdr cannot compare and write
in one step; a test row pins it (paste, then no Enter).
@coderabbitai

coderabbitai Bot commented Oct 29, 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 32 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 010a44d and 5837045.

Files selected for processing: 4
  • changelog.d/claude-session-switch-queued.md
  • server/core/pending-identity-race.test.ts
  • server/core/pending.ts
  • server/pending-input.contract.test.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 29, 2026

Copy link
Copy Markdown
Owner Author

CodeRabbit hit its review limit on this head (5837045) and did not review it. This PR touches queued input, so per AGENTS.md here are the code-review agents' findings and how each was resolved. Reviewers: omo-native-code-reviewer and Codex gpt-6.1-sol (fast tier, xhigh reasoning), both on an adversarial, read-only brief. Each blocking finding was reproduced as a failing test before it was fixed.

Round / SHA Reviewer Finding Resolution
1 / f697ef6 omo HIGH: the new race test broke bun run typecheck (TS2769, readonly tuple rows). Every row is typed as string[]; typecheck exits 0 (9377fab).
1 / f697ef6 omo + Codex HIGH: before Enter, pendingContext read the Claude session and then awaited more herdr reads that checked only the PID. A switch from session A to B during the screen read after the paste still got Enter, and the row was removed as sent. stillInFront checks the pinned session and closes every pendingContext. New enter rows for B, for an unreadable session, and a one-miss control (9377fab).
1 / f697ef6 Codex MEDIUM: the PID-only stillInFront that ran after the new pre-paste session check let a switch during that read reach the paste. Merged into one check that reads the session after herdr's answer (9377fab).
2 / 9377fab omo APPROVE, no findings. It verified each fix with mutations. —
2 / 9377fab Codex HIGH: a Claude process that left the front during the session lookup, but was still alive, kept its valid record, so its replacement got the paste or Enter. stillInFront now reads the foreground, then the session, then the foreground again. New replaced before paste/Enter rows, which fail on 9377fab (5837045).
3 / 5837045 omo APPROVE, no findings. Removing the final foreground read fails the new rows. —
3 / 5837045 Codex APPROVE, no findings. It also checked unpinned and null-PID behaviour, first messages, and that nothing is thrown twice. —

Not changed (LOW, optional, from omo):

  • The after check test row notices only herdr calls made through the paneProcessInfo and paneRead stubs.
  • The JSDoc of stillInFront names only the process. The session part is described in the comment inside the function.

The known limit, a same-process session switch during the final herdr read, is pinned by a test row and described in the PR body. In that case the check before Enter withholds Enter and the row is left uncertain.

Local checks on 5837045: bun run check fast passed (exit 0), and the server/pending-input.contract.test.ts suite passed 103 of 103.

@devswha

devswha commented Oct 29, 2026

Copy link
Copy Markdown
Owner Author

Merging 5837045 (closes #2279). A queued Claude message is now checked against its pinned session last before the paste and again before Enter (foreground, then session, then foreground); if the session cannot be confirmed after the paste, no Enter is sent and the row is marked uncertain, so a message never goes into another session's prompt. Queued input, so the merge pass reviewed it itself beyond the lane's three rounds (2 HIGH + 1 MEDIUM, then a Codex HIGH, each fixed with a failing test first; round 3 omo + Codex APPROVE): no CRITICAL, HIGH or MEDIUM; core tests 211/211, the isolated pending-input contract 103/103, typecheck clean. Known limit (in the PR body): herdr has no compare-and-write, so a session switch in the instant between the last read and the write is not caught; real Claude rendering of the uncertain row was not checked in this review.

@devswha
devswha merged commit 31d193c into main Oct 29, 2026
26 of 28 checks passed
@devswha
devswha deleted the fix/claude-switch-queued branch October 29, 2026 04:55
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.

fix(chat): a Claude session switch during delivery can still take a queued message (from #2241 review)

1 participant