[PR #7125] fix(reference): bound historical source imports #7660

Open
opened 2026-11-03 13:39:27 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/7125
Author: @abdulwasea89
Created: 10/25/2026
Status: 🔄 Open

Base: main ← Head: fix/reference-source-import-budget


📝 Commits (3)

  • 2573a9f fix(reference): bound historical source imports
  • 455026e fix(reference): keep partial import errors JSON-safe
  • 3cb7942 fix(reference): surface oversized Git metadata

📊 Changes

11 files changed (+332 additions, -13 deletions)

View changed files

📝 docs/cli.md (+5 -0)
📝 src/application/ReferenceSourceImportPolicy.ts (+27 -4)
📝 src/application/ReferenceSourceImportTypes.test.ts (+11 -2)
📝 src/application/ReferenceSourceImportTypes.ts (+31 -2)
📝 src/application/ReferenceSourceVcsAdapter.ts (+17 -2)
➕ src/reference/ReferenceSourceLimits.ts (+12 -0)
📝 src/reference/ReferenceSourceReaderEntries.ts (+8 -0)
📝 src/reference/ReferenceSourceReaderTypes.ts (+2 -1)
📝 tests/boundary/cli/referenceSourceImportStatus.test.ts (+133 -1)
📝 tests/boundary/filesystem/referenceSourceImport.test.ts (+58 -0)
📝 tests/boundary/filesystem/referenceSourceMetadataCleanup.test.ts (+28 -1)

📄 Description

Summary

Bound historical source imports so an oversized local tree is rejected before unbounded source or metadata reads.

Problem and expected behavior

Source-derived finding: the importer retained each file's bytes through tree traversal without a total byte cap. A large sparse regular file could drive excessive memory use. The regression uses sparse files to verify early rejection; an out-of-memory run was not performed.

Change and scope

  • Limit retained source bytes to 64 MiB across one import.
  • Limit each local .gitignore and Git metadata read to 1 MiB.
  • Return resource_constraint with the observed partial inventory, and document the limits.
  • This is a security fix within existing analysis boundaries; no new provider or target execution capability is added.

Contract and boundary impact

  • Semantic owner and earliest changed stage: reference source reader and local metadata admission.
  • Contribution scope fit and linked maintainer decision: ordinary security fix; advance scope decision not applicable.
  • CLI and MCP/tool-catalog contract: CLI import reports the existing canonical resource_constraint category; no MCP tool catalog change.
  • Provider, bridge, target-format, or platform compatibility: no provider or bridge change; oversized inputs now fail explicitly.
  • Evidence, artifact, provenance, or reconstruction contract: partial observed inventory is retained on source byte limit.
  • Target selection, authority, upstream behavior, and cleanup: caller-selected local directory; no new authority or side effects.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • 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.

Evidence and regression coverage

  • Added filesystem regressions for a sparse oversized file, aggregate bytes, and oversized .gitignore.
  • Added compiled CLI regressions for resource_constraint, exit code 1, and aggregate-limit failure after a file was read; error diagnostics retain path and size but omit file bytes so JSON output stays bounded.
  • The original unlimited read is established from source inspection; no OOM reproduction or before/after memory benchmark was run.
  • Windows-specific CLI cases were skipped on this Linux host. Large counts of tiny files are outside this byte-limit fix.

Validation performed

  • npm run test:focused -- tests/boundary/filesystem/referenceSourceMetadataCleanup.test.ts tests/boundary/cli/referenceSourceImportStatus.test.ts — 15 passed, 2 Windows skips after the Git metadata fix.
  • npm run check:fast — passed after the Git metadata fix.
  • npm run docs:check — passed with pinned Node 24.22.1 outside the sandbox.
  • npm run check:pr — stopped after 19 minutes. Its full parallel test run reported 3 failures in modelArtifactCli.test.ts and javascriptWorkerUrlCli.test.ts; rerunning those two files alone passed all 25 tests. The full gate did not complete.

Review response

  • Greptile identified that aggregate-limit errors included previously read file bytes in JSON diagnostics, creating an oversized response. The error projection now includes only each read file's path, kind, status, and size; the compiled CLI regression verifies that an aggregate-limit error after a prior read produces small, valid JSON.
  • Greptile identified that oversized Git metadata became a successful unknown VCS result. The adapter now returns the typed limit failure; filesystem and compiled CLI regressions verify resource_constraint is reported.

Compatibility, safety, and release

  • Previously accepted source trees over the new limits now fail with recovery guidance; users can exclude large files and retry.
  • No real provider run is applicable. The full check:pr gate and memory benchmark were not run.
  • No issue is linked; this draft follows the source-derived finding and fix in the current investigation.

Author readiness

Human owner: @abdulwasea89

  • 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

  • Human owner has completed readiness declarations.
  • Required checks and maintainer review have completed.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/7125 **Author:** [@abdulwasea89](https://github.com/abdulwasea89) **Created:** 10/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/reference-source-import-budget` --- ### 📝 Commits (3) - [`2573a9f`](https://github.com/morluto/rea/commit/2573a9fc9994f39d27b9a1fc68ab6e18d0a65729) fix(reference): bound historical source imports - [`455026e`](https://github.com/morluto/rea/commit/455026e01fe428042a9c9d21393c7cba0a2baf42) fix(reference): keep partial import errors JSON-safe - [`3cb7942`](https://github.com/morluto/rea/commit/3cb7942acec9c1ae4a46e71487ceda80a1df3def) fix(reference): surface oversized Git metadata ### 📊 Changes **11 files changed** (+332 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `docs/cli.md` (+5 -0) 📝 `src/application/ReferenceSourceImportPolicy.ts` (+27 -4) 📝 `src/application/ReferenceSourceImportTypes.test.ts` (+11 -2) 📝 `src/application/ReferenceSourceImportTypes.ts` (+31 -2) 📝 `src/application/ReferenceSourceVcsAdapter.ts` (+17 -2) ➕ `src/reference/ReferenceSourceLimits.ts` (+12 -0) 📝 `src/reference/ReferenceSourceReaderEntries.ts` (+8 -0) 📝 `src/reference/ReferenceSourceReaderTypes.ts` (+2 -1) 📝 `tests/boundary/cli/referenceSourceImportStatus.test.ts` (+133 -1) 📝 `tests/boundary/filesystem/referenceSourceImport.test.ts` (+58 -0) 📝 `tests/boundary/filesystem/referenceSourceMetadataCleanup.test.ts` (+28 -1) </details> ### 📄 Description ## Summary Bound historical source imports so an oversized local tree is rejected before unbounded source or metadata reads. ## Problem and expected behavior Source-derived finding: the importer retained each file's bytes through tree traversal without a total byte cap. A large sparse regular file could drive excessive memory use. The regression uses sparse files to verify early rejection; an out-of-memory run was not performed. ## Change and scope - Limit retained source bytes to 64 MiB across one import. - Limit each local `.gitignore` and Git metadata read to 1 MiB. - Return `resource_constraint` with the observed partial inventory, and document the limits. - This is a security fix within existing analysis boundaries; no new provider or target execution capability is added. ## Contract and boundary impact - Semantic owner and earliest changed stage: reference source reader and local metadata admission. - Contribution scope fit and linked maintainer decision: ordinary security fix; advance scope decision not applicable. - CLI and MCP/tool-catalog contract: CLI import reports the existing canonical `resource_constraint` category; no MCP tool catalog change. - Provider, bridge, target-format, or platform compatibility: no provider or bridge change; oversized inputs now fail explicitly. - Evidence, artifact, provenance, or reconstruction contract: partial observed inventory is retained on source byte limit. - Target selection, authority, upstream behavior, and cleanup: caller-selected local directory; no new authority or side effects. - Generated metadata, package, or installation impact: none. Expected effects: - [x] Read existing files or captured data. - [x] Launch or attach to a process. - [x] Inject instrumentation or run scripts/code. - [x] Change process memory, registers, files, or configuration. - [x] Contact network services. - [x] Recover protected code or work around protections. ## Evidence and regression coverage - Added filesystem regressions for a sparse oversized file, aggregate bytes, and oversized `.gitignore`. - Added compiled CLI regressions for `resource_constraint`, exit code 1, and aggregate-limit failure after a file was read; error diagnostics retain path and size but omit file bytes so JSON output stays bounded. - The original unlimited read is established from source inspection; no OOM reproduction or before/after memory benchmark was run. - Windows-specific CLI cases were skipped on this Linux host. Large counts of tiny files are outside this byte-limit fix. ## Validation performed - `npm run test:focused -- tests/boundary/filesystem/referenceSourceMetadataCleanup.test.ts tests/boundary/cli/referenceSourceImportStatus.test.ts` — 15 passed, 2 Windows skips after the Git metadata fix. - `npm run check:fast` — passed after the Git metadata fix. - `npm run docs:check` — passed with pinned Node 24.22.1 outside the sandbox. - `npm run check:pr` — stopped after 19 minutes. Its full parallel test run reported 3 failures in `modelArtifactCli.test.ts` and `javascriptWorkerUrlCli.test.ts`; rerunning those two files alone passed all 25 tests. The full gate did not complete. ## Review response - Greptile identified that aggregate-limit errors included previously read file bytes in JSON diagnostics, creating an oversized response. The error projection now includes only each read file's path, kind, status, and size; the compiled CLI regression verifies that an aggregate-limit error after a prior read produces small, valid JSON. - Greptile identified that oversized Git metadata became a successful `unknown` VCS result. The adapter now returns the typed `limit` failure; filesystem and compiled CLI regressions verify `resource_constraint` is reported. ## Compatibility, safety, and release - Previously accepted source trees over the new limits now fail with recovery guidance; users can exclude large files and retry. - No real provider run is applicable. The full `check:pr` gate and memory benchmark were not run. - No issue is linked; this draft follows the source-derived finding and fix in the current investigation. ## Author readiness Human owner: @abdulwasea89 - [x] 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. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] Human owner has completed readiness declarations. - [x] Required checks and maintainer review have completed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#7660
No description provided.