Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1792689
fix(remote): classify markerless secondmate endpoints safely
dnth Sep 3, 2026
c88c6a5
no-mistakes(review): Port markerless remote reconciliation with ident…
dnth Sep 3, 2026
fde5595
no-mistakes(review): Wire reconciliation sweep and preserve remote id…
dnth Sep 3, 2026
28127bb
no-mistakes(review): Enable reconcile-only markerless remote delivery
dnth Sep 3, 2026
41361c3
no-mistakes(review): Bypass pending replies for fire-and-forget recon…
dnth Sep 3, 2026
d33597d
no-mistakes(review): Preserve generation and remote-root reconciliati…
dnth Sep 3, 2026
ca8fa90
no-mistakes(review): Bind remote root in structured snapshots
dnth Sep 3, 2026
68a73d0
no-mistakes(review): Complete reconciliation identity and lifecycle c…
dnth Sep 3, 2026
e942d4d
no-mistakes(review): Fix route fixture and preserve unknown fire-and-…
dnth Sep 3, 2026
ef4d0eb
no-mistakes(review): Add dedicated reconcile delivery and outcome cov…
dnth Sep 3, 2026
d207617
no-mistakes(review): Fix reconciliation fixture initialization order
dnth Sep 3, 2026
32ab74f
no-mistakes(review): Propagate dedicated reconcile mode and delivery …
dnth Sep 3, 2026
ca7a5d7
no-mistakes(review): Prevent resend after durable OMP delivery outcomes
dnth Sep 3, 2026
8122be7
no-mistakes(review): Ensure unbounded reconciliation and dead-case co…
dnth Sep 3, 2026
cad539e
no-mistakes(review): Preserve cooldown after durable status five
dnth Sep 3, 2026
eea45c5
no-mistakes(review): Revalidate identity before cooldown suppression
dnth Sep 3, 2026
5722855
no-mistakes(review): Unbound registry traversal and serialize reconci…
dnth Sep 3, 2026
903a82f
no-mistakes(review): Unbound registry input and release failed reconc…
dnth Sep 3, 2026
49b3711
no-mistakes(review): Require existing carrier for reconcile delivery
dnth Sep 3, 2026
40ddfc8
no-mistakes(review): Persist and deduplicate reconciliation delivery IDs
dnth Sep 3, 2026
6887131
no-mistakes(review): Route reconcile sends through remote task metadata
dnth Sep 3, 2026
66c6a03
no-mistakes(review): Harden remote reconciliation routing and inbox d…
dnth Sep 3, 2026
ce7e46a
no-mistakes(review): Restrict generic delivery flag to reconciliation…
dnth Sep 3, 2026
f390384
no-mistakes(review): Harden cooldown persistence against symlink attacks
dnth Sep 3, 2026
4559fcc
no-mistakes(test): Classify unreachable reconciliation separately fro…
dnth Sep 3, 2026
3c422d2
no-mistakes(test): Skip dormant RunPod probes; initialize remote send…
dnth Sep 3, 2026
7fb6df1
no-mistakes(lint): Fix ShellCheck scoping and unused variable warnings
dnth Sep 3, 2026
7ed24c6
no-mistakes(ci): Fixed remote marked-send reconciliation: remote Code…
dnth Sep 3, 2026
69cc2d1
no-mistakes(ci): Fixed `bin/fm-remote-secondmate-control.sh` so non-O…
dnth Sep 3, 2026
12de746
no-mistakes(ci): Fixed dead markerless remote reconciliation by durab…
dnth Sep 3, 2026
0a28561
no-mistakes(ci): Fixed `bin/fm-remote-secondmate-control.sh` to load …
dnth Sep 3, 2026
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
4 changes: 4 additions & 0 deletions bin/fm-bearings-snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Default is LOCAL-ONLY (no network); --include-prs is the only path that fetches.

Default fields: schema, home, generated, prs, in_flight{id,kind,state,doing},
secondmates{id,state,doing,provenance,freshness,age_seconds,contradiction,reason},
secondmate_reconcile{id,spawn_gen,host,remote_root,kind,ids},
decisions_open{id,key,verb,summary,owner}, landed{id,what,artifact,owner},
gates{id,title,blocked_by,reason,owner}, reports{id,path}, recorded_prs{id,url},
unhealthy_endpoints{...} (only when non-empty), omitted{surface,reveal}.
Expand Down Expand Up @@ -428,6 +429,9 @@ MODEL=$(printf '%s' "$SNAP" | jq \
prs: $prs,
in_flight: (if $all_in_flight == 1 then $in_flight_all else $in_flight_all[:$in_flight_n] end),
secondmates: (if $all_secondmates == 1 then $secondmates_all else $secondmates_all[:$secondmates_n] end),
secondmate_reconcile: [ (.secondmate_current.records // [])[]
| select(.reconcile_inventory != null)
| {id, spawn_gen:(.spawn_gen // null), host:(.host // null), remote_root:(.remote_root // null), kind:(.reconcile_inventory.kind // null), ids:((.reconcile_inventory.ids // []) | map(select(type == "string")) | sort)} ],
decisions_open: (if $all_decisions == 1 then $decisions_all else $decisions_all[:$decisions_n] end),
landed: ($done | map({id, what:(.title | trunc(70)),
artifact:(.pr_url // .report_path // .local_note // "-"),owner:.home_id})),
Expand Down
9 changes: 9 additions & 0 deletions bin/fm-bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,14 @@ secondmate_liveness_sweep() {
return 0
}

secondmate_reconcile_sweep() {
[ -x "$SCRIPT_DIR/fm-secondmate-reconcile.sh" ] || return 0
local snapshot out
snapshot=$(FM_SNAPSHOT_SECONDMATES=0 FM_SNAPSHOT_REGISTRY_LINES=0 FM_SNAPSHOT_REGISTRY_BYTES=0 "$SCRIPT_DIR/fm-fleet-snapshot.sh" --json 2>/dev/null) || return 0
out=$(printf '%s' "$snapshot" | "$SCRIPT_DIR/fm-secondmate-reconcile.sh" notify --snapshot - 2>/dev/null) || true
[ -z "$out" ] || printf '%s\n' "$out"
}

secondmate_handoff_resume() {
[ -d "$DATA/handoff" ] || return 0
"$SCRIPT_DIR/fm-backlog-handoff.sh" --resume-pending >/dev/null 2>&1 || true
Expand Down Expand Up @@ -1202,6 +1210,7 @@ if [ "${FM_BOOTSTRAP_VERBOSE_FACTS:-0}" = 1 ] \
fi
if [ "${FM_BOOTSTRAP_DETECT_ONLY:-0}" != 1 ]; then
secondmate_liveness_sweep
secondmate_reconcile_sweep
secondmate_sync
secondmate_handoff_resume
x_mode_setup
Expand Down
79 changes: 48 additions & 31 deletions bin/fm-fleet-snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ FM_SNAPSHOT_PARENT_ACTIVITIES=${FM_SNAPSHOT_PARENT_ACTIVITIES:-20}
FM_SNAPSHOT_PARENT_ACTIVITY_TIMEOUT=${FM_SNAPSHOT_PARENT_ACTIVITY_TIMEOUT:-2}
FM_SNAPSHOT_REGISTRY_LINES=${FM_SNAPSHOT_REGISTRY_LINES:-256}
FM_SNAPSHOT_REGISTRY_BYTES=${FM_SNAPSHOT_REGISTRY_BYTES:-65536}
FM_SNAPSHOT_REGISTRY_RECORDS=${FM_SNAPSHOT_REGISTRY_RECORDS:-40}
FM_SNAPSHOT_REGISTRY_RECORDS=${FM_SNAPSHOT_REGISTRY_RECORDS:-0}
FM_SNAPSHOT_REGISTRY_TIMEOUT=${FM_SNAPSHOT_REGISTRY_TIMEOUT:-2}
validate_positive_bound() { # <name> <value>
case "$2" in
Expand Down Expand Up @@ -123,9 +123,8 @@ validate_positive_bound FM_SNAPSHOT_PARENT_ACTIVITY_LINES "$FM_SNAPSHOT_PARENT_A
validate_positive_bound FM_SNAPSHOT_PARENT_ACTIVITY_BYTES "$FM_SNAPSHOT_PARENT_ACTIVITY_BYTES"
validate_positive_bound FM_SNAPSHOT_PARENT_ACTIVITIES "$FM_SNAPSHOT_PARENT_ACTIVITIES"
validate_positive_bound FM_SNAPSHOT_PARENT_ACTIVITY_TIMEOUT "$FM_SNAPSHOT_PARENT_ACTIVITY_TIMEOUT"
validate_positive_bound FM_SNAPSHOT_REGISTRY_LINES "$FM_SNAPSHOT_REGISTRY_LINES"
validate_positive_bound FM_SNAPSHOT_REGISTRY_BYTES "$FM_SNAPSHOT_REGISTRY_BYTES"
validate_positive_bound FM_SNAPSHOT_REGISTRY_RECORDS "$FM_SNAPSHOT_REGISTRY_RECORDS"
case "$FM_SNAPSHOT_REGISTRY_LINES:$FM_SNAPSHOT_REGISTRY_BYTES" in *[!0-9:]*|:) echo "fm-fleet-snapshot: registry bounds must be non-negative" >&2; exit 2 ;; esac
case "$FM_SNAPSHOT_REGISTRY_RECORDS" in ''|*[!0-9]*) echo "fm-fleet-snapshot: FM_SNAPSHOT_REGISTRY_RECORDS must be nonnegative" >&2; exit 2 ;; esac
validate_positive_bound FM_SNAPSHOT_REGISTRY_TIMEOUT "$FM_SNAPSHOT_REGISTRY_TIMEOUT"

# shellcheck source=bin/fm-backend.sh
Expand All @@ -137,6 +136,9 @@ validate_positive_bound FM_SNAPSHOT_REGISTRY_TIMEOUT "$FM_SNAPSHOT_REGISTRY_TIME
# shellcheck source=bin/fm-ff-lib.sh
# shellcheck disable=SC1091
. "$SCRIPT_DIR/fm-ff-lib.sh" # validate_secondmate_home: shared seeded-home boundary checks
# shellcheck source=bin/fm-runpod-lib.sh
# shellcheck disable=SC1091
. "$SCRIPT_DIR/fm-runpod-lib.sh"

usage() {
cat <<'EOF'
Expand Down Expand Up @@ -402,7 +404,7 @@ backlog_json() { # [<backlog-path>] - defaults to this home's $BACKLOG

task_json_lines() {
local meta id kind harness mode yolo project worktree home projects backend target status_log report_path
local remote_host remote_root remote_state remote_rc remote_home_present
local remote_host task_remote_root spawn_gen remote_state remote_rc remote_home_present
local pr pr_source event_json current_json endpoint_exists agent_alive meta_json status_json report_json worktree_json home_json
local last_event_raw current_state current_source pending_decision blocked_event report_present=0 pr_from_status
local open_decisions_tsv open_decisions_json
Expand All @@ -420,7 +422,8 @@ task_json_lines() {
home=$(meta_value "$meta" home)
projects=$(meta_value "$meta" projects)
remote_host=$(meta_value "$meta" remote_host)
remote_root=$(meta_value "$meta" remote_root)
task_remote_root=$(meta_value "$meta" remote_root)
spawn_gen=$(meta_value "$meta" spawn_gen)
remote_home_present=null
if [ -n "$remote_host" ]; then
backend=$(meta_value "$meta" remote_backend)
Expand Down Expand Up @@ -483,24 +486,32 @@ task_json_lines() {
endpoint_exists=null
agent_alive=not_checked
if [ -n "$remote_host" ]; then
if remote_state=$(run_timed "$FM_SNAPSHOT_SECONDMATE_TIMEOUT" \
"$SCRIPT_DIR/fm-on.sh" "$id" fm-remote-secondmate-control.sh state "$id" < /dev/null 2>/dev/null); then
remote_rc=0
else
remote_rc=$?
fi
if [ "$remote_rc" -eq 0 ]; then
remote_home_present=true
remote_state=$(printf '%s\n' "$remote_state" | tail -1)
case "$remote_state" in
alive) endpoint_exists=true; agent_alive=alive ;;
dead) endpoint_exists=true; agent_alive=dead ;;
missing) endpoint_exists=false; agent_alive=dead ;;
*) endpoint_exists=null; agent_alive=unknown ;;
esac
else
# RunPod scale-to-zero routes are deliberate no-host lifecycle states.
# Keep the snapshot read-only and avoid probing their absent SSH endpoint.
if fm_runpod_is_dormant "$DATA" "$id"; then
remote_home_present=false
endpoint_exists=null
agent_alive=unknown
else
if remote_state=$(run_timed "$FM_SNAPSHOT_SECONDMATE_TIMEOUT" \
"$SCRIPT_DIR/fm-on.sh" "$id" fm-remote-secondmate-control.sh state "$id" < /dev/null 2>/dev/null); then
remote_rc=0
else
remote_rc=$?
fi
if [ "$remote_rc" -eq 0 ]; then
remote_home_present=true
remote_state=$(printf '%s\n' "$remote_state" | tail -1)
case "$remote_state" in
alive) endpoint_exists=true; agent_alive=alive ;;
dead) endpoint_exists=true; agent_alive=dead ;;
missing) endpoint_exists=false; agent_alive=dead ;;
*) endpoint_exists=null; agent_alive=unknown ;;
esac
else
endpoint_exists=null
agent_alive=unknown
fi
fi
else
if [ -n "$target" ]; then
Expand Down Expand Up @@ -541,7 +552,8 @@ task_json_lines() {
--arg backend "$backend" \
--arg target "$target" \
--arg remote_host "$remote_host" \
--arg remote_root "$remote_root" \
--arg remote_root "$task_remote_root" \
--arg spawn_gen "$spawn_gen" \
--arg pr "$pr" \
--arg pr_source "$pr_source" \
--arg agent_alive "$agent_alive" \
Expand All @@ -566,6 +578,8 @@ task_json_lines() {
yolo:($yolo // ""),
project:($project // ""),
backend:$backend,
spawn_gen:($spawn_gen | if . == "" then null else . end),
remote_root:($remote_root | if . == "" then null else . end),
remote:(if $remote_host == "" then null else {host:$remote_host,root:$remote_root} end),
paths:{
meta:$meta_path,
Expand Down Expand Up @@ -860,7 +874,7 @@ registry_secondmates_json() {
observed=$6
parse_filter=$7
output_filter=$8
content=$(LC_ALL=C head -c "$((max_bytes + 1))" "$f" || exit 3; printf "\036") || exit 3
if [ "$max_bytes" -eq 0 ]; then content=$(cat "$f" || exit 3; printf "\036"); else content=$(LC_ALL=C head -c "$((max_bytes + 1))" "$f" || exit 3; printf "\036"); fi
content=${content%$'\036'}
bytes=$(printf "%s" "$content" | LC_ALL=C wc -c | tr -d " ")
byte_truncated=false
Expand All @@ -881,7 +895,7 @@ registry_secondmates_json() {
fi
line_truncated=false
if [ "$lines" -gt "$max_lines" ]; then line_truncated=true; fi
window=$(printf "%s\n" "$content" | LC_ALL=C head -n "$max_lines") || exit 3
if [ "$max_lines" -eq 0 ]; then window=$content; else window=$(printf "%s\n" "$content" | LC_ALL=C head -n "$max_lines") || exit 3; fi
if [ -n "$window" ]; then
lines_in_window=$(printf "%s\n" "$window" | awk "END {print NR}")
else
Expand All @@ -890,7 +904,7 @@ registry_secondmates_json() {
records=$(printf "%s\n" "$window" | jq -Rn "$parse_filter") || exit 3
records_in_window=$(printf "%s" "$records" | jq "length") || exit 3
records_truncated=false
if [ "$records_in_window" -gt "$max_records" ]; then records_truncated=true; fi
if [ "$max_records" -gt 0 ] && [ "$records_in_window" -gt "$max_records" ]; then records_truncated=true; fi
printf "%s" "$records" | jq \
--arg path "$path" --arg observed "$observed" \
--argjson byte_truncated "$byte_truncated" \
Expand Down Expand Up @@ -920,7 +934,7 @@ JQ
output_filter=$(cat <<'JQ'
{present:true,available:true,reason:null,provenance:"registered-table",path:$path,
freshness:{status:"fresh",observed_at:$observed},
records:(if length > $max_records then .[:$max_records] else . end),
records:(if $max_records == 0 or length <= $max_records then . else .[:$max_records] end),
input_truncated:($byte_truncated or $line_truncated),records_truncated:$records_truncated,
complete:(($byte_truncated or $line_truncated or $records_truncated) | not),
reasons:[
Expand Down Expand Up @@ -1149,7 +1163,7 @@ parent_evidence_reconciliation_json() { # <summary-json> <activities-json> <dec

secondmate_current_json() { # <parent-tasks-json>
local tasks=$1 registry union rows total_registered total shown truncated
local row id home host remote registered registry_error task status_file event_raw event_note event_epoch event_age
local row id home host root spawn_gen remote registered registry_error task status_file event_raw event_note event_epoch event_age
local activity_scan activities decisions reconciliation provenance freshness reason summary summary_rc summary_bytes summary_valid summary_reason summary_invalidity state current_reason terminal terminal_contradiction contradiction
local records='[]' seen_homes=''
registry=$(registry_secondmates_json) || return 1
Expand Down Expand Up @@ -1179,10 +1193,12 @@ secondmate_current_json() { # <parent-tasks-json>
id=$(printf '%s' "$row" | jq -r '.id')
home=$(printf '%s' "$row" | jq -r '.home // ""')
host=$(printf '%s' "$row" | jq -r '.host // ""')
root=$(printf '%s' "$row" | jq -r '.root // ""')
remote=$(printf '%s' "$row" | jq -r '.remote // false')
registered=$(printf '%s' "$row" | jq -r '.registered')
registry_error=$(printf '%s' "$row" | jq -r '.registry_error // ""')
task=$(printf '%s' "$row" | jq -c '.parent_task // {}')
spawn_gen=$(printf '%s' "$task" | jq -r '.spawn_gen // ""')
status_file=$(printf '%s' "$task" | jq -r '.paths.status_log.path // ""')
event_raw=$(printf '%s' "$task" | jq -r '.paths.status_log.last_event.raw // ""')
event_note=$(printf '%s' "$task" | jq -r '.paths.status_log.last_event.note // ""')
Expand Down Expand Up @@ -1294,19 +1310,20 @@ secondmate_current_json() { # <parent-tasks-json>
fi
if printf '%s' "$terminal" | jq -e '.contradiction == true' >/dev/null; then contradiction=true; fi
record=$(jq -n \
--arg id "$id" --arg home "$home" --arg host "$host" --argjson remote "$remote" --arg state "$state" --arg current_reason "$current_reason" --arg observed "$SNAPSHOT_NOW" \
--arg id "$id" --arg home "$home" --arg host "$host" --arg remote_root "$root" --arg spawn_gen "$spawn_gen" --argjson remote "$remote" --arg state "$state" --arg current_reason "$current_reason" --arg observed "$SNAPSHOT_NOW" \
--argjson registered "$registered" --argjson summary "$summary" --argjson summary_valid "$summary_valid" --argjson decisions "$decisions" \
--argjson activities "$activities" --argjson activity_scan "$activity_scan" \
--argjson reconciliation "$reconciliation" --argjson terminal "$terminal" --argjson contradiction "$contradiction" \
--arg event_raw "$event_raw" --arg event_note "$event_note" --argjson event_age "$event_age" '
{id:$id,home:$home,host:($host | if . == "" then null else . end),remote:$remote,registered:$registered,
{id:$id,home:$home,host:($host | if . == "" then null else . end),remote_root:($remote_root | if . == "" then null else . end),spawn_gen:($spawn_gen | if . == "" then null else . end),remote:$remote,registered:$registered,
current:{state:$state,reason:($current_reason | if . == "" then null else . end)},invalidity:$summary.invalidity,
provenance:{selected:"structured-home",structured_home:$home,summary_valid:$summary_valid,
trust:(if $summary_valid then "complete" else "partial-structured" end),parent_event_role:"historical-only"},
freshness:{status:"fresh",observed_at:$observed,age_seconds:0},
active_children:$summary.active_children,
decisions_open:$summary.decisions_open,holds:$summary.holds,queued:$summary.queued,
landed:$summary.landed,endpoints:$summary.endpoints,counts:$summary.counts,omitted:$summary.omitted,
reconcile_inventory:(if ($summary.invalidity.kind // "") == "" then null else {kind:$summary.invalidity.kind,ids:($summary.invalidity.ids // [])} end),
parent_event:{raw:$event_raw,note:$event_note,age_seconds:$event_age,open_activities:$activities,open_decisions:$decisions,activity_scan:$activity_scan,reconciliation:$reconciliation},
terminal_evidence:$terminal,contradiction:$contradiction}')
else
Expand All @@ -1324,7 +1341,7 @@ secondmate_current_json() { # <parent-tasks-json>
'{provenance:"parent-direct-report-terminal",trust:"untrusted-supplement",captured:false,observed_at:$observed,freshness:"not-collected",reason:"no parent event to compare",lines:0,bytes:0,event_note_seen:false,contradiction:false}')
fi
record=$(jq -n \
--arg id "$id" --arg home "$home" --arg host "$host" --argjson remote "$remote" --arg reason "$reason" --arg observed "$SNAPSHOT_NOW" \
--arg id "$id" --arg home "$home" --arg host "$host" --arg remote_root "$root" --argjson remote "$remote" --arg reason "$reason" --arg observed "$SNAPSHOT_NOW" \
--arg provenance "$provenance" --arg freshness "$freshness" --arg event_raw "$event_raw" --arg event_note "$event_note" \
--argjson registered "$registered" --argjson event_age "$event_age" --argjson activities "$activities" --argjson activity_scan "$activity_scan" \
--argjson decisions "$decisions" --argjson terminal "$terminal" '
Expand Down
Loading
Loading