Skip to content

feat(bin): publish per-home summary ledgers - #3222

Merged
kunchenguid merged 13 commits into
mainfrom
fm/fm-startup-pr2-home-summary-ledger-r1
Aug 29, 2026
Merged

kunchenguid merged 13 commits into
mainfrom
fm/fm-startup-pr2-home-summary-ledger-r1

Conversation

@kunchenguid

@kunchenguid kunchenguid commented Aug 28, 2026 •

Copy link
Copy Markdown
Owner

Intent

Implement PR2 of the captain-approved Firstmate startup and Bearings redesign after PR1 landed: publication only of a per-home state ledger, with no collector, consumer, Bearings behavior change, fleet-snapshot read-path change, or PR3-PR4 work. Each home must best-effort maintain state/home-summary.json as the same fm-secondmate-home-summary.v1 document produced by fm-fleet-snapshot.sh --secondmate-home-summary, extended with generated_epoch, and publish it atomically so interrupted writes leave either the prior complete valid JSON document or a new complete valid JSON document, never torn output. Refresh must be local to the owning home after a status append lands, at that home s locked session start, and after task spawn and teardown, with live-home staleness bounded to minutes; refresh failure must be logged and must never break the triggering caller. The additive design must remain safe on mixed-version fleets because nothing reads the ledger yet. Behavioral tests must exercise real producer and trigger surfaces: a status append on a seeded lab home produces an updated ledger equal to a fresh --secondmate-home-summary result modulo generated fields within trigger cadence, and a writer crash or kill mid-write proves atomic replace. Keep all existing snapshot and Bearings tests untouched and green. Preserve the previously validated and pushed PR2 head and its accepted pipeline fixes while reconciling it through the supported no-mistakes path onto current main, including the landed honest Herdr suite fix, then rerun the full validation pipeline. Do not merge the PR.

What Changed

  • Add an atomic, validated state/home-summary.json publisher using the existing secondmate summary schema with generated_epoch freshness metadata.
  • Refresh the ledger best-effort after locked session starts, task spawns and teardowns, watcher-observed status changes, and a configurable recurring cadence, with bounded failures and local logging.
  • Add behavioral coverage for producer parity, trigger surfaces, refresh cadence, failure isolation, and atomic replacement during interrupted writes, plus architecture and configuration documentation.

Risk Assessment

✅ Low: The change is additive and publication-only, with bounded best-effort lifecycle hooks, atomic replacement, recurring watcher refresh, and no ledger consumer or existing read-path behavior change.

Testing

Inspected the target diff, exercised status/cadence publication, atomic interruption, bounded best-effort failures, session-start/spawn/teardown triggers, and unchanged Snapshot/Bearings behavior. The initial session-start run exceeded a 180-second harness limit but completed successfully when retried with adequate time; all other targeted checks completed, end-to-end ledger evidence was captured, and the worktree remained clean.

Evidence: End-to-end status publication and atomic interruption transcript

Source: End-to-end status publication and atomic interruption transcript

Firstmate per-home ledger end-to-end evidence

1. Started the real fm-watch.sh against a seeded home.
2. Appended a blocked status line to state/ledger-task.status.
3. Watcher published state/home-summary.json with generated=2026-08-28T10:01:00Z and generated_epoch=1787911260.
4. Compared the published document with a fresh real fm-fleet-snapshot.sh --secondmate-home-summary result after removing only generated and generated_epoch: IDENTICAL.
5. Started the real writer with its producer deliberately blocked, allowing its 1-second deadline to terminate the worker mid-refresh.
6. Writer exit code: 124 (deadline termination).
7. Ledger SHA-256 before interrupted refresh: 53da7ce04ef1a0c8b15ce7d7c798b6b5c370e78be9187c012ae12d23d0f02bba
8. Ledger SHA-256 after interrupted refresh:  53da7ce04ef1a0c8b15ce7d7c798b6b5c370e78be9187c012ae12d23d0f02bba
9. The surviving ledger parses as valid JSON: YES.

Result: status-triggered publication matches the real producer, and interrupted publication preserves the prior complete document byte-for-byte.
Evidence: Status-triggered published home-summary ledger

Source: Status-triggered published home-summary ledger

{
  "schema": "fm-secondmate-home-summary.v1",
  "generated": "2026-08-28T10:01:00Z",
  "generated_epoch": 1787911260,
  "home": "/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T//fm-ledger-evidence.Q7y1ej/home",
  "valid": true,
  "reason": null,
  "invalidity": {
    "kind": null,
    "ids": []
  },
  "state": "externally_held",
  "active_children": [],
  "decisions_open": [
    {
      "id": "ledger-task",
      "key": "fixture-dependency",
      "verb": "blocked",
      "summary": "waiting for fixture",
      "reason": null,
      "source": "status"
    }
  ],
  "holds": [
    {
      "id": "ledger-task",
      "title": "ledger-task",
      "blocked_by": null,
      "blocked_by_ids": [],
      "unresolved_blocker_ids": [],
      "reason": "waiting for fixture",
      "source": "child-state"
    }
  ],
  "queued": [],
  "landed": [],
  "endpoints": [
    {
      "id": "ledger-task",
      "state": "blocked",
      "source": "status-log",
      "endpoint": {
        "target": "fmtest:fm-ledger-task",
        "exists": true,
        "agent_alive": "not_checked",
        "status": "unknown",
        "observed_at": "2026-08-28T10:01:00Z",
        "freshness": "fresh"
      }
    }
  ],
  "counts": {
    "active_children": 0,
    "decisions_open": 1,
    "holds": 1,
    "queued": 0,
    "landed": 0,
    "endpoints": 1
  },
  "omitted": []
}
Evidence: Fresh real producer home-summary used for equivalence comparison

Source: Fresh real producer home-summary used for equivalence comparison

{
  "schema": "fm-secondmate-home-summary.v1",
  "generated": "2026-08-28T10:01:00Z",
  "generated_epoch": 1787911260,
  "home": "/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T//fm-ledger-evidence.Q7y1ej/home",
  "valid": true,
  "reason": null,
  "invalidity": {
    "kind": null,
    "ids": []
  },
  "state": "externally_held",
  "active_children": [],
  "decisions_open": [
    {
      "id": "ledger-task",
      "key": "fixture-dependency",
      "verb": "blocked",
      "summary": "waiting for fixture",
      "reason": null,
      "source": "status"
    }
  ],
  "holds": [
    {
      "id": "ledger-task",
      "title": "ledger-task",
      "blocked_by": null,
      "blocked_by_ids": [],
      "unresolved_blocker_ids": [],
      "reason": "waiting for fixture",
      "source": "child-state"
    }
  ],
  "queued": [],
  "landed": [],
  "endpoints": [
    {
      "id": "ledger-task",
      "state": "blocked",
      "source": "status-log",
      "endpoint": {
        "target": "fmtest:fm-ledger-task",
        "exists": true,
        "agent_alive": "not_checked",
        "status": "unknown",
        "observed_at": "2026-08-28T10:01:00Z",
        "freshness": "fresh"
      }
    }
  ],
  "counts": {
    "active_children": 0,
    "decisions_open": 1,
    "holds": 1,
    "queued": 0,
    "landed": 0,
    "endpoints": 1
  },
  "omitted": []
}

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed (2) ✅
  • 🚨 bin/fm-home-summary-refresh.sh:211 - The required “refresh failure must be logged” invariant is bypassed for non-timeout worker termination. If the bounded worker is killed directly or exits via its HUP/INT/TERM traps, the parent receives 129/130/137/143, takes this branch, and returns without logging; --best-effort also returns nonzero despite its documented contract. In best-effort mode, handle every worker failure at this parent boundary with bounded reporting and exit zero.
  • 🚨 bin/fm-home-summary-refresh.sh:217 - The accepted correction requires only bounded parent-side failure reporting, but when the two-second timeout logger fails, this fallback writes synchronously to stderr outside any bound. A blocked/full stderr pipe can therefore hang session start, spawn, teardown, or the watcher indefinitely after the refresh has already timed out. Keep the fallback itself under a deadline or make it nonblocking.

🔧 Fix: Bound and log all best-effort refresh failures
2 issues (1 error, 1 warning) still open:

  • 🚨 tests/fm-home-summary-refresh.test.sh:440 - The worker-termination test shadows only perl, but fm_timeout_mechanism prefers timeout, which is installed on the Ubuntu CI runners. The fake Perl never executes, the refresh succeeds, and the expected exit-143 log is absent, so this test deterministically fails in CI. Exercise the selected timeout mechanism or force a controllable mechanism.
  • ⚠️ bin/fm-watch.sh:1196 - The new cadence uses age_of, which returns a negative age when the ledger mtime is ahead of the current clock. After a backward clock correction, backlog-only changes can therefore remain unpublished until the clock catches up, violating bounded live-home staleness. Clamp future mtimes to “due immediately” at the shared age_of boundary.

🔧 Fix: Harden cadence and timeout regression coverage
✅ Re-checked - no issues remain.

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • git status --short and commit-range diff inspection
  • bash tests/fm-home-summary-refresh.test.sh
  • Manual seeded-home workflow using real fm-watch.sh, fm-home-summary-refresh.sh, and fm-fleet-snapshot.sh --secondmate-home-summary
  • bash tests/fm-session-start.test.sh
  • bash tests/fm-trace-context-spawn.test.sh
  • Focused test_kimi_readiness_gate_precedes_pointer selector from tests/fm-kimi-harness.test.sh
  • Focused test_local_only_fork_remote_allows selector from tests/fm-teardown.test.sh
  • bash tests/fm-bearings-snapshot.test.sh
  • bash tests/fm-fleet-snapshot-view.test.sh
  • Normalized jq comparison of the published ledger against a fresh producer result
  • A combined lifecycle regression command reached its 300-second host timeout during the broader Kimi suite; the relevant Kimi and teardown cases were then run independently and completed

✅ No issues found.

  • git status --short && git diff --stat 420721401c4080d1a4f6982b0ef6769e2a749b23..HEAD && git diff --name-only 420721401c4080d1a4f6982b0ef6769e2a749b23..HEAD
  • bash tests/fm-home-summary-refresh.test.sh
  • bash tests/fm-session-start.test.sh (initial 180-second harness timeout, then completed with timeout=420)
  • bash tests/fm-teardown.test.sh
  • bash tests/fm-trace-context-spawn.test.sh
  • bash tests/fm-kimi-harness.test.sh
  • bash tests/fm-fleet-snapshot-view.test.sh
  • bash tests/fm-bearings-snapshot.test.sh
  • bash tests/fm-bearings-board-render.test.sh
  • Manual seeded-home verification using real fm-watch.sh, fm-home-summary-refresh.sh, and fm-fleet-snapshot.sh --secondmate-home-summary: appended a status event, compared normalized published and fresh summaries, then interrupted a blocked refresh at its deadline and verified identical before/after SHA-256 plus valid JSON.
  • git status --short after testing and cleanup
✅ **Document** - passed

✅ No issues found.

✅ No issues found.

🔧 **Lint** - 1 issue found → auto-fixed ✅
  • ⚠️ linter found issues (exit code 1)

🔧 Fix: Fix direct exit-code check in refresh test
✅ Re-checked - no issues remain.

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (3): Last reviewed commit: "no-mistakes(document): Clarify atomic ho..." | Re-trigger Greptile

Comment thread bin/fm-watch.sh Resolved
@kunchenguid
kunchenguid force-pushed the fm/fm-startup-pr2-home-summary-ledger-r1 branch from 4726e81 to c0c627f Compare August 28, 2026 23:36
@kunchenguid kunchenguid changed the title feat: publish atomic per-home fleet summaries feat(bin): publish per-home state summary ledger Aug 28, 2026
…leted home: teardown now skips side-band summary refresh when its overridden state directory was removed. Verified with remote lifecycle E2E, teardown tests, home-summary tests, ShellCheck, and git diff checks
@kunchenguid kunchenguid changed the title feat(bin): publish per-home state summary ledger feat(bin): publish per-home summary ledgers Aug 29, 2026
@kunchenguid
kunchenguid merged commit a390659 into main Aug 29, 2026
14 of 15 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-startup-pr2-home-summary-ledger-r1 branch August 29, 2026 00:46
prandelicious added a commit to prandelicious/firstmate that referenced this pull request Aug 29, 2026