Repository navigation
fix(sidebar): retry read-finish shares after transient errors and a fixed sign-in - #1747
Merged
Merged
Conversation
|
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 7 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 |
Owner
Author
|
Merge pass: reviewed instead of a CodeRabbit review (rate-limited), since it touches a sign-in-dependent client path. A gate reviewer on a different model from the author's reported:
|
This was referenced Oct 28, 2026
Merged
devswha
added a commit
that referenced
this pull request
Oct 28, 2026
…nish-index code (#1539) (#2183) ## Change Closes #1539, the follow-ups from the merge pass's review of #1536. I re-checked each item against main 97f957b: 1. **Code kept for no current use** (`src/lib/seenFinishes.ts`, `src/lib/sidebarActivity.tsx`), removed: - `hydrate()`'s `if (!refreshing) ... stored = false` loop. Every path that marks the index unhydrated without a refresh (first load, a different storage, a storage clear event, the last subscriber leaving) empties `records` first, so the loop never had anything to reset. - `cleanSeen()` with no arguments, which forced a fresh storage snapshot. Only a test called it, and `hydrate()` already removes old-format and over-limit keys. `retired` is now required, and that test reaches the same cleanup through `loadSeen()`. - The `epochs` map's LRU capped at `SEEN_LIMIT`. The map is keyed by machine ID (one entry per PC in the roster), so it is now a plain `set`. 2. **Past 2,000 records, an old read finish turns unread while you watch.** This is kept on purpose (agreed with Dori), and a comment on `trimRecords()` now says so. It takes 2,000 other panes read since that one. Keeping evicted records for the page's life would bring back the per-update merge that #1536 removed. After a reload the finish shows unread anyway, as it did before. 3. **Stale cache with no subscriber mounted:** already fixed by #1797. 4. **A failed share is not retried if the answer fingerprint changes before the retry:** already fixed by #1747, which made retries timer-driven. A same-ID entry keeps its pending retry, and a newly read answer replaces the entry with one that waits for the same timer. On current main a same-ID fingerprint can only go from "none" to an answer: Codex re-dating is accepted without changing the remembered answer. A new test pins that this retry happens once and carries the answer. 5. **A PC with no finishes is not cached:** `recordFor()` now caches the empty record as well, so each roster update no longer walks up to 2,000 records for such a PC. The empty record is invalidated wherever a non-empty one is: `cacheChange` on a new ID, `trimRecords`, `hydrate`, storage events, storage loss and the last unsubscribe. `cleanSeen()` also drops retired scopes from that cache. The audit doc no longer cites a `/tmp` path for its disposable harness. No visual change, no new setting, and no change to the HTTP/WebSocket contract or the stored record format. **Design precedent:** none in the UI; this is internal bookkeeping. ## Validation - New `seenFinishes.test.ts` case "walks the index once for a PC with no finishes, and sees the first finish written for it". It **failed on main** (`Map.prototype.values` called once on a repeated empty lookup) and passes now. It also checks that the first `saveSeen` and `receiveSeen` into that scope show up. - New hook case "retries a failed share once, with the answer fingerprint that arrived before the retry". It passes on main and after. It fails when the retry is dropped while a backoff timer is pending (mutation checked, then restored). - New hook case "does not cache a retired epoch's scope again while it retires" (the Codex review's one LOW). Without the second commit, `cleanSeen()`'s notification ran the subscriber's state update at once, and that update read the retired epoch and cached its scope again: one entry per epoch change until the last subscriber left. No dot was wrong. The fix records the new epoch before `cleanSeen()` and makes the subscriber skip an epoch that is no longer the PC's current one. This test **failed before that fix** and passes now. - `bun test src/lib/seenFinishes.test.ts src/lib/sidebarActivity.hook.test.ts src/lib/panePresentation.test.ts`: 78 pass, 0 fail. - `bun run check fast` on the head: passes (workflow syntax, generated types and themes, typecheck, build, 7929 unit tests with 0 failures). - `bun run check run --build bun scripts/sidebar-activity-demo-regression.ts` on the head: 44 scenarios pass, 0 fail. - Reviews: omo-native-code-reviewer PASS on the first commit (three LOW notes, none needing a change). Codex Sol 6.1 Fast xhigh found one LOW (the retired-scope entry above), and its re-review of the fix passed with no findings. The items above were re-checked against main 97f957b; the three commits main gained since touch none of these files.
devswha
added a commit
that referenced
this pull request
Oct 28, 2026
#2197) ## Change Part of #1468 (follow-ups of #1463). The server's shared read finishes (`seen.json`) kept the records of herdr runs that had ended (an old `finish_epoch`) until the 500-record cap pushed them 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`: `SeenStore` takes each PC's current finish epoch. `GET /api/seen` and the stream's first `seen` frame leave out a PC's records of another epoch. A `POST` of one is answered 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 remote PC's only once a snapshot or status of the PC itself reached this server since it started (`runtime.heard`). A snapshot restored from `machines.json` is not evidence: it is saved about a second after a status frame moves the epoch, and `stop()` cancels a pending save, so it can name the 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). - DESIGN.md's read-state entry and a changelog fragment. No HTTP/WS shape changes: the same routes and `seen` event, with fewer rows. ### Left in #1468, with reasons (comment on the issue) - The MEDIUM resend after a transient error was fixed by #1747. - Batching `seen.json` writes: a change is held and told only once it is on disk (#1564's contract). The file now holds only runs still going, which bounds the rewrite much lower than the 1.5 MB worst case of 500 records. - A POST with the largest finish ID: it comes from an authenticated browser of the same server 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. - An older cached client dropping a snapshot poll on a `seen` event: an already-cached client cannot 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, and keeps 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 once the PC told it, never from a saved snapshot": fails before the second commit, and fails again with the `heard` check removed (mutation), passes now. - Real HTTP check on a server against the isolated `ovis-test` herdr session (mkdtemp stateDir, port 0): `seen.json` seeded with a local record of an ended epoch and one of a PC not in the roster. `curl GET /api/seen` left out the ended one and kept the other; a POST for the ended epoch answered 200 and was not stored; a POST for the current epoch rewrote `seen.json` without the 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 fast` on the pushed head: exit 0 (7969 unit pass, 0 fail; typecheck, build). - Reviews: omo-native-code-reviewer APPROVE (its LOW-1 is the same restored-snapshot window, 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 #2075 rollback tests pass. No release-guard change: `REMOTE_BUNDLE_VERSION` is raised only by release PRs.
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.
Change
The MEDIUM of #1468. Since 9498d18 (which stopped a resend loop), a read-finish share (
POST /api/seen) that the server or a proxy answered with an error was never sent again for that page. A transient 502/503 while the server restarts behindtailscale serve, or a 401 fixed by signing in without a reload, left that finish known only to the browser that read it.src/lib/sidebarActivity.tsxnow retries without bringing the loop back:The issue's LOWs stay open.
Refs #1468
Validation
src/lib/sidebarActivity.hook.test.tswith fake timers: 502 then 200 delivers once; a 400 is not retried; 100 pending finishes after a 401 make one health request per window and each sends exactly once after recovery; 100 finishes during a 503 outage stay bounded; 20 roster updates during a backoff start no new chain.bun run check fast: pass.