Skip to content

Commit 1886938

Browse files
committed
fix(lifecycle): stop rejected subtask replay loops
1 parent 08d05eb commit 1886938

9 files changed

Lines changed: 513 additions & 108 deletions

File tree

‎docs/architecture/task-lifecycle-gap-report.md‎

Lines changed: 61 additions & 47 deletions
Large diffs are not rendered by default.

‎docs/architecture/task-lifecycle-model.md‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@ TLA+/PlusCal or Quint with TLC becomes a better fit when the lifecycle needs tem
4848
| `interrupt(child)` | cancellation or eviction through `markDelegatedChildInterrupted` |
4949
| `complete(child)` | `ClineProvider.reopenParentFromDelegation` |
5050
| `abandon(child)` | `ClineProvider.abandonSubtask` |
51+
| Pending-action settlement | `settleRejectedCreateSubtaskAction` inside the delegation update path (#1714) |
5152
| Atomic event step | `atomicReadAndUpdate`, `atomicUpdatePair`, and per-parent delegation transition lock |
5253
| Event interleaving | Competing completion, cancellation, abandonment, and new delegation calls |
5354

5455
The model has three fixed task slots, enough to cover competing siblings and a nested parent-child-grandchild chain. It explores every reachable interleaving through depth 12, deduplicating canonical states. Representative checks also exercise rejected operations that do not create a new state: a second concurrent delegation while the first child is active, stale completion after re-delegation, late completion after abandonment, completion after interruption, and nested completion. Named semantic landmarks require the graph to retain interrupted-child re-delegation and nested delegation even when the raw state total changes.
5556

57+
Each task slot can also hold one of two pending `create_subtask` actions. A `stage` action mirrors `setPendingTaskAction` overwrite semantics, delegation and completion clear the action their request carried, and a `settle-rejected` action models the settlement that follows an authoritative delegation rejection (#1714). Production settles through the typed `LifecycleTransitionError` from the shared guards: the provider writes the settled record with one extra `atomicReadAndUpdate` call, then propagates the original rejection. Three named witnesses must remain reachable: settlement from an interrupted record after rejection, settlement through a successful active delegation, and stale-action protection where a settlement targeting one action ID leaves a replacement action intact. A mismatched pending-action request keeps its production behavior: the atomic update throws before any transition, and no settlement runs.
58+
5659
Production completion also accepts a recovery-compatible `active` parent that still awaits the returning child, then clears the stale pointers. Normal model transitions never create that intermediate state, so it is covered by a focused reducer test rather than admitted as a generally valid reachable state.
5760

5861
## Shared-store concurrency model
@@ -134,6 +137,7 @@ The task delegation checker currently enforces:
134137
5. Parent-child lineage is acyclic.
135138
6. Completed task records cannot be changed by later lifecycle events.
136139
7. Active-child re-delegation, stale completion after ownership moves to another child, duplicate/late completion, and abandonment of a live child are rejected by the shared production guards.
140+
8. A rejected delegation settles only the exact matching pending `create_subtask` action. Settlement preserves status, lineage, and accounting, never clears a replacement or different-kind action, and never mutates a completed record.
137141

138142
The completion persistence checker additionally enforces:
139143

@@ -147,15 +151,15 @@ These are safety claims within the documented bounds. The checks do not claim li
147151

148152
## Coverage audit
149153

150-
| Protocol area | Coverage status | Production/model relationship | Explicit limits and open points |
151-
| ------------------------------ | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
152-
| Delegation lifecycle | Production-backed bounded universal | The explorer calls the four production reducers for three task slots through depth 12. | Excludes provider instances, persistence failures, scheduler state, most live `Task` behavior, and generation identity for delayed pre-interruption completion. Recovery-compatible active-parent completion is test-only. |
153-
| Shared-store concurrency | Production-backed bounded scenarios plus known-unsafe witnesses | The explorer imports production delta/merge functions and reducers; a real-filesystem test is a smoke check. | Does not prove crash safety, filesystem/lock semantics, arbitrary processes, or loss-free same-field merging. #1469 and #1021 remain unsafe. |
154-
| Provider handoff and scheduler | Mixed: production-backed reducers/selector plus abstract bounded protocol | Commits use production reducers; provider ownership, publication, transition locks, and permits are model abstractions through depth 15. | Selector correctness does not refine all downstream readers. Scheduler tests cover concrete permit behavior separately. |
155-
| Optional fan-out scope | Planned-only abstract bounded protocol outside baseline CI | The model has two sibling slots and two abstract permits and imports no production fan-out transition. | Excluded from baseline closure; production fan-out remains separately scoped future functionality. |
156-
| Cleanup | Abstract bounded universal plus adapter tests | Abort, disposal, settlement, rejection, and provider shutdown are modeled as protocol/environment actions. | No direct execution of all production cleanup methods, filesystem/editor promises, timing liveness, fairness, or arbitrary task counts. |
157-
| Parser request scope | Production-backed bounded schedule replay | The checker executes production parser APIs across 924 order-preserving schedules for two scopes. | Assumes callers stop invoking a finalized scope; transport behavior, arbitrary request counts, indices, and malformed histories are outside the claim. |
158-
| Completion persistence | Abstract bounded universal plus production tests and one fresh-host E2E path | The model abstracts persistence as a durable phase with at most two write starts; production guards and retry paths are tested separately. | Production permits more retries; no power-loss/filesystem proof, fairness, arbitrary retry count, complete delegated fallback, provider status metadata, or downstream event-consumer model. |
154+
| Protocol area | Coverage status | Production/model relationship | Explicit limits and open points |
155+
| ------------------------------ | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
156+
| Delegation lifecycle | Production-backed bounded universal | The explorer calls the production lifecycle and settlement reducers for three task slots through depth 12. | Excludes provider instances, persistence failures, scheduler state, most live `Task` behavior, and generation identity for delayed pre-interruption completion. Recovery-compatible active-parent completion is test-only. Settlement models the matching-action request only; a mismatched action aborts the update unmodeled. |
157+
| Shared-store concurrency | Production-backed bounded scenarios plus known-unsafe witnesses | The explorer imports production delta/merge functions and reducers; a real-filesystem test is a smoke check. | Does not prove crash safety, filesystem/lock semantics, arbitrary processes, or loss-free same-field merging. #1469 and #1021 remain unsafe. |
158+
| Provider handoff and scheduler | Mixed: production-backed reducers/selector plus abstract bounded protocol | Commits use production reducers; provider ownership, publication, transition locks, and permits are model abstractions through depth 15. | Selector correctness does not refine all downstream readers. Scheduler tests cover concrete permit behavior separately. |
159+
| Optional fan-out scope | Planned-only abstract bounded protocol outside baseline CI | The model has two sibling slots and two abstract permits and imports no production fan-out transition. | Excluded from baseline closure; production fan-out remains separately scoped future functionality. |
160+
| Cleanup | Abstract bounded universal plus adapter tests | Abort, disposal, settlement, rejection, and provider shutdown are modeled as protocol/environment actions. | No direct execution of all production cleanup methods, filesystem/editor promises, timing liveness, fairness, or arbitrary task counts. |
161+
| Parser request scope | Production-backed bounded schedule replay | The checker executes production parser APIs across 924 order-preserving schedules for two scopes. | Assumes callers stop invoking a finalized scope; transport behavior, arbitrary request counts, indices, and malformed histories are outside the claim. |
162+
| Completion persistence | Abstract bounded universal plus production tests and one fresh-host E2E path | The model abstracts persistence as a durable phase with at most two write starts; production guards and retry paths are tested separately. | Production permits more retries; no power-loss/filesystem proof, fairness, arbitrary retry count, complete delegated fallback, provider status metadata, or downstream event-consumer model. |
159163

160164
The production mapping above names primary lifecycle transitions, not every mutation or consumer. Generic store upserts, reconciliation, repair replay, migrations, tool entry points, webview/public API abandonment, provider status updates, and public `TaskCompleted` re-emission remain outside the persisted reducer graph unless explicitly named by a submodel or focused test. For task-local mode, the consumers named under #921/#1623 are a confirmed set, not an exhaustive repository-wide inventory; other mode-sensitive tools must be audited before claiming universal reader isolation.
161165

@@ -197,6 +201,7 @@ The [Task lifecycle verification GAP report](./task-lifecycle-gap-report.md) is
197201
- Shared status vocabulary: [#612](https://github.com/Zoo-Code-Org/Zoo-Code/issues/612).
198202
- Completion visibility history: [#1453](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1453) and [#1279](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1279).
199203
- Cross-instance history preservation: [#920](https://github.com/Zoo-Code-Org/Zoo-Code/issues/920).
204+
- Rejected-delegation pending-action settlement: [#1714](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1714).
200205
- Parser request scoping: [#1468](https://github.com/Zoo-Code-Org/Zoo-Code/issues/1468).
201206

202207
## Extending the model

0 commit comments

Comments
 (0)