Skip to content

feat(review): inject enclosing control-flow scope into review prompts - #531

Merged
ajianaz merged 1 commit into
developfrom
feat/523-review-enclosing-scope
Aug 27, 2026
Merged

feat(review): inject enclosing control-flow scope into review prompts#531
ajianaz merged 1 commit into
developfrom
feat/523-review-enclosing-scope

Conversation

@ajianaz

@ajianaz ajianaz commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Fixes #523 (stages 1 + 2; stage 3 intentionally deferred)

What

  • New engine::enclosing module: for hunks whose add/context lines touch branching constructs, extract the enclosing function from the post-image file (brace-balance heuristic), clamped to 120 lines with head+tail windowing so shared arms stay visible without token blowup
  • Gated injection: new files, deletions, binaries, non-branching hunks, and unreadable files are skipped
  • Always-on prompt guardrail forbidding reachability claims unless verified against surrounding code

Why

Review run 2 on uteke#1084 flagged a false positive: the handler validated author_type up front and set_author_type sat in a SHARED match arm fed by two producers, but build_review_prompt shipped only raw diff hunks — the LLM reconstructed branch structure from diff shape and got it wrong. Plausible reasoning over missing evidence.

Testing

  • Acceptance fixture mirrors the shared-arm case: both producers visible in injected context
  • Negative case without branching → no injection; new-file skip; clamp bound enforced; guardrail present in every prompt
  • Full suite green (897); fmt clean; zero new clippy findings vs develop

All commits signed-off (DCO).

Review run 2 on uteke#1084 flagged a false positive: the handler
validated author_type up front and set_author_type sat in a SHARED match
arm fed by two producers, but build_review_prompt shipped only raw diff
hunks — the LLM reconstructed branch structure from diff shape and got
it wrong (#523).

- new engine::enclosing module: for hunks whose add/context lines touch
  branching constructs, extract the enclosing function from the
  post-image file (brace-balance heuristic), clamped to 120 lines with
  head+tail windowing so shared arms stay visible without token blowup
- gated injection: new files, deletions, binaries, non-branching hunks,
  and unreadable files are skipped
- always-on prompt guardrail forbidding reachability claims unless
  verified against surrounding code (stage 2 of the issue proposal)
- stage 3 (call-graph reachability cross-check) intentionally left out

Regression tests: acceptance fixture mirrors the shared-arm case (both
producers visible in injected context); negative case without branching;
new-file skip; clamp bound; guardrail presence.

Signed-off-by: ajianaz <ajianaz@users.noreply.github.com>
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.

review: LLM context lacks enclosing control-flow — false positives on shared match arms

1 participant