Skip to content

docs(design): target contracts for EventHub and Scheduler - #2097

Closed
eric8810 wants to merge 8 commits into
mainfrom
dim/2023-events-contract
Closed

eric8810 wants to merge 8 commits into
mainfrom
dim/2023-events-contract

Conversation

@eric8810

@eric8810 eric8810 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Design part for #2023: the EventHub and Scheduler owner contracts, written in the owner-redesign shape (responsibility split, caller examples, operations, errors, flows, rule check, binding).

Owners:

  • EventHub: the producer face eventHub (declare, publish); the Session events tool (sources, subscribe, unsubscribe, list) and guide entry. Subscription management is not exposed to producer rows.
  • Scheduler: the scheduleJobs job face; the wakeup and loop operations used in-process by the Session part; the schedule, wakeup and loop tools; session.loop.*. The job, history and loop wire shapes are the shipped ones.

Dependency contracts: #2091 (SessionFiles), #2094 (Settings), #2095 (ServerControl, ManagementMethods), #2093 (SessionScope), #2024 (TimelineTree: no operation used). #2020 (Agents) is parallel; the sessions and SessionDeleted requirements are in the docs and posted on #2020. The SessionFiles put reply requirement is posted on #2018.

Delivery part: #2023 (comment)

Refs #2023
Refs #2015

Merge order

#2029 → #2080 → #2091/#2092/#2093 → #2094 → #2096 → the rest.

Sibling heads this change is aligned with: #2092 d96802349, #2098 c3acab356, #2102 3b48e1248. A paragraph that depends on a sibling names that PR; its head is the one above.

@eric8810

Copy link
Copy Markdown
Collaborator Author

评审(head 8f653648f):符合,没有修改意见。

@eric8810

Copy link
Copy Markdown
Collaborator Author

评审符合,无需修改,head 8f653648f。

@eric8810
eric8810 marked this pull request as ready for review November 23, 2026 12:13

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

Two material items before this becomes the target contract. First, the EventHub rewrite removes the shipped guide and tool text blocks under A.6 and A.4; both existing Linux assertions fail at the heading lookup and ci-ok is red. Please preserve the shipped text and assertions (or move the source of truth and update both consumers consistently). Second, keep Scheduler recovery read-only: the current bounded receipt lookup does not submit new input, while resubmitting the same ID can create input if the original never committed. Specify the receipt lookup and how cross-Session restoration and admission work before adopting the new call map. No runtime reproduction; the first finding is verified in hosted CI and the second is a contract review.

@eric8810

Copy link
Copy Markdown
Collaborator Author

Updated for review, head 56b47b4ec70d0f6e4b3d80fc0b5ff38482108cdd.

  1. CI. Restored the published A.4/A.6 text blocks in EventHub.md. cargo test --locked -p dim-event-hub --test hub_flow design_code_block passes both assertions (entry::the_entry_is_the_design_code_block, tool::the_tool_description_is_the_design_code_block); CI reruns on this head.
  2. Scheduler recovery is read-only. The contract settles a delivering record only by sessions.lookup {sessionId, branchId, submissionId} and never re-submits the same id: accepted → delivered; unknown → lost (or failed for a launch whose Session was not created); reloading/transport → bounded retry; a gone target settles the record and disables or cancels the target. The lookup acquires and restores a cold Session; the delivery's processActivity hold covers the restore and the lookup; a row unload does not release it, the next generation reconstructs it from the delivering records, and activated gates the first pass. The delivery comment's implementation and acceptance now state the same.
  3. §7 binding. Error types are serde data with a {code, message} shape and the codes in the tables; publish and run_now receive the request before returning a future, so a dropped reply does not stop accepted work; JobOrigin replaces the duplicate Origin name; the appendices define every request, reply and error type they use.
  4. Consistency. The job, wakeup and loop error lists now include the Settings, file and default-branch endings their flows can reach; the flows, responsibility split and Rule check name the same parts.
  5. Supersedes. Both contracts list the old sections and the documents they replace. The owner paragraphs in service-faces.md, session-boundary.md, plugin-contract.md, overview.md, cli-commands.md, sessions-service.md, management-methods.md, p6-p7-bindings.md, web-workspace.md, process-typescript.md, typescript-plugin-authoring.md, Notifications.md and acp-gateway-implementation.md now link to the contracts; the session.wakeup entry becomes session.loop; the schedule.watch progress paragraph is removed; the zh pages point to the English contracts. No other owner's paragraph or accepted ADR is changed.
  6. Client-visible changes. Both contracts have the section: eventhub.*, session.wakeup.*, schedule.watch and the source: "Scheduler" notices are removed; no shipped client used them. The wakeup tool gains list/cancel, and its model-visible description changes with the declaration test; EventHub A.4/A.6 and the schedule/loop descriptions are unchanged.
  7. References. The old Scheduler/EventHub anchors are replaced; #317 is no longer cited; the README index rows are updated, and the By-scope names stay because the process/Session parts are unchanged.

Re-requesting review from @zerob13.

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

Scope: this PR writes the target owner contracts for EventHub and Scheduler and updates their references across 18 design files (refs #2023, refs #2015).

Verdict: REQUEST_CHANGES

The restored A.4/A.6 text blocks match the current constants, and recovery no longer repeats the input. The findings below are what remains in the new contract as written.

P1

1. The Scheduler job, history and loop shapes break the shipped clients and the stored job documents

Problem. docs/design/plugins/Scheduler.md:197 says the schedule.* methods, session.loop.*, the schedule tool and the loop tool keep their wire names and shapes. The appendix does the opposite. Schedule becomes an internally tagged form object (Scheduler.md:274-279), Target changes the tag from kind to type (Scheduler.md:289-293), JobOrigin becomes internally tagged (Scheduler.md:282-286), Job and Run switch to camelCase field names. Job loses enabled_at and disabled_reason, the list reply loses next_window, schedule_error and last_run, and Run loses window, policy, attempts, released and job_revision (Scheduler.md:260-309). delete returns unit (Scheduler.md:478), and the conflict code becomes conflict (Scheduler.md:147) instead of schedule_conflict. CreateJob and UpdateJob also take a full stored Job (Scheduler.md:322-331), which requires id, revision and created_by that a creator cannot know, while schedule.save is a patch.

Failure scenario. The shipped web scheduler (web/src/rpc/scheduler.ts:4-86, web/src/features/settings/ScheduledSettings.vue:210-235) reads created_by, enabled_at, disabled_reason, next_window, schedule_error, last_run, run_id, job_id and policy, and the web audit contract (docs/design/web-workspace.md:828-829) also requires next window, window, session origin and policy. The client wraps {job} and {job_id} and checks schedule_conflict. With the appendix, readScheduledJobs throws on the createdBy/created_by mismatch before rendering, the create and save payloads use untagged schedules and kind targets that no longer deserialize, the delete reply loses job_id, and a stale save is not recognized as a conflict. The CLI requirements in docs/design/cli-commands.md:1313-1321 still require created_by, enabled_at, disabled_reason and Disabled: {code} at {instant}. Existing schedule.json documents with untagged schedules and kind targets stop deserializing, and the contract has no format decision or migration for that persisted shape.

Fix. Keep the current job, run, schedule, target, origin, delete and run-now shapes on the management and tool surfaces, or list every change in Client-visible changes and migrate the web, CLI, tool and stored documents in the same change. If the new shapes are intended, add the persistence format decision and migration required by AGENTS.md, and keep schedule_conflict or map it explicitly. Define a create input without owner-derived fields and an update patch whose absent fields mean keep stored.

2. The generated service faces cannot carry the documented error codes

Problem. EventHubError and SchedulerError are plain serde structs with a String code field, and both owner types are marked #[rutis::service] (docs/design/plugins/EventHub.md:367-375, docs/design/plugins/Scheduler.md:464-472). The service macro classifies a struct error by its type name; the dynamic code field is not the wire code. docs/design/service-faces.md:332 records exactly this as the reason the old eventSubscriptions face was a handwritten HostDispatch.

Failure scenario. A TypeScript producer calling eventHub.declare after unknown_source sees failure.code === 'EventHubError', not unknown_source. docs/typescript-plugin-authoring.md:533-535 and runtime/fixtures/event-hub-producer.ts:28-31 retry on that comparison, so the declared retry never runs. The EventHub error table (EventHub.md:132-144) and the Scheduler error table (Scheduler.md:143-154) are not the wire contract, and the scheduleJobs face collapses every code to SchedulerError.

Fix. Define each error as an internally tagged enum with one variant per code (the pattern in crates/dim-agent-capabilities/src/file_access.rs:62-68), or keep the handwritten HostDispatch that writes error.code for the merged faces, and state the chosen wire shape. Update the TypeScript authoring example and the producer fixture if the code stays in data.

P2

3. The EventHub face merge hands subscription management to every producer

Problem. The new contract replaces eventHub and eventSubscriptions with one eventHub face of six operations (EventHub.md:169). docs/typescript-plugin-authoring.md:497-500 still promises that the injected service "has declare and publish and nothing else, so a producer cannot create or remove another Session's subscriptions." The merged face gives every eventHub injector subscribe, unsubscribe and list, and list {sessionId?} returns every subscription (EventHub.md:124-126).

Failure scenario. A producer row that injects eventHub can subscribe another Session, retire another Session's guide, or enumerate all subscriptions. The old design kept the subscription core on a separate name with a documented trusted-plugin boundary; the new contract removes that boundary without listing the authority change in Client-visible changes.

Fix. Keep the producer face to declare and publish and expose the subscription operations on a separate face or name, or scope the operations to the calling row and authorize the target Session. If the broader authority is intended, state it in the TypeScript guide and in Client-visible changes.

4. Recovery contradicts the Sessions lookup semantics and loses the persisted attempt bound

Problem. The new paragraph says unknown settles lost and only reloading and transport retry (Scheduler.md:173). The Sessions contract says lookup answers unknown as final only for writes that returned before the lookup began; an admitted write whose reply was lost keeps running to its own outcome (docs/design/appserver/sessions-service.md:289-296, docs/design/contracts/session-access.md:305). The old Scheduler contract at the merge base stated that unknown, reloading, ambiguous and a transport failure each keep the record delivering, count toward a persisted five-attempt bound, and that unknown cannot settle a record. The new contract drops ambiguous, drops the bound's terminal rule, and the new Run type has no attempts field (Scheduler.md:297-309).

Failure scenario. A Scheduler row reload happens while an accepted sessions.input is still in flight. The lookup answers unknown, the record settles lost, and the old task then commits the input. The delivery is recorded lost while the model received the prompt, and no later pass repairs the history. After a restart the owner cannot know how many lookup attempts a delivering record spent because the record no longer carries the count. The loop flow says a pending round is settled by lookup, while the current loop pass reads sessions.pending and leaves an inconclusive round for the next window (crates/dim-agent-scheduler/src/loops.rs:698-716, 843-855); the contract does not state the loop rule.

Fix. Restore the old rule: unknown, reloading, ambiguous and transport keep the record delivering, each persists an attempts increment before the lookup, and the bound settles lost with a stated detail. State the loop and wakeup rules separately and add the in-flight case to the verification.

5. The admission hold cannot be reconstructed as stated

Problem. processActivity.hold returns an id that release(id) consumes, and the implementation records that a lost owner leaves admission busy until process shutdown (crates/dim-app-server/src/control.rs:76-96). The contract says a row unload does not release the hold and the next generation "reconstructs it from the delivering records" (Scheduler.md:173-175), but the new Run type stores no hold id and no operation adopts an existing id.

Failure scenario. After a row reload the old hold is never released, so admission stays busy for the process lifetime, or the next generation takes a second hold per record and can release only the new one. Either way the statement that the hold is released after the terminal record is false for the old hold.

Fix. State that the old hold is intentionally retained until process shutdown and the next generation takes a separate hold per unsettled record, with the release that ends it. Alternatively persist the hold id in the record and define a cross-generation adopt and release. Add a verification for a row reload with an in-flight delivery.

6. The caller example and binding disagree on wakeup and loop replies

Problem. create_wakeup returns WakeupId, a bare string (Scheduler.md:486), but the table says {wakeupId} (Scheduler.md:129) and the example uses created.wakeup_id (Scheduler.md:69). cancel_wakeup returns WakeupState while the table says {state?} (Scheduler.md:131, Scheduler.md:488). stop_loop returns Loop while the table says {loop, settled} (Scheduler.md:134, Scheduler.md:491), and settled is what docs/design/acp-gateway-implementation.md:298 and docs/design/cli-commands.md:701-702 depend on. jobs.list(ListJobs) uses an undefined ListJobs while list takes no request (Scheduler.md:58, Scheduler.md:474).

Failure scenario. The examples do not compile against the appendix. A session.loop.stop client cannot read settled, a wakeup create caller cannot read wakeupId from a bare string, and a stop reply cannot distinguish a terminal stop from a still-settling one.

Fix. Add reply structs such as CreateWakeupReply, CancelWakeupReply, StopLoopReply { loop, settled } and ListJobs, or change the tables and examples to the bare values. Keep the settled flag on the stop reply and state when it is false.

7. EventHub publish optional fields and the subscribe publication_unknown reply

Problem. The table marks attributes? and to? optional (EventHub.md:122), but PublishRequest has non-optional attributes: BTreeMap and to: Vec with no #[serde(default)] (EventHub.md:331-339). The current type and the TypeScript declaration mark both optional (crates/dim-event-hub/src/model.rs:42-56, npm/plugin.d.ts:321-330). Separately, subscribe lists publication_unknown as an error (EventHub.md:124, EventHub.md:142), while the old contract said a committed guide stores the subscription and the call answers its id.

Failure scenario. A producer publishing to subscribers only, as in the TypeScript fixture and the authoring guide, omits to and attributes and now fails to deserialize. A subscriber whose guide committed but whose reply was lost gets publication_unknown and cannot tell whether the record was stored; a retry can duplicate the subscription or hit the limit.

Fix. Add #[serde(default)] to attributes and to. For publication_unknown, either store the record and reply the subscription id as the old contract did, or define a distinct stored-but-unconfirmed reply with an idempotent retry.

8. The schedule window semantics are gone

Problem. The new Schedule type has Cron, Every and At (Scheduler.md:275-279), but the contract no longer defines the every anchor, the cron time zone default, DST gap and overlap handling, missed-window collapse, the first-window rule, the at disable rule, or the max_run_minutes and input_mode defaults. The old contract pinned those rules in A.4 and its acceptance. The new Job has no enabled_at (Scheduler.md:260-271), and Target::Session requires input_mode while the text says inputMode? (Scheduler.md:137, Scheduler.md:291).

Failure scenario. A re-enabled or edited every job has no defined first window; two implementations can disagree on DST and missed windows; a caller omitting inputMode or maxRunMinutes gets a deserialization failure or an undefined launch stop time. The new verification does not test any of these.

Fix. Keep enabled_at and the old A.4 window rules, or state the new anchor, DST and missed rules explicitly. Mark input_mode and max_run_minutes optional with their defaults, and add the window cases to the verification.

9. The serde attributes do not produce the documented field spelling

Problem. #[serde(tag = "form", rename_all = "camelCase")] and the same on Target, JobOrigin, Cadence and Delivery rename variant names, not the fields inside struct variants. Target therefore serializes session_id, branch_id and input_mode while the contract text says sessionId, branchId and inputMode (Scheduler.md:137, Scheduler.md:289-292). JobOrigin and Cadence keep snake_case fields inside camelCase objects, and Delivery keeps snake_case fields and serializes absent options as null, while the current wire is camelCase and omits them (EventHub.md:359-365, crates/dim-event-hub/src/publish.rs:42-75).

Failure scenario. A caller following the contract text sends sessionId and the face answers for an unknown field. A caller reading delivery.inputId, delivery.subscriptionIds or delivery.truncated sees input_id, subscription_ids or null. The appendix and the current wire disagree.

Fix. Add #[serde(rename_all_fields = "camelCase")] or per-variant #[serde(rename_all = "camelCase")] and skip_serializing_if, or spell the wire as snake_case in the contract text.

P3

  • Reply wrappers. EventHub.md:380,383 return bare Sources and Subscriptions while the table says {sources} and {subscriptions} and the current wire is an object. The same mismatch applies to list_wakeups, list_loops, start_loop, next_loop, create, get and set_enabled. Fix the reply types or the tables.
  • Current-state claim. docs/design/contracts/session-boundary.md:281 says the namespaces are "registered today" and now lists session.loop without session.wakeup. The current code registers both (crates/dim-agent-scheduler/src/session.rs:258-270). Keep the current list and add the target removal, or retitle the list as the target state.
  • Broken links. docs/design/appserver/sessions-service.md:504 links plugins/Scheduler.md from a file under appserver/; the file is at ../plugins/Scheduler.md, so the changed line is broken. docs/design/appserver/management-methods.md:234 uses #13-concrete-package-rows while the heading is ### 1.3 Concrete package row (docs/design/plugins/Workflow.md:92).
  • Stale surfaces. docs/design/overview.md:105 still says clients subscribe through eventhub.*; EventHub.md:175 removes them. overview.md:169 still says Scheduler has a "run-outcome report" although Scheduler.md:199 removes the notices and the contract writes no report. docs/design/plugins/Notifications.md:39,178,209 still describes Scheduler's scheduled_run_outcomes event; the new Scheduler contract has no such event, and the Notifications page is withdrawn and reference only. Update these or mark them historical.
  • Stale history. docs/INDEX.md:105 and docs/design/roadmap.md:31,135 still cite #317, although the PR body says #317 is no longer cited. #317 is merged, so this is stale history rather than a forward reference, but the claim is not true for the tree.
  • Unmerged rule source. The Rule check rows cite §7.2 of docs/architecture/rust-agent/principles.md, whose §7 exists only in #2029 (open). Report the owning PR #2029, and either link the rule text or keep the docs unmerged until it lands.
  • Dangling section numbers. Scheduler.md:177 keeps a ### 12. Loop heading with no parent §12, and EventHub.md:157 keeps ### 9.1 with no §9. Numberless headings would avoid the dangling references.
  • Verification and bounds. The new verification drops the old acceptance for schedule windows, the 16-job, 8-loop, prompt and body bounds, the wakeup grace, the CAS conflict retry and legacy documents. The error kinds loop_limit, invalid and too_large are referenced without their bounds. Keep the rules in the contract or in the delivery acceptance.
  • Translation drift. docs/zh/design/contracts/session-boundary.md:280 still lists session.wakeup and schedule.watch, and docs/zh/design/overview.md:150,268,289,407,560 and docs/zh/design/cli-commands.md:751,1028 still cite #317 and the old Scheduler sections. The two zh plugin pages get banners, but the zh counterparts of the changed English pages still describe the removed surfaces.
  • Typed state and defaults. Run.state is a free String (Scheduler.md:300) instead of the current DeliveryState enum, and the state list is no longer enumerated. Target::Launch.max_run_minutes is Option<u32> with no default. Use an enum or list the states, and state the defaults.

Comment thread docs/design/plugins/EventHub.md Outdated
| `unknown_type` (subscribe) | Fix the pattern or declare the source |
| `limit_reached` | Remove a subscription first; 32 per Session, 1024 in total |
| `session_closed` / `branch_missing` / `branch_ended` | The target cannot take input; fix the target |
| `reloading` / `rejected` / `ambiguous` / `failed` / `publication_unknown` / `transport` | The `sessions` call's answer; the subscription is stored only after a committed guide, `publication_unknown` included |

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.

Problem: publication_unknown is listed as an error, but it means the guide input committed, so the subscription should be stored and the call should answer its id; the old A.3 said exactly that.

Failure: a lost reply leaves the caller unable to tell whether the record exists, and a retry can duplicate the subscription or hit the limit.

Fix: make it a stored success (reply the subscription id) or define a distinct stored-but-unconfirmed reply with an idempotent retry.

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.

Partially fixed in d02268b. publication_unknown is gone from the error list, and the cancellation column says a committed guide stores the record even when its publication is unknown (EventHub.md:122). Remaining: the error table and the Agents requirement (EventHub.md:141,218) do not name publication_unknown, which the accepted sessions.input contract still returns (docs/design/contracts/session-access.md:229). An implementer cannot tell that answer is the stored-success case. Name it or define the distinct reply.

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.

Partially fixed at 853b6aa. EventHub.md:141 names publication_unknown as the stored-success answer, but the new requirement at EventHub.md:220 asks InputQueue's submit for it. submit replies {inputId, sequence} and its errors are invalid, line_ended, cancelled and closed; only withdraw answers publication_unknown (origin/pr-2102:docs/design/plugins/InputQueue.md:81-82,94, head 823124c7). See P2 2 in the new body.

Comment thread docs/design/plugins/EventHub.md Outdated

The marker is the only channel an event uses. Nothing is injected into a request, and an event never becomes a system-prompt change: the guide entry is the writer's contribution to the guide, and the guide is composed where its writers load ([Prompt §3.4](Prompt.md#34-adopted-when-its-writer-loads)).
- `docs/design/plugins/EventHub.md` sections 1–10 and Appendices B–E (the old feature design) are replaced by this contract; A.4 and A.6 remain as the published model-visible texts.
- `docs/design/service-faces.md` §3.2's `eventHub`/`eventSubscriptions` rows and §4's `eventSubscriptions` section: one `eventHub` face with the six operations; `eventSubscriptions` is gone.

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.

Problem: merging the two names into one eventHub face gives every row that injects eventHub the subscribe, unsubscribe and list operations. docs/typescript-plugin-authoring.md:497-500 still promises a producer cannot create or remove another Session's subscriptions, and npm/plugin.d.ts:355-358 declares only declare and publish. list {sessionId?} also returns every subscription.

Failure: a producer row can manage another Session's subscriptions and enumerate all subscriptions, an authority change the contract does not list.

Fix: keep the subscription operations on a separate face or name, or scope them to the calling row and authorize the target Session; update the TypeScript guide and Client-visible changes if the broader authority is intended.

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.

Fixed in d02268b. The producer face is declare and publish only; sources, subscribe, unsubscribe and list are pub(crate) in-process operations (EventHub.md:115,449-452), and list takes one Session (EventHub.md:124). Client-visible changes records the authority change (EventHub.md:175). The requirement table at EventHub.md:30 still says every subscription; that leftover is in the new body.

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.

Fixed in 9b87ef9, still present at 853b6aa. EventHub.md:30 says the events tool reads its own Session's subscriptions; EventHub.md:115 keeps the producer face to declare/publish, and EventHub.md:124 takes {sessionId}. The leftover every-subscription wording is gone.

Comment thread docs/design/plugins/EventHub.md Outdated
pub id: Option<String>,
pub title: Option<String>,
pub body: String,
pub attributes: std::collections::BTreeMap<String, String>,

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.

Problem: the table marks attributes? and to? optional (line 122), but this struct requires both. The current type and the TypeScript declaration use #[serde(default)] (crates/dim-event-hub/src/model.rs:42-56, npm/plugin.d.ts:321-330).

Failure: the TypeScript fixture and the authoring guide publish without to and attributes and now fail to deserialize.

Fix: add #[serde(default)] to both fields, or make them Option.

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.

Fixed in d02268b. PublishRequest.attributes and .to have #[serde(default)] (EventHub.md:261-264), matching crates/dim-event-hub/src/model.rs:51-55.


### A.4 The `events` tool
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(tag = "status", rename_all = "camelCase")]

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.

Problem: rename_all on an enum renames variant names only; these fields stay snake_case, and the two Option fields serialize as null. The current wire is camelCase (inputId, subscriptionIds) and omits absent options (crates/dim-event-hub/src/publish.rs:42-75).

Failure: a producer reading delivery.inputId or delivery.subscriptionIds sees input_id and subscription_ids, and a consumer sees truncated: null where the current wire has no field.

Fix: add per-variant #[serde(rename_all = "camelCase")] and skip_serializing_if, or document the new wire.

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.

Fixed in d02268b. Delivery adds per-variant #[serde(rename_all = "camelCase")] and skip_serializing_if on the two optional fields (EventHub.md:384-415), matching crates/dim-event-hub/src/publish.rs:42-75.

Comment thread docs/design/plugins/EventHub.md Outdated
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, thiserror::Error)]
#[serde(rename_all = "camelCase")]
#[error("{code}: {message}")]
pub struct EventHubError {

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.

Problem: this plain serde struct is served by a generated #[rutis::service] face, which classifies the error by its type name; the dynamic code is not the wire code. docs/design/service-faces.md:332 records exactly this as the reason eventSubscriptions was a handwritten HostDispatch.

Failure: a TypeScript caller sees failure.code === EventHubError, not unknown_source; docs/typescript-plugin-authoring.md:533-535 and runtime/fixtures/event-hub-producer.ts retry on that comparison, so the declared retry never runs. The error table is not the wire contract.

Fix: define an error enum with one variant per code, or keep the handwritten face that writes error.code; state the wire shape.

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.

Fixed in d02268b. EventHubError is now an internally tagged enum with one variant per code (EventHub.md:416-437). The rutis service macro takes the serde tag as the wire code, so failure.code is unknown_source and the retry in docs/typescript-plugin-authoring.md:533-535 fires.

Comment thread docs/design/plugins/Scheduler.md Outdated
pub async fn cancel_wakeup(&self, request: CancelWakeup) -> Result<WakeupState, SchedulerError>;
pub async fn start_loop(&self, request: StartLoop) -> Result<Loop, SchedulerError>;
pub async fn next_loop(&self, request: NextLoop) -> Result<Loop, SchedulerError>;
pub async fn stop_loop(&self, request: StopLoop) -> Result<Loop, SchedulerError>;

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.

Problem: stop_loop returns Loop, but the table says {loop, settled} (line 134), and docs/design/acp-gateway-implementation.md:298 and docs/design/cli-commands.md:701-702 depend on settled: false to report a still-settling stop.

Failure: the session.loop.stop reply loses settled, so the ACP and CLI cannot tell a terminal stop from a pending one.

Fix: return StopLoopReply { loop, settled } or a tuple, and state when settled is false.

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.

Fixed in d02268b. StopLoopReply { loop, settled } is defined and returned (Scheduler.md:745,791), and the semantics are stated (Scheduler.md:198).

Comment thread docs/design/service-faces.md Outdated

六个进程端口的内容本来就是数据,所有者各自把读绑定成端口类型上的 operation,`#[rutis::service]` 生成 dispatcher,名字 shared;Rust 调用方直接调同一个方法,不另写适配层。`eventSubscriptions` 手写 `HostDispatch`,因为 owner 的错误是带动态 `code` 的 struct,生成面会把 `code` 写成类型名。

> `eventSubscriptions` 面已由 [EventHub](plugins/EventHub.md) 取代:四个操作在同一个 `eventHub` 面上。

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.

Problem: the blockquote says the face is replaced but leaves line 332's rule standing: a generated face writes the dynamic code as the type name, which is why eventSubscriptions was handwritten. The new EventHub appendix uses a generated face with exactly that error shape. The blockquote also names four operations, which reads as the whole face, while EventHub.md:117-126 defines six.

Failure: the replacement silently reintroduces the error-code loss the handwritten face avoided and leaves the catalog count wrong.

Fix: say how the error code is preserved (enum or handwritten dispatch) and update the count.

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.

Partially fixed in d02268b. The EventHub appendix now uses an error enum, so the generated face keeps the code (EventHub.md:416-437). Remaining: the blockquote at service-faces.md:334 still says four operations on the same eventHub face; the contract puts declare and publish on the face and the other four in process (EventHub.md:115). Update the blockquote and the count, and update the line 332 rule now that the face uses an enum.

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.

Fixed in 9b87ef9, still present at 853b6aa. docs/design/service-faces.md:332 and :334 state the producer face has declare/publish, the four subscription operations are the events tool's in-process operations, and the generated face keeps the enum variant name as the wire code.

```

Session namespaces registered today: `session.question` (Questions), `session.goal` (Goal), `session.rename` (SessionTitle), `session.input` (InputQueue), `session.context` (ContextCompaction), `session.exec.output` (WorkspaceTools, [background task output](../background-task-output.md)), `session.agent` ([model configuration](../model-configuration.md)), `session.language` (App Server, [PromptSources §3](../plugins/PromptSources.md#3-the-agent-prompt-language-state-source)), `attachment` (Attachments), `shell` (ShellInput), `session.wakeup` (Scheduler, [Scheduler §10](../plugins/Scheduler.md#10-session-scoped-wakeup)), `session.collaboration` (Collaboration, [Collaboration §6.7](../plugins/Collaboration.md#67-stopping-a-member-from-the-client)). `approval.respond` is a built-in Session method, not a part registration. The branch methods — `session.branch_create`, `session.branch_end`, `session.branch_set_default`, `session.branches` and `session.branch.get` — are built-ins too, and their contract is [timeline branches §9, §10 and §14](../timeline-branches.md#14-clients): each `branchId` they take names one line, and one that is omitted names the Session's default branch, not its root. `session.branch_set_default` accepts the root as a target whenever it is not the default branch and refuses only a target that is already the default branch; `session.branch_end` refuses the default branch for every caller, so ending it takes a move of the default branch first. Hooks registers no Session namespace: its `hooks.*` methods are management methods ([Hooks A.7](../plugins/Hooks.md#a7-management-methods)). Each plugin document is authoritative for its methods.
Session namespaces registered today: `session.question` (Questions), `session.goal` (Goal), `session.rename` (SessionTitle), `session.input` (InputQueue), `session.context` (ContextCompaction), `session.exec.output` (WorkspaceTools, [background task output](../background-task-output.md)), `session.agent` ([model configuration](../model-configuration.md)), `session.language` (App Server, [PromptSources §3](../plugins/PromptSources.md#3-the-agent-prompt-language-state-source)), `attachment` (Attachments), `shell` (ShellInput), `session.loop` (Scheduler, [Scheduler](../plugins/Scheduler.md)), `session.collaboration` (Collaboration, [Collaboration §6.7](../plugins/Collaboration.md#67-stopping-a-member-from-the-client)). `approval.respond` is a built-in Session method, not a part registration. The branch methods — `session.branch_create`, `session.branch_end`, `session.branch_set_default`, `session.branches` and `session.branch.get` — are built-ins too, and their contract is [timeline branches §9, §10 and §14](../timeline-branches.md#14-clients): each `branchId` they take names one line, and one that is omitted names the Session's default branch, not its root. `session.branch_set_default` accepts the root as a target whenever it is not the default branch and refuses only a target that is already the default branch; `session.branch_end` refuses the default branch for every caller, so ending it takes a move of the default branch first. Hooks registers no Session namespace: its `hooks.*` methods are management methods ([Hooks A.7](../plugins/Hooks.md#a7-management-methods)). Each plugin document is authoritative for its methods.

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.

Problem: the paragraph says these namespaces are registered today, but the current code registers session.wakeup.* and session.loop.* (crates/dim-agent-scheduler/src/session.rs:258-270). This line removes session.wakeup and adds session.loop.

Failure: the current-state list no longer matches the build; a reader cannot tell the target removal from today's registry.

Fix: keep the current list and add the target removal, or retitle the list as the target state.

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.

Fixed in d02268b. The list now includes session.wakeup and session.loop and says the target removes session.wakeup (docs/design/contracts/session-boundary.md:281).

`{sessionId}` → `{defaultBranchId}`; errors `rejected`, `session_closed`, `reloading`, `failed`.

The read answers the line the Session's conversation is on: the tree's current default, read from its owner (`TreeCommands::default_branch`) after the Session is acquired, so an idle-unloaded Session is restored for the answer as for §6.10. It reads no history page and writes no event. It exists for the request-side defaults that name no line: a management `schedule.save` that records the default branch for a new job ([Scheduler §2.1](plugins/Scheduler.md#21-the-two-targets)), and the `loops`, `wakeups` and EventHub faces when a request omits a branch ([timeline branches §20.22](../timeline-branches.md#20-acceptance)). A caller resolves it once per request.
The read answers the line the Session's conversation is on: the tree's current default, read from its owner (`TreeCommands::default_branch`) after the Session is acquired, so an idle-unloaded Session is restored for the answer as for §6.10. It reads no history page and writes no event. It exists for the request-side defaults that name no line: a management `schedule.save` that records the default branch for a new job ([Scheduler](plugins/Scheduler.md)), and the `loops`, `wakeups` and EventHub faces when a request omits a branch ([timeline branches §20.22](../timeline-branches.md#20-acceptance)). A caller resolves it once per request.

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.

Problem: this link is relative to docs/design/appserver/, so plugins/Scheduler.md resolves to a missing file; the changed line keeps the broken path.

Failure: the request-side default section's Scheduler reference is dead.

Fix: use ../plugins/Scheduler.md.

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.

Fixed in d02268b. The link is now ../plugins/Scheduler.md (docs/design/appserver/sessions-service.md:504).

| Case | Native process owner | TypeScript process owner ([process rows](../process-typescript.md)) | Shipped configuration today |
| --- | --- | --- | --- |
| Pending on a dependency whose row is Failed, Unresolved or Disabled | No. A required host row that fails during startup fails startup (`lib.rs`, required failures); after startup only `RunningServer::restart` can fail one, it has no caller in this repository, and its allow-list (`Rpc`, `Connection`, `Transport`, `Agents`, `Mcp`) holds no provider of an owner dependency | Yes, through the embedding input: an extension row's failure is its own diagnostic and does not fail startup (process rows §2.1), so an owner that injects another process row's service stays Pending when that row fails | None. `dimcode` configures no process rows; the planned Scheduler and Workflow owners inject only `sessions`, `settings`, `pluginFiles` and, respectively, `managementMethods` ([Scheduler §1](../plugins/Scheduler.md#1-structure)) and `workflowFiles` ([Workflow §1.3](../plugins/Workflow.md#13-concrete-package-rows)), all provided by required host rows that cannot be restarted (process rows §5.1) |
| Pending on a dependency whose row is Failed, Unresolved or Disabled | No. A required host row that fails during startup fails startup (`lib.rs`, required failures); after startup only `RunningServer::restart` can fail one, it has no caller in this repository, and its allow-list (`Rpc`, `Connection`, `Transport`, `Agents`, `Mcp`) holds no provider of an owner dependency | Yes, through the embedding input: an extension row's failure is its own diagnostic and does not fail startup (process rows §2.1), so an owner that injects another process row's service stays Pending when that row fails | None. `dimcode` configures no process rows; the planned Scheduler and Workflow owners inject only `sessions`, `settings`, `pluginFiles` and, respectively, `managementMethods` ([Scheduler](../plugins/Scheduler.md)) and `workflowFiles` ([Workflow §1.3](../plugins/Workflow.md#13-concrete-package-rows)), all provided by required host rows that cannot be restarted (process rows §5.1) |

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.

Problem: the changed line's Workflow link uses #13-concrete-package-rows, but the heading is ### 1.3 Concrete package row (docs/design/plugins/Workflow.md:92).

Failure: the anchor does not resolve.

Fix: use #13-concrete-package-row.

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.

Fixed in d02268b. The Workflow link is now #13-concrete-package-row, and the Scheduler link is plain (docs/design/appserver/management-methods.md:234).

@eric8810

Copy link
Copy Markdown
Collaborator Author

已按评审与自查标准修改,head d02268bf2bc896552825ceb0e0cd44d60a315066。

评审逐条

  1. P1.1 客户端形状。 Scheduler 的 job、history、loop 恢复为已发布形状:Schedule 是 untagged {cron,tz?}/{every_minutes}/{at};Target 保留 kind 与 snake_case 字段;JobOrigin 保留 "user"/{tool:{session_id,branch_id}};ScheduledJob 带 enabled_at/disabled_reason/next_window/schedule_error/last_run;Run 带 window/policy/attempts/released/job_revision;delete 回 {job_id};冲突码是 schedule_conflict;JobInput 是补丁,不含 id/revision/created_by;Job 保留 legacy 字段与旧 delivery 状态,schedule.json/runs.json 仍可解码。Client-visible changes 写明这些形状不变。
  2. P1.2 错误类型。 EventHubError/SchedulerError 改为 #[serde(tag = "code", rename_all = "snake_case")] 的内部标签枚举,变体即 wire code;Rejected { reason, message } 承载回调/Settings 的 code;cancelled 单独成码。绑定附录(含 #[rutis::service]、Ctx、CancelledFn、全部请求/回复/错误类型)在临时 crate(workspace crates + rutis 0.23.0、rustc 1.100)cargo check 通过。
  3. P2.3 EventHub 面。 生产者面只保留 declare/publish;sources/subscribe/unsubscribe/list 是 events 工具的进程内操作,list 只接受本 Session 的 id;生产者 row 无法管理订阅。TypeScript 指南的“declare and publish and nothing else”与契约一致;scenario-eval 改为驱动 events 工具。
  4. P2.4 恢复。 unknown/reloading/ambiguous/transport 都保持 delivering,每次 lookup 前持久化 attempts,第五次无事实结 lost 并写 detail;unknown 对已准入但回执丢失的写不构成终态。loop 用 sessions.pending,不冒充 lookup;wakeup 的失败/不确定/过期分开写;验收加入 reload 时 in-flight 的用例。
  5. P2.5 hold。 行卸载不释放旧 hold,它留到进程结束;下一代为每个未结记录单独取 hold,并在终态记录后释放;验收加入 reload + in-flight。
  6. P2.6 回执。 增加 ListJobs、CreateWakeupReply、CancelWakeupReply、LoopReply、StopLoopReply { loop, settled }、JobsReply/JobReply/DeleteJobReply/RunsReply/WakeupsReply/LoopsReply;示例与附录一致;settled: false 的语义写明。
  7. P2.7 可选字段与 publication。 attributes/to 加 #[serde(default)];subscribe 在 guide 已提交时存记录并回 {subscriptionId}(不再有 publication_unknown 错误/字段),A.4 文本不变。
  8. P2.8 窗口。 恢复 every 的 enabled_at 锚、cron tz 默认与 DST、missed 折叠、at 停用、input_mode 默认 queue、max_run_minutes 默认 60;验收覆盖窗口、16 作业/8 loop/32 KiB prompt/4 KiB preview、5 次 lookup、100 条历史、CAS 重试与旧文档。
  9. P2.9 serde。 job/history/loop 的字段拼写按已发布 wire:job/history snake_case,loop/wakeup 视图 camelCase;Delivery 各变体 #[serde(rename_all="camelCase")] + skip_serializing_if;临时 crate 编译验证。

P3

  • 回执包装:SourcesReply/SubscriptionsReply 等与表一致。
  • “registered today” 列表同时写 session.wakeup 与 session.loop,并写明目标移除。
  • sessions-service.md 的 Scheduler 链接改为 ../plugins/Scheduler.md;management-methods.md 的 Workflow 锚点改为 #13-concrete-package-row。
  • overview.md 的 eventhub.* 与 run-outcome report 句改为生产者 declare/publish、events 工具、只存投递记录;Notifications.md 的 scheduled_run_outcomes 标为历史。
  • #317:INDEX.md/roadmap.md 保留已合并的历史;契约段落不再引用它,PR 也不再声称整棵树不再引用。
  • 规则来源:两份契约的 Rule check 注明 §7.2 属于 docs(principles): add owners and operations #2029(head da6f4a950)。
  • 悬空编号:### 9.1 与 ### 12. Loop 保留,因为代码注释锚点 #91-…/#12-loop 仍指向它们;按自查第 7 条本轮不改代码。
  • 类型与默认:DeliveryState 枚举、max_run_minutes/input_mode 默认、旧状态解码。
  • 中文:zh/design/overview.md、zh/design/cli-commands.md、zh/design/contracts/session-boundary.md 的 Scheduler/#317/session.wakeup 段落同步。

自查额外修改

  • Supersedes 列出的文档在本 PR 内都改为链接到新契约或标为历史;service-faces.md 的 scheduleJobs/wakeups/loops/eventSubscriptions 行与段落已改。
  • process-typescript.md 与 management-methods.md 的 Scheduler 进程依赖补上 processActivity。
  • Origin 与 EventHub 的 Origin 重名,Scheduler 侧改为 JobOrigin。
  • 全仓 grep 旧锚点与删除名字:英文文档不再有 EventHub.md#/Scheduler.md# 旧锚点;代码注释锚点保留;#317 只在历史文档。

客户端可见变更

  • eventhub.*、eventSubscriptions、session.wakeup.*、schedule.watch、source: "Scheduler" 通知移除;没有已发布客户端调用。
  • wakeup 工具增加 list/cancel,其模型可见描述随声明测试更新。
  • job、history、loop 的字段与错误码逐字段保持;EventHub A.4/A.6、schedule/loop 描述不变;持久化格式不变。

请 @zerob13 复审。

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

[P2] Preserve the current default-branch selection on management saves. The revised Scheduler contract and binding now preserve the request field spelling, but say an omitted branch_id defaults to main. The shipped management save resolves the Session’s current default branch at save time; only a legacy stored row without a branch keeps the root fallback. If the user has moved the default, the same management request would silently schedule work on a different line. Keep optional branch_id on the management input, resolve and persist the current default on save, and retain the root fallback just for legacy rows. Pin both cases in acceptance. This is separate from the existing read-only receipt and EventHub recovery findings. Verified statically; Linux and macOS passed in the hosted run, with the final gate pending at 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.

Scope: this PR writes the target owner contracts for EventHub and Scheduler and updates their references across 21 design files (refs #2023 and #2015). I reviewed the full main...head at d02268b (merge base 5a279d6), not only the delta from 56b47b4.

Verdict: REQUEST_CHANGES

Round-1 status

The two P1s are fixed.

  • P1 1, Scheduler shapes break clients and stored documents: the appendix now keeps the shipped shapes. Schedule is untagged, Target keeps kind and snake_case fields, JobOrigin keeps its shape, Job keeps the legacy fields, and Run is the delivery record (Scheduler.md:286-341, 368-402, 484-530). The delete reply is {job_id} and the conflict code is schedule_conflict (Scheduler.md:129, 159). The web reader's fields are present and the legacy documents decode as written (Scheduler.md:232; web/src/rpc/scheduler.ts:4-92).
  • P1 2, generated faces lose error codes: both owners now define internally tagged error enums with one variant per code (EventHub.md:416-437; Scheduler.md:753-770), and the Scheduler text states the wire code (Scheduler.md:153). The rutis service macro takes the serde tag as the wire code, so the unknown_source retry in docs/typescript-plugin-authoring.md:533-535 can fire.

Of the 18 round-1 inline threads, 15 are fixed and 3 are partially fixed: 4668856825 (publication_unknown), 4668856906 (recovery and the loop rule), 4668856987 (service-faces blockquote). The P2s on face authority, the recovery paragraph and the hold, the reply wrappers, the window semantics and the serde spelling are fixed; the loop part of the recovery P2 remains.

CI at d02268b: verify (linux), macos-native and ci-ok pass. node scripts/adr-check.mjs --base 5a279d69 passes for 21 changed files.

P2

1. The loop recovery rule is missing and contradicted

Problem. Scheduler.md:192 says the loop pass does not use lookup and settles rounds through sessions.pending. The shipped recovery does use lookup: a record left delivering_round is settled by sessions.lookup with loop:<loopId>:<round> (crates/dim-agent-scheduler/src/loops.rs:933-1070). The forward pass reads sessions.pending only after it has last_input_id (loops.rs:807-858); a recovered record has no input id because the id comes from the reply that was lost.

Failure scenario. A loop round's input commits and the sessions.input reply is lost. The record stays delivering_round (loops.rs:886-914). After a restart the contract's pass reads sessions.pending, which needs an input id the record does not have, so the round cannot settle. The loop stalls with delivering_round set, or a later pass clears it and writes the same round again, duplicating the prompt. Scheduler.md:198 also says "the next pass settles it" without naming the lookup that can do it.

Evidence. docs/design/plugins/Scheduler.md:192,198; crates/dim-agent-scheduler/src/loops.rs:807-858, 886-914, 933-1070.

Fix. State both rules: the forward pass reads sessions.pending and leaves an inconclusive round for the next window; the recovery pass settles a delivering_round by the read-only lookup with the round's submission id. Add the crash-after-commit case to the verification.

2. The sessions dependencies conflict with ADR 027 and the Agents contract

Problem. The dependency lists and the requirements still ask Agents for sessions.input, lookup, pending and defaultBranchId (Scheduler.md:109, 263; EventHub.md:106, 218). The #2029 head this document cites includes ADR 027, which moves those operations to the target owners: a process caller reaches a branch-group data face by (sessionId, branchId) and a Session-group face by sessionId (ADR 027 D1 and D3), and Agents keeps only its own operations plus holds (ADR 027 D5 and D6). The Agents contract states the split and names Scheduler's pending and default-line reads and EventHub's input, receipt and delete cleanup as by-id calls (origin/pr-2098:docs/design/plugins/Agents.md:239, 275).

Failure scenario. If this contract is implemented as written, Scheduler and EventHub keep a sessions facade that principles §7.2 forbids. When the Agents contract lands, sessions.input, lookup, pending and defaultBranchId are removed (ADR 027 D6), so the two owners lose the interfaces this contract depends on. If Agents keeps them, the facade and the target owners' operations both exist, which the same rule forbids.

Evidence. docs/design/plugins/Scheduler.md:109, 263; docs/design/plugins/EventHub.md:106, 218; ADR 027 D1, D3, D5 and D6 at #2029 head da6f4a9; origin/pr-2098:docs/design/plugins/Agents.md:239, 275.

Fix. Call the InputQueue branch data face and the TimelineTree default-line read by id, keep launch, stop, delete, exists and the delete notice with Agents, and use the Agents lease for restore. If the transitional sessions shape is intended until #2098 merges, say so and link #2098.

3. publication_unknown is no longer named

Problem. The subscribe error list and the Agents requirement drop publication_unknown (EventHub.md:122, 218), while the accepted sessions.input contract still answers it when the input committed and its publication failed (docs/design/contracts/session-access.md:229). The old A.3 made it the stored-success case: the guide committed, so the subscription is stored and the call answers its id. The new text keeps the semantics in prose ("a committed guide stores the record even when its publication is unknown", EventHub.md:122) but no longer names the answer or asks Agents for it. The error table row at EventHub.md:141 also groups rejected with "a committed guide stores the record", although rejected is a refusal.

Failure scenario. A subscribe whose guide input commits but whose reply is lost gets publication_unknown. An implementation that follows the error list treats it as an error and stores nothing, so the branch has a guide block with no subscription and the model is told to subscribe to a source that never delivers. A retry writes a second guide block and can hit the subscription limit. publication_unknown was the one code that prevented this, and it is now absent from the contract.

Evidence. EventHub.md:122, 141, 218; docs/design/contracts/session-access.md:229; docs/design/appserver/sessions-service.md:254; current handling at crates/dim-event-hub/src/subscribe.rs:110.

Fix. Name publication_unknown as the stored-success case in the operation table and the Agents requirement (store the record, reply its id), or define a distinct stored-but-unconfirmed reply with the idempotent retry. Move rejected out of the committed-guide row.

4. The scheduleJobs face loses the caller for tool creates

Problem. Scheduler.md:273 says caller is request data, but CreateJob and UpdateJob carry only job and revision (Scheduler.md:623-636); no request has a caller. The current face carries Caller {session_id, branch_id, cwd} (crates/dim-agent-scheduler/src/methods.rs:1167-1174, 1444-1455), and the tool create uses it to set the target and to forbid a launch target (tool_merge, methods.rs:1193-1225). The new text still says only a management create or update may set a launch target (Scheduler.md:141), but without the caller the owner cannot tell a tool call from a management call.

Failure scenario. A cross-language schedule tool row calls create with {job: {name, schedule, prompt}, revision: null}. The owner has no Session or branch, so it cannot fill the target; the call fails or stores a job with no target. If the row fills JobInput.target itself, the owner cannot reject a launch target from a tool, so the management-only rule is unenforceable.

Evidence. docs/design/plugins/Scheduler.md:141, 273, 623-636; crates/dim-agent-scheduler/src/methods.rs:1167-1174, 1193-1225, 1444-1455.

Fix. Add caller: Caller to the create and update requests, or define separate tool operations with the caller, and state which operations are tool and which are management. Take caller: &Ctx instead if the runtime supplies the calling row.

5. The delivery retention rule is the wrong one

Problem. The flow table says terminal records older than seven days are removed (Scheduler.md:186), but the shipped delivery history keeps the newest 100 terminal deliveries per existing job, plus every delivering record and the last record naming a launch-owned Session (crates/dim-agent-scheduler/src/engine.rs:29, 558-700). Seven days is the wakeup and loop retention rule, not the delivery rule. The new verification asserts "the 100-record history" (Scheduler.md:232), so the two parts of the contract disagree.

Failure scenario. A job with 150 terminal deliveries in seven days: the contract keeps all of them because none is older than seven days, while the shipped owner keeps 100. A job with 20 terminal deliveries older than seven days: the contract drops records the shipped owner keeps and schedule.history can still read. A launch-owned Session's deletion follows its last record, so the retention rule also changes when the Session is deleted.

Evidence. docs/design/plugins/Scheduler.md:186, 232; crates/dim-agent-scheduler/src/engine.rs:29, 558-700; the old contract's rule at the merge base, Scheduler.md:660 and 855, is the newest 100 terminal deliveries per job.

Fix. State the newest 100 terminal deliveries per existing job, the delivering and launch-owner exceptions, and the separate seven-day rule for wakeups and loops. Keep the verification in sync.

6. The omitted branch default is wrong

Scheduler.md:141 says an omitted session branch_id defaults to main, but the shipped management save resolves the Session's current default branch at save time (crates/dim-agent-scheduler/src/methods.rs:683-700); only a legacy stored row without a branch keeps the root fallback. A save after the user moves the default schedules the job on main, the wrong line. Keep the resolution rule and pin both cases in acceptance.

P3 (optional)

  • service-faces.md:334 still says the four subscription operations are on the same eventHub face. EventHub.md:115 puts declare and publish on the face and the other four in process. Update the blockquote and the count; the generated-face error-code sentence at service-faces.md:332 is also outdated now that EventHub uses an error enum.
  • EventHub.md:30 still says a caller reads every subscription; EventHub.md:124 takes {sessionId}. Drop "or every subscription".
  • Scheduler.md:225 says the save answers conflict; the table says schedule_conflict (Scheduler.md:127, 159).
  • Scheduler.md:121 claims the surfaces keep the same error codes, but rejected is new (Scheduler.md:128, 162) and the web's known-error list does not include it (web/src/features/settings/ScheduledSettings.vue:151). List the new code or drop the claim.
  • Operation error lists are incomplete: history can answer schedule_invalid (methods.rs:1096-1103) and locked (runs.rs:35-38), and runNow can answer service_reloading (engine.rs:122).
  • JobInput carries both target and input_mode (Scheduler.md:429-448) and does not say which wins when both are present.
  • ScheduledJob omits absent enabled_at and disabled_reason (Scheduler.md:404-427) while reported() emits null (document.rs:357-370); StopLoopReply always serializes settled (Scheduler.md:745) while session.loop.stop omits it when true (session.rs:401-407). The text claims the wire values are unchanged; either match the current wire or list the difference.
  • Dangling headings: ### 12. Loop (Scheduler.md:198) has no parent §12, and ### 9.1 (EventHub.md:159) has no parent §9.
  • Translation drift: docs/zh/design/contracts/session-boundary.md:579 keeps a dead Scheduler §11.2 anchor; docs/zh/design/appserver/sessions-service.md:337 links plugins/Scheduler.md#21-两个目标 from under appserver/; docs/zh/design/plugins/Notifications.md still cites Scheduler §9. These pages are not updated.
  • EventHub.md:169 says §3.2 has eventHub/eventSubscriptions rows; the actual section is §4.9. EventHub.md:126 still describes a client origin although no client subscribe path ships.

Comment thread docs/design/plugins/Scheduler.md Outdated

The timer evaluates wakeups as part of the same one-second pass as job windows; there is no second scheduler and no Job-engine path. A `scheduled` record whose instant is observed within the grace window fires once: the process owner writes one Queue input through the public `sessions.input` with `submissionId` `wakeup:<wakeup_id>`, a first raw block `<dim-scheduler kind="wakeup">wakeup id</dim-scheduler>`, and the prompt as content. Nothing else is called: no `sessions.launch`, no `sessions.stop`, no `withdraw`, no deadline. Several records due in one pass reach their Sessions in `at` order, with the record id as the stable tie-breaker between records sharing an instant; the file's order is not a contract.
- `sessions` ([#2020](https://github.com/arcships/dim/issues/2020)): `input` for a delivery, `lookup` for the submission id, `pending` for a busy branch, `launch`, `stop` and `delete` for a launch target, and `defaultBranchId` for an omitted branch.

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.

Problem: The dependency asks Agents for sessions.input, lookup, pending and defaultBranchId (also Scheduler.md:263), but ADR 027 at the #2029 head this document cites moves those operations to the target owners and leaves Agents only launch, stop, delete, exists and holds (D1, D3, D6). The Agents contract names Scheduler's pending and default-line reads as by-id calls (origin/pr-2098:docs/design/plugins/Agents.md:239,275).

Failure scenario: an implementation that follows this contract keeps the sessions facade principles §7.2 forbids; when #2098 lands, the methods this owner depends on are deleted, so the contract cannot be implemented as written. If Agents keeps them, the facade and the target owners' operations both exist.

Evidence: docs/design/plugins/Scheduler.md:109,263; ADR 027 D1/D3/D6 at #2029 head da6f4a950; origin/pr-2098:docs/design/plugins/Agents.md:239,275.

Fix: call the InputQueue branch data face and the TimelineTree default-line read by id, keep launch/stop/delete/exists and the delete notice with Agents, and use the Agents lease for restore. If the transitional sessions shape is intended until #2098 merges, say so and link #2098.

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.

Fixed in 853b6aa. Scheduler.md:108-111 now lists Agents' create_session/delete_session/session/acquire, the input owner's submit/pending, TimelineTree's directory and Loop's stop_turn, reached by id. The sessions row is gone. The remaining Dependencies heading for by-id calls is P3 in the new body.

Comment thread docs/design/plugins/Scheduler.md Outdated
| The Scheduler generation unloads (reload, disable, shutdown) | `operation_interrupted`, sent by the existing call admission. The client calls `schedule.watch` again; while the namespace reloads, that call answers `service_reloading`, which is retryable |
| The same connection calls `schedule.watch` again | `{}`, and the new call takes over |
| The connection closes | `{}`, which nobody receives. A disconnect cancels nothing, so the handler ends on `caller.closed()` |
The loop pass does not use `lookup`: it reads `sessions.pending` for the loop's branch, and an inconclusive round is left for the next window; a pending round is not written again. A wakeup fire that gets a definite refusal settles `cancelled`; an uncertain reply keeps the record `scheduled` and retries within the grace; a record past the grace settles `expired` and is never replayed. A job window whose write is uncertain follows the delivery rule above.

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.

Problem: This says the loop pass does not use lookup, but the shipped loop recovery settles a delivering_round by sessions.lookup with loop:<loopId>:<round> (crates/dim-agent-scheduler/src/loops.rs:933-1070). The forward pass reads sessions.pending only when it has last_input_id; a recovered record has no input id because the id comes from the lost reply.

Failure scenario: a loop round's input commits and the reply is lost; the record stays delivering_round (loops.rs:886-914). After a restart the contract's pass reads sessions.pending, which needs an input id the record does not have, so the round stalls or is written again, duplicating the prompt. Scheduler.md:198 also says "the next pass settles it" without the lookup rule.

Evidence: docs/design/plugins/Scheduler.md:192,198; crates/dim-agent-scheduler/src/loops.rs:807-858,886-914,933-1070.

Fix: state that the forward pass reads sessions.pending and the recovery pass settles delivering_round by read-only lookup with the round's submission id; add the crash-after-commit case to the verification.

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.

Fixed in substance at 9b87ef9, still present at 853b6aa: the recovery pass settles a delivering_round by re-submitting loop:<loopId>:<round> (Scheduler.md:187,195). Remaining: Scheduler.md:191 and :232-234 still call it lookup and expect accepted; submit replies {inputId, sequence} (origin/pr-2102:docs/design/plugins/InputQueue.md:81). See P2 3.

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.

Still present in ed43cd9. The recovery paragraph and the verification still say lookup and accepted. See P2 3.


If step 3 fails with `storage`, the process is still running, so EventHub retires the guide input it wrote for each source the failed subscription named that no stored subscription on that branch names, with the same retire form and the submission id `eventhub-guide-retire:<subscriptionId>:<source>` using the failed subscription's id, skips a retire that cannot be written, and then answers `storage` (Appendix C).
- `sessions` ([#2020](https://github.com/arcships/dim/issues/2020)): `input` for an event and a guide, `lookup` for the per-branch idempotency, `exists` for the deletion reconciliation, and `defaultBranchId` for a request that omits its branch. `agent/session-deleted` is the notice that removed the Session's stored rows.

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.

Problem: The dependency asks Agents for sessions.input, lookup and defaultBranchId (also EventHub.md:218), but ADR 027 at the #2029 head this document cites moves those operations to the target owners (D1, D3, D6); the Agents contract names EventHub's input, receipt and delete cleanup as by-id calls (origin/pr-2098:docs/design/plugins/Agents.md:239,275).

Failure scenario: EventHub keeps a sessions facade principles §7.2 forbids; when #2098 lands, input, lookup and defaultBranchId are removed from sessions, so delivery and reconciliation cannot run. If Agents keeps them, the facade and the InputQueue and TimelineTree operations both exist.

Evidence: docs/design/plugins/EventHub.md:106,218; ADR 027 D1/D3/D6 at #2029 head da6f4a950; origin/pr-2098:docs/design/plugins/Agents.md:239,275.

Fix: call the InputQueue branch data face for input and lookup and the TimelineTree read for defaultBranchId by id, keep exists and the delete notice with Agents, and use the Agents lease for restore.

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.

Partially fixed at 853b6aa. EventHub.md:220 now names Agents' session/acquire, the input owner's submit and TimelineTree's directory, but EventHub.md:106 still lists sessions.input/lookup/exists/defaultBranchId and :161 still calls sessions.exists. See P2 1.

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.

Still present in ed43cd9. See P2 1.

Comment thread docs/design/plugins/EventHub.md Outdated
| `too_large` / `invalid_event` | Fix the body or fields; the event was not delivered |
| `limit_reached` | Remove a subscription first; 32 per Session, 1024 in total |
| `session_closed` / `branch_missing` / `branch_ended` | The target cannot take input; fix the target |
| `reloading` / `rejected` / `ambiguous` / `failed` / `transport` | The `sessions` call's answer; a committed guide stores the record and replies its id; `rejected` carries the `sessions` code in `reason` |

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.

Problem: The contract removes publication_unknown from the subscribe errors and the Agents requirement (EventHub.md:122,218), but the accepted sessions.input contract still answers it when the guide committed and its publication failed (docs/design/contracts/session-access.md:229). The old A.3 made it the stored-success case. This row also groups rejected with "a committed guide stores the record", although rejected is a refusal.

Failure scenario: a subscribe whose guide input commits but whose reply is lost gets publication_unknown; an implementation that follows the error list stores nothing, so the branch has a guide block with no subscription and the model is told to subscribe to a source that never delivers. A retry writes a second guide block and can hit the subscription limit.

Evidence: EventHub.md:122,141,218; docs/design/contracts/session-access.md:229; docs/design/appserver/sessions-service.md:254; current handling at crates/dim-event-hub/src/subscribe.rs:110.

Fix: name publication_unknown as the stored success (store the record, reply the id) in the errors table and the Agents requirement, or define a distinct stored-but-unconfirmed reply with the idempotent retry. Move rejected out of this row.

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.

Partially fixed at 853b6aa. EventHub.md:141 and :220 name publication_unknown as the stored-success answer, but the write now targets InputQueue's submit, which has no such code; only withdraw answers it (origin/pr-2102:docs/design/plugins/InputQueue.md:81-82,94, head 823124c7). See P2 2.

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.

Still present in ed43cd9. See P2 2.


## Binding appendix

The job operations are marked on the `Scheduler` owner type under the wire name `scheduleJobs`. `caller` is request data: the Session and branch a tool-created job targets. The wakeup and loop operations are Rust methods on the same owner type; the Session part calls them in process. `next` and the record's internal pass stay off the job face.

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.

Problem: This says caller is request data, but CreateJob and UpdateJob carry only job and revision (Scheduler.md:623-636); no request has a caller. The current face carries Caller {session_id, branch_id, cwd} (crates/dim-agent-scheduler/src/methods.rs:1167-1174,1444-1455), and the tool create uses it to set the target and to forbid a launch target (tool_merge, methods.rs:1193-1225). The new text still says only a management create or update may set a launch target (Scheduler.md:141), but without the caller the owner cannot tell a tool call from a management call.

Failure scenario: a cross-language schedule tool row calls create with {job: {name, schedule, prompt}, revision: null}. The owner has no Session or branch, so it cannot fill the target; the call fails or stores a job with no target. If the row fills JobInput.target itself, the owner cannot reject a launch target from a tool, so the management-only rule is unenforceable.

Evidence: docs/design/plugins/Scheduler.md:141,273,623-636; crates/dim-agent-scheduler/src/methods.rs:1167-1174,1193-1225,1444-1455.

Fix: add caller: Caller to the create and update requests, or define separate tool operations with the caller, and state which operations are tool and which are management. Take caller: &Ctx instead if the runtime supplies the calling row.

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.

Partially fixed at 853b6aa. caller is on CreateJob and UpdateJob (Scheduler.md:130-131, 634-650), and the example supplies it (Scheduler.md:56). Remaining: Scheduler.md:144 says create and update fill a session target from caller and refuse a launch target, but tool_merge fills the target from caller only on create; on update it keeps the stored target and only patches input_mode (crates/dim-agent-scheduler/src/methods.rs:1193-1245), and the shipped tool patch has no target (methods.rs:1156-1166). The example also sends both target (Scheduler.md:52) and caller (Scheduler.md:56). See P2 6.

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.

Still present in ed43cd9. See P2 6.

@eric8810

Copy link
Copy Markdown
Collaborator Author

已按评审修改,head 9b87ef9e3e15cc23d12f938a2895f06c37691934。

本轮处理(剩余 inline 项)

  1. EventHub publication_unknown / rejected。 错误表把 publication_unknown 写成 stored-success:guide 已提交、发布未确认时存记录并回 {subscriptionId},回执丢失先读 list;rejected 单独成行(不存,按 reason 处理);reloading/ambiguous/failed/transport 不存,重试或读 list。Agents 需求写明 sessions.input 的 publication_unknown 由 EventHub 存记录并回 id。EventHub 需求表里“every subscription”的残留改为 events 工具只读本 Session。
  2. Scheduler loop 恢复。 前向 pass 在 last_input_id 存在时读 sessions.pending;恢复 pass 对 delivering_round 用只读 lookup 的 loop:<loopId>:<round> 结算(恢复记录没有 input id);Loop round 流程、12. Loop 的 settled 说明和验收加入“提交后崩溃不重复写”。
  3. Scheduler caller。 create/update 增加可选 caller: Caller {session_id, branch_id};工具的调用填 caller,owner 用其填 session 目标并拒绝 launch(schedule_invalid);管理 save 省略 caller、显式给目标。示例、操作表、附录一致。
  4. service-faces.md。 4.9 的 blockquote 改为生产者面 declare/publish、其余四操作是 events 工具的进程内操作;line 332 的规则改为 EventHub 用 serde 枚举错误、生成面保留 wire code,eventSubscriptions 是旧名。
  5. 规则来源。 两份契约的 §7.2 注记更新到 docs(principles): add owners and operations #2029 head a3c7c4d8a。

自查发现(1–9)

  1. 现状声明逐条对源码/契约:subscribe.rs 的 publication_unknown、loops.rs:933-1070 的 loop 恢复、methods.rs:1167-1174 的 Caller、web/src/rpc/scheduler.ts 的字段、session-access.md:229 的 publication_unknown、docs(principles): add owners and operations #2029 a3c7c4d8a。
  2. 与现有文档的冲突在本 PR 修:EventHub 需求/错误表、Scheduler caller/loop、service-faces 4.9、Session 边界现状列表、sessions-service 链接/默认分支、management-methods 锚点/依赖、overview 的 eventhub.*/run-outcome、Notifications 历史标注、process-typescript 的 processActivity、zh 三页;INDEX/roadmap 的 feat(scheduler): run scheduled jobs through public plugin bindings #317 保留为已合并历史。
  3. 一个概念一个词:publication_unknown 是 sessions.input 的 stored-success 答案,不是 EventHub 错误;rejected 单独;Caller;eventHub 生产者面 vs events 工具;ScheduledJob/Run/Loop/Wakeup;错误码 schedule_conflict 等不变。
  4. 表、流程、例外、Rule check、附录、示例一致;EventHub 错误表与附录枚举、Scheduler Caller 与附录/示例、loop 前向/恢复两路已对齐;临时 crate 编译通过。
  5. 每个结束都写下一步:EventHub 的 publication_unknown/rejected/reloading/transport/cancelled/storage;Scheduler 的 schedule_conflict/rejected/service_*/invalid_data/io/locked/wakeup_not_found/loop_*;caller 种类 × 目标种类(工具 caller + launch → schedule_invalid;管理显式 launch;session 目标)。
  6. 全仓 grep:旧锚点只在 zh 旧页(banner 指向英文契约);eventSubscriptions 只在 service-faces 4.9 的历史块与注记、EventHub 的 Supersedes;eventhub.*/session.wakeup/schedule.watch/loops/wakeups 只在删除/历史说明;代码注释锚点 #91-…/#12-loop 保留。
  7. 规则不写 Rust 拼写;未合并目标用 docs(principles): add owners and operations #2029/docs(design): target contracts for the Agents and Collaboration owners #2098 链接;scan 不作为机制 issue。
  8. 新写的句子按 1–5 重查:publication_unknown 行、Caller、loop 恢复、service-faces。
  9. 其他 PR 的最新 head:#2098 Agents 的 by-id、#2029 a3c7c4d8a、#2091/#2094/#2095/#2093 的契约;跨 PR 部分见下。

留给第二步

绑定附录临时 crate(workspace crates + rutis 0.23.0、rustc 1.100)cargo check 通过;adr-check/xtask-check 与两条 EventHub 文本断言通过。请 @zerob13 复审。

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

Verdict: changes requested. The round-5 fixes hold: the loop recovery text matches loops.rs, the events list row and service-faces 4.9 are corrected, and publication_unknown is now documented as the stored-success answer. Three items still block this as a target contract.

Must fix

1. The omitted branch_id default contradicts the shipped management save.

Scheduler.md:142 says an omitted branch_id defaults to main. The shipped save resolves the Session's current default branch instead: TargetInput::resolve calls shared.default_branch(&session_id) when branch_id is absent; only a stored legacy row without it keeps the root fallback. An implementation that follows the contract would schedule work on main after the user moved the default. Say that the management save resolves the current default, and that a stored legacy row without branch_id means the root. Keep branch_id optional on the management input.

2. EventHub and Scheduler still depend on sessions operations that ADR 027 removes.

EventHub.md:106 and Scheduler.md:110 depend on sessions.input, lookup, pending and defaultBranchId; the requirement blocks repeat them at EventHub.md:220 and Scheduler.md:265. At the cited #2029 head a3c7c4d8a, ADR 027 D6 says the sessions methods that are not Agents' own are deleted and callers reach target owners by id; #2098 names the same reads by id. The PR body leaves this for "step 2". A target contract that keeps a facade the same series deletes is not implementable. Move input/lookup/pending to the InputQueue face and defaultBranchId to the TimelineTree read, and keep launch/stop/delete/exists, the delete notice and the restore lease with Agents. If the current shape is intentionally transitional, say so on those rows, link the follow-up issue, and remove them from the target requirement table.

3. caller on update is under-specified and does not match tool_merge.

Scheduler.md:142 says create and update both fill a session target from caller and refuse a launch target. tool_merge fills the target from caller only on create; on update it keeps the stored target and only patches input_mode when the stored target is a session. As written, an implementer would replace a management-created launch job's target or reject an update it should accept. State the create and update paths separately. Also, the shipped update path never reads caller (it is used only for create's origin and quota), so UpdateJob.caller currently carries no behaviour. Either define what update enforces, or drop the field.

Minor

  • The appendix Caller omits the shipped cwd field. Nothing reads it today, so dropping it is safe, but the appendix is the binding: keep it or say why it is gone.
  • The #2029 head cited at EventHub.md:216 and Scheduler.md:261 is already behind #2029 (9e629e9). The ADR still has D6, so finding 2 is unchanged, but the "reviewed against that head" note goes stale on every push.

Verified

  • loops.rs forward pending path and settle_delivering lookup match the new text, including loop:<loopId>:<round>.
  • subscribe.rs treats publication_unknown as written and stores the subscription before replying its id.
  • CI at 9b87ef9: ci-ok, macos-native and verify (linux) pass.

@eric8810

Copy link
Copy Markdown
Collaborator Author

已按评审修改,head 853b6aaa2。

跨 PR 对齐:

验证:node scripts/adr-check.mjs --base origin/main 通过;链接与锚点无新增断链。

@eric8810
eric8810 requested a review from yyhhyyyyyy November 24, 2026 06:14

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

Scope: target owner contracts for EventHub and Scheduler, with reference updates across 21 design files (refs #2023 and #2015). Reviewed the full main...head at 853b6aaa (merge base 5a279d69), including the new by-id conversion commit.

Verdict: REQUEST_CHANGES

What the new commit changed

853b6aaa replaces Scheduler's sessions dependency list with by-id calls to Agents, InputQueue, TimelineTree and Loop, and changes the requirement and rule check to match. That fixes the Scheduler half of the round-2 sessions finding. EventHub's requirement moved to the same shape, but its dependency row and sessions.exists line did not. Scheduler's recovery paragraph now re-submits the same submissionId, but the answer set, the status word and the verification still describe the old lookup.

P2

1. EventHub still keeps the sessions facade in its dependency row

Problem. EventHub.md:106 still declares sessions with input, lookup, exists and defaultBranchId, and EventHub.md:161 repairs a missed delete notice with sessions.exists. EventHub.md:220 now asks for Agents' session, Agents' acquire, the input owner's submit by (sessionId, branchId) and TimelineTree's directory. ADR 027 D1/D2/D3/D4/D5/D6 and the Agents contract move those calls to the target owners and delete the non-Agents sessions methods (origin/pr-2098:docs/design/plugins/Agents.md:217-229,239, head 59e4316d; origin/pr-2029:docs/adr/027-cross-scope-access-by-id.md D1 to D6, head ff3298f).

Failure scenario. An implementer follows the dependency section, injects sessions and calls input and lookup; #2098 removes them, so delivery and reconciliation cannot run. If Agents keeps them, the facade principles §7.2 forbids and the requirement at :220 both exist, and the two sections of this contract disagree.

Evidence. docs/design/plugins/EventHub.md:106,161,220; origin/pr-2098:docs/design/plugins/Agents.md:217-229,239,275; origin/pr-2029:docs/adr/027-cross-scope-access-by-id.md D1, D2, D3, D4, D6.

Fix. Replace the sessions row with the same by-id calls the requirement names: Agents' session and acquire, the input owner's submit, and TimelineTree's directory. Change :161 to the Agents session read. State that these are by-id calls, not injected dependencies.

2. Both contracts ask submit for publication_unknown, which only withdraw answers

Problem. EventHub.md:220 says the input owner's submit answers publication_unknown, and Scheduler.md:267 lists it as a submit retry answer. At the current InputQueue head, submit replies {inputId, sequence} and its errors are invalid, line_ended, cancelled and closed; publication_unknown belongs to withdraw (origin/pr-2102:docs/design/plugins/InputQueue.md:81-82,94, head 823124c7). The Agents contract resolves a lost reply by re-sending the same submissionId, whose duplicate answers the existing receipt, and says no separate lookup exists (origin/pr-2098:docs/design/plugins/Agents.md:223,276). EventHub's subscribe error table still carries the old sessions.input set at EventHub.md:141-143: publication_unknown, reloading/ambiguous/failed/transport and rejected.

Failure scenario. A guide write or a delivery commits and its reply is lost. submit never answers publication_unknown, so an implementation that waits for it cannot settle the record; one that adds the code to submit diverges from #2102, and one that maps ambiguous or failed sees codes the target does not send. A retry with a new subscription id writes a second guide block.

Evidence. docs/design/plugins/EventHub.md:141-143,220; docs/design/plugins/Scheduler.md:267; origin/pr-2102:docs/design/plugins/InputQueue.md:81-82,91-95; origin/pr-2098:docs/design/plugins/Agents.md:223,276.

Fix. Settle a lost reply by re-sending the same submissionId and using the existing receipt. If publication_unknown is genuinely needed on submit, add it to #2102's submit contract as an explicit requirement and update both error tables; do not assume it. Map the EventHub table to submit's errors and the route errors below, and keep publication_unknown only where withdraw is the operation.

3. Scheduler's recovery text still describes the removed lookup

Problem. Scheduler.md:191 now says a delivering record is settled by re-submitting the same submissionId and that submit answers the existing receipt, but then says "the answer accepted settles delivered with the input's id and sequence" and keeps the old lookup answers unknown, reloading and ambiguous; the next paragraph says a cold Session answers NoSession at the route. submit replies {inputId, sequence} with no status, and its errors are invalid, line_ended, cancelled and closed (origin/pr-2102:docs/design/plugins/InputQueue.md:81,91-95). The verification repeats the old text: "settles delivering records by the read-only lookup" and "the first lookup may answer unknown, and a later accepted settles it" (Scheduler.md:232-234).

Failure scenario. An implementer waits for a status: accepted that submit never returns, or treats invalid or line_ended as an undetermined answer, so every recovery attempt is recorded as unknown and the fifth attempt settles lost although the input committed. The attempt bound is also stated for answers submit does not produce.

Evidence. docs/design/plugins/Scheduler.md:191,232-234; origin/pr-2102:docs/design/plugins/InputQueue.md:81,91-95; origin/pr-2098:docs/design/plugins/Agents.md:223.

Fix. State the submit recovery in submit's terms: the receipt settles delivered with its inputId and sequence; a repeated submissionId returns the existing receipt; a transport failure or the route's retry answer counts toward the persisted bound; line_ended, closed and the route's definite answers settle failed. Add SessionClosing/NoLine handling from #2127. Update the verification.

4. The omitted branch still defaults to main

Problem. Scheduler.md:144 says a session target's branch_id defaults to main. The shipped management save resolves the Session's current default branch when the input omits it (TargetInput::resolve, crates/dim-agent-scheduler/src/methods.rs:683-710, shared.default_branch at :696); only a stored legacy row without a branch keeps the root fallback (crates/dim-agent-scheduler/src/document.rs:240-260). The changed paragraph at docs/design/appserver/sessions-service.md:504 says the management save records the default branch.

Failure scenario. A user moves the Session's default line, then a management save without branch_id schedules the job on main, the wrong line, and the stored job keeps delivering there.

Evidence. docs/design/plugins/Scheduler.md:144; crates/dim-agent-scheduler/src/methods.rs:683-710; crates/dim-agent-scheduler/src/document.rs:240-260; docs/design/appserver/sessions-service.md:504.

Fix. State that a management save resolves and persists the current default, and that a stored row without branch_id means the root. Keep branch_id optional and pin both cases in acceptance.

5. The delivery retention rule is still the wrong one

Problem. Scheduler.md:189 says terminal records older than seven days are removed. The shipped delivery history keeps the newest 100 terminal deliveries per existing job plus every delivering record and the last record naming a launch-owned Session (crates/dim-agent-scheduler/src/engine.rs:29,558-600). Seven days is the wakeup and loop rule (crates/dim-agent-scheduler/src/wakeups.rs:31,379; crates/dim-agent-scheduler/src/loops.rs:40,789). The verification still says "the 100-record history" (Scheduler.md:236).

Failure scenario. A job with 150 terminal deliveries in seven days keeps all 150 here while the owner keeps 100; terminal records older than seven days are dropped although schedule.history reads them today. A launch-owned Session's deletion follows its last record, so the rule also changes when that Session is deleted.

Evidence. docs/design/plugins/Scheduler.md:189,236; crates/dim-agent-scheduler/src/engine.rs:29,558-600; merge base Scheduler.md:660,782,855.

Fix. State the newest 100 terminal deliveries per existing job, the delivering and launch-owner exceptions, and the separate seven-day rule for wakeups and loops.

6. caller is added but create and update are still conflated

Problem. Scheduler.md:144 says the tool's create and update pass caller: Caller and the owner fills a session target from it, refusing a launch target with schedule_invalid. The shipped tool patch has no target (crates/dim-agent-scheduler/src/methods.rs:1156-1166), and tool_merge fills the target from caller only on create; on update it keeps the stored target and only patches input_mode (crates/dim-agent-scheduler/src/methods.rs:1193-1245). UpdateJob.caller is never read. The example sends both target (Scheduler.md:52) and caller (Scheduler.md:56).

Failure scenario. A tool update of a management-created launch job is rejected with schedule_invalid or retargeted to the calling Session, neither of which is shipped behavior; Client-visible changes lists no such change. A tool create that follows the example sends target and caller, and the owner cannot tell which to store.

Evidence. docs/design/plugins/Scheduler.md:52,56,130-131,144,634-650; crates/dim-agent-scheduler/src/methods.rs:1156-1166,1170-1174,1193-1245.

Fix. State the create path and the update path separately; remove target from the tool request or make the caller-only rule explicit; drop caller from UpdateJob if update does not read it. Keep or explain cwd on Caller (methods.rs:1170-1174).

P3 (optional)

  • The route names in Scheduler.md:193 (NoSession) and :267 (NoLine) are both defined by #2127. The requirement still lists only NoLine while the recovery paragraph relies on NoSession and omits SessionClosing. Name all three or point at #2127 for the names and next steps.
  • lookup still appears at Scheduler.md:12,34,181,187,195,197,201,232-234,236 although no lookup operation exists. The P2 3 fix should sweep these to the submit wording.
  • The Scheduler dependency section now lists by-id calls under the heading Dependencies (Scheduler.md:106-111). ADR 027 D4 says a by-id call is not a dependency; retitle the list or mark those rows as calls.
  • The EventHub delete requirement asks for one agent/session-deleted notice for loaded and unloaded Sessions (EventHub.md:161,220), while #2098 splits it into agent/unloaded-session-deleted and agent/session-deleted (origin/pr-2098:docs/design/plugins/Agents.md:235). EventHub should consume both or say the session reconciliation covers the unloaded case. docs/design/plugin-contract.md:209 has the same one-notice wording.
  • EventHub.md:171 says service-faces.md §3.2 has the eventHub/eventSubscriptions rows and §4 the eventSubscriptions section; the section is §4.9. docs/design/appserver/sessions-service.md:489 still links EventHub §3.4, and service-faces.md:354 still references EventHub A.3. The zh counterparts (docs/zh/design/plugin-contract.md:179-180, docs/zh/design/plugins/Notifications.md:41,198,209,362, docs/zh/design/contracts/session-boundary.md:579, docs/zh/design/appserver/sessions-service.md:229,337) still link removed anchors.
  • Dangling headings remain: Scheduler.md:199 has ### 12. Loop without a parent §12, and EventHub.md:159 has ### 9.1 without a parent §9.
  • Scheduler.md:228 says a competing write answers conflict while the table says schedule_conflict (Scheduler.md:162). rejected is new in the table but not in the web's known-error list (web/src/features/settings/ScheduledSettings.vue:151). history can answer schedule_invalid and locked, and runNow can answer service_reloading, but the error columns omit them. StopLoopReply serializes settled even when true while session.loop.stop omits it (crates/dim-agent-scheduler/src/session.rs:401-407), and Caller omits the shipped cwd.
  • EventHub.md:126 still describes a client origin although no client subscribe path ships.
  • The #2029 head cited at EventHub.md:216 and Scheduler.md:263 (a3c7c4d8a) is behind the current head ff3298f. The ADR is unchanged; the note goes stale on every push.

Verification

ADR freeze passes for 21 changed files: node scripts/adr-check.mjs --base 5a279d69. At 853b6aaa, macos-native and changes pass, verify (linux) is in progress, and ci-ok has not reported yet. origin/main is 4d081fe6 (#2029 merged); git merge-tree against it is clean, so there is no textual conflict with main.

Cross-PR

  • #2029 at ff3298f (merged as 4d081fe6): ADR 027 keeps D1 to D6 and §7.2; the new commit changed only docs/templates/owner-redesign.md.
  • #2098 at 59e4316d: the directory table still moves input and lookup to InputQueue, pending to InputQueue, and defaultBranchId to TimelineTree, and says no separate lookup exists (Agents.md:217-229,239,275).
  • #2102 at 823124c7: submit answers {inputId, sequence} with errors invalid, line_ended, cancelled, closed; withdraw is the only operation with publication_unknown (InputQueue.md:81-82,94). The earlier interrupted naming conflict with #2103 is resolved: both now use publication_unknown for withdraw.
  • #2103 at 5d3fddd: session.input.withdraw answers publication_unknown (InputMethods.md:79,92), matching #2102.
  • #2127 is the authority for the route error names NoSession, SessionClosing and NoLine; the contracts should cite it rather than restate a subset.
  • #2100 at c7ec39be: the branch tool chain files do not overlap EventHub or Scheduler; no conflict found.


If step 3 fails with `storage`, the process is still running, so EventHub retires the guide input it wrote for each source the failed subscription named that no stored subscription on that branch names, with the same retire form and the submission id `eventhub-guide-retire:<subscriptionId>:<source>` using the failed subscription's id, skips a retire that cannot be written, and then answers `storage` (Appendix C).
- `sessions` ([#2020](https://github.com/arcships/dim/issues/2020)): `input` for an event and a guide, `lookup` for the per-branch idempotency, `exists` for the deletion reconciliation, and `defaultBranchId` for a request that omits its branch. `agent/session-deleted` is the notice that removed the Session's stored rows.

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.

Problem: This row still declares sessions with input, lookup, exists and defaultBranchId, and EventHub.md:161 still repairs a missed notice with sessions.exists. The requirement at EventHub.md:220 now asks for Agents' session, Agents' acquire, the input owner's submit and TimelineTree's directory. ADR 027 D1/D2/D3/D4/D6 and the Agents contract move those calls to the target owners and delete the non-Agents methods (origin/pr-2098:docs/design/plugins/Agents.md:217-229,239, head 59e4316d).

Failure: an implementer follows this section, injects sessions and calls input/lookup; #2098 deletes them, so delivery and reconciliation cannot run. If Agents keeps them, the facade and the requirement both exist and the two sections disagree.

Evidence: docs/design/plugins/EventHub.md:106,161,220; origin/pr-2098:docs/design/plugins/Agents.md:217-229,239,275; origin/pr-2029:docs/adr/027-cross-scope-access-by-id.md D1, D2, D3, D4, D6 (head ff3298f).

Fix: replace the row with Agents' session and acquire, the input owner's submit, and TimelineTree's directory; change :161 to the Agents session read; state these are by-id calls, not injected dependencies.

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.

Still present in ed43cd9. EventHub.md:106 still declares sessions with input, lookup, exists and defaultBranchId, :161 still calls sessions.exists, and :220 still asks the input owner's submit for publication_unknown. #2098 at c3acab35 still moves these calls by id (Agents.md:219-229,239), and ADR 027 is now in origin/main. Also, replacing lookup for per-branch idempotency requires the deterministic submission id eventhub:{source}:{eventId} (crates/dim-event-hub/src/publish.rs:869-874) and the duplicate receipt; the contract does not state it. See P2 1.


## Requirements raised to mechanism owners

- **Agents (#2020) and the line's input owner (#2027):** Agents' `session` for a target's existence, `acquire` when a subscription's reconciliation must keep a Session loaded, the `agent/session-deleted {agentId, sessionId}` notice, and the input owner's `submit` reached by `(sessionId, branchId)` id, which answers `publication_unknown` when the guide committed and its publication is unconfirmed (targets pending [#2098](https://github.com/arcships/dim/pull/2098) and [#2102](https://github.com/arcships/dim/pull/2102)); TimelineTree's `directory` supplies an omitted branch. EventHub takes no `HostDispatch` object and decodes no reply envelope.

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.

Problem: This asks the input owner's submit to answer publication_unknown. At the current InputQueue head submit replies {inputId, sequence} and its errors are invalid, line_ended, cancelled and closed; publication_unknown is a withdraw answer (origin/pr-2102:docs/design/plugins/InputQueue.md:81-82,94, head 823124c7). The Agents contract resolves a lost reply by re-sending the same submissionId, whose duplicate answers the existing receipt (origin/pr-2098:docs/design/plugins/Agents.md:223,276). The subscribe error table at EventHub.md:141-143 still carries the old sessions.input set (publication_unknown, reloading/ambiguous/failed/transport, rejected).

Failure: a guide commits and its reply is lost; submit never answers publication_unknown, so the subscribe cannot settle, or an implementation adds an out-of-contract code and diverges from #2102. A retry with a new subscription id writes a second guide block.

Evidence: docs/design/plugins/EventHub.md:141-143,220; origin/pr-2102:docs/design/plugins/InputQueue.md:81-82,91-95; origin/pr-2098:docs/design/plugins/Agents.md:223,276.

Fix: settle a lost reply by re-sending the same submissionId and using the existing receipt. If publication_unknown is needed on submit, add it to #2102's submit contract explicitly and update this table; otherwise map the table to submit's errors and the route errors.

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.

Still present in ed43cd9. submit at #2102 3b48e124 replies {inputId, sequence} with invalid, line_ended, cancelled and closed; publication_unknown is a withdraw error (InputQueue.md:81-82,94). EventHub's own EventHubError enum (EventHub.md:416-439) has no PublicationUnknown variant, so the table lists a code the binding cannot produce. See P2 2.

| `{seq: 0, kind: "watching"}` | Once, after the connection's watch is registered and before any change can be sent to it |
| `{seq: n, kind: "jobs"}` | A write to the `schedule` Settings document commits: a job save, delete or pause/resume; from the `schedule` source's `settings.changed` event |
| `{seq: n, kind: "run", jobId, runId, state, terminal}` | A delivery's record changes: one item for each state the record took in that write, in the order the writes happened; `terminal` is true exactly on a state that ends the delivery: `delivered`, `failed`, `lost` or `missed` |
Recovery is read-only and never repeats the input. A `delivering` record is settled by re-submitting the same `submissionId` to the line's input owner (`submit` answers the existing receipt, so no separate lookup operation exists); the answer `accepted` settles `delivered` with the input's id and sequence. `unknown`, `reloading`, `ambiguous` and a transport failure carry no fact: the record stays `delivering`, and each answer counts toward a persisted five-attempt bound. `unknown` is final only for a write that returned before the lookup began; an admitted write whose reply was lost keeps running to its own outcome, so `unknown` cannot settle a record. Each pass persists the incremented `attempts` before it sends the lookup, and a crash between the persist and the lookup still counts that attempt. A record whose stored `attempts` is already five settles `lost` with `detail: lookup_budget_exhausted` before any lookup; the fifth answer without a fact settles `lost` with `detail` naming that answer. `session_closed`, `branch_missing` and `branch_ended` settle the record `failed` and disable the session-target job, cancel the wakeup or stop the loop. A launch record whose Session was never created settles `lost` with `detail: launch_reply_unknown`. The record's stored `job_revision` decides the target-gone disable; a record without it never disables its job. A row reload while an accepted input is in flight is the same case: the first lookup may answer `unknown`, the record stays `delivering`, and a later `accepted` settles it `delivered`; the verification covers it.

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.

Problem: The paragraph now says recovery re-submits the same submissionId, but still says "the answer accepted settles delivered" and keeps the lookup answers unknown, reloading and ambiguous. submit replies {inputId, sequence} with no status, and its errors are invalid, line_ended, cancelled and closed (origin/pr-2102:docs/design/plugins/InputQueue.md:81,91-95, head 823124c7); a duplicate submission id answers the existing receipt (origin/pr-2098:docs/design/plugins/Agents.md:223). The verification repeats the old text at Scheduler.md:232-234.

Failure: an implementer waits for status: accepted that submit never returns, or treats invalid/line_ended as undetermined, so a committed input can be settled lost after five attempts.

Evidence: docs/design/plugins/Scheduler.md:191,232-234; origin/pr-2102:docs/design/plugins/InputQueue.md:81,91-95; origin/pr-2098:docs/design/plugins/Agents.md:223.

Fix: state that the receipt settles delivered with its inputId and sequence; a duplicate returns the existing receipt; transport or the route's retry answer counts toward the bound; line_ended, closed and the route's definite answers settle failed. Update the verification and the remaining lookup wording.

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.

Still present in ed43cd9. The paragraph still says the answer accepted settles delivered and keeps unknown, reloading, ambiguous and lookup; the verification at :232-234 repeats it. submit replies {inputId, sequence} with no status (origin/pr-2102:docs/design/plugins/InputQueue.md:81). See P2 3.

Comment thread docs/design/plugins/Scheduler.md Outdated
- Items go only to the connections that watched: there is no broadcast, and a connection that did not watch receives nothing.
- One watch per connection: a second `schedule.watch` on the same connection answers the earlier call `{}` and takes over, so one change sends one item. The earlier call's progress ends at its reply.
- A watch belongs to the generation that admitted it. The call ends in one of three ways, as the client sees it:
The re-submission reaches the target Session by id: a cold Session answers `NoSession` at the route, the scheduler takes an Agents hold, and the next call after Agents loads the generation delivers; the delivery's admission covers the restore and the call. Admission: the hold is taken before the record's external effect and released after the terminal record. A row unload does not release the old hold; it stays until process shutdown, and the next generation takes a separate hold per unsettled record and releases that one after the terminal record. The next generation reconstructs the unsettled set from the `delivering` records before its first window; `activated` gates the first pass. Scheduler never holds a Session handle across the lookup or the delivery.

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.

P3. NoSession is defined by #2127, and so are SessionClosing and NoLine. The requirement at Scheduler.md:267 lists only NoLine at the route, while this paragraph relies on NoSession and does not mention SessionClosing. Name all three or point at #2127 for the names and next steps. This does not block beyond the P2 recovery fix.

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.

Fixed in ed43cd9. Both route references now cite #2127. The remaining error-vocabulary issue is P2 9: :267 lists session_closed and line_ended at the route although #2127 defines NoSession, SessionClosing and NoLine, and :174 and :191 still settle target-gone with branch_missing and branch_ended.


**Retention.** A terminal record has no consumer after it settles: `list` is its only reader, and a record nobody listed is already unrecoverable, so the bound costs no information the design promises. A terminal record is removed once seven days have passed since it settled — `settled_at`, not `created_at`, so a record created long before it fired is not dropped early; the timer pass removes it in the same write that settles the pass's other outcomes, so the file never grows without bound, the per-second pass never parses more than it must, and `list` reads exactly what is stored. The pass reads the file once per second, takes one clock reading, and writes at most once per pass.
A job's target is the shipped shape: `{kind: "session", session_id, branch_id?, input_mode?}` or `{kind: "launch", cwd, agent_id?, policy?, max_run_minutes?}`. `branch_id` defaults to `main`; `input_mode` defaults to `queue`; `max_run_minutes` defaults to 60. Only a management create or update may set a launch target; the tool's create and update pass `caller: Caller` and the owner fills a session target from it, refusing a launch target with `schedule_invalid`. The management save omits `caller` and carries the target explicitly. A job stores its revision; an update reads the stored job under the Settings change and patches the fields the caller sent. The job's submission ids are `scheduler:<runId>`, `wakeup:<wakeupId>` and `loop:<loopId>:<round>`.

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.

Problem: branch_id defaults to main here, but the shipped management save resolves the Session's current default branch when the target omits it (TargetInput::resolve, crates/dim-agent-scheduler/src/methods.rs:683-710, shared.default_branch at :696). Only a stored legacy row without a branch keeps the root fallback (crates/dim-agent-scheduler/src/document.rs:240-260). The changed paragraph at docs/design/appserver/sessions-service.md:504 says the management save records the current default.

Failure: the user moves the Session's default line, then a management save without branch_id schedules the job on main, the wrong line, and the stored job keeps delivering there.

Evidence: docs/design/plugins/Scheduler.md:144; crates/dim-agent-scheduler/src/methods.rs:683-710; crates/dim-agent-scheduler/src/document.rs:240-260; docs/design/appserver/sessions-service.md:504.

Fix: state that a management save resolves and persists the current default when branch_id is omitted, and that a stored row without branch_id means the root. Keep branch_id optional and pin both cases in acceptance.

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.

Still present in ed43cd9. Scheduler.md:144 still says branch_id defaults to main, and the binding at :327-346 cannot express an omitted branch (Target::Session.branch_id is a required String). The shipped management save resolves the default at crates/dim-agent-scheduler/src/methods.rs:683-714, shared.default_branch at :696; only a legacy stored row keeps the root (document.rs:240-260). See P2 4.

| Wakeup expiry | A record past the grace is `expired` unless its submission id is found; a gone target is `cancelled` | — | — | The next load settles it | Scheduler |
| Loop round | The pass reads the file, writes one queued input, advances the round or leaves the loop `waiting` | A stop settles the record; a pending round is not written | The record stays; the next load re-evaluates | The forward pass reads the input owner's `pending` when it has `last_input_id`; the recovery pass settles a stored `delivering_round` by the read-only `lookup` with `loop:<loopId>:<round>` | Scheduler |
| Loop stop | Settle `stopped`; a terminal record is returned unchanged | — | — | — | Scheduler |
| Retention | Terminal records older than seven days are removed in the pass's write | — | — | The next load prunes | Scheduler |

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.

Problem: This row applies the seven-day rule to deliveries. The shipped delivery retention keeps the newest 100 terminal deliveries per existing job plus every delivering record and the last record naming a launch-owned Session (crates/dim-agent-scheduler/src/engine.rs:29,558-600). Seven days is the wakeup and loop rule (crates/dim-agent-scheduler/src/wakeups.rs:31,379; crates/dim-agent-scheduler/src/loops.rs:40,789). The verification still says "the 100-record history" (Scheduler.md:236), so the contract disagrees with itself.

Failure: a job with 150 terminal deliveries in seven days keeps all 150 here while the owner keeps 100; terminal records older than seven days are dropped here although schedule.history reads them today. A launch-owned Session's deletion follows its last record, so the rule also changes when that Session is deleted.

Evidence: docs/design/plugins/Scheduler.md:189,236; crates/dim-agent-scheduler/src/engine.rs:29,558-600; merge base docs/design/plugins/Scheduler.md:660,782,855.

Fix: state the newest 100 terminal deliveries per existing job, the delivering and launch-owner exceptions, and the separate seven-day rule for wakeups and loops.

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.

Still present in ed43cd9. Scheduler.md:189 still applies seven days to deliveries; the shipped rule is the newest 100 terminal deliveries per existing job plus non-terminal and launch-owner records (crates/dim-agent-scheduler/src/engine.rs:29,558-600). Seven days is the wakeup and loop rule (wakeups.rs:31,379; loops.rs:40,789). :236 still says the 100-record history. See P2 5.

..JobInput::default()
},
revision: None,
caller: Some(Caller { session_id, branch_id }),

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.

Problem: The example sends both a session target (Scheduler.md:52) and caller (here), while Scheduler.md:144 says the tool's create and update pass caller and the owner fills a session target from it. The shipped tool patch has no target (crates/dim-agent-scheduler/src/methods.rs:1156-1166), and tool_merge fills the target from caller only on create; on update it keeps the stored target and only patches input_mode when that target is a session (crates/dim-agent-scheduler/src/methods.rs:1193-1245). UpdateJob.caller is never read (Scheduler.md:644-650).

Failure: a tool update of a management-created launch job is rejected with schedule_invalid or retargeted to the calling Session, neither of which is shipped behavior; Client-visible changes lists no such change. A tool create that follows the example sends target and caller, and the owner cannot tell which to store.

Evidence: docs/design/plugins/Scheduler.md:52,56,144,634-650; crates/dim-agent-scheduler/src/methods.rs:1156-1166,1193-1245.

Fix: state the create path (caller fills the session target) and the update path (stored target kept, input_mode may change) separately. Remove target from the tool request, and drop caller from UpdateJob if update does not read it. Keep cwd on Caller or say why it is gone (methods.rs:1170-1174).

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.

Still present in ed43cd9. Scheduler.md:144 still says create and update both fill a session target from caller; tool_merge fills it only on create and on update keeps the stored target and patches only input_mode (crates/dim-agent-scheduler/src/methods.rs:1193-1245), and UpdateJob.caller is never read. The example still sends target (:52) and caller (:56). See P2 6.

Comment thread docs/design/plugins/Scheduler.md Outdated

## Requirements raised to mechanism owners

- **Agents (#2020), the line's input owner (#2027), TimelineTree (#2024) and Loop (#2027):** the operations the dependency list names, reached by id (ADR 027), with `session_closed`, `line_ended`, `NoLine` at the route, `reloading`, `publication_unknown` and `transport` as the target-gone and retry answers. Scheduler takes no `HostDispatch` object and decodes no reply envelope.

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.

Problem: This lists publication_unknown as a submit retry answer. At the current InputQueue head submit has no such error; only withdraw answers it (origin/pr-2102:docs/design/plugins/InputQueue.md:81-82,94, head 823124c7), and a lost submit reply is resolved by re-sending the same submissionId, whose duplicate answers the existing receipt (origin/pr-2098:docs/design/plugins/Agents.md:223,276). The recovery paragraph at Scheduler.md:191 omits publication_unknown from its no-fact set, so the two sections disagree.

Failure: a delivery commits and its reply is lost; the contract gives no answer that submit can produce, so an implementation either waits for publication_unknown or records the delivery failed/lost while the input was accepted.

Evidence: docs/design/plugins/Scheduler.md:191,267; origin/pr-2102:docs/design/plugins/InputQueue.md:81-82,91-95; origin/pr-2098:docs/design/plugins/Agents.md:223.

Fix: use the duplicate submission receipt and restate the no-fact set as transport plus the route's retry answer; remove publication_unknown from this row unless #2102 adds it to submit. Keep the requirement, the recovery paragraph and the verification on one answer set.

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.

Still present in ed43cd9. Scheduler.md:267 still lists publication_unknown as a submit retry answer; #2102 3b48e124 has no such submit error (InputQueue.md:81-82,94). The delta added the #2127 citation but left the answer set. See P2 2.

@eric8810

Copy link
Copy Markdown
Collaborator Author

补充说明,head ed43cd987(ADR 027 收回到决定层后):

  • Scheduler 的恢复段与机制需求段在 NoSession/NoLine 处引用 #2127,不再把错误归到 ADR 027 D2。
  • 按 id 访问只引用 ADR 027 D1,并链到 #2127;契约不复述 ADR 的内容。

验证:node scripts/adr-check.mjs --base origin/main 通过;链接与锚点无新增断链。

@eric8810
eric8810 requested a review from yyhhyyyyyy November 24, 2026 06:29

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

Scope: target owner contracts for EventHub and Scheduler, plus reference updates across 21 design files (refs #2023, #2015). Reviewed the full main...head at ed43cd9 (merge base 5a279d6). The delta from 853b6aa is two Scheduler citations of #2127 and ADR 027 in ed43cd9; none of the six P2s changed.

Verdict: REQUEST_CHANGES

The six P2s remain

P2 1. EventHub still keeps the sessions facade in its dependency row

Problem. EventHub.md:106 still declares sessions with input, lookup, exists and defaultBranchId, and EventHub.md:161 still repairs a missed notice with sessions.exists. The requirement at EventHub.md:220 asks Agents' session and acquire, the input owner's submit and TimelineTree's directory. ADR 027 is now in origin/main (docs/adr/027-cross-scope-access-by-id.md, D1, D3, D4, D5, D6), and the Agents contract moves sessions.input to InputQueue's submit, sessions.lookup to a re-sent submit, sessions.defaultBranchId to TimelineTree's directory and sessions.exists to session.state (origin/pr-2098:docs/design/plugins/Agents.md:219-229,239, head c3acab35).

Failure. An implementer follows the dependency row, injects sessions and calls input/lookup; #2098 deletes those methods, so delivery and reconciliation cannot run. If Agents keeps them, the facade principles §7.2 forbids and the requirement at :220 both exist, and the two sections disagree. Separately, :106 gives lookup for per-branch idempotency and the publish flow still says "look up each branch" (:153), but the target has no lookup and the contract does not state the deterministic submission id (eventhub:{source}:{eventId}, crates/dim-event-hub/src/publish.rs:869-874). An implementer who submits without it writes a second input on a republish, against the verification at EventHub.md:185.

Evidence. docs/design/plugins/EventHub.md:106,153,161,185,220; ADR 027 D1, D3, D4, D5, D6 in origin/main; origin/pr-2098:docs/design/plugins/Agents.md:219-229,235,239,276.

Fix. Replace the row with Agents' session and acquire, the input owner's submit by (sessionId, branchId) and TimelineTree's directory, marked as by-id calls, not injected dependencies (ADR 027 D4); change :161 to the Agents session read; state the deterministic event submission id and that a duplicate answers the existing receipt; consume both agent/session-deleted and agent/unloaded-session-deleted (origin/pr-2098:docs/design/plugins/Agents.md:235).

P2 2. Both contracts ask submit for publication_unknown, which only withdraw answers

Problem. EventHub.md:220 says the input owner's submit answers publication_unknown; EventHub.md:122,141 keep it in the subscribe errors and the stored-success row; Scheduler.md:267 lists it as a submit retry answer. At the current InputQueue head, submit replies {inputId, sequence} with invalid, line_ended, cancelled and closed; publication_unknown is a withdraw error (origin/pr-2102:docs/design/plugins/InputQueue.md:81-82,94, head 3b48e124). The Agents contract resolves a lost reply by re-sending the same submissionId, whose duplicate answers the existing receipt (origin/pr-2098:docs/design/plugins/Agents.md:223,276). EventHub's own EventHubError enum (EventHub.md:416-439) has no PublicationUnknown variant, so the table lists a code the binding cannot produce.

Failure. A guide write or a delivery commits and its reply is lost; submit never answers publication_unknown, so the subscribe cannot settle, or an implementation adds an out-of-contract code and diverges from #2102. A retry with a new subscription id writes a second guide block and can hit the subscription limit. EventHub's error table also names reloading, rejected, ambiguous, failed and transport, which submit does not send.

Evidence. docs/design/plugins/EventHub.md:122,141-143,220,416-439; docs/design/plugins/Scheduler.md:267; origin/pr-2102:docs/design/plugins/InputQueue.md:81-82,91-95; origin/pr-2098:docs/design/plugins/Agents.md:223,276.

Fix. Settle a lost reply by re-sending the same submissionId and using the existing receipt. Remove publication_unknown from the submit error list and the Scheduler requirement; keep it only where withdraw is the operation. Map the EventHub table to submit's errors and the #2127 route errors. If publication_unknown is genuinely needed on submit, add it to #2102's contract explicitly first.

P2 3. Scheduler's recovery text still describes the removed lookup

Problem. Scheduler.md:191 says recovery re-submits the same submissionId, but then says "the answer accepted settles delivered" and keeps the lookup answers unknown, reloading and ambiguous; :193,197 still say lookup; the verification repeats the old text at :232-234. submit replies {inputId, sequence} with no status (origin/pr-2102:docs/design/plugins/InputQueue.md:81), and a duplicate submission id answers the existing receipt (origin/pr-2098:docs/design/plugins/Agents.md:223).

Failure. An implementer waits for a status: accepted that submit never returns, or treats invalid or line_ended as an undetermined answer, so a committed input is settled lost after five attempts. The verification cannot pass as written.

Evidence. docs/design/plugins/Scheduler.md:191,193,197,232-234; origin/pr-2102:docs/design/plugins/InputQueue.md:81,91-95; origin/pr-2098:docs/design/plugins/Agents.md:223.

Fix. State that the receipt settles delivered with its inputId and sequence; a duplicate returns the existing receipt; a transport failure or the route's retry answer counts toward the persisted bound; line_ended, closed and the route's definite answers settle failed. Sweep lookup and accepted from the flows and the verification.

P2 4. The omitted branch still defaults to main

Problem. Scheduler.md:144 says a session target's branch_id defaults to main, and the binding cannot express an omitted branch: Target::Session.branch_id is a required String with default_branch_id() returning main (Scheduler.md:327-346). The shipped management save resolves the Session's current default branch when the target omits it (TargetInput::resolve, crates/dim-agent-scheduler/src/methods.rs:683-714, shared.default_branch at :696); only a stored legacy row without a branch keeps the root fallback (crates/dim-agent-scheduler/src/document.rs:240-260).

Failure. A user moves the Session's default line, then a management save without branch_id schedules the job on main, the wrong line, and the stored job keeps delivering there. A management save cannot omit the branch at all because the request type fills main.

Evidence. docs/design/plugins/Scheduler.md:144,327-346; crates/dim-agent-scheduler/src/methods.rs:683-714; crates/dim-agent-scheduler/src/document.rs:240-260; docs/design/appserver/sessions-service.md:504.

Fix. State that a management save resolves and persists the current default when branch_id is omitted and that a stored row without branch_id means the root; keep the request branch optional (a separate input type or Option<String>); pin both cases in acceptance.

P2 5. The delivery retention rule is still the wrong one

Problem. Scheduler.md:189 says terminal records older than seven days are removed. The shipped delivery history keeps the newest 100 terminal deliveries per existing job, plus every non-terminal record and the last record naming a launch-owned Session (crates/dim-agent-scheduler/src/engine.rs:29,558-600). Seven days is the wakeup and loop rule (crates/dim-agent-scheduler/src/wakeups.rs:31,379; crates/dim-agent-scheduler/src/loops.rs:40,789). The verification still says "the 100-record history" (Scheduler.md:236), so the contract disagrees with itself.

Failure. A job with 150 terminal deliveries in seven days keeps all 150 here while the owner keeps 100; terminal records older than seven days are dropped here although schedule.history reads them today. A launch-owned Session's deletion follows its last record, so the rule also changes when that Session is deleted.

Evidence. docs/design/plugins/Scheduler.md:189,236; crates/dim-agent-scheduler/src/engine.rs:29,558-600; crates/dim-agent-scheduler/src/wakeups.rs:31,379; crates/dim-agent-scheduler/src/loops.rs:40,789.

Fix. State the newest 100 terminal deliveries per existing job, the non-terminal and launch-owner exceptions, and the separate seven-day rule for wakeups and loops. Keep the verification in sync.

P2 6. caller is added but create and update are still conflated

Problem. Scheduler.md:144 says the tool's create and update pass caller: Caller and the owner fills a session target from it, refusing a launch target. The shipped tool patch has no target (crates/dim-agent-scheduler/src/methods.rs:1151-1165), and tool_merge fills the target from caller only on create; on update it keeps the stored target and only patches input_mode (crates/dim-agent-scheduler/src/methods.rs:1193-1245). UpdateJob.caller is never read, and Caller omits the shipped cwd (Scheduler.md:627-630; crates/dim-agent-scheduler/src/methods.rs:1170-1174). The example sends both target (Scheduler.md:52) and caller (Scheduler.md:56), and JobInput carries both target and input_mode without saying which wins (Scheduler.md:433-446).

Failure. A tool update of a management-created launch job is rejected with schedule_invalid or retargeted to the calling Session, neither of which is shipped behavior, and Client-visible changes lists no such change. A tool create that follows the example sends target and caller, and the owner cannot tell which to store.

Evidence. docs/design/plugins/Scheduler.md:52,56,144,433-446,627-650; crates/dim-agent-scheduler/src/methods.rs:1151-1165,1170-1174,1193-1245.

Fix. State the create path (caller fills the session target) and the update path (stored target kept, input_mode may change) separately. Remove target from the tool request or define a separate tool operation; drop caller from UpdateJob if update does not read it. Keep or explain cwd on Caller, and state the target versus input_mode precedence.

New in round 4

P2 7. The hold rule contradicts the ServerControl target contract

Problem. Scheduler.md:193 says "A row unload does not release the old hold; it stays until process shutdown", and :197 says a row unload does not release accepted work early. The ServerControl target says hold is settled by release or the row's unload (origin/pr-2095:docs/design/plugins/ServerControl.md:79); the calling row's unload releases its holds and a later release answers false (:85,106,114); only a row that crashes without unloading keeps its hold until the process ends (:85).

Failure. After a Scheduler row reload, ServerControl releases the old hold at unload. The next generation takes its own hold per unsettled record only before its first window (Scheduler.md:193). In the gap a graceful shutdown can begin while the delivery is unsettled, so the admission guarantee from before the external effect to the terminal record does not hold. An implementer that keeps the old id and calls release later gets false. The verification at Scheduler.md:233 expects the old hold to stay until process shutdown, which the ServerControl target contradicts.

Evidence. docs/design/plugins/Scheduler.md:193,197,233; origin/pr-2095:docs/design/plugins/ServerControl.md:79,85,106,114 (head fa2eea2c); the current code at crates/dim-app-server/src/control.rs:76-96 is the old behavior, not the target.

Fix. State both cases: a row unload releases the old generation's holds, a crashed row keeps them to process shutdown; the next generation takes its own hold before its first window. If the gap is unacceptable for a graceful close, raise a hold-transfer or hold-survives-unload requirement to #2095 instead of contradicting it. Add a row reload with a shutdown request in the gap to the verification.

P2 8. The launch stop cannot name the turn

Problem. Scheduler.md:112 lists only Loop's stop_turn to stop a launch target, and :183,205 say the launch stops at the deadline. The target Loop face takes {turnId, reason} and the caller must read state for the open turn id (origin/pr-2102:docs/design/plugins/Loop.md:51,78-79); the Agents contract states the same read before sessions.stop (origin/pr-2098:docs/design/plugins/Agents.md:224). The Scheduler dependency and requirement (Scheduler.md:112,267) do not name the state read or the line.

Failure. At the deadline Scheduler has a launched Session id, not a turn id. Calling stopTurn with an unknown id answers an absent reply and writes nothing (origin/pr-2102:docs/design/plugins/Loop.md:78,90), so the launched turn keeps running past the stop time. The current sessions.stop stops the branch's turn by branch id; no target Loop operation does that.

Evidence. docs/design/plugins/Scheduler.md:112,183,205,267; origin/pr-2102:docs/design/plugins/Loop.md:51,78-79,90,96; origin/pr-2098:docs/design/plugins/Agents.md:224.

Fix. Add Loop's state read by line id to the dependency list and the requirement. State that the stop flow reads the open turn id, calls stopTurn({turnId, reason}), and treats an absent reply as already ended. State the line (the launched Session's default line at stop time, or the line recorded at launch) and whether a move of the default changes it.

P2 9. The target-gone error vocabulary contradicts the #2127 citation added in ed43cd9

Problem. Scheduler.md:267 now cites #2127 as the routing mechanism but lists session_closed, line_ended and NoLine "at the route". #2127 defines the route errors as NoSession, SessionClosing and NoLine. Scheduler.md:174 and :191 still settle a target-gone delivery with session_closed, branch_missing and branch_ended. session_closed is an Agents acquire error, line_ended is an InputQueue submit error, and branch_missing/branch_ended are the removed sessions.input codes.

Failure. A job targets a line that ended while the Session is alive; the route answers NoLine, but the settlement rule has no NoLine, so the delivery is not marked failed and the job is not disabled; it fires every window. A cold Session answers NoSession; the rule has no NoSession, so an implementer may count it as an uncertain answer until lost or disable a job whose Session can be restored.

Evidence. docs/design/plugins/Scheduler.md:174,191,267; issue #2127; origin/pr-2102:docs/design/plugins/InputQueue.md:81,94; origin/pr-2098:docs/design/plugins/Agents.md:155,192,224.

Fix. Map the route names: NoSession and SessionClosing take an Agents hold and retry; acquire session_closed and NoLine settle failed and disable; submit line_ended/closed settle failed; invalid settles failed with its detail; cancelled, transport and the route's retry answer keep delivering and count. Name the set once and cite #2127 for the names. Apply the same map to EventHub's subscribe errors.

Optional (P3, unchanged)

  • Scheduler.md:263 and EventHub.md:216 still call #2029 open at a3c7c4d8a; #2029 is merged as 4d081fe6 and ADR 027 is in origin/main.
  • Scheduler.md:107 keeps by-id calls under Dependencies; ADR 027 D4 says a by-id call is not a dependency.
  • EventHub.md:171 still points at service-faces §3.2/§4 for eventSubscriptions; the section is §4.9.
  • docs/zh/design/contracts/session-boundary.md:579 keeps a dead Scheduler §11.2 anchor.
  • Scheduler.md:228 says conflict while the table says schedule_conflict (:162); ScheduledJob omits absent enabled_at/disabled_reason while reported() emits null (crates/dim-agent-scheduler/src/document.rs:357-370); StopLoopReply always serializes settled while session.loop.stop omits it when true (crates/dim-agent-scheduler/src/session.rs:401-407).

Verification

  • CI at ed43cd98: changes, ci-ok, macos-native and verify (linux) pass.
  • node scripts/adr-check.mjs --base 5a279d69 passes for 21 changed files.
  • git merge-tree --write-tree origin/main HEAD is clean against origin/main bf3a4e63.
  • No code tests: the PR changes documentation only and touches no runtime fixture.

Cross-PR

  • #2098 c3acab35: the directory table still moves input, lookup, pending and defaultBranchId, the Session access section keeps the facade out, and the delete notice is split into agent/unloaded-session-deleted and agent/session-deleted.
  • #2102 3b48e124: submit replies {inputId, sequence} with invalid, line_ended, cancelled, closed; publication_unknown is a withdraw error.
  • #2095 fa2eea2c: the hold conflict in P2 7.
  • #2092 3113d18a: TimelineTree's directory answers {default, lines}; the PR's use of it for an omitted branch is correct.
  • #2091 8f9f5e1e: SessionFiles put replies {fileId, path, bytes}; EventHub's requirement matches.
  • #2093 53961a15: SessionScope keeps config and identity; both requirements match.
  • #2103 59a77a3d: no interface overlap with these two contracts.
  • ADR 027 / #2029: merged as 4d081fe6; D1 to D6 and principles §7.2 are in origin/main. The facade conflict is against main, not a pending PR.

- Agents ([#2020](https://github.com/arcships/dim/issues/2020), target, pending [#2098](https://github.com/arcships/dim/pull/2098)): `create_session` for a launch target, `delete_session` at retention, `session` for a target's existence, and `acquire` when work must keep a Session loaded across calls.
- The line's input owner, by `(sessionId, branchId)` id ([#2027](https://github.com/arcships/dim/issues/2027), target, pending [#2102](https://github.com/arcships/dim/pull/2102)): `submit` for a delivery, where a repeated `submissionId` answers the existing receipt, and `pending` for a busy branch.
- TimelineTree ([#2024](https://github.com/arcships/dim/issues/2024), target, pending [#2092](https://github.com/arcships/dim/pull/2092)): `directory` when a job omits its branch.
- Loop ([#2027](https://github.com/arcships/dim/issues/2027), target, pending [#2102](https://github.com/arcships/dim/pull/2102)): `stop_turn` to stop a launch target.

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.

Problem: The dependency lists only Loop's stop_turn, but the target Loop face takes {turnId, reason} and the caller must read state for the open turn id (origin/pr-2102:docs/design/plugins/Loop.md:78-79); the Agents contract states the same read before sessions.stop (origin/pr-2098:docs/design/plugins/Agents.md:224). The requirement at :267 names only the operations in this list.

Failure: a launch record carries a Session id, not a turn id. At the deadline, stopTurn with an unknown id answers an absent reply and writes nothing, so the launched turn keeps running past the stop time. The current sessions.stop stops the branch's turn by branch id; no target Loop operation does.

Evidence: docs/design/plugins/Scheduler.md:112,183,205,267; origin/pr-2102:docs/design/plugins/Loop.md:51,78-79,90; origin/pr-2098:docs/design/plugins/Agents.md:224.

Fix: add Loop's state read by line id to this list and the requirement; state the read of the open turn id, the stopTurn({turnId, reason}) call, the absent reply as already ended, and the line the stop targets.

- Items go only to the connections that watched: there is no broadcast, and a connection that did not watch receives nothing.
- One watch per connection: a second `schedule.watch` on the same connection answers the earlier call `{}` and takes over, so one change sends one item. The earlier call's progress ends at its reply.
- A watch belongs to the generation that admitted it. The call ends in one of three ways, as the client sees it:
The re-submission reaches the target Session by id: a cold Session answers `NoSession` at the route ([#2127](https://github.com/arcships/dim/issues/2127)), the scheduler takes an Agents hold, and the next call after Agents loads the generation delivers; the delivery's admission covers the restore and the call. Admission: the hold is taken before the record's external effect and released after the terminal record. A row unload does not release the old hold; it stays until process shutdown, and the next generation takes a separate hold per unsettled record and releases that one after the terminal record. The next generation reconstructs the unsettled set from the `delivering` records before its first window; `activated` gates the first pass. Scheduler never holds a Session handle across the lookup or the delivery.

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.

Problem: This says a row unload does not release the old hold and it stays until process shutdown. The ServerControl target says hold is settled by release or the row's unload (origin/pr-2095:docs/design/plugins/ServerControl.md:79); the calling row's unload releases its holds and a later release answers false (:85,106,114); only a crashed row keeps them to process shutdown (:85).

Failure: after a Scheduler row reload the old hold is released at unload, and the next generation takes its own hold only before its first window. A graceful close can begin in the gap while the delivery is unsettled, so the admission guarantee from before the external effect to the terminal record does not hold. An implementer that keeps the old id and releases it later gets false.

Evidence: docs/design/plugins/Scheduler.md:193,197,233; origin/pr-2095:docs/design/plugins/ServerControl.md:79,85,106,114 (head fa2eea2); current code crates/dim-app-server/src/control.rs:76-96 is the old behavior.

Fix: state both cases: a row unload releases the old generation's holds, a crashed row keeps them to process shutdown; the next generation takes its own hold before its first window. If the gap is unacceptable, raise a hold-transfer requirement to #2095 instead of contradicting it. Add a reload with a shutdown request in the gap to the verification.


## Requirements raised to mechanism owners

- **Agents (#2020), the line's input owner (#2027), TimelineTree (#2024) and Loop (#2027):** the operations the dependency list names, reached by id ([ADR 027](https://github.com/arcships/dim/pull/2029) D1; the mechanism is [#2127](https://github.com/arcships/dim/issues/2127)), with `session_closed`, `line_ended`, `NoLine` at the route, `reloading`, `publication_unknown` and `transport` as the target-gone and retry answers. Scheduler takes no `HostDispatch` object and decodes no reply envelope.

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.

Problem: This now cites #2127 but lists session_closed, line_ended and NoLine at the route. #2127 defines NoSession, SessionClosing and NoLine. Scheduler.md:174 and :191 still settle target-gone with session_closed, branch_missing and branch_ended; session_closed is an Agents acquire error, line_ended is an InputQueue submit error, and the other two are the removed sessions.input codes.

Failure: a job targets a line that ended while the Session is alive. The route answers NoLine, but the settlement rule has no NoLine, so the delivery is not failed and the job is not disabled; it fires every window. A cold Session answers NoSession; the rule has no NoSession, so an implementer may count it as uncertain until lost or disable a restorable job.

Evidence: docs/design/plugins/Scheduler.md:174,191,267; issue #2127; origin/pr-2102:docs/design/plugins/InputQueue.md:81,94; origin/pr-2098:docs/design/plugins/Agents.md:155,192,224.

Fix: map NoSession and SessionClosing to a hold and retry; acquire session_closed and NoLine to failed and disable; submit line_ended and closed to failed; invalid to failed with its detail; cancelled, transport and the route's retry answer to delivering plus the attempt count. Name the set once and cite #2127 for the names. Apply the same map to EventHub's subscribe errors.

@eric8810

Copy link
Copy Markdown
Collaborator Author

Closing as part of abandoning the owner-split experiment.

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