Skip to content

docs(storage): define the session storage owners' target contracts - #2091

Closed
eric8810 wants to merge 19 commits into
mainfrom
dim/2018-storage-contract
Closed

eric8810 wants to merge 19 commits into
mainfrom
dim/2018-storage-contract

Conversation

@eric8810

@eric8810 eric8810 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #2018 · Refs #2015

Summary

Target contracts for the session storage board under design rules §7: responsibility split, caller examples, operations with cancellation and error kinds, flows that settle each resource, exceptions with reasons, rule check and requirements raised to mechanism owners.

  • SessionStore: the stored Session, grants, reply language, title revisions, worktree records and the Session exclusion, on the existing store name. The Store, SessionMetadata and WorktreeAssociations wrappers are replaced by the owner's own operations; the worktree removal is one registration lifecycle: the store checks and registers the root under the Session exclusion, releases it, runs the caller's removal step in the owner's task, and re-takes the exclusion to delete the record; overlaps answer in_use; a creation registers with beginWorktreeCreation and hands over with removeCreatedWorktree. fork reads the source configuration text itself and takes the target text from a caller callback; sessionConfigText is removed.
  • SessionFiles: Session file bytes and ownership on the existing sessionFiles name, marked on the owner type; the read is whole within the owner's limit; the wrapper type and the trait are deleted.
  • ManagedWorktrees: the managed root, task ids and Git on the existing managedWorktrees name, as a data face; remove composes the store's removeWorktree with this owner's Git step as the callback.
  • SqliteStorage: the database file, lease, format and capacity value on the existing sqliteStorage name. The Settings, Provider, Agent record and Timeline transactions are crate-private implementations of their data owners; the file-ownership rows are SessionFiles' private operations. The public face is storageReport and the offline operations.

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

Merge order

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

Sibling heads this change is aligned with: #2080 5b56b495, #2092 43f132d, #2093 4557d0b, #2098 c3acab356, #2099 8f440bde7.

Worktree removal lifecycle

Removal is one lifecycle for every caller: under the Session exclusion the store re-checks and registers the resolved root, releases the exclusion, runs the delete step in the owner's task (a caller leaving does not stop it), and re-takes the exclusion to delete the record and clear the registration. Overlapping create/fork/associate/remove refuse a path at, under or above a registered root with in_use; unrelated work proceeds. A creation registers its selected root with beginWorktreeCreation (a creationId bound to the calling row); create ends it, and a failed creation hands it to the removal set with removeCreatedWorktree.

@eric8810

Copy link
Copy Markdown
Collaborator Author

评审(head 73c259f4e):需改 2 处;ManagedWorktrees、SessionFiles、SessionStore 的 setTitle/removeWorktree 回调符合。

  1. SqliteStorage 代查。 公开面上有 Settings、Provider、Agent 记录三组以别人业务命名的操作(replaceUser{expectedVersion}、writeSelection{expectedVersion}、commitProviderEdit、members 等),版本与 conflict 是这些数据所有者的业务,却由存储引擎回答。按 §7「不代查,有性能需求时重新定义归属」:这些行归各自的数据所有者,引擎是它们的私有实现,不进 catalog;SqliteStorage 的公开面只留 storageReport 和离线操作。design(settings): owner contracts for Settings and the settings sections #2094(Settings)、design(provider): target contracts for the model and provider owners #2096(Provider)、docs(design): target contracts for the Agents and Collaboration owners #2098(Collaboration 的 sqliteStorage.members)的依赖随之改到各自所有者内部。
  2. sessionConfigText 只为 fork 存在。 调用方读出文本再原样传回 fork。改成 fork 自己读源文本;去掉 initialTitle 这一步作为 fork 的 change 回调传入。删掉 sessionConfigText。

@eric8810

Copy link
Copy Markdown
Collaborator Author

