Repository navigation
Conversation
📊 Automated PR Analysis
SummaryAdds open_and_migrate_or_stay_behind to core::db so the tracking database, when read-only and behind the current schema, opens as-is instead of failing migration. Queries hitting missing tables/columns now surface a clear 'read-only and was not upgraded' message, and tracking writes become silent no-ops on a behind database instead of erroring; rtk init and the generic open_and_migrate path are unaffected. Review Checklist
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
6 tasks done
SCHEMA_VERSION is now derived from a SchemaVersion enum, and each variant has its own migration step, applied in order from the database's user_version and stamped in its own transaction. Two changes adding a schema version now conflict instead of merging into one shared bump. The open and the migration engine live in core::db, which the recall database now uses with its own versions, replacing its swallowed ALTER. Each file carries an application_id naming its database, and a file tagged as another database's is refused before rtk changes anything on it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A gated open of a read-only database keeps the connection at the schema it has, for tracking and recall; queries that need the missing table or column say the database was not upgraded. Co-Authored-By: Claude Opus 5.5 <[email protected]>
KuSh
force-pushed
the
fix/schema-version-enum
branch
from
November 4, 2026 18:27
f8f8180 to
d3a5497
Compare
KuSh
force-pushed
the
fix/tracking-readonly-open
branch
from
November 4, 2026 18:27
6ccfa6f to
a5a9ff1
Compare
13 tasks done
KuSh
force-pushed
the
fix/schema-version-enum
branch
from
November 6, 2026 18:18
d3a5497 to
5c66e2a
Compare
Collaborator
Author
|
Closing: #4894 now covers this and goes further. A step that fails on a normal open keeps the database usable whatever the cause, for tracking and recall, which replaces the read-only handling here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #4894: this PR's base is a copy of that branch, so the diff shows only this change. It is retargeted to
developonce #4894 is merged.Summary
When a tracking DB or recall store is read-only and stale (a build that bumped the schema version, then a sandboxed agent shell with a read-only data dir, a read-only mount, or a file left root-owned by
sudo rtk ...), its open failed on the migration:rtk gain,discoverandsessionprinted "Failed to initialize tracking database", andrtk recallsaid the store was unavailable. Both now open the database as it is, and a query that needs a table or column the old schema lacks says why.db::open_and_migrateanddb::open_existing_and_migratereturn the connection and abehindflag. A gated open never migrates a connection SQLite reports read-only (sqlite3_db_readonly: opened read-only, or SQLite's fallback on a file it cannot write, EACCES/EROFS, afterclaimhas tried to make the file writable): it reads the stamp it already has, and the database is behind when the stamp is below the schema's last step. A refusal that only shows on write (a read-only directory) is told by SQLITE_READONLY from a step (anySQLITE_READONLY_*, found anywhere in the error chain;CannotOpenis not one), after the version has been read. Ownership comes first: a read-only file that is another database's, or untagged with a stamp the schema does not own, is refused, not opened behind.rtk init(Always) still fails on a database it cannot migrate, and reports it as a warning.The
Trackerholds a smallDbwrapper withoutDeref, so every query goes throughprepare/execute/query_row, which append "tracking database is read-only and was not upgraded" to a "no such table", "no such column" or "has no column named" error (as a plain SQLite error, without the statement text). BecauseTracker::new()now succeeds on such a DB,record,record_parse_failure,record_hook_decision,record_attributionandclassifier_cache_putreturnOk(())on a behind tracker without touching the DB, so the hook andrtk <cmd>stay quiet.rtk gain --resetis an explicit request and reports the refusal.The recall store caches the flag with its connection, and an error from a closure run on a behind connection gets the same note, "recall database is read-only and was not upgraded". Its writers need no skip: their failures were already handled as on any store that cannot be written.
rtk gainon a read-only stale DB opens and shows what the old schema holds; a query on a newer table fails withno such table: engine_attribution (tracking database is read-only and was not upgraded)instead of "Failed to initialize tracking database".rtk recall --list,rtk recall <hash>andrtk gain --recallson a read-only stale store read what it holds. One withoutrecall_statsshowsRecall store unavailable: no such table: recall_stats (recall database is read-only and was not upgraded)inrtk gain --recalls.rtk <cmd>and the analytics writers stay quiet on such a DB: no "hook_decisions logging failed" and no write errors.rtk gain --reseton it fails with "Failed to reset token savings: tracking database is read-only and was not upgraded".0444backup that can be made writable, a current read-only DB and a corrupt or unreadable DB behave as before.-shm(no sidecars, on a read-only mount) still fails on the first read, as ondevelop.Test plan
-wal/-shmrestricted to0600Alwaysmode still fails with SQLITE_READONLYPRAGMA query_only) keeps the connection behind; inAlwaysmode it failsis_readonlyis true for aSQLITE_OPEN_READ_ONLYconnection and forConnection::openon a0444file (skipped when the process can write it); a0444fileclaimcan make writable is migrated, not kept behindCannotOpenor a plain errorDbcarries the flag fromOpened; a behind DB names the cause for a missing table (prepare,executeandquery_row; a plainSqliteFailuretoo), a missing column and an INSERT naming one, and leaves other errors alone; a current tracker never annotatesOkand leave every table empty (engine-only writers in#[cfg(feature = "engine")]tests); a current tracker still recordsreset_allon a behind tracker reports the notedevelop, fix(db): version the tracking and recall schema migrations #4894 and this branch run on a read-only bind mount (unshare -rm) against stale, current, empty, WAL and foreign recall stores:rtk recall --list,rtk recall <hash>andrtk gain --recallswork whereverdevelop's do, except on a store that is another database's filecargo fmt,cargo clippy --all-targets,cargo test --all, the same with--no-default-features, and ax86_64-pc-windows-gnucheck🤖 Generated with Claude Code