Repository navigation
fix(omp): retire dead and duplicate replacement-handoff wakes - #24
Merged
Merged
Conversation
The omp watch extension replayed every stored actionable wake at session_start and re-persisted whatever was still pending at session_shutdown, with no rule for retiring a record. Because each arm close minted a fresh token for the same unread reason and the queue deduplicated on token alone, one undelivered wake grew a copy per close and survived every restart: a measured store held 100 records, 94 of them the identical turn-end signal for a task torn down nine days earlier, costing the session one model turn and one arm restart each. Bound the store with three rules, applied wherever it is read or written and to the in-memory queue as well: - Liveness. A "signal:" reason names <state>/<id>.status and <state>/<id>.turn-ended files, and state/<id>.meta is that task's record, published by fm-spawn.sh before the worker can write any signal file and removed by fm-teardown.sh with the backlog transition. A record whose every named task has lost its meta is dropped rather than replayed; one naming a live task among torn-down ones stays, and a reason naming no task at all is never dropped. - Identity. Undelivered records collapse by message, keeping the earliest, so one unread reason is one queued turn however often it re-fires. A delivered record is never collapsed into. - Bound. At most 32 records, none older than 24 hours, oldest first. A load that drops records rewrites the store immediately, so a session that never reaches shutdown cannot hand them on. Delivery continuity is unchanged: a live task's undelivered wake is still loaded, delivered, carried across a session replacement, and replayed, which tests/fm-omp-harness.test.sh now pins alongside the three retention rules.
withkrew
approved these changes
Sep 25, 2026
This was referenced Sep 25, 2026
Boxyboxy
added a commit
that referenced
this pull request
Sep 27, 2026
* fix(pi): retire dead and duplicate replacement-handoff wakes The Pi watch extension replayed every stored actionable wake at session_start and re-persisted whatever was still pending at session_shutdown, with no rule for retiring a record. Because each arm close minted a fresh token for the same unread reason and the queue deduplicated on token alone, one undelivered wake grew a copy per close and survived every restart. Replaying the captain's preserved 78-record store through this extension delivered 78 follow-ups, 75 of them for a task torn down nine days earlier, costing the session one model turn and one arm restart each. This is the same defect fixed for the omp fork in #24, and it is bounded the same way, by three rules applied wherever the store is read or written and to the in-memory queue as well: - Liveness. A "signal:" reason names <state>/<id>.status and <state>/<id>.turn-ended files, and state/<id>.meta is that task's record, published by fm-spawn.sh before the worker can write any signal file and removed by fm-teardown.sh with the backlog transition. A record whose every named task has lost its meta is dropped rather than replayed; one naming a live task among torn-down ones stays, and a reason naming no task at all is never dropped. - Identity. Undelivered records collapse by message, keeping the earliest, so one unread reason is one queued turn however often it re-fires. A delivered record is never collapsed into. - Bound. At most 32 records, none older than 24 hours, oldest first. A load that drops records rewrites the store immediately, so a session that never reaches shutdown cannot hand them on. An arm close whose wake is retired no longer waits for a delivery that will never run: it starts its own successor, or defers that re-arm when a restoration is already delivering, so retiring a record never leaves supervision dark. Retention is orthogonal to Pi's supervision branch. It runs at enqueue and at every store read and write, strictly before delivery chooses between the branch and main, so a collapsed duplicate is one branch offer rather than none, and a wake naming only torn-down tasks is offered to neither. lib/fm-branch-dispatch.ts already reads state/<id>.meta as the task record, so the liveness rule rests on the same fact the branch routing does. Delivery continuity is unchanged: a live task's undelivered wake is still loaded, delivered, carried across a session replacement, and replayed, which tests/fm-pi-watch-extension.test.sh now pins alongside the three retention rules and the arm-close continuity cases. * no-mistakes(review): Document Pi handoff retention knobs and bounded replay * no-mistakes(document): Drop stale omp note that retention diverges from Pi
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.
Problem
The omp watch extension replayed every stored actionable wake at
session_startand re-persisted whatever was still pending atsession_shutdown, with no rule for retiring a record.Measured on the primary home: a store of 100 records, 94 of them the identical
signal: <state>/converge-emails-495.turn-endedfor a task torn down nine days earlier. All 100 were undelivered, with 100 distinct tokens and 100 distinctpredecessorArmPidvalues across only 6 distinct messages. A sibling backup from the previous incident held 111 records, 102 of them the same phantom, so a one-off cleanup did not hold.Cause: every arm close mints a fresh
<pid>-<ts>-<seq>token for the same unread reason, andenqueuePendingActionablededuplicated ontokenalone - a field guaranteed unique per close. Nothing retired a record whose task was gone, and shutdown re-persisted the lot. Each record costs the session one model turn plus one arm restart to drain.Change
Three retention rules in one owner,
retainedHandoffRecords, applied at load, at every write, and on the in-memory queue:signal:reason names<state>/<id>.statusand<state>/<id>.turn-endedfiles (bin/fm-watch.sh'sscan_signals), andstate/<id>.metais that task's record:bin/fm-spawn.shpublishes it before the worker can write any signal file, andbin/fm-teardown.shremoves it with the backlog transition. A record whose every named task has lost its meta is dropped rather than replayed; one naming a live task among torn-down ones stays; a reason naming no task at all (stale:,check:,heartbeat) is unjudgeable and never dropped. Paths outside this home's state directory are not judged.FM_OMP_HANDOFF_MAX_RECORDS(32) records, none older thanFM_OMP_HANDOFF_MAX_AGE_MS(24h), oldest dropped first.A load that drops records rewrites the store immediately, so a session that never reaches shutdown cannot hand them on.
Because a filtered close no longer produces a record to deliver, the close handler now owns continuity explicitly: it defers the re-arm while a restoration is running, drives
processPendingActionableswhen the close left a wake still awaiting delivery, and otherwise starts a successor arm directly. Without this the watcher would have gone dark on exactly the closes this change filters.Evidence
Against the preserved 78-record live store, transplanted into a scratch home with the real extension:
Red-then-green: the liveness test failed at
kept 98and the duplicate test atkept 100on the unfixed tree. The continuity guard - a live task's undelivered wake delivered, persisted at shutdown, replayed on replacement, retired on consumption - was green before and after, which is the safety property proven rather than argued.tests/fm-omp-harness.test.sh18/18,bin/fm-lint.sh,bin/fm-doc-audience-check.sh, and a stricttsc --noEmitpass on the extension all clean.Notes
feat/omp-adaptor, and the pipeline's rebase step targetsorigin/main..pi/extensions/fm-primary-pi-watch.tscarries the identical defect (same store, same token-only dedup, same shutdown re-persist). Left out of scope - its delivery path differs through the supervision-branch offers, so the fix is not a safe blind port. Worth a follow-up.