Skip to content

fix(bin): report exited quota-stalled workers as agent gone - #5952

Open
mehulbhagwani wants to merge 25 commits into
kunchenguid:mainfrom
mehulbhagwani:fm/fm-bug-quota-stall
Open

mehulbhagwani wants to merge 25 commits into
kunchenguid:mainfrom
mehulbhagwani:fm/fm-bug-quota-stall

Conversation

@mehulbhagwani

@mehulbhagwani mehulbhagwani commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #5946

Intent

Report an exited, quota-stalled Pi worker as gone when the endpoint shows only a shell. Keep valid terminal outcomes and secondmate handling unchanged.

What Changed

  • Treat readable shell-only endpoints as gone for non-secondmate workers, preventing stale busy/status records from reporting exited quota-stalled agents as working.
  • Preserve valid terminal done/failed status declarations after harness exit, while keeping secondmate status-log handling unchanged.
  • Add regression coverage for Pi quota exits, terminal outcomes, and lost secondmate endpoints, and update the architecture fallback documentation.

Risk Assessment

✅ Low: The change is narrowly scoped to the no-run fallback, preserves terminal declarations, and adds executable regression coverage for the introduced liveness boundary without a substantiated remaining defect.

Testing

The focused crew-state test file completed successfully. Two live product scenarios passed against real isolated tmux workers, with reviewer-visible transcripts captured; Rex-specific live validation remains untested because no Rex executable or disposable credentialed runtime is available.

  • Live validation: ⚠️ inconclusive - 2 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Exited tmux harness with readable shell is reconciled as agent gone ✅ pass live ~/.no-mistakes/evidence/01M8DH4EHMZ1RX6DWVT84MR5FX/live-tmux-shell-only-result.txt
Live tmux endpoint is not falsely classified as agent gone ✅ pass live ~/.no-mistakes/evidence/01M8DH4EHMZ1RX6DWVT84MR5FX/live-tmux-active-result.txt
Rex shell-only endpoint, including quota-stalled worker, is reconciled as agent gone ⏸️ untested no Could not drive this live: Rex is unavailable on PATH, and the workspace provides no repository-local Rex runtime or disposable credentialed quota-error path. The existing Herdr/Rex fake-backend tests…
Evidence: Live tmux shell-only reconciliation

Source: Live tmux shell-only reconciliation

state: unknown · source: none · backend target gone: lab:fm-worker (agent gone, pane shell remains)

state: unknown · source: none · backend target gone: lab:fm-worker (agent gone, pane shell remains)
Evidence: Live tmux active endpoint guard

Source: Live tmux active endpoint guard

state: unknown · source: pane · harness state unavailable (unknown missing)

state: unknown · source: pane · harness state unavailable (unknown missing)
  • Outcome: ⚠️ 1 warning across 1 run (8m45s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

🔧 **Rebase** - 2 issues found → auto-fixed ✅
  • ⚠️ bin/fm-crew-state.sh - merge conflict rebasing onto origin/main
  • ⚠️ tests/fm-crew-state.test.sh - merge conflict rebasing onto origin/main

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Review** - passed

✅ No issues found.

⚠️ **Test** - 1 warning
  • ⚠️ live validation verdict: inconclusive (2 of 3 scenarios were driven live against the product); untested: Rex shell-only endpoint, including quota-stalled worker, is reconciled as agent gone
  • Live validation: ⚠️ inconclusive - 2 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Exited tmux harness with readable shell is reconciled as agent gone ✅ pass live ~/.no-mistakes/evidence/01M8DH4EHMZ1RX6DWVT84MR5FX/live-tmux-shell-only-result.txt
Live tmux endpoint is not falsely classified as agent gone ✅ pass live ~/.no-mistakes/evidence/01M8DH4EHMZ1RX6DWVT84MR5FX/live-tmux-active-result.txt
Rex shell-only endpoint, including quota-stalled worker, is reconciled as agent gone ⏸️ untested no Could not drive this live: Rex is unavailable on PATH, and the workspace provides no repository-local Rex runtime or disposable credentialed quota-error path. The existing Herdr/Rex fake-backend tests…
  • bash tests/fm-crew-state.test.sh
  • Real isolated tmux worker exits to shell, then bin/fm-crew-state.sh worker
  • Real isolated tmux worker remains active, then bin/fm-crew-state.sh worker
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Closes #5946

@greptile-apps

greptile-apps Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] Updates agent skill documentation and operational scripts.

