Skip to content

Consolidate the Session tree and retire treeCommands - #1909

Closed
eric8810 wants to merge 27 commits into
eric/1292-domain-loop-promptfrom
eric/1292-domain-tree
Closed

eric8810 wants to merge 27 commits into
eric/1292-domain-loop-promptfrom
eric/1292-domain-tree

Conversation

@eric8810

@eric8810 eric8810 commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #1292

Implementation

  • Consolidated tree commands and directory, display, batch and history reads on timelineTree.
  • Removed the public treeCommands, timelineFactory and timelineTreeControl names. Session assembly retains its private constructor and lifecycle access.
  • Report captures the main directory head for activity evidence and later opt-in conversation. Both use the same cutoff.
  • timelineTree.call dispatches compactAndWait, contextUsage.read, approval.pending, approval.decide and inputQueue.withdraw. Session Context RPC calls the selected branch through this operation.
  • Dispatch prompt.configure and prompt.adoptedConfiguration through Migrate branch control, Prompt and selected-branch consumers #1911’s Prompt owner. Report and session.agent.get read adopted configuration through the selected tree. This PR is stacked on Migrate branch control, Prompt and selected-branch consumers #1911.
  • Session language uses the existing update operation. Agent configuration, Collaboration approval and input withdrawal use the admitted branch. BranchTool calls timelineTree.endWithFinal(id, source, finalMessage). BranchLine retains the tree’s internal default-move and parent-turn signals, as specified in timeline-branches.

Callers and operations

  • Move create/end/info/input/list/page/query and the live defaultBranch/setDefaultBranch operations onto timelineTree. Keep construction/restore/teardown private. Remove treeCommands without an alias after all callers migrate.
  • Bind directory({}) and directory({id}), inputs for Goal atomic batch, display for detail, batchEnd/pageEnd/page for bounded history. Add call({branchId,operation},cancelled) to dispatch once to the admitted branch.
  • Migrate BranchTool/BranchLine, input/loop/tool management, Goal, Shell, PromptSuggestion, Recall, Questions, Wait, workspace readers, TreeTimeline, native/TS/Python and installed consumers.
  • Preserve BranchTool.end_with_final (final message committed with branch/end) and BranchLine default_from/default_moves/next_move/turn_ends/activity_after. Verify the migration against the existing branch contract: a tool end records its final message on branch/end and restore delivers it exactly once; BranchLine preserves ordered default moves, recovery and parent activity. Reuse the tree owner and existing facts. See branch behavior §§4–12.

Final API

Caller / operation Contract
Branch management, input and history callers → timelineTree create/end/info/input/list/page/query retain their existing signatures on the single Session tree face. Creation returns the branch ID.
Branch directory readers → timelineTree timelineTree.directory({}) → [{info, head, state, endEvent?}], including ending and ended branches.
Goal and Shell admission → timelineTree directory({id}) returns the matching directory entry or the unknown-branch error using a single-branch lookup. Goal reads ended history through query; writes retain the ended/unknown errors.
Goal → timelineTree inputs(id, inputs) → committed events. One validated atomic batch for the Goal record and trigger.
Branch-detail RPC → timelineTree display(id) → {entry,purpose?,cutMessages?,end?}.
History RPC and line-read tools → timelineTree batchEnd(id, sequence) → void, pageEnd(id, after, limit, through) → sequence, and page at the same cutoff. Preserve complete batches and the fixed head of ended lines.

Reuse defaultBranch/setDefaultBranch. For a selected live branch, timelineTree.call({branchId,operation},cancelled) → operation reply. Variants: contextUsage.read, compactAndWait, prompt.configure, prompt.adoptedConfiguration, inputQueue.withdraw, approval.pending and approval.decide.

Acceptance

  • Verify live/ending/ended/unknown targets, default moves, terminal delivery, whole batches and stable cutoffs. Preserve generation for admitted calls.
  • Confirm native and foreign calls use the same owner; verify relevant replies, errors, cancellation and unload. Update bindings, generated catalog and declarations where affected.
  • Resolve the current internal entries: timelineTree, timelineTreeControl, timelineFactory.

Owner contract · Baseline catalog

@eric8810 eric8810 mentioned this pull request Nov 20, 2026
6 of 45 tasks
@eric8810
eric8810 changed the base branch from main to eric/1292-domain-loop-prompt November 20, 2026 14:10
…9-tree

# Conflicts:
#	crates/dim-agent-capabilities/src/timeline_tree.rs
#	crates/dim-agent-capabilities/tests/branch_flow.rs
#	docs/architecture/rust-agent/plugins/TimelineTree.md
#	docs/design/timeline-branches.md
#	docs/zh/design/timeline-branches.md
@eric8810
eric8810 marked this pull request as ready for review November 21, 2026 16:23

@zerob13 zerob13 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.

In timeline_tree.rs:323–340, the cancellation arm calls cancel.cancel() and then polls called again even if dispatch has not reached the selected owner yet. For example, the compaction handler at context_methods.rs:85–99 admits the command before waiting for its result with the token. A caller can see cancellation even though the cancelled request started a new compaction. Refuse cancellation before owner admission, while allowing the owner to settle work already admitted. Please cover a request cancelled before dispatch as distinct from cancellation after admission. This is a static finding; the exact child CI passed.

@yyhhyyyyyy yyhhyyyyyy 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

This PR consolidates the Session tree on timelineTree, retires treeCommands, timelineFactory and timelineTreeControl, and routes selected-branch calls through timelineTree.call. The direction matches the owner contract, and the catalog, generated declarations and runtime fixtures move together. One previously reported blocking issue remains, and one new contract contradiction needs a decision.

