Skip to content

fix: refuse teardown when Git hides untracked files - #7909

Merged
kunchenguid merged 4 commits into
kunchenguid:mainfrom
WTF-Am-ID:fm/up-fm-7779
Oct 29, 2026
Merged

kunchenguid merged 4 commits into
kunchenguid:mainfrom
WTF-Am-ID:fm/up-fm-7779

Conversation

@WTF-Am-ID

@WTF-Am-ID WTF-Am-ID commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #7779

Review was single-family (Codex) by the owner's temporary choice.

Intent

ok same instructions i gave you before pick high value issues from scan, in all the repos you scanning and use codex only to close them

Context: this task is scan pick P1: upstream issue #7779 in kunchenguid/firstmate. Teardown can erase an unadded file when Git is configured with status.showUntrackedFiles=no. Triage contract class: restore. Scan notes for this pick:
Issue: #7779

Teardown can erase an unadded file when Git is configured with status.showUntrackedFiles=no.
A one-flag correction restores an explicit no-uncommitted-work guarantee.
Size S.
Contract class: restore.
Maintainer triage.

Evidence: bin/fm-teardown.sh:2097 still uses plain status --porcelain, while the post-return check at line 2076 requests all untracked files.

Competing work: No exact issue reference in the final 1,820-open-PR index. The overlapping #6067 handles interrupted pool resets, and #7193 handles index flags. Neither targets the missing untracked-files flag. Maintainer triage explicitly distinguishes the hidden-untracked fixture in the former.

Closure test: In a scratch Git repository set status.showUntrackedFiles=no and create an unadded file. Drive the real teardown entry point with fake pool/backend commands. It must refuse before any return or removal, preserve the file and task metadata, and name the dirty state. A clean control still reaches the guarded return. Add to tests/fm-teardown.test.sh and run it through bin/fm-test-run.sh.
The owner approved fixing the scan's high-value picks upstream through PRs, written and reviewed by Codex only.

What Changed

  • Make teardown explicitly check all untracked files before returning a worktree, even with status.showUntrackedFiles=no.
  • Add regression coverage for refusing hidden untracked work, preserving files and task metadata, and allowing a clean return.
  • Replace FIFO synchronization in the watcher-lock concurrency test with regular-file markers and bounded polling.

Risk Assessment

✅ Low: The bounded flag correction restores hidden-untracked-file detection at the shared safety check, with behavioral regression coverage and a test-only synchronization change.

Testing

Both targeted suites passed, with live dirty/clean teardown CLI and state evidence retained; a separate baseline replay was blocked before execution by the cleanup guard.

  • Live validation: ✅ go - 2 of 2 scenarios driven live against the product
Scenario Result Live Evidence
Teardown refuses Git-hidden unadded work, names the dirty path, and preserves file bytes, task metadata, branch and HEAD before pool return ✅ pass live teardown-product-evidence.txt; test_hidden_untracked_work_refuses_before_return
Clean teardown with status.showUntrackedFiles=no reaches pool return and retires task metadata ✅ pass live teardown-product-evidence.txt; clean control in test_hidden_untracked_work_refuses_before_return
Evidence: Teardown CLI output and preserved file state

Source: Teardown CLI output and preserved file state

Live teardown fixture observations from the targeted test runner
Candidate: ba06d2875ea5eb95d2d641b3a3067dd86683c750

Scenario: hidden-untracked-dirty
stdout:

stderr:
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher process holds this home lock (last beat: 1s ago).
●  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 according to the session-start block for this harness; do not use shell &.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
REFUSED: worktree /private/var/folders/gn/m0fr4_4962q75gpmcl14_z0w0000gn/T/fm-test-run.o0sYTO/w2/tmp/fm-teardown-tests.cD6N6E/hidden-untracked-dirty/wt has uncommitted changes.
uncommitted changes present (untracked-only leftovers)
untracked paths (up to 10):
  "new directory/newfile.txt"
