Repository navigation
Move Session admission, faults and branch opening to owners - #1910
Conversation
zerob13
left a comment
There was a problem hiding this comment.
The owner migration needs three lifecycle fixes before merge. The findings below are from static review of a979097486e0c724ecf1ab1939ba6a7b0a4a41f4 against main at 253779557538e8a5fb9fa6f75617bed1ddd36847.
- Enforce Session containment before admitting a loader child.
SessionLoader::createpasses the requested group to rutis using the Session context. Rutis resolves the group’s configured parent by walking up from that context, so the anchor alone does not ensure that Session teardown owns the resulting instance. Check the resolved parent as part of admission, before the loader can start any child. The two-Session fixture verifies removal ownership for an already nested child. SessionLoader::create · rutis parent resolution - Cancel and settle foreign opening work before rollback.
registerOpeningstores a callback without the registering row’s generation or a cancellation signal. On timeout or close, dropping the receipt wait does not settle the foreign Promise, and rollback can start while the callback still owns work. Tie each receipt to its row generation, signal cancellation on abort, and make teardown settle the admitted work before disposing the branch. The new Node fixture covers immediate rejection. The passing native Prompt lifecycle tests cover cancellation and join for native work. Registration · Opening and rollback - Reject a recorded startup fault before publishing Ready. A part can report a non-storage fault during startup and still finish assembly. The Agent inserts
Entry::Readyand activates the Session before the supervisor handles the recorded fault, so creation can report success and bypass durable startup rollback. Make the publication decision check the recorded fault and route it through the existing creation failure and rollback path. The current fixture promotes its report to a storage fault during startup. Agent publication and rollback · Fault fixture
MCP interoperability. Publication serializes resolved settings and the child factory reads them back through the stored-document decoder. The expansion contract permits an empty resolved bearer value, which the transport configuration accepts and the stored decoder rejects. That changes which entries publication can apply. Keep resolved settings in the MCP owner and carry a definition ID through the generic loader. Publication · Factory · Decoder · Expansion contract
Verification. On the pinned head, 12 native admission tests, five Node-backed flows, four native prompt-opening tests, two stop/close cleanup tests, one MCP durable settings flow, the packed SDK tests, strict fixture TypeScript checks, ADR check, and whitespace check passed.
Formatting. The CI-equivalent cargo fmt --all -- --check --config error_on_line_overflow=true failed on two lines. SubmitChecks · SessionLifecycle
GitHub CI at 11:47:47 UTC on November 20. Run 44728318199 was queued. changes and dependencies succeeded, verify was queued, and web, windows-cli, and acp-registry were skipped. CI run
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
Review at a979097
The owner move is directionally right. BranchLifecycle keeps the opening receipts and seals them in the same place, SessionLifecycle keeps the single FaultReporter and the same supervisor, and Skills and MCP keep their per-Session instances behind the loader. The targeted native tests for the changed paths pass. One workspace target does not compile, and the fault contract row this PR edits contradicts the method it documents.
I agree with zerob13 on the containment, startup-fault and MCP points; the fmt failure reproduces at the same two lines. I would drop the foreign-opening cancellation point: dropping the receipt future already cancels the bridge call through CancelOnDrop, and the registering row's unload releases its reference, so it does not describe a concrete leak.
P1: tests/integration no longer compiles
Problem. SessionLoader::create_instance is removed, but tests/integration/tests/extensions.rs:1519 still calls it.
Failure scenario. cargo check --workspace --all-targets exits 101 with E0599: no method named create_instance found for struct Arc<dim_agent_runtime::SessionLoader>. CI's clippy and build step fails before any test runs, so the PR cannot pass verification.
Evidence. crates/dim-agent-runtime/src/scope.rs:88-118 now exposes only create and remove. The caller is in tests/integration/tests/extensions.rs:1519, outside the PR diff, so the removal did not update it.
Fix. Keep a native-only passthrough:
#[service(skip)]
pub fn create_instance(&self, group: &str) -> rutis_loader::edit::CreateInstance<'_> {
self.loader.create_instance(&self.anchor, group)
}A rename to create is not equivalent: create returns NotReady when any created row is not Active, while the test deliberately creates a group with Pending, Failed and unresolved optional rows and asserts they survive.
P2: the fault row contradicts failure
Problem. docs/design/contracts/runtime-owner-operations.md:29, a line this PR edits, still says failure({}) -> AgentError or null. The method returns Option<SessionFault> (crates/dim-agent-runtime/src/config.rs:443-445), and the generated binding says Promise<SessionFault | null> (npm/branch-services.d.ts:905).
Failure scenario. A plugin author follows the accepted contract, types the result as AgentError, and reads fields the external-tagged SessionFault union does not have ({invalidInput: string}, {storage: string}, ...). The same row documents the new observeFault and release, so the old type is not an obvious pre-PR leftover.
Evidence. The doc line, the Rust signature, the generated declaration, and crates/dim-agent-runtime/src/error.rs:55-77.
Fix. Change AgentError or null to SessionFault or null.
P3: the TypeScript binding docs list the old lifecycle methods
Problem. Four binding docs still show sessionLifecycle as activated/closing/hold/release and branchLifecycle as activated/closing. They omit reportFault, failure, observeFault, release's observation role and registerOpening.
Failure scenario. A plugin author follows the binding docs, cannot discover the new calls, and writes against a table the generated npm/branch-services.d.ts has outgrown. The docs and the shipped types disagree in the same release.
Evidence. docs/design/session-typescript.md:322, docs/design/branch-typescript.md:53, docs/typescript-plugin-authoring.md:771 and :849, docs/design/plugin-contract.md:119 and :124.
Fix. Add the new methods to those tables; the generated declarations already carry the names and signatures.
Verification
cargo fmt --all -- --check --config error_on_line_overflow=true fails at crates/dim-agent-capabilities/src/input_queue/face.rs:113 and crates/dim-agent-runtime/src/config.rs:519. cargo check --workspace --all-targets fails only at tests/integration/tests/extensions.rs:1519. xtask check, the MCP publication tests, the integration prompt and skills tests, and the transport and capability suites pass except for two tests that fail identically on origin/main (branches::a_line_cut_before_main_consumes_a_removed_rule_does_not_keep_it_live and hooks_flow::the_session_start_block_is_still_in_context_after_compaction).
The Node fixtures did not run locally because runtime/node_modules is absent and DIM_TEST_NODE/DIM_TEST_JS_RUNTIME are unset. The four new ignored tests and the fixture TypeScript checks are unverified here; CI's Node job covers them once the build passes. At review time changes and dependencies passed and verify was pending.
The branch is based on current origin/main (2537795), so it does not conflict with main. Sibling #1292 PRs #1911, #1909, #1908, #1907 and #1904 touch the same runtime, catalog, generated and npm files, so expect rebase conflicts in names.rs, lib.rs, session_typescript.rs and the generated snapshots whatever the merge order.
|
Updated to main at The real Node opening flow registers two receipts. One waits, the other refuses after the first has started. The test verifies that required row cleanup joins its outstanding operation before failed creation returns. This passes on main's rutis 0.23 runtime. The startup fault issue was independently reproduced on main using only the native FaultReporter, a required Session part and a fresh MemoryTimelineStore. Creation returned a Session that already had a fault, and the creation record survived close. The Agent publication and rollback change is tracked separately in #1955. Verified on the synchronized branch with the two Node opening/containment flows, the 12 MCP publication tests and the generated catalog and declarations. |
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
Review at ba79ec4
Approve. The four follow-up commits close the round-1 blockers and keep the owner move intact.
Prior findings
- The workspace target compiles.
SessionLoader::createreplacescreate_instancewith equivalent semantics: the Active-row gate applies only to registered Session extension groups (crates/dim-agent-runtime/src/scope.rs:125-133), so the host-addedlate-nestedgroup attests/integration/tests/extensions.rs:1519still creates its Pending, Failed and unresolved optional rows.nested_instances_preserve_optional_rows_and_cleanup_across_create_restore_and_failurepasses. - The loader checks the group's configured parent before creation (
crates/dim-agent-runtime/src/scope.rs:102-110).node_session_loader_creates_and_removes_only_its_own_instanceconfirms thesessiongroup is refused and that a second Session cannot remove the first Session's instance. Skills and MCP remain direct Session children. - MCP publication keeps the resolved
McpServerPluginin the publication owner instead of encoding it into loader data (crates/dim-app-server/src/mcp/publication.rs:154-155,745-759). The empty resolved bearer is admitted, andpublication_admits_a_bearer_that_expands_to_emptypasses. - The fault row now says
SessionFault or null(docs/design/contracts/runtime-owner-operations.md:29), the TypeScript lifecycle tables list the new methods, and the two fmt overflows are gone.
I withdraw the startup-fault finding as a blocker for this PR. It reproduces on ffd3e116 with the native fault reporter, so the publication order is not introduced by this change; #1955 tracks the fix. The foreign-opening point stays withdrawn: finish_opening is the same receipt collector moved to BranchLifecycle, dropping the receipt future still cancels the bridge call, and the new Node flow verifies the registering row joins its outstanding work during rollback.
P3 (optional)
docs/design/plugin-contract.md:119 and docs/zh/design/plugin-contract.md:108 join two sentences: ... or that row's unload reportFault reports a fault .... Add a semicolon or period after unload.
Verification
Passed locally: cargo check --workspace --all-targets --locked, cargo clippy --workspace --all-targets --locked -- -D warnings, cargo fmt --all -- --check --config error_on_line_overflow=true, cargo run --locked -p xtask -- check, node scripts/adr-check.mjs --base ffd3e116, and git merge-tree --write-tree against ffd3e116.
Passed targeted tests: runtime unit 5, capabilities unit 71, app-server MCP unit 51, mcp_flow 27, mcp_session_flow 48, integration extensions 20, prompt_lifecycle 22, session_lifecycle 9, skills 27, tool_binding 16. With DIM_TEST_NODE, DIM_TEST_JS_RUNTIME and DIM_TEST_RUTIS_SDK set from runtime/node_modules, all four new ignored Node tests pass: branch opening refusal, Session fault observation, Session loader isolation, and submit check admission. No existing assertion was weakened; the fault test intentionally accepts the current create-success behavior while #1955 is open.
CI at the reviewed head: changes, dependencies and macos-native succeeded, verify (linux) was still running, and web, windows-cli and acp-registry were skipped. The branch is mergeable against ffd3e116. Siblings #1911, #1909, #1908, #1907, #1904 and the later owner moves still edit the same runtime, catalog, generated and npm files, so expect rebase conflicts whatever the merge order.
Not rerun locally: cargo test --workspace, the full CLI and TUI profiles, and the complete ignored Node suite. CI covers them.
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
Review at 332cb34
Approve. The only commit since ba79ec4 fixes the round-2 punctuation note, and every other file is identical to the approved head.
Prior finding
The P3 is fixed in both languages. docs/design/plugin-contract.md:119 now ends the hold sentence after unload and starts reportFault as its own sentence; docs/zh/design/plugin-contract.md:108 splits the clauses the same way. The row matches the face: SessionLifecycle exposes reportFault, failure, observeFault and release (crates/dim-agent-runtime/src/config.rs:440-556), observeFault returns an id, release ends a hold or observation, and unload releases both. The generated declaration agrees (npm/branch-services.d.ts:903-935), and runtime/fixtures/session-fault.ts covers the initial null failure, first-fault precedence, storage precedence, delivery to the subscription, and release returning true then false.
Verification
git diff ba79ec4a..332cb346 touches only those two doc lines; the full diff still has the same 58 files as the reviewed head. git merge-tree --write-tree ffd3e116 332cb346 is clean. cargo fmt --all -- --check --config error_on_line_overflow=true, cargo run --locked -p xtask -- check (module boundaries, plugin documents, service catalog, declarations, plugin locks, comment links) and git diff --check origin/main...HEAD pass. The change is docs-only, so the targeted test evidence from ba79ec4 still applies.
CI at this head: changes and dependencies succeeded; macos-native and verify (linux) were queued; web, windows-cli and acp-registry were skipped. The PR is open, mergeable against ffd3e116, and its head is still 332cb346.
# Conflicts: # crates/dim-agent-runtime/src/error.rs
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
Review at 9ae3f78
Request changes. The head is the approved 332cb346 merged with main 9d1d2e39. The merge is mechanical apart from one content conflict, but the merged Rust type leaves the committed TypeScript declaration stale, so CI fails.
P1: regenerate the service declaration after the merge
Problem. Main added NotOpener and LimitReached to BranchRefusal (crates/dim-agent-runtime/src/error.rs:153-156), and this PR makes the enum serializable (error.rs:136-137). The generated declaration still lists only the four older variants and main's previous doc comment (npm/branch-services.d.ts:855-863).
Failure scenario. cargo run --locked -p xtask-check -- check stops with npm/branch-services.d.ts: service declarations are stale, so the static-checks job fails (run 44916886052, job 136884448599, step "Run pure static repository checks"), and the verify job runs the same check first through target/debug/xtask check (.github/workflows/ci.yml:96-100, :278; xtask/src/main.rs:63-66). If the file shipped, a TypeScript plugin switching on SessionFault.branchRefused.refusal would be typed only for already_default, not_selectable, protected and cannot_end, while the merged tree emits branch_not_opener and branch_limit_reached (crates/dim-agent-capabilities/src/timeline_tree.rs:1740-1754; the design codes are at docs/design/timeline-branches.md:452-453).
Evidence. The Rust enum, the stale union, and the checker that regenerates and compares the file (xtask/check/src/types.rs:65-75). Regenerating at this head adds exactly not_opener, limit_reached and main's doc comment, and all static checks then pass.
Fix. Run cargo run --locked -p xtask -- types at the merged head and commit npm/branch-services.d.ts. Do not hand-edit it.
Merge check
9ae3f788 has parents 332cb346 and 9d1d2e39. git merge-tree --write-tree 332cb346 9d1d2e39 differs from HEAD^{tree} only in the conflicted crates/dim-agent-runtime/src/error.rs; the resolution keeps main's documentation and both new variants plus this PR's serde derives, which is the intended combination. Of the 58 PR files, only error.rs and docs/design/branch-typescript.md differ from the approved head; the second is main's automatic path update to xtask/check/src/types.rs. There are no conflict markers, and git diff --check origin/main...HEAD is clean.
Prior findings
- The loader still checks the group parent before creation (
crates/dim-agent-runtime/src/scope.rs:102-109), and MCP publication keeps the resolvedMcpServerPluginin its own map (crates/dim-app-server/src/mcp/publication.rs:155,:747-751). The round-1 containment and empty-bearer findings stay fixed. - The startup-fault ordering remains #1955; the Node fault test still accepts either a creation failure or a close failure, as in the previous round.
- The foreign-opening point stays withdrawn: dropping a receipt future still cancels the bridge call, and the Node opening flow joins the registering row's work during rollback.
- The round-2 punctuation finding is fixed at
docs/design/plugin-contract.md:119anddocs/zh/design/plugin-contract.md:108.
Verification
Passed locally at the merged head: cargo fmt --all -- --check --config error_on_line_overflow=true, cargo clippy --locked -p xtask-check --all-targets -- -D warnings, and cargo test --locked -p xtask-check. cargo run --locked -p xtask-check -- check fails on the stale declaration; after regenerating it, the same command passes module boundaries, crate boundaries, plugin documents, declarations, plugin locks, comment links and literal_main. I did not rerun the workspace or Node suites: the delta is the merge only, and the round-3 evidence still applies. The runtime-assembled catalog check did not run because xtask check stops at the declaration first.
CI and cross-PR
At 9ae3f788, changes passed, static-checks failed, verify (linux) and macos-native are still running, and the remaining jobs were skipped. The PR is open and mergeable against 9d1d2e39.
Sibling owner-move PRs #1911, #1912, #1913, #1909, #1908 and #1907 still edit the same runtime, generated and declaration files. #1911 adds AgentError::variant in error.rs, so whichever lands first forces a rebase. No semantic conflict with current main.
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
Review at a1fad30
Approve. a1fad301 adds the declaration regeneration the round-4 review asked for, and the full merged diff still holds together.
Round-4 blocker fixed
The new commit touches only npm/branch-services.d.ts (7 insertions, 2 deletions). It adds not_opener and limit_reached (npm/branch-services.d.ts:867-868) and main's updated commentary (:856-860). The file is generated, not hand-edited: xtask-check passes service declarations at this head, and that check compares the committed file byte for byte with the generator output (xtask/check/src/types.rs:65-75). static-checks is green.
Prior findings
- The round-1, round-2 and round-3 fixes remain: the loader checks the group parent before creation (
crates/dim-agent-runtime/src/scope.rs:102-109), the Active-row gate applies only to registered extension groups (:125-133), MCP keeps the resolved plugin in the publication owner (crates/dim-app-server/src/mcp/publication.rs:746-752,:676-686), and the fault row saysSessionFault or null(docs/design/contracts/runtime-owner-operations.md:29). - The startup-fault ordering stays #1955; the Node fault test still accepts either a creation failure or a close failure.
- The foreign-opening point stays withdrawn.
Optional
I left one optional note inline on the new BranchRefusal declaration. It does not change the wire values the bridge sends; it concerns the comment above the union.
Verification
At a1fad301 I ran the existing xtask-check binary and the xtask binary built at the approved head against this worktree, with the isolated home. Module boundaries, crate boundaries, plugin documents, the runtime-assembled service catalog, service declarations, plugin locks, comment links and literal_main all pass. The declaration check reads the worktree's dim-app-server source, so it is valid at this head; the catalog check runs the approved head's compiled assembly, and main's merged files do not change service definitions. I also typechecked the packed declarations (npm/plugin.d.ts with npm/branch-services.d.ts) under tsc --strict, and git diff --check origin/main...HEAD is clean.
The merge of 332cb346 and 9d1d2e39 differs from git merge-tree --write-tree only in the resolved crates/dim-agent-runtime/src/error.rs, which keeps main's variants and comment plus this PR's serde derives. There are no conflict markers, and every file in the diff exists at the head.
I did not rerun the workspace or Node suites: the delta since the round-3 evidence is the merge, which does not change the PR's faces, plus the generated declaration.
CI and cross-PR
At a1fad301, changes, static-checks and macos-native succeeded, verify (linux) is in progress, and dependencies, web, windows-cli, scripts and acp-registry were skipped. The PR is open and mergeable against 9d1d2e39. Sibling owner-move PRs #1911, #1912, #1913, #1909, #1908 and #1907 still edit the same runtime, generated and declaration files, so expect rebase conflicts whatever the merge order.
| } | ||
|
|
||
| /** | ||
| * Why the tree refused an operation on a line, named the way the protocol |
There was a problem hiding this comment.
Optional. The comment says these values are the codes session.branch_set_default answers as its appError and the codes the branch tool answers as its own result, but the union values are the shortened serde names (:862-868). The protocol codes are branch_already_default, branch_not_selectable, branch_target_protected, branch_cannot_end, branch_not_opener and branch_limit_reached (crates/dim-agent-runtime/src/error.rs:161-169; docs/design/timeline-branches.md:452-453). Problem: a TypeScript plugin that observes a fault and forwards branchRefused.refusal as the protocol's appError sends not_opener where clients expect branch_not_opener. Evidence: the union, BranchRefusal::code(), and the design codes. Fix: since SessionFault is new in this PR, serialize each variant to the value code() returns, or correct the comment in error.rs to say the binding spells the variant names. Do not hand-edit the generated file.
zerob13
left a comment
There was a problem hiding this comment.
The owner migration addresses the PR-specific Session containment, foreign opening settlement, and MCP ownership findings. The refreshed service declarations match Rust, and the exact merged tree passed Linux workspace and Node verification, macOS native verification, static checks, and ci-ok. The startup fault behavior also exists on main and remains tracked separately in #1955; this approval does not mark that issue fixed. Exact CI.
Refs #1292
Implementation status
Callers and operations
Final API
sessionLoader.create({group, definitionId, instanceData}) → {instanceId};remove({instanceId}) → void. The Session anchors each instance. Skills supplies its content definition; MCP supplies its connection definition and resolves driver and credentials locally.register(name, check) → void;check({entry, branchId, user?, mode}, cancelled) → proceed{blocks, warnings} or block{message}. Run in name order through the first block. Interrupted checks write nothing.sessionLifecyclereportFault(error) → void,failure({}) → SessionFault or null,observeFault(listener) → id,release(id) → boolean. First fault wins with existing storage-fault precedence.branchLifecycleregisterOpening(completion) → void. Opening waits for admitted completions under its existing deadline and propagates their errors.sessionLifecycle.activated/closing/hold/release,branchLifecycle.activated/closing,dispatcher.listen/consume/committed.Acceptance
sessionLoader,submitChecks,faultReporter,branchOpening.Local validation passed for Skills (27), MCP publication (11), MCP integration (27), and the Node loader test that creates a child, attempts removal from a second Session, and removes it from its owning Session. The Node Session flows, admission and opening tests, strict TypeScript fixture, Clippy and xtask checks also passed.
Owner contract · Baseline catalog