Skip to content

fix(chat): follow a Claude Code /branch to the transcript it goes on in - #2099

Merged
devswha merged 4 commits into
mainfrom
fix/claude-branch-transcript
Oct 28, 2026
Merged

devswha merged 4 commits into
mainfrom
fix/claude-branch-transcript

Conversation

@devswha

@devswha devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Fixes #2020. Reported by @Hyd3-14.

Problem

After Claude Code's /branch, Chat kept reading the transcript the branch was copied from: the /branch bubble 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 isolated CLAUDE_CONFIG_DIR):

  • writes a new <new>.jsonl in the same project folder; each copied record carries forkedFrom: {sessionId: <old>, messageUuid} (after message, so a long first prompt pushes it far into the line); records after the branch have none;
  • rewrites its PID record sessions/<pid>.json to the new session at once;
  • fires SessionStart with source fork. A herdr Claude hook whose SessionStart matcher lacks fork (an older install; this PC's v10 install has it) keeps herdr's report on the old session, and Ovis prefers herdr's report;
  • the old transcript gets only metadata. After /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.ts claudeTranscriptFile(…, live): follow herdr's session and its continued-in chain as before; then take live'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 /resume back, 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

  • Real surface: .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 the fork matcher, an Ovis server on port 0, and reads /api/pane/conversation after /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 /branch shows.
  • 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 only scripts/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).
  • Reviews: omo-native-code-reviewer PASS (five LOW; the error path and the oversized-head cache are fixed, the contract test now restores its PID record). Codex Sol 6.1 Fast xhigh: one MEDIUM on the first head (an unrelated unreadable project made the optional lookup throw), reproduced, fixed in 1face9a with a regression test; the delta re-review confirmed that fix and raised a new MEDIUM against a cache added in f9a3616 (a remembered miss could outlive a transcript recreated on the same inode); 0c43433 drops that cache, so the store code is that of the round that passed.

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

  • A first prompt over 1 MiB, or more than 8 nested branches, keeps the reported transcript (terminal stays truthful).
  • A pane with no PID record (an older Claude, or a platform without one) cannot see the branch until herdr reports it; a herdr Claude integration whose matcher includes fork covers that.

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.
@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 65ffea6 and 0c43433.

Files selected for processing: 5
  • changelog.d/claude-branch-transcript.md
  • server/claude-session.contract.test.ts
  • server/claude-store.test.ts
  • server/claude-store.ts
  • server/conversation.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

CI notes for 0c43433 (run 40606595745), for the merge pass:

  • Attempt 1: Fast checks failed only in server/codex.test.ts "Codex rollout resolution > reads short answers in bounded time however many links a large answer has" (1186 ms against a 1000 ms bound); Integration tests failed only in server/pending-input.contract.test.ts "a create request's first message > is bound to the agent process it was queued under …" (first_message_launch_ended instead of pending_target_changed after the test SIGKILLs the process). Neither touches this PR's path (claudeTranscriptPath / claudeTranscriptFile); the pending-input file passed locally on the isolated herdr (100 pass).
  • Attempt 2 (failed jobs only): Fast checks passed; Integration tests failed in two other cases, server/opencode.contract.test.ts "OpenCode v2 native service > refuses a confirmed Tab agent switch during immediate/queue delivery without Enter". Both pass locally on the isolated herdr (bun run check run bun test ./server/opencode.contract.test.ts -t "Tab agent switch": 2 pass).
  • Each attempt failed in different, untouched tests while the P620 runner host was at a load of ~100-150; attempt 3 of the failed jobs is running.

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.

@devswha

devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

Attempt 3 of the failed jobs passed: every check on 0c43433 is green now (run 40606595745).

@devswha

devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

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.

@devswha
devswha merged commit 817f238 into main Oct 28, 2026
32 of 37 checks passed
@devswha
devswha deleted the fix/claude-branch-transcript branch October 28, 2026 01:02
devswha added a commit that referenced this pull request Oct 28, 2026
… 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.
devswha added a commit that referenced this pull request Oct 28, 2026
…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
devswha added a commit that referenced this pull request Oct 28, 2026
…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.
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.

Chat: after Claude Code's /branch, the chat keeps reading the old transcript and shows no replies

1 participant