Repository navigation
fix(chat): trust a /branch's parent only from its own first message, and follow the file checked - #2126
Conversation
…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
|
No actionable comments were generated in the recent review.
|
| 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:
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 throughforkedFromand 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: 
5
-
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.
Comment @coderabbitai help to get the list of available commands.
|
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. |
… 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
Part of #2118 (follow-ups from the merge pass's review of #2099): items 1-3.
Changes (
server/claude-store.ts)continued-infollow 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.branchedFromskips metadata (file-history-snapshotand the like) and decides on the first user or assistant record, and only when that record'ssessionIdis the file's own. Before, a metadata line carryingforkedFrom, 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 andforkedFrom.sessionId, so real branches are still followed.forgetClaudeSessionFiledrops 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 spawnspson 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..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/conversationshows 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.forgetClaudeSessionFileuntil evicted, and the pre-existing cwd preference when followingcontinued-in), Codex Sol 6.1 Fast xhigh PASS with no findings.