Skip to content

fix(chat): trust a /branch's parent only from its own first message, and follow the file checked - #2126

Merged
devswha merged 1 commit into
mainfrom
fix/claude-branch-followups
Oct 28, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/claude-branch-followups

Conversation

@devswha

@devswha devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner

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 fix(chat): follow a Claude Code /branch to the transcript it goes on in #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.

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

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 6f9b80f and e3fd153.

Files selected for processing: 3
  • changelog.d/claude-branch-followups.md
  • server/claude-store.test.ts
  • server/claude-store.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Fixed Chat’s transcript handling after Claude Code’s /branch. Chat now uses the branch’s own opening message and continues following the branch transcript it found, even when another project has a transcript with the same ID.
    • Fixed cases where changes to a branch transcript’s beginning were not reflected, and where unrelated transcript metadata could affect branch handling.

Branch-parent lookup now validates transcript records and cached file contents. Branch resolution follows the transcript located in the current project, including when the parent chain loops back to the live session.

Changes: Claude branch transcript resolution

Layer / File(s) Summary
Validate branch-parent metadata
server/claude-store.ts, server/claude-store.test.ts
Parent lookup accepts metadata only from a matching conversation record. Cached results are checked against file size and head contents, and file invalidation clears the parent cache. Tests cover metadata placement and rewritten transcript contents.
Follow the located branch transcript
server/claude-store.ts, server/claude-store.test.ts, changelog.d/claude-branch-followups.md
Branch resolution reuses the live transcript located in the current project when following a cycle. A regression test covers a same-ID file in another project. The changelog describes the branch transcript selection.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

  • devswha/ovis#2118 — The changes implement the branch-path, conversation-record ancestry, and cache-validation follow-ups described in the issue.
  • devswha/ovis#2020 — The changes follow the new fork through forkedFrom and the located transcript, addressing the reported case where Chat stays on the old transcript.
Merge Risk: Minimal · up to e3fd1

No merge-blocking issue was established; the change is mergeable after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly summarizes the primary changes: validating a branch parent from its own first message and following the verified file.
Description check Passed The description explains the problem, resulting behavior, validation results, related issue, and remaining scope. It uses equivalent headings, "Changes" and "Verification," instead of the template hea…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the problem, resulting behavior, validation results, related issue, and remaining scope. It uses equivalent headings, "Changes" and "Verification," instead of the template headings.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 2 files. (1 skipped: 1 unsupported.)

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • 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 e3fd153: omo-native-code-reviewer and Codex both pass this head, and the required checks are green. CodeRabbit did not review this head. The three new #2118 tests fail on main and pass here. Two pre-existing findings that reproduce on main (the cross-project continuation lookup and escaped JSON keys) and omo's LOW notes go to a follow-up issue.

@devswha
devswha merged commit c5d9555 into main Oct 28, 2026
19 checks passed
@devswha
devswha deleted the fix/claude-branch-followups branch October 28, 2026 02:07
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