Repository navigation
fix(analysis): append large inventories without exceeding call-argument limits - #8568
kaoru0822-kitauji wants to merge 10 commits into
Conversation
…nt limits Spreading a data-sized collection into push, splice, Math.max/min or a variadic helper turns each element into a call argument. Above roughly 125,000 elements V8 runs out of stack, so admitted inputs failed with RangeError: managed/native verification exited with execution_failure, import-reference-source with UNKNOWN, and DirectoryArtifactReader and JavaScript export-binding selection threw. Add appendAll in src/domain/arrayAppend.ts, which appends in place and in order without expanding elements into arguments, and use it at every production push/splice spread site. Replace the data-sized Math.max/min and variadic loader-queue spreads with loops or array parameters. Add the rea/no-bulk-append-spread lint rule so the pattern cannot return; the few structurally bounded spreads keep disable comments naming their bound. Fixes #8545 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review Summary: ✅ CompletedThis 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. |
[Medium impact] The PR appears safe to merge; no actionable issue remains in the reviewed changes. SummaryReplaces data-sized call spreads with
Reviews (2) · Last reviewed commit: "fix(lint): see through type-only wrapper..." · Reviewed by Greptile |
rea/no-bulk-append-spread unwrapped only optional chains, so `target.push!(...items)`, `(target.push as T)(...items)`, satisfies and angle-bracket assertions reached the call with a non-member callee and were not reported. Strip TypeScript wrapper and grouping nodes before matching the method, and cover those forms and wrapped receivers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Hey @kaoru0822-kitauji, thanks for this! The fix looks good. What's left: it has merge conflicts with main in |
Keep main's newer observations and route every data-sized append through appendAll so the bulk-spread limit still holds.
Keep appendAll at the merged Bun and capture call sites, and use the recoverable reader limits from main.
A capture that does not record selected-path kind must not gain an unknown kind on the export plan. An oversized Windows Ghidra endpoint whose close fails stays an invalid endpoint and keeps that cleanup.
The export result lists task summaries on tasks. The seed-policy check was still looking for a single task object.
|
Maintenance claim: this Codex session ( |
What broke: Several owners appended a data-sized collection with
target.push(...items)(or spread it intosplice,Math.max/Math.minor a variadic helper). Above roughly 125,000 elements V8 runs out of stack for the arguments, so valid large inputs failed withRangeError: Maximum call stack size exceeded: managed/native verification exited withexecution_failure, andimport-reference-sourceexited withUNKNOWN.Fix: Add one domain helper,
appendAll(target, items), which appends in place and in order without turning elements into arguments. Use it at every productionpush/splicespread site, remove the data-sizedMath.max/Math.minand variadic spreads, and add the lint rulerea/no-bulk-append-spreadso the pattern cannot come back.Risk: Low per site. Each edit is mechanical, the append order is the same, and appending an array to itself still duplicates it. The diff is wide (72 production files), so merge conflicts with in-flight PRs are the main cost. One line overlaps the draft #8457 (
InvestigationEvidence.ts).Summary
Fixes #8545.
Inputs that existing budgets admit now complete instead of overflowing the engine stack. A real resource allowance still refuses with its typed failure and its actual bound. This change adds no new inventory cap.
Problem and expected behavior
Spreading an array into a call passes every element as a separate argument, so array cardinality becomes argument count. At about 125,000 arguments V8 throws
RangeError; I measured 124,517 forpushat top level under Node 26.5. On base:verify-managed-native-boundarieswith authenticated Mach-O Evidence holding 130,000 exports exits 1 with genericexecution_failureandrea doctorguidance (collectNativeSymbols).import-reference-source <root> --detail summary --jsonon a directory with 130,000 empty child directories exits 1 with{"code":"UNKNOWN","message":"Maximum call stack size exceeded"}(ReferenceSourceReaderEntries).DirectoryArtifactReader.entrieswith a 130,000-entry allowance lists every child, then throwsRangeErrorwhile it schedules them (DirectoryArtifactReader.ts:301).semanticRuntimeExportValueSources) throws onexport const [v0, …, v129999] = …when the Electron app-path predicate inspects the export.Expected: these inputs complete within their existing budgets, and smaller selected allowances still refuse with a typed failure.
Change and scope
src/domain/arrayAppend.ts:appendAll(target, items). It reads the length once and pushes element by element. It makes no intermediate copy and has the same order and self-append behavior as a spread.push(...x)site (about 110) and the five Ghidrasplice(0, n, ...x)replacements, which now use a localreplaceLimitations. Data-sized sites include native symbols, directory scheduling, IDA/JADX pages, web-bundle observations, JavaScript fingerprints and loader queues, dylib edges and process trees. Converting the small sites as well keeps the rule simple and stops the bound from depending on producers outside the call site.for…ofloop;enqueue/enqueueAtloader queue injavascriptSemanticRequireOrigin.ts, which now takes an array;Math.max/Math.minover observed tool groups and write history inenvironmentManifestRules.ts,EnvironmentStateWriteSimulation.tsandenvironmentStateWriteAttribution.ts, now loops.rea/no-bulk-append-spread(scripts/lint/rules/): it rejects spread arguments topush/unshift/spliceinsrc/**/*.ts, excluding tests and fixtures. It looks through optional chains, parentheses and TypeScript wrappers (!,as,satisfies,<T>) around the callee. The rule is documented indocs/testing.md.unshiftof symlink-target segments indyldPaths.tsandElectronFusePath.ts, where readlink text is bounded by the host's PATH_MAX;Uninstall.tsunshift, one item per literal name;artifactPathSyntax.tsand the GDB string decoder, at most four UTF-8 bytes per code point.Math.min/Math.maxover at most 128 FAT slices, known Bun record sizes, repo-authored tool schemas, the ESP chip table and Devicetree two-element tuples;String.fromCharCodeover a 255-byte DfuSe field, a FIT prefix of at most 4,096 bytes, an S0 header of at most 255 bytes, and Android JNI 4,096-unit chunks;join/resolvesegments.*.fixture.tsfiles are test-controlled and unchanged.Not included: #8455 (retained Evidence closure). Its line is converted here because the lint rule covers it, but its MCP regression stays in the draft #8457.
Contract and boundary impact
appendAlllives insrc/domain, so every layer can use it.Expected effects:
Evidence and regression coverage
Tests added or updated (all regressions use 130,000 items, about 4% above the measured limit):
tests/boundary/cli/managedNativeVerificationLargeInventory.test.ts: public CLI with file input, 130,000 exports against the 3-export control. Summary and P/Invoke outcomes are identical apart from the native Evidence id, and the result isverified:1.tests/boundary/filesystem/wideDirectoryTraversal.test.ts: one shallow tree of 130,000 empty directories, created once and removed inafterAll, shared by both traversal owners.DirectoryArtifactReader: a 130,000-entry allowance lists every child. A cancellation requested after the wide listing is reported ascancelledat the next checkpoint, which comes after the children are scheduled. A 2,000-entry allowance still refuses withlimit,examinedEntries: 2000,maximumEntries: 2000.readReferenceSource: all 130,000 directories are read.tests/boundary/javascript/wideExportBindings.test.ts: production parse plus static analysis of a 130,000-binding export gives the same app-path change as a 3-binding control. It runs in the forkedboundaryproject because the analyzer runs on a child process main-thread stack. Worker-thread projects such asdomainhave a 4 MiB stack and do not reproduce it.tests/evaluation/bulkAppendSpreadRule.test.ts: 24 rule cases, including callee wrapped in!,as,satisfiesor<T>.src/domain/arrayAppend.test.ts: order and self-append.Base reproduction, with base sources and a base
npm run compile:execution_failure;RangeError: Maximum call stack size exceeded;RangeErrorwith the basejavascriptModuleDeclaration.ts.execution_failureandUNKNOWNoutputs.Cost of the large-input tests (local macOS arm64, APFS, Node 26.5, one worker; peak = maximum RSS of the largest process; an empty vitest run is about 211 MB):
User-visible CLI/MCP output: the managed and reference-import commands now exit 0 with their normal results. For example, the 130,000-directory
import-reference-source --detail summaryreportscounts.directories: 130000.Remaining proof gaps:
entry_count: 130000.REA_MCP_MAX_INPUT_ELEMENTS. Under the default allowance it refuses before execution with a typedresource_constraint, so MCP was not run for the large case.Boundary regressions: large or wide inventories at the producer, a typed capacity refusal at the selected bound, and cancellation after the wide stage. No lifecycle ownership changed.
Validation performed
npm run check:fast(typecheck, lint, module boundaries): pass, re-run after mergingorigin/mainat85013da0c. The rule reports no new sites in the merged sources.npx oxlint --quiet: no errors.npm run format:check: pass.npm run test:changed(source projects, 685 files): 14,242 pass, 4 fail. The same 4 tests fail identically on base sources on this machine:src/setupEnvironment.test.ts×2,ZipArtifactReaderzstd truncated frame, andJavaScriptRuntimeScope.cancellation.environmentServeRemediationgetsEADDRNOTAVAILinstead ofENOTFOUNDbecause the local resolver answers.invalid, andjavascriptWorkerFinalizationCancellation×2 hit the known Node 26stripTypeScriptTypestransformrejection.npm run test:local -- tests/conformance/readmeConsistency.test.ts: 9 pass.npm run docs:check, because under local Node 26stripTypeScriptTypesrejects modetransform. CI runs it on the pinned Node 24.Compatibility, safety, and release
Author readiness
Human owner: @kaoru0822-kitauji
Before merge
type(scope): outcome.🤖 Generated with Claude Code