Skip to content

feat(branch): let the root and the default branch open lines - #1923

Merged
yyhhyyyyyy merged 11 commits into
mainfrom
hui/branch-openers-cap
Nov 21, 2026
Merged

yyhhyyyyyy merged 11 commits into
mainfrom
hui/branch-openers-cap

Conversation

@yyhhyyyyyy

@yyhhyyyyyy yyhhyyyyyy commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

This PR follows #1914, which gave the roster its own key, and continues the second design of timeline branches: who may open a line, and what an open costs. Refs #1811.

The guard. create admits the root in every state and the current default branch while it holds the role; every other line is refused branch_not_opener and writes nothing, so a plugin line is never an opener and a former default branch keeps the lines it opened and coordinates them but opens none.

The rule is one predicate, can_open, read only by create, and it is evaluated at the reservation rather than before the call: timeline_tree.rs holds one lock over the caller's eligibility, the lines that are open and the reservations, and a move and an end admit in that same order, so a move that lands while a creation is in flight cannot admit a caller the tree no longer has as an opener and cannot let an open be counted against a protected path the move has already left. The lock covers the admission only: it is released as soon as the reservation exists, before the child's build, and the wait for it stops on the call's cancellation. A refused creation writes nothing.

The cap. It is one total over the Session: the tool lines that are still open and off the protected path, which is the current default branch and its ancestors because an end cannot close them, plus the reservations that will become tool lines. It is charged in the lock that reserves the line, so publication charges nothing a second time and a failed creation releases its slot; a caller that only stops waiting keeps its reservation because the build goes on. A switch that leaves the Session over the cap closes nothing and refuses only later opens. BranchToolConfig::max_open_lines carries the number, four by default.

Four is the larger of four and two plus two. 1222 recorded runs of the timeline-branches scenarios were read, counting the tool lines open at once in each run from its creation and end facts: the maximum was two, p50 one, p90 two, p99 two, and 221 runs reached two. The evaluation re-checks the number.

The changed sentences are these. The tool description's - create (main only): is now - create (the root and the current default branch only):. A tool line's identity bullet - Work on this purpose only. You cannot open lines; if more parallel work is needed, tell P. is now - Work on this purpose only. You cannot open lines unless this line is the default branch of the session, and this block does not make it one: a status note would. If more parallel work is needed and you cannot open a line, tell P.. The note a move writes on the new default branch now says you can open lines with create; among the rules that hold while the block is its latest one, for a tool line and for a line the user opened. The note on the former default branch now says it can no longer open lines with create, before and the rest of the rules above hold again.. The refusal branch_not_main with Only main opens lines. Tell main if more parallel work is needed. is now branch_not_opener with Only the root and the default branch open lines. Tell one of them if more parallel work is needed., and a new branch_limit_reached answers This Session holds its limit of open lines. Continue on this line, or end one of its open lines first.. The tool description's last sentence A line reads the line it was cut from; main reads the lines it opened. Messages pass only between main and the lines it opened. is now A line messages and reads the line it was cut from and the lines it opened. The end action ends the calling line only..

A load also replaces a note an older rule set left. The status note now grants create to a default branch, but a Session that made a line the default under the previous text keeps a default="true" note that forbids opening, while the tool admits the line's create. On load, the line the tree reports as the default branch, never the root, also compares the text of its latest live branch:line block with the note this code writes for it, with the counterpart read from the latest branch/default's from the same way the load already reads it, and a difference writes the current note once before the line's next model request. Every other line keeps the role-only comparison: a current-format Session compares equal and writes nothing, and a former default keeps its note, which still states what is true about it.

§20 case 29 is the_root_opens_a_line_while_another_line_is_default, case 30 the_cap_does_not_count_the_default_branch_or_its_ancestors, case 31 a_switch_over_the_cap_closes_nothing, case 32 a_former_default_branch_keeps_its_lines_and_opens_none, case 33 and case 35 the_cap_is_refused_under_the_tree_lock (the last slot and the reservation that is held before publication), and case 34 a_switch_that_frees_a_slot_admits_the_next_open.

Case 3's create refusal is covered by a_tool_line_still_cannot_open_a_line, a_plugin_line_never_opens_a_line and a_refused_branch_call_writes_nothing; case 21's note sentences and case 23's open from a line that became the default branch by the_default_branch_opens_a_line and a_former_default_branch_keeps_its_lines_and_opens_none; case 3a's second half by a_user_opened_default_branch_coordinates_the_line_it_opens. The two keyed-state flows the roster change left open are covered by an_opener_that_is_not_the_root_keeps_its_identity_and_its_roster and a_status_note_and_a_live_roster_do_not_retire_each_other.

An open's order with a move and an end is covered by an_open_after_a_move_waits_and_counts_the_moves_result and an_open_from_the_moving_line_is_refused_once_the_move_settles, with a_paused_build_does_not_hold_the_tree_lock and an_open_admitted_before_a_move_still_stands keeping the guard honest; the load's replacement of a note an older rule set left is covered by a_tool_lines_note_from_older_rules_is_replaced_once_at_load and a_user_lines_note_from_older_rules_is_replaced_once_at_load.

The code's rule matches BranchEligibility.tla as merged: the guard is CanOpen, the counted set is Counts and CountedTotal, and the charge is the reservation that Create spends.

E3 measures a cold restore of a Session whose root and default branch each hold two open tool lines, median of five restores in a release build: 5.3 ms before this change and 4.3 ms after it. It is an ignored measure test, not a CI threshold.

Every changed text was searched for a pinned copy across the repository: none of these sentences is pinned outside the capability's own flows, and the identity assertion compares only the block's factual sentences, before its rules. The load-comparison sentences added to design §5 and to the BranchTool and TimelineTree pages are new text with no other copy. The one pinned structure in the integration suite is the roster guide entry, which the merge carries.

Checks: cargo test -p dim-agent-capabilities --test branch_flow 141 passed and 4 ignored; --test flows 7 passed; cargo test -p dim-app-server --test transport_flow -- branches:: branch_end:: tree:: fork:: 28 passed; cargo test -p dim-goal 100 passed across its binaries; cargo test -p dim-agent-integration-tests --test prompt_guide 17 passed and --test minimal_execution 22 passed; cargo clippy --workspace --all-targets --locked -- -D warnings and cargo fmt --all -- --check --config error_on_line_overflow=true pass; cargo run -p xtask -- check passes after xtask graph regenerated modules.json for the two new refusal codes while xtask types changed nothing. The BranchTool page states the charge and lists the new flows.

The tool's `create` admits the root in every state and the current
default branch while it holds the role; every other line is refused
`branch_not_opener` and writes nothing. A plugin line is never an
opener, and a former default branch keeps the lines it opened and
coordinates them but opens none.

The admission is taken in the lock that reserves the line, so a move
that lands while a creation is in flight cannot admit a caller the tree
no longer has as an opener. The texts that state who opens a line now
name both openers, a status note tells a line taking the role that it
may open lines and a line losing it that it may not, and the tool
description's last sentence states the reach of messages and of `end`.
A create is charged under the lock that reserves its line: the open tool
lines that are not on the protected path, the current default branch and
its ancestors, plus the admitted reservations. Publication charges
nothing a second time, a creation that definitively fails releases its
slot, and a caller that stops waiting keeps it because the build goes
on.
A switch that leaves the Session over the cap closes nothing and refuses
only later opens.

`BranchToolConfig::max_open_lines` carries the cap, four by default, and
`create` refuses `branch_limit_reached` when an open would cross it. The
number comes from 1224 recorded runs of the timeline-branches scenarios,
where the most tool lines open at once was two; the evaluation re-checks
it.
The Session holds the root and the default branch, each with two open
tool lines, and the measure reports the cold restore in milliseconds.
It is ignored and is not a CI threshold.
The BranchTool page now says how `create` is admitted: the caller's
eligibility and the Session's cap are charged in the lock that reserves
the line, and a failed creation releases its slot. Its tests list names
the flows this change adds.
A move writes one note per participant from each line's own writer. The
test counted the notes after only the former default branch's note had
landed, so a slow writer could leave the new default branch's note out.
The wait makes the count deterministic.
Carries the integration fixture for the roster guide entry, which #1914
changes.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 开线配额和默认分支切换没有按持久化顺序串行。 timeline_tree.rs:1826–1863 在 operations 锁内先追加并发布 branch/default,再更新 state.default;create_child:2351–2405 不参与这把锁,只在预留时读 state。例如上限为 1、A 是受保护的默认工具线:在根上先提交 A → main,随后根在切换尚未更新内存时创建 B,预留仍把 A 排除。根日志却会先记切换、再记开 B,换回 main 后的这次新开线应被拒绝。请让开线的决策/预留与默认分支操作共用顺序,且不要在等子线构建时持锁。建议暂停切换的提交/结算再从根开线,断言不会按旧的保护路径计数。

[P2] 升级已有的默认工具线时,模型仍会看到旧的「不能开线」指令。 新的状态说明增加了 you can open lines with create,但 write_load_note(timeline_tree.rs:4614–4620)只比较已存的默认布尔值;旧 default=true 的说明原样保留。此时工具已经允许开线,而仍生效的 branch:line 说明没有覆盖旧的禁止。请补一个从旧版已切换会话恢复的测试,只升级一次旧说明,并保留当前格式恢复不重复写入的性质。

以上为静态复审,未在本地运行 Rust 测试。

@yyhhyyyyyy
yyhhyyyyyy changed the base branch from hui/branch-roster-own-key to main November 20, 2026 06:08

@codoggy codoggy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings

[Blocking] Serialize opener admission with a default-branch move

When the tool-line cap is one and tool line A is the default, crates/dim-agent-capabilities/src/timeline_tree.rs:2351–2405 can reserve a new line B using the old protected path even after the root has recorded A → main. After settlement, A and B both count against the cap. The new creation, not the move itself, is what should have been refused.

Evidence: Static inspection: the move at timeline_tree.rs:1826–1863 holds operations, appends branch/default and awaits publication before updating state.default. The creator takes only the state lock for its eligibility check and reservation. The sequential switch-then-create test does not exercise the interval between append and settlement.

Requested change: Order the opener check and reservation with default-move settlement, without holding the guard while waiting for the child to build. Add a regression that pauses a move after its append and verifies the subsequent root creation respects the new protected path.

[Blocking] Refresh the old default tool line’s instructions on restore

When a session saved before this change restores a tool line that was already default, crates/dim-agent-capabilities/src/timeline_tree.rs:4614–4622 skips rewriting its branch:line note because the recorded default flag is already true. The tool now permits creation, but the active instruction still tells the model it cannot open a line.

Evidence: Static inspection: the merge-base text at timeline_tree.rs:5665 unconditionally forbade the tool line from opening lines. This head’s note at :5794–5803 permits a default opener, but the restore check compares the role flag rather than whether the old instruction matches. Tests not run locally.

Requested change: Replace a legacy default note once under the same key. Restore a session with the old note, assert the new permission is visible, then restore again and assert no duplicate note is written.

create_child takes the tree's operations guard for its admission: the
opener check, the cap, the branch/create append and the reservation. A
move or an end that already holds the guard has applied its state, so
an open no longer counts a protected path a committed move has left,
and the opener it reads is the one the tree has after the move.

The guard is released as soon as the reservation exists, before the
child's build, and the wait for it stops on the call's cancellation
(design §6.1, §14).

