Skip to content

Move Scheduler, EventHub and Modality to pluginFiles - #1901

Merged
eric8810 merged 5 commits into
mainfrom
eric/1292-domain-plugin-files
Nov 20, 2026
Merged

eric8810 merged 5 commits into
mainfrom
eric/1292-domain-plugin-files

Conversation

@eric8810

@eric8810 eric8810 commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #1292

Implementation

  • pluginFiles.open, scope.withLock/list/remove/directory/openRead/writeStream, and lease text/binary operations already ship.
  • Scheduler, EventHub and Modality open pluginFiles scopes. Modality reads pinned IDs through fsHost. The old catalog entry has been removed.

Callers and operations

  • Scheduler → pluginFiles.open; EventHub → caller-managed PluginFiles::scope retained through publish settlement across row restarts. Both use scope.withLock and lease.read/replace for atomic updates. Reuse list/remove and binary leases where already required.
  • Modality → scope.directory for local adapter paths; scope.openRead → fsHost.readAt/closeRead; scope.writeStream for atomic streamed replacement. Preserve native work/tmp/cache paths, legacy node paths and recorded export names.

Final API

  • pluginFiles.open() → FileScope.
  • Scheduler and EventHub use scope.withLock(path, work, cancelled?) → FileResult<T>. Inside the lease, read() → FileResult<string | null> and replace(text) → FileResult<null>. Reuse scope list/remove and lease readBytes/replaceBytes.
  • Modality uses scope.directory(name) → FileResult<string> for the adapter's local directory, scope.openRead(name) → FileResult<{readId,size} | null> followed by fsHost.readAt/closeRead, and scope.writeStream(name,next) → FileResult<null>. The callback supplies bytes or EOF.

Acceptance

  • Verify ownership, close/unload, pinned lifetime and interrupted writes via native and wire paths. Keep framing policy in its separately tracked issues.
  • Confirm native and foreign calls use the same owner; verify relevant replies, errors, cancellation and unload. Update bindings, generated catalog and declarations where affected.
  • Removed pluginFileTransactions from the generated catalog.

Owner contract · Baseline catalog

Verification

Scheduler transaction, data-face and lifecycle flows (20); PluginFiles flow (8); EventHub flow, including the real Node row (21); Modality flow (81). Regenerated the assembly graph and passed xtask check and the ADR check.

Design rules

Existing process owners keep their state. The native and rutis file bindings share lock acquisition, text envelopes and pinned readers. This migration uses process file operations; it introduces no Timeline commands, handovers, before callbacks, facts, batches or model context changes. Configuration and persisted bytes retain their existing contracts.

@eric8810 eric8810 mentioned this pull request Nov 20, 2026
6 of 45 tasks
@eric8810
eric8810 marked this pull request as ready for review November 20, 2026 04:52

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

Review at 1ab7f4cd (origin/main 31d100f4).

The PR moves Scheduler, EventHub and Modality from the typed PluginFileTransactions service to PluginFiles scopes. Scheduler and EventHub open a scope per process part and keep their text updates under scope.with_lock; Modality uses scope.directory, scope.open_read with fsHost.readAt/closeRead, and scope.write_stream. The generated catalog drops pluginFileTransactions and updates the service faces and the English and Chinese design docs.

Verdict: REQUEST_CHANGES.

P2: the generated app-server services files are stale

Problem. docs/architecture/rust-agent/generated/app-server/services.json:248 records eventhub-ready with id 80, and services.md:15 and services.mmd show p80. A fresh xtask graph built from this worktree writes id 77 in all three files. The rest of the app-server graph matches.

Failure scenario. CI verify runs xtask check, which compares the generated bytes. A fresh graph from this head writes 77, while the committed files say 80, so the check can fail on services.json, services.md and services.mmd; the PR body's "xtask check passed" is not reproducible here. A reader of the committed graph also sees p80 although the assembly run by the current code allocates 77.

Evidence. In this worktree, target/debug/xtask graph changed only the eventhub-ready id in those three files from 80 to 77; no other app-server bytes changed. I restored the files after inspection. git diff --check origin/main...HEAD is clean and git merge-tree --write-tree HEAD origin/main is clean (f149bdd6). The PR body reports that xtask check passed, but that result is not reproducible at this head.

