Skip to content

feat(review): subject-keyed review history with a leave-one-out baseline #607

Closed

Description

@dan-petty

Context & Rationale

Every review report has a "Historical Baseline FP Rate" column (#434). It compares this review session's false-positive rate per category with earlier sessions. Three defects make that figure wrong.

  1. The current session counts itself. generate_consolidated_report writes findings.json (src/devops_cli/ai/review/pipeline.py:3600-3601) before it builds the report (pipeline.py:3616). The baseline reads the session's parent directory (pipeline.py:3034-3035), so the session being compared is part of its own history.
  2. Repeat sessions count again. Every reader sums every session directory: the baseline (src/devops_cli/ai/review/category_metrics.py:114-124), devops review stats (src/devops_cli/commands/review.py:1242, :1141-1159) and the feedback export (src/devops_cli/ai/review/exporter.py:145-153). A re-review, or devops review benchmark (3 sessions by default, src/devops_cli/config/defaults.py:391), counts one subject several times. ReviewSessionPayload (src/devops_cli/ai/review_schema.py:1125-1143) records nothing about what was reviewed, so repeats cannot be told apart. The tests pass target= and timestamp= to it (tests/test_category_metrics.py:173-174, :197-198, :281-282, :300-301). Pydantic ignores unknown fields, so those values are silently dropped.
  3. The two sides count different findings. The session side uses every finding the session raised (candidate_findings or all_findings, pipeline.py:3119-3120). The history side reads findings.json, and the pipeline writes only reportable, non-invalidated findings there (pipeline.py:2840-2846). Every finding goes to candidates.json instead (pipeline.py:3603-3610). In one workstation's history of 26 sessions, findings.json holds 51 invalidated findings out of 2,237 (2.3%), and candidates.json holds 1,840 out of 4,090 (45%).

Evidence:

  • A scratch probe calls format_category_baseline_markdown on a temporary reviews directory. With one earlier VERIFIED session, the cell reads — (baseline established). Once the current INVALIDATED session is written first, it reads 50.0% (1/2). Adding two byte-identical copies of the earlier session makes it 25.0% (1/4). This is a function-level probe: the pipeline itself never writes INVALIDATED findings into findings.json (defect 3).
  • The same 26 sessions cover 8 profile targets. 4 of those targets were reviewed more than once, across 22 sessions. All 26 have a profile.json, which records a target but no commit (src/devops_cli/ai/review/profile.py:101-123). None records a subject, and none holds a human verdict.
  • Benchmark records already have an identity rule: RunRecord.subject_key is run_store.digest(subject) (src/devops_cli/ai/run_store.py:54-57, :89-93). Review sessions are not in that store, and load_runs (run_store.py:201-211) does not collapse repeats either.
  • Two code paths write findings.json. One is the pipeline. The other is _save_findings_json (src/devops_cli/ai/review/runner.py:426-469), reached from _run_persona_loop (runner.py:1257) through _write_summary (runner.py:707-716) when the analysis client is not LLMClient (runner.py:2151). It stamps generated_at in local time (runner.py:451), while the pipeline uses UTC.
  • Human verdicts live only in findings.json: devops review verify sets by = "human" (commands/review.py:1062) and rewrites findings.json alone (commands/review.py:1082).
  • A session run with --no-verification still writes findings.json and candidates.json: the verification stage is skipped (pipeline.py:2671), but reporting is not (pipeline.py:3556). Every finding in it stays UNVERIFIED.
  • A branch review without a named branch diffs the working tree (git diff HEAD, runner.py:1813-1819), so no commit identifies what it reviewed.
  • Full ReviewSessionPayload parsing is slow, because Finding validators normalize every verification criterion (review_schema.py:464-475). With a warm cache, the 26 findings.json files take about 1.7 s and the 26 candidates.json files about 3.4 s. A model holding only the fields the figures read parses both sets in 0.23 s.

Scope & Deliverables

Deliverable: one PR that records what each review session reviewed. History is then read through one reader that leaves out the current session and counts each subject once.

  1. Subject.

    • ReviewSessionPayload gains subject: dict[str, str], empty by default.
    • history.review_subject(target_type, target_ref, pages) returns {"type": target_type, "ref": target_ref, "input": <first 16 hex chars of sha256 over the pages joined by "\n">}. history.subject_key(subject) returns run_store.digest(subject), or None for an empty subject.
    • _execute_review_workflow (runner.py:2115) builds the subject once and passes it to both writers: ReviewPipelineOrchestrator, and _save_findings_json via _run_persona_loop and _write_summary.
    • _save_findings_json stamps generated_at in UTC.
  2. Reader. A new module, src/devops_cli/ai/review/history.py, lists the completed sessions in a reviews directory, meaning those with a findings.json. For each session it returns:

    • its path;
    • its subject key;
    • its profile target, if it has a profile.json;
    • generated_at;
    • the findings in findings.json;
    • every finding it raised (candidates.json if present, otherwise findings.json).

    The reader takes exclude: Path | None and drops that session before it collapses repeats. It parses with a slim pydantic model that holds only the fields the figures read. For each subject key it counts one session, ranked by:

    • most verified_by == "human" findings in findings.json;
    • then most findings raised that carry a verdict (status other than UNVERIFIED);
    • then the newest generated_at.

    Sessions without a subject each count on their own. They are reported as target-only if they have a profile.json, and as unkeyed otherwise.

  3. Baseline.

    • collect_historical_category_metrics reads every finding raised, from the counted sessions, through the reader.
    • format_category_baseline_markdown takes the current session directory as exclude, and _build_category_baseline_section passes self.session_dir.
    • The total_sessions > 1 gate (category_metrics.py:148) changes to: at least one counted earlier session has this category.
    • A line under the table reads _Baseline: {counted} earlier session(s), {repeats} repeat session(s) collapsed, this session excluded._
  4. Stats. devops review stats uses the reader, and its tables count one session per subject. It prints Sessions: {total} (counted {counted}: {repeats} repeat sessions collapsed, {target_only} target-only, {unkeyed} unkeyed). Its findings still come from findings.json (see key question 6).

  5. Tests and docs.

Acceptance criteria: automated tests use tmp_path only, with no network, model or scanner.

  1. Subject recorded.
    • A test runs generate_consolidated_report on a temporary session directory and reads the same subject back from findings.json.
    • A second test calls _save_findings_json with a subject. It reads the subject back, and checks that generated_at parses with a UTC offset.
    • A third test runs devops review verify (CliRunner) on a session and checks that the subject survives the rewrite.
    • A fourth test patches ReviewPipelineOrchestrator and _run_persona_loop, then calls _execute_review_workflow with an analysis client that is not LLMClient. Both patched callables receive review_subject(target_type, target_ref, pages) for the arguments given.
  2. Subject key. A unit test with a tuple assertion checks three cases. The same type, ref and pages give the same key. One changed byte in a page gives a different key. An empty subject gives None. This last case is the guard against every older session collapsing under digest({}).
  3. Reader counts. The fixture has 3 sessions with one subject, 1 target-only session, 1 unkeyed session, and 1 directory without findings.json. The reader returns (sessions, counted, repeats, target_only, unkeyed) == (5, 3, 2, 1, 1). With exclude set to the newest of the 3 same-subject sessions, it returns (4, 3, 1, 1, 1), and the counted session for that subject is the next one by rank. Tuple assertion.
  4. Counted session. Unit test, tuple assertion, three cases within one subject:
    • an older session with a human verdict counts over a newer one without;
    • with no human verdicts, an older session with machine verdicts counts over a newer one whose findings are all UNVERIFIED;
    • otherwise the newest generated_at counts.
  5. Leave-one-out regression. Earlier session P has subject S1. Its candidates.json holds one INVALIDATED and one VERIFIED secret_scanning finding, and its findings.json holds only the VERIFIED one. The current session C also has subject S1 and the newest generated_at. It is written to disk before rendering, as the pipeline does, and passed as exclude.
    • The historical cell reads 50.0% (1/2), and the cell is identical with or without C on disk.
    • After two more sessions with subject S1 and the same findings are added, the cell still reads 50.0% (1/2) and the note line reports 2 repeat sessions collapsed.
  6. Gate. With no earlier session, the cell reads — (baseline established). When C is on disk and the only earlier session has C's subject (a first re-review), the cell shows that earlier session's figures.
  7. Population. A persona-loop-shaped session with findings.json and no candidates.json feeds the baseline from findings.json.
  8. Slim parse. On a fixture that includes a lower-case status and a finding with no category, the reader's per-category figures equal compute_category_metrics over a full ReviewSessionPayload parse of the same files. Tuple assertion.
  9. Stats. CliRunner on the fixture from criterion 3 prints the Sessions: line with those counts, and the status table counts each subject once. Update test_review_stats_command (tests/test_review_verification.py:131).
  10. Speed. Each new or changed test runs in under 1 s, checked with uv run pytest tests/test_category_metrics.py tests/test_review_history.py tests/test_review_verification.py --durations=0. uv run devops ci passes within its 5-minute budget.
  11. Docs. uv run pytest tests/test_agent_task_files.py passes. In PR review: the task file follows the rules in force at merge and has no stale v0.2.24 milestone; the CHANGELOG entry names the feat(review): track false-positive rate across runs #434 correction; docs/ROADMAP.md is edited as in deliverable 5 before feat(github): github-sourced roadmap, migration and generated roadmap view (devops roadmap migrate, render) #739, or untouched after it.
  12. Person-run check (needs the model gateway):
    uv run devops review stats
    uv run devops review benchmark src/devops_cli/ai/review/category_metrics.py --runs 2
    uv run devops review stats
    
    Compared with the first stats, the second shows 2 more sessions, 1 more counted session and 1 more repeat. The second benchmark session's review.md carries the baseline note line.

Key questions:

  1. What identifies a review session's subject? (proposed) {"type", "ref", "input"}, where input is a digest of the review pages, keyed with run_store.digest.

    • One rule covers PRs, branches and paths.
    • It needs no extra git or GitHub call.
    • It covers working-tree branch reviews, which have no commit.
    • A PR's diff changes only when its head or base changes, so the key follows the commits.

    Two limits are accepted. Pages pass through devops-cli's paging and redaction, so a change to either re-keys every subject. A path review's ref is the resolved absolute path, so the same files in another worktree are a different subject. The earlier plan (PR head SHA, branch SHAs, _corpus_digest for paths) needed three rules and missed working-tree diffs. Benchmark run records keep their own subject.

  2. Do personas, models or flags split a subject? (proposed) No. The subject is what was reviewed, as in RunRecord, which keeps subject and setup fingerprint apart. A session over the same subject with different personas counts as a repeat. The counted-session rank (question 4) keeps a --no-verification re-run from displacing a verified session.

  3. Leave out the current session, or its whole subject? (proposed) Only the session, dropped before repeats collapse. Earlier sessions of the same subject count once. Leaving out the whole subject would hide the baseline on every re-review.

  4. Which session counts for a subject? (proposed) The one with the most human verdicts, then the most findings with a verdict, then the newest generated_at. Human verdicts are the only labels a person wrote (commands/review.py:1062), so a later machine session must not displace them. A session whose verification stage was skipped has no verdicts, so it must not displace one that has them. This item does not merge findings across sessions.

  5. How do sessions without a subject count? (from this issue's original constraint) Each counts on its own and is reported as target-only (has a profile.json) or unkeyed. A key is never derived from directory names or profile targets, and these sessions are never dropped. Every session on disk today is target-only.

  6. Which findings does history read? (proposed) The baseline reads every finding raised: candidates.json, otherwise findings.json. That is the same population the session side uses. Stats keeps findings.json, because devops review verify writes human verdicts only there. Its category table therefore still counts reported findings only and will differ from the baseline. Deciding which file holds every finding with every verdict belongs to refactor(review): review session store that owns layout, fingerprints and verdicts #771.

  7. Do human verdicts reach the baseline? (proposed) Not when a session has a candidates.json, because human verdicts are written only to findings.json (commands/review.py:1082). Overlaying them would need a match between consolidated and per-persona findings, which is refactor(review): review session store that owns layout, fingerprints and verdicts #771's job. Today no finding on disk has a human verdict, so nothing is lost yet.

  8. Add a history window? (proposed) No. The earlier plan added a window constant. With 26 sessions over 8 targets on the main workstation, no window would bind yet, and there is no data to calibrate one. Add it when history grows.

  9. Should ReviewSessionPayload forbid unknown fields, so dropped arguments fail loudly? (proposed) No. A findings.json written by a newer version would then fail to load, and the readers skip unreadable files silently. Fix the tests instead.

  10. Where does the reader live? (proposed) In ai/review/history.py, used by category_metrics.py and commands/review.py. refactor(review): review session store that owns layout, fingerprints and verdicts #771's session module can absorb it later.

  11. Does the feedback export change here? (proposed) No. Moving it needs a merge of human verdicts across sessions. That is the split-off item feat(review): feedback export counts each review subject once and keeps every human verdict #877.

  12. Is a full-model parse fast enough? (proposed) No. Use the slim model: 0.23 s against about 5 s warm on today's 26 sessions, and the cost grows with history. Criterion 8 guards against the slim model drifting from the full one.

Constraint:

Strategic Alignment

Activity

  1. added this to the v0.2.23 milestone on Sep 25, 2026
  2. added
    type/feature
    scope/review
    priority/p1-high
    on Sep 25, 2026
  3. modified the milestones: v0.2.23, v0.2.24 on Sep 28, 2026
  4. modified the milestones: v0.2.23, v0.2.25 on Oct 1, 2026
  5. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Retargeted from the shipped v0.2.23 to v0.2.25. It is still valid (checked 2026-10-01), and a P1 left open in a shipped release keeps precedence over P1 work committed later.

  6. changed the title [-]feat(review): run-identity review history with a leave-one-out baseline[/-] [+]feat(review): subject-keyed review history with a leave-one-out baseline[/+] on Oct 1, 2026
  7. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Closed by #940, merged into release/v0.2.25.

    GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by devops gh issues close-merged.

  8. added a commit that references this issue on Oct 3, 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/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions