GeezerVison is showing github.com — usage: test the thinning gap check; end a failure streak once its retry is long overdue by scuttletoby · Pull Request #541 · scuttletoby/t3code
Conversation
scuttletoby
commented
Nov 19, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Fixes #504
Fixes #347
What
#504 (usage history thinning)
- Done: a test for the
gap >= 0 check in thinning. Readings run for 30 minutes at day −31. The clock then steps back to day −36, and that reading falls to retention. Readings then resume 20 minutes before the first batch. The test checks that the break and the new batch survive compaction, and that a second compaction keeps the same lines. It fails with the check removed (all of the new batch is dropped, and the break with it).
- Description only, so nothing changes in code: PR usage history: keep clock step-backs through thinning; test clock guards #502's body overstates one proof. With this PR, removing
edges.add(previous) fails 3 tests, of which 2 are thinning tests ("thinning keeps a clock step back of any size, also one shorter than the interval" and "thinning keeps a break whose reading before the step fell to retention"; the third is "compaction of a file with backwards stamps thins each segment on its own"), so usage history: keep clock step-backs through thinning; test clock guards #502's claim is accurate again.
#347 (headless usage refresher)
- Done: an old failure streak now ends. If a streak's retry is overdue by more than the longest backoff (2 hours, or the interval if that is longer), a failure now starts a new streak. It is logged again and retried after 2 intervals. Before this change, an outage three days later counted as failure 2 of the old streak, with no warning and a 40-minute retry. A sweep that only runs late is minutes overdue, so it never reaches the limit. After a clock goes back, the overdue time is negative, so the streak is kept, and the existing guard still retries at once. The test pins the edge: 2 h overdue keeps the streak, 2 h + 1 ms starts a new one, and 72 h (the issue's case) starts a new one.
- Done: a boundary test for the backoff wait. A sweep in the same millisecond as a failed refresh waits out the backoff. It fails if
<= becomes <.
Proof (fail before, pass after)
Each mutation was run against the new tests, and each makes exactly one of them fail:
- remove
gap >= 0 &&: "thinning keeps a break whose reading before the step fell to retention"
retryAtMs - nowMs <= waitMs to <: "a sweep in the same millisecond as a failed refresh waits out the backoff"
- no streak expiry (
false): "a streak whose retry is overdue by more than two hours is over: a new outage"
- expiry
> to >=: the same test (its 2 h case)
streakExpiryMs returns the plain 2 h limit (no interval arm): "with an interval longer than two hours, a streak lasts that interval overdue"
- a good refresh after an expired streak calls
endStreak: "a good refresh after an expired streak does not log works again"
vp run check:changed passes (format, lint, knip, typecheck, 74 tests).
State
- Runs again: a second compaction gives the same bytes (asserted). A stale streak is replaced by the new one, and later failures count from there.
- Stops half-way: the refresher's streaks live in memory and a restart clears them, the same as before. Compaction still uses an atomic write (unchanged).
- Old or empty state: a streak left from before this change expires by the same rule. No streak means the same code path as before. A clock that jumps forward more than 2 h starts a new streak, which costs one extra warning and a short retry.
Upstream fit
Both files are fork-only (apps/server/src/usage/): the headless refresher (#42) and the usage history (#24). No upstream file changes and no seam lines.
General vs project
General: these are provider-neutral rules for every usage-limit provider instance. No project facts are involved.
🤖 Generated with Claude Code
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…ry is long overdue
- Thinning: a test for a break whose reading before the step fell to retention
(fails without the gap >= 0 check) (#504).
- Headless refresher: a streak whose retry is overdue by more than the longest
backoff is over, so a failure days later is logged and retried as a new
outage; tests for that edge and for a sweep in the same millisecond as a
failed refresh (#347).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review (independent, Opus)
Verdict: no blocking findings. One test gap and two nits. The PR's proofs reproduce.
Verified locally (head b9864e2)
HeadlessUsageRefresher.test.ts + UsageReadingsHistory.test.ts: 70/70 pass.
- PR tests against main's
HeadlessUsageRefresher.ts: only "a streak whose retry is overdue by more than two hours is over" fails. That is the bug from usage refresher: an old failure streak never expires; one backoff boundary untested (#341 follow-ups) #347. The other two new tests guard code that already exists, so they pass on main as expected.
- Each mutation in the PR body fails exactly the test it names:
gap >= 0 && removed, <= → <, expiry > → >=, and no expiry (the main source).
- Thinning test traced by hand: the -36 d reading is the edge that retention drops. Minute -20 is not an edge and survives only through
gap < 0. A second compaction sees 29/-20 as a real break and keeps the same 6 lines. Repeated runs neither drop nor add lines.
Findings (most severe first)
-
SHOULD-FIX (test gap): the intervalMs arm of streakExpiryMs is untested. apps/server/src/usage/HeadlessUsageRefresher.ts:101-103. Changing return Math.max(MAX_BACKOFF_MS, intervalMs) to return MAX_BACKOFF_MS keeps all 70 tests green (run here). Scenario: interval 6 h, so every retry waits 6 h. The host is constrained for 3 h past the retry, and then the refresh fails again. With the arm, the streak is kept: no warning, retry in 6 h. Without it, a new streak starts: a warning, retry in 6 h. Both are defensible, but the PR body and the doc comment promise "or the interval if that is longer", and nothing pins it. Add a 3 * HOUR-interval case (overdue 3 h keeps the streak, 3 h + 1 ends it), or drop the arm and say so.
-
NIT: an expired streak that ends in a success still logs "works again" with the old count. HeadlessUsageRefresher.ts:153-160. previous is cleared for the failure path, but ok calls endStreak, which reads failing again. Scenario: one failure, then 3 days signed out (skipped, canRefresh false), then a good refresh. The log says "headless usage refresh works again {failures: 1}" for a streak this PR now treats as over. The behaviour is the same as main, so this is cosmetic. A silent failing.delete when recorded is expired would match the new rule.
-
NIT: Usage history: test the thinning gap >= 0 check (#502 lens) #504 item 2 (PR usage history: keep clock step-backs through thinning; test clock guards #502's body) is not addressed, and the count has moved. With this PR's test added, removing edges.add(previous) now fails 3 tests (run here): "compaction of a file with backwards stamps…", "thinning keeps a clock step back of any size…", and the new "thinning keeps a break whose reading before the step fell to retention". usage history: keep clock step-backs through thinning; test clock guards #502's "3 thinning tests" is now right in number, though one of the three is not a thinning test. Either edit usage history: keep clock step-backs through thinning; test clock guards #502's line to name the three, or note in Usage history: test the thinning gap >= 0 check (#502 lens) #504 that the count is now correct, so closing Usage history: test the thinning gap >= 0 check (#502 lens) #504 is not read as a fixed description.
Attacks that found nothing
- Retry storm: none. Expiry only resets the count to 1, so the next wait is
backoffMs(interval, 1) = 2 intervals. Repeat expiry needs another retry more than 2 h (or one interval) overdue, which the 5 s scheduler tick never causes. Only hostConstrained, clientRefreshes, the signed-out skip or a clock jump can make a retry that late.
- Suppressed warning: impossible. Expiry only turns a recorded streak into
undefined, which leads to the warning. It adds warnings and never hides one. The cost is one extra warning per gap of more than 2 h (for example, a client was refreshing while the outage went on), and the doc comment states that as intended.
- Clock back:
nowMs - retryAtMs < 0, so the streak is kept. The existing guard at :210-216 still retries at once, and the count grows as before. Clock forward > 2 h: one new streak (one warning, a 2-interval retry). This is stated in the PR.
- Interval 0 / off:
effectiveIntervalMs returns null and the sweep returns before any streak logic. Turning it back on days later expires the stale streak, which is better than main.
- Interval changed mid-streak: overdue is measured from the stored
retryAtMs, and expiry uses the current interval. No path gives a negative or zero wait.
- State: streaks are in memory only, so a restart starts clean (as on main). A streak from an older build cannot outlive a restart. Compaction is unchanged apart from tests (atomic write; torn lines are dropped before thinning).
CI (outside this PR's files)
Test Server 3 is red in src/playtest/PlaytestService.worker.test.ts › "a thread read that hangs: the sweep returns, other sessions renew, and the read is bounded" (expected undefined to not equal undefined). This PR does not touch that area, and I found no open issue for it. Rerun it, or open an issue if it repeats, before merging.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
… expired streak
A test with a 3-hour interval shows that a streak lasts that interval overdue,
not just 2 hours. A good refresh after an expired streak now drops it silently.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fix round 1
Merged origin/main into the branch first (merge, not rebase).
- Should-fix, interval arm of
streakExpiryMs: new test "with an interval longer than two hours, a streak lasts that interval overdue" at apps/server/src/usage/HeadlessUsageRefresher.test.ts:661. The interval is 3 h. 2 h + 1 ms and 3 h overdue keep the streak; 3 h + 1 ms starts a new one. Proof: with streakExpiryMs (HeadlessUsageRefresher.ts:101) changed to return the plain 2 h limit, the test fails (overdue 7200001 ms: expected 2 to equal 1). It passes with the real code.
- Nit, "works again" after an expired streak: fixed at
apps/server/src/usage/HeadlessUsageRefresher.ts:158-161. When the streak has expired, a good refresh drops it without logging. New test "a good refresh after an expired streak does not log works again" at HeadlessUsageRefresher.test.ts:701: one failure, signed out, then a good refresh 72 h later. It fails on the old code (log.infos has "works again") and passes now.
- Nit, Usage history: test the thinning gap >= 0 check (#502 lens) #504 item 2: added a sentence to this PR's body under Usage history: test the thinning gap >= 0 check (#502 lens) #504 item 2. I checked it here: removing
edges.add(previous) (UsageReadingsHistory.ts:349) fails 3 tests. Two are thinning tests: "thinning keeps a clock step back of any size, also one shorter than the interval" and "thinning keeps a break whose reading before the step fell to retention". The third is "compaction of a file with backwards stamps thins each segment on its own".
The two usage test files pass (72/72). vp run check:changed passes (format, lint, knip, typecheck, 76 tests).
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
scuttletoby
added a commit
that referenced
this pull request
Nov 21, 2026
…ry is long overdue (#541)
* usage: test the thinning gap check; end a failure streak once its retry is long overdue
- Thinning: a test for a break whose reading before the step fell to retention
(fails without the gap >= 0 check) (#504).
- Headless refresher: a streak whose retry is overdue by more than the longest
backoff is over, so a failure days later is logged and retried as a new
outage; tests for that edge and for a sweep in the same millisecond as a
failed refresh (#347).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* usage: pin the interval arm of streak expiry; no "works again" for an expired streak
A test with a 3-hour interval shows that a streak lasts that interval overdue,
not just 2 hours. A good refresh after an expired streak now drops it silently.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
scuttletoby
added a commit
that referenced
this pull request
Nov 28, 2026
…ry is long overdue (#541)
* usage: test the thinning gap check; end a failure streak once its retry is long overdue
- Thinning: a test for a break whose reading before the step fell to retention
(fails without the gap >= 0 check) (#504).
- Headless refresher: a streak whose retry is overdue by more than the longest
backoff is over, so a failure days later is logged and retried as a new
outage; tests for that edge and for a sweep in the same millisecond as a
failed refresh (#347).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* usage: pin the interval arm of streak expiry; no "works again" for an expired streak
A test with a 3-hour interval shows that a streak lasts that interval overdue,
not just 2 hours. A good refresh after an expired streak now drops it silently.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
scuttletoby
added a commit
that referenced
this pull request
Nov 28, 2026
…ry is long overdue (#541)
* usage: test the thinning gap check; end a failure streak once its retry is long overdue
- Thinning: a test for a break whose reading before the step fell to retention
(fails without the gap >= 0 check) (#504).
- Headless refresher: a streak whose retry is overdue by more than the longest
backoff is over, so a failure days later is logged and retried as a new
outage; tests for that edge and for a sweep in the same millisecond as a
failed refresh (#347).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* usage: pin the interval arm of streak expiry; no "works again" for an expired streak
A test with a 3-hour interval shows that a streak lasts that interval overdue,
not just 2 hours. A good refresh after an expired streak now drops it silently.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
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.
|