Fix. Rerun cargo run -p xtask -- graph on the final head and commit the resulting services.json, services.md and services.mmd. If the instance id is genuinely nondeterministic, make its allocation deterministic or normalize it before comparing, because xtask check compares exact bytes.

P3: a close failure can orphan the result just written

crates/dim-modality/src/engine.rs:2667-2684 writes a result file, awaits close_read, and only pushes file.name into written after the close succeeds. If write_result succeeds and close_read fails, for example because the reader was released during caller unload, the error branch discards only the earlier names in written; fail_settled with cap set removes the work directory, not result/. The just-written result file is left without a record. Add the name to written before closing, or remove the current file on a close error. This is not blocking.

Verification

  • git diff --check origin/main...HEAD: clean.
  • git merge-tree --write-tree HEAD origin/main: clean (f149bdd6).
  • A fresh xtask graph at this head changes only the app-server eventhub-ready id 80 -> 77 in services.json, services.md and services.mmd; restored afterward.
  • CI at 1ab7f4cd: changes and dependencies pass; verify is pending; web, windows-cli and acp-registry are skipped.
  • I did not rerun the scheduler, pluginFiles, EventHub or Modality test suites at this head. The PR reports 20 scheduler flows, 8 PluginFiles flows, 21 EventHub flows and 81 Modality flows.

Verdict: REQUEST_CHANGES, for the stale generated app-server services files.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing EventHub loader test a_delivery_in_flight_updates_the_view_the_next_generation_reads passes on base 31d100f458 and fails on this head at the assertion that the new generation lists no subscription. Please restore settlement across an EventHub restart. Existing loader test

Comment thread crates/dim-event-hub/src/lib.rs Outdated
fn apply<'a>(&'a self, ctx: &'a Ctx) -> BoxFuture<'a, rutis::Result<Effect>> {
Box::pin(async move {
let files = ctx.require_at(&self.files)?;
let files = ctx.require_at(&self.files)?.open(ctx)?;

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.

This scope is quiesced when the EventHub row unloads. When an admitted publish finishes after the restart, its final Store::change still uses that scope and gets Closed. A branch_ended delivery then reports gone while the ended branch's subscription stays in the file and in the new generation's list. Keep the subscription transaction available to admitted publishes across the EventHub generation change.

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 bd678c2. The EventHub scope now survives the row restart, and cargo test -p dim-event-hub --test loader_flow a_delivery_in_flight_updates_the_view_the_next_generation_reads passes at this head.

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

Review at bd678c2e (origin/main 31d100f4).

The PR moves Scheduler, EventHub and Modality from the typed PluginFileTransactions service to pluginFiles scopes. The new head bd678c2e preserves an admitted EventHub subscription write across a row restart and canonicalizes the process graph IDs.

Verdict: REQUEST_CHANGES.

The prior P2 and P3 are addressed. A fresh xtask check passes (743 modules, 4558 edges), and the generated app-server files now record eventhub-ready as p77; the ID normalization makes the committed graph reproducible. crates/dim-modality/src/engine.rs:2675-2677 records a result name before close_read, so a close failure now discards the file. The EventHub reload regression is fixed: cargo test -p dim-event-hub --test loader_flow a_delivery_in_flight_updates_the_view_the_next_generation_reads passes. I will reply to thread 4638827613.

P2: the contract still describes the old EventHub scope lifetime

Problem. EventHub now opens a caller-managed scope with PluginFiles::scope (crates/dim-event-hub/src/lib.rs:168) and therefore does not register scope.close() with ctx.effect. The contract still says Scheduler and EventHub use pluginFiles.open() (docs/design/contracts/resource-owner-operations.md:13). crates/dim-app-server/README.md:541 says a Rust process plugin opens with PluginFiles::open(ctx), and :533 says to register scope.close() with ctx.effect; docs/design/plugins/EventHub.md:595 still names pluginFiles.open. The new public scope method (crates/dim-app-server/src/plugin_files.rs:530-539) is not described in the contract or README, and FileScope::quiesce stays private, so a Rust caller has no documented way to end a detached scope.

Failure scenario. A maintainer or plugin author follows the contract and uses PluginFiles::open(ctx) for EventHub, registering the cleanup effect. On an EventHub reload, the old scope is quiesced while an admitted publish is still running; its final Store::change gets Closed. The next generation reads the subscription file before that change, so a branch_ended delivery reports gone while the subscription stays. This is the regression the new commit fixes, and the contract would reintroduce it.

Evidence. crates/dim-event-hub/src/lib.rs:168; crates/dim-app-server/src/plugin_files.rs:530-549; docs/design/contracts/resource-owner-operations.md:13; crates/dim-app-server/README.md:533,541; docs/design/plugins/EventHub.md:595.

Fix. Update the contract, README and EventHub storage line to say EventHub uses a caller-managed PluginFiles::scope that survives the row restart until the file service stops, and explain why open() cannot be used there. If scope remains public, give it a documented Rust close or restrict it to a named EventHub-specific path.

Verification

  • git diff --check origin/main...HEAD: clean.
  • git merge-tree --write-tree HEAD origin/main: clean (e67ae612).
  • cargo fmt --all -- --check: passed.
  • node scripts/adr-check.mjs --base origin/main: passed (32 changed files).
  • cargo test -p dim-event-hub --test loader_flow a_delivery_in_flight_updates_the_view_the_next_generation_reads: 1 passed.
  • cargo test -p dim-app-server --test plugin_files_flow: 8 passed.
  • cargo run -p xtask -- check: passed (743 modules, 4558 edges).
  • CI at bd678c2e: changes and dependencies pass; verify is queued; web, windows-cli and acp-registry skip.
  • I did not rerun the Scheduler or Modality suites, or exercise the close-failure path; the PR reports 20 scheduler, 8 PluginFiles, 21 EventHub and 81 Modality flows. No real external service was used.

Verdict: REQUEST_CHANGES, for the stale EventHub scope contract.

| `fileStorage`, `mentionIndex` | File tools and workspace completion use [fsHost §4](../resource-faces.md#4-fshost), including mentions. Storage clients use the owner's file and lease operations. An opened reader uses openRead/readAt/closeRead. |
| `sessionStore` | Session repository, metadata, attachments, Timeline and worktree associations use store, store.readMetadata/setTitle, sessionFiles, timelineStore and store.associateWorktree respectively. Session construction binds the existing Session-scoped timelineStore. Path import and fileId reads use the [Session files contract](../appserver/session-files.md). |
| `pluginFileTransactions` | Scheduler and EventHub use pluginFiles.open(), scope.withLock and lease.read/replace for the same atomic text update. Scope.list/remove and lease.readBytes/replaceBytes have their existing contracts. |
| `pluginFiles` | Scheduler and EventHub use pluginFiles.open(), scope.withLock and lease.read/replace for the same atomic text update. Scope.list/remove and lease.readBytes/replaceBytes have their existing contracts. |

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.

This row still says EventHub uses pluginFiles.open(). The new head uses PluginFiles::scope(Some(ctx)) at crates/dim-event-hub/src/lib.rs:168 so an admitted publish can finish after a row restart. Following this contract reintroduces the EventHub lost-write regression. Update this row, crates/dim-app-server/README.md:533,541, and docs/design/plugins/EventHub.md:595 to describe the detached scope lifetime, and document how a Rust caller ends one.

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 e4742e5. The contract, README, EventHub pages and scope comment now distinguish Scheduler's row-bound open from EventHub's caller-managed scope and describe its lifetime.

@eric8810
eric8810 requested a review from yyhhyyyyyy November 20, 2026 05:52

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

Review at e4742e57 (origin/main 574861f3).

The PR moves Scheduler, EventHub and Modality from PluginFileTransactions to pluginFiles scopes. It adds a caller-managed PluginFiles::scope for EventHub so admitted publishes can finish after a row restart, updates the Scheduler and Modality callers, removes the old typed service, and regenerates the assembly graph and service catalog.

Verdict: APPROVE.

The prior P2 from review 5988130961 is fixed. docs/design/contracts/resource-owner-operations.md:13 now distinguishes Scheduler's row-bound pluginFiles.open() from EventHub's caller-managed scope. crates/dim-app-server/README.md:541 names PluginFiles::scope(Some(ctx.clone())), says the caller releases its last Arc<FileScope> after admitted operations settle, and notes that stopping the file provider cancels and drains them; :533 now limits the scope.close() instruction to a plugin with a row-bound scope. docs/design/plugins/EventHub.md:595 and docs/zh/design/plugins/EventHub.md:590 agree with the code at crates/dim-event-hub/src/lib.rs:168 and the comment at crates/dim-app-server/src/plugin_files.rs:530-539. The EventHub store holds the scope (crates/dim-event-hub/src/store.rs:238-245), and the reload regression test passes. No new contradiction or overclaim remains.

The earlier P2 and P3 are also still fixed. A fresh xtask check passes at 743 modules and 4558 edges; generated app-server/services.json, services.md and services.mmd record eventhub-ready as p77, and the ID normalization in xtask/src/app_server.rs:306-328 makes the graph reproducible. crates/dim-modality/src/engine.rs:2675-2677 records a result name before close_read, so a close failure discards it. I withdraw the prior P2, the prior P3 and the contract P2.

Verification:

  • git diff --check origin/main...HEAD: clean.
  • git merge-tree --write-tree HEAD origin/main: clean (489d4dff).
  • cargo fmt --all -- --check: passed.
  • node scripts/adr-check.mjs --base origin/main: passed (32 changed files).
  • cargo run -p xtask -- check: passed (743 modules, 4558 edges; 97 comment links).
  • cargo test -p dim-event-hub --test loader_flow a_delivery_in_flight_updates_the_view_the_next_generation_reads: 1 passed.
  • cargo test -p dim-app-server --test plugin_files_flow: 8 passed.
  • Cross-PR merge trees with #1916 (9f9b73fc) and #1920 (3510429d) are clean (c9b8142d, bf103127).
  • CI at e4742e57: changes and dependencies pass; verify is queued; web, windows-cli and acp-registry skip.
  • I did not rerun the Scheduler or Modality suites or the close-failure path; the code finding sites are unchanged from bd678c2e, where the PR reports 20 Scheduler, 8 PluginFiles, 21 EventHub and 81 Modality flows.

Verdict: APPROVE.

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

Review summary

I reviewed the merge-base diff for e4742e570fbf290c5e33ebfab3b723b2da07e54c, focusing on who owns each file scope, which writes must survive a plugin restart, and cleanup after a partial Modality result. I found no blocking issues in that scope.

Checks: Static inspection: Scheduler keeps text changes inside a locked transaction. EventHub takes a caller-managed scope at crates/dim-event-hub/src/lib.rs:168, so an admitted delivery can settle after its row restarts; the restart test checks the subscription visible to the new generation. Modality records a written result before closing its reader, so a close error includes that file in cleanup. CI: verify built and linted the workspace, then stopped at the boundary check; the workspace tests did not run and ci-ok failed. The tested main parent reports the same two diagnostics in WebChatTimeline.vue; neither that file nor its checker changed in this PR. Tests not run locally.

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

Review summary

I reviewed the merge-base diff for 514161c47c5df86cdc14f9c9b06fa2360cd752e2, focusing on file ownership across plugin restarts and cleanup after partial writes. I found no blocking issues in that scope.

Checks: Static inspection: the update merges main into the previously reviewed branch. Scheduler still uses a row-bound scope; EventHub retains a caller-managed scope, so a publish admitted before a row restart can finish its subscription write. The loader regression checks the subscription visible to the new generation (crates/dim-event-hub/tests/loader_flow.rs:291–331). Modality records each written result before closing its reader, so a close error does not orphan the file (crates/dim-modality/src/engine.rs:2667–2688). CI: changes and dependencies passed; verify was queued when checked. Tests not run locally.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EventHub restart regression from my earlier review is fixed. Admitted publishes retain their file scope through subscription settlement, and PluginFiles still drains its outstanding operations at shutdown. The exact merge checkout passed the EventHub reload regression, PluginFiles close and interrupted-write flows, Node pinned-reader cleanup, and Modality result publication, cancellation, and native OCR tests. Both verify and ci-ok passed. CI verification

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.

4 participants