Skip to content

chore(schema): inventory universal archive semantics vs provider metadata #840

Closed

Description

@Sinity

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_meta or 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:

Initial areas to inspect

  • Conversation-level provider_meta keys 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_id are 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, and working_directories.
  • Legacy insight payload columns such as payload_json versus 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.

Refs #837 #839 #841 #842 #843 #852.

Activity

  1. Sinity commented on May 5, 2026

    @Sinity
    OwnerAuthor

    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 model plus 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.

  2. Sinity commented on May 5, 2026

    @Sinity
    OwnerAuthor

    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

    1. Conversation write boundary honesty is a storage API issue, now tracked separately in refactor(storage): make conversation writes bundle/hash-honest #841.

    save_conversation() accepts a conversation record/domain object plus independent row lists, then trusts content_hash to 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.

    1. ChatGPT message metadata is a concrete parser/storage contract mismatch, now tracked separately in fix(chatgpt): align parsed message metadata with persisted archive contract #842.

    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.

    1. Provider-event provenance needs an explicit policy.

    provider_events rows include source_message_id and raw_id; batch ingest can attach raw_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.

    1. Session insight rebuild still has a partial provider-meta projection smell.

    The rebuild path avoids loading full provider metadata and projects only selected keys such as cwd, gitBranch, and git. Attribution code also knows about working_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.

    1. Legacy insight payload columns need a policy decision.

    The session insight storage layer still writes legacy payload_json columns 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.

    1. Mapper/tuple duplication is connected to schema clarity.

    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

    • Pydantic/domain validators for non-empty IDs, provider names, and payload shape are ordinary boundary validation, not workaround drift.
    • Search fallbacks may be acceptable as read-model resilience, but they must not hide missing first-class table population.

    Refs #837 #839 #841 #842

  3. added
    type:chore
    phase:architecture
    on May 6, 2026
  4. Sinity commented on May 6, 2026

    @Sinity
    OwnerAuthor

    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:

    • universal archive semantics already modeled correctly;
    • universal-ish semantics that should become first-class schema;
    • provider-specific fields that can stay in provider metadata;
    • accidental/provider-specific columns in universal tables;
    • mapper/row-building repetition where a small local table descriptor/codegen layer would reduce bugs without adopting a full ORM.

    Do not implement broad schema promotion in this issue directly; spawn focused issues/PRs from the inventory.

  5. Sinity commented on May 6, 2026

    @Sinity
    OwnerAuthor

    Execution supplement

    Mass-execution wave: #852 Wave 0 / Wave 3 root.

    Focused verification:

    • This is inventory-first: the main evidence is a schema/API classification comment or small docs artifact plus focused issue updates opened from it.
    • Use rg/schema inspection against polylogue/storage/sqlite/schema_ddl*.py, parser/provider metadata, hydrators, materialization, search/read models, and insight projections.
    • Run devtools render-all --check only if committed docs/generated surfaces change.
    • Do not run full devtools verify for 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.

  6. Sinity commented on May 6, 2026

    @Sinity
    OwnerAuthor

    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 acquisition/provenance: raw_conversations and artifact_observations already carry provider/source/path/artifact/support fields without depending on provider metadata;
    • message core: messages.provider_message_id, role, parent/branch, message_type, stats flags, and content_blocks are canonical storage;
    • tool/action facts: action_events has typed rows for action kind, tool name/id, affected paths, cwd, branch names, command/query/url/output/search text;
    • provider protocol events: provider_events is now the right home for compactions and similar provider-level events;
    • user metadata/tags: tags, conversation_tags, and conversation_user_metadata keep user-owned state separate from content hashes.

    Universal-ish semantics currently trapped in provider_meta or JSON payloads:

    Provider-specific data that can remain provider metadata for now:

    • provider UI/source hints that are not common query/API contracts, such as ChatGPT gizmo fields, provider-specific safe/blocked URL details, moderation/raw UI status, and weak display-label provenance;
    • low-query native details whose only purpose is debugging or provider-specific rendering, as long as raw blobs remain the lossless source of truth;
    • provider capability notes, but they must say provider_meta is retained provider-specific residue, not the canonical path for universal archive semantics.

    Raw-only details:

    • complete provider wire payloads and rare provider fields that no Polylogue surface queries or displays as first-class behavior;
    • exact raw message payloads where canonical content blocks/events/actions already preserve Polylogue semantics.

    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.
    • A full ORM still looks wrong. A small local table/row descriptor may be valuable only if it reduces repeated SQL tuple/mapping drift while preserving explicit SQLite, FTS, generated-column, sync/async, and upgrade control. Keep that decision in this issue until enough field moves show the actual repetition pattern.

    Concrete child ownership

    Closeout test for this inventory issue

    Before closing #840, leave a final matrix with every provider_meta semantic bucket above marked as:

    • promoted in a merged PR;
    • owned by an open issue number;
    • intentionally provider-specific;
    • raw-only;
    • removed as stale/dead compatibility.

    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.

  7. Sinity commented on May 7, 2026

    @Sinity
    OwnerAuthor

    Intended scope

    Produce a schema inventory document (docs/plans/schema-inventory.md) that classifies current schema fields, provider_meta keys, insight projections, and storage mappers across these axes:

    1. Already canonical -- universal archive semantics modeled as first-class columns/rows
    2. Trapped universal -- universal-ish semantics currently in provider_meta, JSON payloads, or ad hoc projection slices
    3. Provider-specific (OK) -- provider metadata that can remain provider_meta
    4. Accidental provider leakage -- provider-specific columns in universal tables
    5. Raw-only -- wire artifacts that should live only in raw blobs
    6. Mapper repetition -- repeated column lists, SQL tuple builders, and row mappers where a local descriptor layer could reduce drift

    Non-goals

    • No code changes, no schema migrations, no implementation PRs
    • No full ORM adoption proposal
    • No raw-provider duplication in canonical tables

    Files expected to change

    • New: docs/plans/schema-inventory.md
    • Possibly: docs/plans/ manifest if one exists, or docs/README.md if links need updating

    Focused 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.py
    • polylogue/storage/insights/session/
    • polylogue/sources/parsers/
    • polylogue/pipeline/prepare_enrichment.py
    • polylogue/core/types.py / polylogue/types.py
    • polylogue/storage/repository/ (mappers, tuple builders)
  8. Sinity commented on May 9, 2026

    @Sinity
    OwnerAuthor

    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.

  9. reopened this on May 9, 2026
  10. Sinity commented on May 9, 2026

    @Sinity
    OwnerAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:schemaphase:architecturetype:chore

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions