# Decisions, failure windows and handoff / 决策、失败窗口与交接

## English

### Evidence before architectural labels

Use the [runtime walkthrough](https://ai.lwkjob.com/lab/senior-runtime/README.md) and [independent settlement task](https://ai.lwkjob.com/lab/senior-runtime/LEARNER_TASK.md). Attach actual source digests, process records, runtime state and the merchant ledger to a claim about this local experiment. Write a production proposal separately, with assumptions and reversal conditions. A phrase such as distributed fencing, exactly once or high availability is not evidence that the corresponding system was built.

The worked design is one host, multiple Python processes and a shared SQLite file. The local merchant checks the shared task's current worker/epoch/lease/admission facts inside the same transaction that creates a return receipt. This arrangement lets the experiment reject a stale worker at the actual business write boundary. Reusing its local epoch alone cannot fence a different external service that does not check it. The budget uses synthetic integer units; neither reservation nor settlement measures model tokens or money.

### ADR 1: which component owns admission and settlement?

**Worked scope and decision.** A bounded fictional after-sales task moves from an Agent proposal through a seeded human-review fixture to a local merchant effect. Multiple workers need one shared admission decision. Use file-backed SQLite transactions for global/tenant admission, estimate reservation, worker fencing and local settlement. The merchant receipt is the business-effect evidence. Keep an unknown result reserved until authoritative reconciliation; a local timeout does not prove no effect.

**Trusted assumptions.** The SQLite file and its transaction behavior are available to all participating processes on this one host. Runtime configuration, tenant policy, worker leases and merchant receipt data come from their respective server/store boundaries, not model text or a task's self-reported fields. The local merchant has access to the same authoritative runtime facts. The demonstration uses fixed fictional review/identity data. Record which assumption your own deployment changes before reusing the decision.

**Alternatives and reversal conditions.** An in-memory per-worker counter cannot enforce a shared cap after restart or across processes. A separate coordinator and remote merchant can support a different deployment, but require a defined fence/authorization protocol, durable effect receipt and explicit ambiguous-outcome handling. Revisit the SQLite choice if workers move to separate hosts, the merchant cannot verify current execution authority, lock waiting exceeds a measured local objective, or shared-file operational requirements no longer hold. The local load report does not establish any of those production thresholds.

**Hand calculation before execution.** Declare fictional global capacity 2, per-tenant capacity 1, A budget 9 and B budget 7. Reserving A=4 and B=3 leaves available A=5/B=4 and consumes two slots. A receipt with actual synthetic charge 3 settles A, releases its reservation/slot and leaves A=6 available. An unknown B result keeps its reservation/slot and available B=4. Only an authoritative, safe no-effect outcome can release B to 7; a confirmed B receipt settles its declared actual charge. These numbers are an authored arithmetic example, not a measured runtime report or provider bill. In your run, copy the actual configured values and repeat the calculation against the ledger.

**Failure window and invariant.** A worker can send a write and lose the response after the merchant commits it. Reclaiming a local lease does not cancel that effect. A replacement keeps the original operation key, queries authoritative evidence and prevents the old worker from creating another effect at the merchant boundary. Record both fences: refusal to update local state and refusal to produce a business effect. Settlement must be idempotent and bound to the current task/key/receipt; stale or inconsistent evidence cannot create fresh budget.

**Overrun boundary.** The old worked policy rejects a charge above its reservation and preserves the reservation. The independent changed requirement adds overrun: after the learner implements that policy at the real hook, actual_units is recorded, the hold remains and further tenant-budget admission freezes. pending_observed_actual_units and pending_uncovered_units expose the debt, while spent is not updated yet. The normal guided run does not prove this changed policy. Manual overrun adjustment is not implemented; write its authority and reconciliation policy as a proposed follow-up rather than reporting zero cost or completed settlement.

**Fill in your decision.** Write status/date/owner, scoped trigger, source/report digests, trusted inputs, alternatives, chosen invariants, failure window, observed counterexample, reversal condition, rollback owner and next missing validation. Quote actual denied and accepted records. If your proposal has no executable proof yet, label it proposed rather than verified.

### ADR 2: migrate without rewriting authority or unknown effects

The following is a migration **design exercise**. The package does not establish a rolling production migration or a completed schema rollback merely by passing its runtime checks. Inventory the real database schema and readers/writers before choosing a change; preserve a reproducible source/database copy for the exercise.

**Example proposal.** Add settlement evidence to an old state record while preserving task identity, tenant, business operation key, worker epoch, consumed budget and existing receipt references. Existing unknown work remains unknown/reconciliation-required. A schema change cannot invent an approval, zero its cost, switch to a new business key or declare it completed. State precisely whether the new field is optional to old readers; do not assume that every old worker ignores extra fields.

**Compatibility sequence to fill in.** List each old/new reader and writer, the exact accepted schema versions and who may execute outstanding work. Stop new admission for the chosen scope. Inspect running/unknown records and reconcile effects under their original keys; do not force an unknown item into no-effect to make migration easier. Make a backup and rehearse an additive mapping on a separate copy. Run old and new read tests, real state/ledger invariants and an idempotent second migration. Resume only with one declared owner for execution and the demonstrated compatible version. If a dual-read or mixed-worker window is proposed, specify which version can write each record and how a stale executor is fenced.

**Rollback sequence to fill in.** State the trigger before rollout. Stop admission, preserve the runtime and independent merchant evidence, fence incompatible workers, reconcile unknown operations, and identify whether rollback means code rollback with an additive schema or an actual data reverse mapping. Once external effects or new settlement evidence exist, restoring an old snapshot alone cannot reverse them. Define information-preserving transforms and test them on the copy; otherwise keep rollback pending and choose a forward repair. A backup file without a restoration rehearsal is not rollback evidence.

**Required artifacts.** Supply before/after schema and representative ready/running/unknown/completed records; exact field mapping; reader/writer compatibility matrix as a list; migration source/digest; failed-before and repaired rerun; second-run idempotence; original runtime regression; a rollback or forward-repair rehearsal; and unresolved cases. Include approval and worker epochs, held reservation and operation key in the invariant checks. Do not mark an unrun script or a written plan as an executed migration.

### Incident: stop, reconcile, resume

Write a one-page incident note from your actual delayed/lost-response run. State the first symptom, time/clock source, task and operation key, worker epoch, known local state, independent merchant effect count, held units and tenant impact. Do not report an unknown outcome as failure or success without its receipt evidence.

1. Stop new admission for the affected scope and name who can change that control. Capture source, configuration, database and merchant evidence before changing state.
2. Fence the stale executor at the runtime and merchant write boundary. A killed process or released local slot cannot undo an already committed return.
3. Query the merchant using the original business key. Separate confirmed effect, safe confirmed no-effect and still unknown; retain holds for unknown. Explain which service is authoritative and why its answer is sufficient at this point.
4. Apply one bound settlement/release under current execution authority, check that a repeated recovery does not double-charge, double-release or duplicate the effect, and compare both ledgers.
5. Resume the declared scope only after the owner reviews the invariant and the relevant regression. Record residual risk, follow-up owner and the condition that stops admission again.

If a proposed operational control is not implemented, identify the missing code/API and exercise it in a separate copy before calling this an operational rehearsal. The guide is a decision worksheet, not a production runbook for an unknown system.

### Handoff: a named responsibility for every boundary

Use role names until real team ownership is agreed. The runtime owner maintains admission, reservation, lease and settlement transactions. The merchant owner maintains current write authority, original-key uniqueness and authoritative receipts. The model/tool owner maintains proposal contracts and reports ambiguous execution instead of inventing success. The review owner defines who can approve the concrete proposal and which approval epoch is current. The data/migration owner owns schema compatibility, backups and forward repair. The evaluation owner checks task-level denominators, failed slices and source-bound artifacts. The incident owner coordinates stop/reconcile/resume and escalation.

For every role fill in input owner, allowed mutation, invariant, failure signal, recovery action, handoff artifact and unresolved dependency. Include one peer review question and the answer supported by an actual record. These are fictional role examples; assigning names in a document is not evidence of observed collaboration or real operational responsibility.

The complete [career responsibility paths](https://ai.lwkjob.com/lab/capstone/CAREER_PATHS.md) still apply. Leave unobserved reviewer decisions, real-provider behavior, production capacity and operational collaboration pending in the [assessment worksheet](https://ai.lwkjob.com/lab/capstone/ASSESSMENT_TEMPLATE.json). This specialty contributes bounded local evidence; it does not certify a whole senior rank.

## 中文

### 先有证据，再使用架构术语

结合[运行时流程](https://ai.lwkjob.com/lab/senior-runtime/README.md)与[独立结算任务](https://ai.lwkjob.com/lab/senior-runtime/LEARNER_TASK.md)。对本机实验的主张附实际源码摘要、进程记录、运行时状态和商家账本；生产方案另写假设与反转条件。写出 distributed fencing、exactly once 或 high availability，不代表已实现对应系统。

引导设计是在一台主机上，由多个 Python 进程共享 SQLite 文件。本机商家在创建退货回执的同一事务内检查任务当前 worker、代次、lease 和准入事实，因此能在实际业务写入处拒绝旧 worker。另一个外部服务若不检查这些事实，仅带本地 epoch 不能为它建立 fence。预算为合成整数单位，预留和结算都不测模型 Token 或金额。

### ADR 1：谁负责准入与结算？

**示范范围与决策。** 有界的虚构售后任务从 Agent 提案，经种子人工审核夹具，到本机商家效果。多 worker 需要同一共享准入决定。采用文件 SQLite 事务维护全局/租户准入、估算预留、worker fencing 和本机结算；商家回执是业务效果证据。未知结果保持预留直到权威对账，本地超时不能证明未产生效果。

**可信假设。** 本机参与进程都能访问 SQLite 文件及其事务行为。运行时配置、租户政策、worker lease、商家回执分别来自服务/存储边界，不来自模型文字或任务自报字段。本机商家能访问同一权威运行时事实；示范采用固定虚构审核/身份数据。复用决策前，写出自己部署改变了哪项假设。

**候选与反转条件。** 每 worker 内存计数器无法在重启或跨进程时保证共享上限。独立协调器与远端商家可支持另一种部署，但须定义 fence/授权协议、持久效果回执及歧义结果处理。worker 分布到多机、商家无法核验当前执行权限、锁等待超出实测本机目标，或共享文件运维前提不成立时，重新评估 SQLite。本机负载报告没有证明这些生产门槛。

**运行前手算。** 明确虚构输入：全局容量 2、每租户容量 1、A 预算 9、B 预算 7。A 预留 4、B 预留 3 后，可用额度 A=5/B=4，占两个槽。A 回执的实际合成扣费为 3 时，结算 A、释放其预留/槽位，A 可用为 6。B 结果未知则保留其预留/槽位，B 可用仍为 4。只有权威且安全的未产生效果结论才能把 B 释放至 7；确认 B 回执后按其实际扣费结算。这是作者编制算例，不是实测报告或提供方账单。自己的运行应抄实际配置，再按账本重算。

**失败窗口与不变量。** worker 可能发写请求，商家已提交而返回丢失。收回本地 lease 不会取消该效果。替代 worker 保留原操作键，查询权威证据，在商家边界防止旧 worker 再造效果。分别记录两道 fence：拒绝本地状态提交、拒绝业务效果。结算须幂等并绑定当前任务/key/回执；过旧或矛盾证据不能凭空生成预算。

**超额边界。** 旧引导政策拒绝超出预留的扣费并保留原预留。独立变化需求增加 overrun：学员政策实现并接入真实 hook 后，记录 actual_units、保留 hold、冻结租户后续预算准入；pending_observed_actual_units、pending_uncovered_units 暴露债务，spent 尚未更新。正常引导运行不证明新政策。人工超额调整未实现，把授权与对账政策写为后续提案，不能报零成本或完成结算。

**填写自己的决策。** 写状态/日期/负责人、具体触发、源码/报告摘要、可信输入、候选、不变量、失败窗口、实际反例、反转条件、回滚负责人和下一项缺失验证。引用实际拒绝与接受记录；方案尚无可运行证明时标 proposed，不能标 verified。

### ADR 2：迁移不能改写授权与未知效果

以下是迁移**设计作业**。运行时检查全通过，不等于本包证明了生产滚动迁移或 schema 回滚。选择变化前先列实际数据库 schema 与读写方，保留可复现的源码/数据库副本。

**示例提案。** 给旧状态增加结算证据，同时保留任务身份、租户、业务操作键、worker 代次、已扣预算及原回执引用。原未知任务保持未知/待对账；schema 变化不能生成批准、清零成本、换业务键或认定完成。明确新字段是否可被旧 reader 忽略，不能默认所有旧 worker 都容忍额外字段。

**填写兼容步骤。** 列出新旧 reader/writer、各自精确接受的 schema 版本，以及谁能执行未完成任务。停止所选范围的新准入；检查运行/未知记录并沿原 key 对账，不能为便于迁移强改未知为无效果。备份，在单独副本演练增量映射，运行新旧读取测试、实际状态/账本不变量和第二次幂等迁移。只有声明唯一执行负责人且已证明版本兼容才恢复；若提双读或混合 worker 窗口，写清各版本能写哪些记录、旧执行器如何被 fence。

**填写回滚步骤。** 上线前定义触发条件。停止准入、保留运行时及独立商家证据、fence 不兼容 worker、对账未知操作，明确是保留增量 schema 的代码回滚，还是实际数据逆向映射。出现外部效果或新结算证据后，仅恢复旧快照不能逆转它们。定义不丢信息的转换并在副本测试；否则保持 rollback pending，选择向前修复。有备份但没演练恢复，不是回滚证据。

**必交产物。** 交前后 schema 与 ready/running/unknown/completed 代表记录、精确字段映射、以列表写的 reader/writer 兼容矩阵、迁移源码/摘要、修改前失败与修后重跑、第二次幂等、原运行时回归、回滚或向前修复演练及未解案例。不变量检查纳入批准代次、worker 代次、保留预留、operation key。未运行脚本或书面计划不能标为已执行迁移。

### 事故：止血、对账、恢复

依据本人真实延迟/丢返回运行写一页记录，包含首个症状、时间/时钟来源、任务与操作键、worker 代次、已知本地状态、独立商家效果数、保留单位和租户影响。无回执证据时，不能把未知结果报成失败或成功。

1. 停止受影响范围的新准入，标明谁能改控制；改状态前保存源码、配置、数据库和商家证据。
2. 在运行时与商家写入边界 fence 旧执行器；杀进程或释放本地槽位不能撤销已提交退货。
3. 沿原业务键查询商家，将确认有效果、安全确认无效果、仍未知分开；未知继续保留。说明哪个服务权威、为何当前答复足够。
4. 在当前执行权限下做一次绑定结算/释放，检查重复恢复不重复扣费、不重复释放、不重复效果，并比两份账本。
5. 负责人复核不变量及相关回归后，才恢复声明范围；记录剩余风险、后续 owner、再次停准入条件。

若运营控制尚未实现，指出缺失代码/API，在独立副本演练后才称运营演练。本指南是决策填写表，不是未知生产系统的运行手册。

### 交接：每个边界都有职责

真实团队明确前用角色名。运行时 owner 维护准入、预留、lease、结算事务；商家 owner 维护当前写入权限、原键唯一效果与权威回执；模型/工具 owner 维护提案合同并报告歧义执行，不能编成功；审核 owner 定义谁能批准具体提案、哪个批准代次当前有效；数据/迁移 owner 负责 schema 兼容、备份、向前修复；评测 owner 检查任务分母、失败切片和源码绑定产物；事故 owner 协调止血/对账/恢复与升级。

每个角色填写输入负责人、允许变更、不变量、失败信号、恢复动作、交接产物及未解依赖；附一项同行评审问题和由实际记录支持的回答。这些是虚构角色示例，文档里分配名称不能证明观察到协作或真实运维责任。

完整[职责路径](https://ai.lwkjob.com/lab/capstone/CAREER_PATHS.md)仍适用。[评审记录](https://ai.lwkjob.com/lab/capstone/ASSESSMENT_TEMPLATE.json)中未观察评审决定、真实提供方、生产容量、运维协作保持 pending。本专题贡献有界本机证据，不认证整个资深职级。
