Repository navigation
fix(chat): check a queued Claude message's session right before its paste and its Enter (#2279) - #2318
Conversation
…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).
|
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 32 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 |
|
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
Not changed (LOW, optional, from omo):
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: |
|
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. |
A queued Claude Code message is pinned to the conversation (session) Claude named when it was queued.
/clear,/resumeor aclaude attachjob 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)stillInFrontchecks 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 everypendingContext, so it also runs right before Enter. Non-Claude agents and messages with no pinned session behave as before.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:
pending_target_changed, and nothing is typed.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.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.bun run check fastpassed. Thepending-inputcontract 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.
bun run typecheck. H2: a session switch during the reads after the session check before Enter still got Enter.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)
paneProcessInfoandpaneReadstubs, notclientSnapshot. omo noted both as optional.stillInFrontdescribes the process check. The session part is described in the comment inside the function.Closes #2279