The tests pause a move after its append: the root's open answers
branch_limit_reached once the move settles, and the moving line's open
answers branch_not_opener. A paused build does not keep a later move
from settling, and an open admitted before a move still stands while
the Session is over the cap.
write_load_note compared only the role a line's latest branch:line block
states. The note now grants create to the default branch, so a Session
that made a line the default under the previous text keeps a note that
forbids opening while the tool admits the line's create.

The line the tree reports as the default branch, never the root, also
compares that block's text with the note this code writes for it, with
the counterpart read from the latest branch/default's from as the load
already reads it. A difference writes the current note once before the
line's next model request, and a load that finds them equal writes
nothing (design §5).

The tests store the older text byte for byte as the previous code writes
it, for a tool line and for a line the user opened, and assert one
replacement before the first request and none on a second load.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

Answering reviews 5988258399 and 5988372477. Fixed in 93a7af630f99b0ff0c4d289ef6377eb692371ceb for the ordering and c5928e75cc6dc9431f3dd8cafd6d67dcb66bc673 for the load note.

An open is ordered with a default-branch move and with an end. The move commits branch/default, waits for its publication and updates the tree's default under the tree lock, and a tool end marks its line ended under that same lock, while create checked the opener, counted the cap and took its reservation under the state lock alone. A create that ran while a move was between its fact and its update therefore read the old protected path: with a cap of one and the protected tool line A, the root's open was admitted beside A → main although the log records the move first. Design §6.1 and §14 make those one order: one lock covers the caller's eligibility, the open tool lines and the admitted reservations, and a move and an end admit in one order with them.

create now takes that lock for its admission only: the opener check, the cap, the branch/create append and the reservation. It releases the lock as soon as the reservation exists, before the child's build, and the wait for the lock stops on the call's cancellation. I audited every holder of that lock for a cycle and found none: the move's settling task awaits one store commit and one state update, the end gives the lock up before it waits for its line's turn to stop, and nothing on either path calls into an open.

The tests pause a move after its append and release it later. an_open_after_a_move_waits_and_counts_the_moves_result calls the root's create during A → main and asserts that it answers branch_limit_reached and writes nothing once the move settles. an_open_from_the_moving_line_is_refused_once_the_move_settles does the same from the moving line and asserts branch_not_opener. a_paused_build_does_not_hold_the_tree_lock pauses a child after its reservation and asserts that a later move still settles, and an_open_admitted_before_a_move_still_stands keeps case 31's rule that a move closes nothing. The first two fail on 9a97081a4ddacaa800fe743eafb0e5ef86e23e63, where the open succeeds and no refusal is written, and all four pass on 93a7af630f99b0ff0c4d289ef6377eb692371ceb.

The load replaces a stale default note once. A Session that made a line the default branch under the previous text keeps a default="true" note that says the line cannot open lines, while the tool now admits its create. write_load_note compared the role only, so the load left that note in place. Design §5 keeps the role comparison for every line and adds one thing for the line the tree reports as the default branch, never the root: the text of its latest live branch:line block is compared with the note this code writes for it, with the counterpart read from the latest branch/default's from the way case 24a already reads it, and a difference writes the current note once, before the line's next model request. A current-format Session compares equal and writes nothing, and a former default keeps its note, which still states what is true about it.

The two tests store the older text byte for byte as the previous code writes it, for a tool line and for a line the user opened. Each restores that Session, asserts that the line gains exactly one note on the same key that says you can open lines with create, that it is the line's latest branch:line block before its first request and that the request carries it, then restores a second time and asserts that no note is added. Both fail on 9a97081a4ddacaa800fe743eafb0e5ef86e23e63, where the restored line keeps the old note and gains none, and both pass on c5928e75cc6dc9431f3dd8cafd6d67dcb66bc673. a_clean_restart_writes_no_status_note, the main → B → C → D clean restart and case 24a still pass.

Design §5's load paragraph and the BranchTool and TimelineTree pages state both rules.

Checks: the branch flow suite reports 141 passed and 4 ignored; flows 7 passed; the prompt guide reports 17 passed; transport flow 28 passed; dim-goal 100 passed; workspace Clippy, formatting and xtask check are clean.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at head c5928e7.

