Skip to content

feat(assertions): persist finding candidates - #2812

Merged
Sinity merged 1 commit into
masterfrom
feature/fanout/rxdo-lifecycle
Jul 13, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fanout/rxdo-lifecycle

Conversation

@Sinity

@Sinity Sinity commented Jul 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds AssertionKind.FINDING and a polylogue.finding.v1 writer that stores detector claims in the existing candidate/judge/promotion lifecycle.

Problem

Detector results with denominators, statistics, and query/result evidence had no durable claim row, so they could not be reviewed, judged, or cited through the assertion lifecycle.

Solution

  • Adds FindingAssertion, deterministic identity over claim, target, canonical value, sorted evidence, and detector ref, plus the upsert_findings_as_assertions writer.
  • Persists required finding evidence (query_ref, result_set_ref), optional delta baseline/current refs, and an additive expected shape for later rigor work.
  • Registers the kind in claim/candidate-review/audit inventories and regenerated OpenAPI/CLI schemas; no user-tier migration is needed because assertions.kind is schema-free TEXT.
  • Keeps query/result refs opaque at this writer boundary; the parallel substrate owns their canonical identity grammar.

Acceptance criteria

Criterion Status Evidence
Pathology-style deterministic writer Satisfied upsert_findings_as_assertions and idempotency test
Judgment queue and lifecycle reuse Satisfied candidate and acceptance assertions use judge_assertion_candidate unchanged
Evidence refs retained Satisfied query/result/baseline/current refs are assertion evidence
Schemas and user audit Satisfied regenerated artifacts and every-kind audit invariant
Identical rerun adds no row Satisfied focused idempotency assertion

Verification

  • TMPDIR=/realm/tmp POLYLOGUE_PYTEST_WORKERS=1 devtools test tests/unit/storage/test_archive_tiers_assertions.py tests/unit/storage/test_archive_tiers_user_audit.py → 30 passed.
  • TMPDIR=/realm/tmp devtools verify --quick → all 15 steps passed.
  • devtools render all --check → exit 0; no out of sync output.

Anti-vacuity: the new lifecycle test invokes the production writer against a real user-tier SQLite database, then sends its resulting candidate through the production judgment function. Removing candidate coercion, evidence propagation, or deterministic identity makes that test fail.

Adversarial review notes

Iteration 1: no legitimate gaps found across all 5 ACs.

Ref polylogue-rxdo.4

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 4 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4870a0b7-8b6c-499e-aa95-2028a38a60c6

📥 Commits

Reviewing files that changed from the base of the PR and between 2e3eb5b and 1772b9d.

📒 Files selected for processing (2)
  • polylogue/storage/sqlite/archive_tiers/user_write.py
  • tests/unit/storage/test_archive_tiers_assertions.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fanout/rxdo-lifecycle

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Problem: detector claims with query and result-set evidence had no durable
lifecycle-safe representation, so they could not be judged or promoted.

What changed:
- add finding.v1 candidate assertions with deterministic provenance identity
- register findings in claim, candidate-review, audit, and generated schemas
- preserve opaque provenance refs for the rxdo substrate contract

Compatibility/migration: AssertionKind is stored in schema-free TEXT; no
user-tier migration is required.

Ref polylogue-rxdo.4

Co-Authored-By: Claude <[email protected]>
@Sinity
Sinity force-pushed the feature/fanout/rxdo-lifecycle branch from f22e7c6 to 1772b9d Compare July 13, 2026 02:12
@Sinity

Sinity commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

Merge-conductor rebase note

Rebased onto master, which already had a minimal partial rxdo.4 delivery
from PR #2791 (annotation-judgment): a narrower `FindingAssertionInput`/
`upsert_findings_as_assertions` with no kind-vocabulary or statistic-shape
validation. This PR's `FindingAssertion` is the richer, intended
implementation (claim_key identity, `_FINDING_KINDS` allowlist, statistic/
n/query_ref/result_set_ref/baseline/current/expected validation, confidence
field). No production code outside these two files referenced the older
shape yet, so I fully replaced it rather than keeping both: removed
`FindingAssertionInput` and its narrower `assertion_id_for_finding`/
`upsert_findings_as_assertions` bodies, kept this PR's versions, dropped
the now-dead `test_findings_reuse_candidate_judgment_lifecycle_and_deduplicate`
test (superseded by this PR's own `test_upsert_findings_reuses_candidate_lifecycle_and_evidence_refs`

  • `test_upsert_findings_rejects_incomplete_delta_and_unresolved_ref_shapes`),
    and de-duplicated `docs/plans/layering.yaml`'s entrypoints list (both sides
    had independently registered `upsert_findings_as_assertions`).

Verification: focused suite (test_archive_tiers_assertions.py +
test_archive_tiers_user_audit.py) — 33 passed. devtools verify --quick —
15/15 checks green, including verify-layering.

@Sinity
Sinity merged commit 61a2808 into master Jul 13, 2026
3 of 15 checks passed
@Sinity
Sinity deleted the feature/fanout/rxdo-lifecycle branch July 13, 2026 02:13
Sinity added a commit that referenced this pull request Jul 13, 2026
…6,2817,2818

th0 (test-harness-2 #2817) and 212.9.1 (fable-demo-2 #2814) fully
satisfied — closed. ra3w/s7ae.8/20d.2 (basetemp-fix #2815, live-performance
continuation #2816) supplementary progress noted on already-open beads.
rxdo.9 (analysis-rigor #2818, program adoption only), rxdo.4 (rxdo-lifecycle
#2812, fuller FINDING implementation but resolve-proof/provenance
projection still deferred), rxdo.2/rxdo.3 (rxdo-substrate #2813, explicitly
incomplete per its own adversarial review) noted with disposition.

Co-Authored-By: Claude <[email protected]>
Sinity added a commit that referenced this pull request Jul 13, 2026
…ne, frontier labels, design enrichment

From the 2026-07-13 open-set characterization (504 open, 355 ready):
raise mhx.2 P4->P2 (gated all three P2 flagship demos + 7yk5 — largest
inversion in the graph; demand-driven policy slice noted); demote
27m<-b5l blocks to related (blue-green rebuild is operational quality,
not hard correctness ordering — un-blocks the P1 excision lane);
release rxdo.4 stale in_progress claim and narrow remaining scope to
the two deferred items (#2812 delivered the writer); add
horizon:frontier to the 10 ready P0/P1s lacking horizon labels; write
grounded design fields for 9e5.8.4, of39, 9rw0, 09rn. Graph lint
clean (no cycles, no missing AC).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013v95mgEuw3uo9AsnpvhDbm
Sinity added a commit that referenced this pull request Jul 14, 2026
… provenance (rxdo cluster) (#2899)

## Summary

Advances the rxdo epic's core query/evidence-contract substrate: a real
(non-test-double) production `CanonicalPlanEvaluator`, wired as the
default daemon standing-query evaluator; a lossless predicate round-trip
that makes it possible; `finding:<id>` refs resolving to a queryable
provenance projection; and a declarative improvement-loop registry.

## Problem

Prior PRs (#2813, #2826, #2812, #2791) landed substantial rxdo schema
and contract substrate but explicitly flagged the same real gap in their
own closing notes: `CanonicalPlanEvaluator` had exactly one kind of
implementation anywhere in the repo — hand-rolled fakes inside test
files. `make_default_convergence_stages()` called
`make_standing_query_stage(db_path)` with no evaluator at all, so the
standing-query convergence stage was permanently inert in production.
`record_query_run()` (ops.db telemetry writer) had zero production
callers. `resolve_ref("finding:<id>")` returned the generic
substrate-pending stub even though findings have been real queryable
assertion rows since PR #2812. rxdo.11 asked for a declared loop
registry that didn't exist.

## Solution

- **`polylogue/archive/query/predicate.py`**: `predicate_from_payload()`
— a lossless round trip colocated with each predicate dataclass's own
`to_payload()`. Not a reverse-compiler over free-form text; every branch
inverts one dataclass's own projection.
- **`polylogue/archive/query/production_evaluator.py`**:
`ArchiveCanonicalPlanEvaluator`, the first real evaluator
implementation. Reconstructs a typed predicate from a durable
`query:<hash>` definition's canonical AST, binds field context through
the existing planner-internal `_bind_predicate_context` seam, executes
through the same `SessionFilter` every surface uses, and records a
bounded `ops.db` `query_runs` row (`surface="daemon-internal"`) per
evaluation — a genuine production caller of `record_query_run`. Legacy
protocol-v0 identities and non-session grains fail closed with named
errors.
- **`polylogue/daemon/convergence_stages.py`**:
`make_default_convergence_stages` now injects
`ArchiveCanonicalPlanEvaluator` by default — the named remaining item
from rxdo.5's notes.
- **`polylogue/storage/sqlite/finding_provenance.py`** +
**`polylogue/surfaces/payloads.py`** (`FindingProvenancePayload`):
`compute_finding_provenance()` re-derives a finding's declared
`query_ref`/`result_set_ref`/`baseline_ref`/`current_ref` plus generic
`evidence_refs`, resolves each live, and reports a current/stale/unknown
staleness verdict.
- **`polylogue/api/archive.py`**: `resolve_ref("finding:<id>")`
dispatches to the new resolver instead of the pending-kind stub.
- **`polylogue/insights/improvement_loops.py`**: `LOOP_REGISTRY`
declaring all 13 loop instances from the rxdo.11 design as the 5-tuple
(watch/measure/propose/judge/artifact). Every entry is
`status="horizon"` — no scheduler exists yet, and a dedicated test
asserts `active_loops()` stays empty until one does.

## Non-goals / explicitly deferred

- Cross-surface (CLI/MCP/daemon-web/API) query-run recording parity —
only the daemon-internal evaluator surface records today.
- `from result-set:<id>` / `from query:<hash>` DSL execution wired into
the CLI (rxdo.6) — the evaluator this needed now exists, but CLI/MCP
command-surface wiring is a separate, larger change against
`cli/archive_query.py` (2500+ lines) deferred to a follow-up.
- Cohort resolution (`resolve_cohort` raises `NotImplementedError`).
- rxdo.8 (DB-native analysis recipes): needs a new user-tier schema
migration slot, and polylogue-60i5's corrective contract requires a
declared window + two-consumer stabilization before any new durable
table lands. Not attempted here.
- rxdo.11's two active pilots (L1/L2 executing through a shared
scheduler): blocked on polylogue-37t.17 (L1's read-access log) and an L2
classifier-residue detector, neither of which exist. Only the
declaration registry landed.

## Verification

- `devtools test tests/unit/archive/query/test_production_evaluator.py
tests/unit/archive/query/test_predicate_payload_roundtrip.py
tests/unit/daemon/test_standing_queries_default_evaluator.py
tests/unit/insights/test_improvement_loops.py
tests/unit/api/test_facade_contracts.py
tests/unit/daemon/test_standing_queries.py
tests/unit/archive/query/test_evaluator.py
tests/unit/daemon/test_convergence_stages.py
tests/unit/daemon/test_convergence_final_state.py` — 351 passed, 6
pre-existing failures. Those 6
(`test_archive_tiers_api_timeline_insights_read_index_tier`,
`test_facade_judges_candidate_assertion_in_user_tier`,
`test_archive_tiers_api_session_costs_read_index_tier`,
`test_archive_tiers_api_tag_rollups_read_index_and_user_tiers`,
`test_archive_tiers_api_latency_profiles_read_index_tier`,
`test_archive_tiers_api_archive_coverage_reads_index_tier`) were
independently confirmed present with identical count/names on unmodified
master (verified via a temporary `git stash` + rerun of
`tests/unit/api/test_facade_contracts.py` alone).
- `mypy --strict` over all touched source + test files: clean.
- `ruff check` / `ruff format`: clean.
- `devtools render all --check`: clean (topology projection regenerated
for the 3 new modules).
- `devtools verify --quick`: exit 0 (ran automatically on push via the
pre-push hook).

## Anti-vacuity

`test_evaluate_matches_real_archive_rows` depends on the actual
predicate reconstruction + `SessionFilter` execution: removing
`predicate_from_payload()` or the `SessionFilter.list_summaries()` call
breaks it, since the assertion checks the archive actually filtered by
origin against real ingested rows (not a toy replica).
`test_evaluate_records_a_production_query_run` depends on the
`record_query_run` call: removing it breaks the test, since it reads the
row back from a real `ops.db`.
`test_default_stage_set_evaluates_a_watched_query_without_an_injected_fake`
depends on the `make_default_convergence_stages` wiring: it injects no
fake evaluator at all, only the production one reached through the real
factory function.

Ref polylogue-rxdo.2, polylogue-rxdo.3, polylogue-rxdo.4,
polylogue-rxdo.5, polylogue-rxdo.6, polylogue-rxdo.8, polylogue-rxdo.11

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Finding references now display detailed provenance, evidence
resolution status, and staleness information.
- Canonical archive queries can be executed with exact session results
and safeguards against self-triggering evaluations.
- Query predicates can be reconstructed reliably from saved
representations.
  - Added a registry for tracking planned improvement loops.

- **Documentation**
- Updated topology documentation and status totals to reflect newly
registered components.

- **Tests**
- Added coverage for finding provenance, query execution, predicate
restoration, and default standing-query behavior.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude <[email protected]>
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