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 86715bc
Browse filesBrowse the repository at this point in the historyBrowse files
fix(delegation): make the repair commit mutually exclusive with a local claim
What: `safeWriteJson` gains a synchronous `preCommit` hook that runs
immediately before the commit rename with no await in between, and
`writeAdministrativeRepair` uses it to re-run the repair guard and the
in-window ownership predicate at the commit point. The post-commit claim
release is removed.
Why: the round-1 guard was merge-time only. `markLocallyActive` is
synchronous and takes no lock, so a claim landing during the temp-write
awaits was invisible to it: the repair committed the child as
`interrupted` and the parent as `active`, and releasing the claim
afterwards undid nothing. A live resumed child was left interrupted and
orphaned. Re-running the guard at the commit point aborts with NOTHING
committed, so the parent half never runs and the live session keeps its
record, its claim, and its delegation link. The same hook closes the
missing-child cross-lock gap: the child-file absence check is now
re-evaluated immediately before the parent rename.
Impact: both the in-pass (`applyDelegationRepairIntent`) and replay
(`replayDelegationRepairIntent`) paths get the protocol, since both write
through `writeAdministrativeRepair`. The regression test now asserts
child `active`, parent `delegated`, and the claim retained. Stale
sentinel comments (threshold-1 / strict bound) are corrected in
taskLifecycle.ts, its spec, TaskHistoryStore, and the lifecycle checker.
@@ -636,12 +639,9 @@ export class TaskHistoryStore {
636
639
continue
637
640
}
638
641
// Re-check local ownership after the async stat await: the
639
-
// persistedActiveIds snapshot was captured before this point, and
640
-
// ClineProvider can claim the child for a live session in THIS
641
-
// window (markLocallyActive, the eager claim in
642
-
// createTaskWithHistoryItemUnlocked) while getChildFileMtimeMs was
643
-
// in flight. The snapshot no longer reflects that claim, so the
644
-
// child is no longer a crash orphan — skip the repair.
642
+
// persistedActiveIds snapshot predates it, and ClineProvider can
643
+
// claim the child for a live session in THIS window while the probe
644
+
// was in flight, so the child is no longer a crash orphan.
645
645
if(this.locallyActiveTaskIds.has(child.id)){
646
646
console.warn(
647
647
`[TaskHistoryStore] Skipping repair for live child ${child.id} `+
@@ -864,13 +864,7 @@ export class TaskHistoryStore {
864
864
// Cross-instance liveness guard (same convention as reconcileDelegationStateCore): if this window crashed mid-repair and another window restarted the same child, the child's history file is being actively persisted there. Replaying the stale intent would overwrite the live child as "interrupted", so quarantine it instead. Only enforced when the replay would actually write the child record: a child already at its target needs no write, and parent-only completion must not be blocked by child liveness. A fresh mtime OR a fresh `lastActivityAt` heartbeat quarantines the intent; a transient stat failure reports the near-future sentinel (see `getChildFileMtimeMs`), which also counts as life and lets a later tick retry.
// A claim that landed after the guard but before this commit describes a session that started once the repair had already decided the record was an orphan. The write above interrupted it, so release the claim instead of letting it shield the interrupted child forever.
0 commit comments