Skip to content

fix: refuse ordinary teardown with attached task feedback - #7448

Open
ironerumi wants to merge 10 commits into
kunchenguid:mainfrom
ironerumi:fm/fm-7426-pr
Open

ironerumi wants to merge 10 commits into
kunchenguid:mainfrom
ironerumi:fm/fm-7426-pr

Conversation

@ironerumi

@ironerumi ironerumi commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Intent

The developer approved building the upstream pull request for #7426. The issue as filed:

At upstream main 67abd40a6b7b0c39fb509527afd3784534c5bd9f, bin/fm-teardown.sh:3873-3880 treats leftover unhandled steering as moot after landing and deletes the task inbox. Landing the code does not acknowledge an unread feedback message or a captured process-event result. Task-owned source/result ownership already exists in bin/fm-procevent.sh, but ordinary teardown does not inventory it before retiring the owner.

The ask is one refusal behavior: ordinary teardown must stop while the task still has an attached task-owned listener, an unread inbox message, or an unhandled captured result belonging to it, and identify the attachment that must be handled. Unrelated tasks' sources must not block it. This does not ask to change forced-discard authority or add automatic retirement, session cleanup, feedback transfer, or pool management.

ironerumi#85 demonstrates a small inventory plus an early check and a pre-close recheck, with fixtures for attached messages/results/listeners, late feedback, and unrelated-source non-interference. A narrow upstream port can use that ownership check without importing the fork's forced-teardown policy changes.

Related but different: #6896 concerns orphaned source cleanup, while #6130 and #6212 concern ending review sessions. This issue asks that pending feedback prevent ordinary owner destruction, not that teardown consume or retire feedback automatically.

The maintainer triaged it ready-for-pr, VISION-aligned, and asked for a narrow upstream port of the ownership check only, without the fork's forced-teardown policy changes, with regression fixtures for an attached message, an attached result, a listener, and an unrelated source not blocking, raised through no-mistakes.

What Changed

  • Make ordinary teardown inventory task-owned listeners, unread inbox messages, and unhandled captured results, identifying attachments and refusing before destructive cleanup; unrelated task sources do not block teardown.
  • Cover secondmate parent and child-home feedback, with a pre-close recheck and locking that prevents feedback writers from racing teardown or recreating retired inboxes.
  • Preserve explicit --force discard behavior and document the ownership safeguard with regression fixtures for attached, handled, late, and unrelated feedback.

Risk Assessment

⚠️ Medium: The change coordinates feedback ownership across process-event, inbox, secondmate, and teardown concurrency paths; the reviewed implementation is bounded and consistent, but the lifecycle locking and ordering are materially complex.

Testing

The Test agent exceeded its invocation budget. An explicit Test exception was approved after all five touched suites and real-endpoint lab checks passed independently on executable-identical code; the full transcript, exact tested/published heads, and documentation-only difference are recorded below.

  • Outcome: ⚠️ 1 warning across 1 run (30m1s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed (2) ✅
  • ⚠️ bin/fm-procevent.sh:697 - register-task acquires the per-source lock at bin/fm-procevent.sh:691, then the new endpoint recheck at bin/fm-procevent.sh:697-698 can fail if the pane dies or its endpoint becomes invalid between the two validations. That die path runs the EXIT trap, which releases only the task-feedback lock, leaving the source lock owned by the exiting process; later operations on the same source must wait for stale-lock recovery and can be delayed or blocked under PID reuse. Release the source lock in this recheck failure (or include it in the cleanup trap). The other post-lock error paths at bin/fm-procevent.sh:701-812 explicitly release it, making this new recheck the exception.

🔧 Fix applied.
1 error still open:

  • 🚨 bin/fm-teardown.sh:3534 - The new gate does not guarantee the required refusal invariant: ordinary teardown must stop while a task has “an attached task-owned listener, an unread inbox message, or an unhandled captured result belonging to it,” before retiring that task. task_feedback_inventory is invoked only against the parent $STATE at bin/fm-teardown.sh:3534-3537. A local secondmate runs with its own FM_HOME, so a task-owned listener, inbox message, or result under the child home is invisible to this check; the child preflight at bin/fm-teardown.sh:3448 does not inventory feedback, and remove_firstmate_home then sweeps process events at bin/fm-teardown.sh:2723,2832 before deleting the child home at bin/fm-teardown.sh:3841. Separately, the late recheck runs only after destructive retirement: the Orca path at bin/fm-teardown.sh:3691 follows branch deletion/hook cleanup, and the normal path at bin/fm-teardown.sh:3772 follows worktree return and slot-owner release. Thus feedback arriving during preparation can be refused only after task-owned worktree state has already been returned, and child-home feedback can be discarded without refusal. The fix must inventory every task-owned home and move the recheck before any retirement at the shared teardown boundary; this changes the teardown sequencing and requires author approval.

🔧 Fix applied.
✅ Re-checked - no issues remain.

⚠️ **Test** - 1 warning
  • ⚠️ The Test agent did not finish within its invocation budget. Reported: agent run tests timed out after 30m0s (silent budget; no still-working cap is set; ran 30m0s): agent last produced output 7s ago (67 observed); agent reported: pi exited: exit status 143. This is a budget or provider-slowness cut, not a code failure. Re-running the same request costs another full budget, so no further attempt is made automatically. If this repository's targeted tests or evidence gathering routinely stay quiet longer than the default 30m0s, raise test_agent_timeout in global config. If the turn was still producing output or running a child process, set or raise test_agent_working_timeout there instead: a turn runs past test_agent_timeout only up to that still-working cap. Respond with fix to spend another budget: a repair turn runs only for selected findings other than this budget cut, then validation re-runs. Or abort and retry after raising the budget.
🔧 **Document** - 1 issue found → no changes applied ✅
  • ⚠️ docs/architecture.md:421 - This edit replaced operative text with a pointer "Ordinary teardown applies the attached-feedback ownership gate described in configuration.md before destructive cleanup and again at the shared pre-destruction boundary; --force retains its explicit discard authority." to docs/configuration.md, but the referenced file does not contain the deleted rule: "Ordinary teardown also applies the attached-feedback ownership gate in configuration.md before cleanup and again before endpoint close; --force retains its explicit discard authority.". Preserve the rule in an authoritative document or keep the pointer only if its target states it.

🔧 No changes applied.
✅ Re-checked - no issues remain.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Issues

Closes #7426

Maintainer-requested follow-up evidence

Tested code head: ad2649a8a5d3cc8a4c63529102281ed326cadfed. Published head: 62c980449475e4c029689c0019463f19a7bf7502; the intervening diff changes only four documentation files, with executable code and tests unchanged. The refreshed no-mistakes attestation binds the published head; all 20 reported checks passed before this evidence-only body update.
All five touched test files passed with the canonical runner: fm-teardown.test.sh, fm-teardown-endpoint-safety.test.sh (including child-home and pre-destruction ownership fixtures), fm-gotmp.test.sh, fm-secondmate-lifecycle-e2e.test.sh, and fm-remote-secondmate-lifecycle-e2e.test.sh.
The runner reported total=5 failed=0 skipped_gate=0 duration_ms=1094091.
The Test agent reached its 30-minute budget; firstmate authorized direct focused verification rather than rerunning that agent.
This is an explicit Test approval based on independent passing evidence, not an assertion that the timed-out turn completed.

Fixture corrections: GOTMP includes the real inventory executable and its libraries; local and remote secondmate fixtures acknowledge messages already consumed by their steer/handoff assertions before retirement (the intended new-default consequence); the lock-mtime fixture injects only the intended mtime error while preserving unrelated ownership queries.
No production refusal or watcher/provisioning bound was weakened.

Composition with #6212: this refusal runs before retirement; whichever lands second needs a rebase that sequences acknowledged-listener retirement without bypassing unread-message/unhandled-result refusal.
No integration with that unmerged change is claimed.

Actual real-endpoint lab transcript (not test doubles)

A fresh lab was created with bin/fm-lab-home.sh; endpoint commands used a private real tmux server, product inbox/capture interfaces, and the exact candidate head above.
Only home-specific code-copy paths are normalized to $TASK_COPY and $VALIDATION_COPY below.
The private server was stopped and its socket directory removed by the driver exit trap.

$TASK_COPY/.no-mistakes/live-7426/head-ad2649a8/home
tested-head=ad2649a8a5d3cc8a4c63529102281ed326cadfed
lab-home=$TASK_COPY/.no-mistakes/live-7426/head-ad2649a8/home
private-tmux-dir=/tmp/fml.XVGubd
real-tmux socket=/private/tmp/fml.XVGubd/tmux-502/feedback-7426 server-pid=26889 pane-pid=26895
product inbox writer created $TASK_COPY/.no-mistakes/live-7426/head-ad2649a8/home/state/feedback-live.inbox/001.msg

$ bin/fm-teardown.sh feedback-live # unread inbox message
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 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 a missing or failed watcher cycle with the Pi tool fm_watch_arm_pi, or restart Pi with -e $VALIDATION_COPY/.pi/extensions/fm-primary-turnend-guard.ts -e $VALIDATION_COPY/.pi/extensions/fm-primary-pi-watch.ts if the extensions are not loaded.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
attached message: file=$TASK_COPY/.no-mistakes/live-7426/head-ad2649a8/home/state/feedback-live.inbox/001.msg
REFUSED: task feedback-live still has attached feedback; handle the attachments listed above before ordinary teardown.
exit=1
preserved real endpoint: feedback-lab:fm-feedback-live pane=%1
acknowledged message by moving to handled/
product capture created $TASK_COPY/.no-mistakes/live-7426/head-ad2649a8/home/state/procevent-inbox/live-source.1.result

$ bin/fm-teardown.sh feedback-live # unhandled captured result
WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
attached result: file=$TASK_COPY/.no-mistakes/live-7426/head-ad2649a8/home/state/procevent-inbox/live-source.1.result owner-task=feedback-live
REFUSED: task feedback-live still has attached feedback; handle the attachments listed above before ordinary teardown.
exit=1
preserved real endpoint: feedback-lab:fm-feedback-live pane=%1
handled: live-source 1

$ bin/fm-teardown.sh feedback-live # all feedback handled
WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
teardown feedback-live complete (window feedback-lab:fm-feedback-live, worktree $TASK_COPY/.no-mistakes/live-7426/head-ad2649a8/home/missing-feedback-live)
Backlog: feedback-live just finished (config/backlog-backend selects manual editing). Update $TASK_COPY/.no-mistakes/live-7426/head-ad2649a8/home/data/backlog.md - move feedback-live 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.
exit=0
confirmed real endpoint and owner metadata removed after acknowledgement

$ bin/fm-teardown.sh feedback-force --force
WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
teardown feedback-force complete (window feedback-lab:fm-feedback-force, worktree $TASK_COPY/.no-mistakes/live-7426/head-ad2649a8/home/missing-feedback-force)
Backlog: feedback-force just finished (config/backlog-backend selects manual editing). Update $TASK_COPY/.no-mistakes/live-7426/head-ad2649a8/home/data/backlog.md - move feedback-force 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.
exit=0
confirmed explicit --force still discards unread steer and closes real endpoint
PASS: unread message refusal, captured result refusal, handled cleanup, unchanged force

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @ironerumi for picking up #7426 so quickly. I checked the body and the diff, and this does implement #7426's ask: ordinary teardown now inventories the task's attached listener, unread inbox messages, and unhandled captured results, and refuses before cleanup and again before endpoint close. --force is unchanged and other tasks' sources don't block. The diff review found nothing risky (no workflow or CI-script changes, no network or credential handling).

What's needed from you (this is waiting on you, not on Kun):

  1. CI has real regressions in existing suites on head 5ea5fa35 (run 39023796025):

    • tests/fm-secondmate-lifecycle-e2e.test.sh (serial 8): "teardown failed for the empty secondmate home". The new gate refuses on state/design.inbox/001.msg and 002.msg, which the earlier send step left there.
    • tests/fm-gotmp.test.sh (serial 7): "teardown exited non-zero with a valid tasktmp".
    • tests/fm-teardown.test.sh (serial 9): "mtime-error-index-lock: teardown did not report the mtime read failure".
    • tests/fm-remote-secondmate-lifecycle-e2e.test.sh (serial 5): "the watcher did not exit on its auto-relaunch wake within the bound". This one may be unrelated, but please check it.
    • Serial 2 hit the 30-minute job cap (fix(pi): keep the Pi watcher armed after a successor or arm child dies #7255), which isn't yours to fix.

    For the existing fixtures that now refuse, please decide case by case: either the fixture should acknowledge its feedback first (file it into handled/), or the gate is catching a path it shouldn't. Then say which it was in the PR body.

  2. Live evidence, please. The "live validation" attached here is the tests/fm-teardown-endpoint-safety.test.sh suite log, which is fixture-level. Could you run it once against a real endpoint in a disposable lab home (bin/fm-lab-home.sh)? Three cases would cover it: ordinary teardown refuses on an unread inbox message and on an unhandled captured result, it proceeds once the message is filed into handled/, and --force behaves as before. Please post the transcript, or re-raise through no-mistakes with a real live lane.

  3. Once those are fixed, re-raise through git push no-mistakes so the attestation binds the new head.

Overlap to keep in mind: open PR #6212 (ending task-owned Lavish review sessions and retiring sources at teardown) touches the same teardown and procevent paths. With this gate, a still-registered task-owned listener blocks ordinary teardown, so the two need to compose: the refusal runs before any retirement, and #6212's retirement must not be made unreachable. Whichever lands second will need a rebase.

Contract-class: new-default. Main documents leftover steering as moot at teardown, and this adds a new refusal on the unconfigured teardown path. I think it's the right direction, but once CI is green and live evidence is in, this goes to Kun for the merge-or-leave decision. It won't be auto-merged.

VISION.md: aligns on every rule (strengthens a refusal path, "a refusal to discard is a finding"; deterministic inventory; --force keeps explicit discard authority; harness-agnostic; command-layer scope).

@ironerumi ironerumi changed the title fix: block teardown with attached task feedback fix: refuse ordinary teardown with attached task feedback Oct 17, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @ironerumi, this is a big step forward. On head 62c98044 every CI job is green (run 39038460457, including serials 5, 7, 8 and 9 that regressed last time), the no-mistakes attestation matches this head, and the branch merges cleanly. Fixing the existing fixtures by moving their consumed messages into handled/ makes sense. I re-read the diff and still found nothing risky: no workflow or CI-script changes, and no network or credential handling.

One thing is still needed from you (this is waiting on you, not on Kun): live validation. The PR body says the no-mistakes Test agent hit its 30-minute budget and "no evidence was gathered for this head", so so far the only proof is the test suite. When you get a chance, could you try it on a real (or lab) firstmate home and post what you see? Ideally:

  1. ordinary fm-teardown.sh <id> on a task with an unread inbox message, then one with an unhandled captured process-event result, and one with an attached listener. Each should refuse and name the attachment.
  2. the same teardown succeeding once the feedback is handled, plus a teardown where only another task's source exists.
  3. a secondmate teardown with feedback in the child home.
  4. --force still discarding as before.

Or you can re-raise through no-mistakes with a bigger test_agent_timeout so the Test step finishes and records its evidence. Either works.

For transparency: I'm treating this as a change to the default teardown behavior. Today ordinary teardown treats leftover steering as moot, and after this PR it refuses instead. So once the live evidence is here, Kun will make the merge call himself. That part won't be waiting on you.

@ironerumi

Copy link
Copy Markdown
Contributor Author

Live lab verification completed for #7448 at head 62c980449475e4c029689c0019463f19a7bf7502.
The run used actual tmux 3.7c task windows, the real inbox writer, and the real process-event registration/capture/listening APIs, not mocked lifecycle commands.
A named non-default Herdr lab was provisioned and removed through the guarded helper; its default-session tripwire passed cleanup.

In the commands below, $ROOT denotes the tested repository and $LAB/$CHILD denote disposable marked Firstmate homes.
Generated absolute paths in output are normalized to those variables; unrelated monitoring and manual-backlog notices are omitted.
Every invocation used FM_HOME="$LAB" FM_ROOT_OVERRIDE="$ROOT" and the lab helper's private TMUX_TMPDIR.

Case Exact teardown command Exit / observed result
Unread inbox message bash "$ROOT/bin/fm-teardown.sh" unread 1; attachment named; real window and task record preserved
Same task after moving message into handled/ bash "$ROOT/bin/fm-teardown.sh" unread 0; real window and task record removed
Actual unhandled captured process-event result bash "$ROOT/bin/fm-teardown.sh" captured 1; result, listener and delivery instruction named; real window and task record preserved
Same task after handled capture-source 1 and inbox acknowledgment bash "$ROOT/bin/fm-teardown.sh" captured 0; real window and task record removed
Attached live listener bash "$ROOT/bin/fm-teardown.sh" listener 1; source named; real window and task record preserved
Same task after retire listener-source bash "$ROOT/bin/fm-teardown.sh" listener 0; real window and task record removed
Only another task's live source exists bash "$ROOT/bin/fm-teardown.sh" unrelated 0; other task's source and real window preserved
Secondmate with unread message in child home bash "$ROOT/bin/fm-teardown.sh" mate 1; child-home message named; real window, record and child home preserved
Same secondmate after child-home acknowledgment bash "$ROOT/bin/fm-teardown.sh" mate 0; real window, task record and child home removed
Explicit discard with unread inbox, listener registration and captured round bash "$ROOT/bin/fm-teardown.sh" forced --force 0; task window, record and unread inbox removed without acknowledging the feedback

Trimmed refusal output:

attached message: file=$LAB/state/unread.inbox/001.msg
REFUSED: task unread still has attached feedback; handle the attachments listed above before ordinary teardown.
attached listener: source=capture-source adapter=lavish artifact=session:\n  status: ended\n
attached message: file=$LAB/state/captured.inbox/001.msg
attached result: file=$LAB/state/procevent-inbox/capture-source.1.result owner-task=captured
REFUSED: task captured still has attached feedback; handle the attachments listed above before ordinary teardown.
attached listener: source=listener-source adapter=lavish artifact=$LAB/listener.fifo
REFUSED: task listener still has attached feedback; handle the attachments listed above before ordinary teardown.
attached message: file=$CHILD/state/mate.inbox/001.msg
REFUSED: task mate still has attached feedback; handle the attachments listed above before ordinary teardown.

Trimmed success output, corresponding to the successful table rows:

teardown unread complete (window evidence:fm-unread, worktree $LAB/absent-unread)
teardown captured complete (window evidence:fm-captured, worktree $LAB/absent-captured)
teardown listener complete (window evidence:fm-listener, worktree $LAB/absent-listener)
teardown unrelated complete (window evidence:fm-unrelated, worktree $LAB/absent-unrelated)
teardown mate complete (window evidence:fm-mate, worktree $CHILD)
teardown forced complete (window evidence:fm-forced, worktree $LAB/absent-forced)

Scope and caveats:

  • Task records were deliberately prepared as disposable scouts with reports/completion attestations, real tmux endpoints and nonexistent scratch-copy paths, avoiding any shared copy-pool administration.
  • config/backlog-backend=manual was used; this proves refusal and actual endpoint cleanup, not automatic backlog transitions or copy-pool return.
  • The capture payload was synthetic Lavish-format terminal data emitted by /usr/bin/printf, but its capture, ownership sidecar, delivery instruction and acknowledgment were produced by the real runner.
  • The captured-result refusal naturally includes its attached listener and queued instruction; the API deliberately prevents detaching a source with an unacknowledged round.
  • --force bypassed the new feedback refusal and discarded the task/inbox. It did not delete the source registration or captured-result files; these were acknowledged/retired explicitly during lab cleanup. The claim verified here is that pending feedback does not prevent forced task cleanup, not that force erases every process-event artifact. No pre-PR executable baseline comparison was performed.

All lab endpoints and disposable homes were cleaned up. The complete final driver exited 0, ending with:

ALL CASES PASSED
cleanup_exit=0

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate.

Thank you @ironerumi — that live lab run is exactly what I asked for. It covers all four scenarios on head 62c98044: ordinary teardown refuses and names the attachment for an unread inbox message, an unhandled captured result and an attached listener; each succeeds once the feedback is handled; another task's source doesn't block; a secondmate with child-home feedback refuses; and --force still discards. The note that --force leaves the source registration and captured-result files behind matches the diff (the force path skips the new inventory and doesn't change force cleanup), so that isn't a regression from this PR.

State: head 62c98044 unchanged, every CI job green (run 39038460457), no-mistakes attestation matches this head, branch merges cleanly (CLEAN). Diff review still finds nothing risky.

contract-class: new-default — on main, ordinary teardown treats a leftover unhandled steer as moot and deletes the inbox; with this PR ordinary teardown refuses when task-owned feedback is still attached. That's a well-motivated change (VISION.md: "a refusal to discard is a finding"), but it changes the default teardown behavior, so it isn't auto-merged.

VISION.md: aligns across the rules — refusal surfaces a real pending obligation, --force keeps explicit discard, the inventory is deterministic script work, obligations are retired by the handled record, vendor-neutral, command-layer scope.

This is now a captain-decision hold, not waiting on you: nothing more is needed from you, and Kun will make the merge-or-leave call himself.

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.

Refuse ordinary teardown before discarding attached task-owned feedback

2 participants