Skip to content

fix: allow stale task cleanup when a pool slot has a new owner - #5993

Open
QIanGua wants to merge 3 commits into
kunchenguid:mainfrom
QIanGua:fm/teardown-slot-collision-held-unlanded
Open

QIanGua wants to merge 3 commits into
kunchenguid:mainfrom
QIanGua:fm/teardown-slot-collision-held-unlanded

Conversation

@QIanGua

@QIanGua QIanGua commented Sep 28, 2026

Copy link
Copy Markdown

Intent

The captain asked whether a Cursor model can be used to carry out a task, and approved running one real task end to end on that runtime; the concrete task chosen for that run is the recorded cleanup deadlock below.
What must be true when this is done: cleaning up a finished task no longer deadlocks when its recorded pool slot is also named by another task's record. Whichever record no longer owns the slot must still be able to complete its own cleanup, while the slot's current owner and its copy, processes, and claim are left completely untouched. A record that genuinely still owns its slot keeps refusing exactly as it does today.

Observed 2026-09-14 in this home, in its own terms: a new scout was handed a Treehouse pool slot that two earlier tasks still record as their own worktree (both finished, one held for a captain review, neither torn down). Cleanup then deadlocks - bin/fm-teardown.sh's exclusivity scan refuses symmetrically, because each record sees the other naming the same live path, and the slot-owner claim only short-circuits when the OTHER record is unreachable. Tearing down the older record is separately refused (captain-held work is retained, and its unlanded branch work refuses without --force), while clearing worktree= strands the record because endpoint validation rejects an empty worktree unconditionally. Net effect: a finished worker's cleanup is blocked until the older held task is resolved.
The same collision exists live in this home today on two slot paths: two finished records and two held records share one worktree path per pair, and no cleanup of the finished records has been possible since.

What Changed

  • Read the pool slot owner claim before checking for conflicting task records. When another task owns the slot, teardown completes the stale record’s cleanup without returning or changing that slot.
  • Preserve the refusal for a slot claimed by the task or lacking a claim. Update the architecture docs and safety tests for colliding records, including an owner with unlanded work.

Risk Assessment

✅ Low: The claim-first check lets a non-owner record complete cleanup without touching the claimed slot, while an owner facing a conflicting record still refuses teardown.

Testing

The focused teardown test file passed on both runs. Its CLI fixture showed the stale task completing cleanup without --force while the claimant’s record, process, claim, and unlanded checkout remained untouched; the worktree contains only the intentional test change. This phase did not exercise a live Cursor runtime.

Evidence: Slot-collision cleanup transcript

Source: Slot-collision cleanup transcript

Teardown completed without --force. The stale record was removed; the claimant’s record, live process, unlanded checkout, and slot claim remained intact. Treehouse return was not invoked.

$ fm-teardown.sh stale-task
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  2 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
●  This is a supervision warning only; the guarded operation WILL still run.
●  repair missing watcher supervision with a foreground checkpoint: bin/fm-watch-checkpoint.sh --seconds 180.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
warning: task stale-task's recorded worktree /private/var/folders/ky/sdncl1hx1b3g7yntpg095s880000gn/T/fm-teardown-endpoint-safety.HSGzET/slot-reassigned-clean/pool/1/project was reassigned to task reassigned-task (home /private/var/folders/ky/sdncl1hx1b3g7yntpg095s880000gn/T/fm-teardown-endpoint-safety.HSGzET/slot-reassigned-clean/other-home), which claimed that pool slot after this record was written; that slot is no longer stale-task's, so its processes, copy, and claim are left untouched and only stale-task's own cleanup runs.
WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
/private/var/folders/ky/sdncl1hx1b3g7yntpg095s880000gn/T/fm-teardown-endpoint-safety.HSGzET/slot-reassigned-clean/project: skipped: no origin remote
teardown stale-task complete (window firstmate:fm-stale-task; pool slot /private/var/folders/ky/sdncl1hx1b3g7yntpg095s880000gn/T/fm-teardown-endpoint-safety.HSGzET/slot-reassigned-clean/worktree left to task reassigned-task (home /private/var/folders/ky/sdncl1hx1b3g7yntpg095s880000gn/T/fm-teardown-endpoint-safety.HSGzET/slot-reassigned-clean/other-home), which it was reassigned to)
Backlog: stale-task just finished (this home keeps no markdown backlog at /private/var/folders/ky/sdncl1hx1b3g7yntpg095s880000gn/T/fm-teardown-endpoint-safety.HSGzET/slot-reassigned-clean/home/data/backlog.md). Update /private/var/folders/ky/sdncl1hx1b3g7yntpg095s880000gn/T/fm-teardown-endpoint-safety.HSGzET/slot-reassigned-clean/home/data/backlog.md - move stale-task to Done, keep Done to the 10 most recent, then re-scan Queued and dispatch only work whose blockers are gone and date is due.
finished record removed: yes
claimant record retained: yes
claimant process alive: yes
claimant checkout HEAD unchanged: yes
claimant unlanded work retained: yes
claimant checkout clean: yes
claimant slot claim: task=reassigned-task
treehouse return invoked: no

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • FM_TEARDOWN_EVIDENCE_FILE=~/.no-mistakes/evidence/01M3KF59BQ46H9FSGDNDX4FWR4/slot-collision-cleanup.txt bash tests/fm-teardown-endpoint-safety.test.sh (run twice, including after the final test assertions)
  • Inspected the saved teardown transcript and final git status --short.
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Changes pool slot ownership verification logic in teardown.

The PR appears safe to merge; no actionable regression was identified.

Reviews (1) · Last reviewed commit: "no-mistakes(document): Confirm teardown ..."

keenvc added a commit to keenvc/firstmate that referenced this pull request Sep 29, 2026
…wner (adopt kunchenguid#5993) (#7)

* Fix reassigned teardown slot collisions

(cherry picked from commit 115333b)

* no-mistakes(document): Document claim-first pool-slot teardown behavior

(cherry picked from commit dcbe51a)

* no-mistakes(document): Confirm teardown documentation reflects slot ownership behavior

(cherry picked from commit bdcedcf)

* fix(teardown): avoid presentation-lock races after claim-first slot cleanup

Reassigned-slot teardown with a dead Herdr husk no longer takes the shared
presentation session lock, restoring the pre-5993 contention profile for stale
records while keeping live-slot protection intact. Herdr presentation recovery
spawns now wait up to 120s for that lock and release it on abort so concurrent
cross-home recovery cannot fail the 5s try loop after a legitimate holder.

Co-authored-by: Cursor <[email protected]>

---------

Co-authored-by: QIanGua <[email protected]>
Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant