Repository navigation
feat(appserver): route the Session's defaults to the default branch - #1917
Conversation
The user's entry to the default branch, and the id the directory reports
beside its lines.
`session.branch_set_default {sessionId, branchId}` is a v3 built-in listed
in `hello.features` under the same admission as `session.branch_end`. It
calls the tree's `set_default_branch` with a user source, answers the new
`defaultBranchId`, and lets the tree's refusals reach the client unchanged:
`branch_already_default`, `branch_not_selectable`,
`branch_target_protected`, `branch_ended` for a line that ended, and
`session_invalid_input` for a line the Session does not have. A refusal
writes nothing (design §14, §20.21).
`session.branches` carries one top-level `defaultBranchId`, read from the
tree's directory: a row cannot express zero or two default branches
(design §14, §20.17).
Every Session-level target that named the root reads the line the fact names, once per request, so a move cannot split one call across two lines. `session.submit`, `session.stop` and `session.idle` resolve an absent `branchId` to it; a v3 caller may omit the line, while v1 keeps it absent and v2 keeps it required, so neither frozen encoding changes meaning. `session.model.update`, `session.agent.update` and `session.prompt.refresh` act on the line they name, and on the default branch when they name none, instead of refusing every line but the root. The catalog's live running state, the attach record and a summary's newest activity follow it, while the preview stays on the root (design §9, §15, §20.22, §20.23). PromptSuggestion folds that line's turn and asks it for the compaction check, Goal resolves an absent branch to it, ShellInput's `!` run belongs to it, and a report's snapshot records the line it read so its plan reads the same one (design §15).
A member is a Session like any other: its own defaults follow its own default branch, not the leader's. The leader's message and stops, the working state it reads, the idle wait that settles a request, and the reads a report makes of the member's conversation all address the line the member's conversation is on (design §9, §15).
`sessions.defaultBranchId {sessionId}` answers the line the Session's
conversation is on: it acquires the Session, reads the tree's current
default from its owner and returns it as `{defaultBranchId}`. It reads
no history page, and an idle-unloaded Session is restored for the
answer like every read except `exists`.
The read exists for requests that name a Session but no line: a
management `schedule.save` that records a new job's branch, and the
`loops`, `wakeups` and EventHub faces. It is documented as §6.11 of the
sessions service, in both languages.
A management `schedule.save` whose session target omits `branch_id` records the Session's current default branch at save time, through the new `sessions.defaultBranchId` read. A stored row that omits it was written before the rule and still means the root, and an update keeps its recorded target. The same read resolves every request-side absence the design left on the root: `session.loop.start`, `session.loop.list` and `session.wakeup.list`, the `loops` and `wakeups` faces' list requests, EventHub's subscription target and a publish's `to` targets. Each is resolved once per request, and a failed read answers the sessions code without writing anything. Tests: a new job keeps a line after a move while a stored row still reaches the root; a loop started without `branchId` delivers its round to the line; a publish `to` entry and a subscription with no branch reach it. Each fails with the read reverted to the root. Design: Scheduler §2.1, §10.2, §12.6, A.1, A.3 and Appendix C, and EventHub §2.3 and A.2, in both languages. `npm/plugin.d.ts` names the new read and the resolved defaults; the generated catalog and module graph follow.
eric8810
left a comment
There was a problem hiding this comment.
这次把显式 branchId 和缺省目标分开,并让审批继续回到发起它的分支,方向对。但默认分支切换现在就能从 RPC 调用,下面三处还不能等客户端后续再修:
-
[P2]
session.attach.sequence换了分支,现有 CLI 仍当它是main的游标。agents.rs:1119–1131回默认分支的本地序号;dim-cli/src/session_host.rs:1005–1011将它写进main的历史窗口,之后只遍历目录的行,不会修正这个截止点。根已到 100、默认子线只有 20 时,重新 attach 会用 20 请求根历史,漏掉根的 21–100;反过来把子线较大的序号当作根的模型更新水位,也会忽略根的后续更新(session_host.rs:4687–4690)。保留现有字段的根分支语义,再给新客户端一个带 branch ID 的新游标,或把客户端迁移与开关一起交付。请用两个不同的分支序号验证兼容路径。 -
[P2] 切换默认分支不清掉上一条线的 PromptSuggestion。
prompt_suggestion.rs:771–848只过滤未来事件,不处理branch/default,而decision()/run()仍使用同一个缓存和 flight。A 完成后开始生成建议、切换到尚未开始新回合的 B,再让 A 的建议返回,仍会发布 A 的 offer;也能拿 A 的 turnId 请求建议,同时拿 B 的 compaction 状态做检查。应在默认分支变更时取消旧 flight、清除旧 offer,并使请求、预检和完成都绑定同一个分支。用现有 completion gate 覆盖切换后才返回的建议。 -
[P2] EventHub 在校验调用者之前恢复目标 Session。
publish.rs:119–146先解析缺失的分支,之后才检查进程暂停、source 所有权和 type,而sessions.defaultBranchId会恢复冷 Session(agents/sessions.rs:638–649)。一个本该被拒绝的 publish 因此能先触发恢复,甚至返回目标 Session 的错误。先完成 admission 和 source/type 校验,再按请求解析一次;冷读取也应受现有并发预算约束。
以上是静态路径核对,未本地跑 Rust 测试。
zerob13
left a comment
There was a problem hiding this comment.
Reviewed 8c066bfb71db9fd654a4ee8bc59c5bc84695676f against 31d100f458f919605c22bfe8b50158697de17c81. The four inline findings are from static inspection of this revision.
| // §9, §20.22). | ||
| let branch = match params.branch_id { | ||
| Some(branch) => branch, | ||
| None => session.default_branch().map_err(RpcError::from)?, |
There was a problem hiding this comment.
[P2] Preserve the v1 submit target across a default-branch move. A newer connection can use a Session created by v1 and move its default. The older connection must omit branchId, so this fallback can accept the submit on a side branch whose turn events the v1 stream filters out. Please preserve the observable v1 behavior and cover a v1-created Session used by both protocol versions. Version admission · v1 event projection
There was a problem hiding this comment.
Fixed in 1ec5c4bdc72a9e90cbdfb7c6eb71e3fee7ab0f0b: a connection whose event projection carries the root alone (v1) now resolves an omitted branchId to the root for session.submit, session.stop and session.idle, so a Session created by v1 keeps running its unnamed calls on the root after a newer connection moves the default, and the v1 stream still shows the turn's output. Covered by default_branch::a_v1_submit_stays_on_the_root_after_a_switch.
| params: Branches, | ||
| ) -> Result<Reply, RpcError> { | ||
| let session = self.session(rpc, ¶ms.session_id)?; | ||
| let default_branch_id = session.default_branch().map_err(RpcError::from)?; |
There was a problem hiding this comment.
[P2] Read the default branch and directory rows from one tree snapshot. The two reads acquire the tree lock separately. If a switch and the ending of the former default occur between them, the result can mark an ending or ended row as the current default. Capture the default ID alongside the directory's identity and lifecycle fields under the same lock. Tree directory reads
There was a problem hiding this comment.
Fixed in c8a9d0788cf4c7d10282b55be0e2ed804f8d7f9c: session.branches takes the default id and the rows' identities and lifecycle states under one tree lock, through the tree's new default_and_directory(), so a switch and the ending of the former default are either wholly in the answer or wholly out of it and the advertised default is always open in the directory the answer carries. Covered by default_branch::a_branches_read_advertises_an_open_default, which holds the read before its snapshot, moves the default away and ends the former default, then asserts the advertised default is open.
| ) -> Result<Reply, RpcError> { | ||
| let session = self.session(rpc, ¶ms.session_id)?; | ||
| let default_branch_id = session | ||
| .set_default_branch( |
There was a problem hiding this comment.
[P2] Refresh catalog recency when the default branch moves. The writer selects the new default for activity writes, but it updates updated_at_ms only for a batch containing activity on that branch. The switch fact and its host-generated status notes do not qualify. After switching between idle branches with different activity timestamps, the stored catalog and summaries can retain the old branch's time until the new branch next records activity. Refresh the activity projection in the switch transaction and check the timestamp immediately after switching. Catalog write · Activity predicate
There was a problem hiding this comment.
Fixed in 5d4c39112867d443b1c258a20900ac502432f8f2: the writer refreshes the catalog's updated_at_ms in the same transaction that records branch/default, from the new default's own latest activity through the same predicate the catalog query uses, one indexed read and never a scan; the switch itself is not activity. Covered by default_branch::a_switch_republishes_the_new_defaults_activity, which switches between two idle lines with different activity times and checks the stored updatedAt immediately after each move.
| let this = self.clone(); | ||
| let branch_id = branch_id.to_owned(); | ||
| branch.tasks.spawn(async move { | ||
| let Ok(line) = session.default_branch() else { |
There was a problem hiding this comment.
[P2] Keep an in-flight Collaboration request on its delivery branch. The request queues input on the member branch selected at delivery. The idle wait reads the member's default again, and settlement and targeted cancellation repeat that read. A move can make settlement use a cutoff from another branch or make cancellation wait for an input on a branch that never held it. Carry the selected member branch with the input ID through wait, settlement, and cancellation. Input delivery · Settlement · Cancellation
There was a problem hiding this comment.
Fixed in 898681690e6b7f2df77ff21a06d2ed99aa0b54da: the request stores the member branch chosen at delivery and reuses it for the idle wait, settlement, withdrawal and every stop, and a collaboration read page names the branch it read while a continuation carries it and a bare after is refused. Covered by collaboration::a_request_completes_from_the_line_its_input_was_delivered_to, collaboration::a_cancel_stops_the_line_the_request_was_delivered_to and collaboration::a_read_continuation_stays_on_the_branch_its_page_read.
codoggy
left a comment
There was a problem hiding this comment.
Findings
[Blocking] Keep a v1 submit on the branch its client can observe
When a v3 connection moves the default of a session created by v1, crates/dim-app-server/src/connection/tree.rs:40–44 routes the next v1 submit to the side branch. That client can receive a successful submit without seeing the turn’s output.
Evidence: Static inspection: v1 must omit branchId, and a newer connection is allowed to use the older session (connection.rs:826–839,884–896). The v1 event projection still filters ordinary events to the root (connection/subscription.rs:371–379). The compatibility test at tests/transport_flow/default_branch.rs:567–607 uses v2 and an explicit main, which avoids this case.
Requested change: Preserve root routing for v1 calls that cannot name a branch. Test a v1-created session shared with v3: after v3 moves the default, a v1 submit must still produce a turn visible to v1.
[Blocking] Do not put a child’s sequence into the CLI’s root history window
When a user reattaches with a shorter child as default, crates/dim-app-server/src/agents.rs:1119–1132 returns the child’s sequence in the existing attach field. The CLI uses it as the root transcript cutoff: a child at 20 and a root at 100 give the root window a cutoff of 20, hiding events 21–100 from that read.
Evidence: Static inspection: crates/dim-cli/src/session_host.rs:1005–1029 stores the number on the main window and then processes directory entries without correcting that cutoff. The CLI also uses it as the root model-update watermark (:976,4685–4692), so a longer child can suppress valid root configuration updates.
Requested change: Keep the legacy root cutoff and add a branch-qualified default cursor, or migrate the consumer and protocol together. Cover reattach with unequal branch lengths in both directions.
[Blocking] Keep an in-flight collaboration request on its delivery branch
When a member changes its default after receiving an input, crates/dim-app-server/src/collaboration.rs:2334–2342,2381–2388,2475–2485 resolves the default again for idle, settlement and cancellation. The leader can receive the wrong result or wait for cancellation on a branch that never held the input while the original turn continues.
Evidence: Static inspection: delivery at collaboration.rs:2218–2224 writes to the branch selected at that time. Later operations retain the input ID, but pair it with the newly selected branch.
Requested change: Store the member’s delivery branch with the input ID and reuse it for idle, result lookup, withdrawal and stop. Test both completion and cancellation after a default switch.
[Blocking] Bind collaboration continuation cursors to the original branch
When a caller requests page two after a default switch, crates/dim-app-server/src/collaboration.rs:1473–1495 applies the first branch’s after to the second branch. An overlapping sequence can silently skip the beginning of the second line; a cursor beyond its head cannot continue the original read.
Evidence: Static inspection: the branch is pinned within a single read_page call, but the result at :1643–1647 returns only a numeric nextCursor and the next call resolves the default afresh.
Requested change: Bind the continuation to the original branch or detect a branch mismatch and explicitly require a fresh read. Test a switch between two pages with overlapping sequence numbers.
[Blocking] Invalidate prompt suggestions from the previous default
When a tool branch finishes a text turn and the user switches back to an idle root, crates/dim-agent-capabilities/src/prompt_suggestion.rs:771–789 filters future events but does not clear the previous branch’s suggestion state. A request for the old turn can still use its cached content in the new conversation.
Evidence: Static inspection: suggestion admission at prompt_suggestion.rs:1073–1104 consults the cached turn/call/content, while compaction is checked against the current default. No new root input is required between the switch and the request.
Requested change: Associate the cached turn, offer and in-flight generation with a branch. Invalidate them on a switch and verify the branch again before publishing. Test switching to an idle root before the old request completes.
[Blocking] Refresh catalog recency when an idle default changes
When the default moves from a recently active child back to an idle root, the switch at crates/dim-app-server/src/connection/tree.rs:595–609 can leave the persisted catalog ordered by the child’s last activity until another qualifying event arrives.
Evidence: Static inspection: storage/timeline.rs:2184–2199 updates updated_at_ms only for activity in the current batch. storage/catalog.rs:48–62 excludes both the switch and host-only notes. The new catalog test (tests/transport_flow/default_branch.rs:485–502) checks running on the move back, not updatedAt before further activity.
Requested change: On a persisted switch, project the new default’s existing last activity into the catalog in the same transaction; do not count the switch as activity. Check the timestamp immediately after a switch between two idle branches.
[Blocking] Preserve the catalog cursor across idle unload
When a session with a non-root default is unloaded, crates/dim-app-server/src/agents.rs:1065–1084 stops overriding the persisted row with the default branch’s sequence. The returned sequence can change even though neither branch received an event.
Evidence: Static inspection: the cold query in crates/dim-app-server/src/storage/catalog.rs:269–278,325–332 takes its sequence from main; the loaded overlay takes it from session.sequence(&default).
Requested change: Use the same branch identity for the loaded and persisted projections without restoring sessions to list them. Test the same catalog row before and after unload with different root and default heads.
[Blocking] Return a default and directory from the same tree snapshot
When another call changes the default and then ends the former default, crates/dim-app-server/src/connection/tree.rs:545–550 can return the old default ID alongside a directory that already marks that branch as ended. A client can select a branch that cannot accept input.
Evidence: Static inspection: crates/dim-agent-capabilities/src/timeline_tree.rs:2823–2825,2846–2875 takes separate locks for the default ID and the rows’ identities and lifecycle states.
Requested change: Capture the default ID together with the directory identities and lifecycle states under one lock. Test the switch/end interleaving and assert the advertised default is open in the returned directory.
[Blocking] Check publish admission before restoring target sessions
When admission is paused or the caller does not own the source or declare the event type, crates/dim-event-hub/src/publish.rs:119–146 still resolves omitted target branches before rejecting the publish. A rejected request can restore a cold target session or return its lookup error instead of the admission error.
Evidence: Static inspection: resolved_to precedes take_hold, held_by, and the type lookup. crates/dim-app-server/src/agents/sessions.rs:631–649 acquires the target session to resolve its default. Tests not run locally. CI: verify failed in daemon_startup_progress::an_assembly_note_is_waited_for_before_the_spawn_answers; that failure is not the evidence for these findings.
Requested change: Complete admission and source/type validation before resolving targets, then resolve each omitted branch once. Test that a rejected publish against a cold target does not invoke the resolver.
A v1 connection's event projection carries the root alone, so a call that
omits branchId keeps reaching the root there: the default-branch move
reaches clients that can name a line. session.attach keeps sequence as
the root's cutoff and adds the branch-qualified cursor defaultBranch
{branchId, sequence}; the catalog row's sequence stays the root's in both
the loaded overlay and the cold query, so an idle unload changes none,
while running and the activity follow the default branch.
The writer refreshes the catalog's activity time in the same transaction that records branch/default, from the new line's own latest activity and never from the switch itself. An idle move between lines no longer leaves the catalog recent by the line the Session left.
session.branches takes the default id and the rows' identities and lifecycle states under one tree lock, so a move or an end that commits while it reads is either wholly in the answer or wholly out of it: the advertised default is always open in the directory the answer carries.
An in-flight request stores the member branch chosen at delivery and reads it for the idle wait, settlement and every withdrawal and stop, so a member that moves its default branch mid-request can neither redirect its result nor leave the stop on an idle line. A read page reports the branch it read, and a continuation carries it: a bare after is refused instead of applying one line's cursor to another.
Process admission, source ownership and the type answer first, and an admitted publish then resolves each omitted target branch once, holding the hub's delivery budget across a cold read. A refused publish no longer restores a cold target Session or answers the target's error.
The cached turn, the shown offer and the generation in flight belong to the line the conversation was on when they were read. A branch/default clears all three, admission and the compaction precheck read the request's own line, and the completion rechecks it before publishing, so a move to another line never offers the old line's suggestion.
The completion test took the first request's result back before the request under test settled, so the reverted delivery-branch code passed it. It now waits for the second result and asserts the result names the delivered turn.
rustfmt over the touched files; no behaviour changes.
A move to a line with no activity yet reports the Session's creation time, the catalog's own rule for no activity, and the root's later activity no longer moves the row.
The design states that a v1 connection's projection carries the root
alone, so its unnamed calls keep the root, that SessionInfo.sequence
keeps the root's meaning, and that the attach reply adds defaultBranch
{branchId, sequence}. The catalog page states the row's sequence and the
switch's activity refresh; the plugin pages state the branch bindings of
Collaboration's reads, PromptSuggestion, EventHub's publish order and the
PromptSuggestion line check.
Clippy's needless_borrow: a model update and a prompt refresh already hold a Session reference.
The new tree read and Session method change the generated module graph.
A line made the default before it has activity of its own, such as a tool line switched to while its first turn runs, is dated by its own opening event; the Session's creation time answers only for the root and for a line with no event at all. The root's path is unchanged.
An opening row that exists but does not decode, or carries no create_at, answers the same error the activity read above does; only a line with no event row at all falls back to the Session's creation time.
eric8810
left a comment
There was a problem hiding this comment.
复审 32c4fa58:session.attach.sequence 已恢复为根游标,PromptSuggestion 会在切换默认分支时清理旧状态;EventHub publish 也已改为先准入并用并发预算限制冷读取。还有两处需要修复:
-
[P2] 一个坏目标不应中断整次 publish。
crates/dim-event-hub/src/publish.rs:165–187用default_branch(...).await?预解析省略分支的显式目标。只要其中一个 Session 已删除或无法恢复,就会在publish_to_completion规划投递前退出。同批有效显式目标和匹配订阅都收不到事件,调用方也拿不到原有的逐目标回执。建议将解析错误记录在对应目标的回执里,继续规划其他目标。请覆盖同次 publish 含有效显式目标、无法解析的省略分支目标和匹配订阅的情况。 -
[P2] 协作恢复仍可能停止错误分支。 实时路径现在固定投递分支,但
crates/dim-app-server/src/collaboration.rs:3969–3972重建未结请求时只读状态、agent 和 session;:4087–4108又在激活时重新取成员的当前默认分支来 stop。请求若投到 B、成员随后把默认切到 C,leader 的协作服务重载时就可能停止 C 上无关的回合,却没有停止 B 的原请求。请在持久化记录中保存实际投递分支并用于恢复;旧记录若无法确认分支,应避免停止当前默认分支。建议用 B 持有协作请求、C 另有回合的重载测试验证。
另一个同类的准入顺序问题:crates/dim-event-hub/src/subscribe.rs:29–67 仍先解析缺省分支,再检查类型声明。未知类型应直接拒绝,而不是先触发冷 Session 恢复或被目标错误掩盖。
以上为静态复审,未本地运行 Rust 测试。
|
Answering reviews 5988019592, 5988175323 and 5988370004. v1 submit target (codoggy, 4639006481). Rule: a connection whose event projection carries the root alone keeps the root for the calls that omit
The catalog and summaries Catalog recency on a switch (codoggy, 4639006491). Rule: a persisted move sets the row's activity time in its own transaction from the new default's latest activity (or that line's own opening time when it has no activity yet), using the catalog's own activity predicate, one indexed read, and the switch is not activity. Fix: the writer calls the catalog's activity refresh when it records The default and the directory from one snapshot (codoggy, 4639006489). Rule: the default id and the rows' identities and lifecycle states come from one tree lock. Fix: An in-flight request keeps its delivery branch (codoggy, 4639006497). Rule: the member branch chosen at delivery is stored with the input id and reused. Fix: Collaboration read continuation (codoggy). Choice: the preferred option. The page names the branch it read as PromptSuggestion follows a switch (eric8810 2, codoggy). Rule: the cached turn, the shown offer and the generation in flight belong to one line. Fix: the part keeps that line, follows EventHub admission before target resolution (eric8810 3, codoggy). Rule: process admission, source ownership and type validation answer first; an admitted publish then resolves each omitted target branch once, under the hub's delivery budget. Fix: CI. The Negative runs. Every new test fails on Checks. |
A to target whose omitted branch cannot be read is answered in its own receipt entry with the code a delivery to that Session would give; the rest of the publish is planned and delivered. Only the Sessions link itself failing (reloading or transport) still refuses the publish. subscribe checks its declared types before it resolves an omitted branch, under the same delivery budget.
A recovered request has no stored delivery branch, so recovery names the member's input from the collaboration/delivered fact and stops the line that holds it; the member's current default is never stopped. A record with no input, or whose input no open line holds, stops nothing and logs the skip.
`session.summaries` on a daemon without the native store read one Session's row in more than one step: it took the default branch and its head, then read that line's activity and, when it had none, the line's opening event. Another client moving the default branch away and ending that line between the reads made the next read refuse the ended line, and the whole listing failed for every Session. The row is now read as one attempt: the Session's default branch, running state and both cutoffs are taken again together with the row's summary, and a concurrent end of the line the row started on makes it read the complete row from the Session's new default. An end during the retry still answers its error. The flow test holds the first activity read on a tool line, moves the default back to the root and ends the line from another connection, then checks that the listing answers the row from the root's activity; on the previous head the listing fails `branch_ended`.
A storeless `session.summaries` row is read again from the Session's new default branch when a concurrent move ends the line it started on, but §3.3 did not say how often that happens. It now states that the re-read happens once: a line that ends again while the second attempt completes answers its error instead of trying a third line. The Chinese §3.3 gains the storeless rule and the re-read: a row reads its Session's default branch and that line's facts, and a concurrent end re-reads the row from the new default instead of failing the listing.
|
Fixed in 2d9085f: a storeless |
eric8810
left a comment
There was a problem hiding this comment.
Reviewed at head 2d9085f.
The blocking finding from my review at a702c22a is resolved: attach_replies_the_record_the_listing_shows_for_that_session now passes on this head, so the record's defaultBranch and the summary entry agree on a field they used to disagree on. That was the one thing gating this change's own correctness, and it is closed.
verify (linux) and ci-ok are still red on this head, with four TUI cases and 696 passing:
crates/dimcode/tests/cli_flow.rs:3942 and :371
goal::tui_goal_shows_the_state_and_marks_the_status_area
interactive_paste_encoding_rejection_keeps_confirmed_items_editable
repicking_the_current_model_keeps_the_effort
tui_models_picker_edits_only_the_subagent_model_policy
The first, third and fourth are the model/status frame cluster that has been failing across heads all evening (#1881, #1923, #1961); the paste case is new to that list but is the same shape — a terminal frame assertion, not an assertion about Session defaults or the branch a Session points at. Nothing here touches the record, the cursor, or branch_set_default.
So the remaining work on this PR is waiting for a green workspace run, not another code change, unless those four turn out to be a real TUI regression once the runner is unloaded.
Not approving while a required check is red.
Non-blocking: none.
zerob13
left a comment
There was a problem hiding this comment.
Re-reviewed 2d9085f91ebb8ba2b134a2aea38697a880f68005. The opening-time fallback and attach/list contract are fixed. The new storeless regression also covers the previous two-query failure when a line has already ended before the second lookup.
[P2] Make the selected line's lifecycle lookup atomic for session.summaries. Session::published checks the ended directory and then reads the active directory under a separate lock. A default switch and end can move the old line from active to ended between those reads. That reports UnknownBranch, but the new per-row retry handles only BranchEnded; a single normal transition can still fail the entire no-store listing. Classify active, ended, and genuinely unknown in one tree lookup, or retry only after confirming the selected line ended. Keep the existing bounded retry and do not mask genuinely unknown IDs. This is the remaining part of the earlier storeless lifecycle issue, not a separate requirement for additional test coverage.
The remaining interleaving is a static finding. Linux transport tests passed 604 cases; the aggregate is red on four TUI failures not attributed to this change.
`Session::published` checked the ended lines and then read the open ones under two separate tree state locks. A default switch and end between those reads removed the line from the open set after the ended set had been read, so the lookup answered `UnknownBranch` for a line that had merely ended; the storeless `session.summaries` re-read handles only `BranchEnded`, so one normal transition could still fail the whole listing. The tree now answers open, ended and unknown in one state lock through `TimelineTreeControl::published`, and `Session::published` delegates to it. A concurrent end therefore reads as `BranchEnded` and takes the existing bounded re-read, while a branch the Session never had still reads as unknown. The flow test holds the listing's lifecycle lookup, moves the default back to the root and ends the line from another connection, then checks that the listing answers the root's row; with the previous two-look body in place it fails `unknown branch`. A branch identity the Session never had stays unknown in the branch flow.
|
Fixed in 0410295: |
eric8810
left a comment
There was a problem hiding this comment.
Reviewed at head 0410295.
The delta since my review at 2d9085f9 is the right follow-through on what I raised: published() now decides "published and open", "ended" and "unknown" under one tree-state lock, with the note that a concurrent end cannot read as unknown — the same discipline as the opener guard, applied to a second reader. The new a_storeless_summary_reclassifies_a_line_ended_mid_lookup flow test earns its place: a move and an end racing a listing is exactly the case a lock-scoped answer exists to settle, and it is asserted at the transport flow rather than on a helper.
verify (linux) failed on this head, and the dominant cause is the runner rather than this change:
crates/dim-agent-capabilities/tests/host_platform_flow.rs:1075
a_confined_helper_gets_the_allowlist_plus_its_own_environment
"bwrap: Can't mount proc on /newroot/proc: Operation not permitted"
8 passed; 10 failed — all ten confined-helper cases
Every confinement test failed with the same bubblewrap permission error, so this runner cannot create the sandbox at all. That is precisely the condition the Linux job was supposed to check before running the workspace tests; it did not hold here, and the failures it produced are not evidence about this PR. The same run also shows execution_settings_decide_the_next_process_boundary, file_storage_flow, the OCR plugin cases, goal_evaluator_judge_…, and the model-picker TUI cluster — a spread that reads as one broken environment rather than four independent regressions.
Not approving while a required check is red, and saying plainly that I read this red as the runner's, not the code's, and not as a reason to change the code.
Non-blocking: none.
eric8810
left a comment
There was a problem hiding this comment.
Reviewed at head f28ee51.
The earlier blocking finding stays closed: attach_replies_the_record_the_listing_shows_for_that_session passes, so the record and the summary agree on defaultBranch, and published() deciding "open", "ended" and "unknown" under one tree-state lock still reads as the right repair for the second reader.
verify (linux) and ci-ok failed on this head, in a test that is adjacent to this PR's subject rather than clearly outside it:
crates/dim-app-server/tests/storage_session_flow.rs:342
session_close_and_idle_unload_persist_finalizers_and_release_branch_parts
branch part must be dropped after Session teardown (idle unload: false)
486 passed; 1 failed
Session teardown releasing branch parts is the machinery this change routes defaults through — a Session now reads and holds its default branch where it previously assumed the root — so I am not willing to call this an unrelated flake the way I could for the compaction and TUI failures on other heads. It may be a timing effect, but it may be a part that stays alive because something in the new default path keeps it referenced, and the assertion is exactly the one that would catch that.
What would settle it: a re-run, and if it reproduces, a look at whether the default-branch handle is released on the teardown path rather than only on the move path.
Not approving while a required check is red, and not dismissing this one as environmental.
Non-blocking: none.
|
Review: #1917 (review) I re-ran that test on this head, on its own, once: The default branch reaches every new path in this change as an id, read under the tree lock; no path stores a
Teardown releases the parts through the unchanged path: dim/crates/dim-agent-runtime/src/agent.rs Line 823 in a50b350 finish (
) cancels its stop token (#L793) and shuts its scope down (#L806), dropping the branch parts; an idle unload calls each branch's unload() first (agent.rs #L842).
The fixture used by that test mounts The same assertion failed on heads that contain no commit of this change: #1969 at 8d43698 (https://github.com/arcships/dim/actions/runs/44863073719, |
eric8810
left a comment
There was a problem hiding this comment.
Reviewed at head a50b350.
Checks are green, and the two things I raised earlier are both settled.
storage_session_flow.rs:342 ("branch part must be dropped after Session teardown") no longer fails, and the delta explains why: the idle waits in branch_flow.rs moved from soon (5 s) to patient (30 s), documented as "[soon] for the waits a loaded machine can stretch". That is the right call and the right scope — the assertion was not weakened, only the wait for the state it observes was given room on a loaded runner, and no product code moved to make a test pass. My caution at f28ee516 was that the failure sat close enough to this PR's subject to be real; with the head green and the fix confined to test waits, that reading looks wrong, and I would rather say so than let the caution stand.
The rest of the delta is main merged in — the dim-branch-line default-note sentence and the single CANNOT_END_TEXT refusal from the branch-prompt work — so the record/listing agreement I checked at 2d9085f9 still holds, and published() still decides open/ended/unknown under the tree-state lock.
Blocking: none.
I read the delta since f28ee516, the two test helpers' timeouts, and the changed assertions in branch_flow.rs; I did not re-read the whole PR, and ran nothing.
Non-blocking: none.
The parent's head carries the attach reply's default cursor (arcships#1917) and moves the generated module files out of the tree (arcships#1946), so the resolution drops both files, as a sync with main does.
This is the third pull request in the default-branch work and it follows #1862: the
branch/defaultfact,TreeCommands::default_branch()andset_default_branch, the end guards,FORMAT53 and the writer thread's cache are onmain, and until this change nothing in the App Server could move the default branch and every Session-level default still named the root. It adds the user's entry, gives the directory the id, and routes the defaults. A line made the default branch still cannot open a line of its own until the opening change lands, and the clients follow in the next pull request.The entry.
session.branch_set_default {sessionId, branchId}is a v3 built-in, listed inhello.featuresunder the same admission assession.branch_end. It calls the tree'sset_default_branchwith a user source, answers the newdefaultBranchId, and lets the tree's own refusals reach the client unchanged:branch_already_default,branch_not_selectable,branch_target_protected,branch_endedfor a line that ended, andsession_invalid_inputfor a line the Session does not have. A refusal writes nothing; the move writesbranch/defaulton the root and the status notes each participant owes (design §14).The directory.
session.branchesnow carries one top-leveldefaultBranchIdbeside its rows, read from the tree's directory rather than derived from a row, because a row cannot express zero or two default branches (design §14). The reply is the one place a client learns both who may open a line and which line the conversation is on.The defaults. Every Session-level target that named the root reads the line the fact names, once per request, so a move in the middle of a call cannot split it across two lines.
session.submit,session.stopandsession.idleresolve an absentbranchIdto that line on a connection whose projection carries every branch; a v2 caller must name a line, a v3 caller may omit it, and a v1 connection keeps its old meaning.session.model.update,session.agent.updateandsession.prompt.refreshact on the line they name, and on the default branch when they name none, instead of refusing every line but the root. The catalog's liverunningand a summary's newest activity follow the same line, so a Session list reads busy and recent by its default branch (session-catalog §3.3). A managementschedule.savewhose session target omitsbranch_idrecords the Session's current default branch at save time, through thesessionsdata face's newdefaultBranchId {sessionId} → {defaultBranchId}read (sessions service §6.11); the same read answers every request that names a Session but no line:session.loop.start,session.loop.list,session.wakeup.list, theloopsandwakeupsfaces, EventHub's subscription target and a publish'stoentry, each resolved once per request.Compatibility. The move is reachable through RPC now, but the clients that follow it come later, so every field and behaviour an existing client relies on keeps its old meaning and the new meaning arrives through new fields. A v1 connection's event projection carries the root alone, so a call that omits
branchIdon it keeps reaching the root: a v1 submit after a newer connection moved the default runs on the root, and the v1 stream shows the turn.SessionInfo.sequenceon thesession.attachreply stays the root's sequence, the cutoff the CLI keeps as themainwindow'sthroughand as the root model-update watermark, and the line the conversation is on arrives beside it asdefaultBranch {branchId, sequence}, the cursor a client resumes that line from; a client that predates the field ignores it. The cursor is the attach reply's alone: asession.summariesitem is a directory row and carries nodefaultBranch, so a client reads the line when it attaches and not from a list. A catalog row'ssequenceis the root's in both the loaded overlay and the cold query, so loading or unloading a Session never changes it, whilerunningand the activity follow the default branch; a persisted move refreshesupdatedAtin its own transaction from the new default's latest activity (or that line's own opening time when it has no activity yet), a daemon without a store dates asession.summariesitem by the same rule, and both projections share that fallback, so an idle move never leaves the row recent by the line the Session left. A storeless row whose line a concurrent move ends while it is read is read again from the Session's new default, so another client moving the conversation cannot fail a listing. The row decides that line's lifecycle in one tree lookup, so the move and end read as an ended line and the bounded re-read, not as a branch the Session does not have. Both design sections state the rule (§14, §15), and the plan's earlier sentence that an older client omittingbranchIdnow reaches the default branch is superseded for a root-only protocol.The parts. PromptSuggestion folds the default branch's turn, asks it for the compaction due-check, and binds its cached turn, its offer and its in-flight generation to that line: a
branch/defaultcancels the generation, clears the offer and the cached turn, and a request after the move refuses the old turn asbranch_changed. Collaboration stores the member branch a request's input was delivered on and reads it for the idle wait, settlement and every withdrawal and stop, so a member that moves its default branch mid-request neither redirects the result nor leaves a stop on an idle line; recovery has no stored branch, so it stops the line that holds the member input itscollaboration/deliveredfact names and stops nothing when that input cannot be found, never the current default; a read page names the branch it read, and a continuation must carry it, so a move between pages never applies one line's cursor to another. EventHub answers process admission, source ownership and the type before it resolves an omitted target branch, so a refused publish never restores a cold Session; a target whose omitted branch cannot be read is answered in its ownfailedreceipt entry, whatever the read answered (session_closed,reloading, ortransportfor a failed call) and with nobranchId, while every other target and every matching subscription is planned and delivered; that is one rule for every resolution failure, and none of them refuses the publish as a whole. Each omitted target Session is resolved once per request even when the first lookup fails: a second entry naming it reuses the first answer, and a failure answers onefailedentry with nobranchId.subscribechecks its declared types before it resolves an omitted branch, under the same delivery budget.subscriberesolves an omitted branch before it takes the target Session's lock, so a delivery that holds a permit while its guide refresh waits for that lock and a subscribe that holds the lock cannot wait for each other; every path takes an event lock, then a delivery permit, then the Session lock, then the change lock, andan_omitted_branch_is_resolved_before_the_session_lockholds the order. Goal'ssession.goal.*resolves an absentbranchIdto the default branch; a report's snapshot records the line it read and its plan reads that same line; ShellInput's!run belongs to it; and a Collaboration member Session's own state follows that member Session's own default branch rather than the leader's.Sites that stay on the root.
approval.respondkeeps thebranchIdits notice carried, so a pending approval stays on the line that asked and a move never delivers an answer to a line that never asked. The catalog's preview and a Session's title stay on the root, because a Session's first words are written there and PR #1862 split preview from activity on purpose. The summary's preview cutoff is the root's head even when its activity follows a line.session.fork's boundary check,session.create'smodelFromSession, the fork reply's, the create reply's and the attach reply'ssequence, and the closed-form reply fields keep naming the root; the attach reply carries the conversation's line beside it asdefaultBranch {branchId, sequence}. A stored job or wakeup or loop row that omitsbranch_idkeeps its recorded meaning because it was written before the rule; a save made now records the default branch instead. The legacyreusemapping still names the Session's root, and the stop of a launched Session (engine.rs) stops that Session's own root.Acceptance. §20.21 is
session_branch_default_reports_the_new_line_and_writes_the_notes, which reads the note counts per line formain → B,B → mainandB → Cand thedefaultBranchIdbefore and after each move, anda_refused_switch_writes_nothing, which answersbranch_already_default,session_invalid_inputandbranch_endedand checks that no note and no move was written. §20.22's line half isa_call_without_a_branch_targets_the_default_branch, which submits with nobranchId, finds the input on the line and not on the root, and reads the line's own cutoff fromsession.idleandsession.stop; its approval half isa_pending_approval_answers_on_the_line_that_asked, which raises a notice on the line, moves the default branch away and answers the notice's own line. §20.23 isa_model_change_acts_on_the_line_it_names, which adopts a profile on the default branch while the root keeps none and then on a named line. §20.10 isa_v3_client_is_offered_the_switch_and_older_clients_are_not: a v3 client'shello.featureslists the method and its history carriesbranch/default, a v2 client's does not, and the v2 call isunknown_method. §20.27 end to end iscontinuing_on_a_line_after_a_switch_survives_a_restart: a user line, a tool result on it, the switch, a submit with nobranchIdthat reaches it, a restart, the same submit still reaching it, and back to the root. The goal entry isa_goal_change_without_a_branch_reaches_the_default_branchin Goal's flows, and the catalog case isthe_catalog_reads_running_and_activity_from_the_default_branch, which readsrunningfrom the line while the root is idle, from neither once the default moves back, and the line's newest activity as the summary'supdatedAt. The storeless and stored listings share the opening fallback assummaries::an_empty_tool_line_is_dated_by_its_opening_in_both_listings: a tool line held in its first turn is made the default, and a daemon without a store and one with the native store each report the line's opening time rather than the Session's creation. The storeless listing's concurrent cases aresummaries::a_storeless_summary_survives_its_default_line_ending_mid_read, which holds the row's activity read on the line, moves the default back to the root and ends that line from another connection, and then answers the row from the new default, andsummaries::a_storeless_summary_reclassifies_a_line_ended_mid_lookup, which holds the row's lifecycle lookup and completes the same move and end inside it, so the row takes the bounded re-read instead of failing the listing as an unknown branch;branch_flow::a_branch_this_session_never_had_is_unknownkeeps an id the Session never had unknown.The scheduled-job half of §20.22 is
a_new_scheduled_job_records_the_default_branch_and_keeps_it_after_a_move: withmain → B, a save with nobranch_idstores B; a move back tomainleaves the job delivering to B; and a stored row written without it still delivers to the root. The loop and EventHub defaults area_loop_started_without_a_branch_follows_the_default_branch, whose round lands on B and not the root, anda_publish_without_a_branch_reaches_the_default_branch, whosetoentry and subscription both reach B.The compatibility rule is
default_branch::a_v1_submit_stays_on_the_root_after_a_switch: a Session created by a v1 connection is used by a v3 connection that opens a line and moves the default to it, and the v1 submit still runs on the root with the turn visible in the v1 stream. The attach reply's two cursors aredefault_branch::attach_keeps_the_root_sequence_beside_the_default_cursor, with the root longer than an idle line and then the line longer than the root. The catalog row's sequence isidle_unload::the_catalog_sequence_stays_the_roots_across_an_idle_unload, the same row before and after an idle unload; the switch's activity refresh isdefault_branch::a_switch_republishes_the_new_defaults_activity, read immediately after each move between two idle lines.default_branch::a_branches_read_advertises_an_open_defaultholds the read before its snapshot, moves the default away and ends the former default, and asserts the advertised default is open. Collaboration's delivery branch iscollaboration::a_request_completes_from_the_line_its_input_was_delivered_to, whose held request answers with the delivery line's turn after the member moves its default, andcollaboration::a_cancel_stops_the_line_the_request_was_delivered_to, whose cancel stops that turn.collaboration::a_read_continuation_stays_on_the_branch_its_page_readcovers a move between two pages with overlapping sequences.prompt_suggestion::a_switch_withdraws_a_running_suggestion_and_its_cached_turnholds a generation at the completion gate, returns the conversation to the idle root, and checks that nothing is offered and that the old turn is refused.fixture_flow::a_refused_publish_reads_no_target_defaultuses a counting resolver: refused publishes read nothing, and an admitted publish naming one Session twice reads once.The negative runs. With each behaviour reverted on
8c066bfb71db9fd654a4ee8bc59c5bc84695676f, its test fails: the v1 submit lands on the moved default and the v1 stream carries no turn; the attach reply reports the line's sequence and nodefaultBranch; the loaded catalog row reports the line's sequence; a switch leaves the old default's activity time; the branches read advertises an ended default; the settle reads the new default and answersFailedfor a cursor past that line's head; the cancel's stop never reaches the delivery line's turn; a bare read continuation succeeds on the new default; the suggestion request failsbranch_changedat admission once the switch is not followed; and the publish reads its target's default before the refusal. Each passes on the head. The listing's side of the attach contract has its own check: givingSessionSummaryadefaultBranchand filling it in both summary constructors failsattach_replies_the_record_the_listing_shows_for_that_sessionon its assertion that a listing item carries no cursor.Measures (earlier head). The switch's transaction now also refreshes the catalog's activity with one indexed read; the figures below were measured before that addition. E1, the catalog's running state and recent activity with the default branch on the root and on a line:
measure_e1_catalog_with_the_default_on_the_root_and_on_a_linereads the catalog with a turn running, release build, and reports 0.24 ms with the default on the root and 0.17 ms with it on a line, each read reportingrunning: truewhile the turn runs and the line's own newest activity asupdatedAtonce it settles. E4, a switch end to end from the RPC call until both notes are committed:measure_e4_switch_until_both_notes_are_committedreports a median of 0.17 ms and a maximum of 0.24 ms over five moves between two lines. Both are#[ignore]d release runs beside their flow tests.Checks. The head merges
mainat46714dbc4. On that head,cargo test -p dim-event-hub --test hub_flow: 54 passed, 1 ignored;cargo test -p dim-agent-capabilities --test capabilities_flow: 632 passed, 4 ignored, thebranch_flowmodule among them;cargo test -p dim-app-server --test transport_flow: 607 passed, 100 ignored;cargo test -p dim-app-server --test app_server_flow: 486 passed, 7 ignored, run withstorage_flow::main_and_branch_formats_upgrade_without_reinterpreting_their_markersskipped because it stalls in a WAL checkpoint busy-wait on this machine while its test and the storage code are identical tomain, so CI covers it;cargo test -p dim-agent-scheduler --test scheduler_flow: 116 passed;cargo test -p dim-goal --test goal_suite: 94 passed; clippy with--all-targets -- -D warningsis clean on each of the seven changed crates;cargo fmt --all -- --check --config error_on_line_overflow=trueis clean;xtask checkpasses withliteral_mainstill reporting its eleven unrelated uses.Refs #1811