Repository navigation
fix(chat): follow a Claude Code /branch to the transcript it goes on in - #2099
Conversation
Claude Code's /branch copies the conversation into a new transcript whose records carry forkedFrom.sessionId and moves its process there, rewriting its PID record. A Herdr hook without the fork matcher keeps reporting the session the branch came from, so Chat kept reading the old transcript. Read the PID record's session beside Herdr's report and take its transcript when its first records say it was branched from the reported session (or a branch of it) in the same project. No folder scan: after /resume back, the branch is newer but no longer the one shown. Fixes #2020
A live session with no transcript yet made the branch check scan every project, and an unreadable one there threw instead of keeping the reported transcript (Codex review).
…estore the contract test's PID record From the omo review's low findings.
A remembered miss outlived a transcript deleted and written again on the same inode (Codex delta review): the cost of re-reading only falls on a first prompt over 1 MiB.
|
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 |
|
CI notes for 0c43433 (run 40606595745), for the merge pass:
The Codex delta re-review (Sol 6.1 Fast xhigh) confirmed the first MEDIUM fixed and raised one against the cache added in f9a3616; 0c43433 removes that cache, so the store code is the one that round passed. CodeRabbit was rate-limited on this head. |
|
Attempt 3 of the failed jobs passed: every check on 0c43433 is green now (run 40606595745). |
|
Merging 0c43433: omo-native-code-reviewer and Codex both pass this head, and the required checks are green (Integration and browser passed on a rerun after a known OpenCode contract flake). CodeRabbit did not review this head. Codex's three MEDIUMs and omo's tracker note go to a follow-up issue. |
… name before debug options (#2119) 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 #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 #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.
…and follow the file checked From the #2099 review (#2118): the branch follow looked the id up again and could land on another project's file of that id; a metadata record before the conversation, or a first record of another session's, could name the parent; and the remembered parent outlived a head written again in the same file. Follow from the verified path, take the parent from the first user or assistant record of the file's own session, and check the remembered head by its digest (and forget it with the file). Part of #2118
…and follow the file checked (#2126) Part of #2118 (follow-ups from the merge pass's review of #2099): items 1-3. ## Changes (`server/claude-store.ts`) 1. **Follow the file that was checked.** After a branch is verified in the reported transcript's project folder, the `continued-in` follow now starts from that exact file. Before, it looked the id up again by cwd and could land on another project's unbranched file of the same id. 2. **Parent only from the branch's own first message.** `branchedFrom` skips metadata (`file-history-snapshot` and the like) and decides on the first user or assistant record, and only when that record's `sessionId` is the file's own. Before, a metadata line carrying `forkedFrom`, or a first record of another session's, made a file pass as a branch. Real Claude Code 2.1.311 writes every copied record with the new session id and `forkedFrom.sessionId`, so real branches are still followed. 3. **A remembered parent is checked against the head it came from.** The cache keeps the length and SHA-256 of the head up to the deciding line, reads that much back on each use (one small record), and `forgetClaudeSessionFile` drops it. Before, a same-inode rewrite kept the old verdict. Items 4 (background-task counts and the plan sidebar keep the old transcript's tracker after `/branch`, not a regression) and 5 (macOS spawns `ps` on each Chat read of a reported pane, as the pending-input path already does) stay open in #2118. ## Verification - `server/claude-store.test.ts`: three new cases (same id in a project a cwd names first; metadata or another session naming the parent; a head written again in the same file) fail on main and pass here; 90 pass in the file. - Real surface: `.omo/run/qa-branch.ts` (local) with real Claude Code 2.1.311 in an isolated herdr session and an Ovis server on port 0: after `/branch`, `/api/pane/conversation` shows the reply typed in the branch (**PASS**), as on #2099. - `server/claude-session.contract.test.ts`: 17 pass on the rebased head. - Reviews on the change: omo-native-code-reviewer PASS (LOW notes only: a head re-read per poll, a branch whose copied metadata exceeds 1 MiB falls back to the reported transcript, chain entries outlive `forgetClaudeSessionFile` until evicted, and the pre-existing cwd preference when following `continued-in`), 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 when the release guards ask.
Fixes #2020. Reported by @Hyd3-14.
Problem
After Claude Code's
/branch, Chat kept reading the transcript the branch was copied from: the/branchbubble could not be confirmed and every later message stayed "working" with no reply.What real Claude Code 2.1.311 does on
/branch(observed with an isolatedCLAUDE_CONFIG_DIR):<new>.jsonlin the same project folder; each copied record carriesforkedFrom: {sessionId: <old>, messageUuid}(aftermessage, so a long first prompt pushes it far into the line); records after the branch have none;sessions/<pid>.jsonto the new session at once;fork. A herdr Claude hook whose SessionStart matcher lacksfork(an older install; this PC's v10 install has it) keeps herdr's report on the old session, and Ovis prefers herdr's report;/resume <old>back, the branch file is the newer one but no longer the one shown, so "newest forkedFrom child in the folder" would pick wrongly.Fix
server/conversation.ts: read the session the pane's one (non-attach) Claude process names in its PID record beside herdr's report. Beside a report, a record that cannot be read leaves the report as it was.server/claude-store.tsclaudeTranscriptFile(…, live): follow herdr's session and itscontinued-inchain as before; then takelive's transcript only when its first conversation record says it was branched (forkedFrom.sessionId) from a session in that chain, or from a branch of one (up to 8 levels), looking only in the reported transcript's project folder. No folder scan, no guess: a live session that is no branch of the reported one (after/resumeback, another conversation) changes nothing.branchedFrom()reads at most 1 MiB of the head, non-blocking and without following links, whole lines only, and remembers the answer per file by device, inode and size (bounded, cleared with the other caches).Verification
.omo/run/qa-branch.ts(local, not committed) runs real Claude Code 2.1.311 in an isolated herdr session (bun run check run) with herdr's own Claude hook without theforkmatcher, an Ovis server on port 0, and reads/api/pane/conversationafter/branch+ a new prompt. main's code: FAIL, Chat stays at the reply before the branch while herdr reports the old id and the PID record the new one. This branch: PASS, the reply after/branchshows.server/claude-store.test.ts(Chat: after Claude Code's /branch, the chat keeps reading the old transcript and shows no replies #2020 block): following a branch and a branch of a branch fails on main and passes here; controls (same session, no live session, an unbranched session, a branch of another session, a branch in another project, a live session with no file, a torn or oversized first record, an unreadable project beside it) keep the reported transcript.server/claude-session.contract.test.ts: a pane whose herdr report stays on the old session while its PID record moves to the branch shows the branch, and an unrelated session keeps the report; fails on main (16 pass, 1 fail), passes here.bun run check fast: green on 8e5204d (7722 pass). On the final head 0c43433 onlyscripts/ci-browser.test.ts"browser lane" (3 cases) timed out at 5 s with the PC's load at ~155 on 128 threads; the same file fails the same way on origin/main in a clean worktree at that load, and this PR does not touch it. Everything else passed (7720).Remote bundle
The server change is a remote-bundle input. Per docs/development.md the release PR raises
REMOTE_BUNDLE_VERSION(now 38) when the release guards ask; this fix PR does not.Known limits
forkcovers that.