Skip to content

fix(scans): preserve saved results when scans stop or restart - #1269

Merged
mldangelo-oai merged 33 commits into
mainfrom
mdangelo/codex/scan-lifecycle
Oct 8, 2026
Merged

mldangelo-oai merged 33 commits into
mainfrom
mdangelo/codex/scan-lifecycle

Conversation

@mldangelo-oai

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

Copy link
Copy Markdown
Collaborator

Summary

Keep saved scan results at the paths recorded in scan history when scans stop or restart. Coordinate output archival with registration, and finish cleanup and result preservation before reporting a stopped scan.

Changes

  • Archive output and its saved registration together. Restore moves owned by rejected registrations and retain committed archive locations after lost responses. Preserve the exported prepareOutputDir behavior and older-helper compatibility.
  • Keep real scans, mock scans, and imports cancellable during registration inspection. The bundled helper waits for an internal acknowledgement before archival; once acknowledged, commit or rollback settles before cancellation returns.
  • Release the SQLite writer slot while hashing the target, then retry and revalidate after contention. Simultaneous starts still join one scan.
  • Preserve original failure diagnostics, wait for cleanup and stopped-result publication within the existing budget, and keep replacement-coordinator results when stale reads or failure responses arrive.
  • Ensure archival test cleanup aborts its operation and closes current and late helper connections before awaiting completion.
  • Reject bundled-helper archival of output containing active workbench state, including aliases. Resume worker numbering from saved artifact directories without numeric rounding.

CI workflows and public CLI syntax and defaults are unchanged.

Testing

  • On 77363c6, based on 6c8ab22, with Bun 1.3.14 on Linux: five complete affected SDK test files plus all 27 archival API cases passed 144 tests with one platform skip and no failures. The complete MCP worker executor entry passed, covering per-scan endpoints and context settings across concurrent discovery/reducer workers and fresh/resumed threads. All 13 deterministic eval scripts, types, formatting, plugin/CI/eval builds, Ruff check and format (142 Python files), source compatibility and all nine checker tests passed.

  • A fresh clean package passed public imports, NodeNext types, CLI/SDK lifecycle, credential locking, all 143 shipped plugin files, MCP startup, a nested worker and the dashboard using exact cached dependencies. Fresh registry resolution was not repeated after an earlier failure to resolve the unchanged pinned Codex prerelease.

  • Earlier validation on a7734df passed 399 Python tests, all 278 MCP tests, and 336 affected SDK tests with 27 platform skips. Three Node/Python lifecycle probes verified shared database identity, migration history, findings and saved report paths across native commands and Python registration/archival. Unchanged Python, MCP production, helper and runtime inputs were verified before reusing that evidence; these are not new executions on 77363c6. Changed API, dashboard, publication and executor consumers received the fresh checks above.

  • On earlier 8b9046f, two complete API orders each passed 221 tests with four platform skips and no failures. Historical full SDK runs each passed 4,076 tests with 68 platform skips and no failures across 172 files: seed 12345 on add6e448, and seed 3115987471 on ceac689, both based on a44eda3. These remain historical runs.

  • Ownership and late-response negative controls reproduce the earlier failures and pass with the corrections. Private Node and Bun 1.3.14 probes reproduce the old fixture cleanup hang when its deadline expires before helper connection; corrected cleanup settles preparation, commit and rollback while preserving saved output and database/archive consistency. The archival matrix covers formatted Unicode input, CRLF stdout, real/mock/import cancellation and legacy helpers.

  • Hosted Windows CI on 8b9046f initially reported a provider-isolation timeout after all 27 archival cases passed. One retry on the unchanged commit passed 612 tests with nine skips, including all 26 provider cases and 27 archival cases. The retry used a different randomized order; the original failure remains recorded. Fresh local execution for 77363c6 was on Linux; hosted CI supplies Windows coverage.

  • Three independent native reviews and a fresh verifier completed on 77363c6 against 6c8ab22 with no actionable findings.

Risk and rollout

Older custom helpers retain the existing limitation when output contains the active database or configured state directory. Older transactional helpers without the acknowledgement callback defer cancellation for the registration call after checking for an already-aborted request. The bundled helper supports the narrower cancellation boundary.

If registration commits but its response is lost, archived results retain their recorded locations; the new registration can remain marked running, as before.

Contention can require hashing the target again. Filesystem changes after the final hash are not atomic with database admission. Preserve archival compatibility, saved results and original failure diagnostics during rollout.

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.

@github-actions github-actions Bot added the bug Something isn't working label Oct 5, 2026
@mldangelo-oai
mldangelo-oai marked this pull request as ready for review October 5, 2026 14:52
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 5, 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 ✅ Completed 2026-10-08T01:00:33.369341Z 77363c6 New commits
🔒 Security Review ✅ Completed 2026-10-08T01:02:14.619112Z 77363c6 New commits
ℹ️ 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.

@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: d573b16721

ℹ️ 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 thread sdk/typescript/src/runtime.ts Resolved

@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: 28dc4cf833

ℹ️ 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".

@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 full contribution at 28dc4cf833f4b3f8f3a713bc010cfcb3735ad9b0 with selected base 1345ea3fa48021ef54ecc2dcc948fde43fec8d0c, including changed tests and touched context, using three independent reviews followed by root synthesis.

No supported introduced finding.

Static source review; tests were inspected but not executed. CI, mergeability and integration are separate.

@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 complete contribution and changed tests with three independent review passes plus root synthesis. No supported introduced finding remains at this head. This is a static source review; tests were not executed, and CI and integration remain separate.

@mldangelo-oai mldangelo-oai changed the title fix(scans): coordinate result preservation and output archival fix(scans): preserve saved results when scans stop or restart Oct 7, 2026

@zcrab-oai zcrab-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 e861fc8. I found the following issue and am leaving this PR unapproved.

[P2] Reject archives that contain the active workbench state — plugins/codex-security/scripts/workbench_scan_start.py:143

If CODEX_SECURITY_STATE_DIR is inside scan_dir, this rename moves the active workbench database into the archive as well. register-cli-scan --archive-existing returns success, but the next command opens a fresh database at the original state path and cannot find previously saved scans. I reproduced this against base and head; base rejects the nonempty output. Reject output containing the active database or a configured state-path ancestor before renaming, including aliases.

@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: 66c627cc25

ℹ️ 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 +1625 to +1626
const savedScans = await savedScanIdentities(scanDir);
await rename(scanDir, archiveDir);

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 Protect state directories before legacy archival

When a legacy custom helper is used and the requested output directory contains CODEX_SECURITY_STATE_DIR, this fallback renames the entire output tree—including the active SQLite database—and recreates an empty directory before invoking the helper with the original state path. The helper can then initialize a new database, stranding prior scan history and configuration in the archive; unlike the bundled Python path, this compatibility path never checks whether the output contains the configured state or active database. Reject that layout before rename, matching the transactional helper's protection.

AGENTS.md reference: sdk/typescript/AGENTS.md:L23-L24

Useful? React with 👍 / 👎.

@mldangelo-oai

Copy link
Copy Markdown
Collaborator Author

@codex review

@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: 66c627cc25

ℹ️ 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 thread sdk/typescript/src/api.ts Outdated
Comment on lines +1643 to +1645
options.archiveExisting
? { ...workbenchOptions, signal: undefined }
: workbenchOptions,

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 Honor cancellation during archived scan registration

When archiveExisting is enabled, this removes the caller's abort signal from the entire register-cli-scan subprocess, including repository inspection and file counting that occur before archival begins. Because the SDK workbench runner has no timeout, a slow or stuck filesystem/helper makes both run() and close() wait indefinitely instead of honoring ScanOptions.signal; cancellation should remain active until the helper enters the short atomic archive/registration section, or that section needs a rollback-safe bounded cancellation mechanism.

AGENTS.md reference: sdk/typescript/AGENTS.md:L23-L24

Useful? React with 👍 / 👎.

@mldangelo-oai
mldangelo-oai merged commit 587a357 into main Oct 8, 2026
84 of 114 checks passed
@mldangelo-oai
mldangelo-oai deleted the mdangelo/codex/scan-lifecycle branch October 8, 2026 01:27
@github-actions github-actions Bot mentioned this pull request Oct 8, 2026
3 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants