You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b267ac7
Browse filesBrowse the repository at this point in the historyBrowse files
fix(delegation): close the four confirmed #1495 liveness and repair races
What:
- Task.ts stops the delegated-child liveness heartbeat on the non-abort
rejection paths of startTask and resumeTaskFromHistory. ClineProvider's
cleanupFailedHistoryTask no longer returns early for non-settlement errors,
so every failed scheduled run tears the task down.
- isLivenessSignalFresh bounds the future side of the freshness window
(Math.abs(now - timestamp) < thresholdMs). getChildFileMtimeMs moves its
transient-stat sentinel one millisecond inside that bound so it still reads
as live, and both comments document the threat model.
- assertChildRepairPreconditions aborts when the locked disk record is absent,
so mergeHistoryDelta can no longer resurrect a peer-deleted child from the
stale cache copy. writeAdministrativeRepair releases a local ownership claim
that lands after the guard but before the commit, because the guard's own
check is synchronous and cannot see it.
- recordTaskActivity's merge callback skips a beat whose ownership was
released, so a heartbeat queued before markLocallyInactive cannot refresh
mtime and lastActivityAt for a session that is gone.
Why:
Each of these let a dead delegated child keep looking alive, or let a repair
recreate a record a peer had deleted. The parent then stayed delegated to a
child no session owned, across startup and every periodic tick, which is the
#1469 bug class this PR exists to close.
Impact:
Production change holds the mutation-diff gate at 498 of 500 changed
executable lines, the same total the branch carried before this round. New
coverage lives in spec files, which the gate excludes. Lifecycle mutations stay
in the shared reducers; the model doc and its liveness comment now describe the
bounded window and the sentinel.
|`markLiveElsewhere(child)` / `expireLiveElsewhere(child)`| child history-file mtime recent vs stale past `LIVE_CHILD_MTIME_THRESHOLD_MS` (abstracted; no wall clock in model) |
55
-
|`heartbeat(child)` / `expireHeartbeat(child)`| persisted `lastActivityAt` liveness heartbeat fresh vs stale past `LIVE_CHILD_MTIME_THRESHOLD_MS` (production: the owning session's throttled heartbeat across the child's whole active lifetime — long streaming turns, long tool calls, and ask-idle periods alike — shared predicate `isDelegatedChildLive`) |
|`markLiveElsewhere(child)` / `expireLiveElsewhere(child)`| child history-file mtime inside the bounded freshness window (`\|now - mtime\| < LIVE_CHILD_MTIME_THRESHOLD_MS`) vs outside it; the store's transient-stat sentinel sits one millisecond inside the future bound (abstracted; no wall clock in model)|
55
+
|`heartbeat(child)` / `expireHeartbeat(child)`| persisted `lastActivityAt` liveness heartbeat fresh vs stale against the same bounded window (production: the owning session's throttled heartbeat across the child's whole active lifetime — long streaming turns, long tool calls, and ask-idle periods alike — shared predicate `isDelegatedChildLive`) |
| Event interleaving | Competing completion, cancellation, abandonment, and new delegation calls |
58
58
59
59
The model has three fixed task slots, enough to cover competing siblings and a nested parent-child-grandchild chain, plus two abstract booleans per slot recording whether an active child's session shows life: one for ownership by another window (recent history-file mtime) and one for a fresh persisted `lastActivityAt` heartbeat from the owning session. 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, a delegated parent whose active child is live in another window surviving startup reconciliation unchanged, a delegated parent whose active child heartbeats through a long streaming turn (stale mtime, fresh `lastActivityAt`) likewise surviving unchanged, and a stale-mtime, stale-heartbeat (crash-orphan) active child being repaired to `interrupted` with the parent returned to `active` only through `reconcileStartup`.
60
60
@@ -178,7 +178,7 @@ The task delegation checker currently enforces:
178
178
5. Parent-child lineage is acyclic.
179
179
6. Completed task records cannot be changed by later lifecycle events.
180
180
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.
181
-
8. No transition may clear a delegated parent's link to a child that is active and live, where live means either marked live-elsewhere (`ModelState.liveElsewhere` true, recent history-file mtime) or heartbeat-alive (`ModelState.heartbeatAlive` true, fresh persisted `lastActivityAt`); reconciliation repairs the link only when both flags are false. This encodes the PR #1495 cross-window misrepair bug class — which broke delegation links so subtask completion could not return to the parent — extended by the liveness-heartbeat fix so a child streaming a long turn (minutes without any other history-file write) is likewise preserved.
181
+
8. No transition may clear a delegated parent's link to a child that is active and live, where live means either marked live-elsewhere (`ModelState.liveElsewhere` true, history-file mtime inside the bounded freshness window) or heartbeat-alive (`ModelState.heartbeatAlive` true, fresh persisted `lastActivityAt` inside the same window); reconciliation repairs the link only when both flags are false. This encodes the PR #1495 cross-window misrepair bug class — which broke delegation links so subtask completion could not return to the parent — extended by the liveness-heartbeat fix so a child streaming a long turn (minutes without any other history-file write) is likewise preserved. The window is bounded in BOTH directions: a timestamp far ahead of `now` (clock rollback, restored archive) is not evidence of life, and only the store's transient-stat sentinel, one millisecond inside the future bound, is treated as fresh.
182
182
9. 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. The settlement compare-and-clear reads the persisted record under the per-file lock, so it never clears from a stale host cache.
183
183
10. A completion clears the completing child's pending action only when the completion event carries the exact matching action ID. A completion with no action ID or a different ID preserves the pending action.
0 commit comments