Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
| `managed-dependency-environment`、bundled npm、worker bridge | M1/M1.3 独立前置;不从旧 M2 分支重复携带 |
| Git candidate ref/commit、delta/path policy、orphan GC | M2.2 |
| T1 mutation profile/base freeze、durable workspace reservation、accepted path truth | M2.3a |
| owner-bound mutating admission、reopen active-reservation gate | M2.3b |
| 真实 Write/Edit composition、Host crash/reopen | M2.4 |
| Runtime managed settlement fail-stop、exact durable response adoption | M2.3b |
| owner-bound mutation profile/worker、active-reservation admission、真实 Write/Edit composition | M2.4 |
| continuation boundary 绑定 workspace version | M3 |
| restore、rebaseline、publish、undo、replication | M4 |

Expand All @@ -63,15 +63,28 @@
| storage/core focused tests | schema、rollback、rebuild、真实 crash、双进程 exclusivity |
| `runtime-managed-workspace-mutation-reservation-v1.zh-CN.md` | owner、原子边界、失败状态与平台矩阵 |

M2.3a 不迁入 Runtime hook、ManagedWorkspaceOwner lease、candidate capture/discard 或真实 Write/Edit;前两项属于
M2.3b,后两项属于 M2.4。
M2.3a 不迁入 Runtime hook、ManagedWorkspaceOwner mutation lease、candidate capture/discard 或真实 Write/Edit;
Runtime settlement hook 属于 M2.3b,其余三项由 M2.4 的真实 owner/consumer 一次性闭环。

## M2.3b 增量归属

| 路径 | 归属 | 不变量 |
|---|---|---|
| `packages/runtime/src/tool-runtime.ts` | M2.3b | managed T1 后整个 normalization/adoption/publication seam fail-stop;只采用 exact durable envelope |
| `packages/runtime/src/__tests__/tool-runtime-durable-boundary.test.ts` | M2.3b | pre-T1 Host seam、success/discard adoption、size/canonicalization/envelope/unsettled fail-stop |
| `docs/architecture/runtime-managed-workspace-mutation-execution-admission-v1.zh-CN.md` | M2.3b | Runtime owner、失败状态、平台证据和 M2.4 seam |

M2.3b 不迁入 `ManagedWorkspaceOwner` mutation lease/profile、built-in Write/Edit 标记、filesystem worker mutation、
Git candidate capture/discard、successor/error bundle composition 或 Desktop/CLI wiring;这些共同构成 M2.4 的首个
生产消费者。只读 worker 的存在不能签发 mutation profile,caller callback 也不能自证执行能力。
## Commit 映射

| 当前重建内容 | 来源 | 说明 |
|---|---|---|
| core RED tests + causal successor facts | `14327f5f0` 的 core 最终状态 | 只保留 subpath contract |
| storage RED tests + atomic successor writer | `14327f5f0` 的 storage 最终状态 | 在 current-main schema 12 上新增 migration 13 |
| reservation RED tests + T1 owner projection | `36e1e3ec4` | 从 M2.2 stack 中只提取 M2.3a 自有差异,跳过旧 Git CLI candidate owner |
| Runtime settlement RED tests + fail-stop owner | `584fe099d..3825677aa` 的 Runtime 净差异 | 不迁入旧 recovery inventory、Host 或 Git candidate 路径 |
| 文档与 extraction ledger | 现行工程实践 | 记录最新 main、Gitoxide 换轨和 M2.2–M2.4 等待关系 |

## Diff 审核门槛
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

# Managed Workspace Mutation Runtime Settlement v1

- 阶段:M2.3b
- 状态:实现切片;保持 Draft,等待 M2.4 Write/Edit 生产消费者
- owner:Tool Runtime managed settlement seam
- durable 真相:M2.3a SQLite reservation 与 owner 已提交的 immutable outcome

## 1. 本切片只证明一个主要不变量

当未来的 Host owner 在 T1 前返回一份 exact `managed_mutation_v1` dispatch 后,Tool Runtime 将它与 call 一起
提交为 durable T1。从这一刻起,整个 settlement、result canonicalization、大小检查、durable outcome adoption、
provider publication 与 telemetry 都处于 managed fail-stop 状态:任何异常都不得进入 generic synthetic T2。

managed T1 后的 operation authority 是 Runtime-owned 线性 capability:`open → running → settled → closed`。
owner 最多调用一次;`execute()` 返回或抛错时 capability 立即关闭。若 owner 在 operation 尚未完成时提前结算,
Runtime 必须先 join 该 operation,再将整个结算判为 unsettled,确保 Runtime 返回后不存在仍可产生副作用的 detached
execution。

Runtime 只接受三种 owner 结算:

