Skip to content

Stop waiting forever on scans that already ended - #144

Open
leenk7991 wants to merge 8 commits into
mainfrom
fix/maven-project-scan
Open

Stop waiting forever on scans that already ended#144
leenk7991 wants to merge 8 commits into
mainfrom
fix/maven-project-scan

Conversation

@leenk7991

@leenk7991 leenk7991 commented Aug 2, 2026

Copy link
Copy Markdown
Member

Stop waiting forever on scans that already ended

corgea wait and corgea scan --wait could hang until the CI job's own
timeout killed them, and in some cases reported a broken scan as a clean one.

What was wrong

  • Failed scans polled forever. The terminal check was status == "complete",
    so the API's incomplete status fell through to the "still running" branch of
    an unbounded loop.
  • The scan-list path never matched. corgea wait without --scan-id
    compared the listing's status against "Complete", but the API reports
    lowercase, so a finished scan was polled again.
  • Failures were invisible. Nothing surfaced failed_reason or per-scanner
    errors, so a scan that died had the same output as one that was slow.
  • "scan_errors": null failed to parse. #[serde(default)] covers a missing
    field, not an explicit null, which the API sends for scans with nothing to
    report — turning a real failure into a generic read error and losing the reason.
  • Tracking links could point at the wrong project. Project names are a
    free-form path segment and CI names them {owner/repo}-{pr}; the unencoded
    / routed the link into a nested path.

What changed

  • classify_scan_status gives one terminal-state contract shared by both wait
    paths. incomplete/failed/error/cancelled are terminal and exit 1;
    unknown statuses keep waiting rather than failing a build on a status the
    server added later.
  • Failures print failed_reason plus the reporting scanners. A scan that
    completes with a scanner's results missing exits 0 with a warning, since
    that is the only place coverage loss is visible.
  • WaitBudget bounds the wait on a single wall clock shared by every read it
    makes, so a stalled request cannot spend the client's 150s timeout on top of
    the budget. Default 10 hours, overridable with CORGEA_SCAN_TIMEOUT_SECONDS.
  • The blocking-rules wait keeps its 15-minute default but is now overridable
    with CORGEA_BLOCKING_RULES_TIMEOUT_SECONDS, for clients whose scans run long.
  • build_scan_url replaces three duplicated URL builders and percent-encodes
    the project-name fallback.
  • check_scan_status is gone; the loop reads the scan directly, because the
    listing omits failed_reason and scan_errors.

Compatibility

Both new response fields are optional and skipped when empty, so older servers
still deserialize and corgea ls --json output is unchanged. Timeouts are
backstops for scans that never report a terminal status — a scan that ends
normally is unaffected, and one that outlives the budget keeps running in the
Corgea cloud.

Tests

tests/cli_scan_wait_terminal_state.rs drives the real binary against a stubbed
scan API and kills it past 30s, so a hang fails a test instead of stalling the
suite: already-failed, fails-mid-poll, degraded-but-complete (via both the first
read and the poll loop), never-finishes, and a stub that accepts the connection
and never answers — covering the budget on both the first read and the loop.
Unit tests cover status classification, timeout parsing and its warning,
WaitBudget, failure and warning formatting with the error-list cap, and
deserialization of missing, null, and partial fields.

Docs: cli.mdx (5 locales), README.md, skills/corgea/SKILL.md.

Linear ticket

Test results

Before fix

2026-08-01 19_48_17-Downloads - File Explorer

After

Screenshot 2026-08-02 at 10 37 05 AM

Comment thread src/utils/api.rs Outdated
Comment thread src/wait.rs Outdated

@corgea-security corgea-security 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.

Automated review risk: 4/5.

The core failure-reporting path breaks when the API returns scan_errors as null. The scan-details fallback URL also mishandles project names containing slashes.

Critical or high-priority changes must be addressed.

Automatic approval was not submitted: automated review found critical or high-priority findings.

@corgea-security corgea-security added the dennis-reviewed Dennis completed an automated review label Aug 2, 2026

@Ibrahimrahhal Ibrahimrahhal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if we check for all scan status why do we need CORGEA_SCAN_TIMEOUT_SECONDS? The issue with this is that we have scans that can take 10 hours or more for big clients. maybe we can set it as 10hours for now and document that clients can override that in the docs

@leenk7991

Copy link
Copy Markdown
Member Author

if we check for all scan status why do we need CORGEA_SCAN_TIMEOUT_SECONDS? The issue with this is that we have scans that can take 10 hours or more for big clients. maybe we can set it as 10hours for now and document that clients can override that in the docs

done, it's set to 10 hours, and documentation updates in https://github.com/Corgea/docs/pull/303

@corgea-security corgea-security 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.

Automated review risk: 2/5.

The diff addresses the existing timeout, null deserialization, and URL-encoding comments with targeted tests. No actionable critical, high-priority, or nitpick findings remain in the supplied diff.

No critical or high-priority changes were found.

Automatic approval was not submitted: changes have been requested.

Comment thread src/scanners/blast.rs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dennis-reviewed Dennis completed an automated review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants