Skip to content

fix(sidebar): end a herdr run's read finishes only on proof, never from a late read (#2206) - #2249

Merged
devswha merged 4 commits into
mainfrom
fix/seen-epoch-followups
Oct 28, 2026
Merged

devswha merged 4 commits into
mainfrom
fix/seen-epoch-followups

Conversation

@devswha

@devswha devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner

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 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 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 (fix(sidebar): follow-ups from the ended-run finishes review (#2197) #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
      (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.
    • "a snapshot held for health that a status laid another run over names no server for that run (fix(sidebar): follow-ups from the ended-run finishes review (#2197) #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 (fix(sidebar): follow-ups from the ended-run finishes review (#2197) #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 machines: 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 a
    later 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 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).

…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.
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between de80980 and fb8e4d2.

Files selected for processing: 11
  • DESIGN.md
  • changelog.d/seen-late-read-epoch.md
  • changelog.d/seen-old-epochs.md
  • server/core/status.ts
  • server/finish-epoch-ledger.ts
  • server/index.ts
  • server/machine-own-update.test.ts
  • server/machines-refresh.test.ts
  • server/machines.ts
  • server/seen.test.ts
  • server/seen.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Read-finish records for runs the server knows have ended are no longer returned or saved. Reconnecting browsers will not write those outdated records back, and they are removed the next time records are saved.
    • Late reports from an earlier run no longer cause read-finish records for the current run to be dropped. This prevents completed (“DONE”) indicators from reappearing after a PC restart.
    • Records for PCs the server has not heard from since startup are retained until their run status can be established.

The server now tracks evidence that local and remote finish epochs have ended. It rejects stale reports and uses the ended-run state to filter and prune saved read finishes.

Changes: Finish-epoch retirement tracking

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: Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

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: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning 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. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the primary fix: preventing late reads from ending a herdr run's read finishes without proof. It is specific and related to the changeset.
Description check Passed The description includes the required Change and Validation sections. It explains the problem, resulting behavior, linked issue, implementation scope, regression tests, integration testing, and valida…
Linked Issues check Passed The PR addresses the coding requirements in #2206. FinishEpochLedger requires a settled read and matching server evidence before it marks a run ended. MachineManager.finishEnded and SeenStore us…
Out of Scope Changes check Passed The changed production files implement finish-epoch retirement, stale event handling, SeenStore integration, and setup-move rollback for #2206. The changed tests validate those behaviors. The change…
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. FinishEpochLedger requires a settled read and matching server evidence before it marks a run ended. MachineManager.finishEnded and SeenStore use that evidence, so a late snapshot or status cannot retire the current run. The PR updates changelog.d/seen-old-epochs.md and DESIGN.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 in server/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, SeenStore integration, and setup-move rollback for #2206. The changed tests validate those behaviors. The changelog and DESIGN.md changes 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

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 (server/finish-epoch-ledger.ts ~23-48; 10,000 holds in a unit probe, back to 1 after a settle); after 64 ended epochs older retirement evidence is forgotten; one new test asserts a private verification field (server/machines-refresh.test.ts ~853).

@devswha
devswha merged commit 792dbb9 into main Oct 28, 2026
26 of 28 checks passed
@devswha
devswha deleted the fix/seen-epoch-followups branch October 28, 2026 13:50
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.

fix(sidebar): follow-ups from the ended-run finishes review (#2197)

1 participant