Commit them (or get the captain's explicit OK to discard, then --force).

pool_return_recorded=False
task_metadata_exists=True
unadded_file_bytes="unadded work\n"
task_metadata_byte_identical=True
$ git config --get status.showUntrackedFiles
no

$ git status --porcelain
(empty output)
$ git status --porcelain --untracked-files=all
?? "new directory/newfile.txt"

$ git rev-parse --abbrev-ref HEAD
fm/task-x1


Scenario: hidden-untracked-clean
stdout:
/private/var/folders/gn/m0fr4_4962q75gpmcl14_z0w0000gn/T/fm-test-run.o0sYTO/w2/tmp/fm-teardown-tests.cD6N6E/hidden-untracked-clean/project: already current
teardown task-x1 complete (window firstmate:fm-task-x1, worktree /private/var/folders/gn/m0fr4_4962q75gpmcl14_z0w0000gn/T/fm-test-run.o0sYTO/w2/tmp/fm-teardown-tests.cD6N6E/hidden-untracked-clean/wt)
Backlog: task-x1 just finished (this home keeps no markdown backlog at /private/var/folders/gn/m0fr4_4962q75gpmcl14_z0w0000gn/T/fm-test-run.o0sYTO/w2/tmp/fm-teardown-tests.cD6N6E/hidden-untracked-clean/data/backlog.md). Update /private/var/folders/gn/m0fr4_4962q75gpmcl14_z0w0000gn/T/fm-test-run.o0sYTO/w2/tmp/fm-teardown-tests.cD6N6E/hidden-untracked-clean/data/backlog.md - move task-x1 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.

stderr:
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher process holds this home lock (last beat: 1s ago).
●  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 according to the session-start block for this harness; do not use shell &.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

pool_return_recorded=True
task_metadata_exists=False
Evidence: Targeted test runner output

Source: Targeted test runner output

FM_TEST_BEGIN 2026-10-29T10:43:11Z tests/fm-watcher-lock.test.sh family=watcher-wake-lock expected_gate_skip=none
ok - disposable watcher refuses inherited state outside its marked lab
ok - wait deadline diagnoses and reaps a stopped test child without hanging
ok - simultaneous watcher starts leave exactly one live process
ok - fm_pid_identity real ps fallback is locale-invariant
ok - fm_pid_identity is locale-invariant across LC_ALL/LC_TIME
ok - fm_pid_identity ps fallback is terminal-width-invariant
ok - /proc process identity ignores simulated btime changes
ok - /proc process identity detects pid reuse
ok - MSYS /proc process identity regression skipped on non-Windows host
ok - killed watcher stale lock is reclaimed
tests/fm-watcher-lock.test.sh: line 1621: 20825 Killed: 9               FM_STATE_OVERRIDE="$state" bash -c '
    . "$1"
    fm_lock_remove_path() {
      if [ "$1" = "$STATE/.watch.lock" ]; then
        kill -KILL "${BASHPID:-$$}"
      fi
      return 1
    }
    fm_lock_try_acquire "$2"
  ' _ "$LIB" "$lockdir" > /dev/null 2>&1
ok - stale watcher reclaim publishes durable recovery evidence before clear
ok - live watcher lock with stale heartbeat is actionable
ok - live watcher lock with a beacon past the hard bound is replaced, under it is still refused
ok - guard banner leads when down with pending wakes (repair-after-drain) and stays silent when live and fresh
ok - concurrent fm_lock_try_acquire yields exactly one winner
ok - dead-pid stale lock is reclaimed by a single acquirer
ok - concurrent stale-lock steal yields exactly one winner
ok - dead steal owner is reclaimed once without a nested steal marker
ok - dead nested steal chain from an interrupted reclaim is recovered
ok - a competing reaper cannot remove the successor's steal mutex
ok - a steal mutex abandoned by this process does not block its own reclaim
ok - a steal reap interrupted in this process is resumed from its own tombstone
ok - live steal mutex is not reclaimed
ok - live-held lock is not stolen
ok - lock whose recorded holder pid was reused by a live process is reclaimed
ok - live holder matching its recorded start time keeps its lock
ok - empty mid-acquire lock keeps a minimum grace
ok - late original claimant cannot claim a recreated lock
ok - paused mid-acquire claimant backs off to active stealer
ok - watch restart preserves recovery without signaling a reused pid
ok - watch restart attaches to a verified healthy peer and later surfaces a successor gap
ok - watcher self-evicts when the lock pid no longer names it
ok - arm turns clean self-eviction without a successor into a typed failure
ok - arm attaches to a live fresh watcher and fails loudly when that cycle has no successor
ok - attached arm signals record a classified lifecycle entry
ok - arm starts cleanly and resurfaces recovery after a dead-pid lock
ok - arm cleans child watcher and temp output on HUP
ok - arm defers TERM until startup watcher can run its lock cleanup
ok - arm TERM stops a startup watcher that never becomes cleanup-ready
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 83873.1793270646.xYAQyP
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 registered custom check(s), but no live watcher process holds this home lock (last beat: 1s ago).
●  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.
●  After draining queued wakes, repair missing watcher supervision according to the session-start block for this harness; do not use shell &.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.
ok - arm propagates an immediate watcher wake before confirmation
ok - arm attaches to a peer watcher after child stands down and surfaces a missing successor
watcher: lock held by live pid 97707 but heartbeat is stale for 846567859s (>300s); inspect or stop that watcher before re-arming.
ok - arm reports FAILED and exits non-zero when no fresh watcher can be confirmed
ok - cycle-exit ledger links a verified successor and remains size-capped
ok - SIGSTOP distinguishes live PID from stale beacon and termination records the exit class
FM_TEST_END 2026-10-29T10:44:36Z tests/fm-watcher-lock.test.sh exit=0 duration_ms=84189 gate_skip=false
FM_TEST_BEGIN 2026-10-29T10:44:36Z tests/fm-teardown.test.sh family=pr-forge expected_gate_skip=none
ok - teardown leaves opencode's busy plugin in the returned pool worktree as on main
ok - hidden untracked work is refused before return while a clean control returns
ok - content fallback distinguishes unavailable Git proof, containment, conflicts, and unlanded content
ok - status archival is opt-in and preserves the complete log
ok - config-absent teardown does not read or invoke record export
ok - unopted teardown ignores symlinked config when record export is absent
ok - teardown commits the record archive before deleting sources and fails closed when export cannot commit
ok - forced secondmate teardown exports task records from the child sub-state
ok - record export waits for endpoint quiescence and retry captures records changed after refusal
ok - forced secondmate retirement preserves two descendant levels and refuses linked child directories
ok - local missing-status retirement stays lock-free without creating an archive
ok - reused task IDs never overwrite archives and retention removes only old owned logs
ok - archive sources and directories reject symlinks; pruning never follows children links
ok - failed archive publication preserves presentation and watcher bookkeeping
ok - cursor retirement failure removes its archive so retry publishes one history
ok - archive publication and cold logs never re-wake or re-present
ok - retention failures warn without aborting unrelated teardown
ok - a missing teardown startup source refuses before cleanup
ok - an unreadable teardown startup source refuses before cleanup
ok - a missing adapter sibling refuses before cleanup
ok - a forced descendant with a missing adapter sibling refuses before cleanup
ok - a forced secondmate with a missing own adapter sibling refuses before child cleanup
ok - present required sources still reach the ordinary teardown refusal
ok - local-only worktree with HEAD on a fork remote is torn down and the home summary is refreshed
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher process holds this home lock (last beat: 1s ago).
●  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 according to the session-start block for this harness; do not use shell &.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ok - teardown closes its own backlog item before reporting success
ok - teardown closes a landed Gerrit task with its change URL as a note and a GitHub task with --pr
ok - teardown closes a landed GitLab task with its merge request URL as a note and GitHub and Forgejo tasks with --pr
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

... [8204 bytes truncated] ...

files survive the scratch clean and plain scratch does not
ok - gh lookup error with content not in default refuses (fail-safe)
ok - a record predating spawn_gen refuses teardown until --legacy-record is passed
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher process holds this home lock (last beat: 2s ago).
●  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 according to the session-start block for this harness; do not use shell &.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ok - a windowless leftover with no spawn_gen and no worktree tears down without --legacy-record
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher process holds this home lock (last beat: 2s ago).
●  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 according to the session-start block for this harness; do not use shell &.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ok - a windowless leftover with no spawn_gen also tears down when --legacy-record is passed
ok - a windowless leftover still refuses while its worktree holds unlanded work
ok - a windowless record with a spawn_gen, a non-tmux backend or endpoint identity, no backlog validation, or ambiguous, foreign, or malformed identity still refuses
WARNING: watcher still down (same stale episode; last beat: 3s ago, grace 300s) - full banner already printed this episode.
ok - a windowless leftover retries its retained legacy stamp without --legacy-record
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher process holds this home lock (last beat: 1s ago).
●  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 according to the session-start block for this harness; do not use shell &.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ok - a landed legacy record with a dead endpoint tears down and logs its accepted incarnation
ok - --legacy-record never relaxes the unlanded-work refusal
ok - an endpoint that cannot be confidently read as dead refuses --legacy-record teardown
ok - --legacy-record teardown rolls its stamp back when the close marker write fails
ok - a legacy stamp a failed rollback left behind still faces the endpoint gate
ok - a corrupt spawn_gen is never accepted as a legacy record
ok - provably-stale worktree index.lock (old, no live holder) is cleared and teardown succeeds
ok - live-held worktree index.lock is never removed and teardown refuses
ok - lsof errors leave worktree index.lock in place and refuse teardown
ok - stale lock cleanup rechecks and refuses dirty worktree before return
ok - normal repo index.lock is resolved from the worktree and cleared when stale
ok - index-lock mtime fault injection is PATH-based; skipped on Darwin where stat is /usr/bin/stat
ok - transient index.lock cleared after first failed return is retried successfully without force-remove
ok - persistent index.lock exhausts retries and refuses without force-removing the lock
ok - empty retry wait overrides use the default without aborting teardown
ok - fractional legacy retry wait remains supported without arithmetic
ok - teardown records the task's pipeline spend before removing its branch and record
ok - teardown skips all pipeline-spend recording when the home has not opted in
ok - teardown records unavailable pipeline spend for an owned ship task whose copy is gone
ok - a task's own parked no-mistakes run is aborted, not orphaned, before the worker is removed
ok - a parked run in a resolved workspace no-mistakes home is aborted before the worker is removed
ok - a run that lands on passed-with-override after abort is still recognized as terminal
ok - a run that lands on passed-with-skips after abort is still recognized as terminal
ok - a parked run the pipeline advanced past the task copy is still concluded from the runs ledger, not orphaned
ok - a ledger row for a different head never authorizes a parked-run abort
ok - a malformed ledger row never authorizes a parked-run abort
ok - an impossible ledger date never authorizes a parked-run abort
ok - a terminal status with a stale gate never reaches ledger cleanup
ok - an advanced head present locally aborts through the strict rule alone - the ledger fallback stays dormant
ok - an unresolvable active row with no same-branch anchor is never concluded (conservative refusal)
ok - an ancestor-only anchor never binds an advanced parked run to this task
ok - a terminal unfetched-head row is stale history and never concludes a run
ok - a terminal newest row anchored at this worktree's head never authorizes an abort
ok - a resolvable diverged newer same-branch row makes every older row stale history; no run is concluded
ok - consecutive unresolvable rows are ambiguous and never conclude a run
ok - a ledger-proven continuation is still left alone while the run is autonomously active
ok - teardown refuses before reap or removal when a task-owned run remains parked
ok - a different run cannot confirm the targeted abort
ok - empty post-abort status is not accepted as confirmation
ok - the CLI's exact run-not-found signal confirms completion
ok - a parked run on another branch is never aborted by this task's teardown (ownership is precise)
ok - a task-owned autonomous running step is left alone rather than aborted
ok - a leaked descendant process rooted under the task's worktree is reaped by teardown, not left surviving
ok - a leaked descendant process rooted under the task's per-task tasktmp is reaped by teardown too
ok - missing lsof falls back to reaping the tmux pane process group
ok - an erroring lsof scan refuses teardown and preserves the task
ok - a reused pid with a different start time is never force-killed
ok - an exec change preserves birth identity and the process is reaped
ok - a process spawned during grace is reaped on a later pass
ok - persistent leaked processes refuse teardown after bounded retries
ok - a process exiting during identity lookup does not block teardown
ok - the run abort and the leaked-process reap both complete before the destructive worktree return
FM_TEST_END 2026-10-29T10:54:10Z tests/fm-teardown.test.sh exit=0 duration_ms=574202 gate_skip=false
FM_TEST_SUMMARY total=2 failed=0 skipped_gate=0 duration_ms=658641
FM_TEST_SUMMARY_FAMILY family=pr-forge count=1 duration_ms=574202 failed=0
FM_TEST_SUMMARY_FAMILY family=watcher-wake-lock count=1 duration_ms=84189 failed=0
FM_TEST_SLOWEST rank=1 script=tests/fm-teardown.test.sh duration_ms=574202
FM_TEST_SLOWEST rank=2 script=tests/fm-watcher-lock.test.sh duration_ms=84189

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

⏭️ **Rebase** - skipped

Step was skipped.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 2 of 2 scenarios driven live against the product
Scenario Result Live Evidence
Teardown refuses Git-hidden unadded work, names the dirty path, and preserves file bytes, task metadata, branch and HEAD before pool return ✅ pass live teardown-product-evidence.txt; test_hidden_untracked_work_refuses_before_return
Clean teardown with status.showUntrackedFiles=no reaches pool return and retires task metadata ✅ pass live teardown-product-evidence.txt; clean control in test_hidden_untracked_work_refuses_before_return
  • bin/fm-test-run.sh tests/fm-teardown.test.sh tests/fm-watcher-lock.test.sh exited 0.
  • Captured actual teardown output and independently checked the disposable fixtures’ Git configuration, unadded file bytes, metadata and return records.
  • A separate baseline replay command was rejected before execution because its cleanup used rm -f; it was not retried.
  • Confirmed fixture cleanup, unchanged source worktree, and HEAD ba06d2875ea5eb95d2d641b3a3067dd86683c750.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Reviews (4) · Last reviewed commit: "no-mistakes(document): Document hidden-u..." · Reviewed by Greptile

@kunchenguid

Copy link