Repository navigation
fix(sidebar): drop the read finishes of a herdr run that ended (#1468) - #2197
Conversation
The server kept every PC's read finishes until the 500-record cap pushed them out, so finishes of a herdr run that had ended (its finish epoch moved on) were sent to every browser on each events-stream reconnect, which wrote them back into localStorage, and every change rewrote them into seen.json. SeenStore now reads each PC's current finish epoch from the machine snapshots: GET /api/seen and the stream's first seen frame leave out a PC's records of another epoch, a POST for one is answered as sent and not kept, and the next write drops them from the file. A PC whose epoch the server does not know keeps every record.
…snapshot's (#1468) A remote PC's snapshot is restored from machines.json at start, and it is saved about a second after a status frame moves its finish epoch. A server stopped in that window started with the PC's previous epoch, so the read finishes of the run the PC was still in were left out and then dropped by the next write (Codex review of f836f1aa). MachineManager.finishEpochs() names a remote PC's epoch only once a snapshot or status of the PC itself reached this server since it started; until then the PC's epoch is unknown and its records are kept.
…ed back (#1468) A setup move that published the new address's snapshot and then failed to save put the PC's restored snapshot back but left it marked as heard, so its stale epoch could again retire current read finishes (Codex re-review of 391c22d8, LOW).
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 20 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Merging 9589b7c: omo-native-code-reviewer and Codex both pass this head. The server drops a read finish only when it knows the PC's current epoch and the finish names another, and the server always learns an epoch before any browser does. So a live run is never treated as ended, and other PCs' finishes are kept. The new tests fail on main and under mutation. The required checks are green, and CodeRabbit did not review this head. Codex's MEDIUM, a delayed snapshot from before a herdr restart that can drop read marks so done dots reappear, needs that race to happen. It goes to a follow-up issue with the LOW notes. |
…om a late read (#2206) (#2249) ## Change Closes #2206 (follow-ups of #2197's review). **The stale snapshot (Codex MEDIUM in #2197).** The manager let a snapshot replace the cached one by its workspace-order pair (`order_epoch`, `read_seq`), which says nothing about herdr's finish epoch. When herdr restarts on a PC while its server stays up, a WebSocket frame read before the restart can arrive after an HTTP read of the new run with the same pair. That frame put the old epoch back, `finishEpochs()` named it, and `SeenStore` then treated the new run as the one that ended: GET left out its records, the next write deleted them, and a POST answered 200 without saving. Read DONE dots came back. - `server/finish-epoch-ledger.ts` (new): per remote PC, which herdr runs this server *knows* have ended. A PC's server only moves its finish epoch forward and labels each read when it ends, so a read that started after every snapshot and status of the PC that reached this server is newer than all of them: the reads `refresh()` publishes (the snapshot revision did not move during the read). Such a read **settles**: every other epoch the cache held since the last one has ended. Anything else only **holds** its epoch, because it may have been overtaken. - An end is final only when the ended run and the settling read are known to come from the same server: a full snapshot names its own `order_epoch`, a status names the connection's health-proven server (none while the proof is pending), and a snapshot held for health is the proven server's own only if no status was laid over it. A restored or status-patched snapshot names no server. A snapshot or status of a finally ended run is refused before it is kept, told to browsers (`machine-message`) or alerted; a run ended by another or an unknown server is held again when a read names it. - The local PC: a late status of a run its read moved on from is refused the same way, and `finishEnded()` treats every local epoch other than this process's current `Finishes` epoch as over, so records an earlier process (or herdr run) left are dropped as before. - `MachineManager.finishEpochs()` becomes `finishEnded(pc, epoch)`, and `SeenStore` hides, refuses and drops a record only when that says its run ended. A late read naming a run the server never saw end can no longer delete the current run's records. `runtime.heard` goes: a snapshot restored from `machines.json` ends nothing until a read of the PC names another run (the #1468 rule, now as evidence). **The setup-move rollback (LOW).** A move that cannot be saved restores the PC's ledger (it replaces `heard`) with its snapshot; the existing #2075 rollback tests now check it. A roster read at the new address waits in `Runtime.move` with the server known to have read it, so once the move connects a later read of that server can end its run for good. **The changelog wording (LOW).** `changelog.d/seen-old-epochs.md` (unreleased) no longer says `seen.json` holds only the runs still going. DESIGN.md's read-state entry describes the rules above. **Records of a PC the server has not heard from (LOW): kept by design.** They are still sent to each browser on connect, capped at 500. Nothing proves their run ended, and a disconnected PC's card shows its saved roster, so dropping them would bring its read dots back. They leave once a read of that PC names another run. **Known limit (LOW, as on main).** A PC served alternately by two servers (its own Ovis and this app's bridge, each with its own finish epoch) has the other server's run treated as ended while one answers, so that run's records can be dropped at a write in that window. It is no longer refused for good: it comes back when its server answers again. **Not reproduced (LOW, from the Codex re-review).** A status is owned by the connection's health-proven server. If the HTTP endpoint could switch between two live servers while an older observer WebSocket stays open in the same connection generation, that observer's status would be credited to the newer server. The review's probe needs a synthetic transport split; it was not reproduced through the SSH-forwarded bridge, where the old observer closes with its server. No HTTP/WS shape changes. No release-guard change: `REMOTE_BUNDLE_VERSION` is raised only by release PRs. ## Validation - `server/machines-refresh.test.ts`, new: - "a late read of a herdr run an HTTP read showed ended cannot bring it back with the same order pair (#2206)": a remote bridge over real HTTP+WS; A then B read by HTTP with the same pair; a stale WS snapshot and status of A leave the PC at B, the A status is not emitted to subscribers, and A is ended; a frame of an unseen run C ends nothing until the next HTTP read. Fails on main (back at A) and on the first head of this PR (A emitted). - "a status heard before a connection's health proof cannot end its run for good under the cached roster's server (#2206)": server R in run A, then the PC's other server S in run B with a slow health, a status of B, R again, then S again: S's read is taken and B shown once health proves it. Fails on the first head of this PR (S's read refused before any health call). Mutations each fail it: every end final; a status owned by the cached roster's server. - "a snapshot held for health that a status laid another run over names no server for that run (#2206)": fails when the proven server is named for a patched held snapshot (omo re-review MEDIUM-1). - `server/seen.test.ts`, new "keeps and saves the read finishes of a herdr run when a late report names the run it replaced (#2206)": `SeenStore` wired to a real `MachineManager` as `index.ts` and `core/status.ts` wire it. A record of an earlier process is left out and leaves the file; B read; a late A status is neither kept nor emitted; a new B POST is saved and A's record leaves the file. Fails on main and on the first head of this PR (earlier-process record kept; A status emitted). - `server/machine-own-update.test.ts` #2075 rollback cases: after a failed move and the reconnect at its own address, the other address's run is not ended. With the ledger restore removed, 2 cases fail. - `server/machine-own-update.test.ts`, new "keeps a moved PC's herdr run its own server's once the move connects, so a later read of that server ends it for good (#2206)": the real `setup()` flow, with the new address's server proved (`verify_source_boot`) while its roster is read; after the move, a read of run C ends B and a late read of B is refused. Without the owner carried through the move, B comes back. - Real HTTP probe (scratch, not committed): a real `Bun.serve` bridge (`/api/session`, `/ws`, health), a real `MachineManager` observing it, `/api/seen` over HTTP driven with `curl`. On main: stale A frames put the PC back at A, `POST` B/p2 → `200` but `seen.json` held only B/p1, and `GET` answered `{"finishes":[]}`. On this branch: the PC stays at B, `POST` B/p2 → `200` and saved, `GET` lists both B records. - `bun run check fast` on the pushed head (through `dori heavy`): unit 8159 pass, 0 fail; typecheck, build, generated files and workflow syntax ok. - Reviews (omo-native-code-reviewer and Codex Sol 6.1 Fast xhigh, adversarial, each round on a pinned checkout): - Round 1 on the first commit: both REQUEST CHANGES. The HIGH both found (a status heard before a connection's health proof was filed under the cached roster's server, ending a live run for good), Codex's MEDIUM (stale statuses still told to browsers), omo's M1 (local records of an earlier process no longer pruned) and M2 (no test for a final end) are fixed in the second commit, each with a test that fails before it. - Round 2: Codex REQUEST CHANGES with one MEDIUM (a moved PC's run lost its server at the move's commit), fixed in the third commit; its final round on that commit APPROVES. omo APPROVES the second commit and found no problem in the third; its MEDIUM-1 (no test for the patched held snapshot) is the fourth commit. - Left as LOW notes: the local-epoch fallback in `finishEnded` is used only by tests (production passes `Finishes.epoch`); one test reads a private field through a cast; snapshot frames `admitRemote` refuses are still forwarded to browsers, which ignore them (as on main).
Change
Part of #1468 (follow-ups of #1463). The server's shared read finishes (
seen.json) kept therecords of herdr runs that had ended (an old
finish_epoch) until the 500-record cap pushedthem out. Every events-stream reconnect sent them to each browser, which wrote them back into
its localStorage, and every change rewrote them into
seen.json.server/seen.ts:SeenStoretakes each PC's current finish epoch.GET /api/seenand thestream's first
seenframe leave out a PC's records of another epoch. APOSTof one isanswered as sent (200, the client only reads the status) and neither kept nor told. The next
write drops them from the file, before the cap is applied. A PC whose epoch the server does not
know keeps every record.
server/machines.ts:MachineManager.finishEpochs()names the local PC's epoch, and a remotePC's only once a snapshot or status of the PC itself reached this server since it started
(
runtime.heard). A snapshot restored frommachines.jsonis not evidence: it is saved about asecond after a status frame moves the epoch, and
stop()cancels a pending save, so it can namethe run the PC has since left (Codex review, MEDIUM, fixed in the second commit). A setup move
that is rolled back restores that mark with the snapshot (third commit, Codex LOW).
No HTTP/WS shape changes: the same routes and
seenevent, with fewer rows.Left in #1468, with reasons (comment on the issue)
seen.jsonwrites: a change is held and told only once it is on disk (fix(state): preserve damaged shared documents before replacement #1564'scontract). The file now holds only runs still going, which bounds the rewrite much lower than
the 1.5 MB worst case of 500 records.
and only marks its own read state until that herdr run ends. A cap would need the server's own
per-pane finish view, which lags status frames, so it would risk refusing real finishes.
seenevent: an already-cached clientcannot be changed from here; a reload ends it.
Validation
server/seen.test.ts"leaves out and drops the finishes of a PC's herdr run that ended, andkeeps a PC's whose epoch it does not know": fails on main, passes now.
server/machines-refresh.test.ts"names a remote PC's finish epoch for read finishes only oncethe PC told it, never from a saved snapshot": fails before the second commit, and fails again
with the
heardcheck removed (mutation), passes now.ovis-testherdr session (mkdtemp stateDir,port 0):
seen.jsonseeded with a local record of an ended epoch and one of a PC not in theroster.
curl GET /api/seenleft out the ended one and kept the other; a POST for the endedepoch answered 200 and was not stored; a POST for the current epoch rewrote
seen.jsonwithoutthe ended record. (Scratch script, not committed.)
HERDR_TEST_MODE=unit bun test server/machine-own-update.test.ts server/machines-refresh.test.ts server/seen.test.ts: 101 pass, 0 fail.bun run check faston the pushed head: exit 0 (7969 unit pass, 0 fail; typecheck, build).fixed); Codex Sol 6.1 Fast xhigh REQUEST CHANGES (MEDIUM, fixed in 26da453), re-review APPROVE
with one LOW (fixed in 9589b7c). The rollback LOW has no new test: it needs a PC that never
connected plus a save fault; the existing machines: a cancelled target change is kept and lets a reconnect start a bridge at an unapproved address #2075 rollback tests pass.
No release-guard change:
REMOTE_BUNDLE_VERSIONis raised only by release PRs.