=== acquire_task_lease: a free task
CALL queue_commit_write
METRIC {"event":"lease_acquired","task_id":"T-1","pid":<SELF>,"ttl_s":900,"at":"2026-10-18T00:00:00+00:00"}
rc=0
-- queue.txt:
   # queue
   # [RUNNING] harness/stories/STORY-1/tasks/T-1.md#t-1
   harness/stories/STORY-1/tasks/T-2.md#t-2
   harness/stories/STORY-2/tasks/T-3.md#t-3
   harness/stories/STORY-2/tasks/T-4.md#t-4
   harness/stories/STORY-3/tasks/T-5.md#t-5
-- lease T-1:
   pid: <N>
   pid_start: <N>
   lane_id: 1
   worktree: 
   base_sha: <SHA>
   started_at: 1792281600
   heartbeat_at: 1792281600
   spec: harness/stories/STORY-1/tasks/T-1.md#t-1
   (heartbeat.pid present)
-- CURRENT_LEASE_TASK_ID=[T-1] LEASE_SWEEP_RETAINED_LANE=[false]
-- LANE_HEARTBEAT_PIDS keys: T-1=set 
=== acquire_task_lease: the same task again (lease held — a deferral)
LOG   Defer (lease held): T-1 is already owned — not a failure, re-evaluated next pass
METRIC {"event":"lease_contended","task_id":"T-1","at":"2026-10-18T00:00:00+00:00"}
rc=1
-- queue.txt:
   # queue
   # [RUNNING] harness/stories/STORY-1/tasks/T-1.md#t-1
   harness/stories/STORY-1/tasks/T-2.md#t-2
   harness/stories/STORY-2/tasks/T-3.md#t-3
   harness/stories/STORY-2/tasks/T-4.md#t-4
   harness/stories/STORY-3/tasks/T-5.md#t-5
-- CURRENT_LEASE_TASK_ID=[T-1] LEASE_SWEEP_RETAINED_LANE=[false]
-- LANE_HEARTBEAT_PIDS keys: T-1=set 
=== acquire_task_lease: a second task (concurrent mode keys both heartbeats)
CALL queue_commit_write
METRIC {"event":"lease_acquired","task_id":"T-2","pid":<SELF>,"ttl_s":900,"at":"2026-10-18T00:00:00+00:00"}
rc=0
-- queue.txt:
   # queue
   # [RUNNING] harness/stories/STORY-1/tasks/T-1.md#t-1
   # [RUNNING] harness/stories/STORY-1/tasks/T-2.md#t-2
   harness/stories/STORY-2/tasks/T-3.md#t-3
   harness/stories/STORY-2/tasks/T-4.md#t-4
   harness/stories/STORY-3/tasks/T-5.md#t-5
-- lease T-2:
   pid: <N>
   pid_start: <N>
   lane_id: 2
   worktree: 
   base_sha: <SHA>
   started_at: 1792281600
   heartbeat_at: 1792281600
   spec: harness/stories/STORY-1/tasks/T-2.md#t-2
   (heartbeat.pid present)
-- CURRENT_LEASE_TASK_ID=[T-2] LEASE_SWEEP_RETAINED_LANE=[false]
-- LANE_HEARTBEAT_PIDS keys: T-1=set T-2=set 
-- T-1's heartbeat after T-2's acquire: alive
=== release_task_lease: releases CURRENT (T-2) and its heartbeat entry only
rc=0
-- lease T-1:
   pid: <N>
   pid_start: <N>
   lane_id: 1
   worktree: 
   base_sha: <SHA>
   started_at: 1792281600
   heartbeat_at: 1792281600
   spec: harness/stories/STORY-1/tasks/T-1.md#t-1
   (heartbeat.pid present)
-- lease T-2: (none)
-- CURRENT_LEASE_TASK_ID=[] LEASE_SWEEP_RETAINED_LANE=[false]
-- LANE_HEARTBEAT_PIDS keys: T-1=set 
-- T-1's heartbeat after T-2's release: alive
=== release_task_lease: nothing held — a no-op
rc=0
-- CURRENT_LEASE_TASK_ID=[] LEASE_SWEEP_RETAINED_LANE=[false]
-- LANE_HEARTBEAT_PIDS keys: T-1=set 
=== release_lane_lease: empty id
rc=0
=== release_lane_lease: T-1, which is not CURRENT
rc=0
-- lease T-1: (none)
-- CURRENT_LEASE_TASK_ID=[T-9] LEASE_SWEEP_RETAINED_LANE=[false]
-- LANE_HEARTBEAT_PIDS keys: 
-- T-1's heartbeat after its release: STOPPED
=== release_lane_lease: a task that IS CURRENT clears it
rc=0
-- lease T-3: (none)
-- CURRENT_LEASE_TASK_ID=[] LEASE_SWEEP_RETAINED_LANE=[false]
-- LANE_HEARTBEAT_PIDS keys: 
-- queue.txt:
   # queue
   # [RUNNING] harness/stories/STORY-1/tasks/T-1.md#t-1
   # [RUNNING] harness/stories/STORY-1/tasks/T-2.md#t-2
   # [RUNNING] harness/stories/STORY-2/tasks/T-3.md#t-3
   harness/stories/STORY-2/tasks/T-4.md#t-4
   harness/stories/STORY-3/tasks/T-5.md#t-5
=== reconcile_abandoned_task: no lane recorded, startup trigger
CALL queue_commit_write
METRIC {"event":"lease_expired","task_id":"T-3","reason":"pid-dead","trigger":"startup","branch":"factory/task/T-3","tag":"","pid":"","heartbeat_age_s":"","at":"2026-10-18T00:00:00+00:00"}
LOG   Lease reconciled: T-3 (pid-dead) -> pending; branch factory/task/T-3; lane none recorded
CALL write_blocker [T-3] [harness/stories/STORY-2/tasks/T-3.md#t-3] [lease-expired (pid-dead)] [ctl/harness/state/logs/session.log]
   | - Recovered by: lease sweep (pid-dead)
   | - Lane: none recorded
   | - Base SHA: unknown
   | - Branch: factory/task/T-3
   | - Owner pid: unknown (dead)
   | - Heartbeat age at sweep: unknown
   | - Uncommitted work: none found
   | - Queue: returned to PENDING (not FAILED — an infrastructure event is never a task failure)
rc=0
-- queue.txt:
   # queue
   # [RUNNING] harness/stories/STORY-1/tasks/T-1.md#t-1
   # [RUNNING] harness/stories/STORY-1/tasks/T-2.md#t-2
   harness/stories/STORY-2/tasks/T-3.md#t-3
   harness/stories/STORY-2/tasks/T-4.md#t-4
   harness/stories/STORY-3/tasks/T-5.md#t-5
-- CURRENT_LEASE_TASK_ID=[] LEASE_SWEEP_RETAINED_LANE=[false]
-- LANE_HEARTBEAT_PIDS keys: 
=== reconcile_abandoned_task: park trigger writes no blocker
CALL queue_commit_write
CALL queue_commit_write
METRIC {"event":"lease_expired","task_id":"T-3","reason":"pid-dead","trigger":"park","branch":"factory/task/T-3","tag":"","pid":"4242","heartbeat_age_s":"17","at":"2026-10-18T00:00:00+00:00"}
LOG   Lease reconciled: T-3 (pid-dead) -> pending; branch factory/task/T-3; lane none recorded
rc=0
-- queue.txt:
   # queue
   # [RUNNING] harness/stories/STORY-1/tasks/T-1.md#t-1
   # [RUNNING] harness/stories/STORY-1/tasks/T-2.md#t-2
   harness/stories/STORY-2/tasks/T-3.md#t-3
   harness/stories/STORY-2/tasks/T-4.md#t-4
   harness/stories/STORY-3/tasks/T-5.md#t-5
=== reconcile_abandoned_task: a clean lane with a committed branch (tagged, freed), live pid
CALL queue_commit_write
METRIC {"event":"lease_expired","task_id":"T-4","reason":"implausibly-old","trigger":"startup","branch":"factory/task/T-4","tag":"factory/abandoned/T-4-20261018-000000","pid":"<SELF>","heartbeat_age_s":"30","at":"2026-10-18T00:00:00+00:00"}
LOG   Lease reconciled: T-4 (implausibly-old) -> pending; branch factory/task/T-4 tagged factory/abandoned/T-4-20261018-000000; lane freed
CALL write_blocker [T-4] [harness/stories/STORY-2/tasks/T-4.md#t-4] [lease-expired (implausibly-old)] [ctl/harness/state/logs/session.log]
   | - Recovered by: lease sweep (implausibly-old)
   | - Lane: freed
   | - Base SHA: <SHA>
   | - Branch: factory/task/T-4 (preserved as tag factory/abandoned/T-4-20261018-000000)
   | - Owner pid: <SELF> (alive)
   | - Heartbeat age at sweep: 30s
   | - Uncommitted work: none found
   | - Queue: returned to PENDING (not FAILED — an infrastructure event is never a task failure)
rc=0
-- tags:
   factory/abandoned/T-4-20261018-000000
-- worktrees:
   worktree <T>/ctl
   branch refs/heads/main
-- CURRENT_LEASE_TASK_ID=[] LEASE_SWEEP_RETAINED_LANE=[false]
-- LANE_HEARTBEAT_PIDS keys: 
=== reconcile_abandoned_task: a dirty lane (captured, RETAINED), no spec, dead pid
METRIC {"event":"lease_expired","task_id":"T-5","reason":"pid-dead","trigger":"startup","branch":"factory/task/T-5","tag":"factory/abandoned/T-5-20261018-000000","pid":"999999999","heartbeat_age_s":"","at":"2026-10-18T00:00:00+00:00"}
LOG   Lease reconciled: T-5 (pid-dead) -> pending; branch factory/task/T-5 tagged factory/abandoned/T-5-20261018-000000; lane RETAINED at <T>/lanes/2 (uncommitted work — not deleted)
CALL write_blocker [T-5] [<no spec recorded>] [lease-expired (pid-dead)] [ctl/harness/state/logs/session.log]
   | - Recovered by: lease sweep (pid-dead)
   | - Lane: RETAINED at <T>/lanes/2 (uncommitted work — not deleted)
   | - Base SHA: unknown
   | - Branch: factory/task/T-5 (preserved as tag factory/abandoned/T-5-20261018-000000)
   | - Owner pid: 999999999 (dead)
   | - Heartbeat age at sweep: unknown
   | - Uncommitted work: <T>/ctl/harness/state/stashed/20261018-000000-T-5-abandoned
   | - Queue: returned to PENDING (not FAILED — an infrastructure event is never a task failure)
rc=0
-- tags:
   factory/abandoned/T-4-20261018-000000
   factory/abandoned/T-5-20261018-000000
-- worktrees:
   worktree <T>/ctl
   branch refs/heads/main
   worktree <T>/lanes/2
   branch refs/heads/factory/task/T-5
-- CURRENT_LEASE_TASK_ID=[] LEASE_SWEEP_RETAINED_LANE=[true]
-- LANE_HEARTBEAT_PIDS keys: 
-- stash dir:
   == ./20261018-000000-T-5-abandoned/README.md
      (16 lines)
   == ./20261018-000000-T-5-abandoned/base.sha
      <SHA>
   == ./20261018-000000-T-5-abandoned/restore.sh
      (34 lines)
   == ./20261018-000000-T-5-abandoned/tracked.patch
      diff --git a/README.md b/README.md
      index df967b9..2ecd216 100644
      --- a/README.md
      +++ b/README.md
      @@ -1 +1,2 @@
       base
      +changed
   == ./20261018-000000-T-5-abandoned/untracked.txt
      scratch-T-5.txt
   == ./20261018-000000-T-5-abandoned/untracked/scratch-T-5.txt
      uncommitted
-- queue.txt:
   # queue
   # [RUNNING] harness/stories/STORY-1/tasks/T-1.md#t-1
   # [RUNNING] harness/stories/STORY-1/tasks/T-2.md#t-2
   harness/stories/STORY-2/tasks/T-3.md#t-3
   harness/stories/STORY-2/tasks/T-4.md#t-4
   harness/stories/STORY-3/tasks/T-5.md#t-5
=== sweep_leases startup: dead-owner lease (A), live lease (A, untouched), orphaned [RUNNING] (B), live [RUNNING] (B, untouched), stale resume records (C)
METRIC {"event":"lease_expired","task_id":"ORPHAN-KEY","reason":"pid-dead","trigger":"startup","branch":"factory/task/ORPHAN-KEY","tag":"","pid":"<DEAD>","heartbeat_age_s":"90","at":"2026-10-18T00:00:00+00:00"}
LOG   Lease reconciled: ORPHAN-KEY (pid-dead) -> pending; branch factory/task/ORPHAN-KEY; lane none recorded
CALL write_blocker [ORPHAN-KEY] [<no spec recorded>] [lease-expired (pid-dead)] [ctl/harness/state/logs/session.log]
   | - Recovered by: lease sweep (pid-dead)
   | - Lane: none recorded
   | - Base SHA: unknown
   | - Branch: factory/task/ORPHAN-KEY
   | - Owner pid: <DEAD> (dead)
   | - Heartbeat age at sweep: 90s
   | - Uncommitted work: none found
   | - Queue: returned to PENDING (not FAILED — an infrastructure event is never a task failure)
CALL queue_commit_write
METRIC {"event":"lease_expired","task_id":"T-1","reason":"pid-dead","trigger":"startup","branch":"factory/task/T-1","tag":"","pid":"<DEAD>","heartbeat_age_s":"90","at":"2026-10-18T00:00:00+00:00"}
LOG   Lease reconciled: T-1 (pid-dead) -> pending; branch factory/task/T-1; lane none recorded
CALL write_blocker [T-1] [harness/stories/STORY-1/tasks/T-1.md#t-1] [lease-expired (pid-dead)] [ctl/harness/state/logs/session.log]
   | - Recovered by: lease sweep (pid-dead)
   | - Lane: none recorded
   | - Base SHA: def5678
   | - Branch: factory/task/T-1
   | - Owner pid: <DEAD> (dead)
   | - Heartbeat age at sweep: 90s
   | - Uncommitted work: none found
   | - Queue: returned to PENDING (not FAILED — an infrastructure event is never a task failure)
CALL queue_commit_write
METRIC {"event":"lease_expired","task_id":"T-3","reason":"orphaned-running-line","trigger":"startup","branch":"factory/task/T-3","tag":"","pid":"","heartbeat_age_s":"","at":"2026-10-18T00:00:00+00:00"}
LOG   Lease reconciled: T-3 (orphaned-running-line) -> pending; branch factory/task/T-3; lane none recorded
CALL write_blocker [T-3] [harness/stories/STORY-2/tasks/T-3.md#t-3] [lease-expired (orphaned-running-line)] [ctl/harness/state/logs/session.log]
   | - Recovered by: lease sweep (orphaned-running-line)
   | - Lane: none recorded
   | - Base SHA: unknown
   | - Branch: factory/task/T-3
   | - Owner pid: unknown (dead)
   | - Heartbeat age at sweep: unknown
   | - Uncommitted work: none found
   | - Queue: returned to PENDING (not FAILED — an infrastructure event is never a task failure)
CALL resume_sweep [86400]
LOG Lease sweep (startup): retired 2 stale resume record(s) into <T>/ctl/harness/state/stashed.
LOG Lease sweep (startup): reconciled 3 abandoned task(s) back to pending.
METRIC {"event":"lease_sweep","trigger":"startup","reconciled":3,"at":"2026-10-18T00:00:00+00:00"}
rc=0
-- queue.txt:
   # queue
   harness/stories/STORY-1/tasks/T-1.md#t-1
   # [RUNNING] harness/stories/STORY-1/tasks/T-2.md#t-2
   harness/stories/STORY-2/tasks/T-3.md#t-3
   harness/stories/STORY-2/tasks/T-4.md#t-4
   harness/stories/STORY-3/tasks/T-5.md#t-5
-- lease T-1: (none)
-- lease T-2:
   pid: <N>
   pid_start: <N>
   lane_id: 1
   worktree: 
   base_sha: def5678
   started_at: 1792281480
   heartbeat_at: 1792281510
   spec: harness/stories/STORY-1/tasks/T-2.md#t-2
-- lease ORPHAN-KEY: (none)
-- CURRENT_LEASE_TASK_ID=[] LEASE_SWEEP_RETAINED_LANE=[false]
-- LANE_HEARTBEAT_PIDS keys: 
=== sweep_leases park: only the live lease is left — nothing to reconcile, no resume pass
LOG Lease sweep (park): nothing to reconcile.
METRIC {"event":"lease_sweep","trigger":"park","reconciled":0,"at":"2026-10-18T00:00:00+00:00"}
rc=0
=== sweep_leases (default trigger), resume sweep retiring nothing
CALL queue_commit_write
METRIC {"event":"lease_expired","task_id":"T-2","reason":"orphaned-running-line","trigger":"startup","branch":"factory/task/T-2","tag":"","pid":"","heartbeat_age_s":"","at":"2026-10-18T00:00:00+00:00"}
LOG   Lease reconciled: T-2 (orphaned-running-line) -> pending; branch factory/task/T-2; lane none recorded
CALL write_blocker [T-2] [harness/stories/STORY-1/tasks/T-2.md#t-2] [lease-expired (orphaned-running-line)] [ctl/harness/state/logs/session.log]
   | - Recovered by: lease sweep (orphaned-running-line)
   | - Lane: none recorded
   | - Base SHA: unknown
   | - Branch: factory/task/T-2
   | - Owner pid: unknown (dead)
   | - Heartbeat age at sweep: unknown
   | - Uncommitted work: none found
   | - Queue: returned to PENDING (not FAILED — an infrastructure event is never a task failure)
CALL resume_sweep [86400]
LOG Lease sweep (startup): reconciled 1 abandoned task(s) back to pending.
METRIC {"event":"lease_sweep","trigger":"startup","reconciled":1,"at":"2026-10-18T00:00:00+00:00"}
rc=0
-- queue.txt:
   # queue
   harness/stories/STORY-1/tasks/T-1.md#t-1
   harness/stories/STORY-1/tasks/T-2.md#t-2
   harness/stories/STORY-2/tasks/T-3.md#t-3
   harness/stories/STORY-2/tasks/T-4.md#t-4
   harness/stories/STORY-3/tasks/T-5.md#t-5
