Repository navigation
fix(pi): retire dead and duplicate replacement-handoff wakes - #26
Merged
Merged
Conversation
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.
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.
Closes the dead-task notification replay defect in the Pi watcher extension, the same one fixed for the omp fork in #24.
The defect
.pi/extensions/fm-primary-pi-watch.tsreplayed every stored actionable wake atsession_startand re-persisted whatever was still pending atsession_shutdown, with no rule for retiring a record.A record only cleared once it was handled against a live task, and a task that no longer exists can never clear one.
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.
Measurement
The captain's preserved live store, 78 records, was transplanted unaltered into an isolated temporary home and replayed through both the pre-fix and post-fix extension on the identical harness.
The fix
Three rules bound the store, applied wherever it is read or written and to the in-memory queue as well:
signal:reason names<state>/<id>.statusand<state>/<id>.turn-endedfiles, andstate/<id>.metais that task's record, published byfm-spawn.shbefore the worker can write any signal file and removed byfm-teardown.shwith 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.
A delivered record is never collapsed into.
FM_PI_HANDOFF_MAX_RECORDSrecords (32), none older thanFM_PI_HANDOFF_MAX_AGE_MS(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.
Divergence from the omp port
The two extensions are not identical, and the differences were established before porting rather than assumed.
Retention is orthogonal to it: retention 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.
A branch-handled wake already clears immediately, so nothing lingers there.
lib/fm-branch-dispatch.tsalready readsstate/<id>.metaas the task record, so the liveness rule rests on the same fact Pi's own branch routing does.node:fsimport lackedexistsSync, which the liveness check needs.validatePendingActionablegates onactionableLine, while omp additionally acceptssupervision-host:messages.The omp header's note that handoff retention diverges from the Pi port became false with this change and is removed; that is the only edit to the omp extension and it is comment-only.
Tests
tests/fm-pi-watch-extension.test.shgains six cases covering the three retention rules, the delivery continuity the fix must not break, and the arm-close continuity cases:state/<id>.metais dropped at load and never delivered.Four of the six fail against the pre-fix extension.
The restoration case was separately confirmed to pin the new deferred re-arm: removing that branch from the fixed code leaves the watcher dark.
The continuity case passes before and after by design, as the guard that retention never drops a live undelivered record.
Validation
tests/fm-pi-watch-extension.test.sh: 57 passed, 0 failed.bin/fm-lint.shover the full canonical set: pass (ShellCheck 0.11.0, actionlint 1.7.12).bin/fm-doc-audience-check.sh: ok, 112 surfaces, 622 local links.No CI checks are expected on this base.