Finalization rejects an otherwise-complete scan when the draft manifest carries an empty `scan.artifacts: []`
Summary
plugins/codex-security/scripts/finalize_scan_contract.py misclassifies an
unsealed draft manifest as "already sealed" when the draft carries an empty
scan.artifacts array ([]). Finalization then skips building the artifact
records and instead validates the empty array, failing with:
manifest.scan.artifacts: sealed manifest requires artifact records
The scan exits non-zero even though it completed and produced 0 findings. The
canonical contract says a draft manifest must omit scan.sealedAt and
scan.artifacts and let finalization populate them; the presence check that
enforces this treats an empty list the same as a populated one, so a draft that
arrives with artifacts: [] is routed down the already-sealed path and rejected.
This is a correctness/robustness bug, not a security-boundary issue, so I'm
filing it as a public issue per SECURITY.md ("Use public issues for ordinary
bugs").
Environment
- Package / CLI:
@openai/codex-security0.1.20 - Bundled plugin version: 0.1.37
- Reproduced by source inspection on the current
main(see analysis). codexVersion/codexSdkVersion:0.148.0-alpha.8- Node.js: 22.x
- OS: Linux (Debian bookworm-slim container) and confirmed logic on macOS
- Auth:
--auth api-key - Scan mode: diff scan (
--diff <base> --head <head>), effortlow - Target type: git diff, single small file changed,
0findings
Root cause
In _prepare_scan_finalization (finalize_scan_contract.py):
was_sealed = scan.get("sealedAt") is not None or scan.get("artifacts") is not None
The contract (see the complete_codex_security_scan tool description in
mcp-app/server.ts) requires the draft manifest to omit both
scan.sealedAt and scan.artifacts; finalization supplies the seal timestamp
and builds the artifact records itself.
The heuristic infers "already sealed" from the mere presence of artifacts.
An empty array is not None, so a draft carrying artifacts: [] is
misclassified:
>>> scan = {"artifacts": []} # sealedAt omitted, artifacts present but empty
>>> scan.get("sealedAt") is not None or scan.get("artifacts") is not None
True
With was_sealed = True, finalization takes the already-sealed branch, which:
- does not run the block that builds
scan["artifacts"] = [findings.json, coverage.json, *coverage receipts], and - does not set
sealedAtfromcompletedAt, and - calls
_validate_existing_seal, which rejects the empty array:
sealed_at = scan.get("sealedAt")
artifacts = scan.get("artifacts") # []
if sealed_at is None and artifacts is None: # [] is not None -> guard is False
return
...
if not isinstance(artifacts, list) or not artifacts: # not [] -> True
raise ContractError("manifest.scan.artifacts: sealed manifest requires artifact records")
The same present-vs-absent idiom (... is not None) is repeated in
_validate_existing_seal (early-return guard) and in _read_sealed_scan, so
the "empty means unsealed" decision is inconsistent across the three call sites.
Why it only shows up on a tiny, zero-finding diff
A scan that produces findings walks the phases that populate finding and
coverage-receipt records, so artifacts is non-empty and the branch behaves
correctly. A degenerate diff with nothing to reconcile, no findings and no
coverage receipts is what leaves artifacts as an empty list, which trips the
is not None check. A full-repository scan of the same tree seals cleanly for
the same reason.
Observed on the failing run: the scan halted after the coverage phase, wrote a
completed manifest with artifacts: [], and never produced report.md or the
SARIF export — because the save/seal step raised before the report and SARIF
projection ran.
Steps to reproduce
-
On a branch, make a single small change to one non-source file (e.g. a CI config), so the diff contains no application source.
-
Run a diff scan against the merge base:
codex-security scan . \ --diff "<merge-base-sha>" --head "<head-sha>" \ --auth api-key --effort low \ --output-dir "<private-output-dir>" --json -
Observe the scan report
0findings, write acompletedmanifest withscan.artifacts: [], then fail the save step withmanifest.scan.artifacts: sealed manifest requires artifact recordsand exit non-zero.
Minimal logic reproduction of the misclassification (no network, synthetic data):
scan = {"artifacts": []} # unsealed draft that carries an empty artifacts list
was_sealed = scan.get("sealedAt") is not None or scan.get("artifacts") is not None
assert was_sealed is True # bug: an empty list is treated as an existing seal
Expected behavior
A completed diff scan with 0 findings should seal normally: finalization
should populate sealedAt and register at least findings.json and
coverage.json as artifact records, then generate report.md and the SARIF
export, and exit 0.
Actual behavior
Finalization treats the empty artifacts array as an existing seal, skips
building the records, and fails validation with
manifest.scan.artifacts: sealed manifest requires artifact records; the scan
exits non-zero and report.md / exports/results.sarif are never produced.
Suggested fix
Treat an empty artifacts array the same as an absent one when deciding whether
a manifest is already sealed:
was_sealed = bool(scan.get("sealedAt")) or bool(scan.get("artifacts"))
For consistency, apply the same empty-vs-absent treatment at the other two call
sites (_validate_existing_seal early-return guard and _read_sealed_scan), and
add a regression test for a draft manifest that arrives with scan.artifacts: []
— that case does not appear to be covered in
tests/test_finalize_scan_contract.py today.
Notes
- Diagnosis is based on reading the source at
openai/codex-security@main. I verified the Python truthiness behaviour directly but did not run the full CLI end-to-end. - All paths, hashes and identifiers above are generalized/synthetic; no credentials, private source or real scan findings are included.