Repository navigation
Description
Problem
Polylogue has accumulated semantic fields across archive tables, provider_meta, raw blobs, provider events, action events, content blocks, and insight projections. Some are clearly provider-specific details that can remain in provider metadata. Others are universal-ish archive semantics and should be modeled as first-class rows/columns instead of living in provider-shaped blobs or ad hoc projection fallbacks.
This distinction matters because provider protocol events are now first-class rows after #837/#843, but similar questions remain around context, metadata, mapper drift, and stale compatibility columns.
Scope
Produce a schema/API inventory. Do not turn this issue into a broad migration bucket.
Classify current fields and metadata into:
- first-class universal semantics already modeled correctly;
- universal-ish semantics currently trapped in
provider_metaor JSON payloads; - provider-specific details that should remain provider metadata for now;
- accidental provider-specific columns/fields in universal tables;
- raw-provider details that should only live in raw blob storage;
- mapper/row-building repetition where a small local table descriptor/codegen layer could reduce drift without adopting a full ORM.
Known adjacent implementation issues
These are already split out and should not be reimplemented here:
- refactor(storage): make conversation writes bundle/hash-honest #841: make conversation writes bundle/hash-honest.
- fix(chatgpt): align parsed message metadata with persisted archive contract #842: align ChatGPT message metadata with the persisted archive contract.
- fix(archive): store context and protocol artifacts semantically, not via projection fallbacks #839: store context and protocol artifacts semantically, not via projection fallbacks.
- fix(storage): make provider protocol events first-class archive rows #837/fix(storage): persist provider protocol events (#843) #843: provider protocol events became first-class rows.
Initial areas to inspect
- Conversation-level
provider_metakeys such as working directories, git/session context, model usage, cost/duration, ChatGPT gizmo/model fields, and browser-capture fields. - Message/content/action-event split: which semantics are stored in
messages,content_blocks,action_events, or still hidden in text/metadata. - Provider-event provenance: whether
source_message_id/raw_idare universal enough to require parser/materialization support, or whether unused columns should be removed until populated. - Session insight rebuild projections such as
cwd,gitBranch,git, andworking_directories. - Legacy insight payload columns such as
payload_jsonversus newer evidence/inference/enrichment payloads. - Search/index surfaces: ensure normal search indexes canonical modeled prose/semantics after protocol artifacts are parsed out, not provider wire artifacts.
- Existing table columns that may be provider-specific despite looking canonical.
- Storage/domain row mappers and SQL tuple builders where repeated column lists create schema drift risk.
Non-goals
- Do not adopt a full ORM by default.
- Do not implement broad schema promotion in the inventory PR.
- Do not preserve search/render fallbacks that hide missing first-class population; classify them as resilience, compatibility, or debt.
- Do not duplicate raw-provider preservation in canonical archive tables.
Acceptance criteria
- Produce a schema inventory with per-field classification and rationale.
- Identify concrete follow-up issues for fields that should be promoted, renamed, demoted, removed, or left provider-specific.
- Explicitly decide whether a small local table-descriptor / row-mapping / SQL tuple descriptor is worth pursuing.
- Preserve the raw-provider boundary: raw exports/blobs remain lossless; canonical archive tables model Polylogue semantics.
- Link each follow-up to the owning architectural layer: parser/source, materialization, storage schema, search/read model, insight projection, or surface contract.
Activity
Sinity commentedon May 5, 2026
Additional design note from implementation work on #837:
The current storage/domain boundary has a lot of hand-written mapper boilerplate, for example
sqlite.Row -> *Record -> domain modelplus parallel SQL tuple builders for ingest. That explicitness is useful for performance and control, especially given SQLite/FTS/generated columns, sync+async paths, bulk ingest, and migration behavior. A full ORM is probably the wrong default abstraction for this archive.However, the repetition is still a schema-design smell. During this inventory, also evaluate whether Polylogue should introduce a small local table-descriptor / row-mapping / codegen layer that keeps explicit SQL and storage/domain separation, but reduces repeated column lists and mapper drift. This should be assessed as part of the schema inventory rather than folded into unrelated migrations.
Sinity commentedon May 5, 2026
Additional schema/API inventory notes from the #837 provider-events implementation scan.
These are not all current-PR blockers; they should guide the inventory so the same workaround pattern does not reappear under different names.
Findings to include in the inventory
save_conversation()accepts a conversation record/domain object plus independent row lists, then trustscontent_hashto decide whether to replace runtime rows. The immediate provider-events gap is fixed in #837, but the API shape still lets hash and row graph diverge.The parser extracts rich message-level provider metadata, while hydrated archive messages do not expose it, and capability/runtime code still implies it exists. The inventory should classify which pieces are universal archive semantics, which are provider-specific but intentionally persisted, and which should only live in raw blobs.
provider_eventsrows includesource_message_idandraw_id; batch ingest can attachraw_id, but the parser contract currently exposes only event type/timestamp/payload. The inventory should decide whether provider-event provenance is universal enough to be required at parser/materialization boundaries, or whether any unused columns should be removed until populated.The rebuild path avoids loading full provider metadata and projects only selected keys such as
cwd,gitBranch, andgit. Attribution code also knows aboutworking_directories. If these are universal session/context semantics, they should become typed projection fields or a first-class context table rather than ad hoc JSON slices.The session insight storage layer still writes legacy
payload_jsoncolumns where present alongside newer evidence/inference/enrichment payloads. That may be intentional compatibility scaffolding, but the inventory should decide whether to migrate once and remove it, or document the compatibility horizon explicitly.The earlier mapper-boilerplate note still stands: full ORM adoption is probably wrong, but a local typed table descriptor / row mapper / SQL tuple descriptor could reduce repeated column lists and drift while keeping explicit SQL.
Non-findings / acceptable validation
Refs #837 #839 #841 #842
fix(storage): persist provider protocol events (#843)
Sinity commentedon May 6, 2026
Backlog hygiene note: inventory scope and concrete adjacent issues
This should be treated as a schema/API inventory issue, not an implementation bucket.
Concrete adjacent implementation issues now split out the known findings:
Remaining useful work here is to produce a schema inventory that classifies current fields/metadata into:
Do not implement broad schema promotion in this issue directly; spawn focused issues/PRs from the inventory.
Sinity commentedon May 6, 2026
Execution supplement
Mass-execution wave: #852 Wave 0 / Wave 3 root.
Focused verification:
rg/schema inspection againstpolylogue/storage/sqlite/schema_ddl*.py, parser/provider metadata, hydrators, materialization, search/read models, and insight projections.devtools render-all --checkonly if committed docs/generated surfaces change.devtools verifyfor a pure GitHub inventory comment; run it if the PR changes code or committed docs.Close only after every identified implementation gap is linked to a focused issue or explicitly classified as intentional provider/raw metadata.
Sinity commentedon May 6, 2026
Schema audit supplement: target classification and child issue
Code audit on 2026-05-07 found one missing execution issue: #864 now owns implementation work to graduate universal/query-relevant semantics out of
provider_meta. This issue should remain inventory/decision-oriented and close only after every promoted/demoted/remain-raw item is linked to a focused issue or explicitly classified.Current classification
First-class archive semantics already modeled reasonably well:
raw_conversationsandartifact_observationsalready carry provider/source/path/artifact/support fields without depending on provider metadata;messages.provider_message_id,role, parent/branch,message_type, stats flags, andcontent_blocksare canonical storage;action_eventshas typed rows for action kind, tool name/id, affected paths, cwd, branch names, command/query/url/output/search text;provider_eventsis now the right home for compactions and similar provider-level events;tags,conversation_tags, andconversation_user_metadatakeep user-owned state separate from content hashes.Universal-ish semantics currently trapped in
provider_metaor JSON payloads:source_name: currently generated fromjson_extract(provider_meta, '$.source')inconversations; promote to a real stored source identity or table (refactor(schema): graduate universal semantics out of provider_meta #864).attachments.provider_meta/attachment_refs.provider_metaforid,provider_id,fileId,driveId; promote to columns/table or classify as temporary compatibility (refactor(schema): graduate universal semantics out of provider_meta #864).cwd,working_directories,gitBranch, andgit.repository_urlare used by attribution, repo filters, context packs, and insights; source from typed context/action/session projection, not ad hoc provider-meta reads (refactor(schema): graduate universal semantics out of provider_meta #864, with artifact parsing in fix(archive): store context and protocol artifacts semantically, not via projection fallbacks #839).provider_metaby pricing and harmonization paths; typed cost/usage model belongs in feat(insights): subscription-aware cost tracking with client-side tokenizer and per-model breakdown #803, with refactor(schema): graduate universal semantics out of provider_meta #864 preventing new provider-meta dependencies.provider_meta; fix(chatgpt): align parsed message metadata with persisted archive contract #842 owns deciding persisted contract vs parser-only/raw-only.Provider-specific data that can remain provider metadata for now:
provider_metais retained provider-specific residue, not the canonical path for universal archive semantics.Raw-only details:
Suspect abstractions / follow-up decision:
schemas/unified/provider_meta_*is currently useful as parser/compatibility glue, but it should not become the durable semantic API after materialization. refactor(schema): graduate universal semantics out of provider_meta #864 should leave it as fallback/import compatibility or shrink it once canonical fields exist.Concrete child ownership
Message.provider_meta.rawclaims.Closeout test for this inventory issue
Before closing #840, leave a final matrix with every
provider_metasemantic bucket above marked as:Focused verification for the inventory itself remains code/schema inspection plus issue updates. Implementation PRs should run the focused tests named on their owning issues.
Refs #864 #842 #839 #803 #800 #841 #852.
Sinity commentedon May 7, 2026
Intended scope
Produce a schema inventory document (
docs/plans/schema-inventory.md) that classifies current schema fields,provider_metakeys, insight projections, and storage mappers across these axes:provider_meta, JSON payloads, or ad hoc projection slicesNon-goals
Files expected to change
docs/plans/schema-inventory.mddocs/plans/manifest if one exists, ordocs/README.mdif links need updatingFocused checks
devtools verify --quick+devtools render-all --check(docs-only change)Issue closure
After merge, #840 stays open until every classified gap is linked to a focused issue. The final closeout matrix (from the 2026-05-06 comment) will be posted before closing.
Key files to read
polylogue/storage/sqlite/schema_ddl.py,schema_ddl_archive.pypolylogue/storage/insights/session/polylogue/sources/parsers/polylogue/pipeline/prepare_enrichment.pypolylogue/core/types.py/polylogue/types.pypolylogue/storage/repository/(mappers, tuple builders)docs: add schema inventory classifying universal vs provider metadata (…
fix(storage): persist provider protocol events (#843)
docs(schema): inventory universal vs provider metadata (#874)
refactor(schema): promote provider_meta fields to columns (#884)
docs(schema): inventory universal vs provider metadata (#874)
refactor(schema): promote provider_meta fields to columns (#884)
Sinity commentedon May 9, 2026
Reopening to confirm: the closeout matrix marking each provider_meta bucket was the AC. Verify each bucket has either landed or has a tracked successor with explicit user sign-off.
Sinity commentedon May 9, 2026
Verified complete. PR #874 created docs/plans/schema-inventory.md (present on master). Closeout matrix marking each provider_meta bucket was provided in the closing PR. Closing.