Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ state/ volatile runtime signals; gitignored
x-poll.error x-poll.claim-error generated X-mode relay and offer-claim diagnostic dedupe markers
.wake-queue durable queued wakes: epoch<TAB>seq<TAB>kind<TAB>key<TAB>payload
.afk durable away-mode flag; present = sub-supervisor may inject escalations (set by /afk, cleared on user return)
.watch.lock .wake-queue.lock watcher singleton and queue serialization locks
.watch.lock .wake-queue.lock .wake-annotation.lock watcher singleton, queue serialization, and drain annotation serialization locks
.claude-autoarm.lock .claude-autoarm-epoch .turnend-claude-blocks Claude Stop auto-arm single-flight, epoch, and guard-budget records; never touch
.hash-* .count-* .stale-* .stale-since-* .paused-* .wedge-escalations-* .seen-* .hb-surfaced-* .last-* .heartbeat-streak watcher internals; never touch
.drain-cursor-<id> .drain-retry-{direct,historical}-<id> per-status-file drain read cursor and durable capped-output retry; drain internal, never touch
.watch-triage.log watcher's absorbed-wake debug log (size-capped); never relied on, safe to delete
.last-watcher-beat watcher liveness beacon, touched every poll (including while absorbing benign wakes); guard scripts read it
.subsuper-* .supervise-daemon.* sub-supervisor internals; never touch
Expand Down Expand Up @@ -138,7 +139,7 @@ A lock-refused session must not spawn, steer, merge, drain the wake queue, repai
When the lock could not be acquired, the worktree-tangle check uses read-only advisory wording without a checkout repair command.
Home-local stale Herdr projection cleanup and the five bootstrap MUTATING sweeps - non-executing legacy PR-check migration, fleet sync, the local secondmate fast-forward sweep, the secondmate liveness sweep, and X-mode artifact writes - run only when this session actually holds the lock from step 1.
The secondmate liveness sweep deterministically accounts for every registered secondmate: it relaunches only from the recovery-grade `dead` or `missing` states, preserves ambiguous or unreadable targets, and reports skipped or failed guarantees as `SECONDMATE_LIVENESS:` lines (`bin/fm-bootstrap.sh`; `bin/fm-backend.sh`'s `fm_backend_agent_state`).
3. **Wake queue** - when locked, drains the durable wake queue and prints the raw records prominently as this turn's first work queue; a bounded, clearly labeled historical status-event annotation may follow a valid `signal` record but never replaces it or current-state reconciliation, and a lapsed watcher chain still surfaces here via the same guard alarm.
3. **Wake queue** - when locked, drains the durable wake queue and prints the raw records prominently as this turn's first work queue; a bounded, clearly labeled historical status-event annotation may also print but never replaces raw records or current-state reconciliation, and a lapsed watcher chain still surfaces here via the same guard alarm.
When the lock could not be acquired and verified, the queue is left untouched because no session mutation is authorized, and the guard's tangle/watcher-liveness alarms still print in read-only advisory mode without drain, supervision repair, or checkout repair commands.
4. **Context digest** - the full contents of `data/projects.md`, `data/secondmates.md`, `data/captain.md`, `data/captain-shared.md`, and `data/learnings.md`, each clearly delimited.
A file that does not exist prints an explicit `ABSENT` marker, never confused with an empty-but-present file: absence is meaningful (`captain.md` absent means use the firstmate repo's built-in defaults, `projects.md` absent means rebuild it from the clones under `projects/`, etc.).
Expand Down
7 changes: 5 additions & 2 deletions bin/fm-teardown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,9 @@ cleanup_firstmate_home_children() {
remove_pr_poll_artifacts "$sub_state" "$child_id" || return 1
rm -f "$sub_state/$child_id.status" "$sub_state/$child_id.turn-ended" \
"$sub_state/$child_id.meta" "$sub_state/$child_id.pi-ext.ts" \
"$sub_state/$child_id.grok-turnend-token" "$sub_state/$child_id.kimi-turnend-token"
"$sub_state/$child_id.grok-turnend-token" "$sub_state/$child_id.kimi-turnend-token" \
"$sub_state/.drain-cursor-$child_id" "$sub_state/.drain-retry-direct-$child_id" \
"$sub_state/.drain-retry-historical-$child_id"
done
}

Expand Down Expand Up @@ -1228,7 +1230,8 @@ fm_backend_clear_transition "$BACKEND" "$STATE" "$T" || true
remove_pr_poll_artifacts "$STATE" "$ID" || exit 1
rm -f "$STATE/$ID.status" "$STATE/$ID.turn-ended" "$STATE/$ID.meta" \
"$STATE/$ID.pi-ext.ts" "$STATE/$ID.grok-turnend-token" \
"$STATE/$ID.kimi-turnend-token"
"$STATE/$ID.kimi-turnend-token" "$STATE/.drain-cursor-$ID" \
"$STATE/.drain-retry-direct-$ID" "$STATE/.drain-retry-historical-$ID"
if [ "$KIND" != scout ] && [ "$KIND" != secondmate ] && [ "$MODE" != local-only ]; then
"$FM_ROOT/bin/fm-fleet-sync.sh" "$PROJ" || true
fi
Expand Down
10 changes: 8 additions & 2 deletions bin/fm-wake-drain.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env bash
# Atomically drain durable watcher wake records, optionally annotate validated
# signal status keys after raw consumption commits, then assert liveness.
# Atomically drain durable watcher wake records, then best-effort annotate
# validated signal status keys after raw consumption commits.
# Each annotation block prints the oldest unseen events that fit before the
# latest line; later drains retry any explicitly marked remainder, and then the
# drain asserts liveness.
set -u

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
Expand Down Expand Up @@ -47,6 +50,9 @@ DRAIN_LOCK_HELD=true

if [ ! -s "$FM_WAKE_QUEUE" ]; then
: > "$FM_WAKE_QUEUE"
fm_lock_release "$FM_WAKE_QUEUE_LOCK"
DRAIN_LOCK_HELD=false
(fm_wake_print_annotations '') || true
assert_watcher_liveness
exit 0
fi
Expand Down
Loading