Repository navigation
feat(branch): let the root and the default branch open lines - #1923
Conversation
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
left a comment
There was a problem hiding this comment.
[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 测试。
codoggy
left a comment
There was a problem hiding this comment.
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.
|
Answering reviews 5988258399 and 5988372477. Fixed in An open is ordered with a default-branch move and with an end. The move commits
The tests pause a move after its append and release it later. The load replaces a stale default note once. A Session that made a line the default branch under the previous text keeps a 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 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 |
eric8810
left a comment
There was a problem hiding this comment.
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.
|
Verified fixed in |
codoggy
left a comment
There was a problem hiding this comment.
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.
|
Answering reviews 5988907614 and 5988941704. The red On |
|
Verified fixed in |
codoggy
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
|
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 The fix keeps the tests' ordering assertions and takes each cut from an idle opener: 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 The verify failure was not caused by this PR. The head is 90fb566. Checks on it: the full branch_flow suite, clippy with |
eric8810
left a comment
There was a problem hiding this comment.
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.
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.
createadmits the root in every state and the current default branch while it holds the role; every other line is refusedbranch_not_openerand 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 bycreate, 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_linescarries 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 saysyou 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 saysit can no longer open lines with create,beforeand the rest of the rules above hold again.. The refusalbranch_not_mainwithOnly main opens lines. Tell main if more parallel work is needed.is nowbranch_not_openerwithOnly the root and the default branch open lines. Tell one of them if more parallel work is needed., and a newbranch_limit_reachedanswersThis Session holds its limit of open lines. Continue on this line, or end one of its open lines first.. The tool description's last sentenceA 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 nowA 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
createto a default branch, but a Session that made a line the default under the previous text keeps adefault="true"note that forbids opening, while the tool admits the line'screate. On load, the line the tree reports as the default branch, never the root, also compares the text of its latest livebranch:lineblock with the note this code writes for it, with the counterpart read from the latestbranch/default'sfromthe 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 30the_cap_does_not_count_the_default_branch_or_its_ancestors, case 31a_switch_over_the_cap_closes_nothing, case 32a_former_default_branch_keeps_its_lines_and_opens_none, case 33 and case 35the_cap_is_refused_under_the_tree_lock(the last slot and the reservation that is held before publication), and case 34a_switch_that_frees_a_slot_admits_the_next_open.Case 3's
createrefusal is covered bya_tool_line_still_cannot_open_a_line,a_plugin_line_never_opens_a_lineanda_refused_branch_call_writes_nothing; case 21's note sentences and case 23's open from a line that became the default branch bythe_default_branch_opens_a_lineanda_former_default_branch_keeps_its_lines_and_opens_none; case 3a's second half bya_user_opened_default_branch_coordinates_the_line_it_opens. The two keyed-state flows the roster change left open are covered byan_opener_that_is_not_the_root_keeps_its_identity_and_its_rosteranda_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_resultandan_open_from_the_moving_line_is_refused_once_the_move_settles, witha_paused_build_does_not_hold_the_tree_lockandan_open_admitted_before_a_move_still_standskeeping the guard honest; the load's replacement of a note an older rule set left is covered bya_tool_lines_note_from_older_rules_is_replaced_once_at_loadanda_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 isCountsandCountedTotal, and the charge is the reservation thatCreatespends.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_flow141 passed and 4 ignored;--test flows7 passed;cargo test -p dim-app-server --test transport_flow -- branches:: branch_end:: tree:: fork::28 passed;cargo test -p dim-goal100 passed across its binaries;cargo test -p dim-agent-integration-tests --test prompt_guide17 passed and--test minimal_execution22 passed;cargo clippy --workspace --all-targets --locked -- -D warningsandcargo fmt --all -- --check --config error_on_line_overflow=truepass;cargo run -p xtask -- checkpasses afterxtask graphregeneratedmodules.jsonfor the two new refusal codes whilextask typeschanged nothing. The BranchTool page states the charge and lists the new flows.