Skip to content

feat(storage): mirror transform candidates as assertions (#1883) - #1973

Merged
Sinity merged 3 commits into
masterfrom
feature/feat/transform-candidate-assertions-1883
Jun 16, 2026
Merged

Sinity merged 3 commits into
masterfrom
feature/feat/transform-candidate-assertions-1883

Conversation

@Sinity

@Sinity Sinity commented Jun 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

Mirrors recovery digest decision/run-state candidates into the #1883 assertion substrate as private, evidence-linked transform_candidate rows. This connects #1880 transform outputs to the user-tier assertion lifecycle without auto-promoting them into memory or context.

Problem

#1880 already extracts deterministic decision and run-state candidates from raw coding-agent sessions, but those candidates only lived inside the recovery digest. #1883 already reserved AssertionKind.TRANSFORM_CANDIDATE, but lacked the policy/write path that turns digest candidates into durable assertion rows with evidence refs, transform author identity, status, and context-injection policy.

Solution

Added assertion_id_for_transform_candidate(...) and upsert_transform_candidate_assertions(...) in the user-tier write helpers. The adapter writes each recovery digest candidate with:

  • kind=transform_candidate
  • status=candidate
  • visibility=private
  • author_kind=transform
  • author_ref=transform:<id>@v<version>
  • raw evidence refs derived from TransformRawRef.to_evidence_ref().format()
  • context_policy={"inject": false, "promotion_required": true}

The transform compiler stays storage-free; storage consumes the typed digest DTO at the assertion boundary.

Verification

  • uv run devtools test tests/unit/storage/test_archive_tiers_assertions.py -k 'transform_candidate or assertion_round_trip or list_assertions' -> 3 passed, 5 deselected
  • uv run devtools test tests/unit/storage/test_archive_tiers_assertions.py tests/unit/insights/test_transforms.py -> 20 passed
  • uv run devtools verify --quick -> exit_code: 0
  • pre-push devtools verify --quick -> exit_code: 0

#1880 PR handoff checklist

Issue slice: #1883-backed transform-candidate promotion policy for #1880 recovery digest candidates.

Files inspected: polylogue/insights/transforms.py, polylogue/storage/sqlite/archive_tiers/user_write.py, tests/unit/insights/test_transforms.py, tests/unit/storage/test_archive_tiers_assertions.py, docs/plans/layering.yaml, issue threads #1880 and #1883.

Files changed: polylogue/storage/sqlite/archive_tiers/user_write.py, tests/unit/storage/test_archive_tiers_assertions.py.

Old surface removed or retained: retained. Recovery digests remain storage-free and no legacy assertion/overlay surface is removed.

Contracts/tests added: transform candidates are written as deterministic assertion rows with candidate status, private visibility, transform author refs, evidence refs, value metadata, and explicit non-injection context policy; re-upsert preserves identity and created_at_ms while updating updated_at_ms.

Generated artifacts updated: none; no topology or generated doc drift.

Verification commands and results: see Verification section above.

Known caveats / SPEC_MISMATCH: none. This does not accept/promote candidates; it only records them as assertion candidates.

Follow-up intentionally not included: acceptance/promotion UI/API, persisted recovery-output tables, and broader #1886 primitive reconciliation.

Refs #1880
Refs #1883

Summary by CodeRabbit

  • Tests
    • Added test coverage for transform candidate persistence and recovery capabilities, validating correct assertion storage, deterministic identification, and idempotent behavior across multiple operations.

Problem: #1880 recovery digests extract decision/run-state candidates, but #1883 had no policy path to persist those candidates in the assertion substrate. Leaving them only in the digest meant future memory/promotion work had no evidence-bearing row shape to consume.

What changed: add deterministic transform-candidate assertion ids and a bulk user-tier adapter that writes recovery digest candidates as private candidate-status AssertionKind.TRANSFORM_CANDIDATE rows. The adapter preserves transform id/version, source origin, body text, evidence refs, transform author identity, and an explicit non-injection context policy.

Verification: uv run devtools test tests/unit/storage/test_archive_tiers_assertions.py tests/unit/insights/test_transforms.py -> 20 passed. uv run devtools verify --quick -> exit_code 0.
@coderabbitai

coderabbitai Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

More reviews will be available in 52 minutes and 37 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

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.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6ae0e35f-5afd-4ea7-8fbf-4577d7732c01

📥 Commits

Reviewing files that changed from the base of the PR and between 4d22355 and 607221e.

📒 Files selected for processing (2)
  • polylogue/storage/sqlite/archive_tiers/user_write.py
  • tests/unit/storage/test_archive_tiers_assertions.py
📝 Walkthrough

Walkthrough

Adds two new exported functions to user_write.py: assertion_id_for_transform_candidate, which computes a deterministic ID from session/transform/candidate fields, and upsert_transform_candidate_assertions, which iterates a RecoveryDigest's decision_candidates and upserts each as a private, non-injected TRANSFORM_CANDIDATE assertion. A companion integration test validates field correctness and idempotent re-upsert behavior.

Changes

TRANSFORM_CANDIDATE assertion upsert and tests

Layer / File(s) Summary
ID generator, upsert function, and exports
polylogue/storage/sqlite/archive_tiers/user_write.py
Adds TYPE_CHECKING imports for transform-candidate types; implements assertion_id_for_transform_candidate (deterministic hash over session/transform/candidate fields); implements upsert_transform_candidate_assertions (iterates RecoveryDigest.decision_candidates, derives scope_ref/target_ref, constructs key/value/body_text/context_policy, upserts each as ACTIVE/PRIVATE non-injected assertion, converts raw refs to evidence strings); exports both via __all__.
Integration test: field correctness and idempotency
tests/unit/storage/test_archive_tiers_assertions.py
Adds _recovery_candidate_session() fixture building a Session with Origin.CODEX_SESSION and two messages; adds test_recovery_digest_candidates_write_transform_candidate_assertions asserting assertion count, deterministic ID mapping against assertion_id_for_transform_candidate, all stored fields (kind, refs, key/value, body text, author, evidence refs, status, visibility, context policy), and idempotent re-upsert (created-at stable, updated-at advances to new now_ms).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 A candidate hops into the archive with care,
Its ID is deterministic — no fluff in the air,
Scope refs and target refs all neatly derived,
Upsert it twice and the created-at survived,
The tests hop in green, every field verified there! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the primary change: mirroring transform candidates as assertions, with specific reference to the related issue #1883.
Description check ✅ Passed The description follows the template structure with all major sections completed: Summary, Problem, Solution, Verification, and Risks sections are present and substantive.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/transform-candidate-assertions-1883

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 and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4d22355569

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Problem: review caught that re-mirroring the same recovery digest could overwrite a transform candidate that had already moved out of candidate status, resetting accepted/deleted lifecycle state back to candidate.

What changed: transform-candidate mirroring now returns an existing assertion unchanged when its status is no longer candidate, preserving user/promotion lifecycle state while keeping candidate rows refreshable before promotion.

Verification: uv run devtools test tests/unit/storage/test_archive_tiers_assertions.py tests/unit/insights/test_transforms.py -> 20 passed. uv run devtools verify --quick -> exit_code 0.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@polylogue/storage/sqlite/archive_tiers/user_write.py`:
- Around line 155-174: The assertion_id_for_transform_candidate function does
not include the candidate occurrence index in its identifier generation, causing
multiple candidates with identical kind, text, and evidence references to
overwrite each other during upsert operations. Add a candidate occurrence or
index parameter to the assertion_id_for_transform_candidate function signature
and include this parameter in the _deterministic_id call to ensure each
candidate occurrence produces a unique assertion ID. Update all call sites that
invoke assertion_id_for_transform_candidate to pass the appropriate candidate
occurrence index.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 613864a2-0f00-468e-b269-c4151fbb1acf

📥 Commits

Reviewing files that changed from the base of the PR and between 3f942ad and 4d22355.

📒 Files selected for processing (2)
  • polylogue/storage/sqlite/archive_tiers/user_write.py
  • tests/unit/storage/test_archive_tiers_assertions.py

Problem: CodeRabbit caught that transform candidate identity included the candidate key index but not the assertion id index, so two identical candidate occurrences could collapse into one row.

What changed: include candidate_index in transform-candidate assertion ids and metadata, pass the mirror loop index, and test duplicated candidate occurrences alongside lifecycle preservation.

Verification: uv run devtools test tests/unit/storage/test_archive_tiers_assertions.py tests/unit/insights/test_transforms.py -> 20 passed. uv run devtools verify --quick -> exit_code 0.
@Sinity
Sinity merged commit 6800efc into master Jun 16, 2026
13 checks passed
@Sinity
Sinity deleted the feature/feat/transform-candidate-assertions-1883 branch June 16, 2026 02:20
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