Repository navigation
fix(bin): retire task-keyed watcher markers and orphan journals at teardown - #5997
Conversation
Re-applies old PR kunchenguid#5584 on current main: teardown retires the turn-ended .seen-* signature and an orphaned Herdr presentation journal whose workspace is already gone, and the wake-drain rotates its own dead scratch files. Not yet validated through no-mistakes.
|
| status_retire_presentation_task "$STATE" "$ID" || exit 1 | ||
| fm_wake_queue_prune_task "$STATE" "$ID" "$T" 2>/dev/null || true | ||
| rm -f "$STATE/$ID.turn-ended" "$STATE/$ID.progress" \ | ||
| "$(fm_wake_signal_seen_path "$STATE" "$STATE/$ID.turn-ended")" \ |
There was a problem hiding this comment.
Sibling marker can be deleted Valid task IDs such as
a.b and a_b share the same .seen-a_b_turn-ended marker because marker naming replaces dots with underscores. This new removal, also added to the remote and home-child cleanup paths, can therefore delete a sibling task’s marker. If that sibling’s turn-ended file remains, the watcher may treat its already-seen signal as new and queue a duplicate wake.
…sh. fm_backend_herdr_projection_token_workspace_gone used `! ... jq -e ... 2>&1`, which swallowed a jq runtime error (thrown when a non-object workspace entry, e.g. a number before a live token-bearing workspace, hits `.label`) and flipped it to a "gone" verdict, causing teardown to delete a still-live v1 presentation journal. Invariant: a workspace-query error/ambiguity must never be read as token absence; only a cleanly-parsed list with no token-bearing label is "gone". Replaced the body with a single jq verdict (unknown/present/gone): a non-array list or any non-object/non-string-label entry yields "unknown", jq errors/empty output fall through `|| return 1` to unknown, and only "gone" returns 0. Sibling fm_backend_herdr_projection_endpoint_matches_journal already fails safe on jq error (empty match -> journal kept), so it needed no change, matching the author's scoping. Added test_teardown_retains_v1_journal_when_workspace_query_ambiguous driving real teardown with a malformed workspace-list entry, proving the journal is kept and no workspace close occurs. Verified the old logic returns GONE on that input (test fails before, passes after); full tests/fm-teardown.test.sh suite passes (exit 0) and shellcheck is clean. Marker-naming finding left untouched per explicit out-of-scope instruction
kunchenguid
left a comment
There was a problem hiding this comment.
Speaking as Kun's firstmate: tip reviewed vs main — restore teardown of task-keyed watcher markers/orphan journals; green CI+NM; approving for squash-merge.
|
Speaking as Kun's firstmate: this is merged. Thank you @karotkriss — really appreciate you taking the time on this. HEAD Closes #5252: body Contract-class: restore (own tip-vs-main; FM-LEARN-CLAIMS). Main already retires status/heartbeat presentation markers; tip completes the same concrete teardown path for turn-ended VISION.md (each rule)
Firstmate flag: no. Security tip: none. |
…ardown (kunchenguid#5997) * WIP: retire task-keyed watcher markers and orphan journals at teardown Re-applies old PR kunchenguid#5584 on current main: teardown retires the turn-ended .seen-* signature and an orphaned Herdr presentation journal whose workspace is already gone, and the wake-drain rotates its own dead scratch files. Not yet validated through no-mistakes. * no-mistakes(ci): Fixed the Greptile P1 finding in bin/backends/herdr.sh. fm_backend_herdr_projection_token_workspace_gone used `! ... jq -e ... 2>&1`, which swallowed a jq runtime error (thrown when a non-object workspace entry, e.g. a number before a live token-bearing workspace, hits `.label`) and flipped it to a "gone" verdict, causing teardown to delete a still-live v1 presentation journal. Invariant: a workspace-query error/ambiguity must never be read as token absence; only a cleanly-parsed list with no token-bearing label is "gone". Replaced the body with a single jq verdict (unknown/present/gone): a non-array list or any non-object/non-string-label entry yields "unknown", jq errors/empty output fall through `|| return 1` to unknown, and only "gone" returns 0. Sibling fm_backend_herdr_projection_endpoint_matches_journal already fails safe on jq error (empty match -> journal kept), so it needed no change, matching the author's scoping. Added test_teardown_retains_v1_journal_when_workspace_query_ambiguous driving real teardown with a malformed workspace-list entry, proving the journal is kept and no workspace close occurs. Verified the old logic returns GONE on that input (test fails before, passes after); full tests/fm-teardown.test.sh suite passes (exit 0) and shellcheck is clean. Marker-naming finding left untouched per explicit out-of-scope instruction
…ardown (kunchenguid#5997) * WIP: retire task-keyed watcher markers and orphan journals at teardown Re-applies old PR kunchenguid#5584 on current main: teardown retires the turn-ended .seen-* signature and an orphaned Herdr presentation journal whose workspace is already gone, and the wake-drain rotates its own dead scratch files. Not yet validated through no-mistakes. * no-mistakes(ci): Fixed the Greptile P1 finding in bin/backends/herdr.sh. fm_backend_herdr_projection_token_workspace_gone used `! ... jq -e ... 2>&1`, which swallowed a jq runtime error (thrown when a non-object workspace entry, e.g. a number before a live token-bearing workspace, hits `.label`) and flipped it to a "gone" verdict, causing teardown to delete a still-live v1 presentation journal. Invariant: a workspace-query error/ambiguity must never be read as token absence; only a cleanly-parsed list with no token-bearing label is "gone". Replaced the body with a single jq verdict (unknown/present/gone): a non-array list or any non-object/non-string-label entry yields "unknown", jq errors/empty output fall through `|| return 1` to unknown, and only "gone" returns 0. Sibling fm_backend_herdr_projection_endpoint_matches_journal already fails safe on jq error (empty match -> journal kept), so it needed no change, matching the author's scoping. Added test_teardown_retains_v1_journal_when_workspace_query_ambiguous driving real teardown with a malformed workspace-list entry, proving the journal is kept and no workspace close occurs. Verified the old logic returns GONE on that input (test fails before, passes after); full tests/fm-teardown.test.sh suite passes (exit 0) and shellcheck is clean. Marker-naming finding left untouched per explicit out-of-scope instruction
…ardown (kunchenguid#5997) * WIP: retire task-keyed watcher markers and orphan journals at teardown Re-applies old PR kunchenguid#5584 on current main: teardown retires the turn-ended .seen-* signature and an orphaned Herdr presentation journal whose workspace is already gone, and the wake-drain rotates its own dead scratch files. Not yet validated through no-mistakes. * no-mistakes(ci): Fixed the Greptile P1 finding in bin/backends/herdr.sh. fm_backend_herdr_projection_token_workspace_gone used `! ... jq -e ... 2>&1`, which swallowed a jq runtime error (thrown when a non-object workspace entry, e.g. a number before a live token-bearing workspace, hits `.label`) and flipped it to a "gone" verdict, causing teardown to delete a still-live v1 presentation journal. Invariant: a workspace-query error/ambiguity must never be read as token absence; only a cleanly-parsed list with no token-bearing label is "gone". Replaced the body with a single jq verdict (unknown/present/gone): a non-array list or any non-object/non-string-label entry yields "unknown", jq errors/empty output fall through `|| return 1` to unknown, and only "gone" returns 0. Sibling fm_backend_herdr_projection_endpoint_matches_journal already fails safe on jq error (empty match -> journal kept), so it needed no change, matching the author's scoping. Added test_teardown_retains_v1_journal_when_workspace_query_ambiguous driving real teardown with a malformed workspace-list entry, proving the journal is kept and no workspace close occurs. Verified the old logic returns GONE on that input (test fails before, passes after); full tests/fm-teardown.test.sh suite passes (exit 0) and shellcheck is clean. Marker-naming finding left untouched per explicit out-of-scope instruction
Intent
Fixes #5252
After a task is torn down, some per-task state files are never removed: the turn-ended "seen" marker, a Herdr presentation journal whose workspace is already gone, and wake-drain scratch files, so a long-running home accumulates dead files that slow session start and wake drains.
Teardown should retire those task-keyed markers and orphan journals, and the drain should rotate its own scratch files.
Status and heartbeat markers are already retired on main and data// is intentionally kept (reports and briefs live there), so this completes the remaining part of upstream issue #5252.
It is complementary to open PR #5951, which closes an empty projected tab that still exists at session start; this change retires a journal whose workspace or pane is already gone at teardown.
This replaces the earlier pull request #5584, re-applied fresh on current main.
What Changed
.seen-*signature for the task'sturn-endedfile across all three cleanup paths (remote_secondmate_teardown,cleanup_firstmate_home_children, and the main teardown), alongside the existingturn-ended/progressremoval.teardown_herdr_journal_orphanedcheck (backed byfm_backend_herdr_projection_token_workspace_goneinherdr.sh): a version 2 binding of the exact closed pane, or a version 1 attempt whose token-bearing projected workspace is confirmed gone; otherwise-bound or still-present/unreadable journals are retained for the session-start sweep with a warning.fm-wake-drain.shgainsrotate_scratch_locked, run right after acquiring the queue lock, to clear scratch files (.main-eligible-rows.tmp.*,.wake-rows.consume.*,.wake-queue.retire.*,.wake-queue.ack.*,.wake-queue.actor-view.*) left by a drain that died mid-write; docs and teardown tests updated to match.Risk Assessment
✅ Low: A tightly scoped, fail-closed cleanup change: each removed file is matched against the exact marker naming the writer uses, orphan-journal retirement is gated behind confirmed-gone pane proof with retain-on-uncertainty defaults, scratch rotation touches only drain-owned lock-scoped temps, and behavior tests cover the new v1/v2 and rotation paths.
Testing
Ran the two affected behavior suites end-to-end. tests/fm-teardown.test.sh passed 101/101 (exit 0) and tests/fm-wake-queue.test.sh passed (exit 0). Each new scenario invokes the real scripts against a seeded state directory and asserts observable results: the torn-down task's .seen-<id>_turn-ended / .seen-<id>_status / .hb-surfaced-<id> markers and orphaned journal are gone while a sibling task's markers survive; a journal bound to a pane the close never proved gone is retained with a stated warning; a v1 attempt journal is retired only once the session workspace list confirms its token workspace is gone and retained (with warning, no workspace-close escalation) while that workspace is still present; and a locked drain rotates away .main-eligible-rows.tmp.* / .wake-rows.consume.* / .wake-queue.{retire,ack,actor-view}.* leftovers while preserving the live main rows claim. These are the adversarial guards named in the intent (don't over-delete a live-workspace journal, don't touch other tasks' state). No UI surface exists in this shell-CLI change, so no visual artifacts apply. Worktree left clean.bash bin/fm-test-run.sh tests/fm-teardown.test.sh- asserts .seen-task-x1_turn-ended/.seen-task-x1_status/.hb-surfaced-task-x1 and ta…bash bin/fm-test-run.sh tests/fm-wake-queue.test.sh- all five orphaned scratch files removed, .main-eligible-rows preserved, drain exit 0Evidence: Behavior-scenario pass log and suite summaries
Source: Behavior-scenario pass log and suite summaries
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.
bash bin/fm-test-run.sh tests/fm-teardown.test.sh- asserts .seen-task-x1_turn-ended/.seen-task-x1_status/.hb-surfaced-task-x1 and ta…bash bin/fm-test-run.sh tests/fm-wake-queue.test.sh- all five orphaned scratch files removed, .main-eligible-rows preserved, drain exit 0bash bin/fm-test-run.sh tests/fm-teardown.test.sh(101 ok / 0 fail, exit 0) - drives real fm-teardown.sh against seeded state dirsbash bin/fm-test-run.sh tests/fm-wake-queue.test.sh(exit 0) - includestest_drain_rotates_orphaned_scratchdriving real fm-wake-drain.shNew scenarios: test_teardown_retires_task_watcher_markers_and_orphan_journal, test_teardown_retains_journal_bound_to_another_pane, test_teardown_retires_v1_journal_when_projected_workspace_gone, test_teardown_retains_v1_journal_when_projected_workspace_present✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.