Repository navigation
fix(managed): charge retained member facts instead of decoding bounds - #1768
Conversation
inspect_managed_members returned no types or methods for ordinary assemblies: Newtonsoft.Json 13.0.3 (netstandard2.0, 705 KB) exceeded the 64 MiB representation budget. Each method body reserved 256 bytes per IL byte and each signature 256 bytes per blob byte before decoding, and those worst-case bounds were never returned, so the budget scaled with total IL size rather than with the retained output. The final projection admission also charged every decoded string at six bytes per character and every scalar at 32 bytes, about eight times its JSON size. Bound IL, exception-clause and signature decoding with a transient admission that does not consume capacity, then reserve the decoded body or signature that is actually retained. Projection admission now charges the exact UTF-8 JSON bytes of decoded strings, keys and scalars; escaped and multibyte text still counts at its encoded size. Newtonsoft.Json now yields 496 types, 4185 methods and 18846 call edges. Assemblies whose retained facts exceed the budget, such as the 2.3 MB System.Private.ServiceModel 4.7.0, remain unavailable.
Codex Review SummaryThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 70a862f39a
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Review follow-up. A method's IL bound and its exception-section bounds were each checked against the same remaining capacity although their bookkeeping is live at the same time, so 40 MiB of IL plus 40 MiB of exception clauses passed a 64 MiB budget. Transient admissions now accumulate until the method body or signature is built, and reserve respects bounds that are still live. Projection admission also serialized each decoded string to measure it, which could allocate about six times a near-limit string before the check. It now counts the exact escaped UTF-8 bytes without building the JSON text.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b82218de32
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Review follow-up. Released IL bounds no longer stand in for the call and field-access records that edges() derives from anchors. Each record is now admitted before the graph grows further, so a crafted assembly cannot materialize the whole derived graph before the representation guard fails.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dd64d3c56f
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Review follow-up. The caller name of call and field-access records was interpolated per anchor before any admission saw it. It is now built once per method, after its exact JSON size, counted from the type and member names, has been admitted.
|
Thanks for reworking the managed metadata budget, @flitzrrr. It now checks transient decoding bounds without consuming the retained-output budget, then charges the projection that is actually kept. That lets the PR’s 705 KB Newtonsoft.Json reproduction return 496 types and 4,185 methods under the existing cap. |
Summary
inspect_managed_membersreturns no types, methods or call edges for ordinary mid-size assemblies. For example,Newtonsoft.Json13.0.3 (lib/netstandard2.0, 705,296 bytes) reportscoverage.state: "unavailable"with "Managed metadata exceeds the 67108864 byte representation budget". The budget was charged with decoding upper bounds that were never returned, rather than with the facts that are actually retained. After this change the same file yields 496 types, 4,185 methods and 18,846 call edges.I did not open a separate issue because the reproduction uses a public NuGet package and is included below.
Problem and expected behavior
Before decoding, every method body reserved 256 bytes per IL byte (
ManagedMethodBodyReader), every exception section 256 bytes per clause, and every member signature 256 bytes per blob byte (budgetedSignature). These reservations bound transient decoding bookkeeping, but they stayed charged for the whole inspection. The budget therefore scaled with the total IL and signature size, not with the output. Instrumenting the budget on the base revision for the Newtonsoft.Json file above showed 41.0 MiB from method-body bounds and 10.8 MiB from signature bounds, before any projection.The final projection admission (
admitManagedProjection) also charged every decoded string at six bytes per UTF-16 unit, every key at the same rate, and every scalar at 32 bytes. That is roughly eight times its JSON size.Expected: the budget limits what the inspection retains and projects, so assemblies whose facts fit are inspected completely.
Change and scope
ManagedDecodeBudget.admitTransientchecks a decoding bound against the remaining capacity without consuming it.reservenow builds on it.admitTransientfor their bounds, then reserve the decoded body or signature that is retained, throughadmitManagedProjection.admitManagedProjectioncharges the exact UTF-8 JSON bytes of decoded strings, keys and scalars. Escaped control characters and multibyte text still count at their encoded size. Heap-string reservations made before decoding keep their worst-case bound because the content is unknown at that point.Not included: when the retained facts genuinely exceed the budget, members are still reported as unavailable rather than partial.
System.Private.ServiceModel4.7.0 (2.3 MB) remains such a case.inspect_managed_artifactsimilarly labels a budget stop as partial without facts. Returning partial member inventories would change whatcompare_managed_membersand the managed application graph can assume, so it deserves its own change.Contract and boundary impact
src/dotnet/ManagedDecodeBudget.ts,ManagedMethodBodyReader.ts,ManagedMemberInstructionDecoder.ts,ManagedMemberRows.ts).unavailable.docs/public/product-catalog.json), package, or installation impact: none.Evidence and regression coverage
src/dotnet/ManagedMemberInspector.test.ts: a fixture method with 200,001 IL bytes plus an 80,003-byte signature. Each bound fits alone, but together they exceeded 64 MiB on the base revision.src/dotnet/ManagedDecodeBudget.test.ts: exact charging of a 12 MiB ASCII string; escaped and multibyte text still exceeds the budget at its encoded size.unavailable) and pass with this change.rea inspect-managed-members ~/.nuget/packages/newtonsoft.json/13.0.3/lib/netstandard2.0/Newtonsoft.Json.dll --format jsontypes: [], methods: [], call_edges: [], coverage: { state: "unavailable", issues: [{ code: "resource-limit", detail: "Managed metadata exceeds the 67108864 byte representation budget" }] }coverage.state: "partial"with no issues. The partial state comes from member signatures or bodies that are not fully decoded, as before.For evidence-bearing changes:
Validation performed
On macOS (Darwin 27.0, Apple Silicon), Node 24.18.0:
npm run test:fast— 376 files, 4272 passed, 7 skippednpm run test:focused -- tests/boundary/providers/managed/*.test.ts tests/conformance/providers/managed/managedNativeVerification.test.ts tests/boundary/mcp/managedMcp.test.ts tests/acceptance/managedCliOutput.test.ts— 9 files, 44 passednpm run check— passednpm run verify:test-discovery— 814 test files discovered exactly oncenpm run build:cachedand the CLI run above — passedReview follow-up
npx vitest run src/dotnet— 92 passed; managed boundary, MCP and acceptance — 44 passed;npm run check:fast— passed. Newtonsoft.Json and the 730 KB assembly still return every member.Compatibility, safety, and release
Review checklist
type(scope): outcome.🤖 Generated with Claude Code