Skip to content

fix(usage): ignore a ChangeTime-only ledger move on Windows (pricing-cache lane=all failure) - #8799

Merged
lidge-jun merged 1 commit into
devfrom
fix/windows-usage-ctime
Nov 16, 2026
Merged

lidge-jun merged 1 commit into
devfrom
fix/windows-usage-ctime

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

tests/server/model-costs-pricing-cache.test.ts:140 ("policy-only API writes refresh warm estimate, summary and aggregate caches") fails on Windows with Expected "unchanged", Received "rebuild": 5/5 runs at stage 0 on a Windows 11 host (desktop-c795oh4), intermittently on hosted Windows (dev lane=all runs on 2026-11-09 e76511d, 1d16d79, c81be32, a144140, 4b38e9a, and windows 11/14 at b378a43 on 2026-11-16, run https://github.com/lidge-jun/opencodex/actions/runs/43790630995). Between the two revisions only revision.ctimeMs differs (+0.18–1.1 s); dev/ino/size/mtime/birthtime are equal, and a plain read/stat does not move ChangeTime on that host.

Root cause (inferred from the code, not yet traced on Windows): hardenConfigDir (src/config/paths.ts) starts a background icacls on the config home whenever the home's ctime differs from the ACL memo (src/lib/windows-secret-acl.ts); config writes and the filter-index database creation change the home, and re-applying inherited ACEs moves usage.jsonl's ChangeTime. usageLogRevisionKey counted ChangeTime, so the next read took the same-size branch of refreshOnce (src/usage/filter-index.ts) and rebuilt the filter index and every retained aggregate — a full ledger scan with no content change.

  • usageLogRevisionKey (src/usage/log.ts) omits ctimeMs on win32 (a platform parameter defaults to process.platform). Content cannot change without moving mtime (100 ns resolution on NTFS), and the append path still verifies the boundary digest. POSIX keeps ChangeTime, where it is the one field that exposes an in-place rewrite that restores mtime. Because the key is the single comparison point, ledger retention and scanner mutation checks also ignore a ctime-only move on win32.
  • The pricing-cache test drops its earlier Windows-only tolerance of a ChangeTime-driven "rebuild": every warm read must be "unchanged", and the ChangeTime diagnostics JSON stays in the failure message, so a remaining failure names any other mover.
  • tests/usage/usage-aggregate-cache.test.ts: a key-level test (a ctime-only move changes the key on linux/darwin, not win32; every other field still does) and a behavioural test (with process.platform set to win32, a chmod-driven ChangeTime-only move leaves the base and filtered aggregates "unchanged" and a later append is still picked up).
  • structure/dashboard-and-usage.md records the rule.

Prepared by a merge-manager implementation task; validated and opened by the merge manager.

Verification

  • macOS (before a final trim of log.ts to 1993 lines): bun test tests/usage/usage-aggregate-cache.test.ts tests/server/model-costs-pricing-cache.test.ts 38 pass / 0 fail; bun run typecheck, bun run structure:check pass.
  • Windows red/green on desktop-c795oh4 and the full local check set (typecheck, structure, layout and file-size guards, the usage suite per file, red-before of the new behavioural test) on a clean host: results are posted on this PR before merge.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed (structure/dashboard-and-usage.md).
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults (no auth, credential or ACL code changed; only the ledger revision comparison on win32).

Summary by CodeRabbit

  • Bug Fixes
    • Improved usage-data cache handling across operating systems, avoiding unnecessary refreshes from Windows file metadata changes while continuing to detect meaningful ledger updates.
  • Documentation
    • Clarified how usage throughput metrics are calculated and noted when older indexes may be rebuilt.

…on Windows

On NTFS the config home's background ACL harden re-applies inherited ACEs to usage.jsonl and moves its ChangeTime with dev/ino/size/mtime/birthtime unchanged, which rebuilt the filter index and every retained aggregate. POSIX keeps ChangeTime. The pricing-cache test now requires unchanged on every platform.
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 16, 2026 05:41
@lidge-jun lidge-jun added bug Something isn't working ci:full Run the four full Ubuntu test shards on this pull request labels Nov 16, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T05:43:13.664036Z e3c2846 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The usage log revision key now includes ChangeTime on non-Windows platforms and excludes it on Windows. Tests cover platform-specific key changes and aggregate-cache behavior. Documentation describes the platform distinction and a one-time rebuild for older indexes with rounded identifiers.

Changes: Usage revision key

Layer / File(s) Summary
Platform-specific revision key policy
src/usage/log.ts, structure/dashboard-and-usage.md
usageLogRevisionKey accepts a platform argument that defaults to process.platform. The key includes ctimeMs except on Windows. The documentation records this distinction and notes that older indexes with rounded identifiers rebuild once.
Aggregate cache validation
tests/usage/usage-aggregate-cache.test.ts, tests/server/model-costs-pricing-cache.test.ts
Tests verify that ctimeMs changes affect Linux and macOS keys but not Windows keys. They also verify Windows cache reuse after a ctimeMs-only change, detection of a later append, and unchanged aggregate results after settling.

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

Change: Bug fix

Suggested reviewers: luvs01

Merge Risk: Minimal · up to e3c28

This change stops Windows ChangeTime-only moves, such as ACL hardening, from triggering needless rebuilds of the usage aggregate cache. POSIX behavior is unchanged. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the usage-ledger revision key now ignores a ChangeTime-only move on Windows. The raw summary confirms that usageLogRevisionKey drops ctimeMs on win32 and keeps it on P…
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.
Full details: Title check

Explanation

The title names the main change: the usage-ledger revision key now ignores a ChangeTime-only move on Windows. The raw summary confirms that usageLogRevisionKey drops ctimeMs on win32 and keeps it on POSIX, and that the tests and docs match. The title also states the pricing-cache failure it addresses. It is specific and concise, and it follows the conventional commit style.

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 595de1e and e3c2846.

Files selected for processing: 4

  • src/usage/log.ts
  • structure/dashboard-and-usage.md
  • tests/server/model-costs-pricing-cache.test.ts
  • tests/usage/usage-aggregate-cache.test.ts

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

@lidge-jun

Copy link
Copy Markdown
Owner Author

Validation evidence for e3c2846 (merge manager):

Windows (desktop-c795oh4, Windows 11, bun 1.3.14, GITHUB_ACTIONS unset):

  • bun test tests/server/model-costs-pricing-cache.test.ts ×5: all exit 0, 1 pass / 0 fail (9.9–11.6 s).
  • bun test tests/usage/usage-aggregate-cache.test.ts tests/usage/usage-filter-index.test.ts: 98 pass / 3 skip / 0 fail (the skips are skipIf(win32) by design).
  • Red with origin/dev's src/usage/log.ts (the diff is usageLogRevisionKey only): 2/2 exit 1 at stage 0, filteredAgain.update "rebuild"; size 296 and mtimeMs equal, only ctimeMs moved. Restored, tree clean.
  • Trace (WMI process-start trace + 2 ms stat poller): during a passing run usage.jsonl's ChangeTime moved ~45 times with size/mtime constant, in triplets ~25 ms apart about every 0.55 s — matching each stage's write/summary/filtered steps. Six icacls.exe launches occurred but do not line up 1:1 with the moves, so the mover is not conclusively identified; the "background ACL harden" explanation in the description should be read as one plausible contributor, not the established cause. The fix does not depend on it: on win32 the ledger key ignores any ChangeTime-only move while dev/ino/size/mtime/birthtime and the append-boundary digest still detect content changes.

Linux (pen-cc-01): typecheck and structure:check exit 0; layout + file-size guards 38/0; aggregate + pricing-cache 38/0; 13 usage / hub-usage / api-usage files run one per process all 0 fail. Red-before: with dev's log.ts exactly the two new ChangeTime tests fail (35 pass). bun test tests/usage in one process: 1653 pass / 3 fail, all three in request-log-anthropic-account-tag.test.ts (19/19 alone); origin/dev 595de1e shows the identical three, so that is pre-existing cross-file isolation, not this PR.

@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer integration of #8799 at e3c2846.

This repairs the last red shard (windows 11/14, tests/server/model-costs-pricing-cache.test.ts "Expected unchanged, Received rebuild") from the failed dev batch run 43790630995 on b378a43. The other two failing shards, windows 3/14 and 8/14, were repaired by #8791 (595de1e).

  • CI on this exact head: all 33 checks passed. That includes test 1–5/5, gates, and a successful enforce-target on this head.
  • Windows 11, desktop-c795oh4 (fresh clone at this head): the pricing-cache test passed 5 of 5 runs with the fix. It failed 2 of 2 runs with dev's src/usage/log.ts: stage 0 got rebuild where unchanged was expected, and only ctimeMs had moved; size and mtime were the same. The aggregate-cache and filter-index tests passed with 98 pass, 3 skips that are skipped on win32 by design, and 0 fail.
  • Linux, pen-cc-01: typecheck, structure:check, the layout and file-size ratchet tests, and the aggregate and pricing-cache tests all passed, and 13 per-file usage, hub-usage and api-usage runs had 0 failures. With dev's log.ts, exactly the two new ChangeTime tests fail. Three failures in request-log-anthropic-account-tag.test.ts when tests/usage runs as one directory also happen on dev 595de1e, so this PR did not cause them.
  • What is known about the cause: we observed that on Windows the file's change time moves while its size and modification time stay the same. A process trace did not identify which operation moves it, so the ACL-hardening explanation is still an inference. The fix ignores ctime in the usage-log revision key on Windows only and does not depend on which operation moves it.
  • assert-mergeable-review.sh --maintainer-integration: OK.

Next step: one batched lane=all on the resulting dev head. Merging stays paused until that run is green.

@lidge-jun
lidge-jun merged commit f329892 into dev Nov 16, 2026
41 of 45 checks passed
@lidge-jun
lidge-jun deleted the fix/windows-usage-ctime branch November 16, 2026 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ci:full Run the four full Ubuntu test shards on this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant