Skip to content

fix(storage): narrow attachment-ref insert to ON CONFLICT DO NOTHING (#820) - #881

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/storage-integrity-820
May 7, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/storage-integrity-820

Conversation

@Sinity

@Sinity Sinity commented May 7, 2026

Copy link
Copy Markdown
Owner

Summary

Narrows attachment-ref insertion from INSERT OR IGNORE to INSERT ... 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 IGNORE silently 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_id FK was reviewed and kept as NO ACTION (implicit SQLite default) — message deletion is conversation-scoped and the FK correctly prevents orphaned references.

Solution

Verification

  • devtools verify --quick — all 14 gates passed
  • 2 files, +4/-2
  • Parent message FK: NO ACTION policy confirmed correct for conversation-scoped deletion

Refs #820 #852

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]>
Copilot AI review requested due to automatic review settings May 7, 2026 06:15
@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 18 minutes and 1 second before requesting another review.

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 @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 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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6b636825-e656-4315-aaef-7464a2f53c9c

📥 Commits

Reviewing files that changed from the base of the PR and between bb8eb51 and fd6b27a.

📒 Files selected for processing (2)
  • polylogue/core/common.py
  • tests/infra/storage_records.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/storage-integrity-820

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.

@Sinity
Sinity merged commit 42952da into master May 7, 2026
3 of 4 checks passed
@Sinity
Sinity deleted the feature/fix/storage-integrity-820 branch May 7, 2026 06:15

Copilot AI 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.

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 IGNORE with INSERT ... ON CONFLICT(ref_id) DO NOTHING for attachment_refs inserts 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.

Sinity added a commit that referenced this pull request May 7, 2026
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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.
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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
Sinity added a commit that referenced this pull request May 7, 2026
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.
Sinity added a commit that referenced this pull request May 7, 2026
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
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.

2 participants