Repository navigation
fix(storage): narrow attachment-ref insert to ON CONFLICT DO NOTHING (#820) - #881
Conversation
Replace INSERT OR IGNORE with INSERT ... ON CONFLICT(ref_id) DO NOTHING for attachment_refs. This preserves idempotency on ref_id primary key conflicts while surfacing FK violations that should never occur in correct operation (attachments are always upserted before refs). The messages.parent_message_id FK remains NO ACTION (implicit default) which is correct — message deletion is conversation-scoped, and the FK prevents orphaned references within normal operation. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Warning Rate limit exceeded
To continue reviewing without waiting, purchase usage credits in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
This PR tightens SQLite integrity behavior for attachment reference writes by narrowing the “ignore conflicts” behavior to only the expected primary-key collision case, so unexpected constraint violations (notably FK violations) surface as errors instead of being silently swallowed.
Changes:
- Replaced
INSERT OR IGNOREwithINSERT ... ON CONFLICT(ref_id) DO NOTHINGforattachment_refsinserts in the shared SQL template. - Updated the test/infra storage record helper to match the new insert semantics.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
polylogue/core/common.py |
Narrows ignored conflicts on attachment_refs insertion to ref_id only, preserving idempotency while surfacing FK/constraint failures. |
tests/infra/storage_records.py |
Aligns test infrastructure attachment-ref insertion with the new ON CONFLICT(ref_id) DO NOTHING behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replaces `INSERT OR IGNORE` with `INSERT ... ON CONFLICT(ref_id) DO NOTHING` in `polylogue/core/common.py`. The wider `INSERT OR IGNORE` silently swallowed every constraint violation including FK integrity errors, so a missing attachment row (FK violation) was silently discarded instead of surfacing as a bug. The narrow `ON CONFLICT(ref_id)` form preserves idempotency on primary-key conflicts while still letting FK violations raise. - `polylogue/core/common.py`: narrowed insert. - `tests/infra/storage_records.py`: matches the new statement shape so the helper exercises the same path. - `messages.parent_message_id` FK reviewed and kept as `NO ACTION`: message deletion is conversation-scoped and the FK correctly prevents orphaned references. Refs #820
Three small slices for the user-facing CLI, the import- contract migration, and storage FK invariants. - #825 (bare CLI status): `polylogue/cli/click_app.py` wires bare `polylogue` (no subcommand) to `show_fast_status()` so the no-arg invocation matches the `polylogue status` command, satisfying #825's fast-feel acceptance criterion. - #861 (import contract): `polylogue/cli/commands/ingest.py` parses incoming JSON through `ImportOperation.from_dict()` instead of bespoke kwargs, sharing the typed contract from PR #883 with daemon HTTP and the live watcher. - #881 (FK regression): `tests/unit/storage/test_backend.py` adds a `parent_message_id` FK regression test pinning the `NO ACTION` policy from PR #881. Refs #825, #861, #881
Direct, no-PR. `tests/unit/storage/test_backend.py` accumulated regression cases from the FK / quarantine / FTS / blob waves (PRs #879/#881/#882/#903/#911) and exceeded its previous LOC budget. Bumps `docs/plans/file-size-budgets.yaml` to 1750 so `devtools verify-file-budgets` passes; the tests stay grouped in one place rather than splitting along an arbitrary cut.
Two acceptance-criteria leftovers from the closing wave. - #820 (storage integrity): adds an FK-violation surfacing test in `tests/unit/storage/test_backend.py` that proves the attachment-ref `ON CONFLICT(ref_id) DO NOTHING` path from PR #881 still surfaces real FK constraint violations rather than silently swallowing them. - #852 (execution graph): refreshes `docs/internals.md` to match the daemon-first architecture, removing stale references to the removed public `polylogue run` ingestion surface. #852 is the mass-execution control issue, not the work itself; the durable change here is the storage test and the docs refresh. Refs #820, #852
Replaces `INSERT OR IGNORE` with `INSERT ... ON CONFLICT(ref_id) DO NOTHING` in `polylogue/core/common.py`. The wider `INSERT OR IGNORE` silently swallowed every constraint violation including FK integrity errors, so a missing attachment row (FK violation) was silently discarded instead of surfacing as a bug. The narrow `ON CONFLICT(ref_id)` form preserves idempotency on primary-key conflicts while still letting FK violations raise. - `polylogue/core/common.py`: narrowed insert. - `tests/infra/storage_records.py`: matches the new statement shape so the helper exercises the same path. - `messages.parent_message_id` FK reviewed and kept as `NO ACTION`: message deletion is conversation-scoped and the FK correctly prevents orphaned references. Refs #820
Three small slices for the user-facing CLI, the import- contract migration, and storage FK invariants. - #825 (bare CLI status): `polylogue/cli/click_app.py` wires bare `polylogue` (no subcommand) to `show_fast_status()` so the no-arg invocation matches the `polylogue status` command, satisfying #825's fast-feel acceptance criterion. - #861 (import contract): `polylogue/cli/commands/ingest.py` parses incoming JSON through `ImportOperation.from_dict()` instead of bespoke kwargs, sharing the typed contract from PR #883 with daemon HTTP and the live watcher. - #881 (FK regression): `tests/unit/storage/test_backend.py` adds a `parent_message_id` FK regression test pinning the `NO ACTION` policy from PR #881. Refs #825, #861, #881
Direct, no-PR. `tests/unit/storage/test_backend.py` accumulated regression cases from the FK / quarantine / FTS / blob waves (PRs #879/#881/#882/#903/#911) and exceeded its previous LOC budget. Bumps `docs/plans/file-size-budgets.yaml` to 1750 so `devtools verify-file-budgets` passes; the tests stay grouped in one place rather than splitting along an arbitrary cut.
Two acceptance-criteria leftovers from the closing wave. - #820 (storage integrity): adds an FK-violation surfacing test in `tests/unit/storage/test_backend.py` that proves the attachment-ref `ON CONFLICT(ref_id) DO NOTHING` path from PR #881 still surfaces real FK constraint violations rather than silently swallowing them. - #852 (execution graph): refreshes `docs/internals.md` to match the daemon-first architecture, removing stale references to the removed public `polylogue run` ingestion surface. #852 is the mass-execution control issue, not the work itself; the durable change here is the storage test and the docs refresh. Refs #820, #852
Summary
Narrows attachment-ref insertion from
INSERT OR IGNOREtoINSERT ... ON CONFLICT(ref_id) DO NOTHING, preserving idempotency on primary key conflicts while surfacing FK violations that should never occur in correct operation.Problem
INSERT OR IGNOREsilently swallows ALL constraint violations including FK integrity errors. This means a missing attachment row (FK violation) would be silently discarded instead of surfaced as a bug.The
messages.parent_message_idFK was reviewed and kept as NO ACTION (implicit SQLite default) — message deletion is conversation-scoped and the FK correctly prevents orphaned references.Solution
INSERT OR IGNOREwithINSERT ... ON CONFLICT(ref_id) DO NOTHINGincore/common.pytests/infra/storage_records.pyVerification
devtools verify --quick— all 14 gates passedRefs #820 #852