Skip to content

Commit b4316be

Browse files
authored
fix(bin): send literal config reread nudges after pushes (kunchenguid#809)
* Send literal config reread after inherited config push When declared inherited config changes under an already-running secondmate, build a per-home instruction from validated destination post-write bytes and deliver it on the routed secondmate path. Unchanged config sends nothing; ABSENT represents removal; captain-shared is never inlined. Covers mid-session config-push and the locked bootstrap convergence path without hardening spawn against deliberate runtime choice. * no-mistakes(review): Fix config reread framing, partial propagation, and respawn order * no-mistakes(review): Send config rereads via durable single-line pointers * no-mistakes(review): Make failed config rereads retryable * no-mistakes(review): Make config reread retries generation-safe * no-mistakes(review): Make config rereads durable and ordered * no-mistakes(review): Drain retries, bound history, preserve detect-only read-only mode * no-mistakes(review): Retain write retries and quarantine stale respawn generations * no-mistakes(review): Preserve exact config reread retries and delivery order * no-mistakes(review): Preserve exact retry bytes and bounded quarantine pruning * no-mistakes(document): Consolidated config-reread documentation
1 parent f9a89c3 commit b4316be

8 files changed

Lines changed: 1900 additions & 32 deletions

File tree

‎.agents/skills/secondmate-provisioning/SKILL.md‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,23 @@ Never copy any secondmate `data/captain-shared.md` back into the primary.
9292
Keep each home's `data/captain.md` domain-local.
9393
After first propagation to an existing home, trim that home's local `data/captain.md` by hand to domain-specific content plus pointers to `data/captain-shared.md`; do not automate or silently delete private content.
9494
Keep every `data/learnings.md` fully local by captain decision; route fleet-general machinery facts into tracked documentation through the normal firstmate repo path rather than inventing shared learnings propagation.
95-
No reread nudge is needed at spawn or respawn because the agent reads `AGENTS.md` fresh on launch; only the bootstrap sweep's running-home instruction-surface advance needs one.
96-
Bootstrap reports successful sends as `BOOTSTRAP_INFO:` and only emits `NUDGE_SECONDMATES:` when that send fails and needs retry.
97-
For already-live secondmates, use `bin/fm-config-push.sh` to push a mid-session inherited local-material change without running the tracked-file fast-forward or nudging the agents.
98-
It uses the same live-home discovery and propagation helper as bootstrap and reports each item as `pushed`, `unchanged`, `skipped`, or `error`.
95+
No AGENTS.md reread nudge is needed at spawn or respawn because the agent reads instructions fresh on launch; only the bootstrap sweep's running-home instruction-surface advance needs that AGENTS.md re-read.
96+
Bootstrap reports successful AGENTS.md re-read sends as `BOOTSTRAP_INFO:` and only emits `NUDGE_SECONDMATES:` when that send fails and needs retry.
97+
A separate, literal-content config reread is required whenever inherited `config/*` material changes under an already-running secondmate.
98+
After each successful allowlisted config write, both the locked bootstrap convergence path and mid-session `bin/fm-config-push.sh` use the shared propagation report to build one per-home generation-specific private instruction file from the validated destination post-write bytes for only the allowlisted config items that actually changed for that home (`config/crew-dispatch.json`, `config/crew-harness`, `config/backlog-backend`), in deterministic allowlist order.
99+
Each changed path is printed with clear begin/end delimiters and the destination file's full exact new bytes unparsed, or the explicit token `ABSENT` when propagation removed the destination copy.
100+
The instruction uses only minimal framing that these are defaults/rules and do not remove judgment; it never includes SHA values, selected profiles, parsed summaries, or any other generated interpretation.
101+
`data/captain-shared.md` is not a config file and is never inlined into this instruction file or message.
102+
Homes whose allowlisted config files were all unchanged receive no config-reread message when no retry is pending.
103+
Different homes may receive different changed-file sets based on their pre-push destination bytes.
104+
Delivery uses the existing routed secondmate path (`fm-send`) with only a single-line `CONFIG_REREAD: <absolute generation-specific instruction path>` pointer; a failed instruction publication retains the generated exact bytes in a bounded private retry queue when possible, legacy retry reports remain recoverable, a failed publication or retry-marker write retains the exact generation until it can be delivered, a failed send records a per-generation durable retry marker when possible, and all failures surface a concrete `CONFIG_REREAD:` diagnostic without claiming the live agent already re-read the values.
105+
The propagation, generation publication, and pointer-delivery sequence holds one per-home inheritance lock, so concurrent mid-session pushes cannot deliver an older generation after a newer one.
106+
A newly launched or relaunched secondmate already reads its files at launch, so its pending config-reread generations are discarded or quarantined after cleanup failure and it needs no redundant live-agent config nudge unless propagation changes files after launch.
107+
Quarantined pre-relaunch generations are retained in bounded private history, and cleanup skips creating an empty quarantine generation.
108+
Successfully delivered generations are retained only within a bounded per-home state history, while pending generations remain until delivery succeeds or a launch supersedes them.
109+
These config values remain defaults and rules only; they must not harden `fm-spawn` to reject a deliberate runtime choice that differs from the configured defaults.
110+
For already-live secondmates, use `bin/fm-config-push.sh` to push a mid-session inherited local-material change without running the tracked-file fast-forward.
111+
It uses the same live-home discovery and propagation helper as bootstrap, reports each item as `pushed`, `unchanged`, `skipped`, or `error`, and follows the config-reread contract above for changed or pending generations.
99112
`bin/fm-home-seed.sh` refuses to copy a missing or placeholder charter.
100113

101114
Direct seed without a preexisting brief requires `FM_SECONDMATE_CHARTER`.

‎bin/fm-bootstrap.sh‎

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ fleet_sync() {
185185
}
186186

187187
secondmate_sync() {
188+
# shellcheck source=bin/fm-wake-lib.sh disable=SC1091
189+
. "$SCRIPT_DIR/fm-wake-lib.sh"
188190
# Local-HEAD secondmate sync: fast-forward every LIVE secondmate home
189191
# to the primary checkout's current default-branch commit. Purely LOCAL - no
190192
# fetch, no origin dependency: a linked-worktree home already holds the primary's
@@ -335,8 +337,13 @@ secondmate_sync() {
335337
# surface into every VALIDATED live secondmate home swept above.
336338
# FF_SEEN_HOMES is exactly that set, and fm-config-inherit-lib.sh owns the
337339
# declared config items plus data/captain-shared.md.
338-
local id home home_real propagated_homes
340+
# After a successful push that changes allowlisted config/* for an already-
341+
# running home, send its literal-content reread instruction pointer so the
342+
# live agent does not keep applying stale defaults. Spawn/respawn already
343+
# re-reads at launch and needs no redundant nudge unless files changed after launch.
344+
local id home home_real home_lock propagated_homes report reread_out reread_skip_pending
339345
propagated_homes=""
346+
SECONDMATE_RESPAWNED_IDS=${SECONDMATE_RESPAWNED_IDS:-}
340347
while IFS='|' read -r id home _window _meta; do
341348
validate_secondmate_home "$id" "$home" || continue
342349
home_real="$VALIDATED_HOME"
@@ -348,9 +355,56 @@ secondmate_sync() {
348355
*" $home_real "*) continue ;;
349356
esac
350357
propagated_homes="$propagated_homes $home_real"
351-
if ! propagate_secondmate_inheritance "$FM_HOME" "$home_real" "$CONFIG" "$DATA"; then
358+
mkdir -p "$home_real/state" || {
359+
echo "CONFIG_REREAD: secondmate $id: send failed: could not create state directory"
360+
continue
361+
}
362+
home_lock=$(fm_config_inherit_lock_path "$home_real") || {
363+
echo "CONFIG_REREAD: secondmate $id: send failed: could not resolve per-home lock"
364+
continue
365+
}
366+
fm_lock_acquire_wait "$home_lock" || {
367+
echo "CONFIG_REREAD: secondmate $id: send failed: could not acquire per-home lock"
368+
continue
369+
}
370+
reread_skip_pending=0
371+
case " $SECONDMATE_RESPAWNED_IDS " in
372+
*" $id "*) reread_skip_pending=1 ;;
373+
esac
374+
if [ "$reread_skip_pending" -eq 0 ] \
375+
&& fm_config_reread_retry_queue_is_full "$FM_HOME" "$id"; then
376+
fm_config_reread_retry_pending "$id" "$home_real" || true
377+
if fm_config_reread_retry_queue_is_full "$FM_HOME" "$id"; then
378+
echo "CONFIG_REREAD: secondmate $id: send failed: retry instruction queue is full"
379+
fm_lock_release "$home_lock" || true
380+
continue
381+
fi
382+
fi
383+
report=$(mktemp "${TMPDIR:-/tmp}/fm-bootstrap-inherit.XXXXXX" 2>/dev/null) || {
384+
echo "SECONDMATE_SYNC: secondmate $id: skipped: inheritance failed"
385+
fm_lock_release "$home_lock" || true
386+
continue
387+
}
388+
if FM_CONFIG_INHERIT_REPORT="$report" \
389+
propagate_secondmate_inheritance "$FM_HOME" "$home_real" "$CONFIG" "$DATA"; then
390+
:
391+
else
352392
echo "SECONDMATE_SYNC: secondmate $id: skipped: inheritance failed"
353393
fi
394+
if ! reread_out=$(FM_HOME="$FM_HOME" FM_ROOT_OVERRIDE="$FM_ROOT" \
395+
FM_STATE_OVERRIDE="$STATE" \
396+
FM_CONFIG_REREAD_SKIP_PENDING="$reread_skip_pending" \
397+
fm_config_send_reread_nudge "$id" "$home_real" "$report" 2>&1); then
398+
if [ -n "$reread_out" ]; then
399+
printf '%s\n' "$reread_out"
400+
else
401+
echo "CONFIG_REREAD: secondmate $id: send failed: unknown error"
402+
fi
403+
elif [ -n "$reread_out" ]; then
404+
printf '%s\n' "$reread_out"
405+
fi
406+
rm -f "$report"
407+
fm_lock_release "$home_lock" || true
354408
done < <(live_secondmate_meta_records "$STATE" "$DATA/secondmates.md")
355409
return 0
356410
}
@@ -388,6 +442,7 @@ secondmate_liveness_sweep() {
388442
# explicitly out of scope here.
389443
[ -d "$STATE" ] || return 0
390444
local meta id window harness backend target verdict out
445+
SECONDMATE_RESPAWNED_IDS=""
391446
for meta in "$STATE"/*.meta; do
392447
[ -f "$meta" ] || continue
393448
grep -q '^kind=secondmate$' "$meta" 2>/dev/null || continue
@@ -409,6 +464,7 @@ secondmate_liveness_sweep() {
409464
dead)
410465
fm_backend_kill "$backend" "$target" 2>/dev/null || true
411466
if out=$(FM_SPAWN_NO_GUARD=1 "$FM_ROOT/bin/fm-spawn.sh" "$id" --secondmate 2>&1); then
467+
SECONDMATE_RESPAWNED_IDS="$SECONDMATE_RESPAWNED_IDS $id"
412468
:
413469
else
414470
echo "SECONDMATE_LIVENESS: secondmate $id: respawn failed: $(first_line "$out")"
@@ -800,8 +856,8 @@ if [ "${FM_BOOTSTRAP_VERBOSE_FACTS:-0}" = 1 ] \
800856
echo "BOOTSTRAP_INFO: tasks-axi available"
801857
fi
802858
if [ "${FM_BOOTSTRAP_DETECT_ONLY:-0}" != 1 ]; then
803-
secondmate_sync
804859
secondmate_liveness_sweep
860+
secondmate_sync
805861
x_mode_setup
806862
fleet_sync
807863
fi

0 commit comments

Comments
 (0)