-
Notifications
You must be signed in to change notification settings - Fork 2
fix: read an unprovisioned archive tier without reporting schema skew #4687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -579,6 +579,12 @@ def _schema_skew_remedy(tier: ArchiveTier) -> str: | |
| ) | ||
|
|
||
|
|
||
| def _tier_holds_no_schema(conn: sqlite3.Connection) -> bool: | ||
| """Report whether a tier file carries any non-internal schema object.""" | ||
| row = conn.execute("SELECT 1 FROM sqlite_master WHERE name NOT LIKE 'sqlite_%' LIMIT 1").fetchone() | ||
| return row is None | ||
|
|
||
|
|
||
| def _assert_schema_supported(conn: sqlite3.Connection, path: str | Path, tier: ArchiveTier | None) -> None: | ||
| """Reject a known archive tier before any caller can issue SQL against it.""" | ||
| from polylogue.core.errors import SchemaSkew | ||
|
|
@@ -593,6 +599,12 @@ def _assert_schema_supported(conn: sqlite3.Connection, path: str | Path, tier: A | |
| except KeyError as exc: | ||
| raise ValueError(f"unknown archive tier: {resolved_tier!r}") from exc | ||
| found = int(conn.execute("PRAGMA user_version").fetchone()[0]) | ||
| if found == 0 and _tier_holds_no_schema(conn): | ||
| # A tier file with neither a version stamp nor any schema object has | ||
| # never been provisioned. Reading it is reading an absent tier: the | ||
| # caller fails on the missing table it asked for, which is a truthful | ||
| # not-provisioned answer, where skew would misreport corruption. | ||
|
Comment on lines
+602
to
+606
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a tier-named durable file such as AGENTS.md reference: AGENTS.md:L107-L115 Useful? React with 👍 / 👎. |
||
| return | ||
| if resolved_tier is ArchiveTier.INDEX and found == 0: | ||
| return | ||
| if found != expected: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the daemon is unavailable and any present tier has a mismatched schema version, this catch lets
_archive_one_tier_statuscontinue, but the same direct-status workflow subsequently calls_sqlite_maintenance_status, whose validating open catches onlysqlite3.Error. BecauseSchemaSkewErroris a separate project exception, both JSON status and the plaintext status path still abort instead of returning the version facts this change intends to preserve; handle the exception in that second pass as well.AGENTS.md reference: AGENTS.md:L109-L115
Useful? React with 👍 / 👎.