The PR does not appear safe to merge while a readable, dead secondmate can still appear finished.

Reviews (7) · Last reviewed commit: "no-mistakes(ci): Captain, added regressi..." · Reviewed by Greptile

Comment thread bin/fm-crew-state.sh Resolved
@mehulbhagwani
mehulbhagwani force-pushed the fm/fm-bug-quota-stall branch 2 times, most recently from 132c3fb to e206c6e Compare September 29, 2026 11:24
@mehulbhagwani mehulbhagwani changed the title fix(bin): classify agent-free quota-stalled workers as gone fix(bin): surface agent-free Pi workers instead of reporting stale working state Sep 29, 2026
@mehulbhagwani
mehulbhagwani force-pushed the fm/fm-bug-quota-stall branch from e206c6e to 51521cd Compare October 1, 2026 11:47
Comment thread bin/fm-crew-state.sh Resolved
@mehulbhagwani
mehulbhagwani force-pushed the fm/fm-bug-quota-stall branch from 51521cd to 26f878d Compare October 2, 2026 12:58
@mehulbhagwani mehulbhagwani changed the title fix(bin): surface agent-free Pi workers instead of reporting stale working state fix(bin): report quota-stalled workers as agent gone in crew-state Oct 2, 2026
@mehulbhagwani

Copy link
Copy Markdown
Contributor Author

The one red job here (Behavior portable serial 4) is tests/fm-remote-delta-read.test.sh, the timing-dependent test from #6363 tracked in #6404; this PR does not touch it. Could you re-run that failed job? I don't have rerun rights on this repo.

@mehulbhagwani

Copy link
Copy Markdown
Contributor Author

