Repository navigation
feat(brief): have no-mistakes workers start validation themselves - #1
Merged
Merged
Conversation
* feat(bin): add deterministic agent lifecycle control Separate firstmate's data plane from its control plane. bin/fm-send.sh is the data plane: conversational text, always routing-marked for a kind=secondmate target. That marking is right for a message and wrong for a lifecycle command - a marked "/quit" arrives as ordinary chat the agent reasons about instead of executing. bin/fm-control.sh is the control plane: allowlisted interrupt, exit, and transactional relaunch verbs addressed to an exact task id, with per-harness mechanics owned by the executable bin/fm-control-lib.sh rather than improvised in agent prose, and a verified postcondition for every action. There is no arbitrary-text and no raw-key entry point. relaunch runs as a transaction with a durable journal: it resolves the profile, proves the work it must preserve is recoverable, records the required progress note, stops the old agent, then delegates the launch to its single owner, bin/fm-spawn.sh --relaunch, which adopts the recorded endpoint and worktree instead of creating either. A refusal before the stop leaves the record and instructions byte-identical; a failure after it reports the concrete state rather than claiming an agent that is not running. Teardown and discard stay separate and explicit. exit and relaunch require a backend with a recovery-grade agent-state classifier, so zellij, orca, and cmux are refused rather than reported as successful blind. A remotely placed secondmate is refused by name, because its agent runs on a host where none of these postconditions can be read. * fix(control): resolve a recorded harness to its adapter before retiring wiring fm-spawn arms per-task harness wiring on prefixes, because a task launched from a raw command records that command's basename rather than the exact adapter name. The control plane's retirement tables are keyed by the exact adapter, so a task recorded as `grok-2` had its turn-end token, private registry entry, and worktree hook pointer armed and never retired - leaving a registry entry that outlived the agent that owned it. State the prefix rule once, in the capability owner, and resolve the recorded value through it before every table lookup. bin/fm-send.sh's composer-clear lookup reads the same owner instead of keeping its own copy of which adapters need one. * test(control): pin muse session-binding retirement across a harness switch * no-mistakes(review): Resolve prefixed harnesses across lifecycle control verbs * no-mistakes(review): Report interrupt delivery without fabricating cancellation state * no-mistakes(review): Clear disabled relaunch trace context atomically * no-mistakes(review): Clarify control interrupts and restore legacy send state * no-mistakes(review): Refuse ambiguous relaunches and report exit delivery * no-mistakes(review): Revalidate interrupts and accept interrupt-stopped exits * no-mistakes(review): Lock descendant tasks before forced recursive teardown * no-mistakes(document): Align lifecycle adapter documentation with control plane * no-mistakes: apply CI fixes * fix(bin): serialize fresh task publication with forced teardown Forced secondmate teardown enumerated a home's task set, locked what it found, then re-enumerated while removing. A fresh spawn takes only its own per-task lock, so a record published inside that window was invisible to the preflight and visible to the cleanup: it was destructively processed while never lifecycle-locked. Reproduced with real agents. A record published 0.249s after teardown began was removed, its window closed, and its worktree returned to the pool - while both commands reported success. A per-task lock cannot protect a task that does not exist yet. Add a per-home task-set lock guarding WHICH tasks a home has, as opposed to the metadata lock guarding one task's record. Teardown takes it per home, parent before child, before enumerating and holds it through cleanup. A fresh spawn takes it before its own per-task locks and holds it through publication; a relaunch is exempt, because it republishes an existing task already covered by that task's control lock. Either the spawn publishes first and the teardown's preflight covers it, or the teardown owns the set and the spawn refuses. Both directions fail closed, and both are pinned by tests that hold the lock rather than racing on timing. * no-mistakes(review): Serialize remote secondmate publication with forced teardown * no-mistakes(review): Preserve remote spawn routing and state initialization * no-mistakes(review): Serialize teardown when descendant state is absent * no-mistakes(review): Cover symlinked descendant state refusal * no-mistakes(document): Document task-set serialization safeguards * no-mistakes(lint): Isolate task-set lock path resolution * no-mistakes: apply CI fixes
The generated no-mistakes definition of done told the worker to append
`done: {summary}` and stop, then wait for firstmate to type /no-mistakes.
That relay applied no judgement, so it only put firstmate's availability
between a finished commit and the pipeline that ships it. Finished work
has repeatedly idled at that gap for hours when the wake channel wedged.
The scaffold now tells the worker to invoke /no-mistakes immediately
after committing. The authority contract is unchanged: ask-user findings
are still never the worker's to answer, `--yes` stays forbidden, and the
worker still stops for firstmate's decision at every gate.
Checked before changing the wording that nothing depends on firstmate
seeing the commit first:
- `bin/fm-spawn.sh` reads the brief's `Delivery contract: mode=` line and
the registered posture only at launch, before the worker starts; no
spawn-side path observes the implementation commit.
- Nothing keys off a mid-flight `done:` line. `done:` is one of several
generic captain-relevant wake verbs in `bin/fm-classify-lib.sh`, and
the terminal `done: PR {url} checks green` report still carries it.
- `bin/fm-teardown.sh` gates on git state and `no-mistakes axi status`,
never on a status line.
- `bin/fm-crew-state.sh` reconciles validation from the run matched to
the current code, which works the same whoever started the run.
Removing the relay also removes a failure mode of its own: sending
`/no-mistakes` into a crew composer is the exact operation behind the
slash-autocomplete submission hazards documented in `harness-adapters`.
A worker loading its own skill bypasses that surface entirely.
`AGENTS.md` section 7 keeps sole ownership of the flow and now points at
`harness-adapters` for the restart case rather than the routine one.
`bin/fm-promote.sh`'s suggested ship instructions get the same rule,
since a promoted scout never receives the scaffolded definition of done.
tests/fm-brief.test.sh pins both halves of the new shape: the self-start
instruction is present, the stop-and-wait instruction is gone, the
escalation gates survive, and neither faster mode picks up a pipeline
instruction it must not have.
…ral, guard test legs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The defect
bin/fm-brief.sh's generated--mode no-mistakesDefinition of done told the worker to stop after its implementation commit and wait for firstmate to send the validation trigger:That step was a pure relay. Firstmate applied no judgement when sending it, so the only thing it added was a dependency on firstmate being awake and reachable, sitting between a finished commit and the pipeline that ships it.
Measured cost, 2026-08-09: two workers finished at 20:03 and 20:51 UTC and nothing moved until 04:22, because the channel that should have woken firstmate was wedged. Four workers in this project's history stopped at this same handoff, and every one was following its instructions correctly. This was not a comprehension problem to be solved with clearer wording.
The change
The scaffold now has the worker start the validation pipeline itself immediately after committing:
The authority contract is unchanged. Ask-user findings are still never the worker's to answer,
--yesis still forbidden, and the worker still stops and waits for firstmate's decision at every gate. Only the idle gap disappears.Three details are deliberate:
harness-adaptersrecords that codex rejects the leading-slash form and that opencode, pi and pi-signed have no verified skill-invocation form at all, so no parameterised form could be correct for them; the worker resolves its own. Worth noting for reviewers that the old wording hardcoded the same claude-only form but harmlessly, because it only described what firstmate would later send, and firstmate sends the harness-correct form. This change makes that sentence operative, which is exactly why it now has to be neutral. The hardcoding was not always broken.done:line", which scanned as a blanket ban while the same section still mandates the terminaldone: PR {url} checks green. A contract that appears to forbid what it elsewhere requires gets resolved by whichever sentence the worker read last. Reporting the commit stays allowed; waiting on it does not.bin/fm-promote.shgets the same rule. A promoted scout never receives the scaffolded Definition of done, so it would otherwise have been the one population still stalling at the removed handoff. Both its emitted hint and the header comment documenting it now put the validation action before the report, for the same reason: a reader who stops early must land on the right primary behaviour.Evidence that nothing depended on the pause
Established before changing any wording, since the handoff would have needed preserving with a stated reason if some path genuinely required firstmate to see the commit first:
bin/fm-spawn.shreads the brief'sDelivery contract: mode=line and the registered posture only at launch, before the worker starts. No spawn-side path observes the implementation commit.done:line. It is one of several generic captain-relevant wake verbs inbin/fm-classify-lib.sh, and the terminaldone: PR {url} checks greenreport still carries it.bin/fm-teardown.shgates on git state andno-mistakes axi status, never on a status line.bin/fm-crew-state.shreconciles validation from the run matched to the current code, which works identically whoever started the run.A completeness sweep across
bin/,.agents/skills/,AGENTS.md,CONTRIBUTING.md,README.mdanddocs/found no remaining place stating the old handoff and no path where the old ordering is correct.Removing the relay also removes a failure mode of its own. Sending the trigger into a crew composer is the exact operation behind the slash-autocomplete submission hazards documented in
harness-adapters, including the 2026-07-03 grok/herdr incident where two crewmates sat with the trigger typed but unsubmitted for minutes. A worker loading its own skill never touches that surface.One-owner rule
AGENTS.mdsection 7 remains the single full statement of the flow and now points atharness-adaptersfor the restart case rather than the routine one. The generated brief is the worker-facing instruction rather than a second copy.harness-adapters' own "no-mistakes skill invocation" section was left alone: it stays the sole owner of the per-harness form, still needed when firstmate must restart a worker that stopped without starting a run. The twofm-promote.shlines carry ordering only and do not restate the flow.Tests
tests/fm-brief.test.shgainstest_no_mistakes_dod_starts_validation_without_a_firstmate_handoff, which pins that the self-start instruction is present, the stop-and-wait instruction is gone, the harness-neutral clause survives, the narrowed prohibition does not read as a blanket ban, the ask-user and--yesgates and the terminal CI-green report are intact, and neither direct-PR nor local-only picks up a pipeline instruction. Both faster-mode legs are guarded so a failed scaffold cannot make a negative assertion pass vacuously.Validated through the no-mistakes pipeline (review, test, document, lint) with push/PR/CI skipped so delivery stays on this fork; two review fix rounds and one documentation correction are included as separate commits.
Is this worth offering upstream?
Honestly: not as-is, and not unsolicited.
The motivation is fleet-specific, but the defect is general - any firstmate deployment running no-mistakes crews has this idle gap, and the safety evidence above is not specific to this fleet. So the problem would likely be recognised upstream.
The change itself, though, is a design change to upstream's supervision contract rather than a bug fix. The pause may have been deliberate, giving firstmate a checkpoint to review the commit before validation starts and a last point to fold in a late requirement without invoking the "route new requirements to follow-up work" rule. I found no mechanism that depends on it, but absence of a mechanism is not evidence the pause was unintentional. An unsolicited design change to someone else's control flow is a much bigger ask than a defect fix, and it should be a conversation first.
Recommendation: if this proves out here, open it upstream as a discussion of the idle gap with the measured evidence, and let them decide whether self-start is the shape they want.
Base note
fork/mainis one commit behindorigin/main, so this PR's comparison includes the unrelated upstream commit2d2be63alongside the four commits of this change. Fast-forwarding the fork's default branch would have meant pushing to a default branch, which this task's instructions forbid, so it was left alone. The four commits authored by this change are the ones from2642ce3onward.