Repository navigation
fix(bin): resolve captain holds and legacy teardowns on non-markdown backends - #3782
kunchenguid merged 12 commits into
Conversation
Confidence Score: 5/5The PR appears safe to merge because the previously reported legacy teardown retry bypasses are no longer reachable. No blocking failure remains; valid retained legacy stamps are treated as legacy records and must pass the dead-or-missing endpoint gate again, while malformed or duplicate incarnation fields refuse teardown. Reviews (6): Last reviewed commit: "no-mistakes(ci): Fixed the Greptile P1 o..." | Re-trigger Greptile |
|
Speaking as Kun's firstmate: Triage on HEAD Contract-class: restore / configured-backend — resolves legacy hold/teardown records through the configured tasks-axi backend (beads only when configured; not always-on BEADS_ACTOR / not a second tracker). OK under no-beads learning. VISION: (1)–(7) OK for the intended restore, but not merge-ready while tip attestation/NM/Greptile are uncleared. Outcome: waiting-author — please (1) re-raise via no-mistakes so tip attestation MATCH and NM green, (2) address Greptile P1 on legacy-stamp rollback so a failed close-marker path cannot skip the endpoint gate. Not waiting-captain. Security FYI (not waiting-captain): Greptile P1 — failed legacy-stamp rollback can let a retry kill a newly live agent on a reused endpoint. Fix before merge; tip-only FYI while author clears. |
Two pre-Beads reads blocked honest closure of leftover records: 1. fm-captain-hold.sh complete/verify resolved attested legacy hold ids only against the live backend and the pre-collapse derived identity, so a home whose holds fm-hold-migration rehomed under fm- ids failed with an empty-name absence message (the resolve failure was swallowed by the command substitution feeding verify_hold_durable). Resolution now falls back, on the Beads backend only, to the legacy id under the configured beads prefix and to the row whose notes carry the exact marker line 'migrated from data/backlog.md id <legacy id>'; every refusal names the id it could not resolve, and the markdown path is unchanged. 2. fm-teardown.sh refused any record without spawn_gen forever. A record that predates the field can now be torn down with an explicit --legacy-record flag once the recovery-grade endpoint classifier confirms the recorded endpoint dead or agent-less; the accepted incarnation is stamped into the record right before its close marker binds to it and named in the teardown line. Refusals leave the record byte-identical, the unlanded-work refusal is not relaxed, and a corrupt (multi-valued) spawn_gen is never accepted. The companion repair this branch carries (follow-up commit) is the backend-gated --file and markdown-file requirement in the mutate path and lifecycle gates: fm_backlog_mutate passed --file and required the markdown backlog file regardless of the resolved backend, and the transition gate plus row probe required that file before any backend work, so a home on a non-markdown backend could neither gate, probe, nor close its rows. Behavior tests: self-contained beads fixtures over a scratch bd graph (self-skipping on markdown-only tasks-axi installs), legacy meta fixtures for every teardown gate, and the relocated markdown backlog coverage stays green.
…and guard legacy spawn_gen stamp against newline-less records
Completes the fm-backlog-transition-lib repair the first commit's message claims: on this base fm_backlog_mutate passed --file and required the markdown backlog file regardless of the resolved backend, and fm_backlog_transition_applies plus fm_backlog_row_probe required that file before any backend work, so a home on a non-markdown backend could neither gate, probe, nor close its backlog rows. All three now gate the markdown file on the resolved tasks-axi backend: markdown keeps exactly its explicit <data>/backlog.md behavior, non-markdown homes address the backend their own configuration selects with no markdown file requirement. fm_backlog_row_show and fm_backlog_row_list already gated correctly and are unchanged. docs/configuration.md owns the contract line. Also extends the same backend gate to fm-captain-hold.sh's own mutation wrapper - hold/add/update/answer/done append the markdown --file only when the resolved backend is markdown, so a captain call on a Beads home reaches the Beads store end to end - and applies the review round's two direct remedies there: the [beads] graph path resolves against the backlog root when relative (never the process CWD), and a failed bd graph read reports bd's own trimmed stderr reason in the refusal. Coverage: tests/fm-backlog-atomicity.test.sh gains a stub-driven Beads completion case proving the transition gate applies, the row probe reads, and done runs without any markdown file or --file override; the relocated markdown backlog test stays green.
… migrated-hold resolution
…kend-aware transition lib The legacy-records change made fm-backlog-transition-lib.sh resolve the configured backend via fm_tasks_axi_backend before the markdown-only skip. The gotmp fixture's fm-tasks-axi-lib stub lacked that function, so the markdown check fell through and teardown hit the incompatible-backend error with unbound FM_TASKS_AXI_MIN under set -u. Stub the backend as markdown and define the floor, restoring the intended no-backlog skip.
A legacy-record teardown stamps its accepted incarnation into the record right before the close marker binds to it; when that marker write then fails, the stamp survived, so a retried teardown sailed past the dead-or-agent-less endpoint gate the stamp now proved unnecessary. The failed marker write now truncates the record back to its exact pre-stamp bytes (verified by size), restoring the byte-identical-refusal invariant; when the rollback itself fails the operator is told to re-run with --legacy-record after reconciling the endpoint. Also completes the recorded review decision's coverage wording: the beads stub test now drives the answer close end to end (update and done through the gated wrapper), asserting no markdown file override reaches either verb.
…rated ids The legacy-record stamp rollback now uses perl (already in the teardown curated PATH; truncate is not, and is absent on stock macOS), routes every failure branch inside the stamp block through the same size-verified rollback so the byte-identical-refusal invariant holds on those paths too, and gains behavior coverage: an unrecordable close (an invalid pr= link) fails the teardown, leaves the record byte-identical, keeps the backlog row in flight, and a flag-less retry still refuses. Migrated-hold resolution now probes the derived pre-collapse identity (<origin>-decision-<entry>) alongside the raw entry - fm-hold-migration recorded the DERIVED id in every migrated row's marker note - in both the prefix and the migration-note forms, with the ambiguity refusal naming every identity tried, plus behavior coverage for a bare decision key resolved through its derived identity's marker. Also aligns fm-backlog-transition-lib.sh's header ADDRESSING/SCOPE paragraphs with the backend-gated contract, drops an unreachable FORCE validity guard the parser rewrite left behind, and switches the new stub fixture to the portable sed -i.bak idiom.
ff64a0d to
9900bb1
Compare
…d rollback of the synthetic legacy stamp let a retry bypass the dead-or-agent-less endpoint gate. Root cause: teardown minted `spawn_gen=legacy-<ts>-<pid>` into the task record before the close marker bound to it. When the close-marker write failed AND the rollback also failed, the record retained that token. On the next invocation `fm_backlog_meta_spawn_gen` succeeded, so `TEARDOWN_LEGACY_PENDING` stayed 0 and the endpoint gate was skipped entirely — even with `--legacy-record`. The script's own error text told the operator to "re-run teardown with --legacy-record", advice the code could not honor. Fix (bin/fm-teardown.sh): - A `legacy-*` spawn_gen is now recognized as a stamp this teardown path minted, never one a spawn published (fm-spawn.sh publishes `s<epoch>.<pid>.<random>`). Such a record still reads as the legacy record it is: it re-enters the endpoint gate, and a flag-less retry refuses naming `--legacy-record`. - Acceptance reuses the retained token instead of minting a second one; the append block is skipped when the record already carries it, so no duplicate spawn_gen is written. - The rollback attempt and its "could not be rolled back" message are guarded to runs that actually appended a stamp, so a run that appended nothing never claims a rollback it did not perform. - Usage header documents the retained-stamp rule. Test (tests/fm-teardown.test.sh): added `test_retained_legacy_stamp_still_faces_the_endpoint_gate`, an end-to-end reproduction — a `perl` stub that fails only the rollback's `truncate` (delegating every other perl call to the real interpreter) leaves the stamp behind, then the retry must still hit the gate, must not stamp a second incarnation, must not close the backlog row, and the flag-less retry must refuse. Verification: the new test fails against the pre-fix script on exactly the reported defect ("the retry skipped the dead-or-agent-less endpoint gate") and passes after. Full tests/fm-teardown.test.sh 80 ok / 0 failures / rc=0; tests/fm-backlog-atomicity.test.sh 80 ok / 0 failures / rc=0; bin/fm-lint.sh (pinned ShellCheck 0.11.0 + actionlint 1.7.12) clean
|
Speaking as Kun's firstmate: Merging. HEAD Contract-class: restore — captain-hold completion and teardown already promised to address the home's configured tasks-axi backend; this removes the markdown-only greps/ VISION: aligns on scripts-own-mechanics, restart durability (closable holds/teardowns), and authority (backend from config, not inferred). Scope stays command-layer backlog tools. CI green (NM pass, Greptile 5/5, attestation MATCH, MERGEABLE/CLEAN). Auto-merge eligible. |
|
Speaking as Kun's firstmate: this is merged. Thank you @RooseveltAdvisors — really appreciate you taking the time on this. |
Upstream main advanced 21 commits past the PR base, including kunchenguid#3782 (resolve captain holds and legacy teardowns on non-markdown backends), which touches the same gate library this PR collapses. Merge-conflict resolution: - bin/fm-backlog-transition-lib.sh: keep this PR's collapsed single-owner gate (fm_backlog_source_present + fm_backlog_tasks_axi) everywhere; upstream's post-kunchenguid#3582/kunchenguid#3782 markdown-only checks are subsumed by it. Upstream's new legacy-close/reopen body (retain-mode deliverable recording) auto-merges and now routes through the collapsed gate. - bin/fm-captain-hold.sh: take upstream's tasks_axi (explicit --file for the markdown backend only) - it is exactly the addressing this PR restores for configured adapters, and this PR deliberately left the function's behavior untouched. - docs/configuration.md: keep this PR's gate description and add upstream's migrated-hold [beads] resolution sentence. - tests/fm-gotmp.test.sh: keep upstream's new fm_tasks_axi_backend stub in the fake tasks-axi lib. Validation: bash -n and ShellCheck clean on both resolved scripts; tests/fm-backlog-atomicity.test.sh 87 ok (including upstream's new configured-adapter cases), tests/fm-lint.test.sh 29 ok, tests/fm-teardown.test.sh 80 ok, tests/fm-gotmp.test.sh 3 ok, all rc=0.
Intent
The developer wanted two leftover firstmate records in the main home to be closeable now that the home runs on the Beads backend, so they asked for fixes to the two tools that still assumed the pre-Beads markdown world. First, bin/fm-captain-hold.sh's completion path had to stop grepping data/backlog.md and instead resolve every attested captain-held task id through the configured backend (tasks-axi/beads per the transition library's data-directory contract), falling back for migrated items either by the exact notes marker "migrated from data/backlog.md id " or by the legacy id with the configured prefix prepended, while still working on markdown homes and naming the id in any refusal (the old message printed an empty name). Second, bin/fm-teardown.sh had to allow tearing down a record that predates spawn_gen when the caller passes an explicit --legacy-record flag, the recorded endpoint is dead or a bare shell, and the worktree passes the ordinary landed test, logging the accepted legacy incarnation while never relaxing the unlanded-work refusal. They also required colocated behavior tests for both paths using a beads fixture home, kept CI-portable via self-skipping since the runner only has markdown-only tasks-axi plus npm bd. Validation had to run through the no-mistakes pipeline on a branch, driving every gate via respond without --yes, escalating ask-user findings rather than answering them, and reporting the PR URL once checks were green.
What Changed
bin/fm-backlog-transition-lib.sh,bin/fm-captain-hold.sh) now branch on the home's configured tasks-axi backend: the explicit--file <data>/backlog.mdoverride and the markdown-file presence requirement apply to the markdown backend only, so a non-markdown home is addressed from its addressing root by its own.tasks.tomland no longer needs a markdown backlog to exist.bin/fm-captain-hold.shresolves an attested legacy markdown id that names no task through the markdown-to-beads migration: it scans the configured beads graph ([beads]path/binaryfrom the root.tasks.toml, viabd list --all --json+jq) for a notes marker linemigrated from data/backlog.md id <legacy id>(bare oron <date>), and only when no row carries that marker falls back to the legacy id under the configured prefix — accepted solely for a single still-captain-held row, with ambiguity and scan failures refusing (rc=2) rather than attesting.completenames each prefix-resolved row in its output,answersreports scan refusals as skips, and refusals now name the id and the configured backlog instead of printing an empty markdown path.bin/fm-teardown.shaccepts a--legacy-recordflag for records that predatespawn_gen: teardown proceeds only when the recorded endpoint classifies as dead or missing, stamps alegacy-<timestamp>-<pid>incarnation into the record immediately before the close marker is written (rolling the stamp back to the record's pre-stamp bytes if the marker write, append, or validation fails), names the accepted incarnation in the teardown line, and never relaxes the unlanded-work refusal; option parsing moved to a loop and the backlog reminder names the configured backend on non-markdown homes. Behavior tests were added for both paths intests/fm-captain-hold-lifecycle.test.sh,tests/fm-teardown.test.sh, andtests/fm-backlog-atomicity.test.sh(beads cases self-skip wherebdis unavailable), withdocs/captain-hold-lifecycle.mdanddocs/configuration.mdupdated to match.Risk Assessment
✅ Low: The migrated-hold resolution, backend-gated addressing, and legacy-record teardown paths all traced cleanly against concrete inputs, the new tests assert observable behavior rather than source text, and both errors the earlier fix rounds introduced (the CLAUDE.md block and the tracked .codegraph artifact) are fully reverted with a clean worktree.
Testing
Completed 1 recorded test check.
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-teardown.sh:1291- backlog_refresh_reminder still names<data>/backlog.mdunconditionally, and this branch is what makes that line reachable on a home that has no such file. Concrete: the branch's own new case tests/fm-backlog-atomicity.test.sh:test_completion_omits_the_file_for_a_beads_done writesbackend = "beads", doesrm -f "$home/data/backlog.md", and teardown now succeeds (before this change fm_backlog_transition_applies skipped on the missing file). The final line therefore printsBacklog: atomic-completion-beads-b1 is closed in <case>/data/backlog.md- a closure claim located in a file that was explicitly deleted, and on the retain branch (line 1289) it tells the operator the item "stays open in" that nonexistent path. The remedy is the pattern this branch already applied in bin/fm-captain-hold.sh:433/852: name the configured backlog by data directory when fm_tasks_axi_backend is not markdown, and keep the file name only for markdown homes.bin/fm-captain-hold.sh:583- The configured-prefix fallback accepts any existing row whose id happens to be<prefix>-<entry>with no migration evidence at all, and it is tried BEFORE the authoritative marker-note scan (line 589), so it shadows a correctly-marked row. The branch's own test test_verify_resolves_a_hold_migrated_under_the_configured_prefix proves the unverified acceptance: legacy idother-legacy-rowresolves tofm-other-legacy-row, a row carrying no marker note whatsoever. On a home whose beads prefix isfm(the migration's own prefix), an ordinary task filed asfm-<key>- or a beads auto-allocatedfm-<n>against a numeric legacy id - is indistinguishable from a migrated row, soverify/completecan attest against an unrelated captain-held task instead of the migrated one. The prefix fallback itself is explicitly what was asked for; what needs your call is the ordering (scan the marker notes first, use the bare prefix guess only when no marker matches) and whether the prefix hit should be required to carry the marker line.tests/fm-captain-hold-lifecycle.test.sh:434- Two of the three new--fileregression assertions can never fail. assert_no_grep (tests/lib.sh:344) isgrep -F, so the.*inassert_no_grep "update $id --body-file .* --file"is matched literally and no log line can ever contain it. Line 422'sassert_no_grep "hold $id --file"is also vacuous: the captain-hold wrapper appends--fileLAST (bin/fm-captain-hold.sh:291), so a markdown-backend call logshold <id> --reason ... --kind captain --file <path>and the asserted adjacency never occurs. (Line 438'sdone $id --fileis real, because that call has no other flags.) The regression is still genuinely caught - the stub hard-fails on--fileand the invocation exits non-zero - but the assertions as written protect nothing; asserting the literal--filetoken in the log would.tests/fm-captain-hold-lifecycle.test.sh:106- The comment citestests/fm-stale-sweep.test.shas the self-skipping precedent, but that file does not exist anywhere in the repo (this comment is its only mention). The actual precedent for thepass "skipped ..."idiom is tests/fm-control-relaunch.test.sh.🔧 Fix: Name the configured backend in teardown's backlog reminder
2 errors still open:
CLAUDE.md:4- The fix round appended a 9-line CODE-INTEL-ROUTING block to CLAUDE.md..github/workflows/ci.yml:424(jobinvariants, step "Compatibility pointers must stay intact") doescmp -s CLAUDE.md "$tmp"against the exact two-line@AGENTS.mdpointer and exits 1 with::error::CLAUDE.md must be the canonical @AGENTS.md pointer. With this block present that job fails deterministically on every push of this branch. It also contradicts the repo's own stated contract (bin/fm-ensure-agents-md.shheader: "CLAUDE.md is a real regular file whose canonical content is the two-line @AGENTS.md pointer"; AGENTS.md:42 lists it as shared tracked material), and the block is unrelated to this branch's intent - it was written by the fixer'scode-index.shtooling, references machine-local MCP servers, and is not part of the legacy-record work. Remedy: drop the block, restoring CLAUDE.md to its two canonical lines (if the routing guidance is wanted, AGENTS.md is where project-intrinsic knowledge belongs)..codegraph/.gitignore:1- The same fix commit added a tracked.codegraph/.gitignore. This run's test step isbin/fm-test-run.sh --changed --exclude-family real-herdr-gated(.no-mistakes.yaml:55).families_for_changed_pathin bin/fm-test-run.sh has no case matching.codegraph/.gitignore(the exempt arm isREADME.md|LICENSE|assets/*|docs/*|.gitignore- root-level only), so it falls to*)->families_for_test_reference '.codegraph/.gitignore', no test file contains that string, so it emits__unmapped__:andselect_changedcallsdie "no changed-test mapping for source path: .codegraph/.gitignore"(bin/fm-test-run.sh:1436). The test phase aborts before running a single suite. The file is also purely a machine-local artifact: it exists only to hide the 4.0 MB.codegraph/codegraph.dbthis worktree's indexer wrote, and has nothing to do with the legacy-record change. Remedy: drop.codegraph/from the change entirely; if the ignore is genuinely wanted, put.codegraph/in the root.gitignore, which the selector explicitly exempts.🔧 Fix: Scan migration markers before the prefix guess
3 issues (2 warnings, 1 info) still open:
bin/fm-captain-hold.sh:616- The prefix fallback accepts a row only whilehold_kindis stillcaptain, butanswerswith close modereleaserunsclose_answered <id> 1->tasks-axi unhold(bin/fm-captain-hold.sh:825-831), which clearshold_kindwhile leavingstate != done. Concrete sequence on a beads home whose migrated row carries no marker note (exactly what this branch exists for): (1)answers <origin>with modereleaseresolves the legacy key through the prefix branch and releases the hold; (2) the row now hashold_kindempty plus a resolution record in its body; (3) the scout teardown'scomplete/verifyre-resolves the same attested key --task_show <legacy>still fails, the marker scan still finds nothing, and line 616 nowcontinues past the very row it just answered, soprefixed_countis 0 andresolve_entryreachesfail "no captain-held task ... and no migrated hold for it". That refusal contradictsverify_hold_durable(line 436-438), which was written to accept precisely this answered-and-released state viabody_has_resolution_record, and it blocks the scout teardown the branch's own intent is trying to unblock. Thedoneclose mode is unaffected (tasks-axi keepshold_kindthrough a close, per the comment at line 907). Thehold_kind = captainrestriction was your explicit instruction last round, so tightening/loosening it is your call: the minimal correction is to also accept a prefixed row whose body already carries a resolution record (the same evidenceverify_hold_durabletrusts), keeping the sole-candidate requirement. The remedy changes an authorized safety constraint, which is why it needs your decision rather than an auto-fix.bin/fm-captain-hold.sh:125- Commit cdcf0f5 reordered resolution (marker note first, prefix guess only as a last resort) and narrowed the prefix guess to a single captain-held row, and it updated the section comment at line 446-458 -- but not the two places this repo treats as the owning contract. The script header at lines 123-126 still reads "accepted through the migrated row fm-hold-migration produced: the legacy id under the configured beads prefix, or a row whose notes carry the exact marker line", listing the prefix guess FIRST as a co-equal alternative. docs/captain-hold-lifecycle.md:113 carries the identical superseded sentence. Neither mentions that the prefix guess is only reached when no marker matches, nor that it requires a still-captain-held sole candidate. A maintainer reading either one will conclude the prefix name alone is sufficient evidence and is tried first -- the exact belief the fix round was meant to correct. (The prior round already required this same header-contract discipline for bin/fm-backlog-transition-lib.sh.)tests/fm-captain-hold-lifecycle.test.sh:220-test_verify_resolves_a_hold_migrated_under_the_configured_prefixattests idother-legacy-rowagainst rowfm-other-legacy-rowand asserts only thatverifyexits 0. By the new sibling test's own comment (line 246-248: "the real one resolves a bare legacy id onto its prefixed row itself, answering before any migration lookup runs"), the real beads-capable tasks-axi resolves the bare legacy id, soresolve_entry's firsttask_show "$entry"probe (line 636) answersexactand the prefix branch is never entered. The test therefore passes unchanged even if the entire prefix fallback is deleted -- it does not prove what its name claims. Coverage of the branch is real but comes solely fromtest_marker_noted_row_wins_over_a_prefix_namesake, which stubs tasks-axi to make the ordering observable. Either fold the stub into this test or note in its body that it is an end-to-end smoke case, not prefix-branch coverage.🔧 Fix: Document marker-first resolution and cover the prefix branch
2 infos still open:
bin/fm-backlog-transition-lib.sh:308- The six new backend gates select markdown addressing only on an exact= markdownmatch (fm_backlog_transition_applies:195, fm_backlog_row_show:220, fm_backlog_row_list:232, fm_backlog_row_probe:255, fm_backlog_mutate:308, and fm-captain-hold.sh:292), so any value that is neithermarkdownnor a real backend name silently selects the no---filepath.fm_tasks_axi_backenditself deliberately fails safe in the opposite direction, returningmarkdownwhen nothing resolves (bin/fm-tasks-axi-lib.sh:153), so the callers are less conservative than the helper they consult. Concrete: exportTASKS_AXI_BACKEND=(set but empty) - the${TASKS_AXI_BACKEND+x}branch at bin/fm-tasks-axi-lib.sh:140 prints the empty string,[ "" = markdown ]is false, andfm_backlog_mutaterunscd <root> && tasks-axi done <id>with no--file. On the ordinary layout that is a no-op (the root.tasks.tomlresolvesdata/backlog.mdto the same file), but on the relocated-data-directory case this addressing exists for - a root with no.tasks.toml, which the header at line 38 says "gets tasks-axi's built-in defaults" - the close lands in tasks-axi's default store instead of<data>/backlog.md, and reports success.backend = ""in a root.tasks.tomlreaches the same state through fm_tasks_axi_backend_from_toml. Remedy is mechanical: treat an empty resolved backend as markdown at the gate, matching the helper's own default.bin/fm-captain-hold.sh:588- The reorder makescaptain_migration_scan_loada hard precondition for the prefix fallback:resolve_migrated_entrynow returns 2 whenever the graph cannot be read (missingbd, missingjq, no[beads] path, or a failedbd list), before the prefix branch at line 601 ever runs. Before the reorder the prefix guess used onlytasks-axi showand needed neither binary, so on a beads home withoutjqorbdaverify/completethat previously resolved a migrated hold now hard-refuses - which also blocks the scout teardown gate at bin/fm-teardown.sh:2741. This follows directly from the authorized marker-first ordering (you cannot know whether a marker exists without reading the graph), so I am flagging it as a consequence to be aware of rather than a defect; docs/configuration.md:98 names only the missing-[beads]-section trigger for rc=2, not the missing-binary one.bin/fm-test-run.sh --changed --exclude-family real-herdr-gated✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.