Skip to content

refactor(review): review session store that owns layout, fingerprints and verdicts #771

Closed

Description

@dan-petty

Ready: implementation plan (refined 2026-10-17 at 3dd7fa6)

This section supersedes any text below that conflicts with it.

Decisions

Delivery

  1. PR 1 (M): one resolver. Add src/devops_cli/review/session.py with ReviewSessionStore.root(). Delete _get_reviews_base_dir and the dashboard's _reviews_root, and point every caller at the store. Add the review_store fixture and replace the 15 patches. Tests first: the dashboard test from the body. It removes DEVOPS_CLI_DATA_DIR, points data.dir at one temporary directory and DEVOPS_CLI_DATA_REVIEWS_DIR at another, writes a session, and asserts that list_review_sessions lists it; it fails today. A second test asserts that root() creates no directory when nothing is written. Files: src/devops_cli/review/session.py, src/devops_cli/ui/data_providers.py, src/devops_cli/ai/review/review_environment.py, runner.py, pipeline.py, exporter.py, category_metrics.py, src/devops_cli/commands/review.py, tests/conftest.py, and the 7 test files with patches. Refs refactor(review): review session store that owns layout, fingerprints and verdicts #771.
  2. PR 2 (M): atomic writes and the marker. ReviewSession gets write_findings, write_raised (still writing candidates.json until PR 3), write_sarif, write_report, write_profile, write_analysis, write_payload and commit. The pipeline's _persist_session_artifacts, the runner's profile write, the per-file payload writes and analysis.json go through them. Every run that writes a report calls commit() after the profile. Listing and latest() use the marker. Tests first: a store whose raised-findings write raises leaves a session that sessions() marks incomplete and latest() skips; a recording writer shows complete.json written after profile.json; a session dir without complete.json (as every session on disk today) is incomplete; the dashboard lists an in-flight session as incomplete. Files: src/devops_cli/review/session.py, src/devops_cli/ai/review/pipeline.py, runner.py, profile.py, src/devops_cli/review/analysis.py, src/devops_cli/ui/data_providers.py, src/devops_cli/config/constants.py, tests/test_review_session_store.py (new). Refs refactor(review): review session store that owns layout, fingerprints and verdicts #771.
  3. PR 3 (L): every reader goes through the store, and the rename. This covers history, the exporter, review stats, review findings, review verify, review score, the corpus commands, _find_session_dir and the dashboard summary. adjudication.py reads and writes through the store. The file becomes raised_findings.json, the options become --raised, and the KB article that names the files is updated. Tests first: the rg check below as a test in tests/test_architectural_invariants.py; review verify --raised 1 on a review_store session records the verdict on both files; review findings --candidates exits 2. Files: src/devops_cli/review/session.py, src/devops_cli/ai/review/adjudication.py, history.py, exporter.py, src/devops_cli/review/score.py, src/devops_cli/commands/review.py, src/devops_cli/ui/data_providers.py, src/devops_cli/lang/en/help.py, src/devops_cli/config/constants.py, src/devops_cli/ai/knowledge_base/devops_cli/tasks/ai_code_review.md, and generated CLI docs. Closes refactor(review): review session store that owns layout, fingerprints and verdicts #771.

Acceptance criteria

  • One function resolves the sessions directory, and the writer, the dashboard and every reader use it. The dashboard test above passes, and it fails on the code at 3dd7fa6.
  • A session is complete only once complete.json exists. The store writes it after findings.json, raised_findings.json, findings.sarif, review.md, profile.json and (when group analysis ran) analysis.json. Each file is written to a temporary file and renamed into place.
  • Listing marks completeness, and latest() and every reader return only complete sessions. A failed raised_findings.json write leaves a session the store does not list as complete.
  • No module outside the store builds a session file path: rg -n '"(findings|raised_findings|candidates|profile|analysis|complete)\.json"|CONST_REVIEW_(FINDINGS|RAISED_FINDINGS|CANDIDATES|SARIF|ANALYSIS|REPORT|PROFILE|VERDICT_LOCK|SESSION_COMPLETE)_FILENAME|CONST_REVIEW_PAGES_DIRNAME' src/devops_cli -g '!src/devops_cli/config/**' matches only src/devops_cli/review/session.py.
  • adjudication.py reads and writes through the store and keeps its lock and its put-back on a failed write. The existing verdict tests pass.
  • rg -n "_get_reviews_base_dir|_reviews_root" src tests returns nothing, and one review_store fixture serves the tests that patched it.
  • devops review findings --raised and devops review verify --raised <n> replace --candidates and --candidate, and rg -n "candidates\.json" src/devops_cli returns nothing.
  • Tests run offline in tmp_path, with no network or model, and each new test runs under 1 s.
  • changelog.d/771.md records the change; CHANGELOG.md and docs/ROADMAP.md are not edited.
  • uv run devops ci passes.

Current references

  • Dashboard resolver: src/devops_cli/ui/data_providers.py:498-517; its readers :531-553 (findings.json at :544), :556-580, :583-592.
  • Review resolver: src/devops_cli/ai/review/review_environment.py:169-185; setting DEVOPS_CLI_DATA_REVIEWS_DIR: src/devops_cli/config/settings.py:604; resolve_review_data_path: src/devops_cli/core/repo.py:326.
  • Session writes: src/devops_cli/ai/review/pipeline.py:4736-4779 (findings.json :4748, candidates :4751, SARIF :4778, review.md :4779); per-file payloads :3192-3196, :3828-3832; session dir and files/ :2421-2424.
  • Profile: written at src/devops_cli/ai/review/runner.py:942; ReviewProfile.write/load src/devops_cli/ai/review/profile.py:167-179; PROFILE_FILENAME :44.
  • analysis.json: src/devops_cli/review/analysis.py:863-868.
  • Readers that treat findings.json as "complete": src/devops_cli/ai/review/history.py:187; src/devops_cli/ai/review/runner.py:122; src/devops_cli/commands/review.py:1818, :1828; src/devops_cli/ui/data_providers.py:544, :592.
  • Other readers: src/devops_cli/ai/review/history.py:207-212; src/devops_cli/ai/review/exporter.py:35, :135, :164-191; src/devops_cli/commands/review.py:1038-1047, :1081-1133, :1321, :2174-2177; src/devops_cli/review/score.py:407, :425, :455; src/devops_cli/ai/review/category_metrics.py:95-97.
  • Candidate options: src/devops_cli/commands/review.py:1019, :1163.
  • Adjudication lock and put-back: src/devops_cli/ai/review/adjudication.py:76-102.
  • File-name constants: src/devops_cli/config/constants.py:872-882, :4038.
  • Atomic writer: src/devops_cli/output/file_writer.py:80-111, :202; SARIF builder src/devops_cli/security/sarif.py:241, plain writer :273-282.
  • Test fixture: tests/conftest.py:354-361. Patches: tests/test_review_defects.py (5), tests/test_review_runner.py (2), tests/test_run_store.py (2), tests/test_review_profile.py (2), tests/test_review_path.py (2), tests/test_review_backend_activity.py (1), tests/test_review_untrusted_tree.py (1).

Dependencies and order


Context & Rationale

A review session's files have no owner. The literal "findings.json" appears 18 times across 6 files, and its two writers disagree: the pipeline moves INVALIDATED findings out of findings.json into candidates.json (ai/review/pipeline.py:2739), while the legacy runner keeps them. The exporter (whose default filter is INVALIDATED), review stats and category_metrics read only findings.json; the latest session holds 0 INVALIDATED findings there and 48 in candidates.json.

review verify rewrites only findings.json, picks a finding by position or title substring, and counts from 1 where MCP counts from 0. Learning side effects are wired by hand (5 auto_record_invalidated_finding calls among 23 apply_verdict calls), and verdict strings appear about 150 times across 16 files. Intake (#742) will take verified findings about merged code as candidates and needs one place to read them, and candidates.json collides with the glossary's Candidate.

Scope & Deliverables

  • Deliverable: one review session module that owns creating and finding sessions, the on-disk layout, which findings are reportable and which are all findings, a stable fingerprint per finding, and recording verdicts together with their learning side effects.
    • The pipeline, CLI, MCP, UI, exporter and stats go through it instead of reading paths.
    • Intake reads verified findings by fingerprint through it.
    • candidates.json is renamed.
    • Tests use a temporary-directory session instead of writing and parsing session files by hand.
  • Constraint: machine and human verdicts take the same write path.

Strategic Alignment

  • Milestone: Backlog (no release)
  • Design: CONTEXT.md (Review session, Finding, Verdict, Candidate)
  • Depends on: none

Scope added 2026-10-02: the architecture review of 2026-10-02 (candidate 3) measured the session layout. Checked at 38517a8, including what has changed since this item was filed.

  • Since filing: fix(review): verdicts land on the finding shown, record who gave them, and machine-invalidated candidates can be overturned #949 (e4ea2e0) added ai/review/adjudication.py. A person's or an agent's verdict now takes a per-session lock, writes findings.json and candidates.json together and puts both back if a write fails. The CLI and MCP count from 1 alike, and a person's verdict records its catalog and ledger side effects there. feat(review): subject-keyed review history with a leave-one-out baseline #607 (35401dc) added a new reader, ai/review/history.py. refactor(review): delete the legacy segment engine so the orchestrator is the only review engine #995's proposed scope makes generate_consolidated_report the only writer of findings.json.

  • The session's files are written by ai/review/pipeline.py (findings.json at :3701, candidates.json at :3709, review.md at :3728, per-file JSON under files/ at :1283, :2037, :2736 and :2896), by ai/review/profile.py (profile.json, written at runner.py:2045 after the orchestrator returns) and by the legacy runner (runner.py:434).

  • Five modules treat "findings.json exists" as "complete": ui/data_providers.py:549, ai/review/exporter.py:147, ai/review/history.py:163, ai/review/runner.py:397 and commands/review.py:1488 and :1498. But findings.json is written first, not last, and every file is written with a plain write_text. A reader during the rest of the write, or after a crash in it, sees a "complete" session without candidates.json, and history.py:186 then reads no candidates for it. The intended order is stated only in a docstring (ui/data_providers.py:563-566).

  • Two functions resolve where sessions live, and they disagree. _get_reviews_base_dir (ai/review/review_environment.py:160-173) uses DEVOPS_CLI_DATA_DIR/reviews or the data.reviews_dir setting. The dashboard's _reviews_root (ui/data_providers.py:503-523) uses DEVOPS_CLI_DATA_DIR or data.dir, plus reviews, and ignores data.reviews_dir (DEVOPS_CLI_DATA_REVIEWS_DIR, config/settings.py:551). With that setting pointed elsewhere, reviews are written where the dashboard does not look (found by reading the code, not run).

  • Session file names appear in about 25 lines of 7 modules, imports excluded. Tests patch runner._get_reviews_base_dir at 12 sites in 5 files.

  • Order: after refactor(review): delete the legacy segment engine so the orchestrator is the only review engine #995, so the store takes over one writer of findings.json, not two.

  • One function resolves the sessions directory. The writer, the dashboard and every reader use it. A test removes DEVOPS_CLI_DATA_DIR (the autouse isolate_data_dir fixture sets it, tests/conftest.py:269-278, and it takes precedence in _get_reviews_base_dir), points data.dir at one temporary directory and DEVOPS_CLI_DATA_REVIEWS_DIR at another, writes a session, and asserts that the dashboard's list_review_sessions lists it. The test fails on the current code.

  • A session counts as complete only once findings.json, candidates.json, review.md and profile.json are all written: whatever marks completion is written after the others. Each file is written to a temporary file and renamed into place. Listing and "latest" return only complete sessions. Keeping findings.json as the marker and writing it last keeps every session already on disk complete, with no compatibility code. A test that fails the write of candidates.json leaves a session that the store does not list as complete.

  • No module outside the store builds a session file path. rg -n '"(findings|candidates|profile)\.json"|CONST_REVIEW_(FINDINGS|CANDIDATES)_FILENAME|PROFILE_FILENAME' src/devops_cli -g '!src/devops_cli/config/**' matches only the store module.

  • adjudication.py reads and writes the session through the store, keeping its lock and put-back. Machine and human verdicts then share one write path, as the Constraint requires. This item does not move verdict side effects, which adjudication.py (fix(review): verdicts land on the finding shown, record who gave them, and machine-invalidated candidates can be overturned #949) and refactor(review): one finding verifier owns the verdict and its side effects #996 own.

  • One store fixture replaces the 12 _get_reviews_base_dir patches (test_review_defects.py 5, test_review_runner.py 2, test_run_store.py 2, test_review_profile.py 2, test_review_backend_activity.py 1).

Update 2026-10-08: refinement

The item holds: _reviews_root (ui/data_providers.py:503-522) ignores data.reviews_dir, and the report writes four files with plain write_text (ai/review/pipeline.py:4873-4934).

Proposed design

Problem statement

The review session's on-disk files (findings.json, candidates.json, review.md, profile.json, findings.sarif) are written and read by seven or more modules with no single owner. Two functions disagree on where sessions live, the completion marker is written first rather than last, files are written with plain write_text (no atomicity), and the literal filename appears in roughly 25 lines across 7 modules. This makes it impossible for new consumers such as intake (#742) to reliably read verified findings, causes the dashboard to miss sessions when data.reviews_dir is set, and leaves readers seeing incomplete sessions after a crash mid-write.

Acceptance criteria

  • Criterion 1: One function resolves the sessions directory, and the writer, the dashboard, and every reader use it. A test removes DEVOPS_CLI_DATA_DIR, points data.dir at one temporary directory and DEVOPS_CLI_DATA_REVIEWS_DIR at another, writes a session, and asserts that the dashboard's list_review_sessions lists it. The test fails on the current code.
    Verification: Run the new test (e.g. pytest tests/ -k 'test_reviews_dir_disagreement' or equivalent) and confirm it passes after the change and fails when run against the pre-change code.
  • Criterion 2: A session counts as complete only once findings.json, candidates.json, review.md, profile.json and findings.sarif are all written; the completion marker (findings.json) is written after the others; each file is written to a temporary file and renamed into place. Listing and 'latest' return only complete sessions. A test that fails the write of candidates.json leaves a session the store does not list as complete.
    Verification: Run the new incomplete-session test (e.g. pytest tests/ -k 'test_incomplete_session_not_listed') and confirm it passes; also confirm that an existing session on disk (written before the change) is still listed as complete.
  • Criterion 3: No module outside the store builds a session file path. The rg check for findings.json, candidates.json, profile.json, findings.sarif and the related constants matches only the store module.
    Verification: Run: rg -n '"(findings|candidates|profile).json"|findings.sarif|CONST_REVIEW_(FINDINGS|CANDIDATES)_FILENAME|PROFILE_FILENAME' src/devops_cli -g '!src/devops_cli/config/**' and confirm the only matches are in the new store module.
  • Criterion 4: adjudication.py reads and writes the session through the store, keeping its per-session lock and put-back on failure. Machine and human verdicts share one write path. Verdict side effects (catalog, ledger) remain in adjudication.py and are not moved by this item.
    Verification: Run the existing adjudication tests (pytest tests/ -k 'adjudication') and confirm they pass; inspect adjudication.py to confirm it calls the store's read/write methods and retains its lock and rollback logic.
  • Criterion 5: One store fixture replaces the 12 _get_reviews_base_dir patches across test_review_defects.py (5), test_review_runner.py (2), test_run_store.py (2), test_review_profile.py (2), and test_review_backend_activity.py (1).
    Verification: Run: rg -n '_get_reviews_base_dir' tests/ and confirm zero matches; run the full test suite for those five files and confirm they pass.

Key questions

Open questions

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#995


Reopened on 2026-10-23 after an early close

devops roadmap close closed this issue on 2026-10-22 after the first part (#1830). The text of that pull request held a closing keyword in a sentence about a later pull request, and the parser read it as a closing link. The pull request itself said Part of. The closing was wrong, because two parts remain.

Delivered in v0.2.39:

Not delivered. These parts stay open and carry no milestone until the roadmap jobs place them:

  1. Every reader and writer goes through the store: history, the exporter, review stats, review findings, review verify, review score, the corpus commands, _find_session_dir, and the dashboard summary and adjudication. No module outside the store names a session file.
  2. candidates.json becomes raised_findings.json, and --candidates and --candidate become --raised, with the changelog fragment and the generated CLI docs.

The task file docs/agent/tasks/task-771-review-session-store.md lists both parts. The pull request that finishes this issue adds changelog.d/771.md.

Activity

  1. added
    type/refactor
    scope/review
    priority/p1-high
    on Oct 1, 2026
  2. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Review redesign (#1137, 2026-10-03): linked, not re-scoped. This item keeps its session-store scope. The redesign's phase P3 job queue (P3-1) will be its own item when that phase starts; reusing this issue's number for it was considered and rejected.

  3. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Linked: #872 and #1008 edit the same constructor and report writer (ai/review/pipeline.py:2372-2377, :4811-4958); whichever lands second rebases. #1141 owns finding identity; the store keys verdicts on its fingerprint. Found by the 2026-10-08 backlog review.

  4. modified the milestones: v0.2.34, v0.2.36 on Oct 9, 2026
  5. dan-petty commented on Oct 14, 2026

    @dan-petty
    OwnerAuthor

    Moved to the backlog: it was New, not Ready, when v0.2.36 started. (devops roadmap reprioritize)

  6. added this to the v0.2.37 milestone on Oct 17, 2026
  7. dan-petty commented on Oct 17, 2026

    @dan-petty
    OwnerAuthor

    Readiness check for v0.2.37, against release/v0.2.36 at 22d8748. Line numbers are at that commit.

    Status: ready after a reference refresh. Land it after #1151, or first agree what replaces _are_findings_duplicate: #1151 deletes it, and adjudication.py uses it.

    Today

    References that moved

    Dependencies

    Questions for the owner

    Slices (L overall)

    1. (S) One resolver, plus a dashboard test.
    2. (M) Atomic writes, the marker written last, and listing only complete sessions.
    3. (M/L) Move the readers, adjudication and the fixture, and rename the file.

    The store is a new src/devops_cli/review/session.py, tested with a single tmp_path store fixture. The dashboard-directory test and the failed-candidates-write test come first.

  8. removed this from the v0.2.37 milestone on Oct 17, 2026
  9. dan-petty commented on Oct 17, 2026

    @dan-petty
    OwnerAuthor

    Moved to the backlog: it was New, not Ready, when v0.2.37 started. (devops roadmap reprioritize)

  10. 5 remaining items

  11. modified the milestones: , v0.2.39 on Oct 20, 2026
  12. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1830, merged into release/v0.2.39 as 893e535.

    Summary

    Two functions resolved where review sessions live and disagreed: the review writer's _get_reviews_base_dir followed data.reviews_dir, while the dashboard's _reviews_root read data.dir/reviews. With DEVOPS_CLI_DATA_DIR unset, data.dir at one directory and DEVOPS_CLI_DATA_REVIEWS_DIR at another, the writer put a session in the second and the dashboard listed none of the review that had just run.

    This is the first part of giving a review session one owner. ReviewSessionStore.root() in src/devops_cli/review/session.py is now the one resolver: $DEVOPS_CLI_DATA_DIR/reviews when the variable is set, otherwise data.reviews_dir, a relative path under the review data root (resolve_review_data_path), resolved, refused with a SecurityError for a traversal sequence or a host system directory, and never created (writing a session creates it). _get_reviews_base_dir and _reviews_root are deleted and every caller (commands/review.py, ai/review/pipeline.py, exporter.py, category_metrics.py, runner.py, the dashboard) uses root().

    The dashboard no longer swallows a settings failure to fall back on ./.data. It answers a refused directory (DevOpsCLIError), an unreadable one (OSError) and a settings value the schema refuses (ValueError, as data.reviews_dir: [1, 2] raises) with a warning and no sessions, so the review panel stays empty instead of raising on every refresh. The swallowed-failures ceiling for `src/devops_cli/ui/data_prov…

    26 file(s) changed.

    How it was verified

    Check runs at 28bea5f:

    • Audit Defect PR Hardening: skipping
    • Prune PR DevContainer Images: pass
    • zizmor: pass
    • devops-cli: pass
    • bandit: pass
    • CodeQL: pass
    • DevContainer Image: skipping
    • Dependency Freshness: skipping
    • Fail-to-Pass Check: pass
    • Fail-to-Pass Self-Check: pass
    • Changed-Test Independence: pass
    • Rule Pack Tests: pass
    • Tests & Coverage: pass
    • Analyze (python): pass
    • Analyze (actions): pass
    • Static Analysis: pass
    • Service Image: skipping

    Acceptance Criteria of docs/agent/tasks/task-771-review-session-store.md:

    No Acceptance Criteria section.

  13. removed this from the v0.2.39 milestone on Oct 23, 2026
  14. dan-petty commented on Oct 23, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1830, merged into release/v0.2.39 as 893e535.

    Summary

    Two functions resolved where review sessions live and disagreed: the review writer's _get_reviews_base_dir followed data.reviews_dir, while the dashboard's _reviews_root read data.dir/reviews. With DEVOPS_CLI_DATA_DIR unset, data.dir at one directory and DEVOPS_CLI_DATA_REVIEWS_DIR at another, the writer put a session in the second and the dashboard listed none of the review that had just run.

    This is the first part of giving a review session one owner. ReviewSessionStore.root() in src/devops_cli/review/session.py is now the one resolver: $DEVOPS_CLI_DATA_DIR/reviews when the variable is set, otherwise data.reviews_dir, a relative path under the review data root (resolve_review_data_path), resolved, refused with a SecurityError for a traversal sequence or a host system directory, and never created (writing a session creates it). _get_reviews_base_dir and _reviews_root are deleted and every caller (commands/review.py, ai/review/pipeline.py, exporter.py, category_metrics.py, runner.py, the dashboard) uses root().

    The dashboard no longer swallows a settings failure to fall back on ./.data. It answers a refused directory (DevOpsCLIError), an unreadable one (OSError) and a settings value the schema refuses (ValueError, as data.reviews_dir: [1, 2] raises) with a warning and no sessions, so the review panel stays empty instead of raising on every refresh. The swallowed-failures ceiling for `src/devops_cli/ui/data_prov…

    26 file(s) changed.

    How it was verified

    Check runs at 28bea5f:

    • Audit Defect PR Hardening: skipping
    • Prune PR DevContainer Images: pass
    • zizmor: pass
    • devops-cli: pass
    • bandit: pass
    • CodeQL: pass
    • DevContainer Image: skipping
    • Dependency Freshness: skipping
    • Fail-to-Pass Check: pass
    • Fail-to-Pass Self-Check: pass
    • Changed-Test Independence: pass
    • Rule Pack Tests: pass
    • Tests & Coverage: pass
    • Analyze (python): pass
    • Analyze (actions): pass
    • Static Analysis: pass
    • Service Image: skipping

    Acceptance Criteria of docs/agent/tasks/task-771-review-session-store.md:

    No Acceptance Criteria section.

  15. added a commit that references this issue on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1-highscope/reviewtype/refactor

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions