Repository navigation
Description
Current status
This issue started as an audit dump of timestamp and storage integrity bugs. Some findings are already fixed or moved by later work:
_iso_to_epochUTC handling was fixed in4d60bdee/ PR fix: datetime UTC, MCP filter wiring, export fields, paste role guard #821-era work.parse_timestamp(None)no longer needs to crash at materialization sort-key calculation;materialization_runtime._timestamp_sort_key()now returnsNonewhen parsing fails.conversations.raw_idnow usesON DELETE SET NULLin the archive schema.attachment_refs.message_idnow usesON DELETE SET NULL, and perf(daemon): keep live convergence status bounded (#845) #854 added an FK-support index for replacement performance.- Old
publications.py/runs.pyquery modules referenced by the original audit are no longer present onorigin/masterafter the daemon-first cleanup.
Keep this issue open only for the remaining concrete integrity review and regression coverage.
Remaining scope
Self-referential message FK policy
messages.parent_message_id still references messages(message_id) without an explicit ON DELETE policy. Decide whether the correct behavior is:
ON DELETE SET NULL, preserving children after deleting a parent message;- cascade through conversation/message replacement semantics;
- no FK, with branch/orphan handling enforced at the archive domain layer;
- or the current behavior, if replacement/delete paths prove it is safe.
Silent attachment-ref insert handling
Shared attachment-ref insertion still uses INSERT OR IGNORE. Verify whether this can silently swallow FK violations or other integrity problems that should be surfaced during archive writes. If it is intentionally idempotent, narrow the ignored conflict to the expected uniqueness case or add diagnostics for unexpected skips.
Regression coverage
The issue should close with tests that prove the remaining decisions, not with another audit list.
Likely files:
polylogue/storage/sqlite/schema_ddl_archive.pypolylogue/storage/sqlite/schema_bootstrap.pypolylogue/core/common.pypolylogue/storage/repository/archive/writes/tests/unit/storage/test_schema_upgrades.pytests/unit/storage/test_backend.pytests/unit/storage/test_store_ops.pytests/unit/pipeline/test_ingest_batch.py
Non-goals
- Do not revive old publication/run tables as part of this issue.
- Do not solve broad write-boundary hash honesty; refactor(storage): make conversation writes bundle/hash-honest #841 owns that.
- Do not make schema changes without an exact fresh-schema and upgrade-path decision.
- Do not preserve the original stale audit wording if code evidence shows a finding is already fixed.
Acceptance criteria
- The issue body/PR closure comment classifies each original finding as fixed, obsolete, still-open, or moved.
- The
messages.parent_message_iddelete policy is explicitly decided and tested. - Attachment-ref insertion either surfaces unexpected FK/integrity failures or documents and tests why
INSERT OR IGNOREis safe there. - Any schema change includes fresh-schema DDL, exact upgrade handling, and schema upgrade tests.
- Focused storage/pipeline tests cover the chosen behavior.
Verification
- Focused storage schema and write-path tests for the changed integrity behavior.
devtools verify-migrationsif schema version/upgrade manifests are touched.devtools verify --quick, and fulldevtools verifybefore PR if schema/write paths change.
Activity
fix: datetime UTC, MCP filter wiring, export fields, paste role guard
Sinity commentedon May 4, 2026
Update:
_iso_to_epochUTC fix landed in 4d60bde. Remaining items: parse_timestamp None crash, naive-aware datetime comparison, 3 FK gaps.[-]fix(core): datetime handling — _iso_to_epoch local-time shift, naive-aware comparison crash, None.timestamp crash, 3 FK gaps[/-][+]fix(storage): close remaining timestamp/FK/upsert integrity gaps[/+]Sinity commentedon May 7, 2026
Wave 1 classification (#852)
Each original finding classified against current
origin/master(1bc0d37):_iso_to_epochUTC handling4d60bdeeparse_timestamp(None)crashNoneat sort-key calc pathconversations.raw_idFK policyON DELETE SET NULLin DDL (line 60)attachment_refs.message_idFK policyON DELETE SET NULLin DDL (line 202), FK-support index via #854publications.py/runs.pyorigin/mastermessages.parent_message_idself-referential FKINSERT OR IGNOREon attachment_refsScope for this PR
parent_message_idFK: Keep NO ACTION (the implicit default). This is the correct policy — message deletion is conversation-scoped, and the FK prevents orphaned references within normal operation. Add regression test proving conversation-scoped deletion works with self-referential chains.INSERT OR IGNOREon attachment_refs: Narrow toINSERT ... ON CONFLICT(ref_id) DO NOTHING. This preserves idempotency onref_idprimary key conflicts while surfacing FK violations that should never occur in correct operation (attachments always upserted before refs). If an FK violation does occur, we want the error, not silent discard.Tests: Message self-referential FK integrity, attachment-ref FK surface, idempotency preserved.
Non-goals
Files
polylogue/core/common.py— narrow INSERT OR IGNOREtests/infra/storage_records.py— update duplicate SQLtests/unit/storage/test_backend.py— FK integrity testsfix(storage): narrow attachment-ref insert to ON CONFLICT DO NOTHING (#…
fix: close remaining gaps — FK policy doc, MCP cursor (#819/#820)
fix: final gaps — stale docs, FK surfacing test (#820/#852)
fix: datetime UTC, MCP filter wiring, export fields, paste role guard
fix(storage): narrow attachment-ref insert to ON CONFLICT (#881)
fix(mcp,storage): next_offset cursor and explicit FK policy (#906)
fix(docs,storage): refresh internals.md and add FK violation test (#911)
fix(storage): narrow attachment-ref insert to ON CONFLICT (#881)
fix(mcp,storage): next_offset cursor and explicit FK policy (#906)
fix(docs,storage): refresh internals.md and add FK violation test (#911)