Skip to content

feat(bin): archive task status history on teardown behind an opt-in flag - #7407

Merged
kunchenguid merged 4 commits into
kunchenguid:mainfrom
reggiespace:fm/astrelm-upstream-status-archive
Oct 22, 2026
Merged

kunchenguid merged 4 commits into
kunchenguid:mainfrom
reggiespace:fm/astrelm-upstream-status-archive

Conversation

@reggiespace

@reggiespace reggiespace commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Closes #7245.

Teardown deletes state/<task>.status, so a finished task's append-only status history (every working, needs-decision, blocked, resolved, and done line) cannot be audited after cleanup.
This adds an archive of that log at teardown.
The feature is opt-in and off by default: it runs only when config/status-archive exists, and without the flag teardown behaves exactly as before and leaves existing archives untouched.

The maintainer's triage (contract-class new-default, opt-in if gated): gating the archive behind a config switch makes it opt-in, which can land without the project owner's call; a default-on version would go to the owner as merge-or-leave.

How each triage note is met

Triage note How it is met Test
Nothing in presentation, wake, classification, or snapshot code reads the archive Archive paths exist only in bin/fm-teardown.sh; status consumers keep reading live state/ records archive publication and cold logs never re-wake or re-present drives fm-wake-drain.sh and the watcher snapshot after retirement and asserts neither presents nor consumes the archive, and that publication raises no watcher wake
Move only after the presentation cursor is retired, with open-decisions and home-appends bookkeeping cleared as today The live state/<task>.status is removed only after its presentation row is retired, and the archive sits outside anything the watcher reads, so an early copy never makes the task presentable. Publishing first is the safe direction, because a failed archive leaves the cursor and signatures intact. A teardown retried after a failed cursor retirement publishes exactly one archive archive publication and cold logs never re-wake or re-present asserts the cursor row, .home-appends, open-decisions cursor, and watcher markers are gone; failed archive publication preserves presentation and watcher bookkeeping; cursor retirement failure removes its archive so retry publishes one history
Cover the secondmate sub-state path and the remote-home no-op path Forced child retirement archives to data/<secondmate>/children/<child>/ outside the home being removed; a remote home with no parent-side status stays a lock-free no-op forced secondmate retirement preserves two descendant levels and refuses linked child directories; local missing-status retirement stays lock-free without creating an archive; in fm-remote-secondmate-lifecycle-e2e.test.sh, remote retirement archives the complete parent-side status log when enabled and remote missing-status retirement remains lock-free with archival enabled
Symlink-safe, never overwrite an existing archive for a reused id Symlinked or non-regular sources and symlinked archive directories are refused; publication is a same-directory hard link that cannot replace an existing file, and reused ids get status.<N>.log archive sources and directories reject symlinks; pruning never follows children links; reused task IDs never overwrite archives and retention removes only old owned logs
Bound retention Each archival prunes archive logs older than a fixed 30 completed days; age-based pruning works the same under every backlog backend, and prune failures only warn reused task IDs never overwrite archives and retention removes only old owned logs; retention failures warn without aborting unrelated teardown
Consider data/<task>/status.log and document the location Uses data/<task>/status.log, since that folder already survives teardown; documented in docs/architecture.md ("Task status archives") and docs/configuration.md status archival is opt-in and preserves the complete log also proves the default-off path creates and prunes nothing

Also fixes: an already-retired remote home could never retire

This PR also fixes a pre-existing bug on main in bin/fm-remote-secondmate-control.sh, surfaced by the new remote missing-status test.
The control script sources fm-pending-reply-lib.sh and fm-task-inbox-lib.sh, which load fm-wake-lib.sh, and that library runs mkdir -p "$STATE" at source time.
For a remote home that is already gone, this fabricated an unseeded <home>/state before cmd_retire checked the home, so its already-retired branch was unreachable.
That retirement and every retry refused with remote home is not a seeded secondmate home.
The fix recognizes an absent home before any library loads and accepts exactly the retire dispatcher's arguments (retire <id> or retire <id> --force), so an invalid option still fails with usage and nothing is recreated.

What Changed

  • bin/fm-teardown.sh and bin/fm-classify-lib.sh: when the new config switch is enabled, the task's status log is moved to an archive after the presentation cursor is retired, so open-decisions and home-appends bookkeeping is still cleared as before. The archive path never overwrites an existing archive for a reused task id and is symlink-safe. Old archives are pruned on a bounded retention schedule. It is off by default, and teardown behavior is unchanged when it is disabled.
  • bin/fm-remote-secondmate-control.sh: the archive also applies on the secondmate sub-state teardown path and the remote-home no-op path.
  • docs/architecture.md, docs/configuration.md and .agents/skills/operational-home-layout/SKILL.md: document the archive location, the opt-in switch and the retention behavior.
  • tests/fm-teardown.test.sh and tests/fm-remote-secondmate-lifecycle-e2e.test.sh: add coverage for the archive paths, including one showing an archived task cannot re-wake or re-present.

Risk Assessment

✅ Low: The archive is opt-in and off by default. The publish, cursor-retire and rollback ordering holds up on trace. I found no new defect beyond the concerns the user already decided on earlier rounds.

Testing

All the local status-archive scenarios passed against the real teardown entry point: opt-in default, complete log preserved, reused task ids never overwritten, symlinks refused, retention pruning, cursor-failure retry without a duplicate, and an archive never re-wakes or re-presents. The remote-home scenario was not driven. Its lifecycle E2E has failed on this host since the base commit, as earlier runs recorded. The worktree is clean.

  • Live validation: ⚠️ inconclusive - 7 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Tear down a task with archiving off, then on: the default leaves no archive and opt-in writes data/<task>/status.log with the full history ✅ pass live teardown-archive-subset.log: status archival is opt-in and preserves the complete log
Retire a secondmate with nested children: parent, child and grandchild logs are archived, and a symlinked child directory is refused ✅ pass live teardown-archive-subset.log: forced secondmate retirement preserves two descendant levels
Tear down a task with no status file: no archive is created and no lock is taken ✅ pass live teardown-archive-subset.log: local missing-status retirement stays lock-free
Reuse a task id: the existing archive is never overwritten and retention removes only old owned logs ✅ pass live teardown-archive-subset.log: reused task IDs never overwrite archives
Make the archive source or directory a symlink: teardown refuses and pruning does not follow links ✅ pass live teardown-archive-subset.log: archive sources and directories reject symlinks
Fail archive publication or cursor retirement: presentation is preserved, and the retry publishes one history with no duplicate ✅ pass live teardown-archive-subset.log: failed archive publication preserves presentation; cursor retirement failure removes its archive
Archived task cannot re-wake or re-present, and a pruning failure only warns ✅ pass live teardown-archive-subset.log: archive publication and cold logs never re-wake or re-present; retention failures warn without aborting
Retire a remote-home secondmate: the parent archives the status, and a missing status is a lock-free no-op ⏸️ untested no The remote lifecycle E2E aborts on this host before reaching its retirement assertions ('remote spawn never reached its blocked inheritance write'), and it fails the same way on the base commit. Re-ru…
Evidence: teardown archive subset log

Source: teardown archive subset log

ok - teardown leaves opencode's busy plugin in the returned pool worktree as on main
ok - status archival is opt-in and preserves the complete log
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
SUBSET-DONE
- Outcome: ⚠️ 1 warning across 1 run (1m34s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

🔧 **Rebase** - 1 issue found → auto-fixed ✅
  • ⚠️ docs/configuration.md - merge conflict rebasing onto origin/main

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

✅ **Review** - passed

✅ No issues found.

⚠️ **Test** - 1 warning
  • ⚠️ live validation verdict: inconclusive (7 of 8 scenarios were driven live against the product); untested: Retire a remote-home secondmate: the parent archives the status, and a missing status is a lock-free no-op
  • Live validation: ⚠️ inconclusive - 7 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Tear down a task with archiving off, then on: the default leaves no archive and opt-in writes data/<task>/status.log with the full history ✅ pass live teardown-archive-subset.log: status archival is opt-in and preserves the complete log
Retire a secondmate with nested children: parent, child and grandchild logs are archived, and a symlinked child directory is refused ✅ pass live teardown-archive-subset.log: forced secondmate retirement preserves two descendant levels
Tear down a task with no status file: no archive is created and no lock is taken ✅ pass live teardown-archive-subset.log: local missing-status retirement stays lock-free
Reuse a task id: the existing archive is never overwritten and retention removes only old owned logs ✅ pass live teardown-archive-subset.log: reused task IDs never overwrite archives
Make the archive source or directory a symlink: teardown refuses and pruning does not follow links ✅ pass live teardown-archive-subset.log: archive sources and directories reject symlinks
Fail archive publication or cursor retirement: presentation is preserved, and the retry publishes one history with no duplicate ✅ pass live teardown-archive-subset.log: failed archive publication preserves presentation; cursor retirement failure removes its archive
Archived task cannot re-wake or re-present, and a pruning failure only warns ✅ pass live teardown-archive-subset.log: archive publication and cold logs never re-wake or re-present; retention failures warn without aborting
Retire a remote-home secondmate: the parent archives the status, and a missing status is a lock-free no-op ⏸️ untested no The remote lifecycle E2E aborts on this host before reaching its retirement assertions ('remote spawn never reached its blocked inheritance write'), and it fails the same way on the base commit. Re-ru…
  • Ran only the status-archive test cases from tests/fm-teardown.test.sh through the real bin/fm-teardown.sh entry point, as a trimmed copy of the file that was deleted afterwards. Cases: opt-in, nested secondmate, missing-status no-op, reuse and retention, unsafe symlink paths, failed publish, cursor-failure retry, inert archive, and pruning failure.
✅ **Document** - passed

✅ No issues found.

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

✅ No issues found.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @reggiespace — this follows the #7245 triage notes point by point, and the table mapping each note to a test made review easy.

I read tip 0bc504c6 against main 5f2b81bc. The body's Closes #7245 holds: this is the archive-on-teardown the issue asked for, in the gated shape the triage said could land without a captain call. The diff touches bin/fm-teardown.sh, bin/fm-classify-lib.sh, docs, and tests only — no workflow, network, or credential surface — so I approved the pending fork CI runs (CI and both body-compliance runs).

Contract-class (mine): opt-in. Without config/status-archive, teardown_retire_status calls status_retire_presentation_task with no archive argument, so the archive block is skipped and teardown behaves exactly as on main; nothing in presentation, wake, or snapshot code reads the archive. config/ is gitignored, so the flag stays local and is not inherited.

VISION.md per rule:

  1. One captain, one interface: aligns. Nothing captain-facing reads the archive; post-mortems answer from records.
  2. Authority is explicit: aligns. Off by default, switched on only by the captain's own flag.
  3. Scripts own the mechanics: aligns. Deterministic copy + hard-link publication under the existing presentation lock.
  4. A restart is a non-event: aligns. A finished task's history becomes a durable record.
  5. Delegation with a spine: aligns. Validation rounds and decisions stay auditable.
  6. The fleet outlives any vendor: neutral (backend/harness-agnostic, age-based retention).
  7. Scope: aligns. Plain-text records inside the home.

Noted, not blocking: the remote-home archive assertions never ran on your host (the e2e fails earlier on base too), and the review's duplicate-archive-on-retry edge is bounded by retention. CI will run the full suite now. Nothing needed from you right now — this is waiting on CI; if it comes back green it's on the merge path.

@reggiespace
reggiespace force-pushed the fm/astrelm-upstream-status-archive branch from 0bc504c to 7ce5065 Compare October 17, 2026 03:11
@reggiespace reggiespace changed the title feat(bin): archive retired task status history behind an opt-in flag feat: archive task status history on teardown Oct 17, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @reggiespace for the new round. I re-read tip 7ce5065d against main ce697402.

What changed since my last look (0bc504c6): retention is now a fixed 30 days, a failed cursor retirement rolls back its published archive, and there's a bundled fix in bin/fm-remote-secondmate-control.sh. I checked that fix on main. fm-wake-lib.sh runs mkdir -p "$STATE" when it's sourced, so main fabricates <home>/state before cmd_retire looks at the home. That makes the existing already-retired branch unreachable. Your early check (retire arguments only, nothing else changes) is the right fix.

Contract-class (mine): opt-in + restore. Archival still runs only when config/status-archive exists. Without it, teardown_retire_status calls status_retire_presentation_task with no archive argument, the same as main. The remote-retire fix restores an existing, specified default (already-retired for an absent home) that was broken.

On the open no-mistakes review note about publishing before cursor retirement: nothing on main reads data/<task>/status.log, so an early copy can't make a task presentable. The live status still goes away only after its row is retired. I'm fine with that ordering.

VISION.md per rule: one captain: aligns (nothing captain-facing reads the archive) · authority: aligns (off by default, local flag, not inherited) · scripts: aligns (deterministic, lock-protected, no-overwrite publication) · restart: aligns (durable history; a retry no longer wedges an absent remote home) · spine: aligns (auditable) · vendor: neutral · scope: aligns.

The diff touches no workflow, network or credential surface, so I approved the pending fork runs (CI and the three body-compliance runs). Live validation was 4 of 5, and the remote path ran in your e2e rather than live. CI runs tests/fm-remote-secondmate-lifecycle-e2e.test.sh unmodified, so CI decides that one. Nothing needed from you right now: this is waiting on CI, and if it comes back green it's on the merge path.

@reggiespace
reggiespace force-pushed the fm/astrelm-upstream-status-archive branch from 7ce5065 to 14a3e7d Compare October 17, 2026 19:58
@reggiespace reggiespace changed the title feat: archive task status history on teardown feat: preserve task status history on teardown Oct 17, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @reggiespace. I re-read the new tip 14a3e7da against main 4e6b9f59.

What changed since my last look (7ce5065d): this is a rebase. I compared the two diffs and the content is the same, apart from where one teardown test sits after rebase context. The archive gate, the 30-day retention, the rollback on a failed cursor retirement, and the already-retired remote-home fix all match what I reviewed before. On the previous head, every CI job passed except serial 2, which was cancelled at the 30-minute ceiling (the known infra limit tracked in #7255).

Contract-class (mine): opt-in + restore, unchanged. Archival runs only when config/status-archive exists. Otherwise teardown behaves as on main. The remote-retire fix restores the existing, specified already-retired default for an absent home.

VISION.md per rule: one captain: aligns · authority: aligns (off by default, local flag) · scripts: aligns (deterministic, lock-protected, no-overwrite publication) · restart: aligns (durable history) · spine: aligns · vendor: neutral · scope: aligns.

The diff touches no workflow, network or credential surface, so I approved the four pending fork runs on this head (CI and three no-mistakes/body-compliance runs). Live validation was 4 of 5. The remote path is covered by tests/fm-remote-secondmate-lifecycle-e2e.test.sh in CI, so CI decides that one.

Nothing needed from you right now: this is waiting on CI. Heads-up: #7448 also edits bin/fm-teardown.sh and bin/fm-remote-secondmate-control.sh, so whichever lands second may need a small rebase.

@reggiespace
reggiespace force-pushed the fm/astrelm-upstream-status-archive branch from 14a3e7d to 3284130 Compare October 21, 2026 02:59
@reggiespace reggiespace changed the title feat: preserve task status history on teardown fix: archive task status history on teardown Oct 21, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @reggiespace for bringing this up to date. I re-read the new head 3284130e against main.

What changed since my 10-17 look (14a3e7da): only a rebase. I compared the two PR diffs, and the only differences are surrounding context lines from main in .agents/skills/operational-home-layout/SKILL.md and docs/configuration.md. The archive gate, the 30-day retention, the rollback after a failed cursor retirement, and the already-retired remote-home fix are unchanged. CI on the previous head 14a3e7da (run 39064725922) was fully green.

Contract-class (mine): opt-in + restore, unchanged. Archival runs only when config/status-archive exists. Without it, teardown matches main. The remote-retire fix restores the existing, specified already-retired default for an absent home.

VISION.md per rule: one captain aligns · authority aligns (off by default, local flag) · scripts aligns · restart aligns (durable history) · spine aligns · vendor neutral · scope aligns.

The diff still touches no workflow, network or credential surface, so I approved the four pending fork runs on this head (CI 39536053525 and no-mistakes 39536053363, 39536078739, 39537179101). The attestation binds this head, with live validation at 4 of 5. CI's remote lifecycle e2e covers the remote path.

Nothing needed from you right now: this is waiting on CI. If it comes back green and still mergeable, it's eligible to land. #7448 still overlaps on files, so whichever lands second may need a small rebase.

…ated

Sourcing fm-wake-lib.sh through the control script's libraries creates
"$FM_HOME/state", so retiring a remote home that was already removed
fabricated an unseeded directory before validate_home ran. The
already-retired branch was unreachable, and that retirement and every
retry refused with "remote home is not a seeded secondmate home".

Check for the absent home before loading any library, accepting exactly
the retire dispatcher's arguments so an invalid option still fails with
usage, and drop the allow-absent branch that could no longer be reached.
@reggiespace
reggiespace force-pushed the fm/astrelm-upstream-status-archive branch from 3284130 to 0f2ff2d Compare October 21, 2026 06:53
@reggiespace reggiespace changed the title fix: archive task status history on teardown feat(bin): archive task status history on teardown behind an opt-in flag Oct 21, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @reggiespace for the rebase. I re-read the new head 0f2ff2de against main 8eb9be51.

What changed since my 06:21Z look (3284130e): only a rebase onto current main. I compared the two PR diffs line by line, and the only difference is one blank context line. The config/status-archive gate, the 30-day retention, the rollback after a failed cursor retirement, and the already-retired remote-home fix are all unchanged.

Contract-class (mine): opt-in + restore, unchanged. Archival runs only when config/status-archive exists (teardown_retire_status returns before any archive work otherwise), so teardown with no flag matches main. The remote-retire fix restores the existing already-retired default for an absent home.

VISION.md per rule: one captain aligns · authority aligns (off by default, local flag) · scripts aligns · restart aligns (durable history) · spine aligns · vendor neutral · scope aligns.

The diff still touches no workflow, network or credential surface, so I approved the four pending fork runs on this head (CI 39558229525 and no-mistakes 39558229610, 39558261531, 39558706830). The attestation binds this head.

Nothing needed from you right now: this is waiting on CI. If it comes back green and still mergeable, it's eligible to land.

@reggiespace

Copy link
Copy Markdown
Contributor Author

Thanks for approving the runs. The two red jobs on head 0f2ff2d look unrelated to this change, and we lack admin rights to re-run them, so could you re-run the failed jobs on CI run 39558229525?

  • Behavior portable serial 2: cancelled by the 30-minute job cap while still passing tests (last test passed at 10:49:34Z, no 'not ok' in the log).
  • Behavior tests (Herdr): fails in tests/fm-backend-herdr-presentation-e2e.test.sh at 'concurrent secondmate recovery' (session-lock refusal). The same failure hit main on 2026-10-20 (CI runs 39506645686 and 39506454292), and this PR touches no Herdr code.
    Main itself was red today (2c93247, f1ef029) on other timing-sensitive tests. If you would rather have a fresh run, say so and we will push a rebase.

@kunchenguid
kunchenguid merged commit df9eb03 into kunchenguid:main Oct 22, 2026
54 of 57 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @reggiespace — really appreciate you taking the time on this.

The reruns you asked for came back: CI run 39558229525 is fully green on head 0f2ff2de (serial 2 and Herdr both passed on the rerun), the no-mistakes attestation binds this head, and the only main changes since your base were unrelated one-line touches in teardown/docs. Contract-class stays opt-in + restore.