1. `workspace_successor_committed`:M2.1 的成功 T2、successor 与 head 已经原子提交;
2. `safely_discarded`:owner 已证明 candidate 未被接受,并已提交 exact error outcome;
3. `unsettled`:副作用或结算状态不可证明,M2.3a reservation 保留给恢复流程。

owner 返回值首先经过运行时结构校验,规范化成内部 terminal union。managed/generic lane 只由 T1 前已经确定的
`managedMutationAdmission` 决定,绝不再用 `durableOutcome` 是否 truthy 选择 writer;terminal settlement 缺失
durable outcome 或 canonical content 时只能 fail-stop。成功路径的 provider value 始终由 Runtime 在执行
`operation()` 时捕获并冻结,不进入 owner settlement。

本切片不声称拥有 mutation worker、execution-profile attestation、Git candidate 或 production admission。它只定义
Runtime 如何消费 M2.4 将提供的 owner capability。这样 T1 不会记录一个由只读 worker 或 caller callback 冒充的
execution profile。

## 2. 权威分层

| 层 | owner | 当前职责 |
|---|---|---|
| durable ownership | M2.3a SQLite authority | T1 时创建跨进程 reservation,successor 时原子消费 |
| runtime settlement | M2.3b Tool Runtime | T1 后禁止 generic T2;采用完整一致的 durable response envelope |
| execution admission | M2.4 Host/workspace owner | 绑定真实 mutation worker、sandbox profile、head、paths 与 candidate lease |
| production composition | M2.4 | 执行 Write/Edit、capture/discard candidate、提交 successor/error |

`admitManagedMutation` 在 M2.3b 是一个注入式 Host seam,不是当前 `ManagedWorkspaceOwner` 的公开能力。没有该 seam
时,标记为 `managed_mutation_v1` 的工具必须在 T1 前拒绝;不得降级为普通工具执行。

## 3. T1 前接口边界

```text
Tool Runtime
-> Host admission seam(operation, tool, args)
-> M2.4: validate real worker/profile/head/path/candidate capability
-> return exact managedMutation dispatch + one-shot execute/dispose handle
-> SQLite commitToolPrepared(call + dispatch + reservation)
```

M2.3b 只校验 Host seam 是否存在,并将其返回的 immutable dispatch 原样纳入 T1。dispatch 的真实性、profile
digest 如何从实际 worker/sandbox 能力产生,以及 admission 如何重验 canonical head,全部由 M2.4 同一个 owner
实现和测试。

## 4. T1 后 fail-stop 状态机

```mermaid
flowchart TD
T1["managed T1 durable"] --> O["Runtime executes and owns provider value"]
O --> Q["owner receives isolated outcome proof"]
Q --> N["normalize terminal proof"]
N --> S{"terminal state proven?"}
S -->|"successor committed"| A["compare exact durable success envelope"]
S -->|"safely discarded"| E["compare exact durable error envelope"]
S -->|"unknown / throw / invalid"| P["fail-stop; reservation remains"]
A --> R["publish provider result"]
E --> R
```

`safely_discarded` 只携带一个 exact `providerResult`。Runtime 从该值生成 canonical content,并执行与普通工具
相同的 `maxResultBytes` 检查。getter、serialization、canonicalization 或 size-check 的任何失败都变成 managed
unsettled,不写 generic T2。

`workspace_successor_committed` 只携带 `durableOutcome`,不得重新提交 provider value。Runtime 在调用真实 operation
完成边界用一次 bounded strict-JSON walker 同时执行 byte budget、类型校验、plain snapshot 和递归冻结。walker
一旦超限立即停止,不会先复制完整对象;并拒绝 `undefined`、非有限数字、稀疏数组、accessor、cycle、`toJSON`、
非 plain container 及其他非 JSON 值。canonical content、proof、message、telemetry 和 provider 返回只能读取该
snapshot。
Runtime 私有保存 snapshot,仅把隔离复制的 `content/isError/durationMs` proof 交给 owner 用于提交 successor。owner
返回后,Runtime 用自己的 canonical outcome 校验 durable envelope;因此 owner 无法构造 live A / replay B,工具也
无法通过事后修改原始返回对象改变已验证结果。

owner 返回的 response 必须与 Runtime 从 T1 identity 构造的唯一 canonical envelope 完全相等,包括:event id、
run/invocation/session/turn、timestamp 形状、origin、model visibility、function response、error bit、exact refs、
parent refs 和 duration。缺字段、多字段或任意值不同都 fail-stop。这样 live provider 与 crash replay 只有一个结果源。

## 5. 失败状态

| 场景 | 结果 |
|---|---|
| Host admission seam 缺失或 admission 在 T1 前失败 | 无 T1、不执行工具 |
| T1 commit 失败 | dispose admission,不执行工具 |
| owner 已原子接受 successor | Runtime 采用 exact durable success outcome |
| owner 已安全 discard | Runtime 采用 exact durable error outcome |
| owner 返回 unsettled、抛错或响应丢失 | 无 generic T2、无 provider result,reservation 保留 |
| owner 结算后再次调用 operation | capability 已关闭,不执行工具 |
| owner 在 operation 运行中提前结算 | join operation 后 fail-stop,不接受 terminal settlement |
| canonicalization、size check、envelope validation 或 publication 失败 | 同上,统一 fail-stop |
| durable envelope origin/visibility/refs/duration 不一致 | T2 boundary error,禁止发布 |

## 6. 平台能力矩阵

| 能力 | Linux | macOS | Windows |
|---|---|---|---|
| T1 reservation kill/reopen | 历史 CI 已证明;重建分支待 CI | 历史 CI 已证明;重建分支待 CI | 本地定向通过;重建分支待 CI |
| 跨进程唯一 mutation reservation | 同上 | 同上 | 同上 |
| Runtime managed settlement fail-stop | 平台无关测试 | 平台无关测试 | 平台无关测试 |
| mutation worker/profile/candidate | M2.4 | M2.4 | M2.4 |
| power-loss convergence | 不在本切片 | 不在本切片 | 不在本切片 |

本次平铺重建保留 `sqlite-runtime-crash` 与 `sqlite-recovery-concurrency` 的真实进程用例,但不从等待
Gitoxide 重建的 M2.2 携带旧 candidate inventory。最终发布 CI inventory 在 M2.2/M2.4 重建时统一登记。

## 7. 验证

- Host admission 缺失时不落 T1、不执行工具;
- owner-committed successor 只采用 durable T2,不调用 generic writer;
- success settlement 缺失 durable outcome 时不调用 generic writer;
- success settlement 不能替换 Runtime-owned provider value,live 与 replay 内容不一致时 fail-stop;
- terminal settlement 撤销 operation capability;detached operation 必须 join 后 fail-stop;
- 工具事后修改原始 result 不得改变 durable、message、event 或 provider snapshot;
- oversized result 必须在遍历越过 budget 前终止;strict-JSON 非法值不得进入 durable event;
- safe-discard live result 与 durable content 不一致时 fail-stop;
- getter/canonicalization 异常和超大 safe-discard 均不写 generic T2、不发布结果;
- code-mode response 的 origin、hidden visibility、parent refs 与 duration 必须完整匹配;
- explicit unsettled、owner throw 和 T1 后任意异常均 fail-stop;
- real-process kill-after-T1 与双进程 reservation 竞争已进入 focused suite;三平台严格 inventory 等待
Gitoxide M2.2/M2.4 重建后统一登记。

## 8. 明确留给 M2.4

- 不给 built-in Write/Edit 启用 `durableExecutionProfile`;
- 不由 `ManagedWorkspaceOwner` 签发 mutation lease 或静态 profile digest;
- 不调用真实 mutation-capable filesystem worker;
- 不 capture、discard 或 accept Git candidate;
- 不接 Desktop/CLI,不改变当前用户可见 resume 能力。

