Repository navigation
fix(sidebar): end a herdr run's read finishes only on proof, never from a late read (#2206) - #2249
Conversation
…ever from a late read (#2206) A WebSocket snapshot read before herdr restarted could arrive after an HTTP read of the new run with the same order pair, put the old finish epoch back, and make SeenStore drop the new run's read finishes and answer POSTs 200 without saving them. FinishEpochLedger keeps, per PC, the herdr runs this server knows have ended: a read that started after every report it held settles them; frames and restored snapshots only hold their epoch. SeenStore hides, refuses and drops records of ended runs only, and a late report of a run its own server moved on from is refused. A rolled-back setup move restores the ledger.
… and tell no stale status (#2206) Review round 1 on the first commit: - A status names no server: it counts as the health-proven connection's, or none while the proof is pending; a snapshot held for health is the proven server's own only if no status was laid over it; a restored snapshot names none. So a status of one server laid over another's cached roster can no longer end the first server's live run for good. - A status of a run ended for good is dropped before it is kept, told to browsers or alerted, on the local PC and remote ones. - The local PC's runs other than this process's current finish epoch are over again, so records an earlier process left are dropped as before (#2197). - SeenStore asks MachineManager.finishEnded(pc, epoch).
… connects (#2206) A roster read at a PC's new SSH address waits in Runtime.move until the setup connects there. Its known server was dropped on the way, so a later read of that server could only end the run for a while, and a late snapshot of it could replace the newer one again (Codex re-review).
…h names no server (#2206) omo re-review MEDIUM-1: a mutation that names the proven server for a patched held snapshot survived every test. The new case fails under it.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Finish ledger and local tracking server/finish-epoch-ledger.ts, server/machines.ts, server/core/status.ts |
Adds a ledger for held and ended finish epochs. Local machine tracking receives the current finish epoch and exposes ended-run state. |
Machine lifecycle and health-gated snapshots server/machines.ts, server/machine-own-update.test.ts, server/machines-refresh.test.ts |
MachineManager rejects stale reports, holds remote snapshots until health verification, and preserves ledger state during setup moves. Tests cover delayed reports and refresh races. |
Seen-finish filtering and validation server/seen.ts, server/index.ts, server/seen.test.ts, DESIGN.md, changelog.d/* |
SeenStore filters and prunes finishes using an ended-run predicate. Tests and documentation cover late reports and known-ended runs. |
Priority:
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
- fix(sidebar): follow-ups from the ended-run finishes review (#2197) #2206 — Addresses the stale-snapshot scenario that could reinstate a retired epoch and remove live read marks.
Possibly related PRs
- devswha/ovis#2181 — Both changes gate snapshot adoption after a setup move on health verification and update setup-move tests.
Suggested reviewers: haeminway1
Merge Risk: 
Minimal · up to fb8e4
-
No merge-blocking issue was identified; the reviewed change is ready for normal merge checks.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The description includes the required Change and Validation sections. It explains the problem, resulting behavior, linked issue, implementation scope, regression tests, integration testing, and validation results.
Full details: Linked Issues check
-
Explanation
The PR addresses the coding requirements in
#2206.FinishEpochLedgerrequires a settled read and matching server evidence before it marks a run ended.MachineManager.finishEndedandSeenStoreuse that evidence, so a late snapshot or status cannot retire the current run. The PR updateschangelog.d/seen-old-epochs.mdandDESIGN.md. Existing connect behavior keeps records for unheard PCs and the validation covers the 500-record behavior. The setup-move rollback restores the ledger, with regression coverage inserver/machine-own-update.test.ts. The new refresh and seen-store tests cover the stale-read and record-retention cases.
Full details: Out of Scope Changes check
-
Explanation
The changed production files implement finish-epoch retirement, stale event handling,
SeenStoreintegration, and setup-move rollback for#2206. The changed tests validate those behaviors. The changelog andDESIGN.mdchanges document the same behavior. No unrelated API shape, release-guard, or feature changes are shown.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 8 files. (3 skipped: 3 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches: 💡 1
-
📝 Generate docstrings: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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 @coderabbitai help to get the list of available commands.
|
Merging fb8e4d2. Codex was at capacity, so an omo reviewer on gpt-6.1-sol and an independent second reviewer reviewed it; both pass with no HIGH. On a real loopback HTTP/WebSocket bridge with the real MachineManager and SeenStore, main reproduced #2206: after a herdr restart a stale WebSocket frame put the old finish epoch back, and a POST of a new seen record answered 200 without saving (records listed: none). On this head the cached epoch stays on the new run and both records are saved and listed. Only an admitted HTTP read settles the ledger; frames and health-delayed candidates only hold evidence, and final retirement needs the held run's owner to match the settling server. The second reviewer drove the real manager, ledger and SeenStore through 720 permutations of stale and current snapshots, HTTP reads, reconnects and stale status frames (4,320 checkpoints): every one fails the current-run persistence check on main and passes here; frames alone end nothing, and 10,000 settled restarts keep the ledger at 64 ended and 1 held epoch. Not filed (not user-visible): the ledger's held-epoch map has no bound of its own, so many distinct finish epochs with no successful settling read accumulate until the next settle ( |
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 restartson 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, andSeenStorethen treated thenew 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 serveronly 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 (thesnapshot 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.
snapshot names its own
order_epoch, a status names the connection's health-proven server (none while the proof ispending), 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 againwhen a read names it.
finishEnded()treatsevery local epoch other than this process's current
Finishesepoch as over, so records an earlier process (orherdr run) left are dropped as before.
MachineManager.finishEpochs()becomesfinishEnded(pc, epoch), andSeenStorehides, refuses and drops a recordonly 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.heardgoes: a snapshot restored frommachines.jsonends nothing until a read ofthe PC names another run (the Shared read finishes: retry transient errors, batch seen.json writes, drop old epochs (#1463 follow-ups) #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 itssnapshot; the existing #2075 rollback tests now check it. A roster read at the new address waits in
Runtime.movewith 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 saysseen.jsonholds onlythe 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_VERSIONis raised only by release PRs.Validation
server/machines-refresh.test.ts, new: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).
(fix(sidebar): follow-ups from the ended-run finishes review (#2197) #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.
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 itreplaced (fix(sidebar): follow-ups from the ended-run finishes review (#2197) #2206)":
SeenStorewired to a realMachineManagerasindex.tsandcore/status.tswire it. A record ofan 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.tsmachines: a cancelled target change is kept and lets a reconnect start a bridge at an unapproved address #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 alater read of that server ends it for good (fix(sidebar): follow-ups from the ended-run finishes review (#2197) #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 isrefused. Without the owner carried through the move, B comes back.
Bun.servebridge (/api/session,/ws, health), a realMachineManagerobserving it,/api/seenover HTTP driven withcurl. On main: stale A frames put the PC back at A,POSTB/p2 →200butseen.jsonheld only B/p1, andGETanswered{"finishes":[]}. On this branch: the PCstays at B,
POSTB/p2 →200and saved,GETlists both B records.bun run check faston the pushed head (throughdori heavy): unit 8159 pass, 0 fail; typecheck, build, generatedfiles and workflow syntax ok.
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.
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.
finishEndedis used only by tests (production passesFinishes.epoch);one test reads a private field through a cast; snapshot frames
admitRemoterefuses are still forwarded tobrowsers, which ignore them (as on main).