Repository navigation
fix: retry OMP main wakes that never enter a model turn - #337
Merged
Merged
Conversation
- A main-bound close consumed by before_agent_start but never entering its own model turn, followed by a non-terminal agent_end, leaves the episode open with no escape hatch and suppresses every later close. - The new test fails today at the forced-follow-up wait: the core logs suppressed behind=episode instead of forcing a turn past the bound.
A staged hidden next-turn send raises before_agent_start immediately, which the core recorded as consumption and used to clear the in-flight marker. When no message_start for the wake and no terminal agent_end followed, the episode stayed open with every escape hatch disarmed and suppressed all 34 later main-bound closes for 90 minutes on 27 Nov. - Record the last tracked main hand-off time and the last observed model entry (the wake's own custom message_start) per generation. - Add a fourth deliverMainWake bypass: an open episode whose hand-off is older than FM_WATCH_MAIN_WAKE_INFLIGHT_BOUND_MS with no entered-turn evidence forces the existing followUp+triggerTurn send, one per interval like the in-flight bound. - Ledger the retirement as consumed by=unentered-bound with the stranded close. The ordinary send shape is unchanged (deliverAs nextTurn).
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.
Summary
The OMP primary watch core suppressed every main-bound close behind an open episode whose one hand-off had been recorded as consumed at
before_agent_startbut never entered a model turn. On 27 Nov 2026 that held 34 close notifications for 90 minutes. This adds a fourth bypass keyed on model entry instead of consumption.mainFallbackHandOff: SentWake { wakeId, close, sentAtMs, consumed, enteredAtMs } notifyWake(tracked) -> handOff = sent; enteredAtMs = null wakeEnteredTurn(id) -> enteredAtMs = now // only when id === handOff.wakeId deliverMainWake staleInFlight // accepted, unconsumed past bound decisionBypass // needs-decision wake idleEpisode // terminal agent_end, no turn since + unenteredBound // consumed, never entered, past bound -> sendWake(followUp, triggerTurn: true) -> ledger: consumed by=unentered-bound (original wake id and close)FM_WATCH_MAIN_WAKE_INFLIGHT_BOUND_MS(default 120000) paces both wall-clock retries, driven by the next main-bound close, never a timer. The ordinary send shape is unchanged:deliverAs: "nextTurn".The CI step also repaired two unrelated test fixtures that flaked under the 9-way serial shard load (details under Evidence). Both repairs are test-only:
tests/fm-remote-secondmate-lifecycle-e2e.test.shandtests/fm-pi-watch-extension.test.sh.Evidence
AC1 - regression fails at base, passes at target (
test_native_omp_unentered_handoff_forces_turn_after_bound): a check close is sent while main streams,before_agent_startconsumes it 2 ms later, itsmessage_startnever fires, only a non-terminalagent_endfollows, then a later close arrives past the bound.Commands:
env -u FM_TASK_ID bash tests/fm-omp-primary.test.shwith the test file at the PR head (the env var is unset only because this worker runs inside an fm-spawn task session). Logs:data/fm-primary-wake-stall-fix/artifacts/{prefix-test-failure,postfix-test-pass}.log.AC2 - one forced send per interval, entry keeps suppression, ledger names the bypass. The same test asserts the forced
followUp+triggerTurnsend, that a close landing inside the renewed bound is suppressedbehind=episode(not by the old in-flight guard), that a latemessage_startfrom the older delivery does not credit the newer hand-off, and that after the latest hand-off enters its own turn the next close staysbehind=episode. Ledger rows assert the originalwake=andclose=tokens with no extra fields:AC3 - knock-rate replay of the live ledger (read-only,
state/extensions/omp-primary-watch/main-wake-deliveries.log; bound 120000 ms, no live override in.envorconfig/):So 2 of 3 forced sends would have landed on a legitimate busy wait (a knock: an extra turn-forcing follow-up while main was already streaming) and 1 would have caught the actual stall at 06:40, two minutes after the stranded hand-off, instead of 90. The estimate is bounded, not certain: a model message inside the bound interval is evidence of an active run, not proof that the staged wake would have entered it. Replay scripts:
data/fm-primary-wake-stall-fix/artifacts/knock-rate-replay.pyandbusy-wait-evidence.py.AC4 - send shape and existing tests.
deliverMainWakestill callssendWakewith the caller'sforceTurn; only the new bypass sets it for ordinary closes.bash tests/fm-omp-primary.test.shon the PR head: all native tests pass, exit 0 (the optional SDK silent-wake check skips withoutFM_OMP_PACKAGE_DIR). CI on headdcd76055: 20 of 20 checks pass.bin/fm-lint.shandbin/fm-doc-audience-check.shpass.CI flake repairs, both confirmed by a local green run at the repaired head before CI confirmed them:
tests/fm-remote-secondmate-lifecycle-e2e.test.sh: the fake SSH incremented a sharedssh.countfile withcatplusprintf, so two concurrent calls produced1\n1and a bash arithmetic error that contaminated an otherwise validaliveresponse. It now appends to an ambiguous-attempt log and asserts exactly one attempt throughwc -l. Full file: exit 0 locally, 700 s.tests/fm-pi-watch-extension.test.sh: two OpenCode fixture arms raced the 250 ms ready timer before their TERM trap was installed, so the retirement signal could kill the fixture and leave noretiredmarker. They now print an explicit failure line after installing the trap. The ready-timeout path still runs intest_opencode_hung_successor_falls_back_to_typed_wake. Full file: exit 0 locally, 22 s.Review findings
Pipeline review round 1 raised six findings; firstmate directed a fix round and approved the result. Disposition at head
dcd76055:latest-handoff-entry-identity(error)SentWake.enteredAtMs(bin/fm-primary-watch-core.ts:124), only set when the delivery id matches the tracked hand-off (:1832), and the bound reads it off that record (:1063); the test exercises a late entry by the older wakeretirement-ledger-close-correlationwakeandclose, with nostranded_close/reason(bin/fm-primary-watch-core.ts:1141)premature-bound-resetnotifyWakesets the hand-off at the accepted attempt (bin/fm-primary-watch-core.ts:878)unrequired-episode-mirror-fieldspersistEpisodeState; the guide no longer claims themunrequired-successor-ledger-doc-changenextis removed from the mid-turn ledger examplerenewed-bound-regression-coverage(auto-fix)behind=episodeinside the renewed boundRemaining, accepted by firstmate on 27 Nov 2026 as bounded costs rather than stalls:
rejected-send-masks-accepted-entry: a rejected send leaves a never-delivered wake in the hand-off slot, so a late cleanup retry can force one extra turn and skip a retirement line.same-millisecond-turn-masks-expired-inflight: aturn_startin the exact millisecond of a send counts as post-send evidence, so the in-flight marker can outlive its bound and the new bypass stays excluded while it is set.Merge Danger
Door: two-way. Reverting restores the previous suppression behavior; no data or queue format changes.
Blast Radius: one. Only the OMP primary watcher's main-fallback delivery changes, and only after a new session loads the extension. Worst case is an extra turn-forcing follow-up per two minutes while a hand-off is stranded; durable queue rows are untouched, and waiting/fleet work in this home is unaffected until the next session start.
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-primary-watch-core.ts:1859- AC2 requires the bound to use entry evidence for the "last hand-off." Line 1859 instead stamps every watcher message_start before resolving its delivery ID. If OMP stages wake A, the bound forces wake B, and A enters late after B is sent, A's entry satisfies B's timestamp check. Once turn_start clears B's in-flight marker, B can fail to enter and the next close past B's bound is still suppressed behind the episode. This is reachable when staged wakes overlap during a long OMP run. Bind entry and retirement to the tracked delivery ID at bin/fm-primary-watch-core.ts:930–931 (send reset), :1083–1086 (entry predicate), and :1092 (retirement lookup). Exercise the late older entry with real delivery metadata at tests/fm-omp-primary.test.sh:2880–2884 and :2937. The current behavior also contradicts the guide's own-message guarantee at docs/omp-supervision-branch.md:79 and :130–131.bin/fm-primary-watch-core.ts:1097- Every model-entry bypass writes the retired wake's ID and elapsed time alongside the newer triggering close's token and reason. An operator following the documented lookup by close at docs/omp-supervision-branch.md:85 and :89 sees a consumption event for the triggering close before its send. The intent only requires recording the stranded hand-off's retirement. Use its original token in the existing close field and remove the added stranded_close and triggering reason fields at bin/fm-primary-watch-core.ts:1098 and :1101, along with their inputs at :1140. The assertion at tests/fm-omp-primary.test.sh:2921 checks the label without checking this correlation.bin/fm-primary-watch-core.ts:1093- The retirement helper advances the hand-off clock before the replacement is sent, even though sendWake establishes that clock at bin/fm-primary-watch-core.ts:930–931. If a staged watcher failure notice opened the episode without a readable queue baseline, a later close can reach retirement and then return at :1164–1168 without sending anything. That close spends another bound interval despite no new hand-off. The intent requires pacing actual send attempts. Remove the extra clock reset from retirement and let sendWake establish the next interval.bin/fm-primary-watch-core.ts:662- The new episode-mirror timestamps add a diagnostic representation beyond the required retirement ledger. On an ordinary wake entry, the adapter acknowledges first and bin/fm-primary-watch-core.ts:1859 updates the entry timestamp afterward without persisting it. An operator reading the mirror during that model call can therefore see zero until the next boundary. Remove both added mirror fields at :662–663 and the corresponding claim at docs/omp-supervision-branch.md:81. The existing sent and turn ledger events already carry the timing.tests/fm-omp-primary.test.sh:2925- The within-interval assertion leaves the forced hand-off in flight, so the old in-flight guard suppresses the third close even if someone deletes the new age comparison at bin/fm-primary-watch-core.ts:1082. This gap occurs on every run of the fixture and leaves AC2's pacing guarantee unproved for the incident path. Stage and consume the forced hand-off without entering it, then assert that the identified third close is suppressed behind the episode before the renewed deadline. The verification claim at docs/verification/runtime-backends.md:817 should match that observable contract.docs/verification/runtime-backends.md:805- The addednextin the unrelated mid-turn ledger example makes the documented event sequence wrong for every successor trace. The existing executable oracle at tests/fm-omp-primary.test.sh:3737 expectsgranted,sent:successor. No wake-stall requirement needs this change. Remove the added word so operators can match the example to the ledger.🔧 Fix applied.
6 issues (1 error, 5 warnings) still open:
bin/fm-primary-watch-core.ts:1859- AC2 requires the bound to use entry evidence for the "last hand-off." Line 1859 instead stamps every watcher message_start before resolving its delivery ID. If OMP stages wake A, the bound forces wake B, and A enters late after B is sent, A's entry satisfies B's timestamp check. Once turn_start clears B's in-flight marker, B can fail to enter and the next close past B's bound is still suppressed behind the episode. This is reachable when staged wakes overlap during a long OMP run. Bind entry and retirement to the tracked delivery ID at bin/fm-primary-watch-core.ts:930–931 (send reset), :1083–1086 (entry predicate), and :1092 (retirement lookup). Exercise the late older entry with real delivery metadata at tests/fm-omp-primary.test.sh:2880–2884 and :2937. The current behavior also contradicts the guide's own-message guarantee at docs/omp-supervision-branch.md:79 and :130–131.bin/fm-primary-watch-core.ts:1097- Every model-entry bypass writes the retired wake's ID and elapsed time alongside the newer triggering close's token and reason. An operator following the documented lookup by close at docs/omp-supervision-branch.md:85 and :89 sees a consumption event for the triggering close before its send. The intent only requires recording the stranded hand-off's retirement. Use its original token in the existing close field and remove the added stranded_close and triggering reason fields at bin/fm-primary-watch-core.ts:1098 and :1101, along with their inputs at :1140. The assertion at tests/fm-omp-primary.test.sh:2921 checks the label without checking this correlation.bin/fm-primary-watch-core.ts:1093- The retirement helper advances the hand-off clock before the replacement is sent, even though sendWake establishes that clock at bin/fm-primary-watch-core.ts:930–931. If a staged watcher failure notice opened the episode without a readable queue baseline, a later close can reach retirement and then return at :1164–1168 without sending anything. That close spends another bound interval despite no new hand-off. The intent requires pacing actual send attempts. Remove the extra clock reset from retirement and let sendWake establish the next interval.bin/fm-primary-watch-core.ts:662- The new episode-mirror timestamps add a diagnostic representation beyond the required retirement ledger. On an ordinary wake entry, the adapter acknowledges first and bin/fm-primary-watch-core.ts:1859 updates the entry timestamp afterward without persisting it. An operator reading the mirror during that model call can therefore see zero until the next boundary. Remove both added mirror fields at :662–663 and the corresponding claim at docs/omp-supervision-branch.md:81. The existing sent and turn ledger events already carry the timing.bin/fm-primary-watch-core.ts:881- AC2 says, “A hand-off that did enter a turn keeps today's suppression.” Round 1 assigns the new hand-off before OMP accepts it at bin/fm-primary-watch-core.ts:880–882, but the rejection paths at :889–894 and :936–943 leave that rejected delivery in the hand-off slot. If OMP rejects a decision-owned send while an earlier wake is in its handling turn, and the existing cleanup retry at :1234–1239 runs after the configured bound, :1073–1077 and :1105–1106 force the retry based on a delivery that never happened. The ledger also omits the required retirement at :1152–1156 because that rejected delivery was never consumed. This requires a send rejection and a retry or later close that reaches the bound before another send is accepted. Remove rejected sends from model-entry eligibility at the shared send boundary, preserving the previous accepted delivery and the pacing of actual attempts. The accepted-send fixture at tests/fm-omp-primary.test.sh:2858–2861 cannot catch this path.bin/fm-primary-watch-core.ts:1075- AC2 requires an expired open episode whose last hand-off “has no entered-turn evidence” to force a send. Round 1 left a sibling gap at bin/fm-primary-watch-core.ts:1075, which excludes every in-flight hand-off. If OMP starts a model call just before the watcher sends, both events can receive the same millisecond timestamp at :878 and :1925. If OMP queues that wake without emitting another consumption or turn event, :1059 treats the earlier call as post-send evidence indefinitely, :1075 prevents the new bypass, and every later ordinary close takes the suppression branch at :1114–1122. This is rare and requires a same-millisecond send during a run that leaves the marker outstanding. At the shared bound check, keep unrelated turn timing from exempting an outstanding delivery without entry evidence, and keep the ledger reason tied to the actual retirement path. The guarantee at docs/omp-supervision-branch.md:130–131 and the fixture at tests/fm-omp-primary.test.sh:2920–2930 cover the consumed case only.✅ **Test** - passed
✅ No issues found.
test_native_omp_unentered_handoff_forces_turn_after_boundagainst separately exported base 078d185d and target 62655fb5, with the generated ledger captured for eachbash tests/fm-omp-primary.test.shin an isolated home, exit 0. The optional SDK silent-wake check skipped because FM_OMP_PACKAGE_DIR was unset.omp --mode rpc --no-uion both revisions with a disposable Firstmate home, a loopback streaming provider, and a watcher check registered viabin/fm-check-register.sh wake-probe. Captured native send options, lifecycle events, the delivery ledger, and the durable queue. Both OMP processes exited 0.✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.