Skip to content

feat(bin): fleet ops hardening with login probe, PR auto-merge, and relay trust - #6924

Closed
derickdsouza wants to merge 22 commits into
kunchenguid:mainfrom
derickdsouza:fm/login-probe-retry-hardening
Closed

derickdsouza wants to merge 22 commits into
kunchenguid:mainfrom
derickdsouza:fm/login-probe-retry-hardening

Conversation

@derickdsouza

Copy link
Copy Markdown

Intent

The daily login-health watch keeps producing false FAILs for pi on the VPS: a transient pi --list-models catalog blip makes bin/fm-agent-login-probe.sh declare "needs re-login" from a single unverified pass. Confirmed transients: 2026-09-08, 2026-09-10, and again today 2026-10-09 (each FAIL was followed by a clean live re-run showing OK pi@g vps; grok/cursor/claude always OK). Each false FAIL burns a firstmate wake and risks escalating a credential problem that does not exist. The ask, per the queued task: add one retry before declaring a failure - a single blip must never produce FAIL.

What Changed

  • Adds bin/fm-agent-login-probe.sh, an agent-agnostic pi/grok/cursor/claude login health probe that retries a failed pi --list-models catalog pass once (locally and over the VPS ssh) so a single transient blip never reports FAIL, plus bin/fm-fleet-watch-poller.sh, a harness-independent when-watch supervisor with single-flight locking and cron install.
  • Adds clean+green+Evidence PR auto-merge (bin/fm-pr-auto-merge.sh with the fm-pr-auto-merge-tick.sh tick wired into fm-watch.sh behind the FM_PR_AUTO_MERGE kill switch, refusing merges for every repo while the harbor queue-only freeze is on), a per-task token usage ledger (bin/fm-usage-lib.sh, harness session log bound at spawn and token totals appended at teardown), and an optional FM_SPAWN_GATE_CMD pre-spawn gate hook (bin/fm-spawn-gate-lib.sh, acquire in fm-spawn.sh, release in fm-teardown.sh).
  • Hardens the Relay path with bin/fm-untrusted-text-lib.sh sanitization of stashed mention strings (.text, .in_reply_to.text, .in_reply_to_chain[].text), validated alternate poll-shim registration via bin/fm-x-watch-register.sh, an ack-before-spawn guard that blocks long work until the initial relay answer is recorded, and stuck-remote-helper classification with replace-relaunch and parent-driven steering-inbox ticks via bin/fm-secondmate-health-lib.sh and the liveness/watch wiring; updates the configuration, remote-secondmates, and scripts docs.

Risk Assessment

✅ Low: The new commits are small and exactly implement the requested single catalog retry for pi with behavior-level tests; two confirmed failures still FAIL, the failure path for genuine re-login is preserved, and the bundled earlier commits were previously gated with no new defects found beyond one trivial duplicated assignment.

Testing

Exercised the login-health probe end-to-end through its public OK/FAIL stdout + exit-code contract, which is the exact surface the daily login-watch consumes (this change has no GUI; the captured CLI transcripts are the reviewer-visible end-user evidence). Ran the focused automated suites (login-probe and fleet-watch-poller, all passing), reproduced the reported false FAIL against the pre-fix script, and demonstrated the fixed script recovers from a single transient pi catalog blip without retrying healthy passes while still FAILing on a confirmed double failure, on both the local VPS path and the remote ssh path. Five transcript artifacts are in the evidence directory; the worktree was left clean.

Evidence: Pre-fix false FAIL reproduction: single transient pi catalog blip -> FAIL pi@vps (needs re-login), exit 1, after only 1 unverified pass (parent commit 8c7c604)

Source: Pre-fix false FAIL reproduction: single transient pi catalog blip -> FAIL pi@vps (needs re-login), exit 1, after only 1 unverified pass (parent commit 8c7c604)

\### Scenario A - single transient `pi --list-models` catalog blip (2026-09-08/10-09 class)
\### PRE-FIX probe (parent commit 8c7c604):
$ run .tmp-probe-eval/probe-prefix.sh   # fake pi: call 1 = blip, call 2 = healthy zai catalog
FAIL pi@vps (needs re-login)
OK   grok@vps
OK   cursor@vps
OK   claude@vps
exit_code=1
pi invocations: 1  (pre-fix: FAILs after a single unverified pass)
Evidence: Fixed probe, same single blip: OK pi@vps, exit 0, exactly 2 pi invocations (one retry) - no FAIL, no firstmate wake (target commit 6e9e1e0)

Source: Fixed probe, same single blip: OK pi@vps, exit 0, exactly 2 pi invocations (one retry) - no FAIL, no firstmate wake (target commit 6e9e1e0)

\### Scenario A - single transient `pi --list-models` catalog blip
\### FIXED probe (target commit 6e9e1e0):
$ bin/fm-agent-login-probe.sh          # same fake pi: call 1 = blip, call 2 = healthy zai catalog
OK   pi@vps
OK   grok@vps
OK   cursor@vps
OK   claude@vps
exit_code=0
pi invocations: 2  (one retry, then OK - no FAIL, no firstmate wake)
Evidence: Fixed probe, catalog down on both passes: FAIL pi@vps (needs re-login), exit 1, 2 pi invocations - real credential problems still escalate

Source: Fixed probe, catalog down on both passes: FAIL pi@vps (needs re-login), exit 1, 2 pi invocations - real credential problems still escalate

\### Scenario B - catalog down on BOTH passes (real credential problem)
$ bin/fm-agent-login-probe.sh          # fake pi: every call = blip
FAIL pi@vps (needs re-login)
OK   grok@vps
OK   cursor@vps
OK   claude@vps
exit_code=1
pi invocations: 2  (retry confirmed the failure -> FAIL still fires)
Evidence: Fixed probe, healthy first pass: OK pi@vps, exit 0, only 1 pi invocation - no wasteful retry on a normal day

Source: Fixed probe, healthy first pass: OK pi@vps, exit 0, only 1 pi invocation - no wasteful retry on a normal day

\### Scenario C - healthy catalog on first pass (normal day)
$ bin/fm-agent-login-probe.sh
OK   pi@vps
OK   grok@vps
OK   cursor@vps
OK   claude@vps
exit_code=0
pi invocations: 1  (no retry on first-pass OK)
Evidence: Remote ssh path (Darwin watch host -> VPS): single remote blip retried once -> OK pi@vps; remote double failure -> FAIL pi@vps (needs re-login)

Source: Remote ssh path (Darwin watch host -> VPS): single remote blip retried once -> OK pi@vps; remote double failure -> FAIL pi@vps (needs re-login)

\### Remote scenario - Darwin watch host probing the VPS over ssh (FM_LOGIN_PROBE_VPS_SSH=fakevps)
\### R1: remote `pi --list-models` blips once (transient catalog error)
$ bin/fm-agent-login-probe.sh
OK   pi@mac
OK   grok@mac
OK   cursor@mac
OK   claude@mac
OK   pi@vps
OK   grok@vps
OK   cursor@vps
OK   claude@vps
exit_code=0
remote pi invocations: 2  (single remote blip retried once -> remote OK)

\### R2: remote catalog down on BOTH passes (real credential problem)
$ bin/fm-agent-login-probe.sh
OK   pi@mac
OK   grok@mac
OK   cursor@mac
OK   claude@mac
FAIL pi@vps (needs re-login)
OK   grok@vps
OK   cursor@vps
OK   claude@vps
exit_code=1
remote pi invocations: 2  (double failure confirmed -> remote FAIL)

\### Note: the reachability gate `ssh <alias> true` requires non-empty stdout (e.g. an sshd Banner); with a fully silent ssh the pre-existing gate (unchanged by this fix) reports "ssh unreachable" before any catalog check runs. The fake ssh above emits a banner line, as the fleet sshd does.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

⏭️ **Rebase** - skipped

Push main to origin, or rebase your branch onto origin/main, before gating.

⚠️ **Review** - 1 info
  • ℹ️ bin/fm-watch.sh:2779 - The bundled auto-merge tick wiring (commit 43527d9, inside this branch's diff) initializes rejected_checks= twice back-to-back (lines 2779-2780) before the check sweep loop. The duplicate assignment is a harmless copy-paste leftover with no behavioral effect; dropping one line is a purely mechanical simplification.
✅ **Test** - passed

✅ No issues found.

  • bin/fm-test-run.sh tests/fm-agent-login-probe.test.sh (4/4 pass: blip recovers on one retry, double failure still FAILs, first-pass OK does not retry, absent pi fails as not installed)
  • bin/fm-test-run.sh tests/fm-fleet-watch-poller.test.sh (7/7 pass, including login probe under minimal cron env and PATH-pi-on-Linux checks)
  • Manual before/after end-to-end: pre-fix probe from parent commit 8c7c604 vs fixed probe from 6e9e1e0, run via env -i HOME=&lt;empty&gt; PATH=&lt;fakebin&gt;:/usr/bin:/bin FM_LOGIN_PROBE_SKIP_VPS=1 with a fake pi whose first --list-models call exits 1 with an empty catalog (the transient blip) — pre-fix reproduced FAIL pi@vps (needs re-login) exit 1 after 1 call; fixed printed OK pi@vps exit 0 after exactly 2 calls
  • Manual persistent-failure and healthy-catalog runs of the fixed probe (double blip -> FAIL needs re-login exit 1 after 2 calls; healthy -> OK exit 0 after 1 call, no wasteful retry)
  • Manual remote-path run: fixed probe with fake uname(Darwin) + fake ssh (FM_LOGIN_PROBE_VPS_SSH=fakevps) where the remote pi catalog blips once -> OK pi@vps after 2 remote invocations; always-down remote catalog -> FAIL pi@vps (needs re-login)
  • Confirmed the ssh &lt;alias&gt; true reachability gate requiring non-empty stdout is pre-existing (present unchanged at parent commit 8c7c604 line 137), not introduced by this fix
⚠️ **Document** - 1 info
  • ℹ️ docs/scripts.md:154 - Pre-existing inventory gap, not staleness from the login-probe retry: docs/scripts.md lists 148 of 219 bin scripts and gained a row for fm-x-watch-register.sh during this branch, but the branch's other new fleet scripts (fm-agent-login-probe.sh, fm-fleet-watch-poller.sh, fm-pr-auto-merge.sh, fm-pr-auto-merge-tick.sh, and the new *-lib.sh helpers) have no rows. Each script's header remains the authoritative owner per the table's own preamble, so nothing is inaccurate. Worth a separate follow-up pass to decide inventory criteria; deliberately not bundled here because most of those scripts come from commits the user declined to treat as this PR's work.
⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

derickdsouza and others added 22 commits September 2, 2026 01:35
…guid#149) (#1)

Extend fmx_poll_shim_valid to honor config/harbor-telegram-hitl.poll-shim.registration.json
so harbor telegram-hitl can replace x-watch.check.sh without watcher rejection.

Enforce relay ack-before-long-work: fm-x-reply records x-context/<id>.answered.json
on the initial answer; fm-spawn refuses while any open x-inbox row lacks that marker.

Co-authored-by: Cursor <cursoragent@cursor.com>
Port of derickdsouza/firstmate PR #2 onto org main: the explicit
bin/fm-x-watch-register.sh binding command with colocated tests, the
stock/registered validator split, watcher exec-target dispatch with the
re-register hint, and bootstrap preservation of a still-matching binding.
Mainline harbor manifest validation is kept as fmx_poll_shim_manifest_valid
and chained into fmx_poll_shim_valid, so harbor-installed and
CLI-registered alternates authenticate through one dispatch-time check.
Port of derickdsouza/firstmate PR #3 in full: deterministic length-bound
fm-untrusted-text-lib.sh neutralizing injection role-markers, HTML comments,
and operational-prefix impersonation, wired into the relay mention stash
path with claim-and-dismiss for empty-after-sanitize mentions, batched
chain sanitizing bounded by string size rather than entry count, and
colocated coverage across locale, multibyte, fixed-point, and budget cases.
…ontract

Port of the parked fm/adopt-constitution-layering branch (7ba0d37):
ship and promoted-scout briefs carry the layering discipline - shared
worker-facing rule files are law and are never same-name overridden by a
project; project specialization lives in distinctly-namespaced local
files. Scaffold tests pin the contract on both brief paths.
Bring in 9 upstream commits (relay media, spawn/startup/wake fixes,
Bearings concurrency, pi supervision, CI shards) while preserving fleet
commits: HITL poll-shim trust, ack-before-spawn, sanitizer, constitution
layering.

Conflicts resolved in docs/configuration.md and tests/fm-x-mode.test.sh
(fleet untrusted-text sanitization kept).

Co-authored-by: Cursor <cursoragent@cursor.com>
…-09-02

merge(upstream): sync kunchenguid/firstmate main (9 commits)
Process-alive is not health. A remote helper with unacked steering-inbox
mail past the ladder, or a repeating Node missing-module capture after a
harness upgrade under a live process, is stuck.

launch now replaces stuck helpers instead of reusing them. Session-start
liveness respawns those stuck remotes. The parent watcher ticks the remote
inbox ladder on the host. Spawn/bootstrap reconcile the reply runner after
arming so a registered source is not left without a child.
…down (kunchenguid#4) (kunchenguid#5)

Co-authored-by: Derick D'Souza <derick@nivasritech.com>
* feat(bin): fleet when-watch poller with cron dedupe and single-flight lock

* feat(bin): agent login probe with login-shell PATH resolution

Cron hardening: default USER/LOGNAME when unset and prepend the standard
CLI install roots (~/.local/bin, nvm per-version bin, ~/.grok/bin,
Homebrew) to PATH so a minimal cron environment no longer misreports
installed CLIs as absent. Also fix the grok and cursor checks, whose
has_stdout ... | grep pipeline could never match because has_stdout
captures the output and returns only a status; they now grep the real
command output. Every expansion is set -u safe under env -i.
kunchenguid#7) (kunchenguid#8)

Grok and cursor cannot neutralize AGENTS.md/CLAUDE.md, so they cannot gate
fleet repos. Keep the chain in ~/.no-mistakes/config.yaml and out of the
tracked repo override.
Darwin still uses zsh -l for pi and may ssh to the VPS. Linux is the VPS:
probe locally as vps via PATH, and do not ssh to ghwave.
Merge upstream firstmate into nivasritech/firstmate without rebasing so
pm-dev can keep pulling with --ff-only.

Conflict resolutions (section 6 of the 6 Oct 2026 upstream check):

Take upstream, then re-apply fork lines:
- AGENTS.md — upstream layout; x-watch.poll-trust row lives in
  operational-home-layout
- CONTRIBUTING.md — drop our now-covered reviewer-chain line
- bin/fm-brief.sh, bin/fm-dod-lib.sh, bin/fm-promote.sh,
  tests/fm-brief.test.sh — layering line moved to per-home
  config/brief-include.md (not in this repo)
- tests/fm-task-delivery.test.sh — keep Captain's intent / Firstmate spec
  checks; drop the layering assertion

Keep both:
- bin/fm-spawn.sh — upstream meta fields plus usage_source/usage_log,
  account pin, usage bind, and the remote procevent reconcile
- bin/fm-teardown.sh — usage-ledger header plus captain-hold retention
- docs/configuration.md — upstream structure plus poll-shim, sanitizer,
  ack-before-spawn, and usage-ledger sentences
- docs/scripts.md — upstream rows plus fm-x-watch-register.sh
- tests/fm-gotmp.test.sh — both fm-env-lib.sh and fm-untrusted-text-lib.sh

Manual:
- bin/fm-bootstrap.sh — keep the upstream liveness lock; classify stuck
  remote helpers inside that lock
- bin/fm-remote-secondmate-control.sh — upstream 4-arg relaunch; keep
  health and inbox-tick
- bin/fm-watch.sh — upstream inbox policy plus remote inbox-tick; keep
  both check-loop variables
- docs/remote-secondmates.md — match the inbox-tick keep

Usage ledger kept. Layering line not kept in code.

Co-authored-by: Derick D'souza <derick-dsouza@users.noreply.github.com>
Upstream fm_test_run_spawn now pins a throwaway user-home, so the
usage-ledger spawn checks read that store. Teardown gotmp fixtures also
link fm-usage-lib.sh because teardown still sources the retained ledger.

Co-authored-by: Derick D'souza <derick-dsouza@users.noreply.github.com>
…am-2026-10-9321

sync: merge kunchenguid/firstmate main (5838f10)
Move remote alive-but-stuck upgrade into the full-mode liveness probe and
remote inbox escalate reason into the health lib so bootstrap and watch stay
one-call hooks. Keep health/inbox-tick on the remote control script.

Co-authored-by: Derick D'souza <derick-dsouza@users.noreply.github.com>
…k-helper-hooks-9321

refactor: thin stuck-helper hooks into secondmate libs
…unchenguid#15)

Implements harbor kunchenguid#664 R1-R10 on firstmate: rebase when dirty, refuse on
red CI / missing Evidence / open ask-user / protected paths, respect the
harbor queue-only freeze, then squash-merge with --match-head-commit and
write a ledger note. Not enabled or deployed — callers opt in.
…chenguid#17)

Call fm-pr-auto-merge for every armed GitHub PR poll on the check cadence.
Kill switch FM_PR_AUTO_MERGE defaults to on. Harbor merges stay refused
while HARBOR_DO_UNFREEZE is unset (tick gate + script gate). Triage_log
only — never wakes on refuse/idle.
…unchenguid#16)

Firstmate's own crew spawns had no fleet cap in code. A host may now set one
command that every fresh ship/scout spawn must pass, under the task-set lock and
before any endpoint, worktree, or record exists: <cmd> acquire <id>; non-zero
refuses. fm-teardown calls <cmd> release <id> after the record is removed (never
fails teardown). Unset = no-op. No shell eval. Relaunch and secondmate exempt.
For harbor: harbor-slot-gate.sh fm-hook (nivasritech/harbor#728).
While HARBOR_DO_UNFREEZE is unset, the auto-merge tick and merge script
refuse merges in every repo (not only */harbor). The PR stays open and
queued. Unfrozen behaviour and the other R1–R10 gates are unchanged.

Refs: harbor kunchenguid#676 (freeze), harbor kunchenguid#737 (merged during freeze; no revert).
A single transient `pi --list-models` blip was declaring needs re-login
and waking the daily login-watch. Retry the catalog once so only a
confirmed double failure becomes FAIL.
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate (OSS triage, not the captain).

Thanks @derickdsouza. I read the whole PR at head 6e9e1e04 against main 19fcbbde. It's CONFLICTING, and no CI has run. I'm closing it as not aligned with this repo's VISION.md. My reasons are below. You're welcome to reopen, or to send the generic pieces as separate PRs against current main.

What the tip bundles: 42 files and about 4.4k lines. That's the pi login-probe retry from the Intent, plus a default-on PR auto-merge tick wired into bin/fm-watch.sh (FM_PR_AUTO_MERGE defaults to on; it rebases, pushes, and squash-merges), a per-task usage ledger, a FM_SPAWN_GATE_CMD hook, Relay poll-shim registration, a spawn guard that waits on a Telegram ack, and remote-secondmate health/steer changes.

VISION.md, rule by rule

  • Authority is explicit and never inferred: does not align. "Merging … require[s] the captain's explicit word" and "new capability ships as an option to enable." A watcher tick that auto-rebases, pushes, and merges by default (held back only by an unrelated HARBOR_DO_UNFREEZE freeze) assumes consent.
  • Scope: does not align. "The shared surface is generic and captain-agnostic." The tip hard-codes one home's setup: harbor's required-check names (relay-tests,tui-tests,quint-gate,…), config/harbor-telegram-hitl.poll-shim.registration.json, harbor issue numbers, and a VPS pi account.
  • The fleet outlives any vendor: does not align. Spawn refusal is tied to a Telegram ack, and Relay check trust is tied to a harbor manifest.
  • Delegation with a spine: does not align. "A new task shape earns its way in only when existing primitives genuinely cannot compose." Several unrelated capabilities ride on one login-probe intent.
  • One captain, one interface: cannot tell (too bundled to judge per feature).
  • Scripts own the mechanics: mostly aligns per script.
  • A restart is a non-event: neutral.

Contract-class: new-default. The auto-merge tick, Telegram-ack spawn guard, and Relay trust changes all run on the unconfigured path.

Security note: the Relay change widens which executable the watcher runs for x-watch.check.sh. Besides the stock shim, it accepts any absolute executable named in a config/ manifest or a registered binding, if its hash matches. That's a new trust root, and it would need its own focused review.

This looks like the same wrong-parent push you described on #3533 (fork-home commits pushed to kunchenguid/firstmate). If the login-probe retry or the mention-text sanitizer is meant for upstream, a small generic PR for each would get a fresh look.

@kunchenguid kunchenguid closed this Oct 9, 2026
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.

3 participants