Skip to content

fix(omp): retire dead and duplicate replacement-handoff wakes - #24

Merged
Boxyboxy merged 5 commits into
feat/omp-adaptorfrom
fm/fm-omp-handoff-replays-dead-wakes
Sep 25, 2026
Merged

Boxyboxy merged 5 commits into
feat/omp-adaptorfrom
fm/fm-omp-handoff-replays-dead-wakes

Conversation

@Boxyboxy

Copy link
Copy Markdown
Owner

Problem

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.

Measured on the primary home: a store of 100 records, 94 of them the identical signal: <state>/converge-emails-495.turn-ended for a task torn down nine days earlier. All 100 were undelivered, with 100 distinct tokens and 100 distinct predecessorArmPid values 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, and enqueuePendingActionable deduplicated on token alone - 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:

  • Liveness. A signal: reason names <state>/<id>.status and <state>/<id>.turn-ended files (bin/fm-watch.sh's scan_signals), and state/<id>.meta is that task's record: bin/fm-spawn.sh publishes it before the worker can write any signal file, and bin/fm-teardown.sh removes 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.
  • 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 - it is about to be retired by consumption, so a later identical close is a new wake.
  • Bound. At most FM_OMP_HANDOFF_MAX_RECORDS (32) records, none older than FM_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 processPendingActionables when 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:

before after
records at load 78 retained store removed
phantom follow-ups to main replaying 0
records carried past shutdown 78 0

Red-then-green: the liveness test failed at kept 98 and the duplicate test at kept 100 on 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.sh 18/18, bin/fm-lint.sh, bin/fm-doc-audience-check.sh, and a strict tsc --noEmit pass on the extension all clean.

Notes

  • Rebase was skipped: this branch is based on feat/omp-adaptor, and the pipeline's rebase step targets origin/main.
  • .pi/extensions/fm-primary-pi-watch.ts carries 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.

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.
@Boxyboxy
Boxyboxy merged commit 3370609 into feat/omp-adaptor 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
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.

2 participants