Skip to content

design(fileStorage): target contract - #2080

Closed
eric8810 wants to merge 20 commits into
mainfrom
dim/2016-filestorage-contract
Closed

eric8810 wants to merge 20 commits into
mainfrom
dim/2016-filestorage-contract

Conversation

@eric8810

@eric8810 eric8810 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #2016 · Refs #2015

Summary

FileStorage's target contract under design rules §7 (#2029): twelve operations on the fsHost name, marked on the FileStorage type.

  • read(path, offset?, length?) is a stateless read: a whole document up to 8 MiB (base64 fits the 16 MiB frame), or a 64 KiB page with size and eof; offset > size is invalid. stat answers kind and size.
  • add_root and root_path stay as trusted-host values for the sibling contracts (docs(storage): define the session storage owners' target contracts #2091, design(settings): owner contracts for Settings and the settings sections #2094); a root is addressability, not authority.
  • claim(path) and release(claim_id) hold the published auth.json.lock marker; update(path, change, claim_id?) verifies the marker nonce. This is the account-marker possession operation, not a lease object.
  • write and update take callbacks by reference; the source chunk, the change content and the import default are 8 MiB.
  • FileError is serde data with snake_case codes; a callback's own code travels in rejected.reason.
  • Managed OAuth is a single refresher under the marker: claim, HTTP refresh, update comparing credentialRevision, release; waiters re-check and claim when the record did not advance. Four flow tests cover the races.
  • PluginFiles withLock is one update; its contract and callers change in the same delivery.

Supersedes the FileStorage paragraphs in resource-faces, resource-owner-operations, service-faces, session-files, p6-p7-bindings, Modality and process-typescript; the tool family is the file-tools face's (#1297).

Delivery part (deletion list, caller migration, implementation task, acceptance): 目标契约:交付部分.

Merge order

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

Sibling heads this change is aligned with: #2091 f7425d55c, #2095 fa2eea2c7. A paragraph that depends on a sibling names that PR; its head is the one above.

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

FileStorage target contract: review of #2080 at 3aa20e9

Scope. This PR adds docs/design/plugins/FileStorage.md (450 lines) and one row in docs/design/plugins/README.md (+451/-0). It claims the owner contract for FileStorage under the proposed design rules section 7 (#2029, not merged), refs #2016 and #2015. It keeps the wire name fsHost, moves the service onto the FileStorage type, deletes the fileStorage object surface and the FsHost wrapper, and replaces the lease surface with write, update, import, read, add_root and root_path.

Verdict: REQUEST_CHANGES. The document is well structured and its relative links and anchors resolve, but the contract omits a requirement that three current callers depend on, exposes root registration to every plugin, and leaves its error contract, cancellation semantics and cross-design fsHost shapes inconsistent with accepted or in-review designs.

P1

1. The contract removes the only way to hold a file key across several operations, and three callers need it

Problem. The public surface no longer has an id-based lease: the delivery list deletes lock, unlock, FileLease and FileReader and replaces read-decide-write with update(path, change, ...). update's change is called once under the file key, but the contract says it "must only compute: waiting on another owner, on network I/O or on FileStorage itself inside change holds the file for that whole wait" (docs/design/plugins/FileStorage.md:157). It also says no new requirement is raised (:235) and treats the problem as a review-time uncertainty (:206). That leaves callers that must hold the key across several operations or across external I/O with no operation.

Failure scenarios and evidence.

  • Managed OAuth acquires a FileLease (crates/dim-app-server/src/managed_oauth.rs:415-429), holds it across an HTTP token refresh (:1042-1071) and persists the rotated token under the same lease (:1086-1087). If this becomes an update change, the HTTP wait is forbidden; if the wait moves outside, two processes can fetch and persist token rotations from the same refresh token unless the design specifies a compare-and-reject retry. The current serialization is exactly what the lease provides.
  • Migration holds migration/snapshot-run for the whole source lifetime (crates/dim-migration/src/source.rs:104, acquisition at :238-243, stored at :421) while it lists and removes snapshots, copies a database and opens the legacy snapshot. update cannot express a key held across that flow.
  • PluginFiles withLock holds a lease across a caller callback that can call read, replace, backup, readBytes and replaceBytes several times (crates/dim-app-server/src/plugin_files.rs:283-343, lease methods at :383-465, acquisition at :828-845). One change callback cannot preserve this lifetime.

The delivery part linked from the PR body maps these callers to update, write and read without a flow that settles the wait. docs/design/contracts/resource-owner-operations.md:11 still describes the storage clients as using the owner's file and lease operations, and docs/design/resource-faces.md:848 lists managed OAuth and the token stores as using lock, backup and replace {leaseId}.

Fix. Add an id-based lease operation set to the contract (lock returns a lease id; read/replace/backup take the id; unlock releases it), with the caller-cancel, caller-unload and owner-close flows and the party that settles the id. Alternatively, specify for each caller a compare-and-reject (or run-id claim) flow that does the external I/O outside the key and retries on conflict, and remove the claim that no new requirement exists. Do not leave the decision to "review checks each caller's change"; that is the design gap this contract is meant to close.

P2

2. add_root and root_path put root authority on the cross-language face

Problem. add_root makes any existing absolute directory addressable (docs/design/plugins/FileStorage.md:41, :142) and root_path returns a root's absolute path (:42, :143). Both are in the #[rutis::service(name = "fsHost")] block (:358, :362), so every cross-language plugin can call them. The contract also says FileStorage never decides whether a call may run (:23).

Failure scenario and evidence. A plugin calls add_root({path: "/"}) or the user's home directory, then reads or writes arbitrary files through read, write or open_read; the authorized-root boundary becomes self-service. docs/design/p6-p7-bindings.md:155-159 says "FileStorage has register_root and root_path ... expose neither root lookup nor registration. Root registration stays with the trusted host." docs/design/resource-faces.md:831 says roots are internals of the fileStorage/fsHost provider, and the current fileStorage catalog entry is internal(object) (docs/architecture/rust-agent/generated/catalog.md:23), not a cross-language face. The new contract widens that authority without a named caller or trust check.

Fix. Keep root registration and root-path lookup out of the public data face: an assembly or trusted-host operation, not a method on the fsHost service. If they must stay public, define who may call them and how the caller's authority is established; Ctx alone does not decide it. root_path returning every root's absolute path to every plugin has the same issue and should be narrowed or justified.

3. The error contract is not data, and callback error codes are lost

Problem. The operations and error tables describe errors as data with kinds such as invalid, missing_parent, too_large, rejected, unsynced, cancelled and closed (docs/design/plugins/FileStorage.md:163-171), and the delivery part says these seven kinds replace FileStorageError. The binding appendix defines FileError with only thiserror::Error and no serde (:336-352), and Rejected loses the callback's code in From<CallError> (:321-325, which hardcodes "rejected" and reads only message()).

Failure scenarios and evidence. The #[rutis::service] macro classifies a method's error by what it implements; without serde Serialize, it uses the Debug fallback and the Rust variant name as the wire code. A foreign caller therefore receives TooLarge, MissingParent, Rejected and so on, not the snake_case kinds the table documents. For a foreign change or source that fails with {code: "conflict", message: ...}, Rejected::from(CallError) produces {code: "rejected", message: <wire text>}; the caller cannot act on conflict as the table's rejected row requires (:168), and the exception's claim that FileStorage "returns the code and message unchanged" (:192) is false. docs/design/service-faces.md:15 requires errors to be {code, message} data, and ADR 002 D5 (docs/adr/002-plugin-scope.md:97) requires documented error data; the Rule check at docs/design/plugins/FileStorage.md:230 claims D5 is met.

Fix. Make FileError serde data with a documented tag and rename_all = "snake_case" (or an explicit {code, message, data} shape) so the wire codes equal the table. Implement From<CallError> so it recovers the wire error's code and message (the raw bridge error carries both), or make the callback error a serializable struct that the caller passes as data. Add the wire codes to the error table and test one callback failure across the bridge.

4. cancelled says "Nothing changed", while remove and create_directory can change state

Problem. The error table says cancelled: "Nothing changed; the call stopped waiting for the key or stopped before the replacement" (docs/design/plugins/FileStorage.md:170). The same table says create_directory cancels "Between levels; created ancestors stay" (:151), and the flows say a remove tree "can be partly removed, a retry is safe" (:182). The verification depends on that partial removal (:203).

Failure scenario. A caller treats cancelled as a no-op and skips reconciliation because the shared table says nothing changed. A half-removed tree or newly created ancestor directories remain, and the caller's next step sees a state it did not account for. This is the exact state the unsynced row tells callers not to misread for writes (:169), but it does not cover cancellation.

Fix. Scope the "nothing changed" sentence to read, write and update before the rename, and state the partial outcomes for remove, create_directory, import and add_root in their own cancellation columns. A separate outcome or a documented reconciliation step is better than widening the shared error row.

5. The contract redefines fsHost against resource-faces and resource-owner-operations

Problem. docs/design/resource-faces.md:19 defines the fsHost face with a tool family (resolve, read, write, edit, glob, grep, mentions) and a storage family (stat, readBytes, openRead, readAt, closeRead, lock, unlock, backup, createDirectory, replace, list, remove). Section 6 assigns those operations to current callers (:845-852), including readBytes/lock/backup/replace for auth and settings. The new document claims the same wire name (docs/design/plugins/FileStorage.md:239) but defines a different twelve-operation set: read is a whole-document raw-byte read (:144), write/import/update are new (:148-150), add_root/root_path are added (:142-143), and stat, readBytes, lock, unlock, backup and replace are gone.

Failure scenario and evidence. The two designs cannot both be implemented. The names read and write collide: in resource-faces §4.1 they are the file tool's line, encoding and binding operations (docs/design/resource-faces.md:351-352); here they are raw byte operations with different requests and replies. The current generated catalog also has fsHost with the storage family only (docs/architecture/rust-agent/generated/catalog.md:24), so "the wire name stays fsHost" is true only as a name, not as a contract. The wire values also move: privateReadOnly (docs/design/resource-faces.md:387; crates/dim-agent-capabilities/src/file_storage/face.rs:34-40) becomes readOnly (docs/design/plugins/FileStorage.md:255-262), and the native name spelling {Unix: ...} / {Windows: ...} (docs/architecture/rust-agent/plugins/FileStorage.md:37; docs/design/resource-faces.md:376) becomes unix / windows (docs/design/plugins/FileStorage.md:292-298). The statement that a listed name is passed back unchanged (:159) is then false for a caller using the current shape.

Fix. Reconcile the designs in one change: update resource-faces and resource-owner-operations to the new operation set, or choose names and shapes that do not collide, and state who owns the tool family. Define the permission and native-name wire migration explicitly, and either keep privateReadOnly or show that ReadOnly is private plus read-only. A design that claims the same public name with an incompatible method set needs a supersession note, not a parallel contract.

6. Root ids survive a reload only if the assembly reuses the root table

Problem. The contract says a root id "stays valid across generations" and that the root table is append-only (docs/design/plugins/FileStorage.md:185, :193). The current code shares the root table only through a FileStoragePlugin clone: FileStoragePlugin holds Arc<Mutex<Vec<PathBuf>>> (crates/dim-agent-capabilities/src/file_storage.rs:1532-1542), apply clones that Arc (:1550), and close clears the generation's handles (:710-717). The current plugin page warns: "Clone the plugin to preserve append-only authorized-root indices across reload; rebuilding from the original list could reuse indices" (docs/architecture/rust-agent/plugins/FileStorage.md:17-18).

Failure scenario. A reload that rebuilds the plugin from the original root list, instead of reusing the shared table, can reuse a root index. A caller that kept a root id from before the reload then addresses a different directory and reads or writes the wrong tree. The design's delivery part keeps FileStoragePlugin and the append-only semantics but does not state this clone or shared-table requirement.

Fix. State the assembly requirement in the contract and the delivery acceptance: the same root table (or a clone of the plugin) must survive every reload, or root ids must be non-reusable (for example a generation-qualified or random id) and validated. Add a flow test that a retained id addresses the same directory after the reload mechanism actually used by the assembly.

P3

  • Stale #861 claim. The Rule check says #861 is "the one unmet runtime requirement" and the Requirements section says it "remains the runtime's requirement" (docs/design/plugins/FileStorage.md:222, :235). Issue #861 is CLOSED as COMPLETED (2026-11-16, PRs #1625 and #1627). Verify what, if anything, remains and update both lines.
  • README by-scope list. The new row adds a process part (docs/design/plugins/README.md:11), but the "By scope" Process parts list at :55 does not include FileStorage. Add it.
  • Unmerged rules reference. The document cites section 7 at docs/design/plugins/FileStorage.md:157, :224-225 and :230, but the current docs/architecture/rust-agent/principles.md has only sections 1 to 6. Section 7 and the owner-redesign template are in #2029. Link #2029 and state the dependency, or land #2029 first; otherwise the Rule check cannot be verified against the repository.
  • Undefined limits and page size. "The owner's limit" and "the document limit" (docs/design/plugins/FileStorage.md:15, :144, :157, :177, :179) have no value or operation to learn them, and read_at has no page bound or limit parameter (:146; current maximum is 64 KiB). State the limits or the operation that reports them. For import, the table does not say what a missing, linked or non-regular source returns; the invalid row's "a path outside every root" (:165) is the import source's normal condition, not an error. Scope that clause to the destination and add the source cases.
  • Backup composition. "Keep the replaced bytes before a destructive rewrite" is marked composable (docs/design/plugins/FileStorage.md:34), but the example reads, writes a sibling copy and then updates (:93-117); another writer can replace the file in between, so the backup may not be the bytes the update replaces. State the compare-and-reject inside update's change and the retry, or add a backup operation under the key.
  • Another plugin's files. The exceptions say ownership of a file follows the plugin that creates it (docs/design/plugins/FileStorage.md:191), but remove takes any path (:153) and has no ownership check. A caller can remove SQLite's database or the model-log JSONL while its owner is writing. State that remove is limited to the caller's files or provide an owner check; otherwise the ownership sentence is not enforceable.
  • Delivery tables reference. The introduction says PluginFiles' calls "appear in the delivery tables" (docs/design/plugins/FileStorage.md:5), but the delivery tables are in the issue comment linked from the PR body, not in this document. Link them or say where they live.

Verification

  • Head 3aa20e95bc55a1b15bc6f43009f3cb6a9afcd6ff, base merge base cecf65f44bc4dae39b507c35d4a2941153ee8379, diff 2 files, +451/-0. PR is OPEN, not draft, MERGEABLE; all PR check runs are success or skipped and ci-ok is success.
  • node scripts/adr-check.mjs --base cecf65f44bc4dae39b507c35d4a2941153ee8379: passed, 2 changed files, no ADR edit.
  • Relative-link and heading-anchor check over both changed files: 0 broken. All cited file:line references were checked against this checkout or the cited document.
  • GitHub files API: FileStorage.md is one added hunk for lines 1 to 450; README.md is the hunk at new lines 9 to 12 with the added row at line 11. Every inline anchor is inside those hunks.
  • No full build was run. The rutis behavior in finding 3 was checked against the rutis 0.23 macro source; the remaining uncertainty is a compile-level test of the exact FileStorage error type and callback signatures.
  • The proposed section 7 text was read from #2029 head 869ef0d7e439ff97e936164e93f6fb2279d12b15; it is not in this PR or main. That is a review dependency, not a verified merge of #2029.

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

`write`'s `source` is called repeatedly until it returns none: each call yields the next chunk, or a `Rejected` error that ends the write and leaves the target unchanged.

`update`'s `change` is called once while the file's key is held, with the current content or none when the file is absent, and returns the next content or a `Rejected` error. The owner writes the returned content atomically; `applied` is false when that content equals the current content, so a repeated write is idempotent. `change` must only compute: waiting on another owner, on network I/O or on FileStorage itself inside `change` holds the file for that whole wait. §7 allows a callback by reference, and the change is never called inside the Timeline's commit lock.

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 change callback may not wait on network I/O, but three current callers hold a file lease across exactly that work. Managed OAuth refreshes a token under the lease (crates/dim-app-server/src/managed_oauth.rs:1042-1087), Migration holds migration/snapshot-run for its whole source lifetime (crates/dim-migration/src/source.rs:104, :238-243, :421), and PluginFiles withLock holds a lease across a caller callback with several read/replace calls (crates/dim-app-server/src/plugin_files.rs:283-343, :383-465). update is one callback under the key and cannot replace a key held across several operations. The delivery migration maps these callers to update/write/read without a flow, and line 235 says no new requirement. Add an id-based lease operation set, or specify a compare-and-reject or run-id flow for each caller and remove the None new claim.

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.

Partly fixed in e951536. Migration has a run-claim flow (FileStorage.md:131); its liveness check still needs the start time. Managed OAuth's compare-and-reject is not sound with rotating refresh tokens: the current lease serializes one HTTP refresh (crates/dim-app-server/src/managed_oauth.rs:997-1015, :1042-1092; test crates/dim-app-server/tests/managed_oauth_flow.rs:383-390), and the new flow can store the wrong refresh token. PluginFiles' serialization is asserted without a mechanism (FileStorage.md:133; crates/dim-app-server/src/plugin_files.rs:283-350). See the new review 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.

Partly fixed in 7224c0c. Migration's claim now checks the process start time (FileStorage.md:145), and PluginFiles' cross-process rule is one update with the delivery order stated (:147). Managed OAuth remains: the refresh runs outside the published auth.json.lock marker and the commit compares the account generation, not the credential revision. See the new P1 and P2.

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 72ea12c. The refresh runs under the published account marker through claim/release (FileStorage.md:14, :146, :166-167, :201-202), so the lease is no longer needed for Managed OAuth. The remaining P2s are the resource-faces inventory and the section summary; see the new review.

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

| Operation | Intent | Request | Reply | Cancellation | Errors |
| --- | --- | --- | --- | --- | --- |
| `add_root` | Make an existing absolute directory addressable | `{path}` | `{root}`; an existing root answers its id | Before the directory handle is opened | `invalid`, `closed`, `cancelled` |

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.

add_root is on the cross-language fsHost face (:358). Any plugin can call it with / or the user's home and then read or write outside the authorized roots. docs/design/p6-p7-bindings.md:155-159 says to expose neither root lookup nor registration and that root registration stays with the trusted host; docs/design/resource-faces.md:831 says roots are provider internals; the current fileStorage entry is internal(object) (docs/architecture/rust-agent/generated/catalog.md:23). Keep root registration off this service, or define who may call it and how authority is checked. root_path at :143 has the same exposure of absolute paths.

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 on this face in e951536: the public face exposes no root registration or lookup (FileStorage.md:11, :139, :143-151), and p6-p7-bindings.md:155-159 is updated. Sibling contracts #2091 and #2094 still call root_path or add_root; see the 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.

Changed in 7224c0c: add_root and root_path are back on the face (FileStorage.md:11, :159-160). The contract now argues roots are addressability, not authority, and limits registration to a trusted process part (:11, :209). I withdraw the earlier P2 if the trusted-plugin boundary is the accepted model; the contract still names no enforcement, so I noted it as P3.

Comment thread docs/design/plugins/FileStorage.md Outdated
pub type ChangeFn =
Arc<dyn Fn(Option<Bytes>) -> BoxFuture<'static, Result<Bytes, Rejected>> + Send + Sync>;

#[derive(Debug, thiserror::Error)]

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.

FileError derives only thiserror, so it is not serde data. The #[rutis::service] macro then uses the Debug fallback and the Rust variant name as the wire code, not the snake_case kinds in the table (:163-171). From<CallError> for Rejected (:321-325) also drops the callback's code and hardcodes rejected, so a foreign change that returns {code: "conflict"} cannot be acted on as the rejected row requires (:168), and the returns the code unchanged claim at :192 is false. docs/design/service-faces.md:15 and ADR 002 D5 require {code, message} data. Derive serde with a documented tag and rename, and recover the bridge error's code in From<CallError>, or make the callback failure a serializable value.

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 e951536. FileError is serde tagged code with snake_case variants (FileStorage.md:353-374), and From<CallError> recovers the bridge code into reason (:334-342). Checked against the rutis 0.23 FailSerde classification and rutis_bridge::session::Error::code.

Comment thread docs/design/plugins/FileStorage.md Outdated
| `too_large` | Use `open_read` when the caller needs the file in pages, or treat it as not a document |
| `rejected` | The change or the source refused or failed with its own `code` and `message`; act on that code, for example re-read and retry the business step on `conflict` |
| `unsynced` | The bytes are in place but durability is unconfirmed; a read sees them and a repeated call confirms the content; do not assume the earlier call failed |
| `cancelled` | Nothing changed; the call stopped waiting for the key or stopped before the replacement |

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 says nothing changed, but the same table says create_directory keeps created ancestors when cancelled (:151) and the flows say a remove tree can be partly removed (:182, verification :203). A caller that treats cancelled as a no-op leaves partial state. Scope this row to read, write and update before the rename, and state the partial outcomes for remove, create_directory, import and add_root, or return a distinct outcome.

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 e951536: cancelled is scoped to read, write and update and points to the cancellation columns (FileStorage.md:168); create_directory and remove state the partial outcomes (:149, :151, :177-180).

Comment thread docs/design/plugins/FileStorage.md Outdated
| --- | --- | --- | --- | --- | --- |
| `add_root` | Make an existing absolute directory addressable | `{path}` | `{root}`; an existing root answers its id | Before the directory handle is opened | `invalid`, `closed`, `cancelled` |
| `root_path` | A root's absolute directory for another module | `{root}` | `{path}` | None; the owner completes the read | `invalid`, `closed` |
| `read` | Read a whole document within the owner's limit | `{path}` | `{bytes}` or none | While the file is opened | `invalid`, `too_large`, `closed`, `cancelled` |

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.

read here is a whole-document raw-byte operation, but fsHost already names the file tool's line and encoding read in docs/design/resource-faces.md:351, with write at :352, and the storage family includes stat, readBytes, lock, unlock, backup and replace (:19, callers :845-852). This contract claims the same wire name (:239) with an incompatible method set and removes those storage operations, so the two designs cannot both be implemented. Update resource-faces and resource-owner-operations in this change, or split the names; reconcile privateReadOnly to ReadOnly and the {Unix}/{Windows} spelling to unix/windows at the same time.

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.

Mostly fixed in e951536: the tool family is assigned to #1297 and the sibling rows are updated. Still open: six contract links in resource-faces.md point to docs/plugins/FileStorage.md, and §4.1 still lists the tool family under the fsHost heading. See the 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 7224c0c. The six links use plugins/FileStorage.md and resolve; §4 is retitled File storage (fsHost) and the file tools and the tool family is no longer under fsHost (resource-faces.md:344-371). The fsHost row lists the ten operations (:19). One leftover remains in the inventories, see the new P2 on service-faces.

Comment thread docs/design/plugins/FileStorage.md Outdated
- The account marker `auth.json.lock` stays in its published TypeScript-compatible form: the account file is shared with the TypeScript subscriber, and both sides must lock the same file under the same marker protocol.
- Files another plugin owns under a root — SQLite's database, the model-log recorder's JSONL, the UI extension cache — are written by their owners, not through FileStorage; FileStorage answers `root_path` or reads such a file when asked. Ownership of a file follows the plugin that creates and manages it, not the root that contains it.
- `Rejected` carries only `code` and `message`: a callback error must cross languages, so it can come back only as data; the caller keeps its business error type inside its own callback, and FileStorage returns the code and message unchanged.
- Root ids are values that survive a reload: the root table is append-only, so a root id a caller kept stays valid across generations; the id is not a resource handle and carries no authority.

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 promise needs the assembly to reuse the shared root table. The code shares roots only through a FileStoragePlugin clone (crates/dim-agent-capabilities/src/file_storage.rs:1532-1542); close clears the generation's handles (:710-717), and the current plugin page warns that rebuilding from the initial list can reuse indices (docs/architecture/rust-agent/plugins/FileStorage.md:17-18). If a reload rebuilds the plugin, a retained root id can address a different directory. State the clone or shared-table requirement in the contract and acceptance, or use non-reusable root ids.

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 e951536: root ids are gone; roots are host values (FileStorage.md:11, :139), and the acceptance covers a provider reload (:215).

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 7224c0c. The root table stays append-only across a generation (FileStorage.md:192) and the acceptance covers a root id before a provider reload (:240); roots are host values, not reusable indices.

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

## Requirements raised to mechanism owners

None new. [#861](https://github.com/arcships/dim/issues/861) remains the runtime's requirement for reaching a Session's process-scope instance; this contract assumes the host resolves the instance and keeps the name's shape unchanged.

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.

#861 is CLOSED as COMPLETED (2026-11-16, PRs #1625 and #1627), so it is not a remaining unmet runtime requirement, and the Rule check at :222 repeats the stale claim. Verify what, if anything, remains and update both lines; otherwise the None new statement cannot be reviewed.

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 e951536: #861 is removed; the rule check and requirements say no runtime requirement (FileStorage.md:235, :245), and resource-faces §7 and §8 are updated.

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

| Plugin | Process part | Session part | Branch part | Phase / issue |
| --- | --- | --- | --- | --- |
| [FileStorage](FileStorage.md) (owner contract) | roots, byte storage, exclusion and pinned readers behind the `fsHost` operations | — | — | [#2016](https://github.com/arcships/dim/issues/2016) |

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 adds a process part, but the By scope Process parts list at line 55 still omits FileStorage. Add it there too.

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 e951536: README.md:55 lists FileStorage in the Process parts.

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 page moved in 9ab508c. docs/design/plugins/FileStorage.md is deleted, the design plugins README no longer lists FileStorage, and the architecture plugins README carries it as the owner contract (docs/architecture/rust-agent/plugins/README.md:48).

@eric8810

Copy link
Copy Markdown
Collaborator Author

已按评审修改,head e951536ec(base 6c46df95)。逐条处理如下。

P1.1 — id 租约:不采纳;三个调用方的流程写出。 把锁交给调用方违反 §7。契约新增「Callers that hold work across an external wait」:Managed OAuth 在键外完成 HTTP 刷新,update 的 change 比较刷新前的记录,相同写新令牌、不同原样保留并采用存储值;同令牌的并发刷新由先写入者胜出,后到者采用存储记录。Migration 的 run claim 用一次 update 做 create-and-own(存在则 held),内容带 run id、进程 id 与启动时间,后来者按存活检查在同一 update 里替换过期认领,进程退出留下的认领由下一次运行回收。PluginFiles withLock 的多步变更是一次 update 或由 PluginFiles 自己串行,跨进程保证就是「一次 update 排他」。删除「没有新需求」的说法,Requirements 为 None。

P2.2 — add_root/root_path:采纳。 两者从公开面删除。宿主在装配与创建 Session 时通过提供方注册根,并以值把路径交给调用方;公开面没有注册或查询。交付评论的迁移表同步。

P2.3 — 错误数据:采纳。 FileError 改为 serde internally tagged enum,code 是 snake_case(invalid、missing_parent、too_large、rejected、unsynced、cancelled、closed),与错误表一致。Rejected 只带 reason 与 message;From<CallError> 用 into_raw 取回 bridge 错误并读它的 code(),不再硬编码,回调自己的 code 进入 rejected.reason。Exceptions 增加一行说明。

P2.4 — cancelled:采纳。 read/write/update 在替换前取消为「没有改变」;create_directory 已创建的祖先保留、remove 的树可能部分删除,分别写进操作取消列、流程与错误表。

P2.5 — fsHost 重定义:采纳。 resource-faces §1 的 fsHost 行改为存储面七个操作并链接契约;§4 的 storage family 与错误表替换为链接,工具族(resolve/read/write/edit/glob/grep/mentions)明确归文件工具所有者(#1297),不是 fsHost;§6 的 fileStorage 行与调用方矩阵同步。resource-owner-operations、service-faces 的对应行同步。权限与名字的 wire 拼写保持不变(privateReadOnly、{Unix: …}/{Windows: …}),没有 wire 迁移。

P2.6 — 根 id 跨重载: 公开面不再有根 id;根由宿主注册,契约的验收包含「装配注册的根与会话注册的根在提供方重载后指向同一目录」的流程测试。

P3 — 删除 #861 的两处声明(Requirements 为 None);README.md 的 By scope 加入 FileStorage;§7 用 #2029 的 PR 链接并说明依赖;文档上限 16 MiB、页大小 64 KiB 写进契约;import 的缺失、非普通文件、链接 source 归入 invalid;DimOAuth 的备份改为 change 内比较字节、conflict 后重试;「另一个插件的文件」例外改为不可强制执行、根不是所有权边界;契约首段链接交付评论。

Rule E: read(path, offset?, length?, cancelled) -> {data, eof} 取代 open_read/read_at/close_read;页大小与整份上限写进契约;示例、操作表、错误、流程、绑定与交付评论同步。

Rule C: 契约新增 Supersedes 小节;已修改 resource-faces、contracts/resource-owner-operations、service-faces、appserver/session-files、p6-p7-bindings 中描述 FileStorage 的段落,未动其他所有者段落与已接受 ADR。

Client-visible changes: 无。契约只改插件面的 fsHost;客户端协议、通知、Session 文件分页、import 回复的 path、模型可见文本与断连/进度行为不变。

检查:node scripts/adr-check.mjs --base origin/main 通过;cargo run --locked -p xtask-check 通过。

@yyhhyyyyyy 请再看一次。

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

FileStorage target contract: review at e951536

Scope. This PR gives FileStorage its owner contract under design rules §7 (#2029), refs #2016 and #2015. It keeps the fsHost wire name, moves the service onto the FileStorage type, deletes the fileStorage object surface and the FsHost wrapper, and replaces the lease surface with write, update, import, read, create_directory, list and remove. It now also supersedes FileStorage text in six other files: diff 7 files, +505/-124. Round 1 was reviewed at 3aa20e9 with 8 inline comments; the branch was rewritten, so this review is at the new head and rechecks those findings.

Verdict: REQUEST_CHANGES. The expansion fixes the round-1 error-data, cancellation, root-id, backup and README findings and most of the operation-set split. It does not fix the Managed OAuth race introduced by removing the lease, and the new read has no file size, which breaks UI resource paging and the #2095 contract. The supersession also leaves removed operations in the documents this PR edits and in four sibling contracts.

Round-1 status

Round-1 finding Status at e951536 Evidence
P1: removing the lease breaks Managed OAuth, Migration and PluginFiles withLock Partially fixed. Migration has a run claim. Managed OAuth has a compare-and-reject flow that is unsound under refresh-token rotation (P1 below). PluginFiles is asserted, not specified (P2 below). docs/design/plugins/FileStorage.md:125-133; crates/dim-app-server/src/managed_oauth.rs:997-1015, :1042-1092; crates/dim-app-server/src/plugin_files.rs:283-350, :828-844
P2: add_root and root_path on the face Fixed on this face. The host registers roots and hands paths as values; the face has no registration or lookup. Sibling contracts still call them (P2 below). FileStorage.md:11, :139, :143-151; docs/design/p6-p7-bindings.md:155-159
P2: FileError not serde; callback codes lost Fixed. Serde tag code, snake_case variants, and From<CallError> recovers the bridge code into reason. FileStorage.md:334-342, :353-374
P2: cancelled says nothing changed Fixed. Scoped to read, write and update; create_directory and remove point to their partial outcomes. FileStorage.md:149, :151, :168, :177-180
P2: fsHost redefined against resource-faces Partially fixed. The rows and the caller matrix are updated and the tool family moves to #1297, but six links are broken and §4.1 still presents the tool family under the fsHost heading (P2 and P3 below). docs/design/resource-faces.md:19, :24, :344-371; docs/design/service-faces.md:127, :163; docs/design/contracts/resource-owner-operations.md:11
P2: root ids across a reload Fixed by removing root ids. Roots are host values; the acceptance covers a provider reload. FileStorage.md:11, :139, :215
P3: stale #861 Fixed. No #861 claim; requirements are None. FileStorage.md:235, :245; docs/design/resource-faces.md:827, :844
P3: README By scope Fixed. docs/design/plugins/README.md:55
P3: unmerged §7 Fixed. #2029 is linked and the dependency is stated; #2029 at f91b72b has §7. FileStorage.md:221
P3: undefined limits Partially fixed. 16 MiB and 64 KiB are stated, but the 16 MiB whole read does not fit the wire frame, and import's default limit is still undefined. FileStorage.md:15, :153, :157, :259-260
P3: backup window Fixed. The use table and the DimOAuth example compare inside the change and retry; the example has a type error (P3 below). FileStorage.md:34, :89-113
P3: another plugin's files Fixed. The exception says ownership is not tracked and a root is not an ownership boundary. FileStorage.md:188
P3: delivery tables reference Fixed. The introduction links the delivery comment. FileStorage.md:5

P1

1. The Managed OAuth flow loses the provider's rotating refresh token (round-1 P1, not fixed)

Problem. FileStorage.md:129 makes the HTTP refresh run outside the key and says "Two concurrent refreshes with the same refresh token both complete; the first update wins and the second adopts the stored record, so the stored refresh token is always the one a completed refresh last wrote." That is not true for rotating refresh tokens, which the current code expects.

Failure scenario. Two services call credential for the same stale account record. Today credential_inner re-reads under the account lease and refresh performs the HTTP request under that lease (crates/dim-app-server/src/managed_oauth.rs:997-1015, :1042-1092), so one refresh runs and both callers get its token. The flow test asserts refreshes == 1 and both callers get rotated-1 (crates/dim-app-server/tests/managed_oauth_flow.rs:383-390), and the fixture rotates the refresh token on every refresh (:134). Under the new flow both callers refresh with the same old token. If the provider accepts both and rotates again, the provider's current refresh token is the second one, but the second update adopts the first record, so the store keeps the first token and the next refresh can fail invalid_grant. If the provider rejects the second use, the losing caller errors instead of adopting, because a failed refresh never reaches the update. Either way the account can be signed out, and the sentence "the stored refresh token is always the one a completed refresh last wrote" is false.

Fix. Keep an id-based exclusion for the refresh (a §7 resource operation; it does not hand the caller the lease object), or use a run claim like Migration's so only one caller refreshes and the others read the winner's record. If compare-and-reject is kept, define the loser's failure path: on a refresh error, re-read the record and adopt it when its generation or revision changed, and state the provider behavior the flow relies on. Add a two-caller flow test with rotation.

P2

2. The face no longer reports a file's size, and two callers need it

Problem. read answers {data, eof} (FileStorage.md:145, :153), and stat and openRead are deleted. No operation returns a file's length. The old openRead returned {readId, size}.

Failure scenario and evidence. session.ui.resources.read returns {offset, bytes, total, mediaType, data} and requires offset > total to be invalid_params (docs/design/client-ui-extensions.md:188, :208, :437). read_page gets total from read.file.len() and rejects offset > total (crates/dim-app-server/src/ui_extensions/resources.rs:115-120). A page read now returns no size, and an offset past the end returns an empty page with eof (FileStorage.md:58), so the service cannot fill total or tell offset == total from offset > total; it would answer a valid empty page for an invalid offset. #2095's UiResources contract also reads the size at publish (docs/design/plugins/UiResources.md:59, :78). The workflow binding has the same dependency: it checks the opened length before allocating for its 8 MiB cap (docs/design/p6-p7-bindings.md:174).

Fix. Add size to ReadReply (the file length, like the old openRead) or keep a size operation; state that offset > size is invalid and keep the client paging contract.

3. The 16 MiB whole-document limit does not fit the 16 MiB bridge frame

Problem. Bytes crosses as base64 text (FileStorage.md:264, :443). The whole read allows 16 MiB of bytes (:15, :153, :259), so its reply is about 21.3 MiB before JSON overhead. The rutis 0.23 transports cap one message at 16 MiB (rutis-bridge-0.23.0/src/pipe/lines.rs:22-25; src/websocket/config.rs:107, :135). The project already states the constraint: docs/design/p6-p7-bindings.md:174 uses an 8 MiB byte cap so base64 and the JSON envelope fit the 16 MiB frame.

Failure scenario. A foreign caller reads a 12 to 16 MiB document whole. The native flow test passes, but the wire reply is refused by the transport. The same applies to update's current content (FileStorage.md:155, :177) and to each write source chunk, whose bound is only "at most the bridge frame" (:155). The documented wire behavior is not achievable for the stated limit.

Fix. Set the whole-read and change content limit to a wire-safe byte count (8 MiB is the existing precedent) or page the content; state the encoded chunk bound for the source. Add a bridge flow test near the limit.

4. PluginFiles withLock still has no defined serialization

Problem. FileStorage.md:133 says "PluginFiles serializes its callers inside itself" and "FileStorage provides no multi-call session", but no written PluginFiles contract says that and the current code does not do it. The only cross-caller exclusion in the withLock path is the FileStorage lease (crates/dim-app-server/src/plugin_files.rs:283-350, acquisition at :828-844); the admission mutex is released after spawning (:300, :724), and FileScope::with_lock (:578-587) also goes through the lease. The current plugin page says the lease is held through the callback (crates/dim-app-server/README.md:563).

Failure scenario. Two callers run withLock on one plugin file. FileStorage no longer blocks the second and PluginFiles has no per-file in-process lock, so their read, replace and backup steps interleave and one update is lost; if the file is shared across processes, an in-process lock would not help. The delivery comment both says PluginFiles' contract is dispatched separately and that its face changes in sync, so the third round-1 caller is not settled.

Fix. Define the serialization and whether cross-process exclusion is required in the PluginFiles contract before removing the lease, and state the delivery order (one change or a gated follow-up). If cross-process exclusion stays, it needs an owner operation, not an in-process claim.

5. Sibling owner contracts still depend on operations this face deletes

Problem. The new face has no root registration, root lookup, stat or file size, but four sibling contracts in review call them: #2091 calls root_path (docs/design/plugins/SessionFiles.md:167 in #2091); #2093 calls stat (docs/design/plugins/FileAccessFacts.md:46); #2094 calls add_root for project authorization and root_path for the home root (docs/design/plugins/Settings.md:117, :191; docs/design/plugins/ModelLog.md:43); #2095 needs the size (docs/design/plugins/UiResources.md:59, :78).

Failure scenario. None of those contracts can be implemented against this face. The FileStorage delivery would either break them or keep compatibility operations that this contract says do not exist. The Settings case is functional: a runtime project authorization needs a host registration path, not only "the host registers at assembly or Session creation".

Fix. Update those PRs to the host-value and size model in the same delivery, or keep the operations this contract removes. Name the coordination in Supersedes or in the requirements section, and define the host registration path that Settings' authorize_project uses.

6. Removed operations remain in the documents this PR edits

Problem. The supersession is incomplete. docs/design/contracts/resource-owner-operations.md:15 still says fsHost resolution and reads; :22 binds FileScope.openRead to fsHost.readAt and closeRead; :137 has authorize_project register a root; :142 says file-backed settings keep their lease behavior. docs/design/appserver/session-files.md:88 still uses root_path(root), :250, :281 and :624 still use Locked or DirectoryNotEmpty, and :766 still declares create_directory(path: &FilePath). docs/design/p6-p7-bindings.md:23 lists FileStorage replace, and :174 checks the opened handle's length. docs/design/plugins/Modality.md:43 uses fsHost.readAt and closeRead; docs/design/process-typescript.md:468-469 documents the same. The new face has no leases, reader ids, root registration, replace, FilePath or Locked.

Failure scenario. The delivery deletes these names while "superseded" documents still instruct callers to use them. The SessionStore sweep is concrete: it keeps a row on Locked (session-files.md:250), but remove now waits for the key and returns cancelled, closed, invalid or unsynced, so the sweep can block on a writer or mishandle the result.

Fix. Update those rows and sections in this change, or narrow the Supersedes list and open follow-ups with the delivery. In session-files, replace the Locked handling with the new cancellation and retry rules.

P3

  • Broken links. Six new links in docs/design/resource-faces.md use ../plugins/FileStorage.md from docs/design/, which resolves to docs/plugins/FileStorage.md and does not exist: lines 19, 24, 346-347, 364-365, 559-560 and 790. Use plugins/FileStorage.md; a reader following any of them lands on a missing file.
  • fsHost heading. docs/design/resource-faces.md:344-371 keeps the heading ## 4. fsHost and the tool-family table under it, while the new note says the tool family is not part of fsHost and §1 lists only the seven storage operations. Retitle the section or move the tool family; a reader cannot tell which operation set is fsHost's.
  • DimOAuth example does not compile. current is Option<ReadReply>/ReadReply but is passed to a Bytes source and compared with Option<&Bytes> (FileStorage.md:92, :95, :100; signatures at :380-388). Use .ok_or(...)?.data.
  • Undefined import limit and chunk bound. max_bytes absent is "the owner's limit" with no value (FileStorage.md:157); the source chunk bound "at most the bridge frame" is undefined and must account for base64. State both or make max_bytes required; two implementations would otherwise choose different caps.
  • Reply shapes. write and import say {size} but return u64, create_directory says {path} but returns String, list says {entries} but returns Option<Vec<Entry>>, and remove says {} but returns () (FileStorage.md:146-151, :396-437). Only sizes are explained at :443. Make the table match the binding; a foreign caller otherwise implements the wrong shape.
  • Migration claim liveness. The claim carries the owning process id and start time, but the check only says "the recorded process: alive" (FileStorage.md:131). A reused pid keeps a stale claim. Check the start time as the account marker does (docs/architecture/rust-agent/plugins/FileStorage.md:121-132); otherwise a stale claim from a crashed run blocks every later run.
  • Rule check. #2029's template requires the §7.2 owner checks; the table answers only §7 callbacks and one change (FileStorage.md:237-238). Add the §7.2 rows or state them; the design cannot be checked against the template it claims to follow.
  • File-tools face name. #1297 is still titled fsHost while the new text says the tool family is not part of fsHost (FileStorage.md:197; docs/design/resource-faces.md:24). Name the file-tools face in #1297 or here; otherwise the collision returns when #1297 is designed.
  • Binding note. FileStorage.md:443 says "every other argument and reply is data", but every operation also takes the cancelled callback. Except the cancellation argument; the summary contradicts the signatures it introduces.

Verification

  • Head e951536eccbc6213df609a74c8b34a8a9cc30e63, merge-base 6c46df95175a5a0a3fe48ce53af288dbdb4bcfb3, PR open, not draft, MERGEABLE; 7 files, +505/-124.
  • node scripts/adr-check.mjs --base 6c46df95175a5a0a3fe48ce53af288dbdb4bcfb3: passed, 7 changed files.
  • Relative links and heading anchors over the changed files: six broken links, all in resource-faces.md (above); all other relative links and anchors resolve.
  • rutis 0.23: the service macro maps create_directory to createDirectory; FromFunction accepts the SourceFn and ChangeFn aliases; FailSerde uses the serde code tag for FileError; CallError::into_raw and rutis_bridge::session::Error::code exist. The appendix callback and error shapes are sound; a full compile of the appendix was not run.
  • rutis 0.23 transports cap one message at 16 MiB (pipe/lines.rs:22-25, websocket/config.rs:107, :135), the basis for P2 item 3.
  • Section 7 of #2029 was read at its current head f91b72b3c6cf13512b488a4d83b0973509918932; it supports callbacks by reference and one-change, and its design template requires the §7.2 checks.
  • CI: ci-ok passed; the other check runs are skipped for this docs-only change. No full build was run.

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

The public face has no lease. Three callers need exclusion across work that cannot run under the file key; each composes it from `update`, and the owner keeps the guarantee that one `update` is exclusive across processes.

**Managed OAuth.** The HTTP refresh runs outside the key. The refreshed token is written with one `update`: the change compares the stored record with the record read before the refresh. Equal means no other process rotated the token, so the change writes the new token; different means another process won, so the change returns the stored content unchanged and the caller adopts that value. Two concurrent refreshes with the same refresh token both complete; the first `update` wins and the second adopts the stored record, so the stored refresh token is always the one a completed refresh last wrote.

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 concurrent refreshes with the same rotating refresh token do not both complete, and the store can keep the wrong one. Today credential_inner re-reads and refresh sends the HTTP request under the account lease (crates/dim-app-server/src/managed_oauth.rs:997-1015, :1042-1092), so one refresh runs and both callers get its token; the flow test asserts one refresh and both get rotated-1 (crates/dim-app-server/tests/managed_oauth_flow.rs:383-390) and the fixture rotates the refresh token at :134. Here both callers refresh outside the key: if both succeed and the provider rotates again, the provider's current token is the second, but the loser adopts the stored first token and the next refresh can fail invalid_grant; if the provider rejects the second use, the loser errors instead of adopting. Keep an id-based exclusion for the refresh or use a run claim like Migration, and add a two-caller rotation test.

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.

Partly fixed in 7224c0c. The Rust-only race is closed by the claim (FileStorage.md:143), but two parts remain: the refresh runs outside the published auth.json.lock marker that #2096 DimOAuth still requires, so a process that honors the marker can rotate concurrently; and the commit compares the account generation, which the flow test shows is unchanged on refresh (crates/dim-app-server/tests/managed_oauth_flow.rs:392-396), instead of credentialRevision, and does not check its own claim. See the new P1 and P2.

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 72ea12c. The marker is now the exclusion for the refresh (FileStorage.md:146, :179, :201-202), the commit compares credentialRevision, and #2096 at 9ca30e0 states the same protocol (docs/design/plugins/DimOAuth.md:105).

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

**Migration snapshot run.** The run claim is a file whose content carries the run id, the owning process id and its start time. The claim is created by one `update` whose change writes the content only when the file is absent and otherwise refuses with `held`. A later run that finds a claim checks the recorded process: alive means the claim stands; gone means the change replaces the stale claim inside the same `update`. A process that exits leaves the claim behind, and the next run reclaims it by that liveness check; no key is held while a run copies files.

**PluginFiles `withLock`.** A multi-step change that is a pure transform of one record is one `update` over that record, and the cross-process guarantee is exactly "one `update` is exclusive". A change with side effects outside the record does them before the `update` and retries when the change refuses with `conflict`. PluginFiles serializes its callers inside itself where a caller expects its several operations to run alone; FileStorage provides no multi-call session.

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.

PluginFiles does not serialize its callers today and no written PluginFiles contract defines it. The only cross-caller exclusion in the withLock path is the FileStorage lease (crates/dim-app-server/src/plugin_files.rs:283-350, :828-844); the admission mutex is released after spawning (:300, :724) and FileScope::with_lock (:578-587) also goes through the lease. Removing the lease leaves two callers free to interleave read, replace and backup. The delivery comment says PluginFiles' contract is dispatched separately while its face changes in sync. Define the serialization and whether cross-process exclusion is required in the PluginFiles contract before removing the lease, or keep an owner operation for 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.

Partly fixed in 7224c0c. The cross-process guarantee is now one update over the record, and the delivery order is stated (FileStorage.md:147). The written PluginFiles contract is still outside this PR, and the caller's own result from withLock has no stated return path through UpdateReply; that belongs in the PluginFiles contract in the same delivery.

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

| Operation | Intent | Request | Reply | Cancellation | Errors |
| --- | --- | --- | --- | --- | --- |
| `read` | Read a whole document, or one page of a file | `{path, offset?, length?}` | `{data, eof}` or none | Before the reply; nothing changes | `invalid`, `too_large`, `closed`, `cancelled` |

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 read reply has no size. crates/dim-app-server/src/ui_extensions/resources.rs:115-120 needs total for session.ui.resources.read and rejects offset > total; the client contract returns {offset, bytes, total, mediaType, data} and requires that error (docs/design/client-ui-extensions.md:188, :208, :437). #2095's UiResources contract also reads the size at publish (docs/design/plugins/UiResources.md:59, :78), and the workflow binding checks the opened length for its 8 MiB cap (docs/design/p6-p7-bindings.md:174). A page past the end now returns an empty page with eof, so the caller cannot tell offset == total from offset > total. Add size to ReadReply or keep a size operation.

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 7224c0c. ReadReply has size and stat returns the kind and length (FileStorage.md:162, :315-336), offset > size is invalid (:170), and #2095 at 82c6f8e maps the size to total.

Comment thread docs/design/plugins/FileStorage.md Outdated
| `list` | One level of a directory | `{path}` | `{entries}` or none when the directory is absent | Before the reply | `invalid`, `closed`, `cancelled` |
| `remove` | Make a file or a directory tree absent; an absent entry counts as removed | `{path}` or `{parent, name}` | `{}` | Before the entry is unlinked; a tree can be partly removed, a retry is safe | `invalid`, `unsynced`, `closed`, `cancelled` |

`read` without `offset` and `length` reads the whole document up to 16 MiB and answers `too_large` above it; with both, it reads one page of at most 64 KiB (`length` above the page is clamped) and `eof` is true when the page reaches the end; one of the two alone is `invalid`. An absent file answers none.

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.

A 16 MiB document does not fit the cross-language frame. Bytes crosses as base64 (FileStorage.md:264, :443), so a 16 MiB read replies with about 21.3 MiB plus JSON; the rutis 0.23 transports cap one message at 16 MiB (rutis-bridge-0.23.0/src/pipe/lines.rs:22-25, src/websocket/config.rs:107, :135), and p6-p7-bindings.md:174 uses 8 MiB precisely to leave room for base64 and the envelope. The same applies to update's current content and the write source chunks. A native test passes but the wire reply is refused. Use a wire-safe byte limit (8 MiB is the precedent) or page the content, and state the encoded chunk bound.

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 7224c0c. The whole read, each chunk and the import default are 8 MiB raw (FileStorage.md:170, :293-298), with the base64 and frame rationale, and a bridge test near 8 MiB is in the acceptance (:233).

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

FileStorage owns:

- **Roots.** The process's authorized directories and their open handles. The host registers a root through the provider when it assembles the process and when it creates a Session; the public face exposes neither registration nor root lookup. A caller receives absolute paths from the host value that names its root.

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 host-value model is not reflected in the sibling contracts in review. #2091 still calls root_path (docs/design/plugins/SessionFiles.md:167 in #2091), #2093 still calls stat (docs/design/plugins/FileAccessFacts.md:46), #2094 calls add_root and root_path (docs/design/plugins/Settings.md:117, :191, docs/design/plugins/ModelLog.md:43), and #2095 needs a file size the face does not expose (docs/design/plugins/UiResources.md:59, :78). None can be implemented against this face. Update those PRs in the same delivery or keep the operations, and define the host registration path that Settings' authorize_project calls.

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.

Mostly fixed in 7224c0c. The face has add_root, root_path and stat, and #2091, #2093, #2094 and #2095 use the operations this contract lists (FileStorage.md:226). Two conflicts remain: #2091 at 0aec7ae says a read past the end is empty while FileStorage.md:170 says invalid, and #2096 at 13f9b94 still keeps the account lease/lock and Modality's readAt/closeRead.

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.

Resolved at the current sibling heads. #2091 at 9ff2b07 clamps an offset above size to size before read (SessionFiles.md:79); #2096 at 9ca30e0 uses claim/release for the marker and says no TypeScript source writes auth.json (DimOAuth.md:105, :134).

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

`write`'s `source` and `update`'s `change` are direct method parameters, not request fields. `source` is called repeatedly until it returns none: each call yields the next chunk of at most the bridge frame, or a `Rejected` error that ends the write and leaves the target unchanged. `change` is called once while the file's key is held, with the current content (at most 16 MiB) or none when the file is absent, and returns the next content or a `Rejected` error; `applied` is false when that content equals the current content, so a repeated write is idempotent. `change` must only compute: waiting on another owner, on network I/O or on FileStorage itself inside `change` holds the file for that whole wait. §7 allows a callback by reference, and the change is never called inside the Timeline's commit lock.

`permissions` is absent for "keep the existing mode; a new file gets the owner's default": `private` is owner-only (0600), `privateReadOnly` is owner-only and read-only (0400), the attribute Session files use. `max_bytes` is absent for the owner's limit. A listed name is passed back to `remove` unchanged. FileStorage waits for a file's key until the caller cancels or the owner closes; there is no fixed bound, so a call that must not wait ends with its cancellation.

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.

max_bytes absent is the owner's limit, but no value is defined (the appendix has only DOCUMENT_LIMIT and PAGE_LIMIT), and the source chunk bound is at most the bridge frame, which is undefined and must account for base64. State the import default and the encoded chunk bound, or make max_bytes required.

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 7224c0c. max_bytes absent is the owner's 8 MiB default, and a source chunk is at most 8 MiB raw with a larger chunk invalid (FileStorage.md:172-174, :297-298).

Comment thread docs/design/resource-faces.md Outdated
| `timelineStore` | Timeline operations and completion notifications (§5.1) | the Session state owner | #1298 |


The tool family (`resolve`, `read`, `write`, `edit`, `glob`, `grep`, `mentions`) is the file-tools owner's operations and is not part of `fsHost`; [#1297](https://github.com/arcships/dim/issues/1297) tracks that design. `fsHost` is the storage face of the [FileStorage contract](../plugins/FileStorage.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.

Six new links in this file point to docs/plugins/FileStorage.md, which does not exist, because ../plugins/ from docs/design/resource-faces.md leaves docs/design: lines 19, 24, 346-347, 364-365, 559-560 and 790. The contract is at docs/design/plugins/FileStorage.md; use plugins/FileStorage.md (and plugins/FileStorage.md#errors at line 560).

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 7224c0c. All six links now use plugins/FileStorage.md and resolve at the head; a link and anchor check over the nine changed files found no new broken link.


## 4. `fsHost`

The storage family in §4.1 and the error table in §4.7 are superseded by the [FileStorage

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 note says the tool family is not part of fsHost, but the section heading is still ## 4. fsHost and §4.1 still lists resolve, read, write, edit, glob, grep and mentions as its methods (:350-371), while §1 lists only the seven storage operations for fsHost (:19). Retitle the section or move the tool family so the document has one answer.

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 7224c0c. §4 is File storage (fsHost) and the file tools, and the note and §4.1 say the tool family is not fsHost (resource-faces.md:344-371).

| --- | --- |
| `hostPlatform` | Exec and Shell use the task and PTY operations in [execHost §3](../resource-faces.md#3-exechost). Hooks calls configured(request); OCR calls confined(request). Both return the result of that call. Process handles remain with the platform. |
| `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. |
| `fileStorage`, `mentionIndex` | Storage clients use the [FileStorage contract](../plugins/FileStorage.md): `read`, `write`, `import`, `update`, `createDirectory`, `list` and `remove`, with no lease or reader id. File tools and workspace completion keep the tool family under [#1297](https://github.com/arcships/dim/issues/1297). |

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 is updated, but the same file still maps removed operations: line 15 says fsHost resolution and reads; line 22 binds FileScope.openRead to fsHost.readAt/closeRead; line 137 has authorize_project register a root; line 142 says file-backed settings keep their lease behavior. The delivery deletes readAt, closeRead, FileReader, root registration and lookup, and leases. Update these rows in this change or narrow the supersedes claim.

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.

Partly fixed in 7224c0c. The fileStorage row, the openRead row and the file-backed Settings row are updated (resource-owner-operations.md:11, :22, :142), and authorize_project now matches add_root. Two leftovers: the paragraph at :26 still says pinned reader and an existing reader ID, and the row at :11 still omits addRoot, rootPath and stat. See the new P2s.

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 72ea12c. docs/design/contracts/resource-owner-operations.md:11 lists the twelve operations, and :26-27 cross no reader id.

holds its lease only while it writes. The sweep never removes a pending file of the live
**Order against Session close and keys.** S5c closes the Session first, then commits its
delete transaction, then SessionStore sweeps. No FileStorage key outlives a put: `write`
holds its key only while it writes. The sweep never removes a pending file of the live

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 next sentence still says a deletion can meet Locked or DirectoryNotEmpty (:281), and the sweep flow still handles Locked (:250) and §12 repeats it (:624). The new contract has neither error: remove waits for the key and returns cancelled, closed, invalid or unsynced, and the acceptance states a tree removal with a held child waits. The sweep rule no longer matches. The superseded sections also still use root_path(root) (:88) and FilePath (:766). Fix the flow and those references.

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 7224c0c. The sweep handles cancelled, unsynced and I/O error (session-files.md:250), §6 talks about keys not Locked (:281), §13 is updated (:624), and the appendix confirms the new create_directory signature and errors (:766). root_path(root) at :88 is valid again because the face has root_path.

@eric8810

eric8810 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

已按评审与自查标准修改,head 7224c0cd4(base 6e86d48c)。

评审逐条

P1.1 Managed OAuth 轮换 token:采纳单一刷新者(未加 lock/unlock)。 记录带 generation 与 claim 字段;需要刷新者先用一次 update 写 claim(已有则 held),claim 带刷新者进程 id、启动时间与读到的 generation。胜者 HTTP 在键外完成,第二次 update 在 generation 未变时写回并清除 claim;败者以自己的取消轮询记录,claim 清除或 generation 变化后采用胜者记录。刷新失败时胜者重读记录:generation 已变则采用已存记录,未变则清 claim 并报错。过期 claim 按 Migration 的存活规则回收(进程 id 存活且启动时间不晚于 claim 创建)。新增两调用方并发、轮换 token 的流程测试,断言 refreshes == 1、两者读 rotated-1。FileStorage.md § Callers that hold work across an external wait;交付评论验收同步。

P2.2 文件大小:采纳。 ReadReply 加 size(文件长度),新增 stat 回 kind 与 size;offset == size 是空页、offset > size 是 invalid。#2095 发布与分页、#2093 的 stat、#2091 的 read 都能实现;session.ui.resources.read 的请求与 total 不变。

P2.3 16 MiB 帧:采纳。 整份读、update 当前/新内容与 source 单块都降到 8 MiB 原始字节(base64 与 JSON 装进 16 MiB 帧),import 缺省上限也是 8 MiB;超过 8 MiB 的 source 块是 invalid。验收加靠近 8 MiB 的跨桥用例。

P2.4 PluginFiles withLock:采纳。 契约写明跨进程保证就是「一次 update 排他」:withLock 是一次 update,change 解码记录、应用调用方步骤并写回;不能放进一次 change 的步骤由 PluginFiles 在自己内部串行、不跨进程安全,由 PluginFiles 契约声明哪些操作需要该保证。交付顺序:PluginFiles 契约与调用方在同一交付里改,无兼容期。

P2.5 sibling 契约:采纳保留操作。 root_path(#2091、#2094)、add_root(#2094 Settings 项目授权)、stat(#2093)、read 的 size(#2095)都在面内;Supersedes 写明这些契约按本契约成立。

P2.6 已删操作残留:采纳。 更新 resource-owner-operations(pluginFiles 的 read、authorize_project、file-backed Settings)、session-files(Locked 改为 cancelled/unsynced、附录的 create_directory 签名)、p6-p7-bindings(replace→write、长度改由 stat)、Modality.md(readAt/closeRead→read)、process-typescript.md(openRead/readAt/closeRead→read)。

P3: 六个 ../plugins/FileStorage.md 链接改为 plugins/FileStorage.md;§4 标题改为「File storage (fsHost) and the file tools」,工具族表标注不属于 fsHost;DimOAuth 示例用 .ok_or(...)?.data;import 缺省与 source 块上限写明;操作表的 reply 与 binding 一致(Stat、ReadReply、size、update 的 applied、path、entries、unit);Migration claim 增加启动时间检查;Rule check 补 §7.2 各行;文件工具面名字留给 #1297 确定;binding note 说明 cancelled 也是参数。

自查(§1)

  1. 每条关于现有代码/契约/调用方的陈述都按路径核对过(managed_oauth.rs、plugin_files.rs、resources.rs、session-files.md、p6-p7-bindings.md、Modality.md、process-typescript.md)。
  2. 与现有文档的冲突在本 PR 内解决,不是只列清单。
  3. Supersedes 的每一条都在本 PR 内改到:链接或删除旧文本。
  4. 评审点名的保留文档中描述本所有者的段落已改:resource-owner-operations、resource-faces、service-faces、session-files、p6-p7-bindings、Modality.md、process-typescript.md;runtime-owner-operations 与 session-boundary 没有 FileStorage 段落;ADR 未动。
  5. 操作名、类型名、错误码前后一致,并与调用方契约的最新 head 对齐(docs(storage): define the session storage owners' target contracts #2091 b4bb7f8a3、docs(design): target contracts for the Session scope and its host ports #2093 5e5dd00ba、design(settings): owner contracts for Settings and the settings sections #2094 be0b5171f、design(connection): target contracts for the connection, entry and UI owners #2095 c9d3ef930)。
  6. 职责分界、示例、操作表、错误表、流程、例外、Rule check、binding 相互一致;示例签名与 appendix 一致;流程的每个结尾都在错误表里;错误表写明可否重试、一次调用、重复调用、对端关闭与重载时的下一步。
  7. 全仓 grep 了被删/改名的引用(open_read、read_at、close_read、FileLease、FilePath、fsHost.readAt、scope.openRead、FileStorage 行);本 PR 内改到,其他 PR 的由各自的 owner 以本契约为准。未改代码,无代码注释锚点。

绑定附录编译

把 appendix 的完整类型与 #[rutis::service(name = "fsHost")] 块放进临时 crate(rutis 0.23、rutis-bridge 0.23、serde、thiserror、base64),cargo check 通过;临时 crate 未提交。

客户端可见变更

无。fsHost 是插件面;客户端协议、通知、session.ui.resources.read 的请求与 total、Session 文件分页、import 回复 path、模型可见文本与断连/进度行为不变。

@yyhhyyyyyy 请再看一次。

@eric8810
eric8810 requested a review from yyhhyyyyyy November 24, 2026 03:25
@eric8810
eric8810 force-pushed the dim/2016-filestorage-contract branch from 55d4192 to 7224c0c Compare November 24, 2026 03:26
eric8810 added a commit that referenced this pull request Nov 24, 2026
Depend on FileStorage operations that exist in #2080: the host registers roots
and hands their paths as values, so Settings and ModelLog take the home
directory from the assembly and Settings reads and updates documents by
absolute path. The refusal is a Rejected variant whose wire code is rejected
and whose callback code is reason; the appendix compiles in a temporary crate.
Scope the source-id row binding to read and change, rename the declaration hint
to writeOnlyHint, split the sync operations from the cancelled ones, and correct
the examples and retained documents the review named.

@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] Keep published UI resource pages bound to the same file version. Adding size fixes the earlier reply-shape finding, but FileStorage’s new contract says UiResources already uses path-based pages and explicitly makes the next page see a replacement. The current #2095 contract instead pins a reader and its size at publication, and keeps it until withdrawal or row close. If the file is replaced between two reads, a client can receive pages from different versions under one published ID and total, despite the claim of no client-visible change. Keep the pinned-reader behavior or agree on an equivalent immutable snapshot/version contract with UiResources before retiring the read operations. Include a replace-between-pages acceptance case. This is static contract review; the hosted docs gate passed, and it did not execute a runtime resource flow.

eric8810 added a commit that referenced this pull request Nov 24, 2026
Settings uses add_root for a project authorization, read and update for a
document; ModelLog uses root_path for the home root. The home directory arrives
as an assembly value, which is a choice: root_path and stat exist and are not
needed here.

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

FileStorage target contract: review at 7224c0c

Scope. This PR gives FileStorage its owner contract under design rules §7 (#2029), refs #2016 and #2015. It keeps the fsHost wire name and puts ten operations on the FileStorage type: add_root, root_path, stat, read, write, import, update, create_directory, list and remove. It supersedes the FileStorage text in resource-faces, resource-owner-operations, service-faces, session-files, p6-p7-bindings, Modality and process-typescript. Full diff main...head: 9 files, +592/-143. Head 7224c0c adds 7 files, +153/-85 over 1f1e048 and answers the round-two review.

Verdict: REQUEST_CHANGES. The size, limit and link fixes are good, and most round-two inline findings are closed. One P1 remains: the Managed OAuth refresh runs outside the published auth.json.lock marker, so this contract's own marker exception and the account owners' serialized refresh contract (#2096) cannot both hold. Five P2s remain: the claim comparison, the #2091 read semantics, the two inventory rows that were not updated for the ten-operation face, the pinned-reader sentence, and the UiResources version binding.

Round-2 status

Round-2 finding Status at 7224c0c Evidence
Managed OAuth compare-and-reject under rotation Partially fixed. The claim serializes Rust update writers, but the refresh is outside the published marker and the commit compares the stable account generation. FileStorage.md:143, :206; crates/dim-app-server/src/managed_oauth.rs:182-186, :203-210, :415-420, :1042-1092; #2096
PluginFiles serialization Partially fixed. One exclusive update is now the cross-process guarantee and the delivery order is stated. The written PluginFiles contract and the caller's own result remain outside this PR. FileStorage.md:147
read lacks size for UiResources Fixed. ReadReply.size and stat exist, offset > size is invalid, and #2095 uses them. FileStorage.md:162, :170, :315-336; #2095 at 82c6f8e
16 MiB document exceeds the bridge frame after base64 Fixed. Whole read, each chunk and the import default are 8 MiB raw. FileStorage.md:170, :233, :293-298
Sibling owner contracts depend on removed operations Mostly fixed. The face has add_root, root_path and stat, and #2091, #2093, #2094 and #2095 call them. #2091 read-past-end and #2096 account owners remain. FileStorage.md:226; #2091 at 0aec7ae SessionFiles.md:100; #2096 at 13f9b94
Removed operations remain in edited documents Mostly fixed. resource-owner-operations.md:15, :22, :142, session-files.md:250, :281, :624, :766, p6-p7-bindings.md:23, :174, Modality and process-typescript are updated. resource-owner-operations.md:11 and :26 remain. Below
Broken resource-faces links Fixed. All six resolve. resource-faces.md:19, :24, :347, :366, :561, :806
fsHost heading and tool family Fixed. §4 is retitled and the tool family is separated. resource-faces.md:344-371
DimOAuth example type error Fixed. .data is taken after ok_or. FileStorage.md:99-101
Undefined import limit and chunk bound Fixed. 8 MiB default, 8 MiB raw chunk. FileStorage.md:172-174, :297-298
Reply shapes table vs appendix Fixed. FileStorage.md:163-168, :436-508
Root ids across a reload Fixed. Append-only root table and a reload acceptance. FileStorage.md:192, :240
session-files Locked handling Fixed. session-files.md:250, :281, :624, :766

P1

1. The Managed OAuth refresh is outside the published account marker, and the claim is not the marker

Problem. FileStorage.md:143 runs the HTTP refresh "outside the key". The key for auth.json is the published auth.json.lock marker: crates/dim-agent-capabilities/src/file_storage.rs:13-15 says auth.json uses the TypeScript-compatible marker protocol, and :1096-1107 maps the lock to that marker. The current code holds the marker across the refresh (crates/dim-app-server/src/managed_oauth.rs:415-420, :997-1015, :1042-1092). This contract's exception at FileStorage.md:206 still says "both sides must lock the same file under the same marker protocol". #2096 at 13f9b94 says the same: docs/design/plugins/DimOAuth.md:13, :75, :85, :93, and docs/design/plugins/ManagedAccount.md:11 ("the account's own revision and lease"). The claim is written with update, which takes the marker only for the claim write and the commit, not during the refresh.

Failure scenario. Another process that honors the marker refreshes while the claim winner's HTTP request is in flight. Both requests use the same refresh token and the provider rotates on each. If the other request is the later one at the provider but the Rust commit is the later write, the file keeps the older token. The next refresh fails invalid_grant and the account is signed out. The claim coordinates only update writers and is not part of the published marker protocol.

Evidence. FileStorage.md:143, :206; crates/dim-agent-capabilities/src/file_storage.rs:13-15, :1096-1107; crates/dim-app-server/src/managed_oauth.rs:415-420, :997-1015, :1042-1092; docs/design/appserver/session-files.md:463 also records that write on auth.json uses the account-marker protocol; #2096 DimOAuth.md:13, :75, :85, :93, ManagedAccount.md:11.

Fix. Keep a narrow account-marker operation for auth.json across the refresh (an id-based exclusion is enough; the general lease object need not return), or make the claim part of the published marker and have every writer honor it, and update #2096. If the other side no longer refreshes, delete the exception and the marker reference instead.

P2

2. The claim commit compares the account generation, not a write revision, and does not fence a reclaimed claim

Problem. FileStorage.md:143 says the claim carries "the generation it read" and the second update replaces the record "only while the generation is still the one it read". In the record, generation is the account identity and credentialRevision is the per-write counter (crates/dim-app-server/src/managed_oauth.rs:182-186, :203-210). The flow test asserts that the generation is unchanged after a refresh while credentialRevision becomes 2 (crates/dim-app-server/tests/managed_oauth_flow.rs:388-396). The second update also clears the claim without checking that the claim is still the caller's; the claim has no unique nonce. The paragraph says a claim older than the refresh timeout is stale, while the migration rule it cites (:145) keeps a claim whose process is alive and whose start time is not later than the claim's creation; the two rules disagree about a slow but alive winner.

Failure scenario 1. The winner's refresh is slow and its claim is reclaimed as stale. Both callers refresh. The first winner's second update still sees the same generation, clears the new claimant's claim, and writes its rotated record. The provider has rotated twice and one refresh token is lost.

Failure scenario 2. The winner's refresh fails transiently. It clears the claim and reports the failure. A waiting loser sees the claim clear and "adopts the winner's record", which still has the old, expired token, so the caller receives no fresh credential.

Evidence. FileStorage.md:143; crates/dim-app-server/src/managed_oauth.rs:182-186, :203-210, :560-571; crates/dim-app-server/tests/managed_oauth_flow.rs:388-396; #2096 ManagedAccount.md:11, DimOAuth.md:13 use "revision" and "account lock", not a stable generation.

Fix. Compare credentialRevision (or a new per-write revision), put a unique claim nonce in the claim, and require the commit to match it. Make a waiting loser re-check freshness after the claim clears and claim again when the record did not advance. Add tests for a write between claim and commit and for a failed refresh with a waiting loser.

3. read past the end contradicts #2091 SessionFiles

Problem. FileStorage.md:170 makes offset > size return invalid, and :232 repeats it. #2091 at 0aec7ae says "an offset at or past the end is an empty page" (docs/design/plugins/SessionFiles.md:100). FileStorage.md:226 says the sibling contracts stay as written.

Failure scenario. sessionFiles.read forwards a page at offset > size. The FileStorage contract returns invalid; the SessionFiles contract promises an empty page. A client that pages past the end now gets an error, or SessionFiles special-cases the result, which loses the distinction the client paging contract relies on. FileStorage.md:213 says Session file offset paging is unchanged, which is not true if this path is reachable.

Evidence. FileStorage.md:170, :213, :226, :232; #2091 at 0aec7ae SessionFiles.md:100; docs/design/appserver/session-files.md:401 (eof exactly when empty).

Fix. Update #2091 to "offset equal to size is an empty page; above is invalid", or state how SessionFiles maps invalid and narrow the "stay as written" claim. #2091 cites this PR at head 7224c0c, so the two can be fixed together.

4. The operation inventories were not updated when add_root, root_path and stat returned

Problem. The delta re-adds the three operations, and FileStorage.md:157-168 and resource-faces.md:19, :366 list all ten. docs/design/service-faces.md:127 still lists seven, and docs/design/contracts/resource-owner-operations.md:11 still lists seven. FileStorage.md:218-219 says this PR supersedes both rows.

Failure scenario. The migration inventory and the owner-operations registry do not show add_root, root_path or stat, while #2091, #2093 and #2094 require them in the same delivery. An implementer or the catalog migration follows the inventory and misses three operations the sibling contracts call.

Evidence. docs/design/service-faces.md:127; docs/design/contracts/resource-owner-operations.md:11; FileStorage.md:157-168, :218-219; resource-faces.md:19, :366.

Fix. Add addRoot, rootPath and stat to service-faces.md:127 and resource-owner-operations.md:11, or narrow the Supersedes claims at FileStorage.md:218-219 to the rows actually replaced.

5. resource-owner-operations.md still promises a pinned reader after the row removed it

Problem. The row at :22 now says openRead uses FileStorage's offset read and "no reader id crosses", but the paragraph at :26 still says "the pinned reader ... an existing reader ID". The face has no reader id or pin (FileStorage.md:15, :162, :234).

Failure scenario. An implementer following the paragraph keeps a pinned reader identity for FileScope.openRead, which the new face cannot provide, or a reader cannot tell which binding is the target.

Evidence. docs/design/contracts/resource-owner-operations.md:22, :26; FileStorage.md:15, :162, :234.

Fix. Change :26 to "the path value, offset reads and a callback" and remove the pinned reader clause.

6. Client-visible changes claim nothing, but UiResources pages are now path-based

The version-bound pages are the issue. #2095 at 82c6f8e records the size at publish and reads each page by path (docs/design/plugins/UiResources.md:59-61, :80); a publisher that rewrites the path between pages changes the bytes and the total under one published reference. The client contract says the resource is immutable and total is fixed (docs/design/client-ui-extensions.md:188, :208). FileStorage.md:213 says client-visible changes are None, and :234 accepts that a page after a replace sees the replaced content. The series must either keep a version pin or state the rewrite prohibition and add a replace-between-pages acceptance; the None sentence cannot stand as written.

P3, optional

  • session-files.md:462 still says "A put is one message, and write holds the content in memory". write streams chunks of at most 8 MiB (FileStorage.md:172), so the reason for the 16 MiB cap is stale even if the cap stays.
  • FileStorage.md:11, :153, :209 say add_root is for a trusted process part, but the face is a public data face and no call-site check is named. If a Session-scoped plugin can inject fsHost, it can call add_root. I withdraw the earlier P2 on the trust model in its original form, but the enforcement is worth one sentence or a follow-up.
  • FileStorage.md:143, :145 say a claim "refuses with held". The error table has no held code, only the rejected reason; say "refuses with reason held" to avoid a new error kind.
  • FileStorage.md:170 does not define length: 0. A zero-length page at offset < size has eof false and does not advance; make zero invalid if callers can send it.

Conflicts with other open PRs

  • #2096 at 13f9b94 keeps the old shapes. docs/design/plugins/ManagedAccount.md:11 says "revision and lease", DimOAuth.md:13, :75, :85 require the refresh under the account lock, Modality.md:43 still says fsHost.readAt/closeRead, and its resource-owner-operations.md:11, :15, :22 and service-faces.md:127 still list the old operations. #2080 changes the same lines. If #2096 lands after #2080 without a rebase, it conflicts with, or reverts, Modality's read line, and the account owners have no lock operation. The series needs an explicit rebase order, and #2096 must take the claim or marker decision from P1.
  • #2091 at 0aec7ae line 100 conflicts with FileStorage.md:170 on read past the end (P2 item 3).
  • #2095 at 82c6f8e matches this face's read and stat; the version question is item 6.
  • #2093 and #2094 at their heads use stat and add_root/read/update and match this face. #2094's rule check cites ADR 027 as not applicable, which is correct for a process owner.

Round-2 items fixed, opinions withdrawn

  • The six broken links now resolve (resource-faces.md:19, :24, :347, :366, :561, :806). My link and anchor check over the nine changed files found no new missing file or anchor.
  • The §4 heading is retitled and the tool family is separated (resource-faces.md:344-371).
  • ReadReply.size and stat close the size gap (FileStorage.md:162, :315-336); #2095 uses them. Withdraw the "read lacks size" P2.
  • The 8 MiB whole-read, chunk and import limits fit the 16 MiB frame after base64 (FileStorage.md:170, :293-298). Withdraw the 16 MiB frame P2.
  • The DimOAuth example uses .data (FileStorage.md:99-101). Withdraw.
  • The reply table and appendix shapes are aligned (FileStorage.md:163-168, :436-508). Withdraw.
  • The import default and chunk bound are stated (FileStorage.md:174, :297-298). Withdraw.
  • The session-files Locked handling and FilePath signature are replaced (session-files.md:250, :281, :624, :766). Withdraw.
  • Root ids across a reload: the root table stays append-only across a generation and the acceptance covers a provider reload (FileStorage.md:192, :240). Withdraw the root-id P2.
  • add_root authority: withdraw the earlier P2 in its original form. The contract now says roots are addressability, not authority (FileStorage.md:11, :209), and limits registration to a trusted process part. The remaining question is enforcement, noted as P3.
  • #861, README, FileError serde, cancelled scope, and the sibling root operations were fixed earlier; no new issue.

Verification

  • Head 7224c0cd41fbc2171903f7517615da0ce9dc7bda, merge base 6e86d48c8361e95575cf8e4425e77f4ec048fc41, PR open, not draft, MERGEABLE, BLOCKED by a CHANGES_REQUESTED review. Full diff 9 files, +592/-143; the delta over 1f1e048 is 7 files, +153/-85.
  • node scripts/adr-check.mjs --base 6e86d48c: passed, 9 changed files.
  • Relative links and heading anchors over the nine changed files: no new broken links. One pre-existing anchor at resource-faces.md:743 (worktree-management.md#5-列出删除与清理) is outside the changed lines.
  • CI: ci-ok passed; the other checks are skipped for a docs-only change.
  • The rutis 0.23 16 MiB frame basis was checked in round 2 and not re-run. The Managed OAuth flow test at crates/dim-app-server/tests/managed_oauth_flow.rs:383-396 confirms one refresh, the same generation and credentialRevision 2.
  • No build or runtime flow was run; this is a static contract review.

Unverified and hypotheses

  • Whether a Session-scoped plugin can inject fsHost and call add_root. The contract says "trusted process part" but names no check. Hypothesis for the P3 note.
  • Whether the account file's other writer preserves a new claim field and bumps the revision. The docs say the file is shared but do not define the claim's cross-language behavior. This is part of P1 and P2 item 2.
  • Whether #2096 and #2091 will be rebased before merge; the conflicts above depend on the order.

Comment thread docs/design/plugins/FileStorage.md Outdated
## Exceptions with reasons

- `import` reads a host path outside the roots: the caller names a file the user or model chose (an attachment); the owner checks that the source is a regular file, does not follow a link and enforces the byte limit, while the root constrains only the destination.
- The account marker `auth.json.lock` stays in its published TypeScript-compatible form: the account file is shared with the TypeScript subscriber, and both sides must lock the same file under the same marker protocol.

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.

P1: the exception and the Managed OAuth flow cannot both hold. This says both sides must lock auth.json.lock under the same marker protocol, but the new flow at :143 runs the HTTP refresh outside the FileStorage key and never holds the marker. The current code holds the account lease across the refresh (crates/dim-app-server/src/managed_oauth.rs:415-420, :997-1015, :1042-1092), and FileStorage maps auth.json to that marker (crates/dim-agent-capabilities/src/file_storage.rs:13-15, :1096-1107). #2096 at 13f9b94 still requires one serialized refresh under the account lock (docs/design/plugins/DimOAuth.md:13, :75, :85, :93; ManagedAccount.md:11).

Failure scenario. Another process that honors the marker refreshes while the claim winner's HTTP request is in flight. Both use the same refresh token and the provider rotates on each. If the other request is later at the provider but the Rust commit is the later write, the file keeps the older token; the next refresh fails invalid_grant and the account is signed out. The claim coordinates only update writers.

Fix. Keep a narrow account-marker operation for auth.json across the refresh (an id-based exclusion is enough; the general lease object need not return), or make the claim part of the published marker and have every writer honor it, and update #2096. If the other side no longer refreshes, delete the exception instead.

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 72ea12c. The refresh runs under the published marker: claim/release and update(claim_id) create and verify auth.json.lock (FileStorage.md:14, :146, :166-167, :179, :201-202), and the four flow tests are at :250. #2096 at 9ca30e0 aligns (docs/design/plugins/DimOAuth.md:105, :134), and crates/dim-agent-capabilities/src/file_storage.rs:1638-1643, :1664-1700 confirm the marker's pid, creation time, nonce and reclaim. Remaining nits are in the new review: the marker field is the creation time, not the process start time, and the failed-release reclaim is not restated.

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 72ea12c, with one residual P2. The refresh runs under the marker, but the page now disagrees on whether the marker is the auth.json key: FileStorage.md:153 says "outside the file key" and :214 says "the marker is the auth.json key". See the new review.

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

The public face has no lease. Three callers need exclusion across work that cannot run under the file key; each composes it from `update`, and the owner keeps the guarantee that one `update` is exclusive across processes.

**Managed OAuth, with a rotating refresh token.** One caller refreshes at a time. The account record carries a generation and a claim field. A caller that needs a refresh first claims it with one `update` whose change writes the claim only when the record has none and otherwise refuses with `held`; the claim carries the refresher's process id, its start time and the generation it read. The winner performs the HTTP refresh outside the key, then writes the rotated record with a second `update` whose change replaces the record only while the generation is still the one it read and clears the claim. A loser waits by re-reading the record with its own cancellation until the claim clears or the generation changes, then adopts the winner's record. If the refresh fails, the winner re-reads the record: a changed generation means another refresher won, so it adopts that record; an unchanged generation means it clears its claim and reports the failure. A claim older than the caller's refresh timeout is stale and is reclaimed by the same liveness check as the migration claim. Two concurrent callers with a rotating token perform one refresh; the flow test asserts `refreshes == 1` and both callers read `rotated-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.

P2: the commit compares the wrong field and does not fence a reclaimed claim. The second update replaces the record "only while the generation is still the one it read", but generation is the account identity and credentialRevision is the per-write counter (crates/dim-app-server/src/managed_oauth.rs:182-186, :203-210). The flow test asserts the generation is unchanged after a refresh while credentialRevision becomes 2 (crates/dim-app-server/tests/managed_oauth_flow.rs:388-396). The second update also clears the claim without checking that the claim is still the caller's; there is no claim nonce.

Failure scenarios. (1) A slow winner's claim is reclaimed as stale; both callers refresh; the first winner's second update still sees the same generation, clears the new claimant's claim and writes its rotated record. The provider has rotated twice and one token is lost. (2) The winner's refresh fails transiently; a waiting loser sees the claim clear and "adopts the winner's record", which still holds the old, expired token, so the caller receives no fresh credential.

Fix. Compare credentialRevision (or a new per-write revision), add a unique claim nonce and require the commit to match it, and make a waiting loser re-check freshness and claim again when the record did not advance. Add tests for a write between claim and commit and for a failed refresh with a waiting loser.

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 72ea12c. The commit compares credentialRevision (FileStorage.md:146), the claim carries a nonce, and a reclaimed claim answers rejected with claim-lost (:179, :190); a waiter re-reads and claims when the revision did not advance (:146, :250). The code's per-write counter is credential_revision (crates/dim-app-server/src/managed_oauth.rs:182-186, :536-546), and the flow test's generation-unchanged and revision-2 assertion is crates/dim-app-server/tests/managed_oauth_flow.rs:388-396.

Comment thread docs/design/plugins/FileStorage.md Outdated
| `list` | One level of a directory | `{path}` | `entries` or none when the directory is absent | Before the reply | `invalid`, `closed`, `cancelled` |
| `remove` | Make a file or a directory tree absent; an absent entry counts as removed | `{path}` or `{parent, name}` | unit | Before the entry is unlinked; a tree can be partly removed, a retry is safe | `invalid`, `unsynced`, `closed`, `cancelled` |

`read` without `offset` and `length` reads the whole document up to 8 MiB and answers `too_large` above it; with both, it reads one page of at most 64 KiB (`length` above the page is clamped), `size` is the file's length and `eof` is true when the page reaches the end; one of the two alone is `invalid`. An offset equal to `size` reads an empty page with `eof`; an offset above `size` is `invalid` (the client paging contract depends on the distinction). An absent file answers none. `Bytes` crosses as base64 text, so 8 MiB of bytes fits the 16 MiB bridge frame with the JSON 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.

P2: this contradicts #2091 SessionFiles. #2091 at 0aec7ae says "an offset at or past the end is an empty page" (docs/design/plugins/SessionFiles.md:100), and FileStorage.md:226 says the sibling contracts stay as written.

Failure scenario. sessionFiles.read forwards a page at offset > size; this contract returns invalid while SessionFiles promises an empty page. A client that pages past the end now gets an error, or SessionFiles special-cases it, losing the distinction the client paging contract relies on. :213 says Session file offset paging is unchanged, which is not true if this path is reachable.

Fix. Update #2091 to "offset equal to size is an empty page; above is invalid", or state how SessionFiles maps invalid and narrow the "stay as written" claim. #2091 cites this PR at head 7224c0c, so both can change together.

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 72ea12c. FileStorage.md:175 and :235 state one rule: at size an empty page with eof, above size invalid. #2091 at f7425d5 clamps an offset above size to size before calling read (docs/design/plugins/SessionFiles.md:79), so its own callers keep the empty page its client contract states. The two documents agree.

Comment thread docs/design/service-faces.md Outdated
| --- | --- | --- |
| `hostPlatform` | `ProcessTree`、`PtyProcessTree`、临时目录 | 数据面 `execHost`:`start`/`wait`/`kill`/`settle`/`output`/`tail`/`removeOutputDirectory`/`shell`/`write`/`resize`/`info`/`confined`/`configured`([resource and store data faces](resource-faces.md) §3,#1295);`hostPlatform` 是提供方和它的 Rust binding |
| `fileStorage` | `FilePath`、根与代次 | 数据面 `fsHost`:工具部分 `resolve`/`read`/`write`/`edit`/`glob`/`grep`/`mentions`,存储部分 `stat`/`readBytes`/`openRead`/`readAt`/`closeRead`/`lock`/`unlock`/`backup`/`createDirectory`/`replace`/`list`/`remove`(§4,#1297);`fileStorage` 是提供方和 binding |
| `fileStorage` | `FilePath`、根与代次 | 数据面 `fsHost`:`read`、`write`、`import`、`update`、`createDirectory`、`list`、`remove`;契约见 [FileStorage](plugins/FileStorage.md)(#2016)。工具族 `resolve`/`read`/`write`/`edit`/`glob`/`grep`/`mentions` 不属于 `fsHost`,归文件工具所有者(#1297)。 |

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: this target list is three operations short. The row lists seven operations, while FileStorage.md:159-161 and resource-faces.md:19, :366 list addRoot, rootPath and stat as well. docs/design/contracts/resource-owner-operations.md:11 also still lists only the seven. FileStorage.md:218-219 says this PR supersedes both rows.

Failure scenario. The migration inventory and the owner-operations registry do not show add_root, root_path or stat, while #2091, #2093 and #2094 require them in the same delivery; an implementer follows the inventory and misses three operations.

Fix. Add addRoot, rootPath and stat here and to resource-owner-operations.md:11, or narrow the Supersedes claims.

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 72ea12c. service-faces.md:127 and resource-owner-operations.md:11 now list all twelve operations, including claim and release. Still open: resource-faces.md:19 and :366 list ten, and the §6 account caller row at :823 lists read, update, write without claim/release, while FileStorage.md:226 says this PR supersedes those rows. See the new P2.

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 5351ea7. docs/design/resource-faces.md:19, :366 and the account row at :824 now list all twelve operations, so the remaining item in this thread is closed.

| --- | --- |
| FileScope.directory(name) → FileResult of node-absolute path | The file scope validates the scoped name, creates parents and returns the directory. Modality passes the node-local input filenames and work directory directly to its native adapter. OCR uses its current work/tmp/cache paths and grants. Existing exports use the recorded result filename. |
| FileScope.openRead(name) → FileResult of {readId,size} or null | The file scope opens a pinned file by relative name and returns None if missing. Bind that reader to the existing fsHost reader identity for the caller on the same node. Use fsHost.readAt/closeRead and the existing caller-unload cleanup. A scoped name never requires a caller-side root lookup. |
| FileScope.openRead(name) → FileResult of {size} or null | The file scope reads the file through FileStorage's offset read (`read` with `offset` and `length`); no reader id crosses. A scoped name never requires a caller-side root lookup. |

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: the next paragraph still promises a pinned reader. This row now says openRead uses FileStorage's offset read and "no reader id crosses", but :26 still says "the pinned reader ... an existing reader ID". The face has no reader id or pin (FileStorage.md:15, :162, :234).

Failure scenario. An implementer following :26 keeps a pinned reader identity for FileScope.openRead, which the new face cannot provide, or a reader cannot tell which binding is the target.

Fix. Change :26 to "the path value, offset reads and a callback" and remove the pinned reader clause.

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 72ea12c. resource-owner-operations.md:22 and :26-27 drop the pinned reader and the existing reader ID; FileScope.openRead reads through FileStorage's offset read and crosses no reader id.

@eric8810

Copy link
Copy Markdown
Collaborator Author

已按评审修改,head 08d29c84c(base 6e86d48c)。

评审逐条

P1 OAuth 刷新与 auth.json.lock:采纳。 契约新增 claim({path}) -> {claim_id} 与 release({claim_id}):claim 在账户文件旁按发布的 marker 协议独占创建 auth.json.lock,内容是本进程 id、启动时间与 nonce;marker 由本行持有(caller: &Ctx),行卸载释放;30 秒且创建时的进程不在才可回收。update(path, change, claim_id?) 先校验 marker 的 nonce,被回收的 claim 返回 rejected{reason:"claim-lost"};change 自己比较 credentialRevision,不符返回 conflict。Managed OAuth 流程改为 claim → 读记录判新鲜度 → HTTP 在键外但在 marker 内 → 带 claim 的 update 写回 → release;刷新失败时释放,重读记录,credentialRevision 前进则采用,否则报错;等待者 claim 后重判,未前进则自己刷新。验收含四个流程测试:两调用方轮换 token refreshes == 1、claim 与提交间有写入、刷新失败由等待者接手、遵循 marker 的外部写者被阻塞。没有 lock/unlock 对象,也没有 lease 表。

TypeScript 是否还写 auth.json:不再写。 证据:crates/dim-oauth/docs/runtime-contract.md:32 明确写「The TypeScript plugin (0.2.0) wrote this file」(过去式);当前唯一写入者是 crates/dim-oauth/src/store.rs(AUTH_FILE = "auth.json");npm/、runtime/、web/、scripts/ 下没有任何 auth.json 引用。因此删掉「与 TypeScript 订阅者共享」的例外文字;marker 仍保留,因为同一 home 上还有多个 Rust 进程(App Server、dimcode CLI 等)写这个文件,dim-oauth 的 runtime contract 也要求写入经 FileStorage 串行化。

P2 service-faces 与 resource-owner-operations 少三个操作:采纳。 两行都补 addRoot、rootPath、stat(这次再补 claim、release),与契约的十二个操作一致。

P2 resource-owner-operations.md:26 仍写 pinned reader:采纳。 改为「OS path 用路径值、input reader 用回调;文件读走偏移读,不跨读 id」。

P2 #2091 的 offset 规则:留给第二步。 #2091 现在写「offset 等于或大于末尾都是空页」,本契约是「等于空页、大于 invalid」。这是跨 PR 的契约段落,按 step 1 的「跨 PR 项留给第二步」处理;本 PR 在 Supersedes 里注明 #2091 的 page-past-end 规则在第二步对齐,不再声明「sibling contracts stay as written」。

自查(1–9)发现

  1. 现有代码/契约陈述按路径核对过:managed_oauth.rs:182-186、:997-1015、:1042-1092,file_storage.rs:1096-1107、:1620-1680(marker 内容与 30 秒回收),resources.rs:115-120,session-files.md、p6-p7-bindings.md、Modality.md、process-typescript.md。
  2. 与现有文档的冲突在本 PR 内改到:service-faces、resource-owner-operations(含 :26)、resource-faces、session-files、p6-p7-bindings、Modality.md、process-typescript.md;唯一例外是 docs(storage): define the session storage owners' target contracts #2091 的 page 规则,留给第二步。
  3. 一个概念一个词:claim/release/claim_id/claim-lost 在操作表、错误表、流程、验收与交付评论一致;错误码仍是七个 snake_case。
  4. 表、流程、例外、Rule check、appendix、示例一致:update 的 claim_id 在操作表、流程、appendix、交付评论一致;claim/release 的 caller: &Ctx 在 appendix 与流程一致;示例签名与 appendix 一致。
  5. 每个结尾都写了下一步:claim/release 的行卸载与所有者关闭、update 的 claim-lost/conflict、write 的 source 失败/撤销、read/stat 的 closed,错误表覆盖一次调用、重复调用、对端关闭与重载。
  6. 全仓 grep:open_read、read_at、close_read、FileLease、FilePath、fsHost.readAt、scope.openRead、auth.json.lock、TypeScript-compatible;本 PR 内改到,未改代码。
  7. 规则不带 Rust 拼写;未合并的 fsHost: remote file and search operations #1297、docs(principles): add owners and operations #2029 用 PR/issue URL;不把扫描 issue 当机制 issue。
  8. 新写句子按 1–5 重核:claim 的 marker 内容、update 的 nonce 校验、等待者的重判路径、TS 结论都按代码与文档核对。
  9. 使用了 docs(storage): define the session storage owners' target contracts #2091、docs(design): target contracts for the Session scope and its host ports #2093、design(settings): owner contracts for Settings and the settings sections #2094、design(connection): target contracts for the connection, entry and UI owners #2095 的最新 head(b4bb7f8a3、5e5dd00ba、be0b5171f、c9d3ef930)与 docs(principles): add owners and operations #2029 的 §7(a3c7c4d8a)。

绑定附录编译:临时 crate(rutis 0.23、rutis-bridge 0.23、serde、thiserror、base64)加了 ClaimReply、claim/release 与 update 的 claim_id,cargo check 通过;未提交。

留给第二步

客户端可见变更

无。fsHost 是插件面;客户端协议、通知、session.ui.resources.read、Session 文件分页、import 回复 path、模型可见文本与断连/进度行为不变。

@yyhhyyyyyy 请再看一次。

Add read(path, cancelled) for a whole document within the owner's limit,
keep the pin operations for large files, remove the fixed key wait and the
busy kind, and state why Rejected carries only code and message.
Replace the pinned readers with a stateless offset read, drop the read id and
the root operations, make errors serde data with snake_case codes and callback
codes preserved, scope cancellation outcomes, state the three callers that hold
work across an external wait, and supersede the FileStorage paragraphs in the
named designs.
Return the size in read, add stat, keep root_path and add_root for the sibling
contracts, lower the whole-read limit to the wire-safe 8 MiB, make managed OAuth
a single-refresher claim, state PluginFiles' serialization and delivery order,
and replace the removed operations in the retained documents.
Add claim and release for the published auth.json.lock marker, make update take
a claim id and compare the marker nonce, rewrite the managed OAuth flow around a
single refresher, and list the missing operations in the two inventories.
Add claim and release to the resource-faces inventories, fix the caller summary
and the update examples, state the marker creation time and the failed-release
reclaim, link the merged §7, record UiResources' path paging in the client
section, and fix the retained-document nits.
Put the target contract first on the architecture plugin page, keep the current
implementation under its own section, delete the design-tree copy, repoint the
inbound links and the two READMEs.
Make the auth.json.lock marker the one lock for auth.json, run a claimed update
under that hold, settle admitted claim-carrying updates before releasing the
claim, add io to FileError and the error table, and turn the superseded
existing-document paragraphs into pointers.
Serialize marker reclamation with the private auth.json key, define remove and
list around the owner's resources, keep the import source length, record the
pluginFiles FileScope read, and update the three target documents that still
named leases and reader ids.
Release the private auth.json key before waiting and make release remove the
marker by owner record, align unload settlement with cancellation, and update
the client and pluginFiles documents that still described leases and reader
ids.
Write the PluginFiles contract with withLock as one update, move the README,
process-typescript and authoring-guide sections to pointers, update the SDK
types, and make the FileStorage claim per operation.
@eric8810
eric8810 force-pushed the dim/2016-filestorage-contract branch from 4f8bd65 to ed23162 Compare November 24, 2026 11:31
@eric8810

Copy link
Copy Markdown
Collaborator Author

已按评审修改,head ed2316298(base 5930539bc,已 rebase 到最新 main,无冲突)。

预审 P1 处理

本 PR 不再改 npm/plugin.d.ts:该文件已回到 origin/main 的内容,PR diff 中不出现。SDK 变更(FileLease 删除、withLock 新签名、FileError 去掉 locked/exists、加 unsynced)写入交付评论的实现任务,与 provider、Workflow store、fixtures 和 plugin_sdk 在同一交付实现。契约的 Client-visible changes 保留 SDK 变更描述。

评审台账

第 1–6 轮:全部已关闭(跨操作持锁、错误 serde、cancelled、fsHost 重名、根 id、#861、README、轮换 token、PluginFiles 串行化、size、帧上限、sibling 操作、示例、reply 形状、import 上限、链接/标题/清单、marker 内刷新、credentialRevision+nonce、#2091 offset、pinned reader、resource-faces 行、段落总结、失败释放、creation time、§7 链接、Ctx、小写句首、两套锁模型、io、unsynced、#2095 验收、write 非绑定方法、claim 结算、两轮预审的 P1-1/P2)。

第 7 轮 zerob13(6037238155)

  • P2 1 claim 每次独占 → F:同一行第二次 claim 等待并可取消;持 claim 的写 auth.json 传 claim_id,否则等待;结算不变;同两行刷新 refreshes == 1 进验收。
  • P2 2 PluginFiles 交易边界 → F:新 PluginFiles.md,withLock 一次 update、change 只计算、外部 I/O 在 change 外;backup/多次 replace 删除;调用方迁移与 SDK 变更列入交付。

第 7 轮 yyhhyyyyyy(6037417725)

  • P2 1 remove/import 不取 marker → F:write/update/import/remove 打 auth.json 都取 marker,持 claim 者传 claim_id;操作表、Flows、排除段同步;并发 remove/import 等待进验收。
  • P2 2 create_directory 递归/非递归 → F:契约与 session-files.md 验收统一为整棵树、缺父目录不是错误;missing_parent 的下一步只指向会返回它的操作。
  • P2 3 README 表仍写 Locked → F:trusted-plugin 整节改为 PluginFiles 契约指针。
  • P3 1 design(connection): target contracts for the connection, entry and UI owners #2095 验收 → 已记为上层对齐项,落地前 UiResources 版本保证不变。
  • P3 2 unsynced 按操作 → F。
  • P3 3 marker 的 external TypeScript 措辞 → F。
  • P3 4 session-files.md:619 缺 io → F。

预审一/二:P1-1 marker 回收死锁与全部 P2 已在前几轮关闭,本轮继续保留修复。

改成指针的段落

  • crates/dim-app-server/README.md "Trusted plugin storage" 整节。
  • docs/design/process-typescript.md §5.2。
  • docs/typescript-plugin-authoring.md 的 withLock/lease/readBytes/list/remove/read 段(示例改为新回调形状)。
  • docs/design/contracts/resource-owner-operations.md 的 pluginFiles 行。
  • FileStorage.md 的 PluginFiles 段指向新契约;Supersedes 逐条对应。

检查

  • adr-check:通过(19 文件);xtask-check:全部通过;git diff --check origin/main...HEAD:干净。
  • 链接/锚点:0 断链。
  • 五份 appendix(FileStorage、PluginFiles、SessionStore、BranchLine、SessionScope)同 crate cargo check 通过。

剩余 P2(交维护者)

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

FileStorage and PluginFiles target contracts: review at ed23162

Scope. This PR gives FileStorage its owner contract, retires the lease, adds the PluginFiles owner contract, moves the FileStorage page to the architecture plugins directory, and updates the callers and sibling contracts. Head ed231629 is based on current main 5930539bc; the previous review used eacc672d. The PR is open, not draft, and MERGEABLE. Full diff origin/main...HEAD: 19 files, +1005/-458. This is round 7.

Verdict: REQUEST_CHANGES. The round-6 P2s are fixed: remove and import of auth.json take the marker for a non-holder, create_directory is recursive in both the owner contract and the Session-files acceptance, and the README no longer tells authors that remove answers Locked. Four P2-level issues remain: the new claim-carrying write, import and remove take claim_id without the trusted caller or a nonce rule; the new PluginFiles withLock cannot leave an absent record absent through FileStorage's update; resource-owner-operations.md still describes a lease in the FileScope writeStream row and the Settings paragraph; and the client-ui R5 section still requires a pinned read resource. A fifth P2 is cross-PR: #2097's EventHub and Scheduler contracts describe a PluginFiles face with no scope object. The P3 items are optional.

Prior round

Finding Status at ed23162 Evidence
P2: remove and import of auth.json did not take the account marker Fixed for the non-holder path. Line 19 and the write, import and remove rows say the account file takes the marker, and a call without claim_id waits. A new P2 covers the missing caller and nonce rule on the claim-carrying operations. FileStorage.md:19, :179-180, :184, :218, :222
P2: create_directory recursive versus the Session-files missing_parent Fixed. The acceptance says create_directory creates the tree and a link at any level is invalid; the operation row and flow are recursive and the row has no missing_parent. One P3 leftover remains at p6-p7-bindings.md:136. FileStorage.md:182, :220; session-files.md:685-686
P2: the README said remove answers Locked Fixed. The trusted-plugin section is deleted and points to the PluginFiles contract; the table row is gone. crates/dim-app-server/README.md:524
P3: #2095 has no replace-between-pages acceptance Partly. The contract now tracks it as an upper alignment item and preserves the current version guarantee; #2095 at fa2eea2c still has no acceptance section. Optional. FileStorage.md:235
P3: the unsynced row was written for writes only Fixed. The row now gives the state after each operation. FileStorage.md:203
P3: the current implementation called the marker the external TypeScript wire format Fixed. The sentence says published marker format and drops the external wire claim. FileStorage.md:646-647
P3: the Session-files scenario omitted io Fixed. The scenario names cancelled, unsynced or io. session-files.md:619
P3: p6-p7 named a write the binding does not have Fixed at 4f8bd65; still fixed. p6-p7-bindings.md:171

Existing review

I agree with the existing reviews at 4f8bd65 and 7224c0c on the PluginFiles transaction boundary and the UI-resource version guarantee; P2 2 and P2 4 name the specific cases that remain.

P2 findings

P2 1. The claim-carrying write, import and remove have no trusted caller and no nonce rule

Problem: The head adds claim_id to write, import and remove (FileStorage.md:179-180, :184) and says a claim holder passes it (:19). The row binding and the nonce check are stated only for update: :190 says update with claim_id checks the marker nonce and a reclaimed claim is rejected with reason claim-lost, and :230 says only claim, release and a claim-carrying update take caller: &Ctx. The appendix signatures for write, import and remove take no caller (:511-520, :522-532, :562-568). The invalid row already promises to reject an other-row claim id (:198), which the owner cannot check without the calling row. The import and remove error lists also omit rejected (:180, :184).

Failure scenario: Row A holds the claim while Managed OAuth refreshes. Row B, another caller row in the same process, calls remove(auth.json, claim_id = A) or import(auth.json, ..., claim_id = A). Because these operations take no Ctx, the owner cannot reject the other row's claim as :198 promises. It either accepts the claim and unlinks or replaces auth.json under A's hold, so A's refresh commits over B's replacement or loses the imported record, or it refuses all claim-carrying write, import and remove calls, which breaks the claim-holder path the contract now documents. A reclaimed claim is the same hole: :190 gives update a rejected/claim-lost result, but import and remove have no caller and no rejected row, so their stale same-row claim id has no stated outcome.

Evidence: FileStorage.md:19, :179-180, :184, :190, :198, :218, :222, :230, :511-520, :522-532, :562-568.

Fix: Add caller: &Ctx to every operation that accepts claim_id, and add those operations to the Exception bullet at :230. State that each claim-carrying call checks the marker nonce and answers rejected with claim-lost on a reclaimed claim, and add rejected to the import and remove rows. Alternatively, move the claim-carrying path onto update and refuse claim_id on the other operations.

P2 2. PluginFiles cannot leave an absent record absent through FileStorage update

Problem: PluginFiles.md:26 says withLock with a null replacement returns the current text; :89 says work receives the current text or none when the file is absent and returns the replacement text, where none keeps the file unchanged; :108 says the owner leaves the file when the replacement is none; :144 verifies that a null replacement leaves the file unchanged. The owner runs work under FileStorage's update (:89). FileStorage's update change receives the current content and must return the next content as Bytes (FileStorage.md:188, :440-441); there is no no-write result. For an existing file, returning the current bytes gives applied: false; for an absent file, the change cannot return none. The current lease implementation skips the replace when the change returns none (crates/dim-app-server/src/plugin_files.rs:747-757), so the target loses exactly that case.

Failure scenario: A fresh product home. The notebook example calls files.withLock("notebook/state.json", current => ({ text: null, value: current })) (docs/typescript-plugin-authoring.md:293), and the requirement row at PluginFiles.md:26 uses the same null replacement to read a record. The file is absent, so work returns text null. To stay inside FileStorage's update, the provider must either write an envelope, creating a file the contract says stays absent, or skip the update, which gives up the cross-process exclusion the withLock transaction promises (:14, :27). The first read of every new record is either a spurious file or a non-exclusive read.

Evidence: PluginFiles.md:26, :89, :108, :144; FileStorage.md:188, :440-441; crates/dim-app-server/src/plugin_files.rs:747-757.

Fix: Let FileStorage's update change return an optional replacement (Result<Option<Bytes>, Rejected>, where none means no write) and document it, or add a read-under-key operation. Map PluginFiles' null replacement to that result. Add a flow test that reads an absent record with a null replacement and asserts no file is created and a concurrent creator serializes.

P2 3. resource-owner-operations.md still describes the lease

Problem: The head retires the lease (FileStorage.md:153; PluginFiles.md:5, :126-127) and updates the pluginFiles row (resource-owner-operations.md:11), but the same document's FileScope.writeStream row still says the scope "consumes a reader to EOF under the destination lease" (:23), and the Settings paragraph still says "File and project profiles retain their lease" (:79) while the same file's line 141 now says file-backed settings use FileStorage's read and update. The PR's Supersedes list covers the fileStorage row, the FileScope read row and the paragraph (FileStorage.md:240), not the writeStream row; PluginFiles.md's Supersedes list does not include this table (PluginFiles.md:136-138).

Failure scenario: An implementer of the FileScope.writeStream binding follows the row and takes a FileStorage lease. The target has no lease and no multi-call session (FileStorage.md:153, :161), so they either keep a lease the contract says does not exist or cannot implement the binding. A settings implementer reads :79 and keeps the lease while :141 says read and update, so the migration inventory has two answers for one path.

Evidence: resource-owner-operations.md:23, :79, :141; FileStorage.md:153, :161, :240; PluginFiles.md:5, :126-127, :136-138.

Fix: Change :23 to FileStorage's write with a source and no lease. Change :79 to FileStorage's read and update or state the migration. Scan the rest of the file for lease before the next round.

P2 4. The client-ui R5 section still requires a pinned read resource

Problem: The PR changes the first R5 bullet to path-offset reads and no file handle (client-ui-extensions.md:287), but the required capability still says FileStorage returns "a locatable read resource" with a per-consumer read position and a release (:289), and the timing still says "the file object is pinned when the read resource is acquired" (:290). The target has stateless reads (FileStorage.md:21), deletes the pinned reader (:235), crosses no reader id (:291), and lets a page after a replace see the replaced content (:261). #2095's UiResources contract says "No reader id exists" (docs/design/plugins/UiResources.md:51 at fa2eea2c). The PR's Supersedes list says it supersedes the reading-resource, read-handle and R5 sentences (FileStorage.md:253), but these two remain.

Failure scenario: A UiResources or client implementer follows R5 and builds a pinned read resource. The FileStorage target has none, and #2095 pages by path, so the implementation cannot exist. If they instead page by path, the pin guarantee in R5 is false: a replacement between pages mixes versions, which the client contract says cannot happen. The existing guarantee is preserved only until #2095's acceptance lands (FileStorage.md:235), not by a read resource.

Evidence: client-ui-extensions.md:287, :289, :290; FileStorage.md:21, :235, :253, :261, :291; #2095 UiResources.md:51.

Fix: Replace the R5 required capability and timing with stat plus stateless read pages, where each caller passes its offset, or state that UiResources owns the version guarantee until #2095 lands and that the read resource and pin are deleted.

P3 findings (optional)

P3 1. The import example does not compile

Problem: The import signature now takes claim_id before permissions (FileStorage.md:522-531), but the example still passes path, source, Some(MAX_FILE_BYTES), Some(Permissions::PrivateReadOnly) and cancelled (:103). The two write examples were updated with None (:101, :113).
Failure scenario: A reader copies the example and gets a missing-argument error; the doc's only import call site does not match the signature it documents.
Evidence: FileStorage.md:103, :522-531.
Fix: Insert None for claim_id.

P3 2. PluginFiles has cancellation outcomes but no cancellation error

Problem: Every operation's Cancellation column promises a cancellation outcome (PluginFiles.md:78-85), and the flows say "the owner's update returns cancelled" and "the call ends cancelled" (:108-109), but the error table (:97-102) and PluginFileError (:235-248) have no cancelled kind. The current code maps FileStorageError::Cancelled to PluginFileError::Closed (crates/dim-app-server/src/plugin_files.rs:512), and the closed row at :101 says the scope is unloading.
Failure scenario: A caller cancels withLock; it receives closed, whose retry row says to use a new scope, although its scope is open and the call changed nothing. An implementation that forwards cancelled has no variant to return.
Evidence: PluginFiles.md:78-85, :97-102, :108-109, :235-248; crates/dim-app-server/src/plugin_files.rs:512.
Fix: Add cancelled to PluginFileError and the error table, or state that cancellation maps to closed and widen that row's meaning and retry guidance.

P3 3. p6-p7-bindings.md still says the creates are non-recursive

Problem: create_directory now creates the whole tree (FileStorage.md:182, :220; session-files.md:685-686), but the workflow definition binding still says createDirectory ensures the two ancestors "through existing non-recursive creates" (p6-p7-bindings.md:136). The PR's Supersedes list covers the definition-file paragraph of section 3.4 (FileStorage.md:243).
Failure scenario: A Workflow implementer or test follows the binding and expects one level per call or a missing-parent refusal; the owner contract creates the tree and has no missing_parent for this operation.
Evidence: p6-p7-bindings.md:136; FileStorage.md:182, :220; session-files.md:685-686.
Fix: Say "through create_directory for each ancestor" or "through the recursive create_directory"; align with the owner contract.

P3 4. The FileStorage and PluginFiles documents claim to supersede each other

Problem: FileStorage.md:246 lists docs/design/plugins/PluginFiles.md as text this page supersedes, while PluginFiles.md:138 lists the FileStorage PluginFiles paragraph as text it supersedes. The paragraph is still present at FileStorage.md:161, and FileStorage.md:10 says PluginFiles "is not covered here". A rule is stated once at its layer (ADR 006 D1 and D9), and a design links to another owner's contract instead of restating it (ADR 008 D3).
Failure scenario: A reader or a future editor cannot tell which document owns the withLock transaction rule. A change to the rule may be made in the wrong page, and one of the two Supersedes claims is false.
Evidence: FileStorage.md:10, :161, :246; PluginFiles.md:138.
Fix: Remove the PluginFiles bullet from FileStorage's Supersedes, and remove or reduce the FileStorage PluginFiles paragraph to a one-line link, so PluginFiles.md is the only owner of that rule.

Cross-PR and main

  • Main. Current main is 5930539bc, not eacc672d; the PR base is 5930539bc. git merge-tree --write-tree origin/main HEAD is clean at 9693c6e3. The PR is open, not draft, MERGEABLE.
  • P2 conflict with #2097 at ed43cd98. Its EventHub and Scheduler contracts say PluginFiles is "the by-name text update and read ... with the lock held across the caller's change; no scope object" (docs/design/plugins/EventHub.md:222, docs/design/plugins/Scheduler.md:269; dependency rows at EventHub.md:108, Scheduler.md:114). This head says PluginFiles' public face is the dimcode/plugin SDK scope (PluginFiles.md:5, :235), withLock is one compute-only change under FileStorage's update (:14, :89), and the FileStorage face has no lease and no multi-call session (FileStorage.md:153, :161). The two target contracts cannot both be implemented: #2097's callers use a by-name process operation with no scope object, and this contract has no such operation, or an implementer adds a second PluginFiles face, which the one-face rule forbids. Align #2097 or this contract before either lands.
  • #2091 at c6d1dae4. Aligned on the contract: its SessionFiles uses the operations this face has (root_path, read, write, import, create_directory, list, remove), clamps an offset above size to size (SessionFiles.md:80), and says put and import never see missing_parent (:82). Its session-files.md changes are in section 9.1, not this head's section 7. It inserts four rows at docs/design/plugins/README.md:11 and rewrites the Process parts line, the same anchor and line this head changes; the two hunks will conflict and one must be rebased.
  • #2093 and #2094. Their contracts are aligned where they touch this face (#2093 FileAccessFacts stat, #2094 Settings file-backed paths). Both also insert owner-contract rows at the same docs/design/plugins/README.md table and rewrite the Process parts line; #2080 inserts the PluginFiles row at :11 and rewrites the same line. These are merge-order conflicts in the shared index, not contract disagreements, and the earlier no-overlap note no longer holds at these heads.
  • #2095 at fa2eea2c. UiResources pages by path, records the size at publish and opens no reader (UiResources.md:51, :61), aligned. Its replace-between-pages acceptance is still absent; this head tracks it as an upper alignment item (FileStorage.md:235). It also inserts rows at the same docs/design/plugins/README.md table and rewrites the Process parts line, so its index hunk conflicts with this head's; rebase one after the other.
  • #2096 at 9ca30e0f. It uses claim and release and says no TypeScript source writes auth.json; aligned, but it is CONFLICTING and needs a rebase.
  • Only this open PR changes docs/architecture/rust-agent/plugins/FileStorage.md and adds docs/design/plugins/PluginFiles.md.

Verification

  • node scripts/adr-check.mjs --base origin/main: passed, 19 changed files.
  • git diff --check origin/main...HEAD: passed.
  • Relative-link scan over the 19 changed files: one anchor warning at docs/design/resource-faces.md:740 for the section 5 anchor in worktree-management.md; that line comes from main and is not changed by this PR. No new broken link was found.
  • git merge-tree --write-tree origin/main HEAD: clean at 9693c6e3.
  • CI at ed231629: changes, static-checks, verify (linux), macos-native and ci-ok passed; the other jobs were skipped. No Rust build or runtime test was run; this is a documentation-only change.

Unverified

  • The current implementation's absent-record path is read from crates/dim-app-server/src/plugin_files.rs:747-757, not run. The claim-carrying write, import and remove behavior was not probed.
  • #2095 and #2097 were checked at fa2eea2c and ed43cd98; either PR may change.
  • The R5 client read path was not executed.

Prior findings to withdraw

The three round-6 P2 findings are withdrawn: the non-holder marker path, the create_directory acceptance and the README Locked row. The unsynced, external TypeScript wire format, io scenario and p6-p7 write P3 findings are also withdrawn. The #2095 acceptance remains optional.

- The account marker `auth.json.lock` is the published exclusion for `auth.json`: every writer of the file, in this process or another, holds the same marker. The marker is a file carrying the holder's process id, creation time and nonce; a marker older than 30 seconds without a live process at its creation is reclaimed, and a marker this process failed to release is reclaimed at once by its next claim. It coordinates the two Rust writers of `auth.json` — the DimOAuth store and managed OAuth; the TypeScript plugin no longer writes the file ([runtime contract](../../../../crates/dim-oauth/docs/runtime-contract.md) line 32), so this is not a cross-language protocol.
- `Rejected` carries only `reason` and `message`: a callback error must cross languages, so it comes back as data; `From<CallError>` recovers the wire error's own code into `reason`, and the caller keeps its business error type inside its own callback.
- A file another plugin owns under a root — SQLite's database, the model-log recorder's JSONL, the UI extension cache — is not FileStorage's data; FileStorage does not track ownership and cannot refuse a `remove` of it. The convention that a plugin removes only its own files is the caller's, and a root is not an ownership boundary.
- `claim`, `release` and a claim-carrying `update` take `caller: &Ctx`, the dispatch's calling row, because the claim is bound to that row; it is not caller-supplied data and no caller sends 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.

P2: claim_id is now on write, import and remove (:179-180, :184), but this bullet still limits the trusted caller to claim, release and a claim-carrying update, and the appendix signatures at :511-520, :522-532, :562-568 take no caller: &Ctx. A claim is row-bound (:190), and :198 promises to reject an other-row claim id, which the owner cannot check without the calling row. Scenario: row B passes row A's claim id to remove(auth.json, claim_id) or import(auth.json, ..., claim_id) while A refreshes; the owner either accepts the other row's claim and unlinks or replaces the file under A's hold, or refuses all claim-carrying calls. Only update states the nonce check and claim-lost; import and remove do not list rejected. Fix: add caller: &Ctx to the three operations and this bullet, state the nonce check and rejected/claim-lost for each, or move the claim path onto update.

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 5b56b49 and verified at e21dc90. claim_id is now only on update; write, import and remove take no claim id, and a claim holder releases the claim first (FileStorage.md:19, :181-182, :186, :192, :232, :513-531, :562). The rows, flows, exception and signatures agree. Withdrawn.

Comment thread docs/design/plugins/PluginFiles.md Outdated
| `quiesce` | Stop admitting work on the scope | — | unit | None; admitted work keeps its time | `closed` |
| `close` | Stop the scope and settle admitted work | — | unit | None; the owner completes | `closed` |

`withLock`'s `work` is a direct callback, not a request field. It receives the current text, or none when the file is absent, and returns the replacement text (none keeps the file unchanged) together with its own result. It only computes: an external wait, another owner or another PluginFiles call inside `work` holds the record for that whole wait. The owner runs `work` under FileStorage's `update`, so two processes cannot interleave; a repeated result is idempotent because the replacement is compared with the current text.

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: a null replacement cannot be expressed by FileStorage's update: its change receives the current content and must return Bytes (FileStorage.md:188, :440-441), so an absent file plus a null replacement can only create an empty envelope or skip the update and lose the cross-process exclusion. The requirement row at :26 and the notebook example (docs/typescript-plugin-authoring.md:293) use that case on a first run. Fix: let update return Option<Bytes> with none meaning no write, or add a read-under-key operation; add an absent-record test.

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 5b56b49 and verified at e21dc90. ChangeFn returns Result<Option<Bytes>, Rejected> and update's change can return None, which writes nothing and does not create an absent file (FileStorage.md:190, :221, :442-443); PluginFiles maps a null replacement to it (PluginFiles.md:89). Withdrawn.

### R5. FileStorage:受授权根约束的原生只读流

- **阻塞与规则:** §3.2 和 §6 需要有界复制与按字节区间读取;[FileStorage](../architecture/rust-agent/plugins/FileStorage.md) 的整块读取/限长读取不提供随传输背压拉取的文件句柄。
- **阻塞与规则:** §3.2 和 §6 需要有界复制与按字节区间读取;[FileStorage](../architecture/rust-agent/plugins/FileStorage.md) 的按路径偏移读满足分页(`read` 的 offset/length),不提供文件句柄或背压流;撤下与在途页竞争时只返回整页或 `resource_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.

P2: this bullet now says path-offset reads and no file handle, but the required capability below (:289) still returns a locatable read resource and the timing (:290) still pins the file object. FileStorage's target has stateless reads (FileStorage.md:21), deletes the pinned reader (:235) and lets a page after a replace see the replacement (:261); #2095 UiResources.md:51 says no reader id exists. Fix: replace :289-290 with stat plus stateless read pages, or state that UiResources owns the version guarantee until #2095 lands.

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 5b56b49 and verified at e21dc90. R5 now requires stat plus caller-carried offset pages and states the published-path guarantee instead of a pinned read resource or file handle (client-ui-extensions.md:289-290). Withdrawn.

// `once` is a source that yields the bytes once and then none.
let size = storage.write(path, once(bytes), None, Some(Permissions::PrivateReadOnly), cancelled.clone()).await?;
// A host file the caller named, without reading it first.
let size = storage.import(path, source, Some(MAX_FILE_BYTES), Some(Permissions::PrivateReadOnly), cancelled).await?;

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: the import signature at :522-531 now takes claim_id before permissions, but this example still passes five arguments. Insert None for claim_id, as the write examples do at :101 and :113.

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 5b56b49 and verified at e21dc90. import no longer takes claim_id, so the example at FileStorage.md:103 matches the signature at :523-531. Withdrawn.


| Operation | Normal path | Caller cancels | Caller unloads | Owner closes or reloads | Settled by |
| --- | --- | --- | --- | --- | --- |
| `withLock` | Resolve the name, call FileStorage's `update`; `work` runs under that hold, the owner writes the replacement or leaves the file when it is none, and FileStorage syncs the parent | Before the replacement: the file is unchanged; the owner's `update` returns `cancelled` | Admitted work settles before the scope closes; an unadmitted call ends `cancelled` | New work is refused; admitted work settles; a later call is `closed` | FileStorage's `update` and temporary file; the scope by 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.

P3: this flow says the owner's update returns cancelled and an unadmitted call ends cancelled, and every Cancellation column promises an outcome, but PluginFileError (:235-248) and the error table (:97-102) have no cancelled kind; the current code maps FileStorageError::Cancelled to Closed (crates/dim-app-server/src/plugin_files.rs:512). The closed row says the scope is unloading. Add cancelled, or state the mapping and widen the closed row's retry guidance.

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 5b56b49 and verified at e21dc90. PluginFileError and the error table now have cancelled, and every operation row lists it (PluginFiles.md:78-85, :100, :252). Withdrawn. The client-visible changes bullet at :137 still lists only unsynced; that is an optional leftover, noted in the review body.

- `docs/design/p6-p7-bindings.md`: the Workflow definitions row of §3, the root registration paragraph and the definition-file paragraph of §3.4.
- `docs/design/plugins/Modality.md`: the FileStorage clause of the dependency table.
- `docs/design/process-typescript.md`: the FileScope read paragraph and §5.2.
- `docs/design/plugins/PluginFiles.md`: the new owner contract for the pluginFiles 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.

P3: PluginFiles.md is the new owner contract in this same head, and its Supersedes at PluginFiles.md:138 names this page's PluginFiles paragraph. Listing it here as text this page supersedes is circular, and the paragraph at :161 remains. Remove this bullet and let PluginFiles.md own the paragraph; :10 already says PluginFiles is not covered here.

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 5b56b49 and verified at e21dc90. The PluginFiles.md bullet is removed from FileStorage's Supersedes, and the paragraph at FileStorage.md:163 is a one-line link. Withdrawn.

@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 per-operation claim now fixes the earlier same-row exclusion issue. The new PluginFiles owner page also makes the migration boundary clearer. One concrete regression remains in that new contract:

Make a committed Workflow update visible even if writing the derived token fails. The proposed two-transaction sequence makes readers reload on a token mismatch. But the current cache only reloads when the observed token changes. If the document commits but publishing the token fails, that token remains unchanged and readers can keep serving the previous runs. Put the observed revision in the same authoritative record, or define a recovery and read rule that cannot hide a committed update. Add acceptance for a failure between the two writes with an already warm reader.

The previous refresh-settlement requirement remains: draining only an admitted storage update does not settle an already admitted refresh before the final update reaches storage. Keep that lifecycle guarantee and the UI version guarantee tracked in the previous reviews. The exact-head peer review already covers the no-write operation and claim binding; I am not duplicating those findings. Hosted checks passed; the changed contract itself is documentation.

Move the claim id to update alone, let update return no write, add the
refresh write-back endings and the Workflow single-commit design, and update
the remaining lease and R5 paragraphs plus their Chinese mirrors.
@eric8810

Copy link
Copy Markdown
Collaborator Author

已按评审修改,head 5b56b4956(base 5930539bc)。

第 9 轮的处理:claim_id 只留在 update;write/import/remove 在自己的调用里取 auth.json marker,任何持有者(含同一行)等待,持 claim 行只能 update(claim_id),其他操作先释放;update 的 change 返回 Option<Bytes>,None 不写(现有不变、缺失不创建、applied: false),PluginFiles 映射 null;刷新成功但写回失败的结局按 managed_oauth.rs:1038-1092 写入;R5 改为 stat + 调用方 offset 的无状态分页;resource-owner-operations 的 lease 行、p6-p7 的非递归 create、PluginFiles 的 cancelled、FileStorage/PluginFiles 互相 Supersede 均已修;中文镜像同步。

新增「留给上层的对齐项」:#2097 的 docs/design/plugins/EventHub.md:108、:222 与 docs/design/plugins/Scheduler.md:114、:269 把 PluginFiles 写成按名操作、没有 scope;按本 PR 的 PluginFiles 契约,它们应改为通过 FileScope 调用 with_lock。本 PR 不改 #2097。

其余留给上层:#2095 的 replace-between-pages 验收与 pinned reader 删除同交付;#2096 的 DimOAuth.md/ManagedAccount.md 行按其 head 对齐;#2091/#2093 的 P2-6/P2-7 与 P3-6 仍属它们。

检查:adr-check(21 文件)、xtask-check、git diff --check、链接/锚点 0 断链、五份 appendix 同 crate cargo check 均通过。

@yyhhyyyyyy @zerob13 请再看一次。

@eric8810

Copy link
Copy Markdown
Collaborator Author

已按评审修改,head e21dc901e(base 5930539bc,只有 P3 改动)。

/tmp/prereview8-2080.md 不存在(目录里只有 prereview-2080.md 与 prereview2-2080.md);我按最新一轮评审(yyhhyyyyyy 6038690215、zerob13 6038864293)与前两轮预审逐条核对了 P3:

  • P3 import 示例参数:claim_id 已从 import 签名移除,示例与附录一致。
  • P3 PluginFiles 缺 cancelled:已加入 PluginFileError、错误表与各操作的错误列;取消不再映射为 closed。
  • P3 p6-p7 仍写非递归 create:已改为「createDirectory for each level」。
  • P3 FileStorage/PluginFiles 互相 Supersede:FileStorage 的 PluginFiles 段已缩成一行链接,Supersedes 移除该条目;PluginFiles.md 是唯一来源。
  • 本轮新发现的 P3:write 示例仍多传一个 None(claim_id 已只属于 update),两处已删。

仍不能在本 PR 修的 P3:

检查:adr-check(21 文件)、xtask-check、git diff --check、链接/锚点 0 断链、五份 appendix 同 crate cargo check 均通过。

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

The new design gives Workflow one commit point, which addresses the split-write problem in my previous review. Please finish the publication and migration contract before implementing it.

PluginFiles.md:119 allows startup cleanup to remove every file not referenced by the current pointer, but also lets a writer stage its next data file before publishing that pointer. The contract does not order cleanup against admitted writers. As written, it cannot guarantee that a committed pointer names existing data. Serialize cleanup against publication or otherwise protect staged files until settlement. Also define recovery for an uncertain pointer update before allowing deletion.

The same migration paragraph only handles a missing pointer, but the shipped writer already writes both the old document and a version token. Define how those existing stores are recognized and migrated. Update the old dual-write example and acceptance at lines 39–44 and 158 to match the single commit point, and cover concurrent startup and an existing store with both legacy records.

This is a contract review, not an executed Workflow test. The documentation and static checks passed on the linked head; native CI was still running when checked.

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

FileStorage and PluginFiles target contracts: review at e21dc90

Scope. This PR gives FileStorage its owner contract, retires the lease, adds the PluginFiles owner contract, moves the FileStorage page to the architecture plugins directory, and updates the callers and sibling contracts. Head e21dc901 is based on current main 5930539bc; the previous review used ed231629. The head moved from 5b56b495 to e21dc901 during this review; e21dc901 only fixes the two write examples for the removed claim_id (FileStorage.md:101, :113). The PR is open, not draft, and MERGEABLE (mergeStateStatus BLOCKED). Full diff origin/main...HEAD: 21 files, 1018 insertions, 467 deletions. This is round 8.

Verdict: REQUEST_CHANGES. The round-7 P2s are fixed: claim_id is only on update, update's change returns Option<Bytes>, the FileScope writeStream row and the Settings paragraph use FileStorage's write and update, and R5 uses stat plus caller-carried pages. Two P2 contract defects remain: the new Workflow one-commit bullet contradicts the same page's example and Verification, the accepted Workflow contract, and the current store; and the PluginFiles invalid_path row rejects every multi-component name, which all callers use. The cross-PR #2097 scope-object conflict is also P2. The remaining P3 items are optional.

Prior round

Finding at ed23162 Status at e21dc90 Evidence
P2: claim-carrying write, import and remove had no trusted caller or nonce rule Fixed by the second option: claim_id is only on update; the other operations take no claim id and a claim holder releases the claim first FileStorage.md:19, :181-182, :186, :192, :232, :513-531
P2: PluginFiles could not leave an absent record absent through update Fixed: ChangeFn and update's change return Option<Bytes>; None writes nothing and does not create an absent file, and PluginFiles maps a null replacement to it FileStorage.md:190, :221, :442-443, :269; PluginFiles.md:89
P2: resource-owner-operations.md still described the lease Fixed: the FileScope.writeStream row uses FileStorage's write, and the Settings paragraph and row use read and update resource-owner-operations.md:23, :79, :141
P2: the client-ui R5 section required a pinned read resource Fixed: R5 requires stat plus caller-carried offset pages and states the published-path guarantee client-ui-extensions.md:289-290
P3: the import example did not match the signature Fixed: the signature no longer takes claim_id, so the example matches FileStorage.md:103, :523-531
P3: PluginFiles promised cancelled outcomes but had no error kind Fixed: PluginFileError and the error table have cancelled; one summary line remains optional PluginFiles.md:78-85, :100, :252
P3: p6-p7-bindings.md still said the creates were non-recursive Fixed: it says createDirectory for each level p6-p7-bindings.md:136
P3: FileStorage and PluginFiles claimed to supersede each other Fixed: the FileStorage bullet is gone and the paragraph is a one-line link FileStorage.md:163, :239-254
Optional: #2095 has no replace-between-pages acceptance Still absent at fa2eea2c; optional #2095 UiResources.md
P2 cross-PR: #2097 still described PluginFiles as a by-name text update and read with no scope object Still open at ed43cd98; see Cross-PR #2097 EventHub.md:108, :222; Scheduler.md:114, :269; this head PluginFiles.md:120

P2 findings

P2 1. The new Workflow one-commit bullet contradicts the example, the Verification and Workflow.md

Problem. The bullet at PluginFiles.md:119, new in 5b56b49, says Workflow's run store has one commit point: the writer stages workflow/runs/<token>.json, then one update of workflow/runs.version is the only commit, startup deletes runs/*.json the token does not point to, and an old runs.json migrates once. The same page's example at :39-44 still writes workflow/runs.json and then workflow/runs.version as two withLock transactions, and the Verification at :158 still says Workflow's two transactions are workflow/runs.json then workflow/runs.version. The accepted Workflow contract says the owner stores one JSON document at workflow/runs.json plus a derived token, the token is written in its own transaction after the store replace, a failed token write leaves the token naming older text, and no migration runs during recovery (docs/design/plugins/Workflow.md:526, :528). The current store implements that model (runtime/plugins/workflow/store.ts:165-217).

Failure scenario. An implementer follows this bullet and writes workflow/runs/<token>.json. Workflow's readers, retention and startup recovery still read workflow/runs.json (Workflow.md:526-528), so the pointer names a file no reader reads. An implementer who keeps the current store keeps the hidden-commit case: the store replace commits and the token write fails, so a warm reader keeps serving the old snapshot. The staged write also targets a workflow/runs/ directory that no doc provisions, and withLock returns io for an absent parent (PluginFiles.md:78), so the first write fails.

Evidence. PluginFiles.md:39-44, :78, :119, :158; docs/design/plugins/Workflow.md:526, :528; runtime/plugins/workflow/store.ts:165-217.

Fix. Remove this bullet and define the Workflow recovery rule in Workflow.md, or make this the agreed Workflow change and update Workflow.md:526-528, PluginFiles.md:39-44, :158, the workflow/runs/ setup and the migration policy in the same delivery. Use withLock rather than FileStorage's update for the pointer if the file stays a PluginFiles text record.

P2 2. The invalid_path row rejects every multi-component PluginFiles name

Problem. PluginFiles.md:97 lists invalid_path for "a name that is not one component". A PluginFiles name is a relative path (:11), and every example and caller uses several components: workflow/runs.json (:42), scheduler/jobs.json (:49), modality/results/42.json (:60). The resolver accepts a multi-component relative path (crates/dim-app-server/src/plugin_files.rs:261, crates/dim-agent-capabilities/src/file_storage.rs:352). The row was present at ed231629; the full-diff pass found it.

Failure scenario. An implementer follows the error row and answers invalid_path for scheduler/jobs.json or workflow/runs.json, so Scheduler, EventHub, Workflow and Modality cannot open a record, and the new Workflow layout at :119 cannot create its staged file. Every caller fails before the transaction starts.

Evidence. PluginFiles.md:11, :42, :49, :60, :97; crates/dim-app-server/src/plugin_files.rs:261; crates/dim-agent-capabilities/src/file_storage.rs:352.

Fix. Drop the clause or replace it with "a component that is empty, . or .., or a reserved component".

Cross-PR and main

  • Still open from round 7, #2097 at ed43cd98. Its EventHub and Scheduler contracts still describe PluginFiles as "the by-name text update and read ... with the lock held across the caller's change; no scope object" (docs/design/plugins/EventHub.md:222, docs/design/plugins/Scheduler.md:269; dependency rows at EventHub.md:108, Scheduler.md:114). This head's Callers and migration bullet moves those callers to withLock on the scope (PluginFiles.md:120). The two target contracts cannot both be implemented: #2097's callers use a by-name process operation with no scope object, and this contract has no such operation, or an implementer adds a second PluginFiles face, which the one-face rule forbids. Align #2097 or this contract before either lands.
  • #2091 at c6d1dae4. Aligned on the operations and the page rules: its SessionFiles.md uses root_path, read, write, import, create_directory, list and remove, clamps an offset above size, and says put and import create their parents. It inserts owner rows at the same docs/design/plugins/README.md table and rewrites the Process parts line, so one of the two index hunks must be rebased.
  • #2093 at 4557d0b8, #2094 at 0677c715, #2095 at fa2eea2c. Their contracts are aligned where they touch this face; all three insert owner rows at the same docs/design/plugins/README.md table and rewrite the Process parts line, so these are merge-order conflicts in the shared index, not contract disagreements.
  • #2095 at fa2eea2c. UiResources pages by path, records the size at publish and opens no reader (UiResources.md:51, :61), aligned. Its replace-between-pages acceptance is still absent; FileStorage.md:237 keeps the existing guarantee and treats the acceptance as an upper alignment item. Optional.
  • #2096 at 9ca30e0f. It uses read and update for the account record and write for the backup; aligned, but it is CONFLICTING and needs a rebase.
  • Main. Current main is 5930539bc, the PR base. git merge-tree --write-tree origin/main HEAD is clean at 9557f80a. The PR is open, not draft, MERGEABLE.
  • Only this open PR changes docs/architecture/rust-agent/plugins/FileStorage.md and adds docs/design/plugins/PluginFiles.md.

Verification

  • node scripts/adr-check.mjs --base origin/main: passed, 21 changed files.
  • git diff --check origin/main...HEAD: passed.
  • Relative-link scan over the 21 changed files: three missing anchors, all pre-existing in origin/main (docs/design/resource-faces.md:740, docs/zh/design/appserver/mcp-oauth.md:462, docs/zh/design/appserver/session-deletion-and-fork.md:239); this PR introduces no new broken link.
  • git merge-tree --write-tree origin/main HEAD: clean at 9557f80a.
  • CI at e21dc901: changes, static-checks and macos-native passed; verify (linux) was in progress, and the other jobs were skipped. No Rust build or runtime test was run; this is a documentation-only change.

P3 items (optional)

  • PluginFiles.md:137 lists the client-visible error changes as dropping locked and exists and adding unsynced; the new cancelled kind is also added (:100, :252). Add it to the summary.
  • FileStorage.md:219 (the write flow) says auth.json takes the marker but does not repeat that a claim holder releases the claim first, unlike the import and remove flows at :220 and :224. Add the clause so a claim-holder write does not wait on its own marker.
  • docs/zh/design/appserver/session-deletion-and-fork.md:86 still says the close releases FileStorage leases, while the English line now says keys and claims (session-deletion-and-fork.md:125). Sync the zh line.
  • crates/dim-app-server/README.md:535 still says the account lease three times, while the runtime contract now says the auth.json.lock marker (crates/dim-oauth/docs/runtime-contract.md:30). Update the paragraph or state that it records current behavior.
  • docs/design/plugins/Modality.md:46 still links the pluginFiles contract to the App Server README's trusted-plugin storage section, which is now a pointer to PluginFiles.md. Point it at PluginFiles.md.

Unverified

  • The current Workflow store path is read from runtime/plugins/workflow/store.ts:165-217, not run. The docs-only PR was not probed at runtime.
  • #2095 and #2097 were checked at fa2eea2c and ed43cd98; either may change.
  • The R5 client read path was not executed.

Prior findings to withdraw

The round-7 P2s on the claim caller and nonce, the null replacement, the resource-owner lease rows and the R5 pin are withdrawn as fixed. The round-7 P3s on the import example, the PluginFiles cancellation error, the p6-p7 creates and the circular Supersedes are withdrawn as fixed. The #2095 acceptance remains optional and open.


| Kind | Retry | What the caller does next |
| --- | --- | --- |
| `invalid_path` | After fixing the name | A relative path escaping the root, an absolute path, a reserved name, or a name that is not one component; nothing changed |

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: this row answers invalid_path for "a name that is not one component", but a PluginFiles name is a relative path and every example and caller uses several components: workflow/runs.json at :42, scheduler/jobs.json at :49, modality/results/42.json at :60. The rule at :11 and the resolver accept a multi-component relative path (crates/dim-app-server/src/plugin_files.rs:261, crates/dim-agent-capabilities/src/file_storage.rs:352). Scenario: an implementer follows this row and rejects scheduler/jobs.json, so Scheduler, EventHub, Workflow and Modality cannot open a record and the staged file at :119 cannot be created. Fix: drop the clause or say "a component that is empty, . or .., or a reserved component".


## Callers and migration

- Workflow's run store has one commit point. A write first writes the new content to `workflow/runs/<token>.json` (a new file), then makes one `update` of `workflow/runs.version`: the callback compares the current token with the one read before the write; on a mismatch it returns `None`, the writer deletes its new file, rereads and retries; on a match it writes the new token. That pointer update is the only commit; after it the writer deletes the old data file, and a failed delete leaves an orphan. A reader reads `runs.version` and reads the data file only when the token changed; if the data file is gone (a later write deleted it), it rereads the token and retries. Startup deletes `runs/*.json` the token does not point to, and when `runs.version` is absent but the old `runs.json` exists, it migrates once. A data-file write failure and a pointer-update failure are both uncommitted and return an error; there is no committed-but-unreadable state. Acceptance: a warm reader plus a write that fails between the data file and the pointer sees the old consistent snapshot and the writer gets an error; two concurrent writers, one retries and succeeds.

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: this new one-commit rule contradicts the caller example above, the Verification below, the accepted Workflow contract and the current store. The example at :39-44 still writes workflow/runs.json then workflow/runs.version as two withLock transactions, and :158 still says Workflow's two transactions with runs.json. docs/design/plugins/Workflow.md:526-528 says the run store is one document at workflow/runs.json, the token is derived and written after the store replace, a failed token write leaves the token naming older text, and no migration runs during recovery. The current store implements that model (runtime/plugins/workflow/store.ts:165-217). Scenario: an implementer follows this bullet and writes workflow/runs/<token>.json; Workflow's readers, retention and recovery still read workflow/runs.json, so the pointer names a file no reader reads. If they keep the current store, the "only commit" claim is false and a failed token write still hides a committed store. The staged file also needs a workflow/runs/ directory that no doc provisions, and withLock returns io for an absent parent (:78). Fix: remove this bullet and define the rule in Workflow.md, or make this the agreed Workflow change and update Workflow.md:526-528, :39-44, :158, the directory setup and the migration policy in this head. Use withLock rather than FileStorage's update for the pointer if it stays a PluginFiles record.

@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