The rule is where the design puts it and has the shape a guard should have: one predicate, can_open(state, line) — the root, or the line that currently holds the default role — read by create and by nothing else, with every other line refused branch_not_opener and no event written for the refusal. Keeping it in the same TreeState as default is what makes "while it holds the role" a fact about a single locked snapshot rather than a second lookup that could disagree with the move; evaluating it at the reservation, under the lock that also holds the open lines and reservations, is what stops a concurrent default move from landing between an eligibility check and the charge.

That a former default branch keeps the lines it opened but opens none is the consequence of the same predicate, and it reads correctly: coordination rights survive the role, opener rights do not. Charging counted_tool_lines against tool lines while exempting the default and its ancestors is the same distinction carried into accounting, so the cap cannot be spent by the lines that keep the tree reachable.

verify and ci-ok failed on this head, at the architecture check and before any test ran:

web/src/chat-ui/WebChatTimeline.vue:34: `"main"` names neither the root nor the default branch;
  write `ROOT_BRANCH_ID` or `DEFAULT_BRANCH_ID`, or name the use in `UNRELATED`
web/src/chat-ui/WebChatTimeline.vue:328: same

That is main's file — variant?: "main" | "panel" at line 34, a render variant — not this PR's. It is the repository-wide red I described on #1920, #1881 and #1937; main has had no green run since 574861f3, so every branch including it inherits this. Renaming the variant is the smallest fix and needs no UNRELATED entry.

Not approving while a required check is red.

Non-blocking: none.

@codoggy

codoggy commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Verified fixed in c5928e75cc6dc9431f3dd8cafd6d67dcb66bc673. At crates/dim-agent-capabilities/src/timeline_tree.rs:2354–2419, 93a7af63 puts the opener check, cap and reservation under the same lock as default-move settlement, then releases it before waiting for the child; an open can no longer use the old protected path during a move. At timeline_tree.rs:4628–4660, restore compares the current default’s live note text and rewrites a stale note under the same key, so the next restore leaves it alone. Static inspection of the regressions cited in your reply confirmed they cover the paused move, first-request visibility and second-restore idempotence; CI stopped before workspace tests. Tests not run locally.

@codoggy codoggy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary

I reviewed the merge-base diff for c5928e75cc6dc9431f3dd8cafd6d67dcb66bc673, focusing on who may open a line, how a reservation is counted when the default moves, and what instructions a restored line sees. I found no blocking issues in that scope.

Checks: Static inspection: eligibility and the cap are checked at reservation, before releasing the tree lock; the child build does not hold that lock. I traced the refusal paths and checked the regressions for a paused move, a paused child build, and restoring a legacy default note twice. Both findings from my previous review are addressed. CI: PR verify passed Rust build/lint and the service catalog, then stopped on two layout literals in WebChatTimeline.vue; the earlier main run reported the same diagnostics. Neither the component nor its literal checker changed in this diff. Compiled workspace tests were skipped and ci-ok failed. Tests not run locally.

@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

Answering reviews 5988907614 and 5988941704.

The red verify on c5928e75cc6dc9431f3dd8cafd6d67dcb66bc673 came from main's own web/src/chat-ui/WebChatTimeline.vue, which #1924 fixed. This branch now carries a merge of main at 68043df9b46b113e631ef7a6c4c57de1470a5b4e, which includes #1924, as 1e74653f0c1e509e65649ab9599d968623a87706. The merge is git's automatic one: no file was resolved by hand, the generated graph regenerated without a change, and no code in this pull request changed.

On 1e74653f0c1e509e65649ab9599d968623a87706 the architecture check passes, with the literal main rule covering WebChatTimeline.vue, and the branch flows, transport flows, Clippy and formatting pass. CI is running on the new head.

@codoggy

