Skip to content

Migrate branch control, Prompt and selected-branch consumers - #1911

Closed
eric8810 wants to merge 15 commits into
mainfrom
eric/1292-domain-loop-prompt
Closed

eric8810 wants to merge 15 commits into
mainfrom
eric/1292-domain-loop-prompt

Conversation

@eric8810

@eric8810 eric8810 commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #1292

Implementation status

  • Main already provides language get/update, the registries, input withdrawal and approval operations.
  • The branch exposes Loop commands and state through agentLoop.
  • Prompt exposes initial completion, configuration and its adopted configuration. Report reads it at the captured head.
  • Skills calls prompt.configure. Session language methods resolve the Session language owner directly. The promptSourcesBranch forwarding service has been removed.
  • ContextPreparation owns configuration publication. Prompt, opening, recovery and guide adoption use the same owner. Removed configurationPublisher. Loaded changes use prompt.configure; the branch exposes awaitPublished for publication progress.
  • Session and branch configuration call the addressed Prompt owner. Removed the configureControl service and its native lookup.
  • Selected-branch routing is implemented on top of this PR in Consolidate the Session tree and retire treeCommands #1909. The combined preparation and publication face is in Expose model preparation, compaction, history and usage operations #1912. Both depend on this owner PR.

Callers and operations

  • Loop control → agentLoop.compact/stopTurn/state/observe. ToolBinding, language and Agent configuration → prompt.initialCompletion/configure/adoptedConfiguration. Loaded changes → prompt.configure; Prompt and guide adoption commit through ContextPreparation.
  • Use existing initialPromptConfiguration.get/promptHost.load/guideEntries.register/toolRegistry.register/toolSourcesView.get/observe. Fold private branch prompt assembly into its owner. Language reads use sessionLanguage.get; writes and clear reuse session.language.update with persisted and loaded-branch adoption.
  • Session Context RPC and PromptSuggestion → selected branch contextUsage.read; compactAndWait waits on the admitted command sequence. InputQueue management/Collaboration → inputQueue.withdraw with checks and approval.pending/decide. Goal/Shell → tree admission and history.
  • Report/Agent configuration → prompt.adoptedConfiguration. Report captures main head once as conversationThrough; activity and later opt-in conversation use the same through, bounded query and include_publishing=false. No cutoff means no conversation. Coordinate report-specific work with Add scoped report email drafts and redacted evidence packs #1881.

Final API

Caller / operation Contract
Compaction, stop and activity callers → agentLoop agentLoop.compact({}) → sequence, stopTurn({turnId, reason}) → sequence or null; agentLoop.state({}) → {phase, turnId?}, observe(listener) delivers that snapshot.
ToolBinding, Session language and Agent configuration → prompt prompt.initialCompletion({}) → void or opening error; prompt.configure({sources, model?}) → unchanged, adopted or superseded.
Prompt and guide adoption → contextPreparation prompt.configure({sources: [[target, entry or null]], model?}) → ConfigureOutcome. Prompt uses the current owner state. ContextPreparation commits the batch internally; awaitPublished({sequence}) → sequence waits for publication.
PromptSuggestion → ContextUsage; Report and Agent configuration → Prompt contextUsage.read, prompt.adoptedConfiguration({}) → adopted configuration or null. Report also uses timelineTree.query at the selected head for evidence.
Language readers → PromptSources sessionLanguage.get.
Language updates → App Server session.language.update accepts 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"}).head as conversationThrough and passes it as through on both evidence queries.

Acceptance

  • Verify admitted branch calls through close, language propagation, prompt supersession, command settlement and fixed Report evidence.
  • 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 internal entries: agentLoop, loopState, prompt, configureControl, promptSourcesBranch, configurationPublisher.

Owner contract · Baseline catalog

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

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

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 removed ConfigurationPublisher (context_preparation.rs:88). Use ContextPreparation.
  • crates/dim-app-server/src/connection.rs:1573, :1629, :1658 and :1761 still read PromptSnapshot directly while the PR moves the other Agent configuration, attachment, Collaboration, Provider startup and Report consumers to prompt.adoptedConfiguration. Migrate these or state why the state cell is the intended read; the acceptance item for the same owner remains unchecked.
  • The new Empty request type renamed the existing Sessions Empty to Empty2 in npm/branch-services.d.ts:1186 and :1200. This changes the public TS alias used by SessionPermissions.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 check and cargo clippy -D warnings for 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 on branch_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-native passed; ci-ok failed. 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 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.

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.publish can 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.rs still reads PromptSnapshot directly: open, item 3 below.
  • P3, the new Empty request type renamed the existing Sessions Empty to Empty2: open, item 2 below.
  • P3, stale design references to the removed publisher: open, item 4 below.

P3 findings (optional)

  1. The new gate has no test. The two new Node tests (crates/dim-app-server/tests/transport_flow/branch_typescript.rs:560 and :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 asserts Cancelled with no PromptChanged or ContextConfigured after the close. This is also the unchecked acceptance item "Verify admitted branch calls through close".
  2. Empty2 is still the public alias for SessionPermissions.permissionDefaults (npm/branch-services.d.ts:1186, :1200). Name the Prompt empty request explicitly or accept the churn.
  3. crates/dim-app-server/src/connection.rs still reads PromptSnapshot directly at :1573, :1629, :1658 and :1761, while crates/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-563 and crates/dim-report/src/evidence.rs:386-390 now use adoptedConfiguration. Migrate these or state why the state cell is the intended read.
  4. 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:63 and docs/design/resume-read-design.md:133. One-word updates to ContextPreparation are enough.

Verification

  • Local pass: cargo fmt --all -- --check --config error_on_line_overflow=true; cargo check --workspace --locked (one unrelated manifest warning for the unused rustls-native-certs dependency 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_lifecycle 22, session_language_flow 13, report_flow 5, wait_protocol 1, 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_modules is absent, so DIM_TEST_JS_RUNTIME cannot resolve. They are #[ignore] in the regular suite and have no Node-backed CI result yet.
  • CI: macos-native and dependencies pass; verify (linux) is in progress; windows-cli, web and acp-registry are skipped. I did not wait.
  • Merge tree against origin/main 44f0dd4 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-server lib.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 same contextPreparation service but merges cleanly.

@eric8810
eric8810 requested a review from yyhhyyyyyy November 21, 2026 15:13

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

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_cancellation drives prompt.configure while main is closing, asserts Err(AgentError::Cancelled(_)), and asserts the branch sequence did not move (tests/integration/tests/prompt_lifecycle.rs:1208-1222). It passes.
  • Empty2 is gone. The Prompt reads use PromptRead (npm/branch-services.d.ts:470) and the Sessions Empty is the only Empty (:1121, :1135).
  • connection.rs no longer reads PromptSnapshot: the four reads use Prompt::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:63 and docs/design/resume-read-design.md:133.

Optional (non-blocking)

  1. PromptConfigurationRequest::Loaded ignores unknown fields while ConfigureUpdate denies them (crates/dim-agent-runtime/src/contracts.rs:99-104). A caller that sends {sources: [[target, entry]], modle: {...}} is answered adopted with the model unchanged: Targets fails on the pair shape and serde accepts Loaded leniently. Give the frozen form its own deny_unknown_fields struct payload. The inline note has the detail.
  2. docs/design/plugin-contract.md:140 now says "a AgentLoop provider"; use "an".
  3. Three current design pages still name the removed ConfigureControl as a negative requirement: docs/design/plugins/EnvironmentClients.md:11, docs/design/plugins/EnvironmentSettings.md:12 and :111. Say prompt.configure or "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_lifecycle 22, prompt_sources 6, wait_protocol 1, context_flow::manual_compaction 11, interrupt_flow::stop_turn_stops_only_the_open_turn_it_names, session_language_flow 13, report_flow 5.
  • The two Node tests are unverified locally: runtime/node_modules is absent and they are #[ignore] in the regular suite. CI verify (linux) is the only job that runs them.
  • CI at 3bb0a85: macos-native, static-checks and changes pass; verify (linux) is queued; windows-cli, web, dependencies, scripts and acp-registry are skipped. I did not wait.
  • origin/main 9d1d2e3 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 second Prompt::adopted_configuration with 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 {

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.

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.

@eric8810

Copy link
Copy Markdown
Collaborator Author

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

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

2 participants