Skip to content

fix(storage): block schema version mismatch - #709

Merged
Sinity merged 3 commits into
masterfrom
feature/fix/schema-compatibility-checks
May 2, 2026
Merged

Sinity merged 3 commits into
masterfrom
feature/fix/schema-compatibility-checks

Conversation

@Sinity

@Sinity Sinity commented May 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

Make mismatched archive schema versions fail explicitly instead of pretending to recreate or migrate legacy layouts, and incorporate timestamp parsing fixes left in the worktree by another agent.

Problem

#618 identified that the version-mismatch path claimed to preserve metadata and recreate the database, but the implementation only reran additive CREATE ... IF NOT EXISTS DDL. That could leave old table shapes in place while setting PRAGMA user_version to the current schema. Read-only opens also skipped compatibility checks, so old databases could fail later with unclear SQL errors.

Separately, another agent had started replacing local timestamp parsing in materialization and ChatGPT ordering with the shared timestamp parser. Those edits were present in the worktree but needed cleanup and coverage.

Solution

  • Reject schema-version mismatches in sync and async schema setup with the reset/re-import diagnostic.
  • Add a non-mutating read-only compatibility check so open_read_connection() fails clearly on mismatched versions or known legacy inline raw layouts.
  • Remove the unused metadata export/import recreate path tied to the misleading in-place upgrade story.
  • Update architecture and assurance text to say mismatches block rather than wipe or migrate.
  • Finish the materialization timestamp fix by routing non-numeric sort-key parsing through parse_timestamp() and covering ISO datetime plus millisecond epoch behavior.
  • Finish the ChatGPT parser timestamp fix so ISO create_time values participate in message ordering, with parser-level coverage.

Verification

  • ruff check polylogue/storage/backends/schema.py polylogue/storage/backends/schema_bootstrap.py polylogue/storage/backends/connection.py polylogue/pipeline/materialization_runtime.py tests/unit/storage/test_backend.py tests/unit/pipeline/test_materialization_runtime.py
  • ruff format --check polylogue/storage/backends/schema.py polylogue/storage/backends/schema_bootstrap.py polylogue/storage/backends/connection.py polylogue/pipeline/materialization_runtime.py tests/unit/storage/test_backend.py tests/unit/pipeline/test_materialization_runtime.py
  • pytest -q tests/unit/storage/test_backend.py tests/unit/pipeline/test_materialization_runtime.py
  • ruff check polylogue/sources/parsers/chatgpt.py tests/unit/sources/test_parsers_chatgpt.py
  • ruff format --check polylogue/sources/parsers/chatgpt.py tests/unit/sources/test_parsers_chatgpt.py
  • pytest -q tests/unit/sources/test_parsers_chatgpt.py tests/unit/pipeline/test_materialization_runtime.py
  • devtools verify-manifests
  • devtools render-all --check
  • git push pre-push hook: devtools verify --quick passed

Ref #618

Sinity added 2 commits May 2, 2026 17:29
Problem: the schema-version mismatch path claimed to recreate or upgrade an old archive, but it only reran additive CREATE IF NOT EXISTS DDL. That could leave incompatible old table shapes in place while advancing PRAGMA user_version. Read-only opens also skipped compatibility checks and could fail later with confusing SQL errors.

What changed: reject mismatched schema versions for sync and async setup with the existing reset/re-import diagnostic, wire read-only connections through a non-mutating compatibility check, and remove the unused metadata export/import path that belonged to the misleading in-place recreate story. Update docs and assurance wording to say mismatch blocks instead of wiping or migrating.

Verification: ruff check polylogue/storage/backends/schema.py polylogue/storage/backends/schema_bootstrap.py polylogue/storage/backends/connection.py tests/unit/storage/test_backend.py; ruff format --check polylogue/storage/backends/schema.py polylogue/storage/backends/schema_bootstrap.py polylogue/storage/backends/connection.py tests/unit/storage/test_backend.py; pytest -q tests/unit/storage/test_backend.py; devtools verify-manifests

Ref #618
Problem: another agent started replacing local ISO parsing in materialization sort-key handling with the shared timestamp parser, but the worktree edit left duplicated imports and dead fallback code.

What changed: finish the change by routing non-numeric sort-key parsing through polylogue.core.timestamps.parse_timestamp and add focused coverage for ISO datetimes and millisecond epoch normalization.

Verification: ruff check polylogue/pipeline/materialization_runtime.py tests/unit/pipeline/test_materialization_runtime.py; ruff format --check polylogue/pipeline/materialization_runtime.py tests/unit/pipeline/test_materialization_runtime.py; pytest -q tests/unit/pipeline/test_materialization_runtime.py
Copilot AI review requested due to automatic review settings May 2, 2026 15:32
@coderabbitai

coderabbitai Bot commented May 2, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 19 minutes and 33 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: d13fac02-0a73-4566-a4c8-82fdb7615ada

📥 Commits

Reviewing files that changed from the base of the PR and between 981fbb3 and 2a4a5d2.

📒 Files selected for processing (10)
  • docs/architecture.md
  • docs/plans/assurance-domains.yaml
  • polylogue/pipeline/materialization_runtime.py
  • polylogue/sources/parsers/chatgpt.py
  • polylogue/storage/backends/connection.py
  • polylogue/storage/backends/schema.py
  • polylogue/storage/backends/schema_bootstrap.py
  • tests/unit/pipeline/test_materialization_runtime.py
  • tests/unit/sources/test_parsers_chatgpt.py
  • tests/unit/storage/test_backend.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/schema-compatibility-checks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 19 minutes and 33 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented May 2, 2026 •

Copy link
Copy Markdown
Contributor

Polylogue Proof Pack

Refs: origin/master..HEAD
Changed paths: 10

Affected Domains

  • architecture_discipline — 1 claim(s), maturity growing
  • spec_completeness — 2 claim(s), maturity seed
  • unclassified — 2 claim(s), maturity seed
Additional routed domains with zero affected claims
  • docs_media — maturity seed
  • mutation_coverage — maturity growing

Focused Gates

  • devtools verify-manifests — assurance coverage manifest changed
  • devtools render-verification-catalog --check — coverage manifests feed proof subjects
  • devtools proof-pack --path docs/plans/assurance-domains.yaml --markdown — coverage changes feed proof-pack gaps
  • pytest tests/unit/sources — parser semantics changed
  • devtools pipeline-probe --provider chatgpt — parser pipeline probe
  • devtools affected-obligations --path polylogue/sources/parsers/chatgpt.py — refresh focused obligation routing

Required PR Gates

  • devtools verify --quick — full PR gate remains explicit
  • devtools verify — full PR gate remains explicit

Optional Confidence Gates

  • devtools build-package — deployment readiness gate; run when packaging or release confidence matters
  • nix flake check — deployment readiness gate; run when packaging or release confidence matters

Known Gaps

  • none for domains with affected claims
Additional gaps in zero-claim routed domains
  • docs_media: docs_media: No scenario for documentation freshness verification [owner: scenario-coverage; next: devtools scenario-projections], docs_media: README examples and media are not yet generated from executable scenario projections. [owner: docs-media; next: devtools render-docs-surface --check], docs_media: Screenshots and VHS media have no committed nonblank/readability verification. [owner: docs-media; next: devtools render-docs-surface --check]

Oracle / Cost

  • oracle mix: {"construction_sanity": 32, "drift_check": 1}
  • cost tier: {"static": 33}
  • stable affected obligations: 33
  • agent judgment cells: 0

Problem: another agent left a ChatGPT parser change that began teaching _coerce_float about ISO timestamp strings, but it was uncommitted and lacked parser-level coverage.

What changed: finish the ChatGPT timestamp coercion fix and add coverage that ISO create_time values sort extracted messages chronologically.

Verification: ruff check polylogue/sources/parsers/chatgpt.py tests/unit/sources/test_parsers_chatgpt.py; ruff format --check polylogue/sources/parsers/chatgpt.py tests/unit/sources/test_parsers_chatgpt.py; pytest -q tests/unit/sources/test_parsers_chatgpt.py tests/unit/pipeline/test_materialization_runtime.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens SQLite archive schema handling by making schema-version mismatches fail explicitly (including for read-only opens) rather than attempting partial “upgrade” behavior, and completes a materialization timestamp parsing fix by routing ISO timestamps through the shared timestamp parser.

Changes:

  • Reject schema-version mismatches in sync and async schema initialization with a clear reset/re-import diagnostic.
  • Add a read-only layout/version compatibility check for open_read_connection() to fail early on incompatible archives.
  • Fix materialization timestamp sort-key parsing by using parse_timestamp() and add unit coverage for ISO and millisecond-epoch inputs.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
polylogue/storage/backends/schema.py Raises DatabaseError on version mismatch; adds assert_readable_archive_layout() for read-only compatibility checks.
polylogue/storage/backends/connection.py Invokes read-only compatibility checks during open_read_connection().
polylogue/storage/backends/schema_bootstrap.py Updates version-mismatch diagnostic message and removes unused metadata export/import helpers.
polylogue/pipeline/materialization_runtime.py Uses shared parse_timestamp() for non-numeric timestamp sort keys.
tests/unit/storage/test_backend.py Updates schema-mismatch expectations and adds coverage for read-only mismatch behavior.
tests/unit/pipeline/test_materialization_runtime.py Adds tests for ISO datetime and millisecond epoch sort-key normalization.
docs/plans/assurance-domains.yaml Updates assurance notes to reflect “block on mismatch” behavior.
docs/architecture.md Updates architecture docs to reflect mismatch rejection behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 108 to 110
if decision.action == "version_mismatch":
_handle_version_mismatch(conn, decision.current_version or 0)
raise DatabaseError(schema_version_mismatch_message(decision.current_version or 0))
return
Comment on lines +109 to 110
raise DatabaseError(schema_version_mismatch_message(decision.current_version or 0))
return
Comment on lines +135 to 136
raise DatabaseError(schema_version_mismatch_message(decision.current_version or 0))
return
@Sinity
Sinity merged commit e802e9f into master May 2, 2026
14 checks passed
@Sinity
Sinity deleted the feature/fix/schema-compatibility-checks branch May 2, 2026 15:38
Sinity added a commit that referenced this pull request May 7, 2026
Summary: Make mismatched archive schema versions fail explicitly instead of pretending to recreate or migrate legacy layouts, and incorporate timestamp parsing fixes left in the worktree by another agent.

Problem: #618 identified that the version-mismatch path claimed to preserve metadata and recreate the database, but the implementation only reran additive CREATE IF NOT EXISTS DDL. That could leave old table shapes in place while setting PRAGMA user_version to the current schema. Read-only opens also skipped compatibility checks, so old databases could fail later with unclear SQL errors. Separately, another agent had started replacing local timestamp parsing in materialization and ChatGPT ordering with the shared timestamp parser; those edits were present in the worktree but needed cleanup and coverage.

Solution: Reject schema-version mismatches in sync and async schema setup with the reset/re-import diagnostic. Add a non-mutating read-only compatibility check so open_read_connection() fails clearly on mismatched versions or known legacy inline raw layouts. Remove the unused metadata export/import recreate path tied to the misleading in-place upgrade story. Update architecture and assurance text to say mismatches block rather than wipe or migrate. Finish the materialization and ChatGPT timestamp fixes by routing non-numeric timestamp parsing through parse_timestamp() and adding focused coverage.

Verification: ruff check polylogue/storage/backends/schema.py polylogue/storage/backends/schema_bootstrap.py polylogue/storage/backends/connection.py polylogue/pipeline/materialization_runtime.py tests/unit/storage/test_backend.py tests/unit/pipeline/test_materialization_runtime.py; ruff format --check polylogue/storage/backends/schema.py polylogue/storage/backends/schema_bootstrap.py polylogue/storage/backends/connection.py polylogue/pipeline/materialization_runtime.py tests/unit/storage/test_backend.py tests/unit/pipeline/test_materialization_runtime.py; pytest -q tests/unit/storage/test_backend.py tests/unit/pipeline/test_materialization_runtime.py; ruff check polylogue/sources/parsers/chatgpt.py tests/unit/sources/test_parsers_chatgpt.py; ruff format --check polylogue/sources/parsers/chatgpt.py tests/unit/sources/test_parsers_chatgpt.py; pytest -q tests/unit/sources/test_parsers_chatgpt.py tests/unit/pipeline/test_materialization_runtime.py; devtools verify-manifests; devtools render-all --check; git push pre-push hook ran devtools verify --quick and passed.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants