Repository navigation
refactor(deep-scan)!: reuse finding matching and save merge progress - #1158
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
Checkpoint writes can race terminal operations, external cancellation is no longer observed, and recovered child coverage may be omitted.
Review effort: Balanced
Findings: 2
Open (3)
What changed in this PR
Introduces version-3 Deep Scan checkpoints and resumable, content-addressed merge state.
Changes:
- Separates aggregates, source evidence, and revisions into restorable artifacts.
- Reworks merge reconciliation, recovery, publication, and cost accounting.
- Expands TypeScript and Python recovery tests and merge evaluation.
| File | Description |
|---|---|
sdk/typescript/tests-ts/support/api-client.ts |
Adds batched restore mock. |
sdk/typescript/tests-ts/scan-projection-fixtures.test.ts |
Updates merge fixture validation. |
sdk/typescript/tests-ts/scan-merge.test.ts |
Tests reconciliation and persistence. |
sdk/typescript/tests-ts/scan-merge-reconciliation.test.ts |
Tests schema and evidence isolation. |
sdk/typescript/tests-ts/runtime.test.ts |
Tests safe batched restoration. |
sdk/typescript/tests-ts/merge-eval.test.ts |
Updates merge quality tests. |
sdk/typescript/tests-ts/deep-scan-composition.test.ts |
Reworks scheduler recovery coverage. |
sdk/typescript/tests-ts/deep-scan-checkpoint.test.ts |
Tests version-3 metadata. |
sdk/typescript/src/scan-merge.ts |
Implements aggregate reconciliation and storage. |
sdk/typescript/src/runtime.ts |
Adds batched artifact restoration. |
sdk/typescript/src/deep-scan.ts |
Refactors scheduling and checkpoint recovery. |
sdk/typescript/src/deep-scan-lifecycle.ts |
Simplifies pass lifecycle state. |
sdk/typescript/src/deep-scan-checkpoint.ts |
Defines version-3 checkpoints. |
sdk/typescript/scripts/merge-eval/run.ts |
Updates merge evaluation runner. |
sdk/typescript/scripts/merge-eval/README.md |
Documents revised evaluation. |
sdk/typescript/scripts/merge-eval/grade.ts |
Grades materialized findings. |
sdk/typescript/scripts/merge-eval/fixtures.ts |
Revises merge fixtures. |
plugins/codex-security/tests/workbench_test_support.py |
Adds version-3 helpers. |
plugins/codex-security/tests/test_workbench_scan_composition.py |
Tests metadata-only loading. |
plugins/codex-security/tests/test_workbench_current_draft.py |
Tests source hydration. |
plugins/codex-security/tests/test_scan_projection.py |
Updates coverage helper usage. |
plugins/codex-security/scripts/workbench_scan_history.py |
Adds composition completion validation. |
plugins/codex-security/scripts/workbench_saved_results.py |
Materializes and recovers aggregates. |
plugins/codex-security/scripts/workbench_composition.py |
Loads version-3 composition state. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| write_scan_local_bytes( | ||
| scan_dir, f"checkpoints/{hashlib.sha256(payload).hexdigest()}.json", payload | ||
| ) |
| await input.writer.restoreMany([ | ||
| ...revisions, | ||
| ...(contents === undefined || aggregatePath === savedAggregatePath | ||
| ? [] | ||
| : [{ path: aggregatePath!, contents: Buffer.from(contents) }]), |
There was a problem hiding this comment.
Reproduced against the actual SDK/workbench fixture at stack tip 835f0d1. With one worker, I canceled the parent through a separate cancel-scan command just after the first child's complete-scan, leaving the caller signal un-aborted. After cancellation returned, the coordinator changed checkpoint.json from mergedScanIds: [], aggregatePath: null to a checkpoint containing the child ID and a new aggregate path. Publication then failed because the parent was canceled. The raw restoreMany write therefore really does modify the stopped parent after its stop operation completes. This probe does not claim that another child launched; it isolates the checkpoint-write violation.
| const executionSignal = AbortSignal.any([signal, externalStop.signal]); | ||
| const discoverySignal = AbortSignal.any([ | ||
| executionSignal, | ||
| deadlineController.signal, | ||
| ]); |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3eaca35c4b
ℹ️ 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".
| await workbench([ | ||
| "update-progress", | ||
| "--scan-id", | ||
| scanId, | ||
| "--phase", |
There was a problem hiding this comment.
Restore continuous parent-status polling
When another process cancels or fails the parent scan, input.signal is not aborted, and this one-shot update-progress call is the only remaining parent-status interaction—its failure is ignored. Since checkpoint saves now use the filesystem writer directly and register_cli_scan does not require a Deep Scan parent to still be running, a resumed or active coordinator can continue launching children and modifying artifacts after the parent has stopped or been sealed. Preserve the previous ongoing status check, or otherwise abort when the persisted parent stops.
AGENTS.md reference: sdk/typescript/AGENTS.md:L23-L25
Useful? React with 👍 / 👎.
| const representative = | ||
| accepted[0] ?? presentations.get(group.representativeId)!; |
There was a problem hiding this comment.
Use the selected representative for revised findings
When a later pass supplies a corrected duplicate of an already accepted finding and the merge decision selects that new source as representativeId, this expression always chooses the old accepted presentation instead. presentGroup only unions summaries, repairs, locations, tests, controls, and severity, so corrected fields such as confidence, taxonomy, and attack-path details remain stale even though the model explicitly selected the newer representative. Base the revised presentation on the selected representative while copying only the established identity fields that must remain stable.
Useful? React with 👍 / 👎.
| onCost: (cost) => { | ||
| input.onCost(pass.directory, cost); | ||
| }, |
There was a problem hiding this comment.
Persist the final cost when a resumed child fails
When an already registered child is resumed and then fails, ScanCostTracker.stop() reports its final snapshot through this callback, but the value is now forwarded without being retained. The API intentionally skips its own fail-scan persistence when resumeScanId is set, while runPass subsequently invokes fail-scan without --cost-json and rereads a null receipt. Consequently a required-cost Deep Scan stops with ScanCostTrackingError despite having measured the cost, and an interrupted optional-cost run cannot recover that usage. Retain the final callback value and persist it at the resumed-child failure boundary.
AGENTS.md reference: sdk/typescript/AGENTS.md:L25-L25
Useful? React with 👍 / 👎.
3eaca35 to
c44918f
Compare
5b80d58 to
7a8a356
Compare
c44918f to
d7ded9c
Compare
7a8a356 to
272b793
Compare
d7ded9c to
1ef7e65
Compare
faizan-oai
left a comment
There was a problem hiding this comment.
Holding approval for writes after external cancellation. In an actual SDK/workbench fixture, I canceled the parent through a separate workbench command after its first child completed, without aborting the caller signal. The coordinator then rewrote the stopped parent's checkpoint, adding the child to mergedScanIds and setting a new aggregatePath, before publication rejected the canceled parent. The persisted stop is therefore not respected at the checkpoint write boundary. Details added to the existing thread. Separately, the new matching/comparison/composition tests pass in the integrated stack.
5477f91 to
253cbca
Compare
alandelong-oai
left a comment
There was a problem hiding this comment.
Reviewed the updated head 253cbca02d7b1ac8347983c6c2ed497451d7d171 with all three independent reviewers and root verification. Approval is withheld for these remaining issues:
- Checkpoint writes bypass continuation and stop checks, and saved-parent cancellation no longer reaches workers. Using the real workbench and SDK artifact writer, I canceled a parent after its child completed. After cancellation returned, the coordinator changed the checkpoint from no merged children/no aggregate to an accepted child and new aggregate path, then attempted publication. The updated head reproduces this.
- Composed recovery must retain its pending marker. A canceled parent with an existing draft retains an unmerged child finding but loses its surface, deferred review, and unfinished-pass explanation. Restoring the prior pending-checkpoint write restores that coverage.
- Resumed-child final cost is no longer persisted. A resumed scheduler probe receives the cost callback but sends fail-scan without cost-json, then replaces the receipt with null and fails required accounting. The API skips its own failure persistence for resumed scans; this also needs verification through the later activation PR.
The earlier selected-representative comment is superseded by this update removing that argument. Several earlier retry/publication bugs are addressed and will be reconciled against the final stack head. Initial validation passed 366 SDK tests (25 platform skips), 81 Python tests, the plugin build, and SDK build:ci. I reran the six affected SDK suites on the updated head and repeated the cancellation and cost probes. No repository files were changed.
253cbca to
c7800a5
Compare
272b793 to
a43db59
Compare
alandelong-oai
left a comment
There was a problem hiding this comment.
Three independent restack passes and root reconciliation are complete.
Durable cancellation now prevents checkpoint persistence, and pending child coverage is retained at this own head. The resumed-child cost issue remains: the scheduler forwards the callback, sends fail-scan without that receipt, then rereads saved cost, while this head's child API omits failure-cost persistence for resumed runs. The later #1162 child API fixes it. Approval remains withheld for this existing P2.
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.
a43db59 to
ea53452
Compare
c7800a5 to
837c840
Compare
alandelong-oai
left a comment
There was a problem hiding this comment.
Re-reviewed the real PR diff at 837c84071b6b254786160eb7ab92bd43c113e79d. Three independent high-reasoning passes covered the complete changed patch and tests; root source checks and focused reproductions informed this decision.
The existing resumed-child cost persistence finding remains at this own head and is repaired later in #1162. A separate recovery regression is now verified: with requireCost, an unavailable receipt prevents subsequent valid recovered receipts from reaching onCost. Exact base/head/tip probes report the known receipt at the base and omit it at this head and the integrated tip; see the new inline finding.
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.
| await save(); | ||
| reportPassCost("previous-work", null); | ||
| } | ||
| for (const [directory, cost] of costs) reportPassCost(directory, cost); |
There was a problem hiding this comment.
[P2] Report available receipts before rejecting missing costs
With requireCost, reportPassCost throws on the first null receipt. hydratePasses first registers all children as unknown, so if a missing receipt precedes a valid one (or state.costUnavailable is already true), the valid recovered receipt never reaches input.onCost. An exact base/head probe with two saved children reports the known receipt at the base but reports none at this head; the same omission remains at the integrated tip. Report the non-null receipts before raising the unavailable-cost error so the parent can retain and report the known spending even though full cost coverage is unavailable.
ea3b8ae to
eef4c96
Compare
3eae769 to
ee01c31
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 eef4c96f0585.
The new recovered-receipt ordering issue is fixed: both own-head and tip probes report the known second receipt before raising the required-cost error, including when costUnavailable was already set. The earlier resumed-child persistence issue remains at this own head: a resumed child reports its final cost and then fails, but fail-scan omits --cost-json and the scheduler replaces the receipt with null. That repair still lands later in #1162.
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.
Approval remains withheld for the findings above.
eef4c96 to
a7392c9
Compare
ee01c31 to
71b58db
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 a7392c95efcb.
Recovered receipt ordering remains fixed. The own-head resumed-child failure path still reports final cost and then omits --cost-json from fail-scan, allowing the scheduler to replace the receipt with null. Production touched files remain byte-identical to the previously verified head; the only inherited touched-file change extends the report grouping test. This repair still lands later in #1162.
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.
Approval remains withheld for the findings above.
71b58db to
270c67a
Compare
a7392c9 to
2be15f7
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 2be15f70a7a3.
Recovered receipt ordering remains fixed. The own-head resumed-child failure path still reports final cost and omits --cost-json from fail-scan, allowing the scheduler to replace the receipt with null. The new inherited changes to touched files concern sealed-path normalization and the current authentication environment; they do not repair this failure path. The receipt persistence fix remains later in #1162.
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.
Approval remains withheld for the outstanding findings.
Consolidate approved Deep Scan changes into the parent topic branch.
Consolidate Deep Scan changes and their reviewed follow-up fixes into the parent topic branch.
Preserve the child source tree while recording its consolidated parent.


Part 35 of 46. Previous: #1157 · Next: #1159 · Stack index
Summary
Let Deep Scans reuse the finding matcher already used by scan history and component scans, and save enough progress to resume completed work. Original findings and accepted combined results remain available for recovery and reports.
Changes
Testing
Local checks for the implementation:
Both recovered-cost regressions failed before the correction; 78 cost, composition and lifecycle cases passed afterward.
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
Live recovery requires version-3 checkpoints. Python can still read version-2 metadata without loading its combined findings, but unfinished older Deep Scans require their original version or a new scan.
Matching compares findings between child scans. Duplicates found only within one child remain that Standard scan's responsibility. Comparisons run in order within a batch and may request additional evidence, so the number of model calls can differ from the previous single grouping request.
The merge evaluation runner keeps successful result records compatible. Failed merges retain raw turns and errors without returning an unaccepted combined decision.
The SDK entrypoint adopts this runner in part 39; the plugin switches in part 40.
Public disclosure review