M2.3b 没有生产消费者,因此即使测试通过也保持 Draft。M2.4 必须由同一个 owner 同时签发并执行真实 mutation
profile,不能重新引入 caller digest、静态标签或 callback 自证。
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ M2.3b/M2.4 的平台 owner 在副作用前验证。Core 不读取 `process.platf

## 8. 后续切片

### M2.3b — Runtime admission composition
### M2.3b — Runtime settlement seam

在 T1 前取得 owner-bound capability,重验平台路径、execution profile 和 canonical head;启动时读取 active
reservation,禁止新 admission 越过 prepared operation。它不得 capture/discard Git candidate,也不得自行写
successor。
Runtime 接收未来 M2.4 Host owner 提供的 admission,但本切片只证明:managed T1 后不再进入 generic T2,且 live
result 只能采用与 T1 identity 完整一致的 durable response envelope。平台路径、execution profile、canonical
head 与 active-reservation admission 由 M2.4 的真实 mutation owner 统一证明。

### M2.4 — Write/Edit production settlement

真实 Write/Edit 执行、candidate capture/verification、owner-controlled settlement 与 reservation terminal
transition 在此闭环。Runtime 必须能区分:successor 已接受、candidate 可安全 discard、effect unknown/park;
不能在 managed callback 后自动写 generic T2。
真实 Write/Edit admission/profile、worker 执行、candidate capture/verification、owner-controlled settlement 与
reservation terminal transition 在此闭环。Runtime 必须能区分:successor 已接受、candidate 可安全 discard、
effect unknown/park;不能在 managed callback 后自动写 generic T2。
Original file line number Diff line number Diff line change
Expand Up @@ -203,23 +203,24 @@ SQLite transaction 提供三平台一致的数据库原子性;本切片不声
- 详细合同见
[Managed Workspace Mutation Reservation v1](./runtime-managed-workspace-mutation-reservation-v1.zh-CN.md)。

### M2.3b — Mutation execution admission
### M2.3b — Runtime managed settlement

主要不变量:T1 前冻结 base workspace head、execution profile、operation identity 和 candidate lease;T1 后禁止切换
attached/managed mode 或退回旧直接写路径。
主要不变量:Host admission seam 缺失时不落 T1;managed T1 durable 后,settlement、canonicalization、大小检查、
durable outcome adoption 与 publication 的任何失败都禁止进入 generic T2。

- owner:Runtime Host managed mutation admission;
- 原子边界:消费 M2.3a,在 T1 durable dispatch 前签发 owner-bound capability;
- 失败状态:能力缺失、scope 失效、base/head/profile 不一致均在工具副作用前拒绝;
- 回滚:T1 前失败走标准 tool error;T1 后不确定状态保持 unsettled,交给 M2.4 收敛。
- owner:Tool Runtime managed settlement seam;
- 事实边界:只采用 owner 已提交且与 T1 identity 完整相等的 durable response envelope;
- 失败状态:invalid/unsettled/throw/lost response 均保留 M2.3a reservation并 fail-stop;
- 明确不证明:真实 mutation worker、execution profile、canonical head admission 和 candidate lease。

该 PR 不新增第二套 workspace writer,不 capture/discard candidate,只消费 M2.1/M2.3a 的 internal capability。
后面四项必须由 M2.4 的同一个 Host/workspace owner 同时签发并执行,不能由只读 worker、静态 digest 或 caller
callback 自证。

### M2.4 — Write/Edit production composition

主要不变量:真实 Write/Edit 的成功只能来自“owned candidate 已验证 + M2.1 bundle 已提交”。

- 把 owner-bound worker、candidate capture 与 successor bundle 串成唯一生产路径;
- 把 owner-bound profile/admission、mutation worker、candidate capture 与 successor bundle 串成唯一生产路径;
- 增加真实 Host kill/reopen crash matrix;
- 保持现有 tool result、permission、sandbox 与 cancellation 语义;
- 作为 M2.2/M2.3 的首个生产消费者,完成后才允许前三个切片转 Ready/依序合并。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,11 @@ M2 按 owner 与原子边界拆成五个 stacked slices:
candidate commit/ref、exact-base CAS 与 artifact receipt;不写 T2,不恢复旧 Git CLI adapter;
3. **M2.3a durable mutation reservation(当前重建切片)**:schema 14 将 T1 与 workspace-instance-exclusive reservation
原子绑定,successor fact 固化 exact changed paths,generic T2 无权结算 managed mutation;
4. **M2.3b mutation execution admission**:T1 前冻结 base head、execution profile、operation identity,
消费 durable reservation gate;T1 后禁止 silent fallback;
5. **M2.4 Write/Edit production composition**:把 owner-bound worker、candidate capture 与 M2.1 bundle
串成唯一生产路径,并用真实 Host kill/reopen crash test 完成前三片的生产消费者。
4. **M2.3b Runtime managed settlement**:Host seam 缺失时不落 T1;managed T1 后所有 normalization、
size/envelope validation 与 publication failure 都 fail-stop,禁止 generic T2;
5. **M2.4 Write/Edit production composition**:由同一 owner 绑定真实 mutation profile、canonical head、
active reservation、worker、candidate capture 与 M2.1 bundle,并用真实 Host kill/reopen crash test 完成前三片的
生产消费者。

M2.2/M2.3a/M2.3b 在 M2.4 消费者存在前保持 Draft。M2.4 不绑定 continuation boundary;该能力仍属于 M3。

Expand Down Expand Up @@ -661,12 +662,13 @@ M0.1 Git artifact owner (merged)
└─> M0.4 baseline open bundle (merged)
└─> M1.1 execution scope admission (current)
└─> M1.2 runtime-host composition
└─> M1.3 explicit environment provisioning
└─> M2.1 mutation version persistence authority
└─> M2.2 Git mutation candidate owner
└─> M2.3a durable mutation reservation
└─> M2.3b mutation execution admission
└─> M2.4 Write/Edit production composition
├─> M1.3 explicit environment provisioning
└─> M2.1 mutation version persistence authority
├─> M2.3a durable mutation reservation
│ └─> M2.3b mutation execution admission
└─> Gitoxide source import + candidate/ref data plane
└─> M2.2 Gitoxide mutation candidate owner
└─> M2.4 Write/Edit production composition
└─> M3 workspace-bound continuation
└─> M4 restore / rebaseline / publish / replication

Expand Down
Loading