codoggy commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Verified fixed in 1e74653f0c1e509e65649ab9599d968623a87706. At xtask/src/literal_main.rs:101–111, the two layout exceptions now match WebChatTimeline.vue at its new path without allowing branch-ID literals elsewhere in the component. Static inspection confirms the correction described in your reply is in the merge; the current verify job had not completed when I checked. Tests not run locally.

@codoggy codoggy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary

I reviewed the merge-base diff for 1e74653f0c1e509e65649ab9599d968623a87706, focusing on who may open a line during a default-branch move and which instructions a restored default sees. I found no blocking issues in that scope.

Checks: Static inspection: opener eligibility, cap accounting and reservation use the same lock as a default move; child construction happens after release. Restore replaces a legacy default note under its original key. The regression tests cover a paused move, a paused child build, the first request after restore and a second restore without a duplicate note. Both earlier fixes remain present after the merge. CI: changes and dependencies passed; verify had no completed result when checked. Tests not run locally.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at head 1e74653.

The code is unchanged from the head I reviewed at c5928e75 — timeline_tree.rs, branch_flow.rs and error.rs are byte-identical — so the guard I read there stands: one predicate, can_open = root or the current default, read only by create, evaluated at the reservation under the lock that also holds the open lines, with every other line refused branch_not_opener and no event written.

The only delta is a note at the top of timeline-branches.md saying the runtime Session tree binding moves calls from treeCommands to timelineTree with the same arguments and replies, and that references to treeCommands below describe the pre-migration binding. That is the right way to keep a design document honest while a rename lands elsewhere: it states the mapping once, at the point a reader meets the old name, instead of rewriting every reference into a term whose contract the document does not own.

Its ancestor commit is also worth noting as good practice: "replace a default branch's stale note at load" — the note is a derived fact, and replacing rather than appending it at load is what keeps a replay from accumulating one per load.

Blocking: none.

Checks are green at this head. I read the file-level delta and confirmed the three code files are identical to the reviewed head; I did not re-read the whole PR, the new commit's contents beyond the doc note, or run anything.

Non-blocking: none.

@codoggy codoggy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary

I reviewed the merge-base diff for 17a8baa677fd30b6de74923424c3fab5b3cf0732 against 44af122ca04085c35c8b975b0b673c10db813d9f. I found no new blocking issues in this PR.

The tool-line admission at crates/dim-agent-capabilities/src/timeline_tree.rs:2354-2420 checks opener eligibility and the cap, then reserves the line under the same lock that orders default-branch moves, releasing the lock before waiting for the child build. The restore path at crates/dim-agent-capabilities/src/timeline_tree.rs:4628-4660 replaces stale default-branch instructions under the same branch:line key. The added regressions cover opening during a move, moving during a paused child build, and idempotent restore behavior.

Checks: On this exact head, GitHub reported changes and dependencies passed; web, windows-cli, and acp-registry were skipped, and verify was still queued. Static review only; I did not run the build or tests locally.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at head 17a8baa.

The delta since the head I approved at 1e74653f does not touch this PR's code: timeline_tree.rs, branch_flow.rs and error.rs are absent from it, and what moved is main merged in (ADR 026, the module-graph change, the Web chat-ui work). The guard I read there stands — one predicate, can_open = root or current default, read only by create at the reservation under the lock that holds the open lines, with every other line refused branch_not_opener and no event written.

verify and ci-ok failed on this head, in a test that is not this PR's and not an assertion about it:

crates/dim-app-server/tests/transport_flow.rs:344
fork::fork_checks_rest_points_without_scanning_completed_history
  deadline waiting for response 7: deadline has elapsed
  (creating a product Session parses the bundled model catalog, about 10 s in an unoptimized build)

That is the response deadline being hit while a product Session is built — a timing failure under a loaded runner, not a rest-point or opener mismatch. The scenario_eval::tests::eval_server_child panics in the same job are the failing-child hook panicking on purpose, with the surrounding tests reporting ok, so I did not count them.

Not approving while a required check is red, and not treating this red as a reason to re-read code that did not change.

Non-blocking: none.

The root and moving-line tests took the opener's head as the cut while the opener could still be in a turn, so the cut could fall inside an unfinished model output and the open was refused before it reached the tree lock. Take the cut while the opener is idle, before the turns the test starts, and pin the inherited prefix at the child's own branch/start instead of comparing the child's own sequences against the cut.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

This follow-up fixes the three tests this PR adds that failed intermittently under load, and records why the verify run was red.

The failure was the test's cut, not the ordering: each test read session.sequence(opener) as the position to open at while the opener could still be in a turn, so the position could point inside an unfinished model output. The open was then refused at history.rs:891 ("branch position is inside an unfinished model output") before it reached the tree lock, which is why the first poll answered while the move was still held. In the captured runs the opener was running a turn started by the idle notice of the line the test had opened: timeline_tree.rs:4387 writes the notice to the opener with InputMode::Steer, and the Loop starts the turn at agent_loop.rs:227 and agent_loop.rs:246.

The fix keeps the tests' ordering assertions and takes each cut from an idle opener: idle_cut waits for the branch to be idle and then reads its head (branch_flow.rs:12140), and the root test runs one completed turn first so the cut is a real prefix with history. A cut taken while the opener is idle is a committed batch boundary, so a later turn cannot split it; the open still waits for the held move and counts its result. The root test's prefix check now pins the inherited prefix at C's own branch/start instead of comparing C's own sequence numbers against the cut.

I proved this without stress runs. A local, uncommitted seam held the opener's request that follows a successful create, so the opener had an unfinished model output exactly when the old tests took their cut. The three tests failed deterministically on 17a8baa with the refusal above; with the fix and the same seam they pass. The sibling test an_open_from_the_moving_line_is_refused_once_the_move_settles was checked the same way: its cut is on the moving line, whose only later writes are appends, so it is not exposed and is unchanged.

The verify failure was not caused by this PR. fork::fork_checks_rest_points_without_scanning_completed_history is slow on an unloaded machine: 21.1 s, 10.8 s and 11.6 s on this head, and 26.0 s at the PR merge-base 44af122, against the harness's 30 s response bound (transport_flow.rs:344); runner load takes it over. This PR changes no app-server code and no fork path, so that test is recorded as a known slow flake rather than a defect here.

The head is 90fb566. Checks on it: the full branch_flow suite, clippy with -D warnings, cargo fmt --check with error_on_line_overflow, xtask check, and the fork test above.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at head 90fb566.

The guard is unchanged: timeline_tree.rs is byte-identical to the head I approved, so can_open still admits the root and the current default and refuses every other line without writing an event, evaluated at the reservation under one lock.

The one commit since is a test change worth naming as a fix rather than a loosened assertion: idle_cut now waits for the line to be idle and then reads its sequence, so the cut the test takes ends a committed batch. Before, it read the sequence directly and could land the cut inside an unfinished model output — the assertion then failed on a boundary the mechanism does not promise. Waiting on the owner's own idle and taking the position after it is the same pattern as the other race repairs in this repository: derive the value from the state, do not guess the moment.

verify (linux) failed on this head with three TUI cases:

crates/dimcode/tests/cli_flow.rs:3942
goal::tui_goal_shows_the_state_and_marks_the_status_area
repicking_the_current_model_keeps_the_effort
tui_models_picker_edits_only_the_subagent_model_policy
  Terminal did not show "test / model" / "test / model · high" / …

All three are the model-picker frame assertions, 697 passed and 3 failed, and none of them touches branch opening. The terminal dump shows the alternate-screen setup and a status line but not the model text, which reads as the TUI render racing its own startup under a loaded Linux runner — the same class as the frame and deadline failures I have recorded on other heads this week, not a regression this PR can fix.

Not approving while a required check is red.

Non-blocking: none.

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.

3 participants