Skip to content

refactor: prepare reusable reference document snapshots - #1147

Merged
mldangelo-oai merged 2 commits into
mdangelo/codex/pr939-split-23-helper-settingsfrom
mdangelo/codex/pr939-split-24-reference-documents
Oct 4, 2026
Merged

mldangelo-oai merged 2 commits into
mdangelo/codex/pr939-split-23-helper-settingsfrom
mdangelo/codex/pr939-split-24-reference-documents

Conversation

@mldangelo-oai

@mldangelo-oai mldangelo-oai commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

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

  • Capture document text with source paths and protected roots, and allow SDK scans to stage a supplied snapshot. Snapshot-only requests on reused clients use the existing temporary-storage path checks.
  • Read severity-classification documents directly from the shared extractor without staging temporary text files.
  • Check cancellation while extracting PDF pages.
  • Hash captured documents incrementally while preserving the existing digest format, avoiding one combined string for the complete snapshot.

Testing

Local checks for the implementation:

  • The reused-client snapshot-only temporary-root regression passed on the implementation checkout.

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

  • No customer, partner, prospect, or user identities, data, or identifying details are included.
  • No credentials, personal data, private source, scan findings, or nonpublic links or tickets are included.
  • I reviewed the branch name, title, description, commits, changes, comments, logs, screenshots, attachments, and links for public disclosure.

@mldangelo-oai

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-04T17:36:21.221446Z fa46636 Draft marked ready
🔒 Security Review ⚠️ Failed 2026-10-04T17:36:27.528316Z fa46636 Draft marked ready
ℹ️ 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Snapshot-only scans can bypass temporary-root validation when reusing an initialized client runtime.

Review effort: Balanced
Findings: 1 High severity

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.

Comment thread sdk/typescript/src/api.ts
Comment on lines +1241 to +1245
if (options.knowledgeBasePaths?.length || options.knowledgeBaseSnapshot) {
knowledgeBase =
this.#preparedKnowledgeBase ??
(await prepareKnowledgeBase(
options.knowledgeBaseSnapshot ?? options.knowledgeBasePaths!,

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +146 to +147
sources: [...snapshot.sources],
snapshot,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread sdk/typescript/src/api.ts
Comment on lines +1241 to +1246
if (options.knowledgeBasePaths?.length || options.knowledgeBaseSnapshot) {
knowledgeBase =
this.#preparedKnowledgeBase ??
(await prepareKnowledgeBase(
options.knowledgeBaseSnapshot ?? options.knowledgeBasePaths!,
signal,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread sdk/typescript/src/knowledge-base.ts Outdated
Comment on lines +149 to +153
sha256: createHash("sha256")
.update(
JSON.stringify({
sources: snapshot.sources,
documents: snapshot.documents,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@mldangelo-oai mldangelo-oai changed the title refactor: read reference documents once per scan refactor: prepare reusable reference document snapshots Oct 1, 2026

@faizan-oai faizan-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the immutable reference-document snapshot and protected-root handling at bd5b551. Knowledge-base tests pass on the integrated stack; current-head CI passed. The separate native resume fallback issue is tracked on #1159/#1163.

@alandelong-oai alandelong-oai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the reference-document snapshot change at bd5b551d97fcdb13b92f066397b6c4ad3bc170fa with three independent passes and root verification. Three existing issues remain reproducible:

All 28 focused knowledge-base and severity-classification tests pass. No model requests were made; no duplicate inline findings added.

@mldangelo-oai
mldangelo-oai force-pushed the mdangelo/codex/pr939-split-23-helper-settings branch from 098d055 to 6d05960 Compare October 1, 2026 23:44
@mldangelo-oai
mldangelo-oai force-pushed the mdangelo/codex/pr939-split-24-reference-documents branch from bd5b551 to 4df7d79 Compare October 1, 2026 23:44

@alandelong-oai alandelong-oai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mldangelo-oai
mldangelo-oai force-pushed the mdangelo/codex/pr939-split-23-helper-settings branch from 6d05960 to b2da405 Compare October 2, 2026 00:36
@mldangelo-oai
mldangelo-oai force-pushed the mdangelo/codex/pr939-split-24-reference-documents branch from 4df7d79 to 5791a46 Compare October 2, 2026 00:36

@alandelong-oai alandelong-oai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mldangelo-oai
mldangelo-oai force-pushed the mdangelo/codex/pr939-split-24-reference-documents branch 2 times, most recently from f9485fc to 5f41f33 Compare October 2, 2026 01:56
@mldangelo-oai
mldangelo-oai force-pushed the mdangelo/codex/pr939-split-23-helper-settings branch from 657a8ba to 2f0fbe5 Compare October 2, 2026 01:56

@alandelong-oai alandelong-oai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mldangelo-oai
mldangelo-oai force-pushed the mdangelo/codex/pr939-split-23-helper-settings branch from 2f0fbe5 to ead8344 Compare October 2, 2026 02:47
@mldangelo-oai
mldangelo-oai force-pushed the mdangelo/codex/pr939-split-24-reference-documents branch from 5f41f33 to 5cd5510 Compare October 2, 2026 02:47

@alandelong-oai alandelong-oai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mldangelo-oai
mldangelo-oai force-pushed the mdangelo/codex/pr939-split-23-helper-settings branch from ead8344 to 1dc2a39 Compare October 2, 2026 03:52
@mldangelo-oai
mldangelo-oai force-pushed the mdangelo/codex/pr939-split-24-reference-documents branch from 5cd5510 to 080c4b6 Compare October 2, 2026 03:52

@alandelong-oai alandelong-oai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@mldangelo-oai
mldangelo-oai marked this pull request as ready for review October 4, 2026 17:35
@mldangelo-oai
mldangelo-oai merged commit f1786ee into mdangelo/codex/pr939-split-23-helper-settings Oct 4, 2026
1 check passed
@mldangelo-oai
mldangelo-oai deleted the mdangelo/codex/pr939-split-24-reference-documents branch October 4, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants