Skip to content

feat: inject static analysis context into review prompt (#140) - #145

Merged
ajianaz merged 4 commits into
developfrom
feat/static-analysis-context
Jun 2, 2026
Merged

ajianaz merged 4 commits into
developfrom
feat/static-analysis-context

Conversation

@ajianaz

@ajianaz ajianaz commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Reduce cora review false positives by injecting static analysis (clippy) context into the LLM prompt.

Problem: LLM flags intentional changes (dead code removal, match arm merges) as errors because it only sees the diff text — it doesn't know clippy/compiler already verified the change.

Solution: Optional static analysis context injection via two modes:

  1. review.static_analysis.auto_clippy: true — automatically run cargo clippy and filter output to changed files
  2. review.static_analysis.clippy_output_file: path — read pre-computed clippy output from file

Config example (.cora.yaml):

review:
  static_analysis:
    auto_clippy: true

New files:

  • src/engine/static_analysis.rs — clippy runner, file reader, Rust file extraction (5 tests)

Modified:

  • src/config/schema.rs — StaticAnalysisConfig, ReviewSection.static_analysis
  • src/engine/llm.rs — build_review_prompt accepts static_context param
  • src/engine/review.rs — collects static context before LLM call

Zero-config: No behavior change when not configured.

Verification: 229 tests ✅ | clippy ✅ | fmt ✅

Closes #140

Co-Authored-By: codecoradev noreply@github.com

Add optional clippy output injection to reduce false positives:
- New config: review.static_analysis.auto_clippy (run cargo clippy)
- New config: review.static_analysis.clippy_output_file (read pre-computed)
- New module: engine/static_analysis.rs with clippy runner + 5 tests
- Prompt injects context between file paths and diff

Zero-config — no behavior change when not configured.

229 tests pass, clippy clean, fmt clean.

Closes #140

Co-Authored-By: codecoradev <noreply@github.com>
@github-actions

github-actions Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (2)

  • src/engine/static_analysis.rs:30 — collect_static_context is a synchronous function that calls tokio::task::block_in_place. This function is called from review_diff_inner in review.rs which is async, so block_in_place works correctly there. However, block_in_place requires being called from a multi-threaded runtime context. If this function is ever called from outside a tokio runtime (e.g., in tests like empty_config_returns_none), it will panic. The tests currently avoid this because they hit early returns, but this is fragile. Consider making this an async function or documenting the runtime requirement.
  • src/engine/static_analysis.rs:130 — When the 30-second timeout fires, the spawned thread continues to wait for the clippy child process, and the child process keeps running. The child_pid is captured but never used to kill the process. This means orphaned clippy processes can accumulate, consuming CPU and holding file locks. The child handle is moved into the spawned thread, so there's no way to kill it from the timeout path.

Review powered by cora-cli · BYOK · MIT

CTO Hermes and others added 3 commits June 3, 2026 01:01
1. UTF-8 safe truncation (is_char_boundary instead of byte slice)
2. block_in_place for async compatibility
3. 30-second timeout via thread + channel
4. Path traversal guard on clippy_output_file

Co-Authored-By: codecoradev <noreply@github.com>
- Switch to wait_with_output() inside spawned thread (no stdout/stderr
  ownership ambiguity)
- Apply cargo fmt

Co-Authored-By: codecoradev <noreply@github.com>
- Wrap collect_static_context in block_in_place for async safety
- Add unused_mut allow (child moved into thread)
- Document process lifecycle on timeout

Co-Authored-By: codecoradev <noreply@github.com>
@ajianaz
ajianaz merged commit 2b5c76e into develop Jun 2, 2026
7 checks passed
@ajianaz
ajianaz deleted the feat/static-analysis-context branch June 2, 2026 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reduce cora review false positives by injecting static analysis context

1 participant