Skip to content

refactor(usage): keep cache state private and test its owner - #144433

Merged
steipete merged 1 commit into
mainfrom
codex/test-usage-owner-imports
Sep 10, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/test-usage-owner-imports

Conversation

@steipete

Copy link
Copy Markdown
Contributor
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:

node scripts/run-vitest.mjs src/gateway/server-methods/usage.test.ts src/gateway/server-methods/usage-cache.test.ts src/gateway/server-methods/usage.sessions-usage.test.ts src/gateway/server-methods/usage.sessions-usage-cache.test.ts src/gateway/server-methods/usage.sessions-usage-owner-attribution.test.ts
node scripts/run-vitest.mjs test/e2e/qa-lab/runtime/gateway-usage-memory-apis.e2e.test.ts

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.

@clawsweeper

clawsweeper Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 10, 2026 21:45
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: L maintainer Maintainer-authored PR labels Sep 10, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 10, 2026
@clawsweeper

clawsweeper Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 10, 2026, 5:57 PM ET / 21:57 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: 619fd4850f4751611003b2210bacdb17cbccf2f3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving refactor with meaningful retained coverage and no blocking findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The verified repository-admin author is exempt from external-contributor proof requirements, and this extraction does not materially change authority. Reported owner tests and authenticated local Gateway E2E coverage match the touched cache paths; they are not live-provider validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The verified repository-admin author is exempt from external-contributor proof requirements, and this extraction does not materially change authority. Reported owner tests and authenticated local Gateway E2E coverage match the touched cache paths; they are not live-provider validation.
Evidence reviewed 7 items Production behavior preserved: Compared the introduced extraction against the pinned merge base. The cache insertion and loading functions are byte-identical after accounting for the added export; TTL, eviction, stale refresh tracking, and partial-result handling remain unchanged.
Complete internal cutover: Both production domain loaders consume the extracted engine. Searches found cache maps only in their owning module and no remaining usageTestApi consumers; the removed handler export is not a published package subpath.
Observable cache coverage retained: Handler tests retain configuration invalidation, query partitioning, role isolation, cold-load coalescing, partial snapshot refresh, and stale replacement checks. The generic owner suite retains bounded growth, active-load preservation, and refresh lifetime coverage.
Findings None None.
Security None None.

How this fits together

Gateway 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
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -12, Tests -35. Total -47 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 3 91 103 -12
Tests 7 255 290 -35
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 346 393 -47

Review metrics

None.

Technical review

Best 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.

Labels

Label changes:

  • add P3: This is an internal ownership and test-maintenance cleanup with unchanged usage-report behavior.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The verified repository-admin author is exempt from external-contributor proof requirements, and this extraction does not materially change authority. Reported owner tests and authenticated local Gateway E2E coverage match the touched cache paths; they are not live-provider validation.

Label justifications:

  • P3: This is an internal ownership and test-maintenance cleanup with unchanged usage-report behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The verified repository-admin author is exempt from external-contributor proof requirements, and this extraction does not materially change authority. Reported owner tests and authenticated local Gateway E2E coverage match the touched cache paths; they are not live-provider validation.

Evidence

What I checked:

  • Production behavior preserved: Compared the introduced extraction against the pinned merge base. The cache insertion and loading functions are byte-identical after accounting for the added export; TTL, eviction, stale refresh tracking, and partial-result handling remain unchanged. (src/gateway/server-methods/usage-cache.ts:13, 619fd4850f47)
  • Complete internal cutover: Both production domain loaders consume the extracted engine. Searches found cache maps only in their owning module and no remaining usageTestApi consumers; the removed handler export is not a published package subpath. (src/gateway/server-methods/usage-result-cache.ts:18, 619fd4850f47)
  • Observable cache coverage retained: Handler tests retain configuration invalidation, query partitioning, role isolation, cold-load coalescing, partial snapshot refresh, and stale replacement checks. The generic owner suite retains bounded growth, active-load preservation, and refresh lifetime coverage. (src/gateway/server-methods/usage.sessions-usage-cache.test.ts:185, 619fd4850f47)
  • Current-main necessity check: Fetched main still exports both domain maps and contains the generic engine inside usage-result-cache.ts, so this ownership cleanup is not already present there. No merged replacement was established. Inspection of the supplied latest-release source failed because that object was unavailable; no release-inclusion claim is made. (src/gateway/server-methods/usage-result-cache.ts:33, 38e0e2e9d4c0)
  • Validation scope: The captured PR body reports 113 passing unit cases, the named usage-memory E2E, six sensitivity controls, and 32 changed-file checks. The inspected E2E exercises authenticated WebSocket usage RPCs against seeded local state. These are contributor-reported results; this read-only review did not execute tests. The introduced diff passes git diff --check. (test/e2e/qa-lab/runtime/gateway-usage-memory-apis.e2e.test.ts:232, 619fd4850f47)
  • Maintainer status verified: Live repository permission lookup returns admin for steipete, resolving the supplied association discrepancy for the maintainer proof exemption. The supplied context also carries the protected maintainer label.

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete steipete self-assigned this Sep 10, 2026
@steipete
steipete merged commit bff918a into main Sep 10, 2026
249 of 250 checks passed
@steipete
steipete deleted the codex/test-usage-owner-imports branch September 10, 2026 22:25
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant