Repository navigation
refactor: prepare reusable reference document snapshots - #1147
Conversation
|
@codex review |
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.
Copilot review overview
🟡 Changes recommended
Snapshot-only scans can bypass temporary-root validation when reusing an initialized client runtime.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Refactors knowledge-base handling so scans can reuse a stable snapshot of extracted reference documents.
Changes:
- Separates document extraction from temporary-file preparation.
- Adds stable snapshot hashing and SDK reuse support.
- Reads classification documents directly from extracted text.
| File | Description |
|---|---|
sdk/typescript/src/knowledge-base.ts |
Adds reusable snapshots, hashing, and direct text access. |
sdk/typescript/src/api.ts |
Accepts and reuses prepared knowledge bases. |
sdk/typescript/src/classify-severity.ts |
Removes temporary-file staging during classification. |
sdk/typescript/tests-ts/knowledge-base.test.ts |
Tests snapshot immutability and change detection. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if (options.knowledgeBasePaths?.length || options.knowledgeBaseSnapshot) { | ||
| knowledgeBase = | ||
| this.#preparedKnowledgeBase ?? | ||
| (await prepareKnowledgeBase( | ||
| options.knowledgeBaseSnapshot ?? options.knowledgeBasePaths!, |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bd5b551d97
ℹ️ 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".
| sources: [...snapshot.sources], | ||
| snapshot, |
There was a problem hiding this comment.
Preserve snapshot use after source paths disappear
When a reference file or directory is renamed or removed after readKnowledgeBaseSnapshot()—for example during a multi-pass Deep Scan—this stages the captured text but propagates snapshot.sources into the existing source-inspection loop in api.ts, where gitMarkerRoot(source) calls realpath() and fails with ENOENT. The later pass therefore aborts instead of using its frozen inputs; snapshot-backed scans should use the already captured snapshot.protectedRoots for executable inspection rather than reopening the original sources.
Useful? React with 👍 / 👎.
| if (options.knowledgeBasePaths?.length || options.knowledgeBaseSnapshot) { | ||
| knowledgeBase = | ||
| this.#preparedKnowledgeBase ?? | ||
| (await prepareKnowledgeBase( | ||
| options.knowledgeBaseSnapshot ?? options.knowledgeBasePaths!, | ||
| signal, |
There was a problem hiding this comment.
Validate the temporary root for snapshot-backed scans
When knowledgeBaseSnapshot is supplied on a subsequent run of a client with a cached runtime and an explicit output directory, the temporary-root guard above is skipped because it only checks knowledgeBasePaths, but this branch still calls prepareKnowledgeBase() without a directory and therefore writes under tmpdir(). If TMPDIR is inside the scanned repository, snapshot-backed scans bypass the protection applied to path-backed scans and create writable temporary material in the protected tree; include snapshots in the temporary-root check or validate the actual staging root.
AGENTS.md reference: sdk/typescript/AGENTS.md:L22-L23
Useful? React with 👍 / 👎.
| sha256: createHash("sha256") | ||
| .update( | ||
| JSON.stringify({ | ||
| sources: snapshot.sources, | ||
| documents: snapshot.documents, |
There was a problem hiding this comment.
Hash snapshot contents incrementally
For a knowledge base whose aggregate extracted text exceeds V8's maximum single-string length, every document can still be decoded and written individually, but JSON.stringify() must concatenate the entire snapshot into one string and throws RangeError: Invalid string length. The previous implementation streamed documents to separate files, so this introduces an effective aggregate-size limit; frame and feed the sources, filenames, and contents into the hash incrementally instead.
AGENTS.md reference: sdk/typescript/AGENTS.md:L24-L25
Useful? React with 👍 / 👎.
alandelong-oai
left a comment
There was a problem hiding this comment.
Reviewed the reference-document snapshot change at bd5b551d97fcdb13b92f066397b6c4ad3bc170fa with three independent passes and root verification. Three existing issues remain reproducible:
- Deleted source paths still abort a scan using captured text.
- Snapshot-only staging skips the temporary-root check on a reused client; the equivalent path-based request correctly rejects the same synthetic setup.
- The document hash requires one aggregate JSON string. The exact serialization expression throws
RangeError: Invalid string lengthon Node 22 for 65 individually valid 8 MiB document strings.
All 28 focused knowledge-base and severity-classification tests pass. No model requests were made; no duplicate inline findings added.
098d055 to
6d05960
Compare
bd5b551 to
4df7d79
Compare
alandelong-oai
left a comment
There was a problem hiding this comment.
Three independent restack passes and root reconciliation are complete.
The snapshot-only temporary-directory protection is fixed: the public API probe now rejects a temporary directory inside the protected repository. The existing large-document hash failure remains in this own head: hashing still JSON.stringify's all documents into one string, so individually accepted documents whose combined text exceeds the engine string limit fail before scanning. The previously verified reproduction and unchanged hashing expression still apply.
Approval remains withheld. This review distinguishes the PR's own head from fixes verified later in the stack; it does not duplicate existing inline findings.
6d05960 to
b2da405
Compare
4df7d79 to
5791a46
Compare
alandelong-oai
left a comment
There was a problem hiding this comment.
Re-reviewed the real PR diff at 5791a46548c01fd47056639816dd56b69583a881. The patch is unchanged from the prior three-pass review. I reconciled the inherited changes in touched files and retained the prior verified findings and tests.
The snapshot-only temporary-directory protection is fixed: the public API probe now rejects a temporary directory inside the protected repository. The existing large-document hash failure remains in this own head: hashing still JSON.stringify's all documents into one string, so individually accepted documents whose combined text exceeds the engine string limit fail before scanning. The previously verified reproduction and unchanged hashing expression still apply.
Validation across touched paths at branch tip 06e75cfe: 1,356 SDK tests, 867 Python tests plus 100 subtests, and 108 MCP tests passed; builds, types, portable checks and installed-package checks passed. These are integration checks at the branch tip, not a claim that every intermediate PR or its CI is clean.
f9485fc to
5f41f33
Compare
657a8ba to
2f0fbe5
Compare
alandelong-oai
left a comment
There was a problem hiding this comment.
Retained the three independent passes for the identical patch and reconciled inherited touched-file changes at 5f41f33f6e41.
The combined-document string limit is fixed. The real implementation hashes 545,259,520 document bytes under Node, above its 536,870,888-character string limit, and the small escaped-text control preserves the prior persisted JSON digest. This clears the prior hold.
Current tip 355ec321 passed 75 report-projection tests, portable source checks, SDK build:ci and plugin build. The immediately preceding tip fec36f1d passed 1,360 SDK tests, 873 Python tests plus 100 subtests, 109 MCP tests, builds/types and the clean 600-entry installed-package check. Only report_projection.py and its test changed between those tips; SDK/MCP runtime files are byte-identical. Both descend from main 008a8b4d. These are integration checks, separate from own-head probes. No native Windows local run.
No serious outstanding finding introduced by this PR. Code review approval does not establish CI or merge readiness.
2f0fbe5 to
ead8344
Compare
5f41f33 to
5cd5510
Compare
alandelong-oai
left a comment
There was a problem hiding this comment.
Retained the three independent passes for the verified identical patch and reconciled inherited touched-file changes at 5cd55103317e.
No actionable introduced finding survives the independent reviews and root reconciliation of this exact patch and inherited changes in touched files.
Integrated tip 6ef8cbb8, based on 008a8b4d, passed 1,388 SDK tests, 879 Python tests plus 100 subtests, 109 MCP tests, portable checks, builds and the clean 600-entry installed-package check. These are branch-tip integration checks, separate from own-head probes; no local Windows execution was performed.
No serious outstanding finding introduced by this PR. Code approval is separate from CI and merge readiness.
ead8344 to
1dc2a39
Compare
5cd5510 to
080c4b6
Compare
alandelong-oai
left a comment
There was a problem hiding this comment.
Retained three prior independent passes for the verified identical patch and reconciled inherited touched-file changes at 080c4b65ad84.
No actionable introduced finding survives the independent reviews and root reconciliation of this exact patch and inherited changes in touched files.
Branch tip 3e0083d9, based on 008a8b4d, passed 1,392 SDK tests, 881 Python tests plus 100 subtests, 109 MCP tests, builds, portable source checks and the 600-entry installed-package check. These are tip checks, separate from own-head probes. No local Windows run was performed. The tip excludes the dependency update merged separately in #1184; combined validation remains outstanding.
No serious outstanding finding introduced by this PR. Code approval is separate from CI and merge readiness.
Consolidate approved Deep Scan changes into the parent topic branch.
f1786ee
into
mdangelo/codex/pr939-split-23-helper-settings

Part 24 of 46. Previous: #1146 · Next: #1148 · Stack index
Summary
Separate reference-document extraction from temporary-file staging. Capture the extracted text and compute a content hash so the later Deep Scan composition can reuse the same inputs across child scans.
Changes
Testing
Local checks for the implementation:
Reference-document tests passed 22 cases; a 512 MiB captured snapshot retained the same digest without constructing one combined string.
Checks against the complete stack passed: SDK and MCP typechecks, formatting, Ruff, the SDK build, portable plugin compatibility and its tests, focused recovery/accounting tests, and local-artifact package smoke using exact cached dependencies. The package check was not a clean registry install. See this PR’s Checks tab for CI results for its current commit.
Risk and rollout
Supported input formats stay the same. Ordinary scans use the new extraction path here; sharing one prepared snapshot across Deep Scan children is connected later. Reused snapshots retain the text captured when they were created.
Public disclosure review