Deep Security Scan
Overview
Deep Security Scan is a higher-recall repository-wide wrapper around Codex Security. It preserves the ordinary Codex Security phase model and final report shape, but repeats the most variance-sensitive phase, finding discovery, before centralized judgment.
The wrapper owns orchestration only:
- resolve the full-repository scan target once using Codex Security repository-wide semantics
- run repeated independent discovery workers, each of which generates its own repository-level threat model before
$codex-security:finding-discovery
- semantically merge discovery outputs into one canonical candidate inventory
- synthesize one canonical validation threat model from the worker threat models after discovery reaches a terminal state
- run
$codex-security:validation, $codex-security:attack-path-analysis, and final report assembly once
Do not replace Codex Security's established scan rules with custom shortcuts.
Required Capabilities
Before starting, confirm that the Codex Security plugin skills needed by this workflow are available:
$codex-security:security-scan
$codex-security:threat-model
$codex-security:finding-discovery
$codex-security:validation
$codex-security:attack-path-analysis
If any required skill is unavailable, stop and say that this Codex Security installation does not include the required scan skills. Do not silently degrade into a different workflow.
This workflow also requires parallel delegated workers for repeated discovery. Treat explicit invocation of Deep Security Scan as the user's request for this fanout workflow. If delegation is unavailable in the current environment, do not claim Deep Security Scan ran; explain the limitation and offer an ordinary Codex Security scan as the fallback path.
When delegated discovery workers are spawned from the current scan thread, inherit the parent worker configuration. Do not override agent_type, model, or reasoning effort on a full-history fork; use the host's inherited defaults so the spawn call does not fail before discovery begins.
User-Facing Contract
- The final answer should feel like an ordinary Codex Security result.
- Do not expose discovery rounds, recurrence counts, worker-by-worker results, or merge bookkeeping in the final report unless the user explicitly asks.
- Preserve Codex Security's normal final-report contract and review-directive behavior by using
../../references/final-report.md.
- Keep intermediate artifacts for auditability, but do not dump them into the user-facing result.
Non-Negotiable Orchestration Invariants
These invariants are part of the workflow contract. Do not relax, reinterpret, or replace them with coordinator improvisation.
- exactly
6 usable discovery workers per completed round
- the same canonical discovery brief for every worker, except for mechanical substitutions such as target metadata, round id, worker id, and worker-specific artifact paths
- no themed lanes, candidate-family hints, prior-round novelty hints, or coordinator-added framing around worker prompts
- no shared pre-discovery threat model; each worker must generate and use its own worker-specific repository-level threat model
- the coordinator must create one shared authoritative
<discovery_dir>/rank_input.csv plus one exhaustive shared <discovery_dir>/deep_review_input.csv before the first discovery round, and every discovery worker must consume that same shared worklist pair without regenerating, reranking, or overwriting it
- collect all round outputs before merge
- close every completed worker from the round before any later round is spawned
- merge only preserved artifacts from closed workers, never live worker state
- during an active discovery round, the coordinator is orchestration-only: it may resolve paths, create shared worklists, monitor worker progress, verify artifact existence, and check parseability or schema conformance, but it must not perform repository-specific security discovery, sink hunting, candidate generation, or validation prep grounded in target code
- before all six workers in a round have completed and been closed, the coordinator may inspect worker artifacts only for existence, completeness, parseability, and schema conformance; it must not read substantive candidate content or infer emerging vulnerability families from partial-round outputs
- the canonical candidate inventory, novelty comparison, and semantic merge may be derived only from preserved completed worker artifacts collected after a round closes; coordinator-originated repo analysis, side notes, or pre-merge hypotheses are not discovery inputs
- merge candidates only when the merged candidate's remediation would remediate every upstream candidate being merged; if fixing the merged issue would leave any upstream issue independently exploitable, independently reportable, or otherwise materially unresolved, keep them separate
- maintain Codex Security's standard
finding_discovery_report.md candidate shape through every merge pass; the merged report is the canonical candidate inventory, not a later summary derived from some other inventory
- every canonical merged candidate must remain present in the merged discovery report passed to validation unless validation itself later rejects it; no candidate may disappear during artifact synthesis or support-artifact consolidation
- every canonical merged candidate must have a standard canonical
findings/<candidate_id>/candidate_ledger.jsonl record that names the absorbed worker candidates and ledgers it subsumes before centralized validation begins
- do not spawn a later round until the prior round has fully completed its output collection, worker closure, merge, and novelty comparison
- stop only after a fully completed round produces zero new canonical merged discovery candidates
- an incomplete round, failed spawn, or partial merge is never evidence of saturation
- if the initial worker spawn batch fails before any worker has started because the host cannot resolve the current sender thread, treat that as a transient orchestration failure and retry the full round cleanly rather than treating it as worker failure or partial progress
Shared Setup
- Read
$codex-security:security-scan first and follow its repository-wide scan semantics exactly.
- Resolve the full-repository target once. Deep Security Scan v0 does not support PR diffs, commits, branch diffs, working-tree diffs, or scoped paths. If the user requested a scoped path, stop this workflow and direct them to ordinary
$codex-security:security-scan; if the user requested a PR, commit, branch diff, or working-tree diff, direct them to ordinary $codex-security:security-diff-scan. Do not silently widen the scope.
- Resolve the ordinary Codex Security scan paths once using its shared artifact-path rules:
repo_name
security_scans_dir
scan_id
scan_dir
artifacts_dir
context_dir
discovery_dir
coverage_dir
reconciliation_dir
findings_dir
- Do not generate a shared pre-discovery threat model in the coordinator.
- Reserve Codex Security's standard per-scan
<context_dir>/threat_model.md path for the later canonical validation threat model that will be synthesized only after the discovery loop reaches a terminal state.
- Create the fixed parent-provided coverage scope before any discovery worker starts:
- generate
<discovery_dir>/rank_input.csv once using Codex Security's ordinary deterministic repository-wide worklist helper for the resolved repository
- treat Deep Security Scan as exhaustive for this version: copy every
rank_input.csv row into <discovery_dir>/deep_review_input.csv and declare that worklist pair authoritative and exhaustive for every worker
- do not create or require
rank_output.csv; repo-wide Deep Security Scan does not use ranked truncation in this version
- every worker must consume those shared standard-path worklists as parent-provided inputs while writing its own worker-local ledgers, candidates, coverage ledger, and discovery report
Do not let individual discovery workers reinterpret the scan target, but do let them independently generate their own repository-level threat models at worker-specific paths before discovery begins.
Deep Discovery Loop
Run discovery in synchronous rounds:
6 independent discovery workers per round
- maximum
10 rounds total
- stop after the first full round that adds no new canonical merged discovery candidates of any kind
Always run at least one round.
After each round:
- collect that round's discovery outputs
- close every completed discovery worker from that round after its artifacts and summary have been collected
- merge the closed round's outputs with every prior round's discovery outputs
- update the canonical candidate inventory
- compare the canonical inventory against the previous round's canonical inventory
- stop if no new canonical candidate clusters of any kind were added
Do not keep completed discovery workers open across rounds. Later rounds should consume only the preserved artifacts, not live worker threads. Before spawning any later round, confirm that every completed worker from the prior round has been closed.
While a discovery round is active, keep the coordinator neutral. It may perform orchestration bookkeeping and artifact-health checks, but it must not run its own target-specific discovery lane, form candidate hypotheses, queue likely finding families, or do repository-grounded validation preparation before the round closes.
This stop rule measures discovery saturation only. It does not claim that validated findings or final reportable findings have saturated; validation and report assembly still happen once after the discovery loop completes.
If the first round finds no plausible candidates, write the appropriate canonical no-findings discovery artifact and continue directly to the final Codex Security no-findings assembly path.
Required Round-Transition Checklist
Execute this checklist in order for every completed round. Do not skip steps.
- confirm the round has exactly six usable completed discovery workers
- confirm every worker artifact needed for this scan type has been collected under its worker-specific path
- close all six completed workers from the round
- confirm there are no remaining completed worker threads from that round still open
- merge the round's preserved artifacts with prior preserved artifacts into Codex Security's standard discovery-report shape
- write the merge record, the round-specific candidate inventory, and the canonical merged
finding_discovery_report.md
- compute novelty against the prior canonical candidate inventory
- choose exactly one next action:
- stop, only if the completed round added zero new canonical clusters of any kind
- spawn the next six-worker round, only after every prior checklist step is complete
Worker Isolation
Each discovery worker must be independent:
- same resolved scan target
- its own independently generated repository-level threat model written to its worker-specific artifact path
- same Codex Security discovery rules
- same canonical worker brief except for mechanical substitutions such as target metadata, round id, worker id, and output paths
- the same parent-provided authoritative
<discovery_dir>/rank_input.csv and exhaustive <discovery_dir>/deep_review_input.csv inputs
- no access to prior workers' findings or merge outputs
- no top-level
$codex-security:validation, no top-level $codex-security:attack-path-analysis, and no final report assembly
- no file edits
The goal is not shallow parallelism; the goal is independent high-quality discovery diversity from repeated same-brief stochastic passes.
Discovery Worker Brief
Use this canonical brief for every discovery worker. Do not prepend or append extra coordinator prose, skill-path boilerplate, themed emphasis, candidate-family hints, prior-round novelty hints, or coordinator-invented specialty lanes. Only substitute the resolved target details, round id, worker id, and worker-specific output paths required for the run.
Run the Codex Security threat-model phase and then the finding-discovery phase only.
Use the provided resolved scan target exactly as given.
First generate your own repository-level threat model for that resolved target using the ordinary `$codex-security:threat-model` rules, but write it only to your worker-specific threat-model output path. Do not read, reuse, overwrite, or infer a shared coordinator threat model.
Then run `$codex-security:finding-discovery` using your own worker-specific repository threat model as the threat-model source of truth.
Do not reinterpret the target, run the top-level `$codex-security:validation` phase, run the top-level `$codex-security:attack-path-analysis` phase, assemble the final report, or edit repository files.
Your task is to enumerate technically plausible, distinct security finding candidates as comprehensively as possible for this scope.
Apply the ordinary `$codex-security:finding-discovery` rules in full:
- stay grounded in the code and your worker-specific threat model
- preserve separate root causes rather than cosmetic variants
- keep independently reachable instances separate
- preserve concrete source, closest-control, sink, impact, and affected-location evidence
- consume the parent-provided authoritative `<discovery_dir>/rank_input.csv` and exhaustive `<discovery_dir>/deep_review_input.csv` exactly as supplied; do not regenerate, rerank, overwrite, or reinterpret them
- treat those standard-path worklists as shared inputs while writing every worker output only to the explicit worker-specific artifact paths supplied for this discovery pass
- for repository-wide scans, perform the normal Codex Security repo-wide deep-review, seed-research, work-ledger, raw-candidate, candidate-ledger, dedupe, repository-coverage-ledger, and frontier-pass work required by finding discovery
- for repository-wide scans, preserve any candidate-local validation evidence and candidate-local attack-path facts that the current Codex Security discovery workflow requires before dedupe; those receipts are discovery support artifacts, not permission to run the later centralized top-level phases
- for repository-wide worker candidate JSONL, use one canonical machine-readable affected-location shape only:
- `affected_locations` must be an array of objects
- every object must contain `label`, `path`, and `lines`
- `detail` may be included when it materially helps later merge or validation
- use `lines` as a string even for one line, such as `"154"`
- do not emit string-only locations such as `"src/file.py:154"`, alternate `file` or `line` keys, or separate-only `source_locations` / `root_locations` / `sink_locations` fields without also materializing the unified `affected_locations` array
Return your worker-specific threat model plus the normal discovery artifact set for your worker-specific artifact paths, with enough detail for later centralized semantic merging and validation.
Worker Artifact Layout
Keep the canonical Codex Security scan paths for the final merged pipeline. Put repeated discovery worker artifacts under the canonical artifacts_dir without overwriting one another:
<artifacts_dir>/
02_discovery/
rank_input.csv
deep_review_input.csv
deep_discovery/
round-01/
worker-01/
threat_model.md
finding_discovery_report.md
seed_research.md
work_ledger.jsonl
raw_candidates.jsonl
dedupe_report.md
deduped_candidates.jsonl
repository_coverage_ledger.md
findings/
<candidate_id>/
candidate_ledger.jsonl
worker-02/
...
round-02/
...
Workers write their worker-local repository-wide discovery artifact set to their assigned paths while sharing only the standard-path <discovery_dir>/rank_input.csv and exhaustive <discovery_dir>/deep_review_input.csv.
Give each worker explicit worker-specific output paths so the discovery reports and repository-wide ledgers do not overwrite one another.
For repository-wide workers, the machine-readable candidate streams must use this canonical affected-location contract in both raw_candidates.jsonl and deduped_candidates.jsonl:
{
"affected_locations": [
{
"label": "root_control",
"path": "src/example.py",
"lines": "154",
"detail": "Optional concise reason this location matters"
}
]
}
Treat this as a schema contract, not presentation guidance:
affected_locations is always an array of objects
label, path, and lines are required on every item
detail is optional
lines is always a string, including single-line locations
- do not substitute string-only locations,
file, line, or parallel source/root/sink-only arrays in place of the canonical array
Semantic Merge After Each Round
Merge at the level of the underlying actionable candidate, not at the level of title similarity.
Treat two candidates as the same cluster only when a careful security reviewer would consider them the same underlying issue, or when one is a narrower or more specific restatement of the other and keeping both would double-count the same candidate.
Do not merge merely because candidates:
- mention the same subsystem
- share a broad CWE or vulnerability family
- involve the same route family, file family, or helper family
- reuse similar attack language
- have overlapping but materially different exploit paths, broken controls, or affected instances
Remediation-subsumption is required for merge eligibility:
- a merge is valid only when fixing the merged candidate would also fix every upstream candidate being merged
- a merge is invalid when any upstream source/control/sink/impact tuple would remain materially unresolved after the proposed merged fix
- related findings may be cross-referenced or grouped thematically later, but they must remain separate canonical candidates unless they share remediation closure
- example: an authentication bypass and an unsafe path-construction or file-impact bug remain separate if the auth fix does not eliminate the file-impact issue and the file-impact fix does not eliminate the auth bypass
When candidates truly merge:
- keep the strongest title or synthesize a better one
- preserve complementary evidence from every merged member
- preserve distinct affected locations that are part of the same proof tuple
- preserve source/control/sink distinctions that make the claim legible
- keep uncertainty explicit rather than inflating confidence
- produce one stronger canonical candidate than any single member when possible
Use a preserving merge, not a lossy summary:
- the merged candidate should retain any materially useful non-redundant detail from each upstream candidate, including narrower exploit framings, affected subpaths, meaningful preconditions, distinct source/control/sink nuances, and remediation-relevant subcases
- do not reduce dimensionality merely because the topline title becomes broader; if an upstream framing helps validation, advisory/CVE matching, or the later final report, keep that detail visible inside the merged candidate
- synthesize the upstream evidence into one coherent candidate rather than concatenating raw worker prose
- omit only detail that is genuinely duplicative, superseded by a more precise shared framing, or irrelevant after the remediation-subsumption test
- when useful, make the merged candidate explicit that the broader root issue also includes narrower implicated behaviors or subcases inherited from the upstream candidates
When candidates overlap but remain materially distinct, keep them separate.
Canonical Discovery Outputs
After each merge pass, retain:
- a merge record showing which worker candidates were grouped
- the current canonical candidate inventory
- the canonical merged
finding_discovery_report.md in Codex Security's normal discovery-report shape
- the novelty comparison against the previous canonical inventory
- the canonical merged candidate set at Codex Security's standard
<reconciliation_dir>/deduped_candidates.jsonl path
- a canonical dedupe report at Codex Security's standard
<reconciliation_dir>/dedupe_report.md path
- one standard canonical
<findings_dir>/<candidate_id>/candidate_ledger.jsonl per merged candidate, recording the discovery provenance, absorbed worker candidate ids, and absorbed worker-ledger paths that justify that canonical candidate
- per-candidate internal provenance:
- first-seen round
- contributing workers and source candidate ids
- later rounds that repeated the same canonical candidate
- whether later evidence strengthened, narrowed, contradicted, or merely repeated the canonical candidate
Suggested placement:
<artifacts_dir>/deep_merge/
round-01_merge_record.md
round-01_candidate_inventory.md
round-02_merge_record.md
round-02_candidate_inventory.md
canonical_candidate_inventory.md
Also write and continuously update the canonical merged discovery report at Codex Security's standard final discovery path:
<discovery_dir>/finding_discovery_report.md
This report is not a selective promotion list, triage summary, or second consolidation layer. It is the lossless canonical merged candidate set in the same artifact shape that ordinary $codex-security:finding-discovery would hand to validation.
Validation and later phases must consume this canonical merged discovery report, not the raw per-worker discovery outputs and not a hand-pruned rewrite of the merged set.
Invariant:
- every candidate present in
canonical_candidate_inventory.md must also appear substantively in finding_discovery_report.md
- every candidate present in
canonical_candidate_inventory.md must also appear in <reconciliation_dir>/deduped_candidates.jsonl and have a canonical <findings_dir>/<candidate_id>/candidate_ledger.jsonl
finding_discovery_report.md may improve wording, synthesize complementary evidence, and normalize candidate formatting, but it may not drop, suppress, or silently collapse a canonical candidate
- a canonical merged candidate ledger may consolidate worker provenance, but it may not erase the absorbed worker candidate ids, worker-ledger references, or remediation-subsumption decision that explains why the canonical candidate exists
- if the merge layer determines that a prior candidate was semantically subsumed, that merge must already be represented in the canonical merge artifacts; it may not be re-decided during final discovery-report assembly
Repository-Wide Support Artifact Assembly
For repository-wide scans, assemble the worker discovery support artifacts into canonical artifacts before validation. This is repository-wide workflow plumbing for Codex Security's normal downstream phases, not a second semantic merge, candidate triage layer, or reportability filter.
<discovery_dir>/rank_input.csv
- preserve the shared parent-provided deterministic repo-wide source inventory without worker rewrite
<discovery_dir>/deep_review_input.csv
- preserve the shared parent-provided exhaustive review scope without worker rewrite
<context_dir>/seed_research.md
- merge authoritative sources searched, candidate anchors, and failed lookup attempts when seed research applies
<discovery_dir>/work_ledger.jsonl
- aggregate worker file-review receipts conservatively while preserving worker provenance; do not claim a file was reviewed without an actual worker receipt
<discovery_dir>/raw_candidates.jsonl
- aggregate worker-local raw candidate objects with round, worker, and source-candidate provenance intact
<reconciliation_dir>/dedupe_report.md
- record the canonical Deep Security Scan dedupe outcome in Codex Security's standard reconciliation location
<reconciliation_dir>/deduped_candidates.jsonl
- write the Deep Security Scan canonical merged candidate set in Codex Security's standard post-dedupe location
<findings_dir>/<candidate_id>/candidate_ledger.jsonl
- write one canonical merged ledger per canonical candidate, preserving absorbed worker candidate ids and worker-ledger references so later centralized phases can append validation and attack-path receipts to the canonical record
<coverage_dir>/repository_coverage_ledger.md
- merge semantically equivalent ledger rows conservatively
- preserve distinct shards and families separately
- if worker dispositions disagree, keep the more conservative unresolved or open state for centralized validation to settle
Write the canonical consolidated versions back to the numbered standard paths above so $codex-security:validation receives the normal repository-wide inputs it expects.
These support-artifact assemblies are mechanical context assembly only:
- they may union, deduplicate, normalize, and conservatively reconcile support-state metadata
- they may preserve open or unresolved coverage rows for validation to settle
- they must not add a second candidate-selection stage
- they must not suppress, downgrade, or silently omit candidates from the canonical merged
finding_discovery_report.md
- they must not treat a support-ledger omission or weaker worker disposition as permission to remove a canonical discovery candidate
- if the assembled repository-wide support artifacts conflict with the canonical merged
finding_discovery_report.md, treat that as a consistency problem to repair before validation, not as authority to drop the candidate
Centralized Tail
Enter the centralized tail only after the discovery loop has a recorded terminal state:
- saturated: a fully completed round added zero new canonical clusters of any kind
- capped: the maximum round count was reached while novelty was still appearing
It is not valid to continue into validation, attack-path analysis, or final report assembly merely because:
- the first round produced a strong-looking candidate set
- the coordinator believes the merged inventory is "good enough"
- validation work has already started opportunistically
- the final report would be useful even without a terminal discovery-loop state
Before the centralized tail begins, ensure the discovery artifacts contain the terminal evidence needed to justify it:
- the final completed round's merge record
- the final completed round's candidate inventory
- the canonical candidate inventory after that round
- the canonical merged
finding_discovery_report.md, with a one-to-one substantive correspondence to the final canonical candidate inventory
- the canonical
<reconciliation_dir>/deduped_candidates.jsonl plus canonical <findings_dir>/<candidate_id>/candidate_ledger.jsonl records aligned one-to-one with the final canonical candidate inventory
- an explicit internal note that the loop ended because it was
saturated or capped
If those artifacts or that terminal state are missing, resume the discovery loop or stop with an internal workflow failure. Do not finalize the scan.
Once the recorded terminal state is present:
- sanity-check the canonical candidate inventory and canonical merged
finding_discovery_report.md against the underlying discovery evidence
- remove accidental overclaims
- repair merges that collapsed distinct issues
- ensure affected locations and proof tuples remain concrete
- confirm no canonical candidate disappeared while producing the standard discovery artifact
- confirm
<reconciliation_dir>/deduped_candidates.jsonl and the canonical per-candidate ledgers match the same merged candidate set and preserve worker provenance
- synthesize one canonical validation threat model from the worker threat models and write it to Codex Security's standard per-scan
<context_dir>/threat_model.md path
- preserve distinct attacker models, trust boundaries, privileged surfaces, and risk framings that remain relevant to canonical merged candidates
- normalize contradictions conservatively rather than erasing plausible but materially useful threat-model distinctions
- treat this canonical validation threat model as downstream context for validation and attack-path analysis, not as a retroactive filter over the discovery candidate set
- confirm
<context_dir>/threat_model.md exists, then run $codex-security:validation once over the canonical merged discovery inputs
- run
$codex-security:attack-path-analysis once over the surviving validated findings and closure rows that require it
- assemble the final Codex Security report outputs once using
../../references/final-report.md
Do not bypass validation simply because a candidate recurred across multiple discovery workers. Recurrence is search evidence, not reportability proof.
Final Output Rules
- Emit only the ordinary Codex Security final report outputs and review directives expected for the resolved scan target.
- Write the final report using
../../references/final-report.md, and include both final report paths in the response.
- Keep priorities, severities, confidence, affected locations, validation reasoning, reachability, attack paths, and remediation in the normal Codex Security style.
- Do not mention:
- number of discovery workers
- number of rounds
- candidate recurrence
- semantic cluster ids
- raw novelty metrics
- If no findings survive the centralized pipeline, produce the ordinary Codex Security no-findings report.
Failure Handling
- If Codex Security dependencies are missing, stop early and explain the dependency.
- If delegated workers are unavailable, stop early and explain that Deep Security Scan requires the fanout workflow.
- If a worker fails, preserve its partial artifacts when available, note the failure internally, and retry or replace only that worker until the round has six usable completed discovery passes.
- Do not count an incomplete round as a no-novelty round.
- Do not reduce the round below six usable workers to keep moving.
- Do not proceed to merge or novelty comparison on partial worker completion.
- Do not reinterpret failed spawning, worker crashes, or missing artifacts as evidence that the candidate space is exhausted.
- Do not enter validation, attack-path analysis, or final report assembly until the discovery loop has recorded a terminal state of
saturated or capped.
- If the first discovery round adds any new canonical clusters, a later round is mandatory unless the maximum round cap has already somehow been reached.
- Do not stop simply because a new candidate looks weak, low-confidence, non-reportable, or likely to close in validation. Any genuinely new canonical discovery candidate keeps the loop open until the next merge determines whether novelty persists.
- Treat missing per-round merge records, missing per-round candidate inventories, or missing terminal-state bookkeeping as a workflow failure, not as permission to finalize early.
- Treat any mismatch between
canonical_candidate_inventory.md and finding_discovery_report.md as a workflow failure. The discovery report may refine merged prose, but it may not omit canonical candidates before validation.
- Treat any mismatch among
canonical_candidate_inventory.md, <discovery_dir>/finding_discovery_report.md, <reconciliation_dir>/deduped_candidates.jsonl, and canonical per-candidate ledgers as a workflow failure. Centralized validation must receive one coherent canonical candidate set.
- For repository-wide scans, treat malformed worker
affected_locations output as a worker-artifact defect that must be repaired before semantic merge. Lossless mechanical normalization is acceptable only for trivial equivalent variants such as line -> lines or file -> path; string-only locations or alternate location inventories that cannot be mapped without interpretation are incomplete worker outputs, not merge inputs.
- Treat coordinator-authored target-specific candidate hypotheses, sink hunts, or partial-round substantive worker-result interpretation as orchestration drift to stop and correct before merge; those outputs are not eligible discovery evidence and must not influence novelty, dedupe, or validation inputs.
- Do not mutate later worker prompts based on prior findings, suspected blind spots, or earlier novelty observations.
- If the first worker-spawn batch fails before any worker starts with a sender-thread lookup error such as
no thread with id, preserve the clean pre-round state, retry the full round once with the same canonical worker brief, and do not count the failed attempt toward round progress.
- If a later round cannot spawn because worker-thread capacity is exhausted, first close completed workers whose artifacts have already been collected, then retry the spawn once.
- If the thread-capacity retry still cannot produce a complete six-worker round, preserve the gathered state and explain that Deep Security Scan could not complete the configured discovery loop normally. Do not silently reduce the round size or claim novelty collapse occurred.
- If the maximum of ten rounds is reached while new candidate clusters are still appearing, continue to the centralized validation pipeline with the best canonical inventory gathered so far. Do not claim novelty collapse occurred.
Guardrails
- Do not edit repository files during scanning.
- Do not collapse the Codex Security phases together.
- Do not let discovery workers see one another's results.
- Do not let repeated speculative phrasing turn into a reportable issue without centralized validation.
- Do not merge away independently reachable vulnerable instances that Codex Security would normally keep separate.
1---2name: openai-codex-security-deep-security-scan3description: Use when the user asks for a deep, exhaustive, multi-pass, or variance-reducing repository-wide Codex Security scan. Run repeated independent repository-wide discovery passes with worker-specific threat models, semantically merge candidates, synthesize one canonical validation threat model, then run validation, attack-path analysis, and final reporting once. Repository-wide targets only; do not use for PRs, commits, branch diffs, working-tree diffs, or scoped paths.4license: MIT5---6
7# Deep Security Scan
8
9## Overview
10
11Deep Security Scan is a higher-recall repository-wide wrapper around Codex Security. It preserves the ordinary Codex Security phase model and final report shape, but repeats the most variance-sensitive phase, finding discovery, before centralized judgment.
12
13The wrapper owns orchestration only:
14
151. resolve the full-repository scan target once using Codex Security repository-wide semantics
162. run repeated independent discovery workers, each of which generates its own repository-level threat model before `$codex-security:finding-discovery`
173. semantically merge discovery outputs into one canonical candidate inventory
184. synthesize one canonical validation threat model from the worker threat models after discovery reaches a terminal state
195. run `$codex-security:validation`, `$codex-security:attack-path-analysis`, and final report assembly once
20
21Do not replace Codex Security's established scan rules with custom shortcuts.
22
23## Required Capabilities
24
25Before starting, confirm that the Codex Security plugin skills needed by this workflow are available:
26
27- `$codex-security:security-scan`
28- `$codex-security:threat-model`
29- `$codex-security:finding-discovery`
30- `$codex-security:validation`
31- `$codex-security:attack-path-analysis`
32
33If any required skill is unavailable, stop and say that this Codex Security installation does not include the required scan skills. Do not silently degrade into a different workflow.
34
35This workflow also requires parallel delegated workers for repeated discovery. Treat explicit invocation of Deep Security Scan as the user's request for this fanout workflow. If delegation is unavailable in the current environment, do not claim Deep Security Scan ran; explain the limitation and offer an ordinary Codex Security scan as the fallback path.
36
37When delegated discovery workers are spawned from the current scan thread, inherit the parent worker configuration. Do not override `agent_type`, model, or reasoning effort on a full-history fork; use the host's inherited defaults so the spawn call does not fail before discovery begins.
38
39## User-Facing Contract
40
41- The final answer should feel like an ordinary Codex Security result.
42- Do not expose discovery rounds, recurrence counts, worker-by-worker results, or merge bookkeeping in the final report unless the user explicitly asks.
43- Preserve Codex Security's normal final-report contract and review-directive behavior by using `../../references/final-report.md`.
44- Keep intermediate artifacts for auditability, but do not dump them into the user-facing result.
45
46## Non-Negotiable Orchestration Invariants
47
48These invariants are part of the workflow contract. Do not relax, reinterpret, or replace them with coordinator improvisation.
49
50- exactly `6` usable discovery workers per completed round
51- the same canonical discovery brief for every worker, except for mechanical substitutions such as target metadata, round id, worker id, and worker-specific artifact paths
52- no themed lanes, candidate-family hints, prior-round novelty hints, or coordinator-added framing around worker prompts
53- no shared pre-discovery threat model; each worker must generate and use its own worker-specific repository-level threat model
54- the coordinator must create one shared authoritative `<discovery_dir>/rank_input.csv` plus one exhaustive shared `<discovery_dir>/deep_review_input.csv` before the first discovery round, and every discovery worker must consume that same shared worklist pair without regenerating, reranking, or overwriting it
55- collect all round outputs before merge
56- close every completed worker from the round before any later round is spawned
57- merge only preserved artifacts from closed workers, never live worker state
58- during an active discovery round, the coordinator is orchestration-only: it may resolve paths, create shared worklists, monitor worker progress, verify artifact existence, and check parseability or schema conformance, but it must not perform repository-specific security discovery, sink hunting, candidate generation, or validation prep grounded in target code
59- before all six workers in a round have completed and been closed, the coordinator may inspect worker artifacts only for existence, completeness, parseability, and schema conformance; it must not read substantive candidate content or infer emerging vulnerability families from partial-round outputs
60- the canonical candidate inventory, novelty comparison, and semantic merge may be derived only from preserved completed worker artifacts collected after a round closes; coordinator-originated repo analysis, side notes, or pre-merge hypotheses are not discovery inputs
61- merge candidates only when the merged candidate's remediation would remediate every upstream candidate being merged; if fixing the merged issue would leave any upstream issue independently exploitable, independently reportable, or otherwise materially unresolved, keep them separate
62- maintain Codex Security's standard `finding_discovery_report.md` candidate shape through every merge pass; the merged report is the canonical candidate inventory, not a later summary derived from some other inventory
63- every canonical merged candidate must remain present in the merged discovery report passed to validation unless validation itself later rejects it; no candidate may disappear during artifact synthesis or support-artifact consolidation
64- every canonical merged candidate must have a standard canonical `findings/<candidate_id>/candidate_ledger.jsonl` record that names the absorbed worker candidates and ledgers it subsumes before centralized validation begins
65- do not spawn a later round until the prior round has fully completed its output collection, worker closure, merge, and novelty comparison
66- stop only after a fully completed round produces zero new canonical merged discovery candidates
67- an incomplete round, failed spawn, or partial merge is never evidence of saturation
68- if the initial worker spawn batch fails before any worker has started because the host cannot resolve the current sender thread, treat that as a transient orchestration failure and retry the full round cleanly rather than treating it as worker failure or partial progress
69
70## Shared Setup
71
721. Read `$codex-security:security-scan` first and follow its repository-wide scan semantics exactly.
732. Resolve the full-repository target once. Deep Security Scan v0 does not support PR diffs, commits, branch diffs, working-tree diffs, or scoped paths. If the user requested a scoped path, stop this workflow and direct them to ordinary `$codex-security:security-scan`; if the user requested a PR, commit, branch diff, or working-tree diff, direct them to ordinary `$codex-security:security-diff-scan`. Do not silently widen the scope.
743. Resolve the ordinary Codex Security scan paths once using its shared artifact-path rules:
75 - `repo_name`
76 - `security_scans_dir`
77 - `scan_id`
78 - `scan_dir`
79 - `artifacts_dir`
80 - `context_dir`
81 - `discovery_dir`
82 - `coverage_dir`
83 - `reconciliation_dir`
84 - `findings_dir`
854. Do not generate a shared pre-discovery threat model in the coordinator.
865. Reserve Codex Security's standard per-scan `<context_dir>/threat_model.md` path for the later canonical validation threat model that will be synthesized only after the discovery loop reaches a terminal state.
876. Create the fixed parent-provided coverage scope before any discovery worker starts:
88 - generate `<discovery_dir>/rank_input.csv` once using Codex Security's ordinary deterministic repository-wide worklist helper for the resolved repository
89 - treat Deep Security Scan as exhaustive for this version: copy every `rank_input.csv` row into `<discovery_dir>/deep_review_input.csv` and declare that worklist pair authoritative and exhaustive for every worker
90 - do not create or require `rank_output.csv`; repo-wide Deep Security Scan does not use ranked truncation in this version
91 - every worker must consume those shared standard-path worklists as parent-provided inputs while writing its own worker-local ledgers, candidates, coverage ledger, and discovery report
92
93Do not let individual discovery workers reinterpret the scan target, but do let them independently generate their own repository-level threat models at worker-specific paths before discovery begins.
94
95## Deep Discovery Loop
96
97Run discovery in synchronous rounds:
98
99- `6` independent discovery workers per round
100- maximum `10` rounds total
101- stop after the first full round that adds no new canonical merged discovery candidates of any kind
102
103Always run at least one round.
104
105After each round:
106
1071. collect that round's discovery outputs
1082. close every completed discovery worker from that round after its artifacts and summary have been collected
1093. merge the closed round's outputs with every prior round's discovery outputs
1104. update the canonical candidate inventory
1115. compare the canonical inventory against the previous round's canonical inventory
1126. stop if no new canonical candidate clusters of any kind were added
113
114Do not keep completed discovery workers open across rounds. Later rounds should consume only the preserved artifacts, not live worker threads. Before spawning any later round, confirm that every completed worker from the prior round has been closed.
115
116While a discovery round is active, keep the coordinator neutral. It may perform orchestration bookkeeping and artifact-health checks, but it must not run its own target-specific discovery lane, form candidate hypotheses, queue likely finding families, or do repository-grounded validation preparation before the round closes.
117
118This stop rule measures discovery saturation only. It does not claim that validated findings or final reportable findings have saturated; validation and report assembly still happen once after the discovery loop completes.
119
120If the first round finds no plausible candidates, write the appropriate canonical no-findings discovery artifact and continue directly to the final Codex Security no-findings assembly path.
121
122### Required Round-Transition Checklist
123
124Execute this checklist in order for every completed round. Do not skip steps.
125
1261. confirm the round has exactly six usable completed discovery workers
1272. confirm every worker artifact needed for this scan type has been collected under its worker-specific path
1283. close all six completed workers from the round
1294. confirm there are no remaining completed worker threads from that round still open
1305. merge the round's preserved artifacts with prior preserved artifacts into Codex Security's standard discovery-report shape
1316. write the merge record, the round-specific candidate inventory, and the canonical merged `finding_discovery_report.md`
1327. compute novelty against the prior canonical candidate inventory
1338. choose exactly one next action:
134 - stop, only if the completed round added zero new canonical clusters of any kind
135 - spawn the next six-worker round, only after every prior checklist step is complete
136
137## Worker Isolation
138
139Each discovery worker must be independent:
140
141- same resolved scan target
142- its own independently generated repository-level threat model written to its worker-specific artifact path
143- same Codex Security discovery rules
144- same canonical worker brief except for mechanical substitutions such as target metadata, round id, worker id, and output paths
145- the same parent-provided authoritative `<discovery_dir>/rank_input.csv` and exhaustive `<discovery_dir>/deep_review_input.csv` inputs
146- no access to prior workers' findings or merge outputs
147- no top-level `$codex-security:validation`, no top-level `$codex-security:attack-path-analysis`, and no final report assembly
148- no file edits
149
150The goal is not shallow parallelism; the goal is independent high-quality discovery diversity from repeated same-brief stochastic passes.
151
152## Discovery Worker Brief
153
154Use this canonical brief for every discovery worker. Do not prepend or append extra coordinator prose, skill-path boilerplate, themed emphasis, candidate-family hints, prior-round novelty hints, or coordinator-invented specialty lanes. Only substitute the resolved target details, round id, worker id, and worker-specific output paths required for the run.
155
156```text
157Run the Codex Security threat-model phase and then the finding-discovery phase only.
158
159Use the provided resolved scan target exactly as given.
160First generate your own repository-level threat model for that resolved target using the ordinary `$codex-security:threat-model` rules, but write it only to your worker-specific threat-model output path. Do not read, reuse, overwrite, or infer a shared coordinator threat model.
161Then run `$codex-security:finding-discovery` using your own worker-specific repository threat model as the threat-model source of truth.
162Do not reinterpret the target, run the top-level `$codex-security:validation` phase, run the top-level `$codex-security:attack-path-analysis` phase, assemble the final report, or edit repository files.
163
164Your task is to enumerate technically plausible, distinct security finding candidates as comprehensively as possible for this scope.
165
166Apply the ordinary `$codex-security:finding-discovery` rules in full:
167- stay grounded in the code and your worker-specific threat model
168- preserve separate root causes rather than cosmetic variants
169- keep independently reachable instances separate
170- preserve concrete source, closest-control, sink, impact, and affected-location evidence
171- consume the parent-provided authoritative `<discovery_dir>/rank_input.csv` and exhaustive `<discovery_dir>/deep_review_input.csv` exactly as supplied; do not regenerate, rerank, overwrite, or reinterpret them
172- treat those standard-path worklists as shared inputs while writing every worker output only to the explicit worker-specific artifact paths supplied for this discovery pass
173- for repository-wide scans, perform the normal Codex Security repo-wide deep-review, seed-research, work-ledger, raw-candidate, candidate-ledger, dedupe, repository-coverage-ledger, and frontier-pass work required by finding discovery
174- for repository-wide scans, preserve any candidate-local validation evidence and candidate-local attack-path facts that the current Codex Security discovery workflow requires before dedupe; those receipts are discovery support artifacts, not permission to run the later centralized top-level phases
175- for repository-wide worker candidate JSONL, use one canonical machine-readable affected-location shape only:
176 - `affected_locations` must be an array of objects
177 - every object must contain `label`, `path`, and `lines`
178 - `detail` may be included when it materially helps later merge or validation
179 - use `lines` as a string even for one line, such as `"154"`
180 - do not emit string-only locations such as `"src/file.py:154"`, alternate `file` or `line` keys, or separate-only `source_locations` / `root_locations` / `sink_locations` fields without also materializing the unified `affected_locations` array
181
182Return your worker-specific threat model plus the normal discovery artifact set for your worker-specific artifact paths, with enough detail for later centralized semantic merging and validation.
183```
184
185## Worker Artifact Layout
186
187Keep the canonical Codex Security scan paths for the final merged pipeline. Put repeated discovery worker artifacts under the canonical `artifacts_dir` without overwriting one another:
188
189```text
190<artifacts_dir>/
191 02_discovery/
192 rank_input.csv
193 deep_review_input.csv
194 deep_discovery/
195 round-01/
196 worker-01/
197 threat_model.md
198 finding_discovery_report.md
199 seed_research.md
200 work_ledger.jsonl
201 raw_candidates.jsonl
202 dedupe_report.md
203 deduped_candidates.jsonl
204 repository_coverage_ledger.md
205 findings/
206 <candidate_id>/
207 candidate_ledger.jsonl
208 worker-02/
209 ...
210 round-02/
211 ...
212```
213
214Workers write their worker-local repository-wide discovery artifact set to their assigned paths while sharing only the standard-path `<discovery_dir>/rank_input.csv` and exhaustive `<discovery_dir>/deep_review_input.csv`.
215
216Give each worker explicit worker-specific output paths so the discovery reports and repository-wide ledgers do not overwrite one another.
217
218For repository-wide workers, the machine-readable candidate streams must use this canonical affected-location contract in both `raw_candidates.jsonl` and `deduped_candidates.jsonl`:
219
220```json
221{
222 "affected_locations": [
223 {
224 "label": "root_control",
225 "path": "src/example.py",
226 "lines": "154",
227 "detail": "Optional concise reason this location matters"
228 }
229 ]
230}
231```
232
233Treat this as a schema contract, not presentation guidance:
234
235- `affected_locations` is always an array of objects
236- `label`, `path`, and `lines` are required on every item
237- `detail` is optional
238- `lines` is always a string, including single-line locations
239- do not substitute string-only locations, `file`, `line`, or parallel source/root/sink-only arrays in place of the canonical array
240
241## Semantic Merge After Each Round
242
243Merge at the level of the underlying actionable candidate, not at the level of title similarity.
244
245Treat two candidates as the same cluster only when a careful security reviewer would consider them the same underlying issue, or when one is a narrower or more specific restatement of the other and keeping both would double-count the same candidate.
246
247Do not merge merely because candidates:
248
249- mention the same subsystem
250- share a broad CWE or vulnerability family
251- involve the same route family, file family, or helper family
252- reuse similar attack language
253- have overlapping but materially different exploit paths, broken controls, or affected instances
254
255Remediation-subsumption is required for merge eligibility:
256
257- a merge is valid only when fixing the merged candidate would also fix every upstream candidate being merged
258- a merge is invalid when any upstream source/control/sink/impact tuple would remain materially unresolved after the proposed merged fix
259- related findings may be cross-referenced or grouped thematically later, but they must remain separate canonical candidates unless they share remediation closure
260- example: an authentication bypass and an unsafe path-construction or file-impact bug remain separate if the auth fix does not eliminate the file-impact issue and the file-impact fix does not eliminate the auth bypass
261
262When candidates truly merge:
263
264- keep the strongest title or synthesize a better one
265- preserve complementary evidence from every merged member
266- preserve distinct affected locations that are part of the same proof tuple
267- preserve source/control/sink distinctions that make the claim legible
268- keep uncertainty explicit rather than inflating confidence
269- produce one stronger canonical candidate than any single member when possible
270
271Use a preserving merge, not a lossy summary:
272
273- the merged candidate should retain any materially useful non-redundant detail from each upstream candidate, including narrower exploit framings, affected subpaths, meaningful preconditions, distinct source/control/sink nuances, and remediation-relevant subcases
274- do not reduce dimensionality merely because the topline title becomes broader; if an upstream framing helps validation, advisory/CVE matching, or the later final report, keep that detail visible inside the merged candidate
275- synthesize the upstream evidence into one coherent candidate rather than concatenating raw worker prose
276- omit only detail that is genuinely duplicative, superseded by a more precise shared framing, or irrelevant after the remediation-subsumption test
277- when useful, make the merged candidate explicit that the broader root issue also includes narrower implicated behaviors or subcases inherited from the upstream candidates
278
279When candidates overlap but remain materially distinct, keep them separate.
280
281## Canonical Discovery Outputs
282
283After each merge pass, retain:
284
285- a merge record showing which worker candidates were grouped
286- the current canonical candidate inventory
287- the canonical merged `finding_discovery_report.md` in Codex Security's normal discovery-report shape
288- the novelty comparison against the previous canonical inventory
289- the canonical merged candidate set at Codex Security's standard `<reconciliation_dir>/deduped_candidates.jsonl` path
290- a canonical dedupe report at Codex Security's standard `<reconciliation_dir>/dedupe_report.md` path
291- one standard canonical `<findings_dir>/<candidate_id>/candidate_ledger.jsonl` per merged candidate, recording the discovery provenance, absorbed worker candidate ids, and absorbed worker-ledger paths that justify that canonical candidate
292- per-candidate internal provenance:
293 - first-seen round
294 - contributing workers and source candidate ids
295 - later rounds that repeated the same canonical candidate
296 - whether later evidence strengthened, narrowed, contradicted, or merely repeated the canonical candidate
297
298Suggested placement:
299
300```text
301<artifacts_dir>/deep_merge/
302 round-01_merge_record.md
303 round-01_candidate_inventory.md
304 round-02_merge_record.md
305 round-02_candidate_inventory.md
306 canonical_candidate_inventory.md
307```
308
309Also write and continuously update the canonical merged discovery report at Codex Security's standard final discovery path:
310
311```text
312<discovery_dir>/finding_discovery_report.md
313```
314
315This report is not a selective promotion list, triage summary, or second consolidation layer. It is the lossless canonical merged candidate set in the same artifact shape that ordinary `$codex-security:finding-discovery` would hand to validation.
316
317Validation and later phases must consume this canonical merged discovery report, not the raw per-worker discovery outputs and not a hand-pruned rewrite of the merged set.
318
319Invariant:
320
321- every candidate present in `canonical_candidate_inventory.md` must also appear substantively in `finding_discovery_report.md`
322- every candidate present in `canonical_candidate_inventory.md` must also appear in `<reconciliation_dir>/deduped_candidates.jsonl` and have a canonical `<findings_dir>/<candidate_id>/candidate_ledger.jsonl`
323- `finding_discovery_report.md` may improve wording, synthesize complementary evidence, and normalize candidate formatting, but it may not drop, suppress, or silently collapse a canonical candidate
324- a canonical merged candidate ledger may consolidate worker provenance, but it may not erase the absorbed worker candidate ids, worker-ledger references, or remediation-subsumption decision that explains why the canonical candidate exists
325- if the merge layer determines that a prior candidate was semantically subsumed, that merge must already be represented in the canonical merge artifacts; it may not be re-decided during final discovery-report assembly
326
327## Repository-Wide Support Artifact Assembly
328
329For repository-wide scans, assemble the worker discovery support artifacts into canonical artifacts before validation. This is repository-wide workflow plumbing for Codex Security's normal downstream phases, not a second semantic merge, candidate triage layer, or reportability filter.
330
331- `<discovery_dir>/rank_input.csv`
332 - preserve the shared parent-provided deterministic repo-wide source inventory without worker rewrite
333- `<discovery_dir>/deep_review_input.csv`
334 - preserve the shared parent-provided exhaustive review scope without worker rewrite
335- `<context_dir>/seed_research.md`
336 - merge authoritative sources searched, candidate anchors, and failed lookup attempts when seed research applies
337- `<discovery_dir>/work_ledger.jsonl`
338 - aggregate worker file-review receipts conservatively while preserving worker provenance; do not claim a file was reviewed without an actual worker receipt
339- `<discovery_dir>/raw_candidates.jsonl`
340 - aggregate worker-local raw candidate objects with round, worker, and source-candidate provenance intact
341- `<reconciliation_dir>/dedupe_report.md`
342 - record the canonical Deep Security Scan dedupe outcome in Codex Security's standard reconciliation location
343- `<reconciliation_dir>/deduped_candidates.jsonl`
344 - write the Deep Security Scan canonical merged candidate set in Codex Security's standard post-dedupe location
345- `<findings_dir>/<candidate_id>/candidate_ledger.jsonl`
346 - write one canonical merged ledger per canonical candidate, preserving absorbed worker candidate ids and worker-ledger references so later centralized phases can append validation and attack-path receipts to the canonical record
347- `<coverage_dir>/repository_coverage_ledger.md`
348 - merge semantically equivalent ledger rows conservatively
349 - preserve distinct shards and families separately
350 - if worker dispositions disagree, keep the more conservative unresolved or open state for centralized validation to settle
351
352Write the canonical consolidated versions back to the numbered standard paths above so `$codex-security:validation` receives the normal repository-wide inputs it expects.
353
354These support-artifact assemblies are mechanical context assembly only:
355
356- they may union, deduplicate, normalize, and conservatively reconcile support-state metadata
357- they may preserve open or unresolved coverage rows for validation to settle
358- they must not add a second candidate-selection stage
359- they must not suppress, downgrade, or silently omit candidates from the canonical merged `finding_discovery_report.md`
360- they must not treat a support-ledger omission or weaker worker disposition as permission to remove a canonical discovery candidate
361- if the assembled repository-wide support artifacts conflict with the canonical merged `finding_discovery_report.md`, treat that as a consistency problem to repair before validation, not as authority to drop the candidate
362
363## Centralized Tail
364
365Enter the centralized tail only after the discovery loop has a recorded terminal state:
366
367- **saturated**: a fully completed round added zero new canonical clusters of any kind
368- **capped**: the maximum round count was reached while novelty was still appearing
369
370It is not valid to continue into validation, attack-path analysis, or final report assembly merely because:
371
372- the first round produced a strong-looking candidate set
373- the coordinator believes the merged inventory is "good enough"
374- validation work has already started opportunistically
375- the final report would be useful even without a terminal discovery-loop state
376
377Before the centralized tail begins, ensure the discovery artifacts contain the terminal evidence needed to justify it:
378
379- the final completed round's merge record
380- the final completed round's candidate inventory
381- the canonical candidate inventory after that round
382- the canonical merged `finding_discovery_report.md`, with a one-to-one substantive correspondence to the final canonical candidate inventory
383- the canonical `<reconciliation_dir>/deduped_candidates.jsonl` plus canonical `<findings_dir>/<candidate_id>/candidate_ledger.jsonl` records aligned one-to-one with the final canonical candidate inventory
384- an explicit internal note that the loop ended because it was `saturated` or `capped`
385
386If those artifacts or that terminal state are missing, resume the discovery loop or stop with an internal workflow failure. Do not finalize the scan.
387
388Once the recorded terminal state is present:
389
3901. sanity-check the canonical candidate inventory and canonical merged `finding_discovery_report.md` against the underlying discovery evidence
391 - remove accidental overclaims
392 - repair merges that collapsed distinct issues
393 - ensure affected locations and proof tuples remain concrete
394 - confirm no canonical candidate disappeared while producing the standard discovery artifact
395 - confirm `<reconciliation_dir>/deduped_candidates.jsonl` and the canonical per-candidate ledgers match the same merged candidate set and preserve worker provenance
3962. synthesize one canonical validation threat model from the worker threat models and write it to Codex Security's standard per-scan `<context_dir>/threat_model.md` path
397 - preserve distinct attacker models, trust boundaries, privileged surfaces, and risk framings that remain relevant to canonical merged candidates
398 - normalize contradictions conservatively rather than erasing plausible but materially useful threat-model distinctions
399 - treat this canonical validation threat model as downstream context for validation and attack-path analysis, not as a retroactive filter over the discovery candidate set
4003. confirm `<context_dir>/threat_model.md` exists, then run `$codex-security:validation` once over the canonical merged discovery inputs
4014. run `$codex-security:attack-path-analysis` once over the surviving validated findings and closure rows that require it
4025. assemble the final Codex Security report outputs once using `../../references/final-report.md`
403
404Do not bypass validation simply because a candidate recurred across multiple discovery workers. Recurrence is search evidence, not reportability proof.
405
406## Final Output Rules
407
408- Emit only the ordinary Codex Security final report outputs and review directives expected for the resolved scan target.
409- Write the final report using `../../references/final-report.md`, and include both final report paths in the response.
410- Keep priorities, severities, confidence, affected locations, validation reasoning, reachability, attack paths, and remediation in the normal Codex Security style.
411- Do not mention:
412 - number of discovery workers
413 - number of rounds
414 - candidate recurrence
415 - semantic cluster ids
416 - raw novelty metrics
417- If no findings survive the centralized pipeline, produce the ordinary Codex Security no-findings report.
418
419## Failure Handling
420
421- If Codex Security dependencies are missing, stop early and explain the dependency.
422- If delegated workers are unavailable, stop early and explain that Deep Security Scan requires the fanout workflow.
423- If a worker fails, preserve its partial artifacts when available, note the failure internally, and retry or replace only that worker until the round has six usable completed discovery passes.
424- Do not count an incomplete round as a no-novelty round.
425- Do not reduce the round below six usable workers to keep moving.
426- Do not proceed to merge or novelty comparison on partial worker completion.
427- Do not reinterpret failed spawning, worker crashes, or missing artifacts as evidence that the candidate space is exhausted.
428- Do not enter validation, attack-path analysis, or final report assembly until the discovery loop has recorded a terminal state of `saturated` or `capped`.
429- If the first discovery round adds any new canonical clusters, a later round is mandatory unless the maximum round cap has already somehow been reached.
430- Do not stop simply because a new candidate looks weak, low-confidence, non-reportable, or likely to close in validation. Any genuinely new canonical discovery candidate keeps the loop open until the next merge determines whether novelty persists.
431- Treat missing per-round merge records, missing per-round candidate inventories, or missing terminal-state bookkeeping as a workflow failure, not as permission to finalize early.
432- Treat any mismatch between `canonical_candidate_inventory.md` and `finding_discovery_report.md` as a workflow failure. The discovery report may refine merged prose, but it may not omit canonical candidates before validation.
433- Treat any mismatch among `canonical_candidate_inventory.md`, `<discovery_dir>/finding_discovery_report.md`, `<reconciliation_dir>/deduped_candidates.jsonl`, and canonical per-candidate ledgers as a workflow failure. Centralized validation must receive one coherent canonical candidate set.
434- For repository-wide scans, treat malformed worker `affected_locations` output as a worker-artifact defect that must be repaired before semantic merge. Lossless mechanical normalization is acceptable only for trivial equivalent variants such as `line` -> `lines` or `file` -> `path`; string-only locations or alternate location inventories that cannot be mapped without interpretation are incomplete worker outputs, not merge inputs.
435- Treat coordinator-authored target-specific candidate hypotheses, sink hunts, or partial-round substantive worker-result interpretation as orchestration drift to stop and correct before merge; those outputs are not eligible discovery evidence and must not influence novelty, dedupe, or validation inputs.
436- Do not mutate later worker prompts based on prior findings, suspected blind spots, or earlier novelty observations.
437- If the first worker-spawn batch fails before any worker starts with a sender-thread lookup error such as `no thread with id`, preserve the clean pre-round state, retry the full round once with the same canonical worker brief, and do not count the failed attempt toward round progress.
438- If a later round cannot spawn because worker-thread capacity is exhausted, first close completed workers whose artifacts have already been collected, then retry the spawn once.
439- If the thread-capacity retry still cannot produce a complete six-worker round, preserve the gathered state and explain that Deep Security Scan could not complete the configured discovery loop normally. Do not silently reduce the round size or claim novelty collapse occurred.
440- If the maximum of ten rounds is reached while new candidate clusters are still appearing, continue to the centralized validation pipeline with the best canonical inventory gathered so far. Do not claim novelty collapse occurred.
441
442## Guardrails
443
444- Do not edit repository files during scanning.
445- Do not collapse the Codex Security phases together.
446- Do not let discovery workers see one another's results.
447- Do not let repeated speculative phrasing turn into a reportable issue without centralized validation.
448- Do not merge away independently reachable vulnerable instances that Codex Security would normally keep separate.