Skip to content

feat: automate stow on session re-emits and heartbeats - #2947

Open
bingb0t5 wants to merge 9 commits into
kunchenguid:mainfrom
bingb0t5:fm/fm-auto-stow-ship
Open

feat: automate stow on session re-emits and heartbeats#2947
bingb0t5 wants to merge 9 commits into
kunchenguid:mainfrom
bingb0t5:fm/fm-auto-stow-ship

Conversation

@bingb0t5

Copy link
Copy Markdown

Intent

Implement automatic /stow so the captain does not have to type it.

Two triggers, no new daemon, watcher, or second cascade:
(1) On session-start compact/clear re-emit, prepend a STOW DUE instruction to the digest when state/.last-stow-attempt is missing or older than FM_AUTO_STOW_INTERVAL_SECS (default ~24h); stay silent when current or when the session could not verify fleet-lock ownership.
(2) On heartbeat wake handling (AGENTS.md section 8 rule 4), add one staleness-gated /stow instruction using that same larger interval so a pass runs at most once per interval rather than on every heartbeat wake.

Touch state/.last-stow only at the end of a reset-safe /stow pass. Touch state/.last-stow-attempt at the end of every /stow pass, reset-safe or not, so a sticky exception still throttles automatic retriggering. Away-mode heartbeats stay bash-only.

Executable tests cover the digest line's staleness gate by exercising fm-session-start.sh's real output, never by grepping source.

Accepted decision C: skip wiring heartbeat /stow into the Pi supervision branch; do not edit fm-branch-prompt.sh. Document that gap and file follow-up #2944. Compact/clear re-emit remains the automatic path on default Pi.

Also applied remaining review auto-fixes: promote the marker-touch instructions out of the cascade heading so secondmate homes still throttle, and pin the stale-marker age assertion to a 9xxxx band instead of the prefix 900.

This PR targets https://github.com/bingb0t5/firstmate; the captain cannot merge upstream themselves.

What Changed

  • Add a staleness-gated STOW DUE instruction to lock-owning compact/clear session re-emits, with a configurable 24-hour default interval.
  • Run automatic /stow during eligible heartbeat handling and track both attempted and reset-safe passes so unresolved exceptions remain throttled.
  • Document automatic stow behavior, marker semantics, and the deferred Pi supervision-branch integration tracked by issue Wire heartbeat automatic /stow into the Pi supervision branch #2944.

Risk Assessment

✅ Low: The change is well-bounded, satisfies the automatic stow intent and prior fixes, and introduces no substantiated merge-blocking source risk.

Testing

The focused session-start suite passed, including lock ownership, default and custom staleness intervals, attempt-marker throttling, read-only silence, and ordinary-startup exclusion; a reviewer-visible CLI transcript demonstrates the real missing, fresh, and stale marker behavior. No screenshot was captured because this is a CLI digest change with no rendered UI.

Evidence: Automatic stow session-start transcript

Source: Automatic stow session-start transcript

Missing and stale markers emit STOW DUE before BOOTSTRAP; a fresh marker emits zero STOW DUE lines.

SCENARIO 1 - missing attempt marker, lock-owning clear re-emit
STOW DUE: no recorded /stow pass (source=clear); run /stow before other work.
BOOTSTRAP

SCENARIO 2 - fresh attempt marker, same re-emit
STOW DUE lines: 0

SCENARIO 3 - stale attempt marker (90000 seconds), default interval
STOW DUE: last /stow pass was 90000s ago (over the 86400s interval, source=compact); run /stow before other work.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • ⚠️ bin/fm-session-start.sh:364 - FM_AUTO_STOW_INTERVAL_SECS accepts any nonzero digit string, but [ cannot compare values outside the shell's integer range. For example, with a stale marker and FM_AUTO_STOW_INTERVAL_SECS=999999999999999999999, the comparison errors and || return 0 silently suppresses STOW DUE. Validate the configured value against a supported upper bound before using it.

🔧 Fix: Cap automatic stow interval safely
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-session-start.test.sh
  • Real bin/fm-session-start.sh --reemit checks for missing, fresh, and 90000-second-old state/.last-stow-attempt markers using the session-start test harness; transcript captured with tee
  • git status --short after testing to confirm no transient worktree artifacts remained
✅ **Document** - passed

✅ No issues found.

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

🔧 Fix: Fix numeric stow interval lint comparison
✅ Re-checked - no issues remain.

✅ **Push** - passed

✅ No issues found.

…ss gates

Adds the two triggers from data/fm-auto-stow/report.md so the captain no
longer has to type /stow to keep memory current, without a new daemon,
watcher, or cascade:

- bin/fm-session-start.sh prepends a STOW DUE line to a compact/clear
  session-start re-emit when state/.last-stow is missing or older than
  FM_AUTO_STOW_INTERVAL_SECS (default ~24h), silent when current.
- AGENTS.md section 8 rule 4 now also checks that same marker on a
  heartbeat wake, using the same larger-than-heartbeat interval, so a
  pass runs at most once per interval rather than on every wake.
- The stow skill touches state/.last-stow only at the end of a pass it
  can call reset-safe, mirroring state/.last-heartbeat's bare-mtime
  marker.

Away-mode heartbeats stay bash-only and unaffected: they never reach an
LLM turn to run /stow in, per the existing away-daemon design.
Promote the last-stow marker contract out of the cascade heading so a
secondmate home still throttles automatic /stow. Pin the stale re-emit
age assertion to a 9xxxx band instead of the prefix 900. Document that
default Pi branch supervision does not run heartbeat /stow, and leave
that wiring as follow-up (kunchenguid#2944) rather than
editing fm-branch-prompt.sh.
@greptile-apps

greptile-apps Bot commented Aug 24, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (4): Last reviewed commit: "no-mistakes: apply CI fixes" | Re-trigger Greptile

Comment thread AGENTS.md Outdated
Comment thread bin/fm-session-start.sh
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.

1 participant