Verdict: REQUEST_CHANGES.

Blocking

Cancellation is not checked before owner admission. Agree with the earlier review on this arm: TimelineTree::call (crates/dim-agent-capabilities/src/timeline_tree.rs:332-340) cancels the token and then polls call_branch, so an operation that has not reached its owner is still started. compact commits agentLoop.compact at crates/dim-agent-capabilities/src/context_methods.rs:91-93 and only observes the token later, at :200. Failure scenario: a client disconnects while session.context.compact is being dispatched. call takes the cancellation arm, then polls call_branch, which commits agentLoop.compact; the caller receives operation_interrupted, a compaction runs anyway, and a retry can commit another. No test separates cancellation before dispatch from cancellation after admission. Fix as proposed earlier: check the caller's cancellation before polling call_branch and answer operation_interrupted without admitting; once the owner has admitted work, let it settle and return the owner's result instead of reporting interruption.

New finding

inputQueue.withdraw refuses the steer that the owner contract says it accepts. The withdraw helper on the public tree face (crates/dim-agent-capabilities/src/timeline_tree.rs:655-663) forwards to InputQueue::withdraw, which rejects every steer (crates/dim-agent-capabilities/src/input_queue.rs:244-250). The contract says inputQueue.withdraw takes the owner's existing command and the caller runs the submit checks for steer before writing (docs/design/contracts/runtime-owner-operations.md:27,54). Failure scenario: a foreign plugin follows the contract, runs its submit checks, and calls timelineTree.call with {kind:"inputQueue.withdraw", command:{input_id, steer}}. It receives session_invalid_input and cannot replace the withdrawn input, while the checked steer path is only the App Server's session.input.withdraw method. Fix the contract to state that steer is refused here and stays on session.input.withdraw, or add a checked steer variant to the tree operation. The contract change is the smaller one.

Optional

directory_entry is documented as returning a record for a "published or still opening" line (crates/dim-agent-capabilities/src/timeline_tree.rs:1779-1781), but Node::directory_entry returns None unless the node is published (crates/dim-agent-capabilities/src/timeline_tree.rs:153-155). Goal, Shell and Collaboration now call directory_entry where they used get (crates/dim-goal/src/session.rs:121,199, crates/dim-agent-capabilities/src/shell_input.rs:227, crates/dim-app-server/src/collaboration.rs:1309), so a line in its opening window answers session_invalid_input instead of being accepted from its built context (the context is stored at timeline_tree.rs:1243, before publication at :1310). The design already treats an opening line as unknown for end (docs/design/timeline-branches.md:396), so if the same rule is intended for these admission checks, correct the comment and state it in the contract; otherwise include opening nodes with their context head.

Cross-PR and CI

The head does not merge cleanly into origin/main: git merge-tree --write-tree origin/main HEAD reports conflicts in 26 paths, including crates/dim-agent-capabilities/src/input_queue.rs, crates/dim-agent-capabilities/src/timeline_tree.rs and docs/design/timeline-branches.md. This belongs to the stack: the base PR #1911 is DIRTY against main, while this PR is CLEAN against its declared base, and #1911's head is an ancestor of this head. There is no conflict with #1911 itself.

Required CI at head 6f36d5d passed: ci-ok, static-checks, macos-native and verify (linux). The verify (linux) job includes a passing "Verify public Node bindings" step, so the changed declarations and TypeScript fixtures were exercised. "Verify Python plugins" was skipped, so the renamed runtime/fixtures/python/python_branch_part.py was not exercised. The scripts and web jobs were also skipped by change selection.

Ok(async move { approval.decide(request_id, decision).await })
}

pub fn withdraw(

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.

This helper forwards to InputQueue::withdraw, which rejects any steer (crates/dim-agent-capabilities/src/input_queue.rs:244-250). The owner contract says inputQueue.withdraw takes the owner's existing command and the caller runs the submit checks for steer before writing (docs/design/contracts/runtime-owner-operations.md:27,54). A foreign caller following that contract sends {kind:"inputQueue.withdraw", command:{input_id, steer}} and receives session_invalid_input, so it cannot replace a withdrawn input through this face; the checked steer path is the App Server's session.input.withdraw method, which this face does not expose. Fix the contract to state that steer is refused here and stays on session.input.withdraw, or add a checked steer variant to this operation.

/// A line's directory record, published or still opening; absent once a
/// failed creation removed it.
fn info(&self, id: &str) -> Option<TimelineInfo> {
pub fn directory_entry(&self, id: &str) -> Result<BranchDirectoryEntry> {

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.

The comment says "published or still opening", but Node::directory_entry returns None unless ready is Some(Ok(_)) (crates/dim-agent-capabilities/src/timeline_tree.rs:153-155), so a line in its opening window returns UnknownBranch. Goal (crates/dim-goal/src/session.rs:121,199), Shell (crates/dim-agent-capabilities/src/shell_input.rs:227) and Collaboration cancel (crates/dim-app-server/src/collaboration.rs:1309) now call this where they used get, which accepted a built context before publication (the context is stored at crates/dim-agent-capabilities/src/timeline_tree.rs:1243, before ready is published at :1310). A caller that learns a branch id from branch/create and writes before publication now gets session_invalid_input. The design already treats an opening line as unknown for end (docs/design/timeline-branches.md:396). If the same rule is intended here, correct the comment and state the behavior in the contract; otherwise include opening nodes with their context head.

@eric8810

Copy link
Copy Markdown
Collaborator Author

未完成所有者调查就开始的改动,关闭。后续按 #2015 的扫描结论重新设计,对应 #2024。分支保留,供重新设计时参考。

@eric8810 eric8810 closed this Nov 23, 2026
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