refactor(usage): type saveRequestUsage with UsageEntry interface + any-budget ratchet (#3512) (#6809)

Replace saveRequestUsage(entry: any) with a typed UsageEntry interface
mirroring the usage_history columns 1:1. Fields stay optional/nullable
since different writers (chatCore success/failure, rejected-request
accounting, Codex Responses WS) populate the row incrementally; tokens
stays unknown since callers pass either raw provider-shaped usage or
the normalized {input,output,cacheRead,...} shape.

Also cleaned the file's other any usages (getUsageHistory filter,
getUsageDb next-cursor cast, appendRequestLog tokens param,
getRecentLogs catch) so it now sits at zero any and can be added to
the check:any-budget:t11 zero-any allowlist.

Documents the DB-entity <-> TS-interface convention in
docs/architecture/CODEBASE_DOCUMENTATION.md Sec 11.
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-07-11 04:32:10 -03:00
committed by GitHub
parent 6d3d122b84
commit d96bd80343
4 changed files with 76 additions and 6 deletions

View File

@@ -22,6 +22,10 @@ const budget = [
{ file: "src/lib/db/prompts.ts", maxAny: 0 },
{ file: "src/lib/db/providers.ts", maxAny: 0 },
{ file: "src/lib/db/settings.ts", maxAny: 0 },
// #3512: saveRequestUsage typed with UsageEntry (DB-entity 1:1 interface); the
// other any's in this file (getUsageHistory filter, nextCursor cast,
// appendRequestLog tokens, getRecentLogs catch) were cleaned in the same pass.
{ file: "src/lib/usage/usageHistory.ts", maxAny: 0 },
{ file: "open-sse/config/providerRegistry.ts", maxAny: 0 },
{ file: "open-sse/config/providerModels.ts", maxAny: 0 },
{ file: "open-sse/mcp-server/audit.ts", maxAny: 0 },