CI evidence on head 9e6091902ce17566f583c387c2aae610bcb5e7f1 (run https://github.com/kunchenguid/firstmate/actions/runs/38721174876): 17 checks passed, including Require no-mistakes. The only non-success was Behavior portable serial 2, which was cancelled at the job time limit with no test failure reported (same ~30m cancel pattern seen on other concurrent fork PRs under the runner backlog). Could you re-run just that one job? I do not have re-run rights on this repo.

@mehulbhagwani mehulbhagwani changed the title fix(bin): report quota-stalled workers as agent gone in crew-state fix(bin): report quota-stalled workers as agent gone Oct 23, 2026
@mehulbhagwani

Copy link
Copy Markdown
Contributor Author

Fresh exact-head Herdr/Pi proof

At exact PR head 85610d785a6bae8a68d67420098b3732b08d2384, I ran the real Pi 1.3.0 plus Herdr 0.9.4 private-lab proof:

  • bash tests/fm-backend-herdr-agent-exit-shell-e2e.test.sh passed the readable-shell exit cases and preserved a live idle Pi sibling.
  • bash tests/fm-herdr-pi-stale-registration-live-e2e.test.sh passed the real /quit stale-registration recovery, classifying the surviving shell as dead rather than a live agent.
  • bash tests/fm-crew-state.test.sh passed.

The disposable named Herdr lab cleaned up successfully, and the default Herdr session plus fm-remote survived the tripwire check. No source, PR head, shared fleet state, Rex installation, or provider configuration changed.

Rex is unavailable on this machine, so the Rex case remains explicitly untested. This proof covers the requested Pi readable-shell and stale-agent path; it does not claim provider quota exhaustion.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @mehulbhagwani, and thanks for the fresh Pi + Herdr proof at the exact head.

I read the whole thread and the diff of head 85610d78 against main. The real change is three files: crew_agent_gone in bin/fm-crew-state.sh, a short note in docs/architecture.md, and two regression tests. It's narrow. A readable endpoint that only holds its shell now reads agent gone before a stale busy record or status log can report working. A valid terminal done/failed line still wins. Tmux confirms its foreground command is a shell before it trusts dead/missing, so a flaky process read can't turn a live agent into a dead one.

Contract-class: restore. The documented crew-state default already says a dead endpoint "stays unknown instead of trusting a stale log". A harness that exited and left its shell behind was slipping past that. Nothing new is on by default.

VISION: one captain aligns (no false "working" hiding a stalled worker) · authority aligns (read-only, no recovery action) · scripts/judgment aligns (deterministic classifier) · restart aligns (reconciles from live session state) · delegation aligns · vendor aligns (tmux/Herdr/Rex each use their own classifier) · scope aligns.

Where it stands:

  • The no-mistakes attestation matches 85610d78.
  • CI: everything passed except Behavior portable serial 1, which was cancelled at the 30-minute ceiling with no test failure (fix(pi): keep the Pi watcher armed after a successor or arm child dies #7255). I re-ran that job (run 39941467685).
  • Live evidence: your Herdr/Pi run covers the readable-shell exit and the stale-registration recovery. Tmux is the default backend, though, and its new current-command gate has only fake-tmux coverage so far.

One small ask (waiting on you): could you do one quick live check on tmux at this head and post the output here? Start a Pi (or any harness) worker on tmux, exit the harness so the pane drops to its shell, and show bin/fm-crew-state.sh <id> reading agent gone. Also show that a live sibling still reads working. Re-raising through git push no-mistakes with that scenario driven live works just as well. Rex can stay explicitly untested. Once that's posted and CI is green, I can merge this.

@mehulbhagwani mehulbhagwani changed the title fix(bin): report quota-stalled workers as agent gone fix(bin): report quota-stalled workers as agent gone in crew-state Oct 27, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @mehulbhagwani for the re-raise and for driving the tmux case.

Delta since my 2026-10-23 stamp (85610d78): the branch now sits on current main 7da4c362 (0 behind, MERGEABLE). The real diff is still three files: bin/fm-crew-state.sh, docs/architecture.md and tests/fm-crew-state.test.sh. The crew_agent_gone logic is byte-identical to the head I reviewed. The new commits drop a stray copy of the test suite, revert an attempted done/failed reorder, and add a one-line Rex mention to the docs. There are no workflow, credential or network changes.

Live evidence: the PR body now has a real disposable tmux run in which the harness exits and leaves its shell, and bin/fm-crew-state.sh reads unknown · none · backend target gone … (agent gone, pane shell remains). With the Herdr exited-worker/live-sibling proof, that covers the default tmux path I asked about. Rex stays explicitly untested, which is fine.

Gates on head 97a70bb3:

  • No-mistakes: the attestation binds this head, and the check is green.
  • CI (run 40482307580): 18/19 passed. Behavior portable serial 1 was cancelled at the 30-minute ceiling with no test failure. That's the same serial-1 problem main has right now, and it isn't from your change. I re-ran that job.

Contract-class: restore (unchanged). VISION verdicts are as in my 2026-10-23 comment: it aligns on all rules.

Nothing more is needed from you. When serial 1 is green on this head, this can auto-merge on a later pass.

@mehulbhagwani mehulbhagwani changed the title fix(bin): report quota-stalled workers as agent gone in crew-state fix(bin): report exited quota-stalled workers as agent gone Nov 13, 2026
@mehulbhagwani mehulbhagwani changed the title fix(bin): report exited quota-stalled workers as agent gone fix: prevent stale crew state after harness exit Nov 27, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @mehulbhagwani for keeping this current. Head f648e259 merges main (clean against current main b119e422) and adds the explicit dead-secondmate outcome guard and the fallback documentation. Diff review (stands in for Greptile while it's out): safe, no P1. The change in bin/fm-crew-state.sh is gated on KIND != secondmate, on tmux's foreground command being a shell, and on the backend's own dead/missing verdict, so every ambiguous result keeps the existing fallback, and a valid done:/failed: declaration is preserved. I read the old Greptile P1 (dead secondmate shown as finished) against the code and your reply: it is already covered by the secondmate exclusion and by test_..._secondmate endpoint loss outranks done and failed, so I don't count it as blocking. P2, no action needed: a pane that still shows only its shell during the brief window before a freshly launched harness starts would read unknown, never working.

Waiting on you for one thing: the no-mistakes attestation on this head has intent: skipped. Every step has to complete on the head we'd merge, so please re-raise once through git push no-mistakes. No code change is needed. Live validation is inconclusive (2 of 4: the Rex scenarios were untested), and the earlier Herdr + Pi proof you posted covers that gap for tmux and Herdr. The Closes #5946 line is also gone from the body; please put it back if this is meant to close that issue.

Contract class: restore (a dead harness with a stale busy record or working: line no longer reads as working). After the clean re-raise and a green full suite, it merges as a restore.

mehulbhagwani and others added 25 commits November 27, 2026 09:05
A shell-only pane with no attributed run was reporting unknown on the
dead-endpoint path before a valid ship/scout done: or failed: status could
be preserved. Check the status log first on every death-class verdict.
This reverts commit 51521cd526d6cd38a27d64da0178dee38b476a86.
A documentation pass committed a full duplicate of tests/fm-crew-state.test.sh
as tests/crewstate_targeted_run.sh; it is not a test entry point and only
duplicates the real suite.
A shell-only pane with no attributed run was reporting unknown on the
dead-endpoint path before a valid ship/scout done: or failed: status could
be preserved. Check the status log first on every death-class verdict.
This reverts commit 51521cd526d6cd38a27d64da0178dee38b476a86.
A documentation pass committed a full duplicate of tests/fm-crew-state.test.sh
as tests/crewstate_targeted_run.sh; it is not a test entry point and only
duplicates the real suite.
A shell-only pane with no attributed run was reporting unknown on the
dead-endpoint path before a valid ship/scout done: or failed: status could
be preserved. Check the status log first on every death-class verdict.
This reverts commit 51521cd526d6cd38a27d64da0178dee38b476a86.
A documentation pass committed a full duplicate of tests/fm-crew-state.test.sh
as tests/crewstate_targeted_run.sh; it is not a test entry point and only
duplicates the real suite.
A shell-only pane with no attributed run was reporting unknown on the
dead-endpoint path before a valid ship/scout done: or failed: status could
be preserved. Check the status log first on every death-class verdict.
This reverts commit 51521cd526d6cd38a27d64da0178dee38b476a86.
A documentation pass committed a full duplicate of tests/fm-crew-state.test.sh
as tests/crewstate_targeted_run.sh; it is not a test entry point and only
duplicates the real suite.
…secondmates ending in done/failed. The faulty production override was already reverted. Regression fails on historical code and passes now. Crew-state suite, ShellCheck, and real-tmux verification passed. The suite emitted one nonfatal missing-basename fixture warning
@mehulbhagwani mehulbhagwani changed the title fix: prevent stale crew state after harness exit fix(bin): report exited quota-stalled workers as agent gone Nov 27, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @mehulbhagwani for the re-raise. Head dbe5923e binds with no skipped steps now (including intent), Closes #5946 is back in the body, and it merges cleanly onto main aa6c1235.

Diff review of the current net diff (stands in for Greptile while it's out): safe, no P1, unchanged in substance from the head I reviewed last pass. crew_agent_gone in bin/fm-crew-state.sh runs only for non-secondmates, on tmux only after the foreground command is confirmed to be a shell, and only on the backend's own dead/missing verdict; every ambiguous result keeps the old fallback, and a valid terminal done:/failed: declaration is preserved. The old Greptile P1 about a dead secondmate is covered by the KIND != secondmate guard and its test. One thing in the docs: the long fallback-order sentence in docs/architecture.md is replaced by a pointer to the fm-crew-state.sh header; I read that header and it carries the order.

Still open, not on you: live validation is inconclusive (2 of 3 driven; the Rex path was untestable because Rex is not available to you), and the old Greptile thread is outdated but not marked resolved. You are welcome to resolve it. The Rex behavior is covered by the fake-backend tests. I'll take this to the full suite next pass if the live gate allows it; otherwise I'll ask Kun whether the Rex fake-backend coverage is enough.

Contract class: restore. VISION, rule by rule: One captain: aligns · Authority: aligns (it reports a state, takes no action) · Scripts: aligns (exact backend verdicts) · Restart: aligns (durable status log) · Delegation: aligns ("supervised, not trusted": a dead worker is not read as working) · Vendor: aligns (only backend-owned classifiers) · Scope: aligns.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @mehulbhagwani. Both old Greptile threads are now resolved, and head dbe5923e is unchanged (attestation binds it with no skipped steps, quick checks pass, merges cleanly onto main 326ba38e).

Live gate, decided: live validation is inconclusive (2 of 3) only because Rex isn't available to you. The tmux path is driven live, your earlier Herdr + Pi proof covers Herdr, and the fake-backend tests cover the Rex verdict. I'm accepting that as the live evidence for this restore rather than asking Kun.

Diff review: safe, no P1 (unchanged from my last note). Contract class: restore.

Next: this pass is at its cap on new full-ci labels, so the full suite runs next pass, and as a restore it merges after a green run. Nothing is needed from you.

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.

fix(bin): do not read agent-free Pi panes as working after quota errors

2 participants