Skip to content

refactor(domain): charge resource allowances through one Budget owner - #11293

Merged
morluto merged 1 commit into
mainfrom
refactor/budget-owner
Nov 15, 2026
Merged

morluto merged 1 commit into
mainfrom
refactor/budget-owner

Conversation

@morluto

@morluto morluto commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Summary

Plan W6 step 5, first slice: one Budget owner (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: NativeMatchingAdmission subtracted before checking and did not check for a safe non-negative integer, so a negative charge would have silently refunded; CdpScriptSourceBudget had 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) with charge(amount, exhausted), tryCharge(amount), refund(amount), used, remaining. Unit tests in budget.test.ts.
  • Migrated (failures and messages unchanged): WxapkgDirectoryBudget and UnityFsDirectoryBudget (classes deleted; callers charge a Budget), ProtobufBudget, ModelReportBudget, WasmInterfaceBudget, NativeMatchingAdmission, CdpScriptSourceBudget (keep their public API, delegate arithmetic).
  • Guard budget-arithmetic: counts this.#…remaining/retained/used… -=/+= outside src/domain/budget.ts. Baseline 30 sites in 17 files; it can only shrink.
  • Not included: InterfaceBuilderDecodeBudget and 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), CudaMetadataBudget and sqlite OutputBudget (their fields are named #readBytes / #bytes, which the guard pattern does not match yet), and the remaining baselined sites.

Contract and boundary impact

  • Semantic owner and earliest changed stage: Budget (domain); consumers listed above.
  • Contribution scope fit and linked maintainer decision: not applicable (internal refactor).
  • CLI and MCP/tool-catalog contract: none. Limit errors, codes and messages are unchanged.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata, package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: 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.
  • Base reproduction or other evidence: source-derived (charge-then-check in NativeMatchingAdmission.checkpoint); no caller passes a negative charge today, so there is no user-visible failure to reproduce.
  • User-visible CLI/MCP output (if applicable): none.
  • Remaining proof gaps: none known.

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

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: a malformed charge in native matching is now refused instead of silently refunding.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-15T15:40:06.962467Z
We couldn’t complete this review. Comment @codex review to try again.
c3031c3 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The code appears safe to merge; no actionable issues were found.

Summary

Moves seven allowance owners onto Budget and adds a counted guard against new copies of the covered arithmetic pattern.

  • Seven resource limits now use one shared budget owner.
  • The architecture check now counts hand-written budget arithmetic.

Deferred by morluto: InterfaceBuilderDecodeBudget and the NativeAOT budget await #11194; ManagedDecodeBudget needs a second counter; CudaMetadataBudget and SQLite OutputBudget use fields outside the guard pattern. Other baselined sites remain for later slices.

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"]
Loading

Reviews (1) · Last reviewed commit: "refactor(domain): charge resource allowa..." · Reviewed by Greptile

@morluto
morluto merged commit 3d67404 into main Nov 15, 2026
7 checks passed
@morluto
morluto deleted the refactor/budget-owner branch November 15, 2026 15:47
@morluto morluto added the area: domain Domain logic, errors, and pure functions label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant