Skip to content

fix(usage): count a silent PC's time from ask to ask, so that no record grows younger - #3791

Merged
devswha merged 2 commits into
mainfrom
fix/usage-silence-count
Nov 12, 2026
Merged

devswha merged 2 commits into
mainfrom
fix/usage-silence-count

Conversation

@devswha

@devswha devswha commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Change

A follow-up to #3789 (merged as 95b3c813c) for what its reviews left, all on how long a PC has been silent.

The count. The page ages the usage report it holds by the time gone by since the PC's last answer. That time was measured anew at every ask, from the arrival of the answer to the latest ask, by the longer of the device's two clocks. Two cases went wrong:

Now the usage hook keeps the silence itself and starts it again at every answer of the PC. At each ask it becomes the longer of two: what it was plus what surely went by since the ask before, which is the running clock's stretch; and what the two clocks say of the whole time since the answer. So:

  • a clock put right later takes nothing back, and no record grows younger while the PC is silent;
  • an answer is not aged at all;
  • a clock set back and then forward again counts for nothing (the merge pass's review of this PR, Opus: counting each stretch by the longer clock, as this PR first did, took the forward half for time gone by);
  • a sleep still counts, through the wall clock.

agedReport takes that time as a number; the device's clocks are read in the hook alone.

Two limits stay. A wall clock set forward with no set back before it still counts as time gone by, since it cannot be told from a sleep: a silent PC and a clock that only jumps forward err toward "old". And a single stretch between two asks that holds both a sleep that stopped the running clock and a wall clock set back loses that sleep; neither clock recorded it.

Kept, with the reason: an older server and a device clock a little ahead (the merge pass's review of #3789, both reviewers, LOW). Against a server that sends no server_time, the device's clock is asked for a record's age, and believed where the answer lies between no age and the tool's 15 minutes. A clock less than 15 minutes ahead can pass that test, and then the record reads old that much early.

Nothing else changes. No contract change, no UI change, and no changelog entry: #3789 is in no tagged build yet, and its unreleased entry already describes this behaviour.

Validation

Ran on the pushed head (eb606a96d), from a clean tree:

  • bun run check fast: passed, exit 0 (workflow syntax, fresh generated types and themes, typecheck, build, unit tests: 16,728 pass, 0 fail, 54 skip in 926 files).
  • Browser, isolated herdr session: bun run check run --build bun scripts/usage-regression.ts: 4 of 4 pass, the case with the device's clock set back while the PC is silent among them.

Also:

  • Failing first. Two new tests of the hook fail on main (95b3c813c) and pass here: a sleep that stopped the running clock and then the wall clock set back (the record read current again), and the wall clock set back while an ask is in flight (the answered record read old). The third, a clock set back and then forward again, is the merge pass's own: it passes on main, failed on this PR's first head (ec9b14739), and passes now.
  • Mutations, one change at a time, each restored: 22 of 22 turned a test red on the first head, counted by distinct test names. On this head, 7 of 7 of the hook's count turn a hook test red: nothing counted at an ask; an answer not starting the count again; only the two clocks' whole time since the answer, as main does; only the running clock's stretches; each stretch by the longer clock, as the first head did; an answer still counting from where the page opened; a stretch counted twice.
  • In the CI runner image: not run again. No UI component changes against main. This same code, before it was moved onto main and without the second new test, passed all eight steps there shortly before fix(usage): age a record without comparing clocks, and name an unknown recorder by its id #3789 merged (usage-regression, ui-contexts-regression with 63 checks, the demo build and five demo suites).
  • After the reviews of this PR, one more push (one commit). At ec9b14739 the dori review was CLEAR with one LOW, CodeRabbit had no actionable comments, and the merge pass's two reviewers were CLEAR with one LOW:
    • the clock set back and forward again (merge pass, Opus): fixed as described under Change, with its test;
    • the hook does not reset its count when the meters are switched off (the dori review): kept. It shows nowhere, since nothing is handed on until the next answer and that answer starts the count again.
  • CI at ec9b14739 failed once in "Integration tests", in server/opencode.contract.test.ts:426 ("native stand-in opencode did not start"), a herdr-backed test this PR does not touch. It was not re-run; this push started CI again.
  • Not run: bun run check full.

…rd grows younger

The time gone by since the PC's last answer was measured anew at every ask, from the arrival of that answer to the latest ask. Two cases went wrong:

- After a sleep that stopped the running clock, the wall clock gives the longer answer on waking. A wall clock then set back made the whole measure shrink, and a record already old read current again while the PC stayed out of reach (CodeRabbit on #3789).
- A wall clock set back while an ask was in flight left the answer's arrival earlier, by the wall clock, than the ask before it. That difference counted as time gone by, and a record the PC had just called current read old until the next ask (the merge pass's review of #3789, Opus).

The hook now adds up the stretches from one ask to the next, each by the longer of the two clocks, and starts again at every answer of the PC. A clock put right later takes nothing back, and an answer is not aged at all. agedReport takes that time as a number; the device's clocks are read in the hook alone.

Where one stretch holds both a sleep that stopped the running clock and a wall clock set back, that stretch's sleep is lost: nothing on the device recorded it.

Co-authored-by: sisyphus-dev-ai <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Usage records now continue aging correctly during periods without a server response, including when the device clock changes while the computer is idle.
    • Reports for recently read records remain current when the device clock moves backward during an in-progress request.
    • Older usage reports are correctly marked as non-current after extended elapsed time.

agedReport now ages usage by elapsed milliseconds. useUsage accumulates silence across fetch attempts and resets it after a successful answer. Tests cover stale-report behavior during device clock changes and delayed answers.

Changes: Usage report aging

Layer / File(s) Summary
Elapsed-time usage aging
src/lib/usage.ts, src/lib/usage.test.ts, src/lib/usage.hook.test.ts
agedReport now accepts elapsed milliseconds. useUsage accumulates silence across fetch attempts, retains it after failures, and resets it after a successful answer. Tests check report aging and clock changes during silence or an in-flight request.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • devswha/ovis#3789: Changes the agedReport input contract and usage aging logic, which overlap with this PR.

Suggested reviewers: nahwan-kim

Merge Risk: Minimal · previous review ec9b1

Usage-report aging now counts elapsed time more robustly across device clock changes. No actionable merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: usage-report aging for a silent PC now counts time from ask to ask, so no record grows younger. It matches the summary and objectives, and it is specific enough for a …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the template's two sections, Change and Validation. The Change section explains the problem, the fix, and the remaining limits in detail. The Validation section lists the check…
Full details: Title check

Explanation

The title names the main change: usage-report aging for a silent PC now counts time from ask to ask, so no record grows younger. It matches the summary and objectives, and it is specific enough for a teammate scanning history. It is a bit long at 85 characters, but it is clear.

Full details: Description check

Explanation

The description follows the template's two sections, Change and Validation. The Change section explains the problem, the fix, and the remaining limits in detail. The Validation section lists the checks run with results, plus the checks not run (CI image, bun run check full). It gives no linked issue, but the template asks for one only for features, and this is a fix. The description is mostly complete and substantive.

Finishing Touches

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 95b3c81 and ec9b147.

Files selected for processing: 3

  • src/lib/usage.hook.test.ts
  • src/lib/usage.test.ts
  • src/lib/usage.ts

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

@devswha

devswha commented Nov 12, 2026

Copy link
Copy Markdown
Owner Author

Reviews at ec9b14739, and one CI failure that is not this PR's:

  • The dori review: CLEAR, one LOW, kept. The hook does not reset its count when the meters are switched off, so the first ask after switching them on again adds the whole time they were off. It shows nowhere: nothing is handed on until the next answer arrives, and that answer starts the count again. A reset in that branch would be a line no test can see.
  • CodeRabbit: no actionable comments.
  • CI, "Integration tests": failed once, in server/opencode.contract.test.ts:426, "native stand-in opencode did not start": a herdr-backed test's own ten-second start deadline. This PR changes three files under src/lib and nothing that test runs. I will re-run the failed job once when the run has finished, without a push.

…e the PC is silent

Counting each stretch between two asks by the longer of the device's two clocks took a wall clock set forward for time gone by, also where it only undid a set back: with the PC silent, 25 minutes back and 25 forward a minute later made a record the PC had called two minutes old read stale. On main it stayed current.

At each ask the silence is now the longer of two: what it was plus what surely went by since the ask before (the running clock's stretch), and what the two clocks say of the whole time since the PC's answer. A set back and forward nets out in the second and adds nothing to the first. A record still never grows younger, a sleep still counts, and an answer is still not aged.

A wall clock set forward with no set back before it still counts: it cannot be told from a sleep.

Found by the merge pass's review of #3791 (Opus), with the hook test it wrote.

Co-authored-by: sisyphus-dev-ai <[email protected]>
@devswha

devswha commented Nov 12, 2026

Copy link
Copy Markdown
Owner Author

Second push (ec9b14739..eb606a96d, one commit), for the merge pass's finding (Opus, LOW, reproduced).

With the PC silent, a wall clock set back and then forward again read as time gone by, because each stretch between two asks was counted by the longer of the two clocks: a record two minutes old read stale. Now the silence is, at each ask, the longer of two: what it was plus the running clock's stretch since the ask before, and what the two clocks say of the whole time since the answer. A set back and forward nets out; a record still never grows younger; an answer is still not aged. The reviewer's hook test is in, and seven mutations of the count each turn a hook test red.

A wall clock set forward with no set back before it still counts, since it cannot be told from a sleep; the description says so.

Checked on eb606a96d before the push: bun run check fast (16,728 pass, 0 fail) and the usage browser check, 4 of 4.

@devswha
devswha merged commit 6439926 into main Nov 12, 2026
13 of 14 checks passed
@devswha
devswha deleted the fix/usage-silence-count branch November 12, 2026 20:01
@devswha

devswha commented Nov 12, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head eb606a96d4da as 64399265e642 on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
claude CLEAR
codex CLEAR

Two reviewers at this head: Claude (Opus) CLEAR, Codex Terra CLEAR. Two heads were reviewed. Client only (src/lib/usage.ts and its two test files); no HTTP or WS change. Follow-up to #3789, which merged before its lane's last fix was in.

While the PC is out of reach, the page now counts the time gone by from one ask to the next: at each ask, the longer of what it had plus the running clock's stretch since the ask before, and what the two clocks say of the whole time since the last answer. So a record never grows younger while the PC is silent, an answer is not aged at all, and a sleep (which stops the running clock on several browsers) still counts.

The Opus reviewer put main's usage.ts back under the PR's tests: "sleep, then wall clock set back" and "wall clock set back while an ask is in flight" fail on main and pass here. Its own case from the first head (a clock set back and then forward again counts for nothing) passes at this head.

Stated limits, both erring toward "old" and both ending at the PC's next answer; sent to the author's lane:

  • LOW (Claude, reproduced with a scratch hook test): a wall clock set forward 25 minutes and then put right while the PC is silent leaves the record stale until the next answer (main read it current again). A forward jump cannot be told from a sleep.
  • MEDIUM (Codex, traced, not run): after a clock correction, a later sleep can drop out of the count (its trace gives 9, 10 and 11 minutes at three polls against the 15-minute limit), so a record could read current a little longer than it should.

Reports: ~/.cache/ovis-tmp/reports/pr-3791-*.report.md.

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.

1 participant