Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
243 changes: 243 additions & 0 deletions docs/architecture/runtime-managed-workspace-baseline-open-v1.zh-CN.md

Large diffs are not rendered by default.

111 changes: 111 additions & 0 deletions docs/architecture/runtime-managed-workspace-owner-v1.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Managed Workspace Owner v1:M0 生命周期门

- 状态:实现完成;Git Workspace Service 与 Workspace Version Authority 合并后平铺重建
- 更新日期:2026-08-02
- 主要不变量:一个 authenticated interactive storage-root owner 在其生命周期内至多发布一个
managed workspace owner;已经 admission 的 workspace 操作必须在关闭前 drain
- artifact owner:`GitWorkspaceService`
- lifecycle owner:`ManagedWorkspaceOwner`
- canonical workspace history:仍由 Workspace Version Authority 拥有;M0 composition 只允许 owner 的
`openManagedWorkspaceBaseline(...)` 通过 storage-internal writer 写入 baseline RuntimeEvents

## 1. 为什么需要独立 owner

`GitWorkspaceService` 能创建、验证、repair 与 quarantine Maka-owned Git artifacts,但它是一个
operation-scoped service;仅有它还不能回答:

- 哪一个 host 有权在当前 storage root 上驱动这些操作;
- 初始化进行中或失败时,是否可能发布半个可用 owner;
- shutdown 与进行中的 Git 操作谁先完成;
- Desktop、CLI 与 runtime-host 是否可能各自绕过同一生命周期门。

本切片把现有 authenticated `InteractiveRootOwner` 作为上层 lease authority。它不增加第二个 OS
owner lock,也不通过路径自行证明 ownership。

## 2. Owner、边界、失败状态与回滚

| 项目 | 决策 |
|---|---|
| 唯一 owner | 一个真实 `InteractiveRootOwner` 对象只能组合一个 `ManagedWorkspaceOwner` |
| 初始化边界 | pinned Git digest 验证与 storage-root authority probe 全部运行在 root write lease 内 |
| operation admission | 仅 `ready` 可 admission;每项操作同时持有 managed-owner residency 与 root lease operation |
| shutdown | `ready -> closing -> closed`;`closing` 拒绝新操作并等待已 admission 操作 drain |
| 初始化失败 | 返回 `managed_workspace_owner_unavailable`,释放未发布 claim,允许同一 root owner 修正后重试 |
| 重复组合 | 返回 `managed_workspace_owner_conflict` |
| drift | 不返回 drifted cwd;receipt/artifact 复验发现 drift 时 fail closed;复验后 reopen 竞态发现 drift 时 durable quarantine |
| 回滚 | 不接 Desktop/CLI/runtime-host,不改变 attached mode;可删除本 owner 而不改变 Git artifacts 或 RuntimeEvents |

owner 不关闭外层 `InteractiveRootOwner`。Runtime Host 仍拥有 root owner 的最终关闭顺序;managed owner
必须先关闭。反过来,如果 root owner 已开始关闭,lease revalidation 会阻止新的 managed operation。

## 3. 公开状态机

```mermaid
stateDiagram-v2
[*] --> opening
opening --> ready: pinned Git + root lease probe 成功
opening --> failed: 初始化失败,释放 unpublished claim
ready --> closing: close()
closing --> closing: 拒绝新 operation,等待 residency drain
closing --> closed: active operations = 0
closed --> closed: repeated close()
```

`opening` 与 `failed` 不作为已发布 owner 的可见状态。factory 只有在初始化完成并再次确认 root owner
仍然有效后才返回 `ready` owner。

## 4. Workspace gate

owner 的 public surface 只开放一个 workspace admission 操作:

1. `openManagedWorkspaceBaseline(store, identity)` 从 eligible clean source 创建/exact-adopt artifact,
持久化并复验 receipt,再由 storage-internal writer 接受 canonical baseline。

artifact-only create/open 和 `GitWorkspaceService` factory 不从 package root 导出。调用者不能在 SQLite
acceptance 前取得 `worktreePath` 或裸 `ManagedWorkspaceBinding`。入口返回前必须验证 worktree、index、
HEAD、tree、ownership lock、canonical `runtime.sqlite` pathname/inode、durable receipt,以及最终时刻的
`InteractiveRootOwner`/root marker identity;任何失败都不能把 cwd 交给工具。SQLite 已提交而最终 owner
复验失败时,canonical history 保留,但本次调用不得发布 usable workspace。

本切片不扫描目录来猜测 workspace identity。Baseline Open Bundle 通过 Git artifact owner 的 durable
receipt 与 canonical workspace authority 绑定 exact identity;未接受 Git artifact 属于 orphan GC 范畴。

## 5. Crash 与并发证明

