Repository navigation
refactor(usage): keep cache state private and test its owner - #144433
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 10, 2026, 5:57 PM ET / 21:57 UTC. ClawSweeper reviewWhat this changesThe PR makes usage-report cache state private, extracts the existing shared cache engine, and moves tests from handler-level test exports to the cache owner and observable results. Merge readiness✅ Ready for maintainer review Keep open: this is a coherent ownership cleanup that remains distinct from current main. No introduced correctness defect was found, and the maintainer-authored, protected PR is not a cleanup-close candidate. Priority: P3 Review scores
Verification
How this fits togetherGateway usage handlers turn session records and cost summaries into usage reports for clients. Their in-memory caches reuse results, coalesce concurrent requests, and refresh stale data. flowchart TD
A[Usage report requests] --> B[Gateway usage handlers]
B --> C[Query and visibility selection]
C --> D[Private domain caches]
D --> E{Fresh or loading?}
E -->|Reuse| F[Usage report response]
E -->|Load or refresh| G[Session and cost summaries]
G --> D
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -12, Tests -35. Total -47 across 10 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep domain cache state private and preserve one shared cache engine with complementary owner-level and handler-level coverage. Do we have a high-confidence way to reproduce the issue? Not applicable: this refactor addresses internal ownership rather than a reported runtime failure; source comparison confirms the cache algorithm is preserved. Is this the best way to solve the issue? Yes: extracting the existing engine while retaining private domain maps removes test-only access without duplicating policy or changing public contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 38e0e2e9d4c0. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
Additional instructions
MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.
What Problem This Solves
Usage tests reached cache internals through a handler-level test API and exported domain Maps. That mixed handler, domain-cache and generic cache ownership, making tests depend on incidental internal exports.
Why This Change Was Made
Move the existing generic cache engine to an adjacent owner consumed by both production domain loaders. Keep their Maps private, exercise engine state with caller-owned Maps, and retain domain caching and query checks through loader and handler results.
The retired test API existed in a stable release as an internal export. The inspected package and SDK boundaries do not expose it as a public SDK API; Gateway RPC and published SDK contracts remain unchanged.
User Impact
The ownership boundary is simpler, with no intended change to usage results or cache policy. Ten paths include two new owner/test files and one retired test file. Production code shrinks by 12 lines and tests by 35.
Evidence
The final five unit suites passed all 113 cases with the recorded case relocations. The named usage-memory E2E passed through its normal entry point, including the full runtime prebuild:
Six bounded fault controls each produced the intended native assertion failure and restored the exact source, covering retention, in-flight eviction, stale refresh tracking, both domain owners and incomplete session snapshots. These failures are sensitivity evidence, not passing tests.
Independent R2 review is clean. All 32 required changed-file checks passed, including the production and test type graphs, lint, boundaries, and all three unused-export scans. The earlier Knip failure on exported Maps is retained separately; it motivated the private-state owner repair and is not substituted for the new gate. Proof uses local tests and controlled state, not live-provider or production-service validation.