已按评审修改,head b5606d106。

  1. 存储引擎不再代查。 SqliteStorage 公开面只留 storageReport 与离线操作(backup、restore、vacuum)。Settings、Provider、Agent 记录与 Timeline 四组事务改为引擎的 crate 私有实现,操作与错误归各自所有者(design(settings): owner contracts for Settings and the settings sections #2094、design(provider): target contracts for the model and provider owners #2096、docs(design): target contracts for the Agents and Collaboration owners #2098 与 所有者扫描:会话存储 #2018 的 Session 仓储);catalog.md 的 sqliteStorage 行只剩 storageReport。交付评论的删除清单、迁移表与验收同步。
  2. sessionConfigText 删除。 fork 自己读源配置文本,initialTitle 的处理作为 fork 的 text 回调传入;回调在 fork 的排他内运行、只做计算,返回目标文本或 Rejected。操作表、调用方示例、错误、流程、绑定与交付评论已同步,fork 请求里的 configText 字段删除。
  3. 其余部分未动。 ManagedWorktrees、SessionFiles、setTitle 与 removeWorktree 的回调按评审保留。

两个检查通过。

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

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Scope: this PR adds four target contracts for the session storage owners (SessionStore, SessionFiles, ManagedWorktrees, SqliteStorage) under design rules section 7, refs #2018 and #2015. I checked the claims against the current storage code and against resource-faces, service-faces, resource-owner-operations, session-files, Attachments, SessionTitle, ADR 002 and ADR 013, and against section 7 of the principles text in PR #2029.

Verdict: REQUEST_CHANGES. The four docs agree with each other on most of the owner split, but several P2 contract defects remain: a creation and removal race in the stated order, error tables that contradict their own flows, SessionFiles read and import shapes that break the existing Attachments contract, a register check the owner cannot perform, unreconciled conflicts with the existing store, timelineStore, sqliteStorage and title contracts, and a binding appendix that would not produce the documented codes or compile.

Findings

P2: create validates the workspace before taking the exclusion

  • Problem: SessionStore.md:147 gives the order "Validate the id and the workspace, take the exclusion". The exclusion invariant at line 16 and the verification at line 169 require the workspace check inside the exclusion. The current code takes ownership first (crates/dim-app-server/src/storage/timeline.rs:1628) and checks config.cwd next (1629-1636).
  • Failure scenario: create checks a cwd under a worktree root; removeWorktree holds the exclusion, removes the root and deletes the directory record; create takes the exclusion, inserts the directory record and the association, and commits a Session whose cwd is gone. The verification "either sees the surviving directory or fails on the missing workspace" does not hold.
  • Fix: state "validate the id, take the exclusion, validate the workspace, write ..." and keep the code order.

P2: SessionStore error lists omit closed and delete omits invalid

  • Problem: the flows say new create and removeWorktree calls are refused closed (147, 154) and pending reads end closed (150), but those operations do not list closed (107, 120, 126). delete lists only storage (108), while the errors table defines invalid for "an id that is not one path component" (134), and delete_session rejects such ids (timeline.rs:1551-1554; resource-faces.md:754-755).
  • Failure scenario: a caller uses a closing generation for title, gets storage, and retries the same generation; a caller sends an id with a slash to delete, gets storage, and retries instead of fixing it.
  • Fix: add closed wherever the flow names it, and add invalid to delete.

P2: SessionFiles read removes offset paging and claims every caller needs the whole file

  • Problem: SessionFiles.md:71 and 77 make read whole-file, and line 110 says "every caller needs the whole file". The current contract returns at most 64 KiB per call with an offset (docs/design/appserver/session-files.md:419; crates/dim-app-server/src/storage/files.rs:619-620). Attachments A.1 defines attachment.read {sessionId,fileId,offset} returning {data,eof} at most 64 KiB (docs/design/plugins/Attachments.md:148-149; crates/dim-agent-attachments/src/lib.rs:169-178). The web download streams by offset (crates/dim-app-server/src/web_entry/uploads.rs:234,257), and image materialization pages by offset (crates/dim-agent-capabilities/src/session_files.rs:23-41).
  • Failure scenario: attachment.read and the HTTP download either stop compiling or must load a 16 MiB file (about 21 MiB base64) for each 64 KiB request. The stated reason, "a page protocol would push the read id's lifetime to callers", is not true of the existing stateless offset read.
  • Fix: keep offset and the 64 KiB chunk, or update Attachments and the web API and state the memory bound. Line 77 also calls a file id outside the Session invalid, while line 121 and the current read return not_found; pick one.

P2: SessionFiles import reply drops path

  • Problem: SessionFiles.md:69 returns {fileId, size} while put and write return {fileId, path, size} (68, 70). Attachments A.1 uses sessionFiles.import and returns {attachmentId, path, bytes, image} (Attachments.md:143-145; dim-agent-attachments/src/lib.rs:203-223). The current contract returns {fileId, path, bytes} (session-files.md:419).
  • Failure scenario: Attachments cannot produce the path for a text import or for attachment.import; the caller would have to reconstruct the owner's private <db>.session-files/<fileId>/<name> path, which the contract does not expose.
  • Fix: return {fileId, path, size} from import; align size and bytes with Attachments and session-files or update those contracts.

P2: SessionFiles register requires a check the owner cannot perform

  • Problem: SessionFiles.md:23 leaves the output directory with WorkspaceTools, but line 31 requires the owner to keep a registered path "inside the Session's output directory", and line 83 makes a path outside it invalid. The current contract has the caller check its own root (crates/dim-agent-capabilities/src/host.rs:1526-1527), and ADR 013 D2 has two roots, one owned by HostPlatform (docs/adr/013-command-output-ownership.md:36-39).
  • Failure scenario: WorkspaceTools registers command-output/<session>/... and ShellSession registers .dim/exec/<session>/<branch>/...; the owner cannot validate the second without depending on HostPlatform and the branch, so either shell registration fails or the owner takes another owner's path policy.
  • Fix: leave the root check with the caller as today, or name the owner that supplies both roots and raise the requirement there.

P2: the new store, timelineStore and sqliteStorage boundaries contradict the existing contracts

  • Problem: SessionStore.md:195 and 209 mark the service on SessionStore and delete Store, while resource-faces.md:795-798 says the Rust Store binding is the public type and "SessionStore remains the native bootstrap/implementation owner, not the public store type". SessionStore.md:205 and SqliteStorage.md:130 remove createSession, releaseSession, rollbackSession and append from timelineStore, while resource-faces.md:616 and service-faces.md:129 keep them there and resource-faces.md:619-630 defines append as the sync face operation. SqliteStorage.md:18, 32 and 90 make the Settings, Provider, Agent and Timeline transactions crate-private, while resource-owner-operations.md:41, 47, 57 and 59 and service-faces.md:128 say those owners call the public sqliteStorage face. SessionStore.md:99 also says sqliteStorage is not a service face, while SqliteStorage.md:119 and 160-169 mark it as one.
  • Failure scenario: an implementer following resource-faces keeps append on the Session face or keeps the engine's proxy operations; the catalog and the callers cannot satisfy both targets.
  • Fix: update resource-faces, service-faces and resource-owner-operations in this series, or add explicit requirements for their owners and state which rows these docs supersede.

P2: the setTitle appendix cannot keep the dropped-reply guarantee

  • Problem: SessionStore.md:121, 153 and 172 say a dropped reply still commits and announces, but the appendix declares pub async fn set_title (SessionStore.md:351-359). An async fn future runs only on first poll, so dropping it before polling never admits the write. The current set_title is a plain function that admits the write and spawns it before returning the wait future (crates/dim-app-server/src/storage/metadata.rs:201-224 and 342-350).
  • Failure scenario: a Rust caller creates the future and drops it; the write never commits, and the flow test "a dropped reply still commits and announces" fails.
  • Fix: keep the binding a plain fn that admits and returns impl Future, or state that a drop before the first poll does not admit the write and change the flow.

P2: the binding error types do not produce the documented codes and the callbacks do not compile

  • Problem: the appendices declare the error enums with #[derive(Debug, thiserror::Error)] only (SessionStore.md:299, SessionFiles.md:179, ManagedWorktrees.md:185, SqliteStorage.md:148). Under #[rutis::service], rutis 0.23 derives the wire code from serde when the error is Serialize, otherwise from the Debug variant; these types have no Serialize, so StoreError::WorkspaceMissing becomes WorkspaceMissing, not workspace_missing, and StoreError::Rejected { code, message } becomes Rejected, not the caller's code. The documented codes are snake_case and rejected must carry the callback's code (SessionStore.md:132-141). The callback aliases TextFn, ChangeFn and RemoveFn return Rejected (SessionStore.md:246-282), but rutis 0.23 FromFunction requires the callback error to implement From<rutis::host::CallError>; Rejected does not, so the #[rutis::service] methods with those parameters fail to compile.
  • Failure scenario: a foreign caller matches workspace_missing or the callback's rejected code and sees WorkspaceMissing or Rejected; the Rust binding cannot be built.
  • Fix: serialize the errors with the documented representation or provide a custom __rutis_fail that emits the code, including the inner Rejected code; add impl From<rutis::host::CallError> for Rejected.

P2: SessionFiles remove says an unowned file succeeds but also returns not_found

  • Problem: SessionFiles.md:72 says "a file the Session does not own answers success" and line 120 verifies that; line 85 defines not_found as "The Session has no such file". The two rules cannot both hold.
  • Failure scenario: an idempotent delete of a foreign or already removed file either fails or succeeds depending on the implementation; the caller cannot decide whether to retry.
  • Fix: drop not_found from remove or define it only for a missing Session and state the foreign-file result explicitly.

P2: the title change callback supersedes SessionTitle's expected-revision contract without a requirement

  • Problem: SessionStore.md:121, 153 and 160 replace the revision-checked write with a change callback and remove conflict; SessionTitle.md:384, 414 and 428-449 and session-title-metadata.md:22, 92 and 104 still define {sessionId, expectedRevision, title} with conflict, and resource-faces.md:793 and resource-owner-operations.md:57 still route readMetadata and setTitle with revisions. No requirement in the four docs covers the caller.
  • Failure scenario: SessionTitle's "manual title always wins" rule and its retry path have no target; the caller cannot migrate without a second title contract.
  • Fix: add the SessionTitle and title-metadata migration to the requirements or state how the callback replaces the conflict rule, and update those docs in the series.

P3: cancellation arguments contradict the tables

  • ManagedWorktrees.md:71 says discard is "Not cancellable", but the appendix takes CancelledFn (224) and the caller example passes CancellationToken::new() (45). SessionFiles.md:275 says "only the operations that wait take CancelledFn", but the appendix gives it to remove, register and owned_paths (237-271), whose table entries say None (72-75), and the register example passes a token (43). Fix: remove the argument or state what it stops, and use one token type in the examples.

P3: binding appendices use undefined request and reply types

  • SessionStore.md uses Create, DeleteReply, Fork, SetTitle and TitleReply without defining them; SessionFiles.md uses Put, Import, WriteFile, ReadFile, RemoveFile, Register, Owns, Owned, OfSession and Paths; ManagedWorktrees.md uses Removed, which is defined only in SessionStore.md; SqliteStorage.md uses Empty. Fix: define the types or point to the shared types, as the template requires.

P3: broken relative link

  • SessionFiles.md:62 links FileStorage.md, which is absent from docs/design/plugins in this tree; the file is added by PR #2080. The link resolves only if #2080 merges first. Use the PR URL, as line 153 does, or add the file before merging.

P3: SessionFiles write and remove name no caller and contradict the current file contract

  • SessionFiles.md:29 and 33 add operations whose requirement rows name no caller; session-files.md:443 says "SessionStore offers no operation that changes, renames or removes one file". The delivery comment names MCP for write, read and remove, but the design doc does not. Fix: name the caller in the rows and update session-files.md, or drop the operations.

P3: SqliteStorage restore does not take the lease it claims

  • SqliteStorage.md:15, 82 and 88 say backup, restore and vacuum take the same lease; restore_store takes no lease and requires a non-existent destination (crates/dim-app-server/src/storage/backup.rs:135-138 and 241-250). Fix: say the destination non-existence is restore's exclusion, or add the lease.

P3: flows name closed but error tables omit it in three docs

  • SqliteStorage.md:81 says pending storageReport calls end closed but line 59 lists only storage; ManagedWorktrees.md:100-101 say pending list and pruneSelection calls end closed but 72-73 omit it; SessionFiles.md:101 says pending owns calls end closed but 74 omits it. Fix: add closed or state that the generation's cancellation is the answer.

P3: a failed creation can leave an orphan branch after a reload

  • ManagedWorktrees.md:99 has discard delete the branch, 108 has remove keep it, and 76 makes discard answer unknown_preparation after a reload; a process death between create and store.create (104) then leaves the branch with no operation to delete it. Fix: state the retention, or let remove delete a branch whose worktree was never adopted.

Verification

  • Head b5606d1. PR open, not draft, mergeable. Checks: changes and ci-ok success; the docs-only jobs are skipped. Diff size 4 files, +1060/-0, base 1bc7d67.
  • LC_ALL=en_US.UTF-8 node scripts/adr-check.mjs --base 1bc7d67d7e3b357a64fd82c2589f57e4cb4b4bec passed: "ADR freeze passed: 4 changed files".
  • Relative-link check over the four files found one missing target, docs/design/plugins/FileStorage.md, from SessionFiles.md:62.
  • No full build or tests, because the diff is docs-only. No workspace changes. All cited code lines were checked at head b5606d1. Every inline anchor is inside the single @@ -0,0 +1,N @@ hunk of its new file.

Residual risks: the binding compile issues are reasoned from the rutis 0.23 #[rutis::service] rules and the current code, not from a build of the target shape. The cross-PR texts (#2080, #2093, #2094, #2096, #2098) were read from their PRs, not merged main.

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

### Dependencies

The engine's crate-private operations for every row read and write and for the Timeline batches; `sqliteStorage` is not a service face. The file owner `sessionFiles` for the Session file steps a delete releases. Neither dependency crosses back into SessionStore. The assembly provides both; deployment chooses the instance.

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.

sqliteStorage is a service face: this same PR marks the capacity read on the SqliteStorage type under that name (SqliteStorage.md:119 and 160-169). The sentence should say the engine's row and transaction operations are not on the face, not that the face does not exist. Otherwise the two contracts disagree about whether storageReport is callable at all. Fix: "the engine's row and transaction operations are crate-private and are not a service face; sqliteStorage carries only storageReport".

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 b4bb7f8. SessionStore.md:99 now says the engine's public face is the capacity read and its row and transaction operations are crate-private, matching SqliteStorage.md:14 and 132.

Comment thread docs/design/plugins/SessionStore.md Outdated
| Operation | Intent | Request | Reply | Cancellation | Errors |
| --- | --- | --- | --- | --- | --- |
| `create` | Write one admitted Session and its optional worktree association | `{id, config, agentId, protocolVersion, leader?, origin, worktree?}` | `{}` | Before the transaction starts; a dropped future does not undo a commit | `invalid`, `workspace_missing`, `storage` |
| `delete` | Remove a closed Session's output, visible rows and Timeline rows | `{id}` | `{hadRows}` | Before the first step; after the first commit the steps run to their end | `storage` |

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.

delete rejects an id that is not one path component (delete_session calls check_session_id, crates/dim-app-server/src/storage/timeline.rs:1551-1554; resource-faces.md:754-755), but this row lists only storage while the errors table defines invalid for exactly that case (line 134). A caller sends a/b, gets storage, and retries instead of fixing the id. Add invalid to delete. The flow also says new calls are refused closed (147), so add that 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 b4bb7f8. delete lists invalid and closed (SessionStore.md:108), and every flow that names closed has it in the error list (107-126).

Comment thread docs/design/plugins/SessionStore.md Outdated
| `removeGrant` | Remove one grant; an absent grant counts as removed | `{id, path}` | `{}` | None | `storage` |
| `setLanguage` | Write the reply language into the stored configuration | `{id, language?}` | `{}` | None | `not_found`, `invalid`, `storage` |
| `title` | The title, its source and its committed revision | `{id}` | `{revision, title?: {text, source}}` | None | `not_found`, `storage` |
| `setTitle` | Commit the title the caller's change returns and announce it; the owner serializes writes | `{id}` + `change` | `{revision}` | The reply may be dropped; the admitted write is not cancelled | `not_found`, `rejected`, `storage` |

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 dropped-reply guarantee cannot hold with the async fn set_title shown at 351-359: an async fn future is not admitted until its first poll, so dropping it before polling never starts the write. The current set_title is a plain fn that spawns the write before returning the wait future (crates/dim-app-server/src/storage/metadata.rs:201-224 and 342-350), which is what makes "a dropped reply still commits" true. Make the binding a plain fn returning impl Future, or weaken the flow and the verification at line 172.

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. The Rust signature is now a plain fn returning a future (SessionStore.md:411), so a native caller that drops it is covered. For a marked service, rutis 0.23 treats an impl Future return as awaited and puts the call inside the reply future, so the wire path still admits on first poll. The current hand-written invoke does it eagerly (crates/dim-app-server/src/storage/metadata.rs:366-380); see the new inline on line 411.

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

| Operation | Normal path | Caller cancels | Caller unloads | Owner closes or reloads | Settled by |
| --- | --- | --- | --- | --- | --- |
| `create` | Validate the id and the workspace, take the exclusion, write the rows, the owner row, the main branch, the catalog row and the association, commit | Before the transaction: nothing written. During: the transaction completes or fails; the reply may be lost | The transaction still completes; the caller keeps the id it supplied and decides whether to publish or delete the Session | New calls are refused `closed`; admitted work ends before the writer closes | Rows by SessionStore; the workspace by the caller |

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 order puts the workspace check before the exclusion, which reopens the race the exclusion exists to close: removeWorktree can remove the root after this check and before the transaction, and create then writes the association to the missing root and commits a Session whose cwd is gone. The current code takes ownership first and checks config.cwd under it (crates/dim-app-server/src/storage/timeline.rs:1628-1636), and line 169 promises the removal case fails on the missing workspace. State "validate the id, take the exclusion, validate the workspace, write ...".

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 b4bb7f8. The create flow is now "Validate the id, take the exclusion, validate the workspace, write ..." (SessionStore.md:149), matching crates/dim-app-server/src/storage/timeline.rs:1628-1636.

| `create` | Validate the id and the workspace, take the exclusion, write the rows, the owner row, the main branch, the catalog row and the association, commit | Before the transaction: nothing written. During: the transaction completes or fails; the reply may be lost | The transaction still completes; the caller keeps the id it supplied and decides whether to publish or delete the Session | New calls are refused `closed`; admitted work ends before the writer closes | Rows by SessionStore; the workspace by the caller |
| `delete` | Take the exclusion, read whether rows exist, remove output, touch worktree use, remove visible and Timeline rows, schedule the file sweep | Before the first commit: every row stays. After: the steps run to their end | The work continues under the owner's task; the reply may be lost | The admitted delete ends before close | Output and rows by SessionStore; files by SessionFiles |
| `fork` | Take the exclusion, read the source text, call `text`, copy in bounded transactions with the returned text, write the target row, commit | Before the first copy; a refused text step copies nothing | The copy continues; the reply may be lost | The admitted fork ends before close | Rows by SessionStore |
| `title`, `creationRecord`, `owner`, `hasRecords`, `sessionConfig`, `grants` | One read; no lock | Before the read | Nothing to release | Pending reads end `closed` | SessionStore |

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 flow says pending reads end closed, but none of these operations lists closed in its errors column (lines 111-120). A title or sessionConfig call during a generation close would be reported as storage, and the caller would retry the same closing generation instead of the replacement. Add closed to each read's error list. The same omission exists for create and removeWorktree, whose flows also say new calls are refused closed (147, 154).

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 b4bb7f8. closed is listed on every read and write row that names it (SessionStore.md:107-126), and catalog/query distinguish cancelled from closed at 153.

Comment thread docs/design/plugins/SessionFiles.md Outdated
| `import` | Copy a regular host file into the Session namespace and commit ownership | `{sessionId, name, source}` | `{fileId, size}` | Before the replacement; a cancelled import leaves no owned row | `invalid`, `too_large`, `not_found`, `node_unavailable`, `cancelled`, `closed`, `storage` |
| `write` | Replace one Session file's bytes under the same id and path | `{sessionId, fileId, bytes}` | `{fileId, path, size}` | Before the replacement; the old bytes stay | `invalid`, `too_large`, `not_found`, `node_unavailable`, `cancelled`, `closed`, `storage` |
| `read` | Read one Session file whole, within the owner's limit | `{sessionId, fileId}` | `{bytes}` | While the file is read; nothing changes | `not_found`, `node_unavailable`, `cancelled`, `closed`, `storage` |
| `remove` | Remove one Session file and its ownership row; a file the Session does not own answers success | `{sessionId, fileId}` | `{}` | None; the owner completes the removal | `not_found`, `node_unavailable`, `storage` |

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 row says a file the Session does not own answers success and line 120 verifies it, while line 85 defines not_found as "The Session has no such file". The operation cannot be both idempotent and report a missing file; a caller cannot tell whether to retry. Define not_found only for a missing Session, or drop it for remove and state the foreign-file result.

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 b4bb7f8. remove lists only storage and says an absent or foreign file answers success (SessionFiles.md:76, 101 and 135), so it is idempotent. One residual: remove omits node_unavailable, covered by the new inline on line 76.

Comment thread docs/design/plugins/SessionFiles.md Outdated
| `owns` | Whether a path or file id belongs to the Session | `{sessionId, path}` | `{owned}` | While the path is resolved | `node_unavailable`, `cancelled`, `storage` |
| `ownedPaths` | Every path the Session owns | `{sessionId}` | `{paths}` | None | `node_unavailable`, `storage` |

`bytes` is the file content as data; the owner's limit is 16 MiB. `read` answers the whole file within that limit: the limit is the owner's, so callers do not page. A `fileId` outside the Session, or a name that is not one component, is `invalid`.

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 removes the offset page that the existing callers use: attachment.read {sessionId,fileId,offset} returns at most 64 KiB (docs/design/plugins/Attachments.md:148-149; crates/dim-agent-attachments/src/lib.rs:169-178), the HTTP download streams by offset (crates/dim-app-server/src/web_entry/uploads.rs:234,257), and image materialization pages by offset (crates/dim-agent-capabilities/src/session_files.rs:23-41). The claim "every caller needs the whole file" is false, and the stated page-id lifetime does not exist in the stateless offset read. Keep offset and the 64 KiB chunk, or update those callers and state the 16 MiB memory and single-reply cost. The same paragraph also calls a foreign file id invalid while line 121 returns not_found; pick one.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fixed in b4bb7f8. read takes {sessionId, fileId, offset}, returns {data, eof} with the 64 KiB bound and pages at the offset (SessionFiles.md:30, 49-51, 73, 79 and 112), matching crates/dim-app-server/src/storage/files.rs:620 and Attachments.md:148-149.

Comment thread docs/design/plugins/ManagedWorktrees.md Outdated
| Operation | Intent | Request | Reply | Cancellation | Errors |
| --- | --- | --- | --- | --- | --- |
| `create` | Allocate a task id and make a Git worktree and branch for a Session creation | `{source, base?, branch?}` | `{taskId, repository, root, subtree, branch, base}` | Between Git calls and before the branch is created; a cancelled creation removes its empty task directory | `unavailable`, `invalid`, `branch_exists`, `git`, `interrupted` |
| `discard` | Settle a created worktree that the Session creation did not adopt | `{taskId}` | `{}` | Not cancellable: the cleanup runs to its end | `unknown_preparation`, `in_use`, `git` |

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.

discard is "Not cancellable" here, but the appendix takes CancelledFn (224) and the caller example passes CancellationToken::new() (45), a different token type. Section 7.2 says every parameter is complexity, so a no-op cancellation argument is a defect. Remove the argument or state what it stops, and make the example use the binding's CancelledFn.

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 b4bb7f8. discard takes no CancelledFn and is stated not cancellable (ManagedWorktrees.md:71 and 238-244), and the caller example passes no token (45).

- **Offline operations.** Backup, restore and vacuum, each holding the same lease and refusing while a daemon owns the store.
- **The capacity value.** Database bytes, WAL bytes and reclaimable bytes, read through `storageReport`.

The rows belong to their data owners, and their operations live on those owners' faces: the Session rows and the Timeline batches to [SessionStore](SessionStore.md), the Agent records to Agents and Collaboration ([#2098](https://github.com/arcships/dim/pull/2098)), the Settings documents to Settings ([#2094](https://github.com/arcships/dim/pull/2094)), the Provider records to Provider ([#2096](https://github.com/arcships/dim/pull/2096)). The engine executes each owner's transactions and returns the stored form; it answers no business read or write on its public face and is not in the catalog for those rows.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This moves the Settings, Provider, Agent and Timeline transactions off the sqliteStorage face, but resource-owner-operations.md:41, 47, 57 and 59 and service-faces.md:128 still say those owners call the public face, and SessionStore.md:99 says the face does not exist. The four new docs need one target: either update those contracts and raise the requirements, or keep the face. The same tension appears at line 32 and in the rule check at 119-120.

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 b4bb7f8 for the face tables. service-faces sections 3.3 and 3.4, resource-faces section 5 and SqliteStorage.md:14-18 now agree that storageReport is the public face and the owner rows are crate-private. Residual P3: resource-owner-operations.md:12 still says store.readMetadata/setTitle.

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

### Dependencies

`fsHost` for the owner's directory, file creation, atomic replacement, import, listing and removal; the operations used are the ones in [FileStorage's contract](FileStorage.md). The engine's file-ownership rows are private to the storage crate and are not a service. The owner does not depend on `store`: the store depends on this owner when a delete releases files.

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 relative link is broken in this tree: docs/design/plugins/FileStorage.md is absent and is added by PR #2080 (the text at line 153 already links the PR). The link resolves only if #2080 merges first. Use the PR URL, or add the file before this merges.

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 b4bb7f8. The link now points at the FileStorage PR (SessionFiles.md:64 and 167), so it resolves before #2080 merges.

@eric8810

Copy link
Copy Markdown
Collaborator Author

已按评审修改,head b4bb7f8a3。

  1. create 顺序。 改为「校验 id → 取排他 → 校验 workspace → 写行」;验收与流程一致。
  2. 错误表补齐。 每个流程里出现的 closed 都进了操作错误表(SessionStore 的创建、删除、读、写、removeWorktree,SessionFiles 的 owns,ManagedWorktrees 的 list/pruneSelection,SqliteStorage 的 storageReport);delete 补 invalid;catalog/query 补 closed。
  3. SessionFiles 的读与导入。 read 保留 offset 与 64 KiB 页、回复 {data, eof},不引入读 id;put、import、write 回复 {fileId, path, bytes};remove 对不存在或别的 Session 的文件返回成功,错误只剩 storage;register 不再校验输出根,根由 WorkspaceTools / HostPlatform 的调用方决定。客户端可见面因此不变(见契约的 Client-visible changes)。
  4. write/remove 的调用方。 在 SessionFiles 的职责表与 Exceptions 里点名 MCP 的结果文件;session-files.md §9.1 改为指向契约,删掉「不提供改、删单个文件」的旧句。
  5. store/timelineStore/sqliteStorage 的边界。 按 C 修改 resource-faces.md(§4.6、§5、§5.1 生命周期步骤、§5.2 改为指针、§9(6))、service-faces.md(sessionFiles、worktreeAssociations、sessionStore、sqliteStorage、timelineStore 行)、resource-owner-operations.md(Persistent Agents 与 Native storage 改为指针,保留 credential 小节)。四份契约新增 Supersedes 小节;sqliteStorage 公开面只剩 storageReport 与离线操作。
  6. setTitle 的交接。 绑定改成普通 fn:先接纳写、启动所有者任务,再返回等待的 future;丢弃 future 不撤销已接纳的写。
  7. 绑定附录。 错误类型改为 {code, message} 的 serde 结构,代码即错误表的 kind;回调错误类型加 From<rutis::host::CallError>,保留回调自己的 code 与 message;Rejected 在 SessionStore 与 SessionFiles 分别改名 StoreRejected/FileRejected,Create/Discard/Remove/Prune/Created 等按所有者改名;所有附录用到的 request/reply 类型已定义。
  8. 取消与类型。 discard、register、owned_paths、remove 不再带取消参数;示例统一用 CancelledFn。
  9. restore 的排他。 改为「目标不存在」是其排他规则,不再声称取租约;backup 与 vacuum 取租约。
  10. 遗留分支。 在 ManagedWorktrees 的 Exceptions 写明:未采用的创建或提前结束的 discard 留下的分支保留,remove 只删目录,操作者用 Git 删分支。
  11. 链接与索引。 FileStorage.md 用 design(fileStorage): target contract #2080 的 PR URL;README 增加四行 owner contract 并更新 By scope。
  12. title 的迁移。 在 SessionStore 的 Requirements 增加 所有者扫描:产品功能插件(goal、session-title、web、Code Mode) #2033;session-title-metadata.md 与 SessionTitle.md 中描述本所有者写标题的段落改为 change 回调形状。

两个检查通过。请 @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.

Scope: this PR defines target contracts for the session storage owners (SessionStore, SessionFiles, ManagedWorktrees, SqliteStorage) under section 7 of the principles, refs #2018 and #2015. I reviewed the full main...head tree at b4bb7f8a and the delta since b5606d10 against the storage code, the sibling contracts and section 7 of #2029.

Verdict: REQUEST_CHANGES. Most round-1 findings are fixed, but three round-1 P2s remain partially fixed: the setTitle handover for wire callers, the title interface migration, and the Timeline face wording in resource-faces.

Round-1 status

Fixed: create order; SessionStore error lists; SessionFiles offset paging, import reply and register root; remove idempotence; binding error types and the callback From<CallError> impls; and the P3s (cancellation arguments, undefined types, FileStorage link, MCP callers, restore destination rule, closed in the error tables, leftover branch).

Partially fixed: the store/timelineStore/sqliteStorage boundary (the tables and owner docs are updated; resource-faces section 5.1 is not), the title callback migration (the new docs are updated; SessionTitle and the title metadata doc are not), and the setTitle drop guarantee (the Rust signature is fixed; the wire path is not).

Findings

P2: setTitle still cannot guarantee the handover for wire callers

  • Problem: SessionStore.md:411-418 declares set_title as a plain fn returning impl Future inside #[rutis::service], and lines 121, 155 and 186 say a dropped reply still commits. In rutis 0.23 a method whose return type is impl Future is treated as awaited, and the macro places the call inside the reply future (Answer::Later), so set_title runs on the first poll of the reply, not when the host receives the call. The current hand-written dispatch calls it eagerly in invoke (crates/dim-app-server/src/storage/metadata.rs:366-380), which is what makes the claim true today; the appendix replaces that adapter with the marked service. session-title-metadata.md:153 still says the named service calls it inside invoke.
  • Failure scenario: a foreign caller sends setTitle and abandons the reply before its future is polled; the write is never admitted, so the title is not committed or announced. The flow at 155 and the verification at 186 fail.
  • Fix: keep the hand-written method registration for setTitle (its invoke calls the plain fn, then returns the wait), or state that a wire call dropped before the reply is polled does not admit the write and change the flow and verification.

