Repository navigation
refactor(domain): charge resource allowances through one Budget owner - #11293
Conversation
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
[Medium impact] The code appears safe to merge; no actionable issues were found. SummaryMoves seven allowance owners onto
Deferred by Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
C["Seven allowance owners"] --> B["Budget"]
B --> V{"Safe amount that fits?"}
V -->|Yes| U["Charge the allowance"]
V -->|No| F["Leave the allowance unchanged"]
F --> E["Return false or throw the owner's error"]
Reviews (1) · Last reviewed commit: "refactor(domain): charge resource allowa..." · Reviewed by Greptile |
Summary
Plan W6 step 5, first slice: one
Budgetowner (src/domain/budget.ts) for charge/refund arithmetic on resource allowances, seven budget classes migrated onto it, and a counted guard so new hand-written budget arithmetic cannot appear.Problem and expected behavior
About 20 budget classes each re-implement "refuse a malformed or oversized charge, otherwise subtract". The copies drift:
NativeMatchingAdmissionsubtracted before checking and did not check for a safe non-negative integer, so a negative charge would have silently refunded;CdpScriptSourceBudgethad no safe-integer check. Expected: one owner that refuses malformed or oversized charges without changing the remainder, keeps refunds within the maximum, and lets each caller keep its own limit failure.Change and scope
src/domain/budget.ts:Budget(maximum)withcharge(amount, exhausted),tryCharge(amount),refund(amount),used,remaining. Unit tests inbudget.test.ts.WxapkgDirectoryBudgetandUnityFsDirectoryBudget(classes deleted; callers charge aBudget),ProtobufBudget,ModelReportBudget,WasmInterfaceBudget,NativeMatchingAdmission,CdpScriptSourceBudget(keep their public API, delegate arithmetic).budget-arithmetic: countsthis.#…remaining/retained/used… -=/+=outsidesrc/domain/budget.ts. Baseline 30 sites in 17 files; it can only shrink.InterfaceBuilderDecodeBudgetand the NativeAOT parser budget (both touched by refactor: report NativeAOT, Interface Builder and owned-MCP output limits through the shared limit owners #11194; next slice after it lands),ManagedDecodeBudget(transient admission needs a second counter),CudaMetadataBudgetand sqliteOutputBudget(their fields are named#readBytes/#bytes, which the guard pattern does not match yet), and the remaining baselined sites.Contract and boundary impact
Budget(domain); consumers listed above.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
src/domain/budget.test.ts(refused charge changes nothing; malformed charges -1, 1.5, NaN, MAX_SAFE_INTEGER+1; refund bound; malformed maximum). Existing limit tests of the migrated owners are unchanged and pass.NativeMatchingAdmission.checkpoint); no caller passes a negative charge today, so there is no user-visible failure to reproduce.Validation performed
npm run test:local -- src/domain/budget.test.ts src/application/native/NativeFunctionMatchingService.test.ts src/application/wasm/WasmInterfaceComparisonService.test.ts src/artifacts/UnityFsArtifactReader.boundaries.test.ts src/artifacts/UnityFsArtifactReader.test.ts src/artifacts/WxapkgArtifactReader.boundaries.test.ts src/artifacts/WxapkgArtifactReader.test.ts src/browser/history/protobuf/ProtobufCapture.test.ts src/browser/history/protobuf/ProtobufWire.test.ts src/wasm/WasmInterfaceBudget.test.ts— 10 files, 189 passed.npm run test:local -- src/browser/CdpPageCaptureScripts.test.ts src/browser/CdpElectronInspection.test.ts— 55 passed.npm run test:focused -- tests/acceptance/tools/nativeFunctionMatching.test.ts tests/acceptance/modelSafetensorsZipCollision.test.ts tests/acceptance/wasmInterfaceComparison.test.ts tests/boundary/mcp/wxapkgMcp.test.ts— 4 files, 13 passed.npm run check:fast— pass.node scripts/verify/architecture-guards.mjs— pass.Compatibility, safety, and release
Author readiness
Human owner:
Before merge
type(scope): outcome.