Skip to content

refactor(history): make cora.db the sole review history, drop the .cora/history JSON layer - #731

Merged
ajianaz merged 2 commits into
developfrom
refactor/history-db-sole-source
Nov 16, 2026
Merged

ajianaz merged 2 commits into
developfrom
refactor/history-db-sole-source

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

What

Review history is read from and written to cora.db only. The per-review JSON snapshot in .cora/history/ is no longer written, cora debt no longer falls back to it or prunes it, and the MCP tool cora.get_debt reads the database instead of the JSON files.

Why

Closes #724 (items 1 to 3; item 4, the fleet cleanup of .cora/history/ directories, is not a code change).

  • engine/finalize.rs was the last writer of the JSON layer, costing a file write per review and leaving untracked files in every working tree, although the schema v5 doc says the DB replaces it.
  • cora.get_debt (mcp/tools.rs) read only those files while cora debt read the DB first, so agents got an empty or stale answer on a repository whose history exists only in the DB.

How

  • finalize::save_debt and its three call sites (review single and chunked, commit) are removed; save_history already records the run in cora.db.
  • commands/debt.rs: no load_snapshots fallback, no cleanup_old_snapshots.
  • mcp/tools.rs: handle_get_debt loads load_snapshots_from_db(cwd); the report building moved to debt_report_result so it can be tested.
  • debt_tracker.rs: delete save_snapshot, load_snapshots, cleanup_old_snapshots, snapshot_filename, the history_dir helper and the retention_days() accessor, and their tests. DebtSnapshot::from_review and its score helpers stay as #[cfg(test)] builders. The nine #[allow(dead_code)] on this file were removed; clippy confirms only the dead accessor needed deleting.
  • debt.history_dir is deprecated and ignored but still parses (the config section uses strict parsing, so removing it would break existing .cora.yaml files); retention_days stays for the retention work in feat(findings): retention & hygiene — stale project roots, scan blow-up bounds, recurring aggregation #725.
  • Docs (configuration.md, usage.md) and the changelog are updated. The changelog commit also restores two [Unreleased] entries (the walk-order fix and the stray-JSON fix) that went missing in earlier rebases.

Testing

  • cargo test --features tree-sitter passes (1334 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 check with the real binaries and a throwaway CODECORA_HOME, one project directory: the previous release binary's cora review wrote 1 file to .cora/history/; two runs of the new binary wrote none (still 1 file); cora debt then showed Reviews: 3 (all three, from cora.db); the MCP cora.get_debt over stdio returned total_reviews: 3, and still 3 after .cora/history was moved away.
  • New unit tests: get_debt_without_history_says_so, get_debt_reports_the_loaded_snapshots, and debt_config_still_accepts_the_deprecated_history_dir.

Related Issues

Closes #724. Related: #725 (retention), #727.

Checklist

  • Branch name follows convention (refactor/)
  • 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]>
…ra/history JSON layer (#724)

- Stop writing a DebtSnapshot JSON per review and commit (finalize::save_debt
  and its three call sites).
- `cora debt` no longer falls back to the JSON files or prunes them.
- MCP cora.get_debt read only the JSON snapshots; it now reads cora.db like
  `cora debt`, so it works on repositories whose history is only in the DB.
- Delete save_snapshot, load_snapshots, cleanup_old_snapshots, snapshot_filename
  and the dead_code allows on live items; from_review and its score helpers
  stay as test builders.
- debt.history_dir is deprecated and ignored but still parses.
@ajianaz
ajianaz force-pushed the refactor/history-db-sole-source branch from 3cd14da to 59cd492 Compare November 16, 2026 00:40
The walk-order fix (#729) and the stray-JSON fix (#718) vanished from
[Unreleased] on develop: my changelog resolver dropped bullets that sat before
the first section heading inside a conflict block. The resolver now keeps the
union of both sides and merges sections afterwards.
@ajianaz
ajianaz force-pushed the refactor/history-db-sole-source branch from 509217e to c44c2e1 Compare November 16, 2026 00:48
@ajianaz
ajianaz merged commit f974791 into develop Nov 16, 2026
16 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

Development

Successfully merging this pull request may close these issues.

refactor(history): cora.db as sole SoT — remove legacy .cora/history JSON dual-write (audit 2026-11-14)

1 participant