Skip to content

test(server): pin clock in saved-usage window test - #261

Merged
NoahHendrickson merged 1 commit into
customfrom
fix/pin-usage-test-clock
Nov 1, 2026
Merged

NoahHendrickson merged 1 commit into
customfrom
fix/pin-usage-test-clock

Conversation

@NoahHendrickson

Copy link
Copy Markdown
Owner

Problem

UsageService.test.ts > reports saved usage of a removed directory only for windows it reaches writes a transcript dated 2026-08-01 10:00 UTC, and the usage cache keeps files for 92 days (CACHE_RETENTION_DAYS). As of 2026-11-01 10:00 UTC the saved usage is past retention, so the test fails on every branch (it's failing Test Server 7 on #260).

Change

Cherry-picks upstream's fix, 1280ccd (pingdotgg#28603), which pins the test clock near the write.

Verification

  • The cherry-pick applies cleanly.
  • Locally the test passes with it and fails without it. Two other cases in the file fail on this machine with or without the fix and pass in CI.

🤖 Generated with Claude Code

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 1280ccd)
@github-actions github-actions Bot added the vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. label Nov 1, 2026
@NoahHendrickson

Copy link
Copy Markdown
Owner Author

Code quality review of 1d204b6bc3c67cfe80a47c6e5b56f1693cdcdacf: no major structural issues found.

The diff matches upstream's 1280ccd line for line, and it uses the same TestClock.setTime + Effect.provide(TestClock.layer()) pattern this file already uses for the Cursor case (UsageService.test.ts:1255/1284). Pinning the clock is the right fix. The retention cutoff comes from Clock.currentTimeMillis (UsageService.ts:664, :678), so the test now controls it, and the wall-clock time bomb is gone without touching production code. No new helpers, branches, or file growth.

The file's other hard-coded 2026-08 timestamps read live transcripts, not saved usage past retention, so they aren't affected by this time bomb.

@NoahHendrickson NoahHendrickson left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit 1d204b6bc3c67cfe80a47c6e5b56f1693cdcdacf against base 1cbd9f2bab5d10ae81dc40297fbf92f23ba10136.

No actionable findings. The test-scoped TestClock pins the retention cutoff within 92 days of the fixture's file timestamp and preserves the assertions for both query windows. Production code is unchanged.

Validation: vp test run apps/server/src/usage/UsageService.test.ts -t "reports saved usage of a removed directory only for windows it reaches" passed (1 passed, 39 skipped).

@NoahHendrickson NoahHendrickson left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review — commit 1d204b6

No issues found.

  • Matches upstream. The diff is the same as upstream 1280ccd (pingdotgg#28603). Only the line offsets differ.

  • The fix works. UsageService gets "now" from Clock.currentTimeMillis (UsageService.ts:664), and the retention cutoff is derived from it (:678). Wrapping the case in TestClock.layer() and setting the clock to 2026-08-15 puts the 2026-08-01 transcript inside the 92-day window no matter what the real date is. The file already uses this pattern for the Cursor case (UsageService.test.ts:1255/:1284).

  • Placement is fine. Effect.provide(TestClock.layer()) wraps the whole generator, so the clock is frozen for setup and UsageService.make too. Nothing in this path sleeps on the clock, and the case passes.

  • Local run (macOS, this commit): the target case passes. In the full file, 38 of 40 tests pass. The two failures don't involve dates:

    • discovers Pi history…: a /private/var vs /var tmpdir realpath mismatch.
    • retains Codex reconciliation…: also a path comparison (path === transcript, :2007).

    Both fail the same way without this change and are macOS-specific.

Not blocking: other cases still hardcode 2026-08 fixtures (BEFORE_NARROW_WINDOW, the created/timestamp literals), but they don't depend on cache retention, so they shouldn't break with time. CI was still pending when this review was posted.

Reviewed by Claude Opus 5.5 (Claude Code).

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.0 KiB 5.0 KiB +6 B (+0.1%) 6.8 KiB ✅
Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.2 KiB 1.3 KiB +6 B (+0.5%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 21.6 KiB 21.6 KiB 0 B (0.0%) 24.4 KiB ✅
Codex Live turn messages 2 2 0 (0.0%) 8 ✅
Claude Total thread wire 5.1 KiB 5.1 KiB 0 B (0.0%) 6.8 KiB ✅
Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.3 KiB 1.3 KiB 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅
Claude Live turn messages 2 2 0 (0.0%) 8 ✅

Baseline: 1cbd9f2 · PR result: 1d204b6 · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@NoahHendrickson
NoahHendrickson merged commit 4ca88ca into custom Nov 1, 2026
25 checks passed
@NoahHendrickson
NoahHendrickson deleted the fix/pin-usage-test-clock branch November 1, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants