Repository navigation
Conversation
# Conflicts: # npm/branch-services.d.ts
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
Refs #1292. This migrates branch loop control, Prompt adoption and the selected-branch consumers to their owners, and removes configureControl, promptSourcesBranch and configurationPublisher.
Verdict: REQUEST_CHANGES for one P2 in the new contextPreparation.publish face. The other owner migrations, the generated catalog and the declarations are consistent, and the targeted tests pass.
P2: contextPreparation.publish can commit a batch the owner would refuse
Problem. The new data face builds before from request.adopted.prompts and commits with |_| Ok(()) (crates/dim-agent-capabilities/src/context_preparation.rs:60-72). The owner's other publication paths check more. adopt_guide refuses a closing branch and rechecks the phase under the commit lock (context_preparation.rs:319-343), and Prompt::adopt passes a register closure that rejects a closed or superseded operation (crates/dim-agent-capabilities/src/prompt.rs:616-635). Prompt also has no public read for the checkpoint: adoptedConfiguration returns only the model (prompt.rs:1109-1114), so a foreign caller must supply adopted from outside. The new Node test gets it from native PromptSnapshot state (crates/dim-app-server/tests/transport_flow/branch_typescript.rs:622-627) and runtime/fixtures/branch-prompt.ts publishes it; that does not show a foreign caller can produce the state on its own.
Failure scenario. A branch part calls publish while the branch starts closing, or after another adoption moved the prompt. The batch commits a PromptChanged or ContextConfigured whose System is composed from the stale checkpoint (context_preparation.rs:256-283). The next request can lose entries adopted after the checkpoint; if the batch commits after close, the branch records a System it never ran with. The acceptance item for close and prompt supersession is unchecked.
Fix. Pass a register closure that returns Cancelled when self.closing() is true, matching adopt_guide, and either validate the checkpoint revision against Prompt's projection or keep publish owner-only and document that adopted must be the Prompt projection. If the face stays public, add a public read for the checkpoint.
P3 findings
publish's fault still names the removedConfigurationPublisher(context_preparation.rs:88). UseContextPreparation.crates/dim-app-server/src/connection.rs:1573,:1629,:1658and:1761still readPromptSnapshotdirectly while the PR moves the other Agent configuration, attachment, Collaboration, Provider startup and Report consumers toprompt.adoptedConfiguration. Migrate these or state why the state cell is the intended read; the acceptance item for the same owner remains unchecked.- The new
Emptyrequest type renamed the existing SessionsEmptytoEmpty2in npm/branch-services.d.ts:1186 and :1200. This changes the public TS alias used bySessionPermissions.permissionDefaults; name the Prompt request type explicitly if that churn is not intended. - Stale design references to the removed publisher remain in docs/design/appserver/restore-shared-read.md:105, docs/zh/design/appserver/restore-shared-read.md:63 and docs/design/resume-read-design.md:133. The research and example pages also name it but are historical.
Verification
- Local:
cargo fmt --all --check,node scripts/adr-check.mjs --base origin/main,cargo run -p xtask -- check,cargo checkandcargo clippy -D warningsfor dim-agent-runtime, dim-agent-capabilities, dim-app-server and dim-report pass. - Targeted tests pass:
session_language_flow(13),report_flow(5),prompt_lifecycle(22),wait_protocol(1),interrupt_flow::stop_turn_stops_only_the_open_turn_it_names,context_flow::manual_compaction::repeated_and_concurrent_requests_join_the_outstanding_command, and the CI-failing branch_events test passes locally in 1.22s. - CI:
verify (linux)failed onbranch_events::restored_task_branches_are_discovered_locally_and_named_stops_preserve_the_leader(timeout) and three dimcode TUI tests; the branch_events test passes locally and the TUI failures are unrelated.macos-nativepassed;ci-okfailed. The new Node tests are ignored in the regular suite, and the Node-backed step did not run after the job failed, so the two new owner tests have no CI result in this run.
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
Refs #1292. This PR moves branch loop control, Prompt configuration and the selected-branch consumers onto their owners, and removes configureControl, promptSourcesBranch and configurationPublisher.
Verdict: REQUEST_CHANGES. d4efbef correctly closes the closing-branch race from round 1 and fixes the stale fault name, and the rest of the owner migration, the generated catalog and the declarations are consistent. The other half of the round 1 P2 is still open: the public contextPreparation.publish still accepts a Prompt checkpoint from its caller and commits it without an owner check.
P2 (narrowed): contextPreparation.publish trusts a checkpoint no owner produces and Prompt does not validate
Problem. The new gate at crates/dim-agent-capabilities/src/context_preparation.rs:71-79 refuses a publication once the branch is closing, but publish still builds before from request.adopted.prompts (crates/dim-agent-capabilities/src/context_preparation.rs:64), writes previous: before.revision (:252), and composes the System from that snapshot (:264, :271-289). Prompt's live projection applies a PromptChanged without comparing data.previous with its snapshot (crates/dim-agent-capabilities/src/prompt_state.rs:182-184 and :88-119; crates/dim-agent-capabilities/src/prompt/recovery.rs:640-696); only the checkpoint recovery path checks it (crates/dim-agent-capabilities/src/prompt/recovery.rs:1203-1208). No public data face produces PromptCheckpointState: the shipped prompt face has no read for it, and adoptedConfiguration returns only Option<ModelConfiguration> (crates/dim-agent-capabilities/src/prompt.rs:1109-1114; docs/architecture/rust-agent/generated/catalog.md:115). The new Node test obtains the checkpoint from native test state and passes it through RPC params (crates/dim-app-server/tests/transport_flow/branch_typescript.rs:622-627, :649-656), so it does not show that a foreign caller can produce one. The operation also bypasses Prompt's serial adoption ownership: start records source owners and supersedes earlier operations (crates/dim-agent-capabilities/src/prompt.rs:301-333), while a direct publish records nothing, so a pending configure still owns its source and compares its loaded value with the current projection (crates/dim-agent-capabilities/src/prompt.rs:544-613).
Failure scenario. A branch part publishes twice with one cached checkpoint, or publishes with a checkpoint older than the current Prompt state. If the second change renders the System, the batch composes ContextConfigured.system from the cached snapshot (crates/dim-agent-capabilities/src/context_preparation.rs:264-289), so the next request loses a System entry adopted in between. If a prompt.configure for the same source is pending, the part's publish does not supersede it, and the configure's older loaded value can be adopted after the publish (crates/dim-agent-capabilities/src/prompt.rs:597-613). This is the case docs/design/prompt-state-read.md:67 rules out: an older Snapshot must not overwrite newer state.
Evidence. crates/dim-agent-capabilities/src/context_preparation.rs:60-80, :112, :249-289, :307; crates/dim-agent-capabilities/src/prompt.rs:301-333, :544-557, :586-613, :650-676, :1109-1114; crates/dim-agent-capabilities/src/prompt_state.rs:88-119, :182-184; crates/dim-agent-capabilities/src/prompt/recovery.rs:640-696, :1203-1208; crates/dim-app-server/tests/transport_flow/branch_typescript.rs:622-627, :649-656; npm/branch-services.d.ts:321-341; docs/architecture/rust-agent/plugins/ContextPreparation.md:91.
Fix. Do not accept adopted across the public face. Route publication through the snapshot owner: a prompt operation that passes its own projection.snapshot and configuration to publish_registered, or frozen content through the existing prompt.configure Loaded form. If the public face must stay on ContextPreparation, add a public Prompt read that returns the checkpoint, make Prompt's live projection reject a PromptChanged whose previous is not its current revision, and document the precondition and the cancel error in the plugin page and owner contract. Dropping publish and awaitPublished from this PR and landing them with #1912 is the smallest option.
Verified fixed in d4efbef. The closing gate is correct. The register closure runs under the Timeline commit lock (crates/dim-agent-runtime/src/core/timeline.rs:279-280, :515-517), the branch phase advances to Closing synchronously before the close task (crates/dim-agent-runtime/src/timeline_context.rs:758; crates/dim-agent-runtime/src/assembly.rs:1477), and Timeline::close sets data.closing under the same lock (crates/dim-agent-runtime/src/core/timeline.rs:970-981). A publication admitted before Closing is allocated before appends stop, and close waits for it to publish; one admitted after is refused. Cancelled matches adopt_guide (crates/dim-agent-capabilities/src/context_preparation.rs:340-350), Prompt's configure path maps it to Superseded (crates/dim-agent-capabilities/src/prompt.rs:639-641), and the adoption queue does not report Cancelled as a fault (crates/dim-agent-capabilities/src/prompt.rs:1078-1088), so the owner does not turn it into a user-visible fault.
Round 1 findings
- P2,
contextPreparation.publishcan commit a batch the owner would refuse: partially fixed. The closing half is fixed; the checkpoint and serial-adoption half is the P2 above and still blocks. - P3, the fault named the removed
ConfigurationPublisher: fixed in d4efbef. Withdraw this finding. - P3,
crates/dim-app-server/src/connection.rsstill readsPromptSnapshotdirectly: open, item 3 below. - P3, the new
Emptyrequest type renamed the existing SessionsEmptytoEmpty2: open, item 2 below. - P3, stale design references to the removed publisher: open, item 4 below.
P3 findings (optional)
- The new gate has no test. The two new Node tests (
crates/dim-app-server/tests/transport_flow/branch_typescript.rs:560and:600) cover the AgentLoop face and the unchanged and changed publish paths, but neither races a close. Add one flow test that starts a publication while the branch closes and assertsCancelledwith noPromptChangedorContextConfiguredafter the close. This is also the unchecked acceptance item "Verify admitted branch calls through close". Empty2is still the public alias forSessionPermissions.permissionDefaults(npm/branch-services.d.ts:1186,:1200). Name the Prompt empty request explicitly or accept the churn.crates/dim-app-server/src/connection.rsstill readsPromptSnapshotdirectly at:1573,:1629,:1658and:1761, whilecrates/dim-app-server/src/agents/configuration.rs:91-98,crates/dim-app-server/src/collaboration.rs:1975-1980,crates/dim-app-server/src/provider/startup.rs:559-604,crates/dim-app-server/src/connection/subscription.rs:560-563andcrates/dim-report/src/evidence.rs:386-390now useadoptedConfiguration. Migrate these or state why the state cell is the intended read.- Stale design references to the removed publisher remain at
docs/design/appserver/restore-shared-read.md:105,docs/zh/design/appserver/restore-shared-read.md:63anddocs/design/resume-read-design.md:133. One-word updates toContextPreparationare enough.
Verification
- Local pass:
cargo fmt --all -- --check --config error_on_line_overflow=true;cargo check --workspace --locked(one unrelated manifest warning for the unusedrustls-native-certsdependency in dim-app-server);cargo clippy --locked -p dim-agent-runtime -p dim-agent-capabilities -p dim-app-server -p dim-report --all-targets -- -D warnings;cargo run --locked -p xtask -- check(743 modules, 26 plugin documents, service catalog, declarations, locks, links and literal main pass);node scripts/adr-check.mjs --base origin/main(86 changed files). - Targeted tests pass:
prompt_lifecycle22,session_language_flow13,report_flow5,wait_protocol1,branch_events::restored_task_branches_are_discovered_locally_and_named_stops_preserve_the_leader,context_flow::manual_compaction::repeated_and_concurrent_requests_join_the_outstanding_command,interrupt_flow::stop_turn_stops_only_the_open_turn_it_names. - The two new Node tests are unverified locally:
runtime/node_modulesis absent, soDIM_TEST_JS_RUNTIMEcannot resolve. They are#[ignore]in the regular suite and have no Node-backed CI result yet. - CI:
macos-nativeanddependenciespass;verify (linux)is in progress;windows-cli,webandacp-registryare skipped. I did not wait. - Merge tree against
origin/main44f0dd4 is clean. Conflicts with open PRs: #1913 (branch_typescript.rs,docs/design/service-faces.md), #1910 (agent.rs,names.rs,session_typescript.rs,branch_typescript.rs, generated catalog and services,Prompt.md), #1917 (collaboration.rs), #1908 (app-serverlib.rs), #1906 (provider/startup.rs,npm/branch-services.d.ts). No conflicts with #1912, #1909, #1930, #1881 or #1905. #1912 states it depends on this PR and edits the samecontextPreparationservice but merges cleanly.
# Conflicts: # crates/dim-agent-capabilities/tests/flows.rs # tests/integration/tests/minimal_execution.rs
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
Refs #1292. This PR moves branch loop control, Prompt configuration and the selected-branch consumers onto their owners, and removes configureControl, promptSourcesBranch and configurationPublisher.
Verdict: APPROVE. The blocking P2 from d4efbef is closed at 3bb0a85. The public contextPreparation.publish is gone, publication is crate-private and fed only by Prompt's own projection, and cross-language changes go through prompt.configure, which keeps the closing gate and Prompt's serial source ownership. The four prior P3s are fixed and no P0-P2 remains.
The ownership and supersession bypass is closed
publish_registered is pub(crate) (crates/dim-agent-capabilities/src/context_preparation.rs:73) and its only callers pass Prompt's projection under the projection lock (crates/dim-agent-capabilities/src/prompt.rs:514, :660). AdoptedPrompt and PublishConfiguration are deleted, no public face accepts a PromptCheckpointState, and contextPreparation keeps only awaitPublished (docs/architecture/rust-agent/generated/catalog.md:109, npm/branch-services.d.ts:48-54). A caller can no longer commit a PromptChanged or ContextConfigured built from a checkpoint the owner did not take.
Cross-language changes use the new prompt.configure face (crates/dim-agent-capabilities/src/prompt.rs:1114). Both forms, targets and target/frozen-entry pairs, go through submit (:697-727), whose phase check runs before the request event and again in the register closure under the commit lock (:702-706, :716-720). A request admitted before Closing commits before appends stop and close waits for it; one that loses returns Cancelled without a write. Source ownership and supersession stay in start and consume_result (:301-333, :549-558), and the loaded value is compared with the owner's current projection before adoption (:586-613), so an older snapshot cannot overwrite newer state. The only writer sets previous from that projection (crates/dim-agent-capabilities/src/context_preparation.rs:209-225), so the missing previous comparison in the live projection is no longer a bypass.
Prior P3s
- The closing admission has a flow test:
overlapping_load_is_superseded_and_close_joins_cancellationdrivesprompt.configurewhilemainis closing, assertsErr(AgentError::Cancelled(_)), and asserts the branch sequence did not move (tests/integration/tests/prompt_lifecycle.rs:1208-1222). It passes. Empty2is gone. The Prompt reads usePromptRead(npm/branch-services.d.ts:470) and the SessionsEmptyis the onlyEmpty(:1121,:1135).connection.rsno longer readsPromptSnapshot: the four reads usePrompt::adopted_configuration(crates/dim-app-server/src/connection.rs:1573,:1626,:1652,:1755).- The stale publisher references are updated in
docs/design/appserver/restore-shared-read.md:105,docs/zh/design/appserver/restore-shared-read.md:63anddocs/design/resume-read-design.md:133.
Optional (non-blocking)
PromptConfigurationRequest::Loadedignores unknown fields whileConfigureUpdatedenies them (crates/dim-agent-runtime/src/contracts.rs:99-104). A caller that sends{sources: [[target, entry]], modle: {...}}is answeredadoptedwith the model unchanged:Targetsfails on the pair shape and serde acceptsLoadedleniently. Give the frozen form its owndeny_unknown_fieldsstruct payload. The inline note has the detail.docs/design/plugin-contract.md:140now says "aAgentLoopprovider"; use "an".- Three current design pages still name the removed
ConfigureControlas a negative requirement:docs/design/plugins/EnvironmentClients.md:11,docs/design/plugins/EnvironmentSettings.md:12and:111. Sayprompt.configureor "prompt configuration".
Verification
- Local pass:
cargo fmt --all -- --check --config error_on_line_overflow=true;cargo clippy --locked -p dim-agent-runtime -p dim-agent-capabilities -p dim-app-server -p dim-report --all-targets -- -D warnings;cargo check --workspace --locked;cargo check --locked -p dim-agent-aimux -p dim-goal --all-targets;cargo run --locked -p xtask -- check(743 modules, 26 plugin documents, service declarations, locks, links, literal main and service catalog pass);node scripts/adr-check.mjs --base origin/main(89 changed files); the crossing-service unit test. - Targeted tests pass:
prompt_lifecycle22,prompt_sources6,wait_protocol1,context_flow::manual_compaction11,interrupt_flow::stop_turn_stops_only_the_open_turn_it_names,session_language_flow13,report_flow5. - The two Node tests are unverified locally:
runtime/node_modulesis absent and they are#[ignore]in the regular suite. CIverify (linux)is the only job that runs them. - CI at 3bb0a85:
macos-native,static-checksandchangespass;verify (linux)is queued;windows-cli,web,dependencies,scriptsandacp-registryare skipped. I did not wait. origin/main9d1d2e3 is an ancestor of the head, so the merge tree against main is clean. Conflicts with open PRs: #1910 (agent.rs, names.rs, app-server lib.rs, session_typescript.rs, branch_typescript.rs, generated catalog and local services, Prompt.md), #1913 (branch_typescript.rs, service-faces.md), #1917 (collaboration.rs, connection.rs), #1908 (lib.rs), #1906 (lib.rs, provider/startup.rs), #1905 (lib.rs), #1970 (prompt.rs, collaboration.rs, connection.rs; it adds a secondPrompt::adopted_configurationwith a different signature, so reconcile the two), #1963 (collaboration.rs, connection.rs). Clean with #1912, #1909, #1904, #1903, #1902, #1900, #1899, #1967 and #1977. #1881's merge conflict is against main already and does not involve this PR's files.
| #[serde(untagged)] | ||
| pub enum PromptConfigurationRequest { | ||
| Targets(ConfigureUpdate), | ||
| Loaded { |
There was a problem hiding this comment.
Loaded does not deny unknown fields, unlike ConfigureUpdate (crates/dim-agent-runtime/src/contracts.rs:99-104). A caller that sends {sources: [[target, entry]], modle: {...}} is answered adopted with the model unchanged: the Targets variant fails on the pair shape, serde then accepts Loaded leniently and drops modle. Give the frozen form its own deny_unknown_fields struct and use it as the variant payload. Optional.
Refs #1292
Implementation status
agentLoop.prompt.configure. Session language methods resolve the Session language owner directly. ThepromptSourcesBranchforwarding service has been removed.configurationPublisher. Loaded changes useprompt.configure; the branch exposesawaitPublishedfor publication progress.configureControlservice and its native lookup.Callers and operations
Final API
agentLoopagentLoop.compact({}) → sequence,stopTurn({turnId, reason}) → sequence or null;agentLoop.state({}) → {phase, turnId?},observe(listener)delivers that snapshot.promptprompt.initialCompletion({}) → void or opening error;prompt.configure({sources, model?}) → unchanged, adopted or superseded.contextPreparationprompt.configure({sources: [[target, entry or null]], model?}) → ConfigureOutcome. Prompt uses the current owner state. ContextPreparation commits the batch internally;awaitPublished({sequence}) → sequencewaits for publication.contextUsage.read,prompt.adoptedConfiguration({}) → adopted configuration or null. Report also usestimelineTree.queryat the selected head for evidence.sessionLanguage.get.session.language.updateaccepts the existing language code or clear action. The owner serializes persistence, live-state replacement and Prompt adoption on main and loaded branches before replying.Report captures
directory({id:"main"}).headasconversationThroughand passes it asthroughon both evidence queries.Acceptance
agentLoop,loopState,prompt,configureControl,promptSourcesBranch,configurationPublisher.Owner contract · Baseline catalog