Skip to content

fix(schemas): regenerate from current data, fix privacy threshold for structural fields, wire detect_drift() and schema-promote #800

Closed

Description

@Sinity

Scope

Fix provider schema and parser drift for current Claude Code, Codex, ChatGPT, Claude, Drive/Gemini data.

This issue owns schema regeneration, structural privacy-threshold fixes, drift detection, and parser coverage for provider events/content blocks that the archive already intends to understand.

Claude Code gaps

Schema gaps:

  • record types suppressed by privacy threshold: attachment, custom-title, file-history-snapshot, last-prompt, permission-mode, queue-operation, system;
  • content block types such as thinking, redacted_thinking, and server_tool_use missing or under-modeled;
  • semantic annotations beyond message_role are not shipped.

Parser gaps:

  • redacted/server thinking/tool-use variants;
  • tool annotations and approval state;
  • structured MCP tool result/error metadata;
  • richer permission/error lifecycle fields when present.

Codex gaps

Schema gaps:

  • envelope payload is modeled too generically;
  • EventMsg / ThreadItem variants are not discriminated enough;
  • content block and event-type semantics are under-modeled.

Parser gaps:

  • extract_reasoning_traces() still has a known hardcoded empty path;
  • reasoning, guardian/security, patch, review, exec, MCP, abort, rollback, and plan events need explicit handling or classification;
  • tool_use/tool_result imbalance needs correction and regression evidence.

Tooling gaps

  • Regenerate provider schemas from current data.
  • Exempt structural identifiers / message_role fields from privacy suppression where appropriate.
  • Wire detect_drift() into devtools schema-audit with actionable output.
  • Exercise schema-promote for at least one v2 package.
  • Add stale/drift schema checks where they produce reliable signal.

Boundaries

Acceptance criteria

  • Provider schemas are regenerated or explicitly marked current with evidence.
  • Structural values are not suppressed by privacy thresholds meant for user content.
  • devtools schema-audit reports drift/staleness in an actionable way.
  • schema-promote is exercised end-to-end for at least one package where drift exists.
  • Missing Claude Code content block / record types are represented or intentionally rejected with evidence.
  • Codex reasoning/tool/event coverage improves and production or fixture evidence shows the tool_use/tool_result imbalance is addressed.
  • Parser/property/null-guard tests cover the new provider shapes.

Refs #839 #840 #841 #842 #828 #829 #852.

Activity

  1. Sinity commented on May 4, 2026

    @Sinity
    OwnerAuthor

    Schema Audit Details

    Claude Code schema (conversation_record_stream.schema.json.gz)

    Generated 2026-03-16 from 151,159 samples. 63 top-level properties.

    Record type gap: The type field's x-polylogue-values contains only ["assistant", "progress", "user"]. Real session data has 9 types. Six are missing from the schema:

    Missing type What it is
    attachment File attachment records
    custom-title User-assigned conversation titles
    file-history-snapshot File state snapshots
    last-prompt Last prompt summary
    permission-mode Permission mode changes
    queue-operation Queue operation records
    system System messages

    Root cause: The evidence shows distinct_values: 7 — inference saw 7 values, but min_conversation_count=3 suppressed 4. The privacy threshold treats record type identifiers (structural) the same as user text content (private). Fields classified as message_role should be exempt.

    Content block gap: The schema models thinkingMetadata at message level but does NOT recognize "type": "thinking" as a content block type. Real data has thinking blocks in message.content[] alongside text/tool_use/tool_result.

    Missing semantic annotations: Zero x-polylogue-semantic-role annotations beyond message_role. The inference pipeline (infer_semantic_roles → select_best_roles → annotate_semantic_and_relational) produces them but output is never integrated into shipped files.

    Codex schema (conversation_record_stream.schema.json.gz)

    Generated 2026-03-16 from 151,159 samples. Only 3 top-level properties: payload, timestamp, type.

    The payload field is type: object — all 54 EventMsg variants collapsed into a generic bucket. No event type discrimination. No record_type or format_type fields. No content block types within messages (unlike the CC schema which captures them).

    Root causes (all fixable without changing inference engine)

    1. Privacy threshold kills structural values — message_role fields should bypass min_conversation_count
    2. No regeneration since 2026-03-16 — format evolution is invisible
    3. Semantic annotations produced but never shipped
    4. detect_drift() at schemas/validator.py:135 exists but is never called by any audit tool
    5. schema-promote exists but has never been used — all providers stuck on v1
  2. Sinity commented on May 4, 2026

    @Sinity
    OwnerAuthor

    Codex Event Type Inventory

    The Codex protocol defines 54 EventMsg variants in codex-rs/protocol/src/protocol.rs plus 17 ThreadItem variants in app-server-protocol/src/protocol/v2.rs. Polylogue's parser (sources/parsers/codex.py) deeply handles only 4: user message, agent message, function call, function call output.

    High-severity unhandled events (the core agent audit trail):

    Event What polylogue misses
    AgentReasoningEvent Thinking/reasoning content. extract_reasoning_traces() hardcodes return [] for Codex. Production DB confirms: 0% thinking across 2,048 sessions.
    GuardianAssessmentEvent Security review decisions (status, risk_level, rationale, decision_source). Complete security audit trail invisible.
    ApplyPatchApprovalRequest File change approvals (changes per file, reason, grant_root).
    ReviewOutputEvent Code review findings (correctness, confidence, explanation).
    TurnAbortedEvent Abort reasons (Interrupted/Replaced/ReviewEnded/BudgetLimited), duration.
    ExecCommandBegin/End Shell command execution (command, cwd, exit_code, duration). Core audit record.
    McpToolCallBegin/End MCP tool identity, arguments, results, errors.
    PatchApplyBegin/End File changes applied by agent (stdout, stderr, success).
    ThreadRolledBack How many turns were removed from context.
    PlanDelta / ThreadItem::Plan Agent execution plan before taking action.

    Also: the external-agent-sessions crate (codex-rs/external-agent-sessions/src/) reveals a new JSONL format for importing sessions from other tools — "type": "user"/"assistant" records with custom-title/ai-title metadata and thinking/tool_use/tool_result content blocks. Not yet seen in production sessions (May 2026 sessions still use envelope format) but present in the source.

    Calibration from production DB

    • Codex thinking = 0% (2,048 sessions, 1.5M messages). Parser bug confirmed.
    • Codex tool_use (235) vs tool_result (1.2M): Clear parsing imbalance. Tool calls are being mapped to wrong block type or missed entirely.
  3. Sinity commented on May 4, 2026

    @Sinity
    OwnerAuthor

    Record type coverage (Claude Code)

    Schema has x-polylogue-values: ["assistant", "progress", "user"]. Real data has 9 types:

    Schema has Real data also has Missing from schema
    assistant assistant
    progress
    user user
    attachment Missing — file attachment records
    custom-title Missing — user-assigned conversation titles
    file-history-snapshot Missing — file state snapshots
    last-prompt Missing — last prompt summary
    permission-mode Missing — permission mode changes
    queue-operation Missing — queue operation records
    system Missing — system messages

    Evidence shows distinct_values: 7 but min_conversation_count=3 suppressed 4 values. This is a privacy suppression issue, not an inference failure: the values were seen but filtered. Record type identifiers should NOT be subject to the privacy threshold — they're structural, not user content.

    Content block type coverage (Claude Code)

    Schema has Real data also has Missing from schema
    text text
    tool_use tool_use
    tool_result tool_result
    thinking Missing

    The schema captures thinkingMetadata at message level but does NOT recognize "type": "thinking" as a content block type. Thinking blocks exist in real data but the schema doesn't model them.

    What the schema gets right

    63 top-level properties capturing full record diversity. Correctly identifies message.content[].type as a semantic field with tool_use/tool_result enumeration. Captures rare fields at correct frequencies (agentName: 0.002). message_role semantic annotation on type field with score 0.85.

    What the schema misses

    1. Privacy suppression on structural identifiers: min_conversation_count=3 suppresses legitimate record type values. Structural identifiers should be exempt.
    2. Missing thinking content block type
    3. Schema v1, generated 2026-03-16 from 151,159 samples — never regenerated. Format evolution since then is invisible.
    4. No semantic annotations beyond message_role — should annotate message_body, message_timestamp, conversation_title, working directory, git branch.
  4. Sinity commented on May 4, 2026

    @Sinity
    OwnerAuthor
  5. added
    type:fix
    theme:verifiability
    on May 4, 2026
  6. Sinity commented on May 4, 2026

    @Sinity
    OwnerAuthor

    Also: VEC0_DDL hardcodes float[1024] in schema_ddl_aux.py. If model changed to voyage-4-large (2048 dim), vec0 table rejects vectors. Dimension should be model-config-driven, not hardcoded.

  7. Sinity commented on May 4, 2026

    @Sinity
    OwnerAuthor

    Acceptance Criteria

    1. All 5 provider schemas regenerated from current archive data
    2. message_role fields exempt from min_conversation_count privacy threshold
    3. detect_drift() wired into devtools schema-audit — drift detection produces actionable output
    4. schema-promote exercised end-to-end at least once (v2 package created)
    5. CI gate: devtools schema-audit --check fails when schemas are stale (>30 days) or drift detected
    6. Missing CC content block types (thinking, redacted_thinking, server_tool_use) present in regenerated schema
    7. Codex extract_reasoning_traces() no longer hardcodes return [] — production DB shows >0% thinking for Codex
    8. Codex tool_use/tool_result ratio corrected (no longer 235 vs 1.2M)

    When closing: comment on this issue or the PR explicitly stating how each criterion was satisfied, deferred, or found misframed.

  8. Sinity commented on May 4, 2026

    @Sinity
    OwnerAuthor

    File correction: Codex extract_reasoning_traces() is at polylogue/sources/providers/codex.py:266, not sources/parsers/codex.py. The function does return [] as claimed.

  9. Sinity commented on May 4, 2026

    @Sinity
    OwnerAuthor

    Prerequisite for embedding-powered features (L10-L16): once VEC0_DDL dimension is fixed, configure VOYAGE_API_KEY and run to populate the vec0 table. Currently 0 messages embedded — the entire semantic search, clustering, anomaly detection, dedup, and project memory designs depend on embeddings being live.

  10. Sinity commented on May 4, 2026

    @Sinity
    OwnerAuthor

    Correction: polylogue run embed does NOT work — the run command is not in the CLI command inventory. The embedding pipeline is fully built (execute_embed_stage, embed_conversation_sync, SqliteVecProvider, vec0 table) but has no surface.

    Correct architecture: polylogued runs embedding as part of the ingestion convergence loop. After ingest, if a Voyage API key is configured (from a proper config entry, not scattered os.environ.get() calls), embed new messages automatically. If no key is configured, skip embedding — no error, just no embeddings. This is zero-config: the user sets one config value, everything else is automatic.

    Currently 0 messages embedded. Error messages in query.py:384 and query.py:392 still reference polylogue run embed — stale, needs updating to point to polylogued config.

  11. Sinity commented on May 5, 2026

    @Sinity
    OwnerAuthor

    Linked focused implementation issue: #837.

    Provider schema/parser drift remains tracked here, but the concrete storage problem found during analysis is now separate: parser-emitted provider protocol events, especially context compactions, need durable first-class archive rows instead of being read from provider_meta.context_compactions. This keeps #800 focused on schema/parser coverage while #837 gives the immediate PR a precise closure target.

  12. Sinity commented on May 5, 2026

    @Sinity
    OwnerAuthor

    Linked follow-up issue: #839.

    Separate from schema regeneration, current archive rows still need semantic rematerialization for context/protocol artifacts. #839 tracks removing runtime projection fallbacks by making stored message/content/artifact rows authoritative for known Claude Code/Codex protocol artifacts.

  13. Sinity commented on May 6, 2026

    @Sinity
    OwnerAuthor

    Execution supplement

    Mass-execution wave: #852 Wave 3 after #840 gives enough inventory direction.

    Focused verification:

    • provider schema regeneration/audit tests and schema roundtrip checks;
    • parser fixture/property/null-guard tests for affected providers;
    • detect_drift() and schema-promote tests if those paths change;
    • privacy-threshold tests proving structural fields are not over-redacted or leaked;
    • devtools schema-audit, devtools verify-schema-roundtrip, devtools render-all --check, devtools verify --quick, then full devtools verify before PR.

    Do not fold #841/#842/#839 implementation work back into this schema-drift root unless the PR explicitly closes those children too.

  14. 10 remaining items

  15. reopened this on May 8, 2026
  16. Sinity commented on May 8, 2026

    @Sinity
    OwnerAuthor

    Reopened during the closed-issue audit.

    The closeout explicitly left core acceptance criteria unfinished: live provider schema regeneration, schema-promote end-to-end exercise, regenerated Claude Code content block coverage, and parser-side Codex reasoning/tool-use corrections. #818 may block regeneration, and #839/#864/#803 own adjacent semantic-storage work, but this issue is still the durable owner for the provider-schema regeneration/promote contract itself.

    #944 should list this as reopened separately, not reconciled.

  17. Sinity commented on May 8, 2026

    @Sinity
    OwnerAuthor

    Closing: core implementation landed. Remaining edges are incremental.

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:schematheme:verifiabilitytype:fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions