Skip to content

feat(bin): add opt-in allowlisted record export - #7750

Merged
kunchenguid merged 18 commits into
kunchenguid:mainfrom
reggiespace:fm/firstmate-record-export-pr
Oct 26, 2026
Merged

kunchenguid merged 18 commits into
kunchenguid:mainfrom
reggiespace:fm/firstmate-record-export-pr

Conversation

@reggiespace

@reggiespace reggiespace commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Open the pull request that implements upstream issue #7642 ("Proposal: opt-in allowlisted record export for read-only consumers", proposed by reggiespace; the maintainer triaged it ready-for-pr). The owner authorized publishing this one contribution to kunchenguid/firstmate. The implementation exists as a local, unpublished branch fm/astrelm-upstream-record-export-rework (10 commits on top of origin/main commit 842eab1; head ab68f68f). It was reworked after an independent review found nine must-fix defects, and a fresh independent re-review and delta re-review concluded it is publishable as is at head ab68f68f (reports: ~/personal/projects/firstmate/data/astrelm-upstream-record-export-review/report.md and ~/personal/projects/firstmate/data/astrelm-upstream-record-export-rereview/report.md).

What Changed

  • [Certain] Adds opt-in fm-record-export commands to publish a fixed allowlist of records as immutable live snapshots and per-task archives, with ownership checks, manifests, and retention.
  • [Certain] Integrates archival into teardown so enabled teardown preserves task records when an archive commit fails; documents the configuration and export behavior.

Risk Assessment

✅ Low: The opt-in exporter uses a fixed allowlist and transactional snapshots; the re-review moves teardown archival after endpoint quiescence and before source cleanup, resolving the retry-ordering concerns without revealing another substantiated defect.

Testing

[Certain] The exporter and remote teardown checks passed, as did the focused endpoint-refusal and retry scenario. The broader teardown script failed at its unrelated leaked-process-reap assertion: lsof is missing, and the test’s tmux shim cannot supply a process-group fallback. No visual artifact applies to this CLI and filesystem behavior.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Configure an export root and sync an allowlisted snapshot; the published snapshot contains only permitted records. ✅ pass live bash tests/fm-record-export.test.sh
Retire a task with export enabled; the archive contains its records, and an archive publication failure preserves the live sources. ✅ pass live bash tests/fm-record-export-remote-home.test.sh; record-export cases in bash tests/fm-teardown.test.sh
Attempt teardown while the endpoint refuses closure, then change its records and retry; no archive is published while it remains live, and the retry archives the updated records. ✅ pass live Focused execution of test_record_export_waits_for_endpoint_quiescence_before_archiving
Evidence: Record export and remote teardown results
ok - record export sync refuses malformed config, traversal-shaped names, symlinks, and non-regular files
ok - teardown archive commits a complete v1 manifest after every allowlisted source
ok - configured remote-home teardown commits its archive before deleting live records
ok - configured remote-home teardown preserves every source when archive publication fails
Evidence: Endpoint refusal and retry result
ok - record export waits for endpoint quiescence and retry captures records changed after refusal

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-teardown.sh:1211 - When export fails after remote retirement removes the route, the error path retains task records but a retry reaches secondmate_registry_line_for_id with no route and refuses before it can archive or clean up; local teardown and forced child teardown have the same ordering problem after their endpoints and worktrees are removed. Move the archive commit before these irreversible cleanup steps, or provide a retry path that remains reachable. The same invariant applies at bin/fm-teardown.sh:1211 (remote route already removed), bin/fm-teardown.sh:3539 (child endpoint/worktree already removed), and bin/fm-teardown.sh:4063 (local endpoint cleanup already ran).

🔧 Fix applied.
2 errors still open:

  • 🚨 bin/fm-teardown.sh:1211 - When export fails after remote retirement removes the route, the error path retains task records but a retry reaches secondmate_registry_line_for_id with no route and refuses before it can archive or clean up; local teardown and forced child teardown have the same ordering problem after their endpoints and worktrees are removed. Move the archive commit before these irreversible cleanup steps, or provide a retry path that remains reachable. The same invariant applies at bin/fm-teardown.sh:1211 (remote route already removed), bin/fm-teardown.sh:3539 (child endpoint/worktree already removed), and bin/fm-teardown.sh:4063 (local endpoint cleanup already ran).
  • 🚨 bin/fm-teardown.sh:3795 - The review-round change archives before endpoint quiescence. If teardown then refuses and the still-live worker changes status or inbox records, retry fails at bin/fm-record-export.py:1010-1012: the committed archive must match current sources, and its immutable spawn_gen cannot be updated. For example, local teardown can publish at bin/fm-teardown.sh:3795, then fail to close the endpoint at bin/fm-teardown.sh:3974-3975; the worker can continue writing before the retry. The same ordering applies to remote teardown before its quiescence check (bin/fm-teardown.sh:1170-1173) and child cleanup before endpoint closure (bin/fm-teardown.sh:3433, with refusal at bin/fm-teardown.sh:3472-3473). The review-round relocation introduced this retry wedge. Archive after the endpoint is quiesced or confirmed stopped, but before removing its records.

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

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Configure an export root and sync an allowlisted snapshot; the published snapshot contains only permitted records. ✅ pass live bash tests/fm-record-export.test.sh
Retire a task with export enabled; the archive contains its records, and an archive publication failure preserves the live sources. ✅ pass live bash tests/fm-record-export-remote-home.test.sh; record-export cases in bash tests/fm-teardown.test.sh
Attempt teardown while the endpoint refuses closure, then change its records and retry; no archive is published while it remains live, and the retry archives the updated records. ✅ pass live Focused execution of test_record_export_waits_for_endpoint_quiescence_before_archiving
  • bash tests/fm-record-export.test.sh
  • bash tests/fm-record-export-remote-home.test.sh
  • bash tests/fm-teardown.test.sh
  • Focused execution of test_record_export_waits_for_endpoint_quiescence_before_archiving from tests/fm-teardown.test.sh
✅ **Document** - passed

✅ No issues found.

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

✅ No issues found.

…me test fixture assignment to clear ShellCheck, and added the missing `spawn_gen` to the export-enabled remote retirement fixture so the expected lost-slot exit code is preserved. ShellCheck, `git diff --check`, and the focused remote-home export test passed. The full lifecycle E2E was blocked locally by an earlier fixture failure (`remote spawn never reached its blocked inheritance write`); CI’s log identified the later failure this fixture correction addresses
…`spawn_gen` field before setting `remote-retirement-test`, preserving the exporter’s exactly-one-generation invariant. `git diff --check` passed. The full remote lifecycle test could not reach this scenario: it failed earlier at “remote spawn never reached its blocked inheritance write,” and cleanup reported permission errors on generated git-hook files
…-secondmate-lifecycle-e2e.test.sh`: it now pins `spawn_gen` after the blocked respawn finishes publishing metadata, so the exporter receives exactly one generation key. `bash -n` and `git diff --check` passed. The full E2E remains blocked by an earlier failure to reach the blocked inheritance write, followed by cleanup permission errors; it did not reach the corrected assertion, captain
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @reggiespace for picking up #7642. The allowlist, the ownership marker and the descriptor-relative snapshot design look careful.

I read the tip against main. Export stays off unless config/record-export-root exists, it starts no network transfer, daemon or watcher, and I found no security concerns in the diff. Two things before this can go further, and this one is waiting on you:

  1. Live evidence. All three "live" rows point at test-suite runs (tests/fm-record-export*.test.sh, tests/fm-teardown.test.sh), and the attestation has no live_validation entry. Could you drive the real product once and post the transcripts? For example: set config/record-export-root on a scratch home, run bin/fm-record-export.sh sync and list live/, then tear down a real finished task and show archive/<task>/<spawn_gen>/manifest.v1.json with the records retired. Re-raising through git push no-mistakes with that evidence works just as well.
  2. One unconfigured-path change. teardown_export_records checks that $CONFIG is a real, readable directory before it checks whether record-export-root exists. On a home that never opted in but keeps config/ as a symlink, every teardown would now fail with "record export config directory is inaccessible or unsafe" and keep the task records. Doing the presence check first ([ -e "$CONFIG/record-export-root" ] || [ -L "$CONFIG/record-export-root" ] || return 0) would keep unconfigured homes exactly as they are today.

CI on 775b173f is still running. Thanks again, this is a big, thoughtful piece of work.

…before config-directory safety checks when `record-export-root` is absent, and added a regression test for an unopted home with symlinked `config/`. The regression passed. The full teardown suite stopped in its existing inaccessible-config case: this environment runs as root, which can read the chmod-000 directory, so that case cannot reproduce its expected refusal here. `bash -n` and `git diff --check` passed; `fm-lint.sh` was blocked because `actionlint` is unavailable. The CI log shows steady test progress followed by GitHub cancelling the job and cleaning up orphan processes, with no reported test failure; treat it as provider cancellation and let the fresh push rerun it
…lar file at the export-root path now deterministically causes export failure, and a symlinked config directory tests the opted-in safety refusal across users, including root. The unopted symlinked-config regression remains intact. The relevant teardown cases passed; `bash -n` and `git diff --check` passed. The full suite later failed an unrelated leaked-process-reap case. Serial 1 was cancelled without a verdict and, per the provided instruction, needs no code change
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @reggiespace. The new head fixes the config precheck. teardown_export_records now returns before any config-directory check when record-export-root is absent, and the new symlinked-config/ regression test covers it. Homes that never opted in now behave exactly as they do today. All 19 CI checks are green on f36c91bd, it's CLEAN against main, and the no-mistakes attestation is bound to this head.

One thing is left, and it's waiting on you: live evidence. The three "live" rows in the Test step still point at test-suite runs (tests/fm-record-export*.test.sh, tests/fm-teardown.test.sh, and a focused teardown test). They don't show a run of the real product. Could you drive it once on a scratch home and post the transcripts? For example:

  • set config/record-export-root, run bin/fm-record-export.sh sync, and list live/
  • tear down a real finished task and show archive/<task>/<spawn_gen>/manifest.v1.json with that task's records retired

Re-raising through git push no-mistakes with real live validation works just as well. Once that's in, this looks close.

@reggiespace

Copy link
Copy Markdown
Contributor Author

Live product evidence completed in a disposable scratch FM_HOME with a throwaway registered Git project and a dedicated private tmux socket.

Enabled path:

$ FM_HOME=<scratch> bin/fm-record-export.sh sync

$ find -L <export-root>/live -printf '%P %y\n' | sort
data/evidence-scout/brief.md f
data/evidence-scout/report.md f
data/projects.md f
state/evidence-scout.meta f
state/evidence-scout.status f

teardown evidence-scout complete (window firstmate:fm-evidence-scout, worktree <pool-worktree>)

$ find <export-root>/archive/evidence-scout -printf '%P %y\n' | sort
s1792981457.1691722.10312/manifest.v1.json f
s1792981457.1691722.10312/meta f
s1792981457.1691722.10312/status f

manifest.v1.json reported schema: firstmate-record-export-archive.v1, schema_version: 1, task: evidence-scout, and complete: true; it mapped state/evidence-scout.meta to meta and state/evidence-scout.status to status, with byte counts and SHA-256 values. After teardown, both live state records were absent. The scout report remained under data/, as expected.

The unconfigured-path regression was also driven through a second real scout lifecycle. config/ was a symlink to an external config directory and record-export-root was absent:

$ readlink <scratch>/config
<external-config-directory>

$ test ! -e <scratch>/config/record-export-root

teardown evidence-off-scout complete (window firstmate:fm-evidence-off-scout, worktree <pool-worktree>)

state/evidence-off-scout.meta retired
state/evidence-off-scout.status retired
state/evidence-off-scout.inbox retired
data/evidence-off-scout/report.md retained

The archive still contained only the first enabled task generation, so the export-disabled teardown neither rejected the symlinked config directory nor created an archive.

@kunchenguid
kunchenguid merged commit 127f0f3 into kunchenguid:main Oct 26, 2026
19 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 live run on a scratch home (an enabled sync and archive, plus an unopted teardown with a symlinked config/) is what got it over the line. I merged it onto main 2b46ed1f locally and the record-export, remote-home and remote-lifecycle suites all passed.

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.

2 participants