Skip to content

fix(cli): emit structured JSON errors for failed scans - #709

Open
Hughhhhcoder wants to merge 4 commits into
openai:mainfrom
Hughhhhcoder:codex/codex-security-scan-json-error-clean
Open

fix(cli): emit structured JSON errors for failed scans#709
Hughhhhcoder wants to merge 4 commits into
openai:mainfrom
Hughhhhcoder:codex/codex-security-scan-json-error-clean

Conversation

@Hughhhhcoder

Copy link
Copy Markdown
Contributor

Fixes #375

Summary

scan --json and scan --format json could exit with status 2 while writing nothing to stdout when the scan failed. This made automation report an ambiguous invalid or empty response.

Changes

  • Return a structured { status: "failed", code: "SCAN_FAILED", message } result for JSON and JSONL scan failures.
  • Preserve the existing text-mode error path, exit status, stderr diagnostics, partial-output guidance, and credential redaction.
  • Add regression coverage for --json, --format json, and --format jsonl.

Testing

  • bun test --timeout 30000 ./tests-ts/cli.test.ts -t "emits structured failures for machine-readable scan output" (1 passed)
  • bun test --timeout 30000 ./tests-ts/cli-authentication.test.ts (27 passed)
  • Full cli.test.ts run: 143 passed; 2 unrelated configuration-documentation tests failed in the sparse local checkout/environment.
  • Prettier 3.2.5 check passed for all changed files.
  • TypeScript typecheck was not run locally because the full development dependency install exceeded the available local disk space; CI should provide the authoritative typecheck.

Risk and rollout

This is a CLI-only additive output change for machine-readable scan failures. Text output and non-scan commands are unchanged. The process still exits nonzero, and error messages are passed through the existing safety filter before JSON serialization.

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 Aug 28, 2026
@Hughhhhcoder

Copy link
Copy Markdown
Contributor 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: 0ce5e09772

ℹ️ 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/cli.ts
Comment on lines +3035 to +3039
if (format === "json" || format === "jsonl") {
return {
status: "failed",
code: "SCAN_FAILED",
message: safeErrorMessage(outcome.error),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Document the structured failure response

For automation using the advertised scan --schema discovery flow, this introduces a new public JSON/JSONL response contract (status, code, and message) without updating the generic scan output schema or documenting the failure shape and exit semantics in sdk/typescript/README.md; consumers therefore cannot discover or reliably generate types for the new contract. Update the relevant schema and CLI documentation alongside the implementation.

AGENTS.md reference: AGENTS.md:L40-L41

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 7f681ac. The scan command schema now advertises the structured {status: "failed", code: "SCAN_FAILED", message} output variant, sdk/typescript/README.md documents the stdout/stderr and exit-code semantics, and the CLI schema regression test verifies the failure shape. Focused checks pass: Prettier, TypeScript, and the schema/output Bun tests.

@Hughhhhcoder

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 29, 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-08-29T06:09:42.738916Z 7f681ac Manual request
🔒 Security Review Completed 2026-08-29T06:11:06.537827Z 7f681ac 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.

@Hughhhhcoder

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 7f681ac217

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

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.

codex-security scan aborts mid-scan with "flagged for possible cybersecurity risk" on a private enterprise repo

1 participant