P2: the title migration leaves two contracts and two request fields

  • Problem: the new requirement (SessionStore.md:219) says the revision-checked shape is superseded, but the siblings still define it. SessionTitle.md:385 still declares sessionMetadata.read, 413 keeps revision r, 430 and 450 keep conflict, and 517-519 keep set_title(session_id, expected_revision, title) with Conflict. session-title-metadata.md:132, 171, 207, 224, 333, 374 and 404 still show revision != r, conflict and the expected-revision write. They also use request {sessionId} (session-title-metadata.md:92-93, SessionTitle.md:384), while the owner table and appendix use {id} (SessionStore.md:120-121 and SetTitle at 297-299 with deny_unknown_fields). The close code also differs: the owner lists closed, while the metadata table folds it into storage.
  • Failure scenario: a caller following SessionTitle or the metadata doc sends {sessionId, expectedRevision, title}; the owner's SetTitle has only id, so the call is a malformed request. A call during close cannot distinguish closed from storage. The document set gives two title contracts.
  • Fix: in this series, update SessionTitle.md and session-title-metadata.md to store.title and store.setTitle(id, change), remove the conflict and expected-revision rows and the Appendix G shape, use id, and align the close code.

P2: resource-faces still defines the Timeline operations the target removed

  • Problem: resource-faces.md:610 and 672 say createSession, releaseSession, rollbackSession and append are not operations of the timelineStore face, but section 5.1 still calls append "the one face operation a caller may issue inside its own commit lock" (633-650) and describes releaseSession and rollbackSession replies and the remote-consumer rule for append (645-650, 684-705).
  • Failure scenario: an implementer following section 5.1 keeps append on the face, or exposes it to remote consumers, which the SessionStore contract and service-faces now forbid. The same document gives two answers.
  • Fix: rewrite section 5.1 as the owner's internal admission and drain steps, or state in place that the face no longer carries them.

P3: remove omits the node failure and write lists an unused code

  • Problem: SessionFiles.md:76 lists only storage for remove, while the removal goes through FileStorage on the Session's resource node, the condition put, read and owns report as node_unavailable (70, 73, 75, 88). write lists invalid (72), but line 79 and the error table define no invalid case for a write.
  • Failure scenario: a caller that should retry later gets storage and reports failure; a caller cannot tell what invalid means for write.
  • Fix: add node_unavailable to remove, and define or drop invalid for write.

P3: discard cannot always run to its end

  • Problem: ManagedWorktrees.md:71 and 99 compose store.removeWorktree, whose errors include closed, storage and rejected (SessionStore.md:126), but discard lists only unknown_preparation, in_use and git and says its cleanup is not cancellable (109).
  • Failure scenario: a failed creation during store close calls discard; the store refuses closed, the worktree and branch stay, and discard has no error to report.
  • Fix: map the store refusals and state the retention, or weaken the non-cancellable claim.

P3: the leftover-branch recovery needs a caller to run Git

  • Problem: ManagedWorktrees.md:111 leaves a branch from a never-adopted creation and says the operator deletes it with Git, while the same contract's rule check at 145 says no caller invokes Git or reads the root and the operations own the branch.
  • Failure scenario: a process death between create and store.create leaves a branch with no operation to delete it, so the documented recovery requires an action the contract forbids.
  • Fix: let remove delete the branch whose worktree was never adopted, or state the operator CLI step explicitly outside the caller contract.

P3: backup does not report the format code, and the lease bullet covers restore

  • Problem: SqliteStorage.md:61 lists owned and storage for backup, but backup_store validates the current schema (crates/dim-app-server/src/storage/backup.rs:183; validate_backup_schema at crates/dim-app-server/src/storage/sqlite.rs:2364-2369), and line 90 says the format gate applies to every offline tool. A wrong-format store fails as storage, while the error table defines format for exactly that. The ownership bullet at line 11 also says an offline tool takes the same lock, while restore does not (15, 84).
  • Failure scenario: a backup of an older store reports a generic failure instead of the format code, so the caller does not run the documented upgrade path; a reader expects restore to take the lease.
  • Fix: add format to backup and map the schema refusal, and qualify the lock bullet.

P3: stale pointers and one stale table row

  • Problem: SessionStore.md:5 points to resource-faces section 5.2, which this commit replaced with a supersede paragraph (709-712); SqliteStorage.md:5 points to resource-owner-operations, whose Native storage section is now one paragraph (resource-owner-operations.md:32). resource-owner-operations.md:12 still says store.readMetadata/setTitle and points file reads at the superseded session-files interface, while line 32 supersedes it.
  • Failure scenario: a reader follows the current-implementation pointer or the table row to a retired operation.
  • Fix: update the pointers and the row, or mark the row superseded.

Verification

  • Head b4bb7f8a3f2aed61a0c37ca6a9e15a00c40c6d1c, base 1bc7d67d7e3b357a64fd82c2589f57e4cb4b4bec. PR open, not draft, mergeable. Delta since b5606d10: 12 files, +439/-469.
  • node scripts/adr-check.mjs --base 1bc7d67d7e3b357a64fd82c2589f57e4cb4b4bec passed with 12 changed files. A link and anchor scan over the 12 changed files found no broken target.
  • CI: changes and ci-ok pass; the docs-only jobs are skipped.
  • Code checks: create order (crates/dim-app-server/src/storage/timeline.rs:1628-1636), eager setTitle admission in the current hand-written invoke (crates/dim-app-server/src/storage/metadata.rs:366-380), restore destination rule (crates/dim-app-server/src/storage/backup.rs:243-250), file page size (crates/dim-app-server/src/storage/files.rs:620), caller-side register root (crates/dim-agent-capabilities/src/host.rs:1526-1527).
  • The rutis 0.23 macro behavior for an impl Future return is from the published macro source; the wire-code derivation for the new {code, message} structs and the target appendix shapes were not built, because the diff is docs-only.
  • Cross-PR: #2094 Settings and #2093 SessionScope align with this split. #2098, #2100 and #2103 still carry the previous service-faces and resource-owner-operations rows at their heads, so they will need the same rebase; #2103's Attachments contract gives attachment.read errors without node_unavailable or cancelled, which SessionFiles.read can return.
  • Residual risk: no build or test of the target binding appendix.

Comment thread docs/design/plugins/SessionStore.md Outdated
}

/// Admits the write under the owner's serialization and returns the wait future; dropping it never cancels the admitted write.
pub fn set_title(

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 marked service does not admit the write at this line. In rutis 0.23 a method returning impl Future is awaited, and the macro puts the call inside the reply future (Answer::Later), so set_title runs on the first poll of the reply, not when the host receives the call. The current hand-written dispatch calls it eagerly in invoke (crates/dim-app-server/src/storage/metadata.rs:366-380), which is what makes line 186 true today. Keep that eager call for the wire path, for example with the hand-written method registration, or change lines 121, 155 and 186 to say that a wire call dropped before the reply is polled does not admit the write.

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. Moving set_title out of the marked block is the right direction, but the appendix still does not define the hand-written store table it relies on: the only one today is the storage::Store wrapper at crates/dim-app-server/src/storage/face.rs:290-303, which lines 212 and 228 delete. A marked service dispatches only its marked methods, and a second provider for store is refused. State which dispatcher serves setTitle and how its invoke admits the write before returning, or keep the whole face on the hand-written table. The new inline at 408 covers this.

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 9c81829. The hand-written invoke now calls set_title eagerly before returning the wait (SessionStore.md:419-422 and 463-486), so the wire handover is defined. SessionStore.md:228 and resource-faces.md:700 still advertise the marked service, which is the remaining contradiction.

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 9ff2b07. The hand-written table now serves the whole store face, including setTitle, and SessionStore.md:213 and :229 plus resource-faces.md:700 no longer advertise a marked service.

| --- | --- | --- | --- | --- |
| `read` | async | `{sessionId}` | `{revision, title: {text, source} \| null}` | `not_found`, `storage` |
| `setTitle` | async | `{sessionId, expectedRevision, title: {text, source: "auto" \| "manual"} \| null}` | `{revision}`: the committed revision | `conflict`, `not_found`, `storage` |
| `title` | async | `{sessionId}` | `{revision, title: {text, source} \| null}` | `not_found`, `storage` |

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 owner contract uses {id} for title and setTitle (SessionStore.md:120-121 and SetTitle at 297-299 with deny_unknown_fields), but this table and SessionTitle.md:384 use {sessionId}. A caller following this doc sends a field the owner does not accept, so the request is malformed. The doc also leaves the old interface in place: 132, 207, 224, 374 and 404 still show conflict and set_title(expected_revision, ...), and SessionTitle.md:385, 413, 430 and 517-519 still declare sessionMetadata and the expected-revision write. Finish the migration in this series and use one field name.

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. session-title-metadata.md:92-93 now uses {id} and the change callback, but SessionTitle.md:386 and :416 still send {sessionId} to the owner's {id} with deny_unknown_fields, and Appendix G at :508 and :516 still uses SessionMetadataService::read. Section 6 at :153/:156 and acceptance 12 at :352 still say a call after close fails storage while section 4.1 and section 8 now say closed. These remain in the body and the inline at SessionTitle.md:386.

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 9c81829. session-title-metadata.md:92-93 and SessionTitle A.2 and A.4 now use {id} and the change callback. The old interface remains in SessionTitle 226, 291 and 332 and in session-title-metadata.md's read references at 112, 216-217, 265, 286, 333 and 338. Finish the sweep.

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 9ff2b07 except one sentence: session-title-metadata.md:311 still says SessionStore decides through its revision check. The listed read names and the SessionTitle rows now use title and the change callback.

Comment thread docs/design/resource-faces.md Outdated
workflow. `releaseSession` drains accepted backend writes and releases their resources without
closing the Agent Session or its admission. App Server creation/deletion retain the repository
and lifecycle obligations in §5.2.
`createSession`, `releaseSession`, `rollbackSession` and `append` are the store's own creation and

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 paragraph says the four operations are not on the face, but section 5.1 still defines append as the one face operation allowed inside a commit lock and describes releaseSession and rollbackSession replies (633-650 and 684-705). The doc now gives two answers. Rewrite 5.1 as the owner's internal admission and drain steps, or state in place that the face no longer carries them.

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. Section 5.1 is rewritten at resource-faces.md:622-626, but the rule check at :740 still calls timelineStore.append the one face operation allowed inside the caller's commit lock and :742 still says append admits one atomic batch. Update those two rows or label them as the current implementation superseded by section 5.1. The inline at 624 covers this.

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 9c81829. resource-faces.md:740 and 742 are rewritten to the store's internal admission; §5.1 and the rule check now agree.

Comment thread docs/design/plugins/SessionFiles.md Outdated
| `read` | One page of a Session file, at most 64 KiB | `{sessionId, fileId, offset}` | `{data, eof}`, `data` is base64 and `eof` is true exactly when it is empty | While the page is read; nothing changes | `not_found`, `node_unavailable`, `cancelled`, `closed`, `storage` |
| `register` | Record a caller-owned output path for the Session | `{sessionId, path}` | `{}` | None | `invalid`, `not_found`, `storage` |
| `owns` | Whether a path or file id belongs to the Session | `{sessionId, path}` | `{owned}` | While the path is resolved | `node_unavailable`, `cancelled`, `closed`, `storage` |
| `remove` | Remove one Session file and its ownership row; an absent or foreign file answers success | `{sessionId, fileId}` | `{}` | None; the owner completes the removal | `storage` |

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.

remove lists only storage, but removal goes through FileStorage on the Session's resource node, the condition put, read and owns report as node_unavailable (70, 73, 75, 88). A caller that should retry later gets storage and reports failure. Add node_unavailable here. The same table lists invalid for write (72) with no rule in line 79 or the error table that produces it for a write; define the trigger or drop 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.

Fixed in 0aec7ae. write no longer lists invalid (SessionFiles.md:72) and remove lists node_unavailable (:76).

Comment thread docs/design/plugins/ManagedWorktrees.md Outdated
| Operation | Intent | Request | Reply | Cancellation | Errors |
| --- | --- | --- | --- | --- | --- |
| `create` | Allocate a task id and make a Git worktree and branch for a Session creation | `{source, base?, branch?}` | `{taskId, repository, root, subtree, branch, base}` | Between Git calls and before the branch is created; a cancelled creation removes its empty task directory | `unavailable`, `invalid`, `branch_exists`, `git`, `interrupted` |
| `discard` | Settle a created worktree that the Session creation did not adopt | `{taskId}` | `{}` | Not cancellable: the cleanup runs to its end | `unknown_preparation`, `in_use`, `git` |

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.

discard is not cancellable, but it composes store.removeWorktree (99), whose errors include closed, storage and rejected (SessionStore.md:126). This row has no such codes, so a store refusal during unload leaves the worktree and branch with no defined answer and the promise at 109 does not hold. Map the store refusals and state the retention, or weaken the 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.

Fixed in 0aec7ae. discard lists closed and storage (ManagedWorktrees.md:71) and the exception at :110 says a store refusal leaves the directory and branch in place. The new retry sentence in that same line contradicts the preparation table at :76 and :100; that is a separate P2 in the body and the inline at 110.

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 9c81829. ManagedWorktrees.md:71 lists closed and storage, and line 110 now says a store refusal leaves the directory and branch in place; the preparation-drop sentence is fixed 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 for closed and storage in 9ff2b07. A related gap remains: store.removeWorktree and store.removeUnregisteredDirectory can answer rejected or invalid, and discard and remove do not map those codes. Covered in the new body.

Comment thread docs/design/plugins/ManagedWorktrees.md Outdated
- A branch is kept when `remove` deletes a worktree: committed content must not disappear with the directory.
- `discard` is not cancellable: a cancelled Session creation still has to settle what the owner made.
- Unregistered directories are never pruned: the owner has no record to age, so only an explicit `remove` by task id deletes them.
- A branch outlives a creation that was never adopted: a process death between `create` and `store.create`, or a `discard` that ended before the branch deletion, leaves the branch. `remove` on an unregistered directory deletes the directory only; the operator deletes the leftover branch with Git, and `list` names the task id the branch was made for.

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 leaves a branch with no operation to delete it and hands the cleanup to the operator through Git, but the rule check at 145 says no caller invokes Git or reads the root. Either let remove delete a branch whose worktree was never adopted, or state the operator CLI step explicitly outside the caller contract.

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 0aec7ae. remove on an unregistered directory deletes the default dim/<taskId> branch of a never-adopted worktree and retains an explicit branch (ManagedWorktrees.md:112), so no Git step is handed to the caller.

Comment thread docs/design/plugins/SqliteStorage.md Outdated
| Operation | Intent | Request | Reply | Cancellation | Errors |
| --- | --- | --- | --- | --- | --- |
| `storageReport` | The store's own file bytes, WAL bytes and reclaimable bytes | `{}` | `{databaseBytes, walBytes, reclaimableBytes}` | None | `closed`, `storage` |
| `backup` | Copy a closed store and its sidecar files into an archive | the database path and the destination | `{}` | None; the tool runs alone | `owned`, `storage` |

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.

backup lists owned and storage, but backup_store validates the current native schema (crates/dim-app-server/src/storage/backup.rs:183 and validate_backup_schema at crates/dim-app-server/src/storage/sqlite.rs:2364-2369), and line 90 says the format gate covers every offline tool. A wrong-format store fails as storage instead of format. Add format and map the schema refusal, or change line 90. The ownership bullet at line 11 also says an offline tool takes the same lock, while restore does not (15, 84).

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 0aec7ae. backup lists format (SqliteStorage.md:61), and the lease sentence now limits the shared lease to backup, migration and vacuum (:90); restore keeps the destination rule.

Discovery and credential admission run in Provider before the conditional write. SQLite executes
the existing mutation, including its index updates, in one transaction. Provider constructs the
existing business reply. `importLegacy` remains its existing separate bulk transaction.
Superseded by the owner contracts. The Agent records belong to [Agents and Collaboration](https://github.com/arcships/dim/pull/2098), the Settings document operations to [Settings](https://github.com/arcships/dim/pull/2094), the Provider record operations to [Provider](https://github.com/arcships/dim/pull/2096), and the Session repository operations to [SessionStore](../plugins/SessionStore.md). The engine's public face is the capacity read and the offline operations ([SqliteStorage](../plugins/SqliteStorage.md)); its transactions are the data owners' crate-private implementation, and no operation of those owners is published under `sqliteStorage`.

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 table at line 12 still says store.readMetadata/setTitle and points file reads at the superseded session-files interface, although this paragraph supersedes it. A reader following the row gets a retired method. Update the row to store.title and setTitle(id, change) and the SessionFiles contract.

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 0aec7ae. resource-owner-operations.md:12 now points at SessionStore and SessionFiles and keeps only the pointer. One residual: the Credential values section below the new supersede paragraph still advertises sqliteStorage.readRecord and the user methods; that is a separate P2 in the body.

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

Scope: process. Issue: #2018.

SessionStore owns the stored Session: its rows, its grants, its reply language, its title revision, its worktree records, the exclusion that keeps those records consistent with Session creation, and the Timeline storage engine those rows are read through. This document is the owner's target contract. The current implementation is described in [Session rows §5.2](../resource-faces.md#52-session-rows) and [Native storage format](../appserver/native-storage-format.md). The Session-scoped `timelineStore` face carries this owner's Timeline operations; SessionScope binds that face at the Session instance ([#2093](https://github.com/arcships/dim/pull/2093)).

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 pointer is stale: this commit replaced resource-faces section 5.2 with a supersede paragraph (resource-faces.md:709-712). Point at native-storage-format and the code, or say 5.2 is superseded. SqliteStorage.md:5 has the same problem with resource-owner-operations, whose Native storage section is now one paragraph at line 32.

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 0aec7ae. SessionStore.md:5 now points at native storage format, and SqliteStorage.md:5 does the same.

eric8810 added a commit that referenced this pull request Nov 24, 2026
Goal keeps the trigger's sequence, names the state record's one writer, takes
cancellation on the line read, carries a submission id, states the ended-line
client change and the evaluator refusals, and uses GoalViewStatus. SessionTitle
follows #2091's ChangeFn binding and drops the broadcast row. Web declares
search for a configured adapter. Code Mode gates on the mount exclusion and its
examples compile. Compatibility anchors and the standing documents' owner
paragraphs point at the new contracts.

Refs #2033
@eric8810
eric8810 force-pushed the dim/2018-storage-contract branch from b4bb7f8 to 4011e4f Compare November 24, 2026 03:25
@eric8810

eric8810 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

已按评审修改,head c6d1dae4f(基于 main 5930539bc)。

台账

  • zerob13 6037325558 / 新文件结算:fixed。put/import 自己递归建父目录,调用方不再收到 missing_parent;新文件 unsynced 由所有者同步或重试,成功提交归属并返回 id,失败删字节、不发布归属;调用方只看到附件面的 attachment_invalid/attachment_too_large/node_unavailable/storage_failed。只有 write 把 unsynced 交给调用方;两种结局都在 flows。
  • zerob13 / 已登记根已消失的删除:fixed。removeWorktree 对已核验缺失的根走成功路径,记录在同一排他下注销,重试安全;not_found 只留给 removeUnregisteredDirectory。
  • yyhhyyyyyy 6037358592 / P2 1(示例多传 token):fixed。
  • yyhhyyyyyy / P2 2(ManagedWorktrees 未映射 store 拒绝):fixed,按 store 的 invalid/not_found/in_use/rejected reason/closed/storage 逐项映射到 worktree_*,discard 补 worktree_invalid。
  • yyhhyyyyyy / P3 1–3:fixed(releaseTimeline、兄弟 head/FileStorage 引用、EOF 空行)。
  • 上一轮跨 PR 补丁:fixed(unsynced/missing_parent 映射、Timeline face 实例身份校验、timelineStore 三向指针)。
  • 历轮 R1/R2 正文、第 1–5 轮 inline、预审 1/2:全部 fixed;not adopted 仍为保留公开 Store 与 revision 请求形状(§7/本 PR 决定)。
  • rebase 冲突:resource-owner-operations.md、resource-faces.md、worktree-management.md;保留 main 的新内容,弃用的段落以指针落地。

指针清单

与上一轮相同:resource-faces §5/§5.1/§5.2/§9(6)/§6 行/§1 行/§4.2;service-faces 五行/§4.5/§4.8/timelineStore 三向指针;resource-owner-operations credential;session-title-metadata §1/§4.1/§4.2/§5/§6/§10/Appendix A;SessionTitle 三行;session-files §9.1;worktree-management §5;worktree-access §4;typescript-plugin-authoring/plugin-contract/session-deletion-and-fork/overview;中文镜像。

最后一轮预审摘要(第二轮)

  • 无 P1。
  • P2(10 条)已全部处理:SessionFiles 新文件结算与 unsynced/missing_parent 映射、removeWorktree 已缺失根成功、示例 token、ManagedWorktrees store 拒绝映射、Timeline face 实例身份、timelineStore 三向指针、releaseTimeline、兄弟 head、EOF 空行、main 的删除登记模型进入契约。
  • rebase 后把 main 的删除/创建登记、记录清理操作与非 Unix 未登记删除规则写入 SessionStore/ManagedWorktrees 契约,指针段不丢 main 内容。

剩余 P2

无。

剩余 P3

  • worktrees/worktreeUsages/sessionsUnder 的回复类型仍只在操作表写字段,未在附录定义。
  • 中文 session-title-metadata.md 的结构/实现段仍用 sessionMetadata 旧名(接口段已为指针)。

检查

adr-check 通过;xtask-check 通过;git diff --check origin/main...HEAD 干净;27 个改动文件相对链接 0 断链;四份附录同一临时 crate(rutis 0.23 + serde)cargo check 通过。

请 @yyhhyyyyyy 复核。

@eric8810
eric8810 requested a review from yyhhyyyyyy November 24, 2026 09:53

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

Settle new-file creation inside SessionFiles when durability is uncertain. The new unsynced and missing_parent contract tells the caller to read and retry the same file or create its parent. That applies only to a replacement with a known file ID. A failed put or import may have placed bytes under a new ID the caller never receives, and the parent belongs to SessionFiles. Specify owner-side resync and commit or cleanup without publishing ownership; return the established attachment-facing errors where appropriate. This is creation settlement, not just an error-enum addition.

Also align SessionStore's removal with ManagedWorktrees' stale-record cleanup. Preserve the existing success path when the registered root is already gone so a retry can retire the record under the same exclusion. The earlier refusal-mapping discussion can stay where it is.

Hosted checks passed. They exercise the existing implementation, not these proposed flows.

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review: PR #2091, round 6, head 05284be

Scope: this PR defines the target contracts for the session storage owners (SessionStore, SessionFiles, ManagedWorktrees and SqliteStorage) and moves the title, Session file and worktree call sites onto them, refs #2018 and #2015. I reviewed the full main...head at 05284be against current main eacc672d and the storage code; the PR diff is 27 files, +1466/-734. Verdict: REQUEST_CHANGES.

Prior round

  • P2 1, the Session face carried the process store's reads: fixed and withdrawn. resource-faces.md §5 is now a pointer to the SessionStore contract (:604-618), service-faces.md:129 states the split, and SessionStore.md:18 keeps sessionConfig and query only on the process store.
  • P2 2, session-title-metadata still described a revision check: fixed and withdrawn. Line 3 states the interface has no expectedRevision, and §10 is now a pointer (session-title-metadata.md:3, :153-154).
  • P2 3, the fork requirement and flow disagreed on transactions: fixed and withdrawn. SessionStore.md:34 now reads the source body and decides the target text under the fork exclusion, and writes the target body and rows in the last batch transaction.
  • P2 4, ManagedWorktrees did not map the store's removal refusals: partly fixed. The owner error table now uses the published worktree_* codes (ManagedWorktrees.md:82-94), but the store's rejected reason and the discard row still have no complete mapping; see P2 2 below.
  • P2 5, the setTitle example passed a cancellation token the binding does not accept: fixed and withdrawn. The call is now store.setTitle(SetTitle { id }, change) (SessionStore.md:84).

P2 findings

P2 1. The removeWorktree example passes a cancellation token the binding does not accept

Problem: SessionStore.md:95 calls store.removeWorktree(Directory { repository, root }, remove, cancelled.clone()), but the binding at :514-519 takes only caller, request and remove; the token is already captured by the RemoveFn closure at :91-94. The operation table at :129 says the caller's step ends and the record stays; no store argument cancels the call.

Failure scenario: An implementer copies the example and gets a compile error. If the implementer instead adds a cancellation argument to the binding, the store can cancel after it has taken the Session exclusion, while the operation contract says the callback owns cancellation and the record stays. This is the same extra-token shape the round-5 setTitle finding identified, now in the removal example.

Evidence: docs/design/plugins/SessionStore.md:89-95, :129, :427-429, :514-519.

Fix: Remove the third argument and keep the token in the RemoveFn closure. If store-level cancellation is intended, add it to the binding and the operation contract together.

P2 2. ManagedWorktrees still does not map every store removal refusal

Problem: ManagedWorktrees.md:74 says a started removal reports worktree_git_failed, and the discard row at :71 lists neither worktree_not_found nor worktree_invalid. The store's removeWorktree and removeUnregisteredDirectory return invalid, not_found, in_use, rejected, closed and storage, and a callback refusal is rejected with the callback's reason (SessionStore.md:129-130, :180, :185). The new error table names the owner codes but does not say which store refusal maps to which code.

Failure scenario: A cancelled Git step returns rejected reason cancelled; the remove row says a started removal reports worktree_git_failed, and no sentence maps the refusal, so the CLI sees a Git failure instead of an interrupted removal. The discard row also omits worktree_invalid and worktree_not_found, which its removeWorktree call can answer, so the caller has no code for those outcomes. The caller cannot distinguish cancellation, a missing directory and a Git failure.

Evidence: docs/design/plugins/ManagedWorktrees.md:71, :74, :82-94, :111; docs/design/plugins/SessionStore.md:129-130, :180, :185, :199.

Fix: State the mapping explicitly, for example rejected reason git to worktree_git_failed, cancelled to worktree_interrupted, invalid to worktree_invalid, not_found to worktree_not_found, and closed/storage to worktree_store_failed; add the missing codes to the discard row.

P3 findings (optional)

P3 1. releaseSession names two different owners

Problem: SessionStore.md:136 and :276 call releaseSession a store creation and commit step, while SessionFiles.md:77 defines releaseSession as a SessionFiles operation and SessionStore.md:192 calls sessionFiles.releaseSession. The same name belongs to two owners.

Failure scenario: An implementer binds store.releaseSession instead of sessionFiles.releaseSession, or implements both. The Timeline face's internal release and the file-owner release are no longer distinguishable by name.

Evidence: docs/design/plugins/SessionStore.md:136, :192, :276; docs/design/plugins/SessionFiles.md:77.

Fix: Rename the Timeline internal step (for example releaseTimeline) or qualify every mention by owner.

P3 2. Sibling heads in the contract and PR body are stale

Problem: SessionFiles.md:172 cites #2080 at 2a312945c, but #2080 is at 4f8bd658; the PR body lists #2080 72ea12c9c, #2092 d96802349 and #2093 4209c4464. At the current sibling heads, git merge-tree reports conflicts with #2080 in docs/design/contracts/resource-owner-operations.md, docs/design/resource-faces.md and docs/design/service-faces.md, and with #2093 in docs/design/plugins/README.md, docs/design/resource-faces.md and docs/design/service-faces.md.

Failure scenario: An implementer aligns against the stale FileStorage or SessionScope head. The PR body's merge order still names old heads, so the actual rebase and conflict resolution are not visible to a reviewer.

Evidence: docs/design/plugins/SessionFiles.md:172; PR body; merge-tree of 05284be with 4f8bd65 and d4e4284.

Fix: Update the sibling heads and the FileStorage citation after rebasing, and state the conflicts resolved by each rebase.

P3 3. git diff --check reports a blank line at EOF

Problem: git diff --check reports docs/zh/design/appserver/session-title-metadata.md:248: new blank line at EOF.

Failure scenario: The local whitespace check is not clean, unlike the rest of the documentation changes.

Evidence: git diff --check origin/main...HEAD.

Fix: Remove the trailing blank line.

Cross-PR and main

  • The PR is open, not draft, mergeable, and its head is 05284be. Current main is eacc672; the merge base is also eacc672, so the full diff is the 27-file, +1466/-734 change above.
  • #2080 at 4f8bd65 defines the FileStorage operations SessionFiles calls; #2093 at d4e4284 defines the Session timeline face and the sessionConfig/query split. #2092 at 91da0de defines the Timeline operations. The PR's merge order places #2080 before the #2091/#2092/#2093 group; the current heads conflict in the shared pointer sections above, so a rebase is needed before those branches can land.
  • The PR body lists #2098 and #2099 as later in the merge order; their current heads were not rechecked this round.

Verification

  • PR state before drafting: head 05284be, OPEN, not draft, MERGEABLE, clean worktree.
  • CI at 05284be: changes, static-checks, verify (linux), macos-native and ci-ok succeed; the other jobs are skipped.
  • LC_ALL=en_US.UTF-8 node scripts/adr-check.mjs --base eacc672d: passed for 27 changed files.
  • git diff --check origin/main...HEAD: failed with the blank line at EOF listed in P3 3.
  • A local relative-link scan over the 27 changed files found no missing target.
  • No Rust build or test was run; this is a documentation-only PR.

Unverified

  • The target bindings and examples were not compiled.
  • The cross-PR conflicts were checked with git merge-tree at the current sibling heads; no merge was performed.
  • The stale sibling-head citations were not checked against every commit referenced by the PR body.

Comment thread docs/design/plugins/SessionStore.md Outdated
let cancelled = cancelled.clone();
Box::pin(async move { git_remove(&root, force, &cancelled).await })
});
store.removeWorktree(Directory { repository, root }, remove, cancelled.clone()).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.

P2: this call passes cancelled, but the binding at :514-519 takes only caller, request and remove; the token is already captured by the RemoveFn closure at :91-94, and the operation table at :129 says the caller's step ends with the record kept. The example either does not compile or teaches a store-level cancellation the binding does not have. Remove the third argument and keep the token in the closure; if store-level cancellation is intended, add it to the binding and the operation contract 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.

Partly fixed in c6d1dae. The extra token is gone, but the example still omits the caller: SessionStore.md:95 passes only Directory and remove, while the binding at :519-524 takes caller: &Ctx first and the other examples pass ctx at :59, :73 and :84. Add ctx, otherwise the example still does not compile. The remaining signature point is in the body.

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

#### Timeline face

`timelineStore` is the same owner's Session-scoped Timeline face; SessionScope installs the binding at the Session instance (#2093). This contract owns the spellings. The instance identity is the Session: every request's `sessionId` must equal it, and a mismatch answers `invalid`; that rule is part of every row's `invalid` below. The face carries the line reads and the completion subscriptions; `createSession`, `releaseSession`, `rollbackSession` and `append` are the store's own creation and commit steps, and `sessionConfig`/`query` are the process `store` reads.

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: releaseSession is defined as a SessionFiles operation at SessionFiles.md:77 and called as sessionFiles.releaseSession at :192, but this paragraph and :276 call releaseSession one of the store's own creation and commit steps. The same name belongs to two owners. Rename the store step (for example releaseTimeline) or qualify every mention by owner.

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 c6d1dae. The store's Timeline step is now releaseTimeline (SessionStore.md:137, :193, :281), and sessionFiles.releaseSession is qualified at :102 and :193. One stale mention remains: SqliteStorage.md:153 lists releaseSession among the timelineStore operations the face does not carry; use releaseTimeline there too. The thread can close once that line is fixed.

Add the target contracts for the four owners of the session storage board
under design rules §7: SessionStore, SessionFiles, ManagedWorktrees and
SqliteStorage. Each document has the responsibility split, the caller
examples, the own contract with operations, errors and flows, the
exceptions with reasons, the rule check and the requirements raised to
mechanism owners.

Refs #2018
Refs #2015
…callback

SessionStore owns title write order: the caller supplies the title, the owner
serializes the write, answers the committed revision and publishes the notice.
The expected revision leaves the request, the caller example, the operation,
the errors and the flows.

Worktree removal becomes one removeWorktree operation with the caller's
removal callback: the store holds the Session exclusion, checks the
association and workspace state, runs the caller's Git step and deletes or
keeps the record by its result. The claim id and the two-step claim/settle
protocol leave SessionStore and ManagedWorktrees.

Refs #2018
Refs #2015
setTitle takes the caller's change instead of a title plus an expected
revision: the change receives the current title, its source and revision,
and returns the next title or its own refusal. SessionStore serializes the
decision, commits the returned title, announces it and answers the new
revision. The conflict error leaves the contract; a refused change keeps
the title. The title read now carries the source.

Refs #2018
Refs #2015
SessionStore: query serves loaded and unloaded Sessions; the store owns the
Timeline operations and the timelineStore face, bound by SessionScope at the
Session instance.

SessionFiles: put answers the path a read tool opens; write replaces an
existing file under the same id and path; remove deletes one Session file.

SqliteStorage: Settings gains a change operation under the row's exclusion
beside the user path's compare-and-set; the Provider group carries the record
projections, candidate and page queries, source activation and adoption, edit
commits and legacy import.

Refs #2018
Refs #2015
…nto the fork

SqliteStorage's public face is the capacity read and the offline operations.
The Settings, Provider, Agent record and Timeline transactions are crate-private
implementations of their data owners; the engine no longer answers their reads
or writes under sqliteStorage.

SessionStore.fork reads the source configuration text itself and takes the
target text from a caller callback that runs under the fork's exclusion; the
source text cannot change between the read and the copy. sessionConfigText is
removed.

Refs #2018
Refs #2015
SessionFiles: read pages by offset with the 64 KiB bound, import and put keep
{fileId, path, bytes}, register leaves the output root with the caller, remove
is idempotent, and the binding appendix defines its request, reply and error
types. SessionStore: create validates the workspace inside the exclusion, every
flow's ending is in the error list, setTitle is a plain fn that admits the write
and returns the wait future, and the binding errors carry their codes.
ManagedWorktrees: discard takes no cancellation, list and prune answer closed,
the leftover branch rule is stated, and the appendix types are defined.
SqliteStorage: the public face is storageReport and the offline operations;
restore is excluded by its destination rule, not a lease.

The named design documents now point at the contracts: resource faces, service
faces, resource owner operations, session files, session title metadata,
SessionTitle and Attachments.

Refs #2018
Refs #2015
Rebase onto main. SessionStore keeps setTitle on the hand-written method table
so a dropped wire reply still admits the write; the title interface is migrated
in SessionTitle and the title metadata doc to store.title and setTitle(id,
change), without expectedRevision or conflict. Resource faces section 5.1 now
describes admission and drain as the store's internal steps.

SessionFiles removes the unused invalid code from write and reports
node_unavailable on remove; the FileStorage dependency drops root_path and
states that the host's root set covers the store directory. ManagedWorktrees
maps store refusals in discard and deletes the default dim/<taskId> branch of a
never-adopted worktree. SqliteStorage reports format from backup and limits the
lease to backup and vacuum; the stale pointers are fixed.

The binding appendices use the routed error enums with the code tag, the
callback error keeps the callback's code in reason, and all four appendices
compile in a temporary crate against rutis 0.23.

Refs #2018
Refs #2015
FileStorage's latest contract restores root_path, add_root, stat and read's
size. SessionFiles reads the store directory's root with root_path instead of
computing it from the database path; the requirement names the operations at
that head and the host's root registration for the native store directory.

Refs #2018
Refs #2015
SessionStore: the store face is one hand-written HostDispatch on the owner, so
setTitle is admitted in invoke before the reply future is returned; the
supersede entry names title and setTitle(id, change).

SessionFiles: an offset above the file size is clamped before the page read,
remove reports closed during unload, and the parent close row matches.

SessionTitle and session-title-metadata: use {id} and setTitle(id, change),
list closed with its service_reloading mapping, and replace the
SessionMetadataService binding.

Resource faces: the rule check names the store's internal admission instead of
append as a face operation. The credential rules now point at the Provider and
Settings owners' operations, not at sqliteStorage. ManagedWorktrees: a discard
refused by a closing store drops its preparation and retries through remove.

Refs #2018
Refs #2015
The store face is one hand-written HostDispatch on SessionStore; the
"service is marked" wording is gone from the contract and resource faces.
Titles keep only setTitle {id} plus the change callback: the revision-check
diagrams, expected-revision labels and conflict retries are removed from
SessionTitle and the title metadata doc, which now use title and add closed
to the error tables.

The associateWorktree request uses {id} in service faces, resource faces and
worktree access, and the supersede list records them.

Refs #2018
Refs #2015
SessionTitle: the revision-check sentences and diagram labels are replaced by
the change callback, the A.4 listen step starts on activated(), and closed maps
to service_reloading. The title metadata doc names title everywhere, and its
binding paragraph no longer calls read.

Refs #2018
Refs #2015
The five owners have no architecture page of their own, so their contracts stay
in the design tree: the architecture README names each of them, and the
Attachments pages link the SessionFiles contract instead of the retired
session-files interface.

Refs #2018
Refs #2015
The paragraphs this PR supersedes in resource faces, service faces,
resource-owner-operations, session-title-metadata, SessionTitle,
worktree-management and worktree-access become one-line pointers; their
headings stay. The Supersedes lists match the changed sections.

SessionStore.fork reads the source body and decides the target text under the
fork exclusion, and the target body and rows are written by the last batch
transaction. The contract names the process-face query and sessionConfig with
{id}. ManagedWorktrees maps each store refusal to its own answer and the
caller's next step. The setTitle example drops the cancellation argument the
binding does not take.

Refs #2018
Refs #2015
SessionStore restores the timelineStore operation contract (reads, completion
subscriptions, notification shape, watermark and release rules) and keeps the
query read scope. create/fork/delete hand over to owner tasks; duplicate
create, missing fork source and second removal have results; associateWorktree
dedupes; removeUnregisteredDirectory keeps the lock after the caller leaves.
SessionFiles adds releaseSession and states the put cancellation and the close
endings. SqliteStorage separates the offline functions from the service face.
ManagedWorktrees keeps the published worktree_* codes, never deletes a branch
on an unregistered removal and answers keptBranch.

The remaining main-tree paragraphs that describe these owners point at the
contracts, and the zh mirrors follow for the title and session-files interfaces.

Refs #2018
Refs #2015
removeWorktree accepts a directory without a record, so discard can settle a
created worktree; the reply says whether a record was deleted. The write
operations no longer take a cancellation token, and setTitle commits once its
change runs. The timelineStore flows and the worktree read flows are stated.
query keeps the full read scope, session_owners has one writer, the delivery
maps every code and rename, and the zh mirrors point at the contracts.

Refs #2018
Refs #2015
SessionFiles maps FileStorage's unsynced and missing_parent on put, import and
write, and remove's cancellation to cancelled. The Timeline face states that a
sessionId differing from the instance identity is invalid. Service faces names
the three owners of the timelineStore row.

Refs #2018
Refs #2015
SessionFiles settles new-file creation itself: put and import create their
parents, resolve unsynced by committing the ownership row or deleting the
bytes, and keep only the attachment-facing codes; only a replacement leaves
unsynced to the caller. removeWorktree treats a missing root as success and
unregisters the record under the same exclusion. The example drops the extra
argument, ManagedWorktrees maps every store refusal, and the internal Timeline
step is releaseTimeline. The sibling heads and the trailing blank line are
fixed.

Refs #2018
Refs #2015
The store's removal checks and registers the resolved root, releases the
exclusion, runs the callback in its own task and re-takes the exclusion to
delete the record and clear the registration; create, fork, associate and a
second removal refuse a path at, under or above a registered root. Creations
register symmetrically, the record-only cleanup keeps its operation, and the
worktree owner states the non-Unix unregistered removal rule.

Refs #2018
Refs #2015
@eric8810
eric8810 force-pushed the dim/2018-storage-contract branch from 05284be to c6d1dae Compare November 24, 2026 11:33
@eric8810
eric8810 requested a review from yyhhyyyyyy November 24, 2026 11:33

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

New-file settlement and cleanup when a registered root is already missing now address the previous review. One new contradiction remains in the reconciliation with merged #2133.

Use one worktree removal lifecycle throughout. The new registration paragraph records the root under the lock and releases the lock before an owner task removes it. The operation flow next to it, and the ManagedWorktrees flow, still hold the exclusion across removal or allow caller unload to stop the process. Make the merged lifecycle authoritative in both places: retain the path registration through owner-task settlement even if the caller leaves, refuse overlapping operations with the existing in-use behavior, and let unrelated work proceed. This is distinct from the earlier error-mapping finding.

Hosted checks passed; the native jobs exercise existing code, not the proposed contract.

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review: PR #2091, round 7, head c6d1dae

Scope: this PR defines the target contracts for the session storage owners (SessionStore, SessionFiles, ManagedWorktrees, SqliteStorage) and moves the title, Session file and worktree call sites onto them, refs #2018 and #2015. I reviewed the full origin/main...HEAD at c6d1dae against main 5930539 and the storage code; the PR is 27 docs files, +1485/-754. Verdict: REQUEST_CHANGES.

Prior round

  • Prior P2 1, the removeWorktree example passed a cancellation token: partly fixed. The token is gone, but the example still omits the caller; see P2 1.
  • Prior P2 2, ManagedWorktrees did not map the store refusals: partly fixed. The table and the discard row exist, but several rows still disagree with the operation rows and the new registration paragraph; see P2 4.
  • Prior P3 1, releaseSession dual ownership: partly fixed. The store's Timeline step is now releaseTimeline in SessionStore.md:137, :193 and :281, but SqliteStorage.md:153 still names releaseSession; see P3 1.
  • Prior P3 2, stale sibling heads and the FileStorage citation: fixed. The PR body lists the current sibling heads and SessionFiles.md no longer pins a head; withdrawn.
  • Prior P3 3, the EOF blank line: fixed. git diff --check is clean; withdrawn.
  • The earlier fixed findings on the Session face, the title revision check, the fork transaction and the setTitle token stay withdrawn.
  • The existing review's two points at 05284be are addressed: SessionFiles.md:82 settles a new unsynced file in the owner, and SessionStore.md:179 treats an already-missing root as success.

P2 findings

P2 1. The removeWorktree example still does not match its binding

Problem: SessionStore.md:95 calls store.removeWorktree(Directory { repository, root }, remove).await?, but the binding at :519-524 takes caller: &Ctx first, then the request and the callback. The create, fork and setTitle examples all pass ctx (:59, :73, :84).

Failure scenario: An implementer copies the removal example and gets a compile error on the missing caller argument. The prior fix removed the extra token but left the example one argument short, so the document still teaches a call shape the binding does not have.

Evidence: docs/design/plugins/SessionStore.md:95, :519-524, :59, :73, :84.

Fix: store.removeWorktree(ctx, Directory { repository, root }, remove).await?;.

P2 2. The removal section still says the exclusion is held across the callback

Problem: The new registration paragraph at :210 says removeWorktree checks under the exclusion, registers the root, releases the exclusion, runs the callback in the owner's task, and re-takes the exclusion to delete the record. Several earlier statements say the opposite:

  • :87 and :90 say the owner holds the exclusion while the Git step removes the root.
  • The flow row at :200 says "take the exclusion, ... call remove, delete the record on success, release" and "the exclusion releases" when the callback ends.
  • The exception at :208 says the step "runs ... under the Session exclusion".
  • The ManagedWorktrees flow at :116 says "the store checks and holds the exclusion, this owner removes the Git worktree".
  • The verification at :242 and :246 says a concurrent creation "waits for" the removal, while :210 says create is refused invalid while a root is registered.

Failure scenario: An implementer follows :200 or :208 and holds the exclusion across the callback. The callback has no time bound (a recursive forced deletion runs to its end), so every Session creation, fork and worktree association blocks for the whole deletion, which is the slow step the registration exists to take out of the lock. A test author following :242 or :246 writes a test that expects the creation to wait or succeed, while an implementation following :210 refuses it.

Evidence: docs/design/plugins/SessionStore.md:87, :90, :200, :208, :210, :242, :246; docs/design/plugins/ManagedWorktrees.md:116.

Fix: Rewrite :87, :90, :200, :208, ManagedWorktrees.md:116 and the two verification bullets to the release-register-reacquire model and the invalid refusal, or change :210 to the held-lock model and accept the unbounded lock. Keep one model.

P2 3. Worktree creation registration has no operation on the store face

Problem: The new exception at ManagedWorktrees.md:125 says a creation registers its selected root in the store's creating set before it makes the directory, and a failed creation hands the registration to the removing set. No operation on the store face performs either step: the operations table at SessionStore.md:110-131 has no creation-registration operation, store.create (:110) runs after the directory exists and receives only {repository, root, subtree}, and the ManagedWorktrees create reply at :189-196 carries no registration handle. The requirements section at :176 says "None new", so the gap is not raised anywhere.

Failure scenario: A removal starts after ManagedWorktrees creates the directory but before store.create writes the association. Without the creation registration, the store's removal checks see no association and no stored workspace, so removeUnregisteredDirectory or removeWorktree accepts the root; the removal deletes the worktree while the creation is about to hand it to the Session, and store.create then fails workspace_missing or associates a directory being deleted. The contract says this race is closed, but no caller can invoke the step that closes it. The current code has the missing piece: crates/dim-app-server/src/storage/timeline.rs:2162-2182 begin_worktree_creation returns a WorktreeCreation guard that the prepared value holds until adoption.

Evidence: docs/design/plugins/ManagedWorktrees.md:112, :125, :176, :189-196; docs/design/plugins/SessionStore.md:110, :125, :210.

Fix: Name the operation (for example store.beginWorktreeCreation {root} -> {creationId}) in the store table and pass the creation id or handle to store.create and the failed-creation cleanup, or state that the store itself makes the directory under create. Update the "Requirements raised to mechanism owners" sections accordingly.

P2 4. ManagedWorktrees maps one store answer to two codes

Problem: The mapping table at ManagedWorktrees.md:80-90 still disagrees with the operation rows and the SessionStore contract:

  • :84 maps store invalid to worktree_invalid, while SessionStore.md:210 maps an invalid caused by a path being removed to worktree_in_use.
  • :88 maps rejected reason cancelled to worktree_interrupted, while the remove row at :74 and the flow at :116 say a started removal "completes or reports worktree_git_failed". The binding takes CancelledFn and the SessionStore removal example at :93 passes the token into git_remove, so a started Git step can return cancelled.
  • :90 maps store closed to worktree_store_failed, while the error table at :104 says worktree_interrupted is also reported when the generation closed.

Failure scenario: The CLI gets two codes for the same transition. A second worktree.remove that meets an in-flight removal receives invalid, and the table tells the operator to fix the task id instead of retrying (worktree_invalid), while the owner contract says the client reports worktree_in_use. A cancelled Git step reports a Git failure or an interrupted removal depending on which row the implementer follows, and the caller's next step differs: report Git's message or retry on the same generation. A store reload during a removal reports a store failure or an interruption for the same close.

Evidence: docs/design/plugins/ManagedWorktrees.md:74, :84, :88, :90, :104, :116; docs/design/plugins/SessionStore.md:93, :210.

Fix: Add the missing row for invalid on a path being removed and map it to worktree_in_use, make the cancellation row and the remove rows agree on worktree_git_failed or worktree_interrupted, and scope the error table's generation-close sentence to the owner's own close so the store's closed stays worktree_store_failed.

P2 5. The Chinese mirrors still define the revision-checked title interface

Problem: The English owner contract and the English SessionTitle now use store.title and setTitle(id, change) with rejected, but the Chinese mirrors still define setTitle {sessionId, expectedRevision, title}, conflict and the sessionMetadata service:

  • docs/zh/design/appserver/session-title-metadata.md:9, :12, :15, :27, :43, :46, :53, :110, :121, :165, :238-242.
  • docs/zh/design/plugins/SessionTitle.md:87, :120, :147, :165, :214-216, :262.

The zh title metadata banner at :3 says the Write and Binding sections are superseded, but section 1 still contains both bullets and the revision-checked summary; sections 4 to 6 are pointers to the contract, so the same file gives two interfaces. The zh SessionTitle section 3.4 text now says a rejected change discards, while the sequence diagram in the same section still sends setTitle(expected r, manual) and expects r+1.

Failure scenario: A Chinese reader implements the owner or the caller from the mirror: a revision-checked write with a conflict retry, a sessionMetadata injection and a metadata read. The owner serves none of these; the caller fails to compile or retries a conflict the store never returns.

Evidence: docs/zh/design/appserver/session-title-metadata.md:9, :12, :15, :53, :110, :238-242; docs/zh/design/plugins/SessionTitle.md:147, :165, :214-216; the English contract at docs/design/plugins/SessionStore.md:123-124 and docs/design/appserver/session-title-metadata.md:3.

Fix: Mirror the English sweep in both zh files: replace the Write/Binding bullets and the structure table with the store face, update the revision and conflict text to the change callback and rejected, and update the diagrams. The author's ledger lists only the old sessionMetadata name as P3; the stale expectedRevision and conflict text is a different interface, so this is not just naming.

P3 findings (optional)

P3 1. SqliteStorage still names releaseSession for the Timeline face

Problem: SqliteStorage.md:153 says the timelineStore face does not carry createSession, releaseSession, rollbackSession or append, but SessionStore.md:137 and :281 renamed the store's Timeline step to releaseTimeline; releaseSession is the SessionFiles operation at SessionFiles.md:77. The same dual name the prior round flagged is still in this cross-reference.

Failure scenario: A #2025 implementer excludes the wrong operation from the Session Timeline face and keeps a releaseSession method on timelineStore, while the SessionFiles release keeps its own name.

Evidence: docs/design/plugins/SqliteStorage.md:153; docs/design/plugins/SessionStore.md:137, :281; docs/design/plugins/SessionFiles.md:77.

Fix: Rename it to releaseTimeline.

P3 2. The ManagedWorktrees code citation is off by about thirty lines

Problem: ManagedWorktrees.md:94 cites crates/dim-app-server/src/worktrees.rs:85-108 for the published worktree_* codes. In main the WorktreeError enum starts at :111, code() at :125 and the strings at :127-134; :85-108 is the prune view.

Evidence: docs/design/plugins/ManagedWorktrees.md:94; crates/dim-app-server/src/worktrees.rs:111, :125-135.

Fix: Cite :111-135 or :125-135.

P3 3. remove says it is not cancellable but lists cancelled

Problem: SessionFiles.md:76 gives remove the cancellation column "None; the owner completes the removal during close" and lists cancelled among its errors; the flow at :105 says the caller cancels before the unlink, and the binding at :267-273 takes no CancelledFn.

Failure scenario: An implementer adds a cancellation path the binding cannot receive, or maps an unreachable code; a caller reads the error table and waits for a cancelled outcome that never arrives.

Evidence: docs/design/plugins/SessionFiles.md:76, :105, :267-273.

Fix: Drop cancelled from the row and the flow, or add the token to the binding and the cancellation column.

P3 4. The resource caller matrix still gives Session files to SessionStore

Problem: resource-faces.md:637 still lists "SessionStore Session files and command output" with createDirectory, replace, list, remove and execHost.removeOutputDirectory. This PR makes SessionFiles the file owner (SessionFiles.md:5-11), whose dependency uses FileStorage's write, import, create_directory, list and remove; replace is the old fsHost spelling the FileStorage contract replaces. The SessionFiles supersedes list does not cover this row.

Failure scenario: A caller consulting the matrix wires Session file writes to SessionStore and uses replace, while the SessionFiles contract has no such dependency and FileStorage (PR #2080) does not publish replace.

Evidence: docs/design/resource-faces.md:637; docs/design/plugins/SessionFiles.md:5-11, :64, :128-132.

Fix: Name SessionFiles in the owner column and use the FileStorage operations; leave command output with its owners.

P3 5. The English SessionTitle diagrams still use the old read and write names

Problem: The prose and A.2 now use store.title and setTitle(id, change), but the flowchart at :117 is labelled "setTitle with revision" and the sequence diagrams read metadata at :173, :194, :257 and :283. The owner has no metadata operation and no revision argument.

Failure scenario: A reader of the diagrams implements a metadata method or a revision-checked setTitle that the operation table and the owner do not have.

Evidence: docs/design/plugins/SessionTitle.md:117, :173, :194, :257, :283, :385-386.

Fix: Use title and setTitle(id, change) in the labels.

Cross-PR and main

  • The PR is open, not draft, mergeable, at c6d1dae; main is 5930539 and the merge base is also 5930539, so the full diff is the 27-file, +1485/-754 change above. git merge-tree --write-tree origin/main HEAD is clean.
  • The PR body lists the current sibling heads (#2080 ed23162, #2092 43f132d, #2093 4557d0b, #2098 c3acab3, #2099 8f440bd); the stale-head citation from the prior round is fixed.
  • git merge-tree --write-tree HEAD <sibling> still conflicts with every sibling in the shared pointer rows: #2080 and #2098 in resource-owner-operations.md, plugins/README.md, resource-faces.md, service-faces.md; #2092 in service-faces.md; #2093 in plugins/README.md, resource-faces.md, service-faces.md; #2094 in overview.md, plugins/README.md, service-faces.md; #2096 in resource-owner-operations.md, plugins/README.md, ImageUnderstanding.md; #2099 in resource-owner-operations.md, plugin-contract.md, plugins/SessionTitle.md, resource-faces.md. The merge order in the body covers them; no resolution is shown.
  • #2099 also rewrites SessionTitle.md and plugin-contract.md, so the title rows are the likely conflict when it lands after this PR.

Verification

  • PR state before drafting: head c6d1dae, OPEN, not draft, MERGEABLE, clean worktree.
  • CI at c6d1dae: changes, static-checks, verify (linux), macos-native and ci-ok pass; the other jobs are skipped.
  • LC_ALL=en_US.UTF-8 node scripts/adr-check.mjs --base origin/main: passed for 27 changed files.
  • git diff --check origin/main...HEAD: clean.
  • A relative-link scan over the 27 changed files checked 1232 links and found no new missing target. One pre-existing anchor miss remains in native-storage-format.md (a link to section 5 of timeline-branches.md whose heading is English in that file); the PR does not touch that line.
  • No Rust build or test was run; the head changes no code.

Unverified

  • The four binding appendices were not compiled.
  • The sibling conflicts were checked with merge-tree at the current heads; no merge was performed.
  • The inline anchors were checked against the local diff hunks at c6d1dae.


| Store answer | Owner code | Caller next step |
| --- | --- | --- |
| `invalid` | `worktree_invalid` | Fix the task id or root; if the root is under a registered directory, call `removeWorktree` |

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 maps every store invalid to worktree_invalid, but SessionStore.md:210 says an invalid caused by a path being removed is worktree_in_use at the worktree client. A second worktree.remove on an in-flight path then tells the operator to fix the task id instead of retrying. Add a separate row for the registered-path invalid and map it to worktree_in_use.

| `not_found` (unregistered removal only) | `worktree_not_found` | The directory is already gone; nothing to retry |
| `in_use` | `worktree_in_use` | Delete the Session or stored workspace that uses the directory, then retry |
| `rejected` with reason `git` | `worktree_git_failed` | Report Git's message; the directory and record stay |
| `rejected` with reason `cancelled` | `worktree_interrupted` | Retry the removal on the same generation |

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 maps a cancelled Git step to worktree_interrupted, but the remove rows at :74 and :116 say a started removal reports worktree_git_failed; the binding and the SessionStore example at SessionStore.md:93 pass the token into the Git step, so cancelled is reachable. Also :90 maps store closed to worktree_store_failed while the error table at :104 says a generation close is worktree_interrupted. Pick one code per condition.

- A branch is kept when `remove` deletes a worktree: committed content must not disappear with the directory, and `worktree.list` reports it.
- `discard` is not cancellable: a cancelled Session creation still has to settle what the owner made. A store refusal (`closed` or `storage`) leaves the directory and branch in place; the caller reports it. The preparation is dropped with the generation, so the directory is unregistered and `remove` by task id is the retry path on the replacement generation.
- Unregistered directories are never pruned: the owner has no record to age, so only an explicit `remove` by task id deletes them.
- A creation registers its selected root in the store's creating set before it makes the directory; a removal that meets the registration is refused, and a failed creation hands the registration to the removing set so its own cleanup is not blocked. The set is in memory; a process death leaves the directory removable by task id.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

P2: this says a creation registers its root in the store's creating set before it makes the directory and hands the registration to the removing set, but no store operation does that: the table at SessionStore.md:110-131 has none, store.create runs after the directory exists, and CreatedWorktree at :189-196 carries no handle. The current code's begin_worktree_creation (crates/dim-app-server/src/storage/timeline.rs:2162-2182) returns the guard this text assumes. Name the operation and the handover, or the removal race stays open.

let cancelled = cancelled.clone();
Box::pin(async move { git_remove(&root, force, &cancelled).await })
});
store.removeWorktree(Directory { repository, root }, remove).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.

P2: this call omits the caller. The binding at :519-524 takes caller: &Ctx first, and the create, fork and setTitle examples pass ctx at :59, :73 and :84. Use store.removeWorktree(ctx, Directory { repository, root }, remove).await?.

- `create` takes the caller's already-validated configuration; `fork` reads the source text itself and calls the caller's text step under the fork's exclusion, so the lifecycle owner's `initialTitle` decision cannot race the copy and the copied bytes stay the source's text.
- `delete` does not close the Session, remove its Agent admission slot or remove the worktree: closing is Agents', and a managed worktree is removed by ManagedWorktrees under `removeWorktree`.
- `setTitle` runs the caller's change under the owner's serialization: the change only computes the next title from the current title and revision, and returns its own refusal; the reply may be lost, so the caller re-reads rather than assumes failure.
- `removeWorktree` serves both a recorded directory and a directory a failed creation left without a record (ManagedWorktrees' `discard`); the record is deleted only when it exists, and the reply says whether one was deleted. It runs ManagedWorktrees' removal step under the Session exclusion: the checks and the record deletion cannot interleave with a Session creation that would point into the removed root. A failed or cancelled step keeps the record and clears the registration.

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 sentence and :87, :90, :200 and :242/:246 say the callback runs under the exclusion and a concurrent creation waits, while :210 says the exclusion is released before the callback and create is refused invalid while a root is registered. The callback has no time bound, so holding the lock blocks creation and fork for the whole recursive deletion. Align these with :210.

@@ -215,7 +214,7 @@ sequenceDiagram
R->>Meta: setTitle(expected r, manual)
Meta-->>R: r+1
G->>Meta: setTitle(expected r, auto)

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 diagram still sends setTitle(expected r, auto) and expects a revision, while section 3.2 in the same file now says a rejected change discards and the English contract uses setTitle(id, change) (SessionStore.md:124). The zh mirror still defines the revision-checked interface in sections 1 to 3; mirror the English sweep.

@@ -176,17 +121,7 @@ Rpc 从不调用 `setTitle`,也不新增方法。各错误到达客户端的
| SessionStore 或 SqliteStorage 重载 | 按 §6 了结。`sessionMetadata` 的使用方随 SessionStore 重载([ADR 002](../../adr/002-plugin-scope.md) D3),SessionTitle §1 已接受。SessionStore 只随没有依赖的 SqliteStorage 重载 |

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 zh mirror still names sessionMetadata and the revision-checked write in sections 1, 2, 3, 8, 9, 12 and 17, while its own banner at :3 and the English file state that interface is superseded. A reader following this line injects a service the owner no longer provides. Replace the old interface text with the store face, not only the operation sections.

@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