Skip to content

Bug: Non-deterministic review output — same diff produces different issues on every run #97

Closed

Description

@ajianaz

Bug Description

cora review --staged produces different issues, different severities, and different line numbers on every run against the exact same staged changes. This makes the pre-commit hook unreliable — a commit may pass on one run but fail on another.

Environment

  • cora version: 0.1.6
  • OS: Linux 6.8.0-1052-oracle (aarch64)
  • Staged diff size: ~611 lines across 8 files (Go + Svelte/TS)
  • Review mode: cora review --staged --format compact

Reproduction Steps

With the same staged changes (no modifications between runs):

for i in 1 2 3; do
  echo "--- Run $i ---"
  cora review --staged --format compact
  echo "EXIT: $?"
done

Actual Output

Run Issues Found Severity Mix Example Titles
1 2 0 CRITICAL, 2 MAJOR "Refresh token from cookie bypasses body validation path"
2 5 2 CRITICAL, 3 MAJOR "Cookie-based tokens bypass CSRF protection", "Token confusion"
3 3 0 CRITICAL, 3 MAJOR "restore() silently swallows auth errors"
4 4 1 CRITICAL, 3 MAJOR "OAuth callback page may not receive server-redirect with cookies"
5 — — Command interrupted (timeout)

Format inconsistency: --format compact and --format json also produce different issues for the same diff.

Expected Output

Same staged diff → identical issues (same files, lines, severities, titles) on every run. The only acceptable variance is ordering.

Specific False Positives Generated

Some issues are clearly incorrect, suggesting the LLM is hallucinating:

  1. "Cookie-based tokens bypass CSRF protection" (CRITICAL) — FALSE. The code sets SameSite: "Lax" on all cookies, which IS CSRF protection. The LLM didn't read the cookie configuration.

  2. "Refresh token sent in body AND cookie causes double-use" (MAJOR) — FALSE. The code checks body first; only falls back to cookie if body is empty. There is no double-use path.

  3. "Token confusion from cookie priority inversion" (MAJOR) — FALSE. Both paths produce the same JWT string; there is no confusion possible.

  4. "Cookie auth bypasses token_version invalidation" (MAJOR) — FALSE. Cookies only replace the transport mechanism. The JWT still contains token_version and is validated by AuthMiddleware after extractToken() returns.

Root Cause Analysis

Likely causes:

  1. LLM temperature > 0 in the review prompt — causes non-deterministic output
  2. No output caching — same diff is re-analyzed from scratch every time
  3. Possible token limit — large diffs may get truncated differently, causing the LLM to see different code slices
  4. No structured output validation — the LLM generates free-form JSON that isn't validated against the actual diff

Suggested Fixes

  1. Set temperature=0 for review prompts (or lowest supported value)
  2. Cache review results keyed by diff hash — return cached result for identical diffs
  3. Add structured output validation — verify that reported files, line numbers, and code snippets actually exist in the diff
  4. Reduce severity for speculative issues — if the LLM can't cite exact code, downgrade to suggestion/info
  5. Add deterministic post-processing — deduplicate and normalize issue titles

Additional Issue: Timeout/Hang

cora review --staged sometimes hangs with no output for 30-45 seconds before either completing or being killed by timeout. For a pre-commit hook, this should have:

  • A progress indicator during LLM processing
  • A configurable timeout with graceful failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions