Skip to content

Move file history, tool bindings and nested execution to branch faces - #1913

Closed
eric8810 wants to merge 14 commits into
mainfrom
eric/1292-domain-tools
Closed

eric8810 wants to merge 14 commits into
mainfrom
eric/1292-domain-tools

Conversation

@eric8810

@eric8810 eric8810 commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #1292

Caller Branch owner and API
File read, edit and write tools fileReads.binding({path}), writeBinding({path}), record({path,binding,established}). The original read supplies the established Timeline sequence.
Loop and Code Mode toolBinding.bind({requestId,through,tools,toolSources}), bindCurrent({requestId,declared?}), definitions({requestId}), transfer({from,to}), release({requestId}). ToolBinding pins the request’s original handler generation.
Code Mode and foreign nested tool callers toolExecutor.open({parentCallId,context},cancelled) → gateId, invoke({gateId,call}) → ToolResult, close({gateId}) → ToolEffect[]. ToolExecutor admits and executes children, writes the child facts and returns effects in invocation order.

Verified native workspace file workflows, Code Mode and product transport flows, actual Node callers for all three faces, strict TypeScript declarations, Clippy and the generated service catalog.

@eric8810 eric8810 mentioned this pull request Nov 20, 2026
6 of 45 tasks

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

Please address these issues before merging.

  • Nested call ownership (crates/dim-agent-capabilities/src/tool_executor.rs). Bind nested work to its admitted, live parent on the owning branch. Give nested registrations an identity isolated from other calls.
  • Cancellation and settlement (crates/dim-agent-capabilities/src/tool_executor.rs and tool_executor/face.rs). Reject new nested work after cancellation. Keep accepted work tracked until settlement and preserve confirmed child effects in the parent result.
  • Pinned bindings (crates/dim-agent-capabilities/src/tool_binding.rs). Preserve an existing destination binding when transfer is refused, and make the refusal atomic so the source binding also remains intact.

Formatting. The required Linux command cargo fmt --all -- --check --config error_on_line_overflow=true passes on main and fails on the PR head at tool_executor.rs:591–593.

All three new Node-backed flows, strict TypeScript checking, six focused Rust regressions, and the ADR check passed in an isolated checkout. CI checked out merge commit 9ff300778230004625c569a9ffc28b6edbb0e986 with first parent ffd3e11623267f15e11421aa419532e131da82cb and second parent 6f924ab3d8cbb700f52f566d40b27da834ba8e29. macOS native and dependency checks passed. Linux verify job 136285357805 was queued at submission.

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

Verdict: REQUEST_CHANGES.

This PR moves branch FileReads bindings, ToolBinding declarations and ToolExecutor nested execution behind branch data faces, so native file tools and Node callers use the owner's operations. Ownership sits on the branch plugins, the executor-level definitions shortcut and the NestedGate trait are gone, and gate ids, cancellation, the five second close bound and effect ordering are preserved.

Findings

P2 - The formatting gate fails. cargo fmt --all -- --check --config error_on_line_overflow=true reports two lines over 100 columns in crates/dim-agent-capabilities/src/tool_executor.rs:591 (109 columns) and :593 (106 columns). CI's verify job runs this exact command before clippy, and ./dev check uses it too, so the PR fails CI. Fix: bind std::mem::take(&mut state.gates) to a local before the tuple and collect the close futures in a local so both lines fit. No behavior change.

Optional P3 - The new automatic gate drain at batch end (same lines) has no test: both fixtures close their gates explicitly. A fixture path that opens a gate and returns without closing, then invokes after the batch result, would pin that cleanup. Not blocking.

Conflicts

  • origin/main ffd3e11: merge-tree clean.
  • #1904: merge-tree clean.
  • #1911 and #1912: textual conflicts only (branch_typescript.rs appended tests; docs/design/service-faces.md table edits).
  • #1910: conflicts in file_storage/face.rs, src/lib.rs, branch_typescript.rs, ToolExecution.md and service-faces.md. One semantic point: #1910 replaces file_storage::deserialize_name with crate::os_string::deserialize, while this PR imports the old helper at crates/dim-agent-capabilities/src/workspace_tools/file_reads/face.rs:6, so whichever merges second must switch that import.

Verification

Passed: cargo check --workspace --all-targets --locked; cargo clippy --workspace --all-targets --locked -- -D warnings; xtask check; adr-check; tsc on npm/plugin.d.ts; cargo test -p dim-codemode (25 tests); cargo test -p dim-agent-capabilities --lib --test interrupt_flow --test workspace_files (154 tests); the three new branch_typescript Node tests against rutis-runtime 0.23.0, including the cp932 Legacy binding round trip.
Failed: cargo fmt, as above.
GitHub verify (linux) was still queued at review time; the fmt failure will fail it.

The file history page boundary and ended/unknown error items in the brief have no matching code in this diff: this PR exposes the FileReads binding face, not a history page API, so those paths are not verifiable here.

@eric8810

Copy link
Copy Markdown
Collaborator Author

b82c494 addresses both reviews. The executor checks the live parent and call identity before admitting a child. Closing a gate stops admission. Confirmed descendant effects reach the parent result even when its handler returns without reporting them. A refused binding transfer preserves both bindings.

Two Node-backed transport tests passed, including a grandchild settling before its parent is cancelled. All 25 Code Mode tests and 16 tool-binding tests passed, along with strict TypeScript, the CI rustfmt command, targeted Clippy and the ADR check.

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

Verdict: APPROVE.

This PR moves branch FileReads bindings, ToolBinding declarations and ToolExecutor nested execution behind branch data faces, so native file tools and Node callers use the owner's operations. The new commit binds nested calls to their admitted, live parent, isolates nested call identities within the batch, refuses work after cancellation, tracks accepted children on the executor, and preserves confirmed child effects on the parent result. The formatting gate now passes.

Findings

No blocking findings.

The live parent is the running_parents entry inserted by run_parent after admission, and open and invoke read that map under the same state lock as removal (crates/dim-agent-capabilities/src/tool_executor.rs:199-225, :274-282, :306-315). A gate therefore opens only for a running parent, and a new invocation is refused once the parent returns or its token is cancelled. stop keeps the five second bound from the first close (:101-113). Child effects are recorded under the child tool-call sequence (:182-187), collected and sorted when the parent settles (:230-243), and deduped against a result that already reports them, so a handler that discards its close result still gets them exactly once and a handler that attached them does not double them. The Node fixture now covers cancellation refusal, duplicate child ids, a grandchild gate, and the parent result carrying both preserved effects; the assertions are stronger than before.

Optional P3, not blocking: the rustdoc on ToolExecutor::open (crates/dim-agent-capabilities/src/tool_executor.rs:247-249) still describes only the context match. ToolExecution.md now also requires a running parent and a batch-unique child id, so the comment is incomplete for the next caller. Fix: add those two sentences there.

Withdrawn from the previous round: the P2 formatting finding is fixed at b82c494, and the optional batch-end drain note is covered by the new parent-settlement tests.

Conflicts

  • origin/main ffd3e11: merge-tree clean.
  • #1904, #1903, #1951: merge-tree clean.
  • #1909: textual conflict in crates/dim-app-server/src/lib.rs (both edit the same register_faces list).
  • #1900: textual conflict in crates/dim-agent-capabilities/src/file_storage.rs (the new pub(crate) re-export sits next to its new pub mod mentions).
  • #1911: textual conflict in crates/dim-app-server/tests/transport_flow/branch_typescript.rs (both append tests).
  • #1912: textual conflict in docs/design/service-faces.md (both edit the section 3.5 rows).
  • #1910: conflicts in file_storage/face.rs, app-server/src/lib.rs, branch_typescript.rs, ToolExecution.md and service-faces.md. Semantic point: #1910 replaces file_storage::deserialize_name with crate::os_string::deserialize and removes the helper, while this PR imports crate::file_storage::deserialize_name at crates/dim-agent-capabilities/src/workspace_tools/file_reads/face.rs:12 and :19 and re-exports it at crates/dim-agent-capabilities/src/file_storage.rs:34. Whichever merges second must switch the import and drop the re-export.

Verification

Passed at b82c494 in an isolated checkout with isolated HOME, TMPDIR, XDG and target directories: cargo fmt --all -- --check --config error_on_line_overflow=true; cargo check --workspace --all-targets --locked; cargo clippy --workspace --all-targets --locked -- -D warnings; cargo test -p dim-agent-capabilities --lib (71 tests); cargo test -p dim-codemode (25 tests); cargo test -p dim-agent-capabilities --test interrupt_flow --test workspace_files (83 tests); cargo run -p xtask -- check; node scripts/adr-check.mjs --base ffd3e11; tsc --strict on npm/plugin.d.ts. The three Node-backed transport_flow tests pass against rutis-runtime 0.23.0: node_nested_execution_runs_the_pinned_native_tool_in_the_current_batch, node_tool_binding_transfers_pinned_handlers_in_the_native_owner and node_file_reads_round_trips_a_native_binding_used_by_write.

GitHub: dependencies passed; verify (linux) was still pending at review time; macos-native was queued; web, windows-cli and acp-registry skipped.

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

The earlier concerns about nested call ownership and identity, cancellation and settlement, and preserving pinned bindings are addressed on this revision.

P2 · Preserve invocation order for child effects. The ToolExecutor contract promises that close returns effects in invocation order. The previous implementation assigned an ordinal when the gate admitted each invocation. The current implementation sorts by the Timeline sequence assigned inside each child task, which can differ from admission order for parallel calls. That order matters to effect projection during compaction, which keeps the last effect for a given path or command. Please preserve the admission ordinal when returning and projecting confirmed effects, and add an ordinary functional regression that verifies the order of distinguishable effects from parallel child calls.

On b82c49411294a0d66270f06b2a0ae666520afc6d, I verified the exact CI rustfmt command, strict TypeScript checking of the three fixtures, the ADR check, and six focused Code Mode and workspace-file regressions locally. CI run 44741836624 tested merge 5037420d8c3b2f139a63e9612ce7c19fb5a90389 against ffd3e11623267f15e11421aa419532e131da82cb. At submission, changes, macOS native, and dependency checks passed. Linux verify job 136307474340 passed build, lint, and boundary checks, then failed the compiled workspace step with three CLI TUI test failures. CI skipped its public Node bindings step after that failure.

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

Verdict: REQUEST_CHANGES.

This PR moves branch FileReads bindings, ToolBinding declarations and ToolExecutor nested execution behind branch data faces, so native file tools and Node callers use the owner's operations. The new commit at 02d6075 replaces the Timeline sequence with a batch-wide admission ordinal, so close and parent settlement return confirmed child effects in invocation order across gates. The ordering change is correctly serialized: NestedGate::start inserts the child id and takes ids.len() under the state lock before it spawns the child, and invoke holds that same lock (crates/dim-agent-capabilities/src/tool_executor.rs:86-97, :308-316). The live-parent check, cancellation and duplicate-id refusal, the five second close bound, and the dedupe against an already reported result are unchanged.

Findings

P2 - The formatting gate fails again, so the PR cannot merge. The new commit leaves the effect push split over four lines at crates/dim-agent-capabilities/src/tool_executor.rs:185-188, while rustfmt wants self.effects.lock().unwrap().push((ordinal, child_effects));. The verify job runs cargo fmt --all -- --check --config error_on_line_overflow=true as the first command of "Build and lint the Rust workspace" and failed on this diff (run 44777715684 job 136432171214). The same command locally prints the diff at line 182 and exits 1. The line 591 overflow from the earlier thread is fixed; this is a new diff introduced by 02d6075. Fix: run cargo fmt --all or collapse lines 185-188.

Optional P3, not blocking: the ordering fix has no regression that can detect a reordering. Every child result in the Node test declares the same FileWritten { path: "/fixture" } (crates/dim-app-server/tests/transport_flow/branch_typescript.rs:697), so the two-effect assertion at :796-807 passes for admission order, Timeline order, or any permutation. The Rust tests cover only the step barrier (crates/dim-agent-capabilities/src/tool_executor.rs:1325-1405). Failure scenario: a later change reverts to sequence order, parallel children return effects in Timeline order, and compaction keeps the last effect per path (crates/dim-agent-capabilities/src/context_policy.rs:2031-2044), so a stale effect can win while tests stay green. Fix: derive echo's effect path from its input and assert two distinct paths in invocation order from parallel child calls.

Optional P3, not blocking: the rustdoc on ToolExecutor::open (crates/dim-agent-capabilities/src/tool_executor.rs:249-251) still names only the context match, while ToolExecution.md now also requires a running parent and a batch-unique child id. A caller reading only the rustdoc can pass an unknown parent and get the generic "no current tool batch accepts a Code Mode child" refusal. Fix: add those two preconditions there.

Upheld from the previous round: the line 591 overflow remains fixed, the live-parent and settlement guarantees still hold at this head, and the batch-end drain remains covered by the parent settlement test.

Conflicts

  • origin/main e6833df: merge-tree clean. Changes since ffd3e11 are scheduler and Permission documentation work and do not touch these files.
  • #1907, #1902, #1953: merge-tree clean.
  • #1911: textual conflicts in crates/dim-app-server/tests/transport_flow/branch_typescript.rs (both append tests) and docs/design/service-faces.md (both edit the pending face rows).
  • #1910: conflicts in crates/dim-agent-capabilities/src/file_storage/face.rs, crates/dim-app-server/src/lib.rs, branch_typescript.rs, docs/architecture/rust-agent/plugins/ToolExecution.md and docs/design/service-faces.md. Semantic point: #1910 removes file_storage::deserialize_name and uses crate::os_string::deserialize, while this PR imports the old helper at crates/dim-agent-capabilities/src/workspace_tools/file_reads/face.rs:12 and :19 and re-exports it at crates/dim-agent-capabilities/src/file_storage.rs:34, so whichever merges second must switch the import and drop the re-export.
  • #1908: textual conflict in crates/dim-app-server/src/lib.rs (both edit the same register_faces list).

Verification

At 02d6075 in the isolated checkout: cargo check --workspace --all-targets --locked passed with no warnings; cargo clippy --workspace --all-targets --locked -- -D warnings passed; cargo test -p dim-agent-capabilities passed (709 tests); cargo test -p dim-codemode passed (25 tests); cargo run --locked -p xtask -- check passed; node scripts/adr-check.mjs --base origin/main passed; tsc --strict on npm/plugin.d.ts passed; node_nested_execution_runs_the_pinned_native_tool_in_the_current_batch passed against rutis-runtime 0.23.0. The exact CI fmt command fails as described.

GitHub at submission: dependencies and macos-native passed; verify (linux) failed on rustfmt; ci-ok failed on that result; web, windows-cli and acp-registry skipped.

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

The admission ordinal fixes the previous ordering concern in close. There is still one ordering gap in the new automatic settlement in run_parent: it sorts the confirmed child effects but leaves effects already reported by the handler in front of all recovered effects. If the handler reports a later child's effect and the earlier child's effect is recovered during settlement, those two are reversed in the final parent result. Compaction keeps the last effect for a path or command, so it can retain the older state. Please preserve admission order when merging child effects from both sources. A focused test with distinguishable effects on that path would verify the fix.

Three focused Code Mode tests and the ADR check passed. The separate formatting failure is already tracked in the peer review.

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

Verdict: REQUEST_CHANGES.

This PR moves branch FileReads bindings, ToolBinding declarations and ToolExecutor nested execution behind branch data faces, so native file tools and Node callers use the owner's operations. At e53ac59 rustfmt passes, the nested settlement at 87ef53f orders confirmed child effects by admission ordinal and removes effects the handler already reported before re-appending them, and the new test covers a later child effect that is already reported while an earlier one is recovered.

Findings

P2 - The new TextFileBinding wire shape contradicts the owner contract and open PR #1900.

Problem: The PR adds the first cross-language serialization and declaration of TextFileBinding. rawRevision is a 32-element number array and encodingSource omits the documented workspace value.

Failure scenario: A TS plugin reads a file through fsHost after #1900, where a binding carries rawRevision as a lowercase hex string, and passes it to fileReads.record. The bridge rejects the string where [u8; 32] expects a sequence, the binding is not recorded, and a following existing-file write is refused with text_binding_required. Separately, merging this PR and #1900 leaves both TextFileBinding declarations in npm/plugin.d.ts, and tsc --strict fails with TS2300 Duplicate identifier 'TextFileBinding'.

Evidence: crates/dim-agent-capabilities/src/workspace_tools/file_reads.rs:67-71 and npm/plugin.d.ts:820-826 versus the contract at docs/design/resource-faces.md:531-534 and the frozen baseline at crates/dim-agent-types/tests/fixtures/baseline/types/tool.ts:55-59. #1900 at its current head 8d2958d declares rawRevision: string and uses #[serde(with = "revision_hex")].

Fix: Serialize raw_revision as lowercase hex with a serde(with) module, declare rawRevision: string, and declare the documented workspace encoding source or update resource-faces.md §4.3 with maintainer agreement.

Optional P3 - The new ordering test cannot detect a return to Timeline order. nested-echo is awaited before nested-wait starts, so admission order and completion order coincide and the two-effect assertion passes for either. A Promise.all pair of echo calls with distinct ids would pin admission order.

Conflicts

  • origin/main 9d1d2e3: merge-tree clean.
  • #1899, #1902, #1903, #1904, #1905, #1906, #1907: merge-tree clean.
  • #1908, #1909, #1910: textual conflict in crates/dim-app-server/src/lib.rs (the same register_faces list).
  • #1909, #1910, #1911, #1912: textual conflict in crates/dim-app-server/tests/transport_flow/branch_typescript.rs (all append tests).
  • #1909, #1910, #1911, #1912: textual conflict in docs/design/service-faces.md.
  • #1912: textual conflict in docs/architecture/rust-agent/generated/local/services.json.
  • #1910: textual conflict in crates/dim-agent-capabilities/src/file_storage/face.rs and docs/architecture/rust-agent/plugins/ToolExecution.md.
  • #1900: textual conflicts in crates/dim-agent-capabilities/src/file_storage.rs, workspace_tools/files/edit.rs, files/read.rs, files/write.rs and crates/dim-app-server/src/lib.rs, plus the TextFileBinding shape above. #1900 replaces file_storage::deserialize_name with crate::os_string::deserialize, while this PR imports and re-exports the old helper (crates/dim-agent-capabilities/src/workspace_tools/file_reads/face.rs:6, crates/dim-agent-capabilities/src/file_storage.rs:34); whichever merges second must switch the import and drop the re-export.

Verification

At e53ac59 in an isolated checkout with HOME, TMPDIR, XDG and target directories under the data directory: cargo fmt --all -- --check --config error_on_line_overflow=true passed; cargo check --workspace --all-targets --locked passed; cargo clippy --workspace --all-targets --locked -- -D warnings passed; cargo test -p dim-agent-capabilities --lib passed (70 tests); cargo test -p dim-agent-capabilities --test capabilities_flow passed (631 passed, 4 ignored); cargo test -p dim-codemode passed; cargo run --locked -p xtask -- check passed (service catalog passed); node scripts/adr-check.mjs --base origin/main passed; tsc --strict on npm/plugin.d.ts passed; the three Node-backed transport_flow tests passed against rutis-runtime 0.23.0.

GitHub at e53ac59: changes, static-checks and macos-native passed; verify (linux) was still in progress at review time; dependencies, web, windows-cli, scripts and acp-registry skipped.

Comment thread npm/plugin.d.ts
}

export interface TextFileBinding {
rawRevision: number[];

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: rawRevision is a number array, but the accepted TextFileBinding shape is a lowercase hex string (docs/design/resource-faces.md:531, crates/dim-agent-types/tests/fixtures/baseline/types/tool.ts:56), and open PR #1900 declares and implements string with revision_hex. crates/dim-agent-capabilities/src/workspace_tools/file_reads.rs:67-71 serializes [u8; 32] as 32 numbers, and encodingSource here also omits the documented workspace value (resource-faces.md:534). Failure: a TS plugin that passes the binding returned by fsHost.read after #1900 to fileReads.record is rejected by the bridge (invalid type: string, expected a sequence), so the file is not bound and a following write fails with text_binding_required; merging both PRs also leaves two TextFileBinding declarations and tsc --strict fails with TS2300. Fix: serialize raw_revision as lowercase hex with a serde(with) module, declare rawRevision: string, and declare the documented workspace source or update resource-faces.md §4.3 with maintainer agreement.

@eric8810

Copy link
Copy Markdown
Collaborator Author

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

@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