Repository navigation
Description
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: $?"
doneActual 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:
-
"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. -
"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.
-
"Token confusion from cookie priority inversion" (MAJOR) — FALSE. Both paths produce the same JWT string; there is no confusion possible.
-
"Cookie auth bypasses token_version invalidation" (MAJOR) — FALSE. Cookies only replace the transport mechanism. The JWT still contains
token_versionand is validated by AuthMiddleware afterextractToken()returns.
Root Cause Analysis
Likely causes:
- LLM temperature > 0 in the review prompt — causes non-deterministic output
- No output caching — same diff is re-analyzed from scratch every time
- Possible token limit — large diffs may get truncated differently, causing the LLM to see different code slices
- No structured output validation — the LLM generates free-form JSON that isn't validated against the actual diff
Suggested Fixes
- Set temperature=0 for review prompts (or lowest supported value)
- Cache review results keyed by diff hash — return cached result for identical diffs
- Add structured output validation — verify that reported files, line numbers, and code snippets actually exist in the diff
- Reduce severity for speculative issues — if the LLM can't cite exact code, downgrade to suggestion/info
- 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
Activity