Skip to content

fix: propagate score_lines errors, fix compact response shape (CodeRabbit follow-up) - #196

Merged
getappz merged 1 commit into
masterfrom
fix/compact-error-propagation-and-response-shape
Jul 15, 2026
Merged

fix: propagate score_lines errors, fix compact response shape (CodeRabbit follow-up)#196
getappz merged 1 commit into
masterfrom
fix/compact-error-propagation-and-response-shape

Conversation

@getappz

@getappz getappz commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Summary

Follow-up addressing 2 CodeRabbit findings from the PR #193 review that were on src/compact.rs/src/memory/mcp.rs (unrelated to #193's actual scope — that code came from an earlier duplicate branch and was reconciled against the already-merged, already-fixed version from #192/#195; these 2 are new findings against that merged code).

  • score_lines() used .expect() on every SQLite call (connection, table create, insert, query) and would panic on any SQLite failure, even though handle_compact (its only non-hook caller) already returns a Result. Now returns rusqlite::Result<Vec<ScoredLine>> and propagates. The PreCompact hook caller has no Result to propagate through, so it fails soft (skips output) on error, consistent with its existing degrade-gracefully pattern for a missing/unreadable transcript.
  • handle_compact's empty-entries early-return response ({"lines": [], "kept": 0, "total": 0}) was missing the "query" field the full response includes — a client relying on a consistent response shape could break on the empty-input path. Added it.

Test plan

  • cargo test --workspace — all passing, new regression test for the response-shape fix
  • cargo clippy --workspace --all-targets -- -D warnings -A unsafe_code -A clippy::pedantic — clean
  • cargo fmt --check — clean

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling during line scoring to prevent crashes when database or query operations fail.
    • Compaction now safely stops when scoring cannot be completed.
    • Empty compaction responses now consistently include the submitted query.
  • Tests
    • Added coverage for query details in empty compaction responses and updated scoring tests for error handling.

- score_lines now returns rusqlite::Result<Vec<ScoredLine>> instead of
  panicking via .expect() on every SQLite call (connection, table
  create, insert, query). handle_compact already returns Result and
  now propagates a scoring failure as an error; the PreCompact hook
  (which has no Result to propagate through) fails soft and skips
  output instead, consistent with its existing degrade-gracefully
  pattern for a missing/unreadable transcript.
- handle_compact's empty-entries early return was missing "query" from
  its response, unlike the full response -- clients relying on a
  consistent shape could break on the empty-input path. Added it.
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: fe6574ef-7419-4480-b6b5-10bda53ef86b

📥 Commits

Reviewing files that changed from the base of the PR and between be22ffc and 094edd5.

📒 Files selected for processing (3)
  • src/compact.rs
  • src/hook.rs
  • src/memory/mcp.rs

📝 Walkthrough

Walkthrough

Compact scoring now returns SQLite errors instead of panicking, and callers handle failures explicitly. Empty compaction responses now retain the input query, with tests updated for both behaviors.

Changes

Compact scoring and response handling

Layer / File(s) Summary
Fallible scoring API
src/compact.rs
score_lines returns rusqlite::Result, propagates SQLite and row-mapping errors, and tests unwrap successful results.
Caller errors and empty responses
src/hook.rs, src/memory/mcp.rs
pre_compact exits when scoring fails, while empty handle_compact responses include and test the supplied query.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: error propagation in score_lines and the compact response shape fix.
Description check ✅ Passed The description covers the required Summary and Test plan sections; the reviewer notes section is missing but non-critical.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/compact-error-propagation-and-response-shape

Comment @coderabbitai help to get the list of available commands.

@getappz
getappz merged commit 342c4c3 into master Jul 15, 2026
14 checks passed
@getappz
getappz deleted the fix/compact-error-propagation-and-response-shape branch July 15, 2026 11: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.

1 participant