Repository navigation
feat(bin): record durable task outcomes and extend fleet telemetry - #27
Merged
Merged
Conversation
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
HelloWorldSungin
force-pushed
the
fm/fleet-outcome-manifest
branch
from
August 4, 2026 06:47
d78036e to
e1d92fa
Compare
added 9 commits
August 4, 2026 07:21
A finished task used to leave nothing structured behind. Teardown removes state/<id>.meta, and the backlog's Done section is pruned to a recent window, so once a task was cleaned up there was no canonical record of what it was, what it shipped, or which session ran it. Nothing downstream could attribute its usage, ingest its outcome, or place it in history. Introduce three data contracts and project all three through the read-only fleet snapshot: - data/<id>/outcome.json (fm-outcome-manifest.v1) is the canonical completion manifest. Teardown publishes it atomically before removing the volatile records it is composed from, and refuses the cleanup when publication fails rather than erasing a task it could not archive. - data/<id>/work-items.json (fm-work-items.v1) carries forge- and host-agnostic work-item references, several per task or none, each marked as declared at intake or derived from a PR, with nullable enrichment consumers must render without. This owns storage and transport only; population and per-forge resolution stay with the project-issue-linkage work. - state/<id>.pr-status (fm-pr-status.v1) holds one normalized review, check, and mergeability observation per PR, refreshed only by fm-pr-status.sh so read-only consumers never call a forge. fm-fleet-snapshot.v1 grows additively, so existing v1 consumers keep working unchanged: task model and effort, the last task-event timestamp and its age, the parsed PR identity with its normalized state, work-item references, a computed card column resolved against a published and tested precedence ladder, watcher heartbeat age with away-mode state, and manifest-backed durable history that outlives teardown. Secret safety is enforced rather than described. A fixed recursive key allowlist gates manifest publication, so a field can only be emitted by being declared in one place, and every free-text value is stripped of control characters, collapsed to one line, and length-capped. jq becomes a universal bootstrap requirement: the snapshot, the dispatch profile reader, and now the manifest all depend on it, and without it a home cannot archive a finished task.
A retired secondmate's state and data directories can live inside the home teardown removes, which is exactly the shape the remote parent-route shadow uses. Publishing the manifest after that removal left the writer with no task metadata to compose from, so the remote lifecycle end-to-end run failed on a retirement that should have succeeded. Move the publication to the last point where every source record still exists: after the final refusal gate and the confirmed endpoint close, before the home removal. Pin it with an assertion that a retired secondmate leaves a manifest recording its retirement in the parent's durable history. Also give the gate-refusal teardown fixture its own data directory so the suite stops writing a manifest into the repository's own gitignored data/.
The old-versus-new teardown conformance case rebuilds a bin/ tree from a fixed sibling list, and teardown now shells out to fm-outcome-manifest.sh. Without the writer and its library in that tree the rebuilt teardown could not publish a manifest and refused a cleanup that should have succeeded.
CI caught two ways the hardening round's value validation was stricter than the rest of firstmate, and because teardown refuses when a manifest cannot be published, each one made a real task impossible to clean up. The task-id rule invented a 64-character cap and a bounded character pattern. bin/fm-pr-lib.sh's fm_task_id_path_safe has no length cap, so a legacy id the whole rest of the system accepts could not be archived and its teardown refused. The manifest now mirrors that predicate exactly: the archive records the ids that exist rather than policing them. The mode field was validated against a closed delivery-mode vocabulary, but mode is provenance copied verbatim from task metadata, and task kinds appear there in practice alongside delivery modes. A scout task therefore could not be torn down at all. mode now gets the same bounded type and length treatment as project, harness, and model; enums stay only on the values this contract generates itself. Also bump the snapshot test count CI pins for the stock-macOS-Bash job from 15 to 19, which this branch's four new fleet-snapshot cases changed. The Bash 3.2 parse sweep in that job passed unchanged.
HelloWorldSungin
force-pushed
the
fm/fleet-outcome-manifest
branch
from
August 4, 2026 07:24
052c1fe to
207f862
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #18
Why
A finished task used to leave nothing structured behind. Teardown removes
state/<id>.meta, and the backlog's Done section is pruned to a recent window, so once a task was cleaned up there was no canonical record of what it was, what it shipped, or which session ran it. Nothing downstream could attribute its usage, ingest its outcome, or place it in history.This is the data-contract foundation shared by both the memory epic (#3) and the dashboard epic (#4): archive ingestion (#7), usage attribution (#13), kanban cards (#11), inbox health (#12), and durable history (#16) all consume it.
What landed
Three artifacts, with their wire shapes owned by
bin/fm-outcome-lib.sh:data/<id>/outcome.jsonfm-outcome-manifest.v1bin/fm-outcome-manifest.shdata/<id>/work-items.jsonfm-work-items.v1bin/fm-work-item.shstate/<id>.pr-statusfm-pr-status.v1bin/fm-pr-status.shThe manifest.
bin/fm-teardown.shpublishes it atomically before removing the volatile records it is composed from, and refuses the cleanup when publication fails rather than erasing a task it could not archive. Publication sits after the last refusal gate and the confirmed endpoint close, but before a retired secondmate's home is removed, because that home can contain the very records the manifest is composed from.Work-item references. Forge- and host-agnostic: canonical URL plus parsed forge, host, project path, owner, repo, number, and kind. Several per task or none. Each marked
intakeorpr-linked. Enrichment is nullable by contract and consumers must render a reference that was never enriched. An unrecognized host storesforge: "unknown"rather than being guessed at, and an explicit override handles self-hosted instances. This PR owns storage and transport only; population and per-forge resolution belong to #21.Normalized PR state.
bin/fm-pr-status.shis the one network caller and the one place each forge's vocabulary maps ontostate/review/checks/mergeableenums. The observation is cached so the read-only snapshot stays offline;fm-pr-check.shseeds it andfm-pr-merge.shrefreshes it, both best effort, and a failed refresh keeps the previous good reading instead of overwriting it withunknown.Snapshot projection.
fm-fleet-snapshot.v1grows additively, so existing v1 consumers keep working unchanged and no renderer migration is required: taskmodelandeffort, last task-event timestamp and computed age, parsed PR identity with normalized state and age,work_items, a computedcard, top-levelcard_precedence,supervision(watcher beacon age against the shared grace window plus away-mode state), and manifest-backedhistory.Card precedence. Signals overlap constantly, so exactly one column wins per task against a published ladder, with
card.rankand the decidingcard.signalscarried alongside so a surprising column is inspectable:needs_decision>blocked>parked>failed>review>done>waiting>active>secondmate>idleAn open decision outranks everything because it is unanswered work even when a PR is open; a blocker outranks a failure because the worker is still there and asking; a failure outranks an open PR because the PR is not the live problem; and an open PR outranks
donebecause a task that reported "PR checks green" has not landed until that PR is merged.Secret safety is enforced, not described. A fixed recursive key allowlist gates manifest publication, so a field can only be emitted by being declared in one place. Bounded type, enum, and length conformance runs at the shared read boundaries, so a hand-edited or corrupt store cannot carry arbitrary text through an allowlisted value. Every durable free-text value is control-stripped, collapsed to one line, and capped. Deliberately not a general secret scanner: values are conformed to the contract's own types, enums, and lengths and nothing more.
docs/fleet-data-contracts.md(maintainer-architecture) owns the field-ownership map. Script headers keep exact mechanics.AGENTS.mdgains only layout lines and one refusal clause.Decisions worth knowing
titlefor a secondmate is intended, not a defect. Secondmates are never backlog items by contract, so no synthetic title is manufactured; the contract documents the null. "Required" in the manifest validator therefore means the key is present with the right type or null, which is also what keeps an absent GBrain provider, a task with no PR, and unenriched work items valid.created=line was added tostate/<id>.meta. A live-harness Herdr end-to-end test asserts spawn metadata is byte-identical except for container IDs, and a per-spawn timestamp would break that claim. Timestamps instead carry explicit provenance intimestamp_sources, and a future recorded stamp can supersede a source without a schema change.jqis now a universal bootstrap requirement. The snapshot, the dispatch-profile reader, and now the manifest all need it, and without it a home cannot archive a finished task. Making that explicit keeps the new teardown refusal from surfacing as a mystery.issue=<number>metadata field is deliberately not migrated into the work-item store here. Resolving a bare number to a URL needs the project's repository, which is foundation: Project-scoped work-item linkage across managed forges #21's resolution territory; doing it here would fork a second schema.Two defects the work surfaced in itself
remove_firstmate_homebroke remote secondmate retirement, because the remote parent-route keeps its state and data inside the home being removed. The remote lifecycle e2e caught it; a new assertion in the local secondmate lifecycle suite now pins the ordering.bin/from a fixed sibling list and lacked the new writer, so the rebuilt teardown refused a cleanup that should have succeeded.Findings the pipeline fixed on top
Recorded for review, since they are corrections the original change missed:
approvals_before_merge, then fromapprovedalone; it now keys onapprovals_leftto separatenone,review_required, andapproved, degrading contradictions tounknown.FM_PR_STATUS_TIMEOUTwas not a real bound when GNUtimeoutwas unavailable.add/remove/clear, losing durable references; mutation paths now refuse while the read-only projection keeps its fallback.showand history.jqprocesses per work-item reference; consolidated to one pass per document.Verification
bin/fm-lint.sh,bin/fm-doc-audience-check.sh, and the test coverage guard all pass. Both portable parallel lanes and the portable serial lane are green. New coverage lives intests/fm-outcome-manifest.test.sh, with additions to the fleet-snapshot, teardown, and secondmate lifecycle suites.Rebase after the pipeline run
The no-mistakes pipeline validated this work at
d78036e3. Sibling PRs then merged and movedmain, so the branch was rebased onto3df0ac3and force-pushed with lease ase1d92fa.One conflict, in
bin/fm-teardown.sh, resolved by composing both sides rather than replacing either: main'sfix: preserve crew run attribution during validation(#25) addsstate/<id>.run-stepto the task cleanup list, and this branch addsstate/<id>.pr-statusandstate/<id>.gbrainto the same list. The final list carries all three. The acceptance-critical ordering is unchanged and re-verified:publish_outcome_manifeststill runs before the secondmate home removal, the per-task temp root removal, the PR-poll cleanup, the busy-state retirement, and the state-filerm.Re-verified after the rebase:
bin/fm-lint.sh,bin/fm-doc-audience-check.sh, and thefm-outcome-manifest,fm-teardown,fm-gotmp,fm-crew-state,fm-fleet-snapshot-view,fm-secondmate-lifecycle-e2e,fm-backend, andfm-briefsuites.The pipeline section below is the run's own record and its commit references predate that rebase.
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
⏭️ **Rebase** - skipped
.agents/skills/afk/SKILL.md- branch carries 58 commit(s) that exist on your local main branch but were never pushed to origin/main; rebasing would bundle this unrelated work (69 file(s)) into the PR:Push main to origin, or rebase your branch onto origin/main, before gating.
🔧 **Review** - 6 issues found → auto-fixed (3) ✅
bin/fm-outcome-lib.sh:295- The required guarantee that manifests and snapshots contain no credentials or secret-bearing payloads is not enforced by the current validators.fm_outcome_work_items_readaccepts arbitrary reference contents,fm_outcome_pr_status_readaccepts any status object, and the manifest allowlist validates keys but not values, so a sentinel placed in an allowed field such asenrichment.titleorstatus.sourceis emitted unchanged. Either add strict type, enum, length, and value validation at these shared read/write boundaries, or explicitly narrow the secret-safety guarantee; I recommend validation because retaining the current claim leaves a reachable disclosure path.bin/fm-outcome-lib.sh:328- The cached PR status is not checked against the task's current PR identity. If PR A is cached as merged,fm-pr-check.shreplaces metadata with PR B, and B's best-effort refresh fails, consumers combine B's URL with A's merged status; the card can then classify B as done and teardown archives the mismatched observation. Bind cache reads to the expected canonical URL and return unknown on an identity mismatch while retaining same-PR observations after refresh failures.bin/fm-outcome-manifest.sh:91- The required manifesttitleis not reliably retained.backlog_titlereturns empty for tasks without a backlog row, which includes retired secondmates, and its blanket parenthesis removal turns a legitimate title such asRefresh sidebar (mobile)intoRefresh sidebar. The smallest compliant fix is to reuse the canonical backlog-title parser and source secondmate titles from their structured registry or intake record; otherwise the contract must explicitly make title nullable and lossy. I recommend preserving the actual title for every task.bin/fm-pr-status.sh:128- GitLab review state is derived fromapprovals_before_merge, which is the deprecated configured approval count rather than the current approval decision. Consequently an approved MR with a nonzero threshold still reportsreview_required, while approval-rule configurations can reportnoneincorrectly. Read GitLab's approvals or approval-state endpoint and map its currentapprovedresult, degrading tounknownwhen unavailable. See the official GitLab approvals API.bin/fm-pr-status.sh:71-FM_PR_STATUS_TIMEOUTis not a bound when GNUtimeoutis unavailable: the fallback executesgh-axi,gh, orglabwithout any timeout. On supported macOS environments this can leavefm-pr-check.shor the post-merge refresh blocked indefinitely despite the documented 20-second contract. Use the repository's establishedgtimeout/Perl fallback or fail bounded when no timer is available.bin/fm-outcome-lib.sh:295- Malformed and absent work-item stores are collapsed to the same empty document. Becauseadd,remove, andclearconsume this reader, a present corrupt or old-schema durable store is silently overwritten, losing all prior references. Keep the empty fallback for an absent read-only projection, but make mutation paths fail when a present store does not validate.🔧 Fix: Harden outcome contracts and preserve cache identity
2 issues (1 error, 1 warning) still open:
bin/fm-pr-status.sh:139- The GitLab fix maps everyapproved:falseresponse toreview_required, but GitLab Community Edition also returns false when an MR has zero required approvals and nobody has voluntarily approved it; that ordinary no-review case must benone. Enterprise Edition can conversely return true with zero rules and no approving users. Useapprovals_requiredplusapproved_byorapprovals_leftto distinguishnone,review_required, andapproved, degrading ambiguous responses tounknown. See the official GitLab approvals API.bin/fm-outcome-lib.sh:375- The new validator starts roughly ten separatejqprocesses per work-item reference, and history invokes it for every retained manifest before applyingFM_SNAPSHOT_HISTORY. A durable history of 1,000 tasks with two references can therefore launch tens of thousands of processes on every snapshot. Consolidate structural validation and field extraction into onejqinvocation per document or reference, retaining only canonical URL reconstruction in shell.🔧 Fix: Normalize GitLab approvals and bound outcome validation
3 errors still open:
bin/fm-outcome-lib.sh:536- GitLab can returnapproved:truewhileapprovals_leftremains positive, including on Community Edition where any approval makesapprovedtrue. The current branch checksapprovedfirst and incorrectly reportsapprovedeven though required reviews remain. Prioritize a presentapprovals_left: positive meansreview_required, zero plus a consistent approved result meansapproved, and contradictions meanunknown. See the official GitLab approvals API.bin/fm-outcome-lib.sh:830- Manifest validation checks onlywork_itemsandpr; the key allowlist rejects extra paths but does not require missing ones. A same-schema record containing onlyschema,task_id, validwork_items, and validprtherefore passesshowand history without required fields such as title, timestamps, outcome, report, attribution, or GBrain status. Validate the complete manifest shape, required keys, types, enums, nullability, lengths, and task identity at this shared boundary so malformed or old records are disclosed instead of emitted.bin/fm-outcome-lib.sh:182- The generic reader applies its predicate independently to every top-level JSON value, so a file containing two concatenated valid objects is accepted. For work-item stores, mutation then processes both documents but publication selects the first slurped reference array, silently discarding references from the second; history can likewise emit two records while incrementingtotalonce. Slurp input and require exactly one object at the shared read boundary, with the same invariant enforced during publication.🔧 Fix: Enforce outcome contracts and approval precedence
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bash bin/fm-test-run.sh tests/fm-outcome-manifest.test.sh tests/fm-fleet-snapshot-view.test.sh tests/fm-teardown.test.sh tests/fm-secondmate-lifecycle-e2e.test.shAdded unenriched GitHub intake and GitLab PR-linked references throughbin/fm-work-item.sh, then published the canonical artifact throughbin/fm-outcome-manifest.sh write.Removed the demo task’s volatile metadata and pruned its Done backlog entry, then ranbin/fm-fleet-snapshot.sh --jsonand confirmed the task remained in manifest-backed history with attribution and both work-item references.Usedjq -eto validate the generated manifest and snapshot contracts andrgto prove a brief-embedded secret sentinel was absent from both outputs.Inspectedgit status --shortafter testing to confirm no transient working-tree artifacts remained.🔧 **Document** - 2 issues found → auto-fixed ✅
bin/fm-fleet-snapshot.sh:690- The secondmate card reason claims the home has an empty queue, but the predicate only checks that no higher-priority task signal exists. Align the executable reason with the predicate or add queue evidence.bin/fm-brief.sh:349- The generated scout brief says the report is the only surviving artifact, but teardown now also preserves the outcome manifest and work-item store. Rephrase this as the only task-authored deliverable.🔧 Fix: Align fleet documentation wording
✅ Re-checked - no issues remain.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.