| 场景 | 必须结果 |
|---|---|
| 同一 root owner 两次 open | 一个 ready;另一个 owner conflict |
| pinned Git 初始化失败 | 不发布 owner;修正 digest 后可重试 |
| operation admission 后 close | close 等待 operation;新 operation 被拒绝 |
| root owner 同时 close | root close 与 managed close 都等待同一 lease-bound operation |
| external drift 后 reopen | receipt/artifact 复验 fail closed;若发生在复验与 reopen 之间则 durable quarantine |
| post-commit artifact 复验后 root marker 被替换 | admission 时捕获的 lease identity guard 最终复验并拒绝;保留 canonical head,不发布 cwd;owner closing 只阻止新 admission,不误杀正在 drain 的操作 |
| repeated close | exact no-op,不重复释放外层 root owner |

Git artifact create/quarantine 的进程崩溃矩阵继续由 `GitWorkspaceService` 负责;本 owner 不复制第二套
repair 状态机。Baseline Open Bundle 将补充“startup 时先验证 canonical receipt,再按 exact binding
reopen/repair,最后才允许 baseline authority read”的组合顺序。

## 6. 平台能力矩阵

| 能力 | Linux | macOS | Windows |
|---|---|---|---|
| owner uniqueness / lifecycle | 支持 | 支持 | 支持 |
| root lease-bound operation drain | 支持 | 支持 | 支持 |
| pinned Git initialization | 支持 | 支持 | 支持 |
| external drift quarantine | 支持 | 支持 | 有限支持,沿用 Git service 的 Windows 承诺 |
| power-loss durability | 不承诺 | 不承诺 | 不承诺 |

## 7. 明确延期

- Desktop、CLI、runtime-host 接线与 managed-mode 设置;
- filesystem worker、mutation coordinator 与工具 cwd 切换;
- candidate refs、mutation repair、GC、replication outbox;
- ignored dependencies、build/test environment provisioning;
- Durable Write、workspace-bound continuation 与自动 resume。
- whole-root import 后既有 linked worktree 的 relocation/adoption;
- 非空 legacy database 的显式备份与 root-binding migration 工具。

这些能力不能借 owner lifecycle PR 顺手接入。Baseline Open Bundle 已作为本 owner 的第一个
canonical-fact consumer 完成组合,证明 Git baseline 与 RuntimeEvent baseline 不会只成功一半;后续
M1 execution admission 仍必须从该 bundle 成功返回的结果进入,不能重新开放 artifact-only 旁路。
8 changes: 6 additions & 2 deletions docs/architecture/runtime-resume-extraction-ledger.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ Continuation Authority 合并后,workspace plane 不再从 #1346 移植通用
> baseline-accepted fact、epoch/version/head projection 对外只能全可见或全不可见;并发只能接受一个
> baseline identity。若 projection 被外部删除,reader 必须 fail closed,不能把损坏态当作未创建。

Schema 9 进一步要求该 authority stream 在首次写入前绑定 authenticated storage root 的 durable
`rootId`;只有 metadata-only 新库可自动绑定,已有逻辑数据必须显式 adoption,单独复制数据库不能改变归属。

### 10.1 文件归属

| 文件 | 本切片职责 |
Expand All @@ -423,7 +426,7 @@ Continuation Authority 合并后,workspace plane 不再从 #1346 移植通用
| `core/runtime-event.ts` | typed `actions.workspaceFact` 与 control-plane stream 说明 |
| `core/runtime-event-store.ts` | baseline authority capability 与专用 writer contract |
| `storage/runtime-event-authority.ts` | workspace fact/authority stream generic-writer reservation |
| `storage/sqlite-runtime-schema.ts` | schema 7、三张 projection、capability marker |
| `storage/sqlite-runtime-schema.ts` | schema 7 facts/projections/capability;schema 8 headless task events;schema 9 singleton durable storage-root binding |
| `storage/sqlite-runtime-store.ts` | atomic baseline bundle、read cross-check、rebuild、failpoints |
| `storage/agent-run-store.ts` | JSONL 与 conversation copy fail closed |
| `storage/conversation-operational-state.ts` | ordinary Session purge 不得删除 authority stream |
Expand All @@ -446,7 +449,8 @@ Continuation Authority 合并后,workspace plane 不再从 #1346 移植通用
- projection delete/rebuild、canonical corruption fail closed;
- SQLite/JSONL/tool/recovery/continuation/copy writer bypass;
- 两进程 exact/conflicting baseline arbitration;
- 两进程 schema 6→7 migration;
- 两进程 schema 6/7→8 migration;
- DB rootId exact binding、跨 root 单文件复制拒绝、whole-root storage authority import/adopt 与 unbound operational data fail closed;既有 managed worktree relocation 和 legacy DB binding 仍是独立维护协议,不由 M0 baseline open 暗中完成;
- Linux/macOS process-kill crash harness;
- workspace fact 不进入 UI/provider message projection。

Expand Down
Loading
Loading