Skip to content

fix(review): retry in smaller pieces when the model cannot answer, never print stray JSON, add llm.reasoning_effort - #727

Merged
ajianaz merged 2 commits into
developfrom
fix/review-truncated-reply
Nov 16, 2026
Merged

ajianaz merged 2 commits into
developfrom
fix/review-truncated-reply

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Depends on #733 (it replaces #726, closed). This branch was stacked on it; the diff showed the #720 commit until #733 merged.

What

Three fixes for #718: a model that cannot answer a whole request no longer ends the run (the diff is reviewed again in smaller pieces); JSON that follows the findings array is never printed as a summary; and a new llm.reasoning_effort setting is sent with every request.

Why

Closes #718.

  • A reasoning model can spend the whole output budget on thinking and return an empty reply with finish_reason=length, at any max_tokens. The run then ended with "Review could not complete".
  • extract_json_and_summary treated any text after the first array as the summary (None => rest). A reply like [] followed by a truncated JSON blob became "No issues found!" plus the raw blob.
  • The error message told users to "disable reasoning on the model", but there was no setting for it.

How

Testing

  • cargo test --features tree-sitter passes (1339 unit tests + integration suites)
  • cargo fmt --all -- --check passes
  • cargo clippy --all-targets --features tree-sitter -- -D warnings passes
  • cargo build --release --features tree-sitter passes (left to CI)
  • Manual smoke-test with the real binary and a local fake OpenAI-compatible server that returns an empty reply with finish_reason=length for request bodies above 10.5 KB:
    • default: three requests of about 13.9 KB fail, the diff is split in two, the two requests of about 9.6 KB succeed, exit 0;
    • with a deterministic finding in the diff (so the engine falls back instead of erroring): same recovery, no stale "LLM review failed" text, one finding, not duplicated;
    • --no-auto-chunk (old behaviour): exit 1 with "provider returned an EMPTY response (finish_reason=length)".

Regression tests: stray JSON after an empty array is an error (not a clean pass), stray JSON after findings keeps the findings and drops the blob, prose and ||| summaries still work (a ||| summary may start with a bracket), bracketed prose is not stray, split_for_retry keeps every hunk once, small or single-hunk chunks are not retried, retry_budget is half the diff, reasoning_effort is sent only when configured, config merge and validation of llm.reasoning_effort, and ReviewResponse.judge_failure stays set on the judge fallback.

Related Issues

Closes #718. Related: #720 (#733).

Checklist

  • Branch name follows convention (fix/)
  • Branch is from develop
  • Commit messages follow Conventional Commits
  • No secrets or credentials committed
  • One logical change per PR (no mixed concerns)

ajianaz added a commit that referenced this pull request Nov 16, 2026
…729)

## What
The three CI fixes that only work together, in one PR: the Clippy
`needless_bool` rewrite, the `Cargo.lock` bumps for `rustix` and
`libz-sys`, the `rusqlite` 0.41 upgrade for the SQLite CVE, and the
sorted directory walk that de-flakes a test. It supersedes #728 and
#730, whose commits are included here.

## Why
Every PR to `develop` fails the same three checks, none of them caused
by the PR, so no single fix can be green on its own and none can be
merged under the required checks:
- **Clippy**: `clippy::needless_bool` at `src/engine/rules/builtin.rs`
on Rust 1.100 (the CI toolchain; local 1.97 does not report it).
- **Security Audit (CVE)**: `rustix 1.1.5` (RUSTSEC-2026-0486),
`libz-sys 1.1.30` (RUSTSEC-2026-0418) and `libsqlite3-sys 0.28.0`
(CVE-2026-119375, SQLite before 3.54.0).
- **Test**:
`mcp::agent_tools::tests::finalize_agrees_with_prepare_only_for_the_same_filters`
depends on the filesystem's `readdir` order.

## How
- `26768e8` (#728): `builtin.rs` returns the condition directly;
`Cargo.lock` only: `rustix` 1.1.6, `libz-sys` 1.1.33.
- `beee771`: `rusqlite` 0.31 to 0.41 (`libsqlite3-sys` 0.39.1, SQLite
3.54.1), `rust-version` 1.85 to 1.89, `usize` binds as `i64` in
`index/brain.rs`, and `[lints.clippy] collapsible_if = "allow"` because
Rust 1.89 enables let-chains and clippy would report 56 hits in
untouched code (a wide mechanical rewrite for a later change).
- `1275b71` (#730): `WalkBuilder::sort_by_file_name`, and the test uses
a selection whose `path` and `source-first` orders differ by
construction.
- Two merge commits bring #728 and #730 in with no conflicts.
- MSRV 1.89 is user-visible for anyone building with `cargo install` on
an older toolchain; the release notes should say so.

## Testing

- [x] `cargo test --features tree-sitter` passes (1313 unit tests +
integration suites)
- [x] `cargo fmt --all -- --check` passes
- [x] `cargo clippy --all-targets --features tree-sitter -- -D warnings`
passes (the CI Clippy check on Rust 1.100 is the real proof for
`needless_bool`)
- [ ] `cargo build --release --features tree-sitter` passes (left to CI)
- [x] Locked versions after the merges: rustix 1.1.6, libz-sys 1.1.33,
libsqlite3-sys 0.39.1, rusqlite 0.41.1.
- [x] Database compatibility of the `rusqlite` upgrade was checked in
both directions (old release binary indexed 800 symbols, new build read,
re-indexed and ran a `brain` search on the same `cora.db`, old binary
read it back, `PRAGMA integrity_check` = `ok`).
- Individually, the earlier runs showed: #728 Clippy green (fix proven),
#730 Test green (flake fixed), #729 Audit with only `rustix`/`libz-sys`
left.

## Related Issues
Supersedes #728 and #730. Unblocks #727, #731, #732, #733, #734, #735,
#736, #737.

## Checklist

- [x] Branch name follows convention (`chore/`)
- [x] Branch is from `develop`
- [x] Commit messages follow [Conventional
Commits](https://www.conventionalcommits.org/)
- [x] No secrets or credentials committed
- [x] One logical change per PR: one logical goal (a green CI), several
small causes that cannot be separated under the required checks

🤖 Generated with [Claude Code](https://claude.ai/code)

https://claude.ai/code/session_01F36Uc6swK21c7x7J14k1wc

---------

Co-authored-by: Claude <[email protected]>
@ajianaz
ajianaz force-pushed the fix/review-truncated-reply branch from 8ba088b to 19faea4 Compare November 16, 2026 00:26
ajianaz added a commit that referenced this pull request Nov 16, 2026
…complete (#733)

> Replaces #726 (same commit, `8a9e0ed`). That PR's head branch
`claude/...` failed the Branch Naming check and a head branch cannot be
renamed.

## What
`cora review` now splits a diff above `review.max_chunk_chars` (default
48,000 chars) into chunks, also with `--ci`; adds `review.exclude`
(globs removed from the reviewed diff); and adds
`review.fail_on_incomplete` (default `true`) so a review that skipped
part of the diff names the files and exits 1.

## Why
Closes #720.
- Chunking only started above `hook.max_diff_size` (5 MB) and never with
`--ci`, so a ~1,850-line diff went to the model in one request and
failed with `finish_reason=length`.
- `ignore.files` does not filter the reviewed diff, so docs, lockfiles
and changelogs always counted toward its size.
- A failed model call degraded silently to deterministic findings and
the run exited 0.
- Found while testing: the chunker lost files. It cut each file block at
the wrong header and joined blocks without a newline, so only the last
file of a multi-file chunk parsed back (3 files in, 1 out).

## How
- `engine/chunker.rs`: splitting follows `diff --git` boundaries and is
lossless; a file larger than the budget is split at hunk boundaries with
its header repeated; new `exclude_paths` reuses
`path_match::PathMatcher`.
- `commands/review.rs`: chunk when `diff > min(review.max_chunk_chars,
hook.max_diff_size)`; failed chunks and judge fallbacks are collected
and named; `incomplete_exit_code` turns exit 0 into 1 and never lowers
2.
- `ReviewResponse.judge_failure` (not serialized, like
`dropped_findings`) marks a judge fallback. It replaces the
`starts_with("LLM review failed")` check in the commit gate. JSON and
SARIF output are unchanged.
- Behaviour change: a failed model call in `--format sarif` still emits
valid SARIF but now exits 1 unless `review.fail_on_incomplete: false`.
- Not in this PR: file bundling by CALLS/IMPORTS edges, and the
`exclude` input of `cora-review-action` (separate repo).

## Testing

- [x] `cargo test --features tree-sitter` passes (1329 unit tests +
integration suites)
- [x] `cargo fmt --all -- --check` passes
- [x] `cargo clippy --all-targets --features tree-sitter -- -D warnings`
passes (the CI toolchain additionally reports an unrelated
`needless_bool` in `builtin.rs`, fixed by #728)
- [ ] `cargo build --release --features tree-sitter` passes (left to CI)
- [x] Manual smoke-test with the real binary and a local fake
OpenAI-compatible server:
  - tiny budget in `--ci` mode splits into 3 chunks (before: none);
- `exclude: [CHANGELOG.md]` drops its 200+ findings and names the file;
- chunk 2/2 returns HTTP 500: exit 1 plus "Review incomplete ... Not
reviewed: src/b.rs";
  - same with `fail_on_incomplete: false`: exit 0;
  - single request failing: exit 1; all chunks ok: exit 0.

Regression tests: `every_file_survives_chunking` (fails on the old
chunker), lossless join, hunk split keeps every hunk once, plain unified
diffs, binary/deleted paths, `exclude_paths`, config merge/validate,
`incomplete_exit_code`, coverage note, and `judge_failure` set on the
judge fallback.

## Related Issues
Closes #720. Related: #718 (#727), #728, #729, #730.

## Checklist

- [x] Branch name follows convention (`feat/`)
- [x] Branch is from `develop`
- [x] Commit messages follow [Conventional
Commits](https://www.conventionalcommits.org/)
- [x] No secrets or credentials committed
- [x] One logical change per PR (no mixed concerns)

---
_Generated by [Claude
Code](https://claude.ai/code/session_01F36Uc6swK21c7x7J14k1wc)_

Co-authored-by: Claude <[email protected]>
…ver print stray JSON, add llm.reasoning_effort (#718)

- A reply that stays empty at finish_reason=length, or a failed model call,
  no longer ends the run: the diff is reviewed again in halves and a failing
  chunk is halved again (down to a quarter; a single hunk is not cut).
- Text after the findings array that is not marked with ||| is not a summary
  when it is JSON or a code fence. Findings in the array are kept; with an
  empty array the reply is retried instead of reported as "No issues found".
- Add llm.reasoning_effort, sent as reasoning_effort with every request.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01F36Uc6swK21c7x7J14k1wc
…t only JSON-looking text as stray (#718)

- In the chunk loop the "LLM review failed" summary was pushed before the
  chunk was split and retried, so a run that then succeeded still reported a
  failure. It happens exactly when deterministic findings exist (the judge
  falls back instead of erroring). The summary is now added only for a chunk
  that is kept.
- is_stray_json: `[` opens JSON only when an element or `]` follows, so a reply
  like `[] [INFO] nothing to flag` keeps its summary instead of being retried.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01F36Uc6swK21c7x7J14k1wc
@ajianaz
ajianaz force-pushed the fix/review-truncated-reply branch from 19faea4 to d08adab Compare November 16, 2026 00:33
@ajianaz
ajianaz merged commit 727542d into develop Nov 16, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants