Skip to content

test(usage): stop asserting the overlay version against a moving oracle - #2549

Merged
lidge-jun merged 50 commits into
devfrom
codex/api-usage-overlay-version-oracle
Aug 25, 2026
Merged

lidge-jun merged 50 commits into
devfrom
codex/api-usage-overlay-version-oracle

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Aug 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

tests/api-usage.test.ts fails reproducibly outside CI's dedicated single-file job. It blocked the release preflight, and it reproduces on the already-shipped main (71c57ea64, v2.32.1) — it is not caused by anything in the current release.

(fail) usage route does not cache a summary whose overlay version changed mid-read
Expected: 10   Received: 9

Cause

Two independent problems, both in the test rather than the route.

1. The final assertion used a moving oracle. It compared the cache stamp against userCostOverlayVersion() read after the response:

expect(getUsageSummaryCacheEntry("30d:all")?.overlayVersion).toBe(userCostOverlayVersion());

The server runs a 5-second overlay reconciler that re-reads the config from disk and refreshes the registry. Instrumenting the test showed the counter moving 9 → 10 during the settled request, so the cache was correctly stamped with the version its summary was priced under, and the assertion then compared it against a newer number.

The contract is "the cache is stamped with the version its summary was priced under" — not "the counter never moves again". The test now captures the version before issuing the request and asserts the stamp is at least that.

2. Module-level overlay state leaked across files. preservedDiskOnlyProviders outlives a test file. Every other overlay suite calls resetPreservedDiskOnlyProvidersForTests(); this one did not, so a leftover provider could make a refresh byte-identical and the version would not bump at all.

Why CI never saw it

ci.yml runs api-usage in a dedicated job on a fresh runner with only this file, so neither the cross-file leak nor enough overlay history to make the timing matter ever existed there.

Verification

bun test tests/api-usage.test.ts    # 32 pass, 0 fail — 5 consecutive runs
bun x tsc --noEmit                   # exit 0

The relaxed assertion is not vacuous. I injected a deliberate defect into the route — stamping the cache with userCostOverlayVersion() - 1, exactly the stale-price bug the test guards — and the suite went to 3 fail. Reverting restored 32 pass. No production file is touched by this PR.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. Test-only change; no runtime behavior is modified.

Summary by CodeRabbit

  • Bug Fixes

    • Improved API usage test reliability by preventing state from carrying between tests.
    • Updated overlay-version checks to handle timing changes during requests more accurately.
  • Chores

    • Updated the package version to 2.32.1-preview.20260825.

lidge-jun and others added 30 commits August 14, 2026 21:30
preview now carries the same tree as main and dev (36aed0b). The version
string is the only difference, which is what the release workflow requires:
preview publishes prerelease versions under the 'preview' dist-tag.

Before this, the preview channel was 12,065 lines behind dev and still shipped
the Compatibility Lab on every install's request path.
chore(preview): promote dev for the v2.20.0 line
[WRONG BRANCH] Merge dev into preview: Windows suite green
Merge dev into preview: ignore leftover test temp files
Merge main into preview: v2.24.2 release
Promote dev to preview: Wave 5 campaign (107 commits)
Promote dev to preview: CodeQL #87 ReDoS fix + closeout correction
Promote dev to preview: Wave 5 record corrections
Promote dev to preview: alert-precision record
Promote dev to preview: post-scan closing note
Promote dev to preview: final Wave 5 errata
Promote dev to preview: Wave 5 closing record
Promote dev to preview: v2.25.0 release train
promote: dev to preview for v2.26.0-preview.20260819
[WRONG BRANCH] release: sync dev into preview for 2.27.0
[WRONG BRANCH] release: sync dev into preview for 2.28.0
[WRONG BRANCH] release: v2.28.0-preview.20260820
[WRONG BRANCH] promote: dev to preview for v2.29.0-preview
[WRONG BRANCH] release: promote dev to preview for v2.31.0-preview.20260822
release: promote dev to preview (v2.32.0-preview)
merge dev into preview for the v2.33.0-preview.20260825 release
merge dev into preview for the v2.33.0-preview.20260825 release (release-gate parity)
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner August 25, 2026 09:59
@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature). label Aug 25, 2026
@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a075a990-f5ff-4712-9e0c-a0dd84530d8a

📥 Commits

Reviewing files that changed from the base of the PR and between c0c9544 and 121ecbc.

📒 Files selected for processing (2)
  • package.json
  • tests/api-usage.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The package version is updated to a preview release. API usage tests now reset preserved disk-only provider state and use a settled overlay-version baseline for the mid-read race assertion.

Changes

Package release metadata

Layer / File(s) Summary
Preview package version
package.json
The package version changes from 2.32.0 to 2.32.1-preview.20260825.

Overlay test stability

Layer / File(s) Summary
Overlay state isolation and race assertion
tests/api-usage.test.ts
The tests import resetPreservedDiskOnlyProvidersForTests, clear preserved provider state before and after each test, and compare the cached overlay version with a captured settled baseline in the race test.

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

Merge Risk: ⚪ Minimal · up to 121ec

This PR adjusts a flaky usage test and related test setup without changing production behavior; the targeted suite and type check pass, so no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: ingwannu, luvs01

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: updating the usage test to avoid asserting the overlay version against a changing value.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
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: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/api-usage-overlay-version-oracle

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

Comment @coderabbitai help to get the list of available commands.

@lidge-jun
lidge-jun merged commit e1fb675 into dev Aug 25, 2026
30 checks passed
@lidge-jun
lidge-jun deleted the codex/api-usage-overlay-version-oracle branch August 25, 2026 10:10
tarunravi pushed a commit to tarunravi/opencodex that referenced this pull request Sep 14, 2026
…lay-version-oracle

test(usage): stop asserting the overlay version against a moving oracle
agentHits pushed a commit to agentHits/opencodex that referenced this pull request Sep 17, 2026
…lay-version-oracle

test(usage): stop asserting the overlay version against a moving oracle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant