Repository navigation
Closed
Labels
Description
Scope
Composite issue for archive-storage correctness and compactness around schema bootstrap, direct write paths, FTS/search side effects, legacy product payloads, and storage helper duplication.
Problem
Several storage issues share one root: archive writes and schema side effects are split across multiple paths that are not governed by one contract.
Already completed
Sync ingest FTS/cache side effects (#707 / fix(pipeline): commit sync ingest side effects)
_process_ingest_batch_sync()now restores FTS triggers, repairs changed-conversation message/action FTS rows, commits that teardown work, then invalidates the search cache when conversations changed.- Regression test: caches an empty search, sync-ingests a conversation through the direct sqlite batch path, then verifies from a fresh connection that FTS rows persisted and the same search query returns the new conversation.
Schema version mismatch (#709 / fix(storage): block schema version mismatch)
- Schema-version mismatch now blocks with the reset/re-import diagnostic instead of running additive DDL and advancing
PRAGMA user_version. - Sync and async schema setup share that behavior.
open_read_connection()performs a non-mutating compatibility check for mismatched versions and known legacy inline raw layouts.- Removed the unused metadata export/import path that belonged to the misleading in-place recreate story.
Force-write propagation (#711 / #714)
run --reparsepropagatesforce_writethrough run workflow, pipeline execution, parsing services, and sync ingest writes._write_conversation(..., force_write=True)replaces same-hash message rows (corrected in fix(acquisition): harden live freshness and reparse writes #714 — earlier version left old message rows behind).
Remaining acceptance criteria
- Broader write-path unification: repository writes, sync ingest/batch writes, and other direct archive write paths should share a post-write contract for FTS repair, trigger restoration, cache invalidation, and product/readiness side effects.
- FTS trigger/table SQL single source of truth: FTS lifecycle SQL is still split across
schema_ddl_archive.pyandfts_lifecycle.py. Unify. - Hot search readiness: exact row-count FTS readiness should not be on the hot search path. Exact counts belong in doctor/readiness/repair, or behind bounded freshness caching.
- Legacy session-product payload support: delete from hot read/write paths or move into an explicit documented migration/repair path.
- Unsafe asset IDs: accepted through the advertised
asset_path()contract without failing in temp-file creation. - Storage module consolidation:
schema.py+schema_bootstrap.pyare already coupled — consider merging.connection_profile.pycache pragmas should be verified against WAL mode across both sync and async paths. - Write-path ownership clarity: function names/signatures should indicate whether they mutate, commit, invalidate cache, or expect the caller to do so.
Storage subsystem map
polylogue/storage/
├── backends/
│ ├── schema_ddl.py/archive.py # schema definition, SCHEMA_VERSION
│ ├── schema.py # fresh-only init, version guard
│ ├── schema_bootstrap.py # shared bootstrap + extension planning
│ ├── connection.py # read/write connection lifecycle
│ ├── connection_profile.py # canonical PRAGMA/performance profiles
│ ├── async_sqlite.py # async SQLite runtime
│ ├── sync_sqlite.py # sync SQLite (CLI, schema tooling)
├── search_providers/
│ ├── fts5.py # lexical search
│ ├── hybrid.py # RRF fusion
│ ├── vector.py # vector search
├── repository/
│ ├── repository.py # 10-mixin composition facade
│ ├── insight/ # session insight repositories
├── blob_store.py # content-addressed blob storage
├── run_state.py # run state tracking
├── repair.py # health/repair operations
Consolidated findings
This issue absorbs and supersedes:
- refactor(storage): remove or quarantine legacy session-product payload paths #609 legacy session-product payload path removal/quarantine.
- fix(storage): sanitize asset temp filenames during writes #611 asset temp filename sanitization.
- fix(storage): commit and invalidate sync ingest side effects #619 sync ingest FTS/cache side effects.
- refactor(storage): single-source archive FTS schema DDL #626 single-source archive FTS schema DDL.
Related but kept separate:
- fix(acquisition): make live cursors and source freshness content-aware #620 acquisition/live cursor correctness.
- fix(query): unify read filters, raw records, and query descriptors #621 query/read semantics above storage.
Ref #578
Activity
[-]fix(storage): make schema mismatch handling explicit[/-][+]fix(storage): unify schema, FTS, cache, and write side effects[/+]Sinity commentedon May 1, 2026
Additional write-path audit detail from
.agent/scratch/636-write-path-data-integrity-audit.md:The sync-ingest FTS finding is sharper than the current wording. In
_process_ingest_batch_sync(), ingest rows are committed first, thenfinallyrestores triggers and callsrepair_fts_index_sync()before closing the connection. A sqlite smoke check confirms the trigger DDL persists when no transaction is open, but the subsequent FTS repair DML opens an implicit transaction and is rolled back onclose()unless committed. So the concrete bug is: sync ingest can persist conversation/message rows while losing the targeted FTS repair rows.The same audit also confirmed the cache side-effect split:
invalidate_search_cache().Suggested acceptance additions:
messages_ftsandaction_events_ftsrows.Sinity commentedon May 1, 2026
Storage-side-effect guard: the close path should define who owns commit, FTS repair, and cache invalidation for every write family.
Suggested acceptance split:
The key bug class is not only duplicated SQL; it is rows being durable while their derived search/cache side effects are not.
Sinity commentedon May 1, 2026
Implementation anchors and acceptance additions from the 2026-05-01 follow-up audit.
Code anchors to preserve:
polylogue/pipeline/services/ingest_batch.py:843-869:_process_ingest_batch_sync()suspends FTS triggers, startsBEGIN IMMEDIATE, writes/commits ingest rows, then infinallyrestores triggers and callsrepair_fts_index_sync()before closing the connection.polylogue/storage/fts/fts_lifecycle.py:159-168: trigger restore executes DDL but does not own commit.polylogue/storage/fts/fts_lifecycle.py:217-228:repair_fts_index_sync()performs delete/insert FTS DML but does not own commit.polylogue/storage/search/cache.py:74-87: cache invalidation primitive exists, butingest_batch.pydoes not call it.Acceptance additions:
messages_ftsandaction_events_ftscontain rows for changed conversations.Also fold the closed #619 performance edge into this issue: hot search should not do exact row-count FTS readiness by default. Exact counts belong in doctor/readiness/repair, or behind bounded freshness caching. #619 already contains the evidence that search calls exact readiness on the hot path and that derived status already has a
verify_fullknob.Sinity commentedon May 1, 2026
Storage decision from 2026-05-01 bundle
Integrated decisions:
Acceptance refinements:
Ref #635
Sinity commentedon May 2, 2026
Storage subsystem map (2026-05-02)
These are the key storage modules and their current sizes — useful for planning the unification work:
The unification targets from the issue title (schema, FTS, cache, write side effects) suggest consolidating:
schema.py+schema_bootstrap.py— they're already coupled (branching logic shared)fts5.pytriggers currently live inschema_ddl_archive.py— FTS lifecycle split across two filesconnection_profile.pycache pragmas interact correctly with WAL mode across both sync and async pathsrepository.pymixin composition is powerful but hard to trace write ordering — document the commit sequencefix(pipeline): commit sync ingest side effects (#707)
Sinity commentedon May 2, 2026
Landed first #618 implementation slice in #707.
Scope completed:
_process_ingest_batch_sync()now restores FTS triggers, repairs changed-conversation message/action FTS rows, commits that teardown work, then invalidates the search cache when conversations changed.Verification recorded on the PR:
ruff check polylogue/pipeline/services/ingest_batch.py tests/unit/pipeline/test_ingest_batch.pyruff format --check polylogue/pipeline/services/ingest_batch.py tests/unit/pipeline/test_ingest_batch.pypytest -q tests/unit/pipeline/test_ingest_batch.pydevtools verify --quickStill open in this composite issue:
fix(storage): block schema version mismatch (#709)
Sinity commentedon May 2, 2026
Landed second #618 storage slice in #709.
Scope completed:
PRAGMA user_version;open_read_connection()now performs a non-mutating compatibility check for mismatched versions and known legacy inline raw layouts;Also incorporated unrelated timestamp fixes that were present in the worktree from another agent:
parse_timestamp()for ISO timestamps;create_timevalues now participate in message ordering.Verification recorded on #709:
pytest -q tests/unit/storage/test_backend.py tests/unit/pipeline/test_materialization_runtime.py;pytest -q tests/unit/sources/test_parsers_chatgpt.py tests/unit/pipeline/test_materialization_runtime.py;devtools verify-manifests;devtools render-all --check;devtools verify --quick.Still open in #618:
Sinity commentedon May 2, 2026
#711 also landed a small write-path correction that was present as in-progress work from another agent:
run --reparsenow propagatesforce_writethrough run workflow, pipeline execution, parsing services, and sync ingest writes. This means same-content-hash conversation rows are still replaced after parse status is explicitly reset, instead of being skipped by_check_content_unchanged().Regression added:
_write_conversation(..., force_write=True)replaces same-hash message rows. This narrows the remaining #618 write-side drift to broader repository/sync-ingest unification and hot search readiness work.Sinity commentedon May 2, 2026
PR #714 incorporates the pending forced-reparse ingestion fix from the other-agent workstream, with an important correction.
The uncommitted hunk had the right goal —
force_write=Truemust replace same-hash rows instead of skipping by content hash — but it left old message rows behind during forced same-hash reparses. I corrected_write_conversation()so force-write remains a true replacement path and verified it withtests/unit/pipeline/test_ingest_batch.py::test_write_conversation_force_write_replaces_same_hash_rowsas part of the fulltests/unit/pipeline/test_ingest_batch.pyrun.I also fixed the sort-key SQL predicate placement while keeping the ingest file under its file-size budget.
1 remaining item
Sinity commentedon May 2, 2026
Implementation plan: storage write-path unification (from agent analysis 2026-05-03)
Purely mechanical?
Mostly. FTS DDL dedup and asset temp filename fix are mechanical. Legacy payload removal is dead code deletion. Hot search readiness is a parameter change on two call sites.
Files touched
polylogue/storage/fts/sql.py— remove duplicated DDL, import from canonical schema_ddl modulespolylogue/storage/fts/fts_lifecycle.py— remove duplicated trigger DDLpolylogue/storage/insights/session/storage.py— delete legacy_with_legacy_payload_column,has_legacy_payload,payload_jsonbranchespolylogue/storage/search/runtime.pyline 57 —verify_total_rows=Falsepolylogue/assets.pyline 49 — use sanitized temp filename prefixpolylogue/storage/post_write.py(new) — canonicalcommit_write_side_effects()Order of operations
Estimated effort
Medium — ~2.5 days. FTS DDL dedup 0.5 day, legacy payload 0.5 day, hot search 0.25 day, asset fix 0.1 day, write-path unification 1 day.
Sinity commentedon May 3, 2026
AC audit (2026-05-03)
Hot search readiness is already done:
polylogue/readiness/__init__.py:329-330usesexact_index_counts = deep or not probe_only. Whenprobe_only=True,verify_total_rows=Falseflows to FTS lifecycle, avoiding the expensive row-count check. This AC can be marked resolved.Remaining: FTS SQL single-source + legacy session-product payload removal + write-path unification.
Sinity commentedon May 3, 2026
Implementation slice published in PR #742: #742
Scope realized:
messages.message_typecolumn andidx_messages_conversation_message_typeindex;Verification recorded in the PR:
60 passed in 8.31s;git diff --check;devtools verify --quickand pre-push hook both passed.Live motivation: the workstation archive had a physically v3-shaped
messages.message_typeschema whilePRAGMA user_versionwas 2, caused by an older binary writing the version marker. The current runtime then rejected it and scheduled runs could drift into expensive catch-up/reimport behavior instead of applying the small additive delta.fix(storage): upgrade schema v2 archives in place (#742)
fix(storage): skip redundant v2 message backfill (#743)
feat(storage): add ArchiveWriteGateway, tags M2M, insights.db, blob GC (
feat(storage): ArchiveWriteGateway, tags M2M, insights.db, blob GC (#618
Sinity commentedon May 3, 2026
Closed by #756. ArchiveWriteGateway is the canonical write path.
commit_archive_write_effectsconsolidated inpolylogue/archive/write_effects.py.fix(pipeline): commit sync ingest side effects (#707)
fix(storage): block schema version mismatch (#709)
fix(acquisition): harden live freshness and reparse writes (#714)
fix(storage): upgrade schema v2 archives in place (#742)
fix(storage): skip redundant v2 message backfill (#743)
feat(storage): ArchiveWriteGateway, tags M2M, insights.db, blob GC (#618