Repository navigation
fix(gateway): refresh usage caches in background (#82773) - #82778
Conversation
|
Codex review: needs real behavior proof before merge. Summary Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path. Real behavior proof Next step before merge Review detailsBest possible solution: Retry the Codex review after fixing the execution failure. Do we have a high-confidence way to reproduce the issue? Unclear. The review failed before ClawSweeper could establish a reproduction path. Is this the best way to solve the issue? Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction. What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 94ed68bc7688. |
This comment was marked as low quality.
This comment was marked as low quality.
78cbc63 to
9e5025d
Compare
|
Verification before merge: Behavior addressed:
|
|
Landed, thanks @hclsys. Merged as |
- Refresh selected session usage summaries with bounded background work instead of blocking Gateway responses on full transcript scans. - Persist transcript-level usage metadata so cached full and ranged summaries preserve totals, model usage, tool usage, latency, and time buckets. - Add regression coverage for background refresh, range derivation, cache-version invalidation, append-only upgrades, and untimestamped usage. Fixes openclaw#82773. Co-authored-by: hclsys <[email protected]>
- Refresh selected session usage summaries with bounded background work instead of blocking Gateway responses on full transcript scans. - Persist transcript-level usage metadata so cached full and ranged summaries preserve totals, model usage, tool usage, latency, and time buckets. - Add regression coverage for background refresh, range derivation, cache-version invalidation, append-only upgrades, and untimestamped usage. Fixes openclaw#82773. Co-authored-by: hclsys <[email protected]>
- Refresh selected session usage summaries with bounded background work instead of blocking Gateway responses on full transcript scans. - Persist transcript-level usage metadata so cached full and ranged summaries preserve totals, model usage, tool usage, latency, and time buckets. - Add regression coverage for background refresh, range derivation, cache-version invalidation, append-only upgrades, and untimestamped usage. Fixes openclaw#82773. Co-authored-by: hclsys <[email protected]>
- Refresh selected session usage summaries with bounded background work instead of blocking Gateway responses on full transcript scans. - Persist transcript-level usage metadata so cached full and ranged summaries preserve totals, model usage, tool usage, latency, and time buckets. - Add regression coverage for background refresh, range derivation, cache-version invalidation, append-only upgrades, and untimestamped usage. Fixes openclaw#82773. Co-authored-by: hclsys <[email protected]>
Summary
usage.costgateway cache load to request background refresh instead ofsync-when-emptysessions.usagerequest-path session cost cache loads to background refreshContext
Fixes #82773.
The issue reports that large profiles can still block the gateway for minutes because two request-path usage cache call sites use
refreshMode: "sync-when-empty". The existing cache helpers already supportbackground; this PR only changes the gateway request-path callers, leaving the shared cache implementation intact.Audit
loadCostUsageSummaryFromCache,loadSessionCostSummaryFromCache, and the existingrefreshMode: "background"path.src/gateway/server-methods/usage.tsgateway handlers and their direct tests.Real behavior proof
usage.costandsessions.usagerequest-path cache loads no longer ask the gateway to synchronously rebuild usage data when the cache is empty.refreshMode: "background", matching the reporter's installed-build workaround that reducedusage.costto 1857ms andsessions.usageto 2888ms on the large profile in sessions.usage still blocks gateway in 2026.5.12 despite #76650 #82773.Tests
pnpm exec oxfmt --check --threads=1 src/gateway/server-methods/usage.ts src/gateway/server-methods/usage.test.ts src/gateway/server-methods/usage.sessions-usage.test.tsnode scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.json src/gateway/server-methods/usage.ts src/gateway/server-methods/usage.test.ts src/gateway/server-methods/usage.sessions-usage.test.tsnode scripts/run-vitest.mjs src/gateway/server-methods/usage.test.ts src/gateway/server-methods/usage.sessions-usage.test.tsgit diff --check