Skip to content

The Chat store migrates in place: a schema step keeps every Chat, so a turn still running across an update is followed to its end - #252

Merged
SitgesRun merged 1 commit into
stagingfrom
store-migrations
Nov 15, 2026
Merged

SitgesRun merged 1 commit into
stagingfrom
store-migrations

Conversation

@SitgesRun

@SitgesRun SitgesRun commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Until now, a Chat store of another schema was renamed aside and a fresh one opened. So after any schema change, the
Studio's start found no Chat that was running a turn, and that turn's results stayed on the Computer until it idled
out. Now the store migrates in place: a schema step keeps every Chat.

What changes

  • core/store.ts: SCHEMA_VERSION/SCHEMA become MIGRATIONS, numbered steps, after Code-OSS's own SQLite stores
    (src/vs/platform/agentHost/node/sessionDatabase.ts, runMigrations). A schema change appends the next version, and a
    step that has shipped is never edited. The steps above the file's user_version run once, in one begin immediate
    transaction (Store.tx). The version is read again under the lock. Foreign keys are off around the transaction and
    checked before commit (https://www.sqlite.org/lang_altertable.html#otheralter). The first step is 20, today's staging
    schema.
  • A store older than the first step is copied aside with VACUUM INTO by the window that holds the write lock, then
    replaced in place. Firefox Places does the same for schemas it no longer migrates. The released v0.2.x stores are at
    16 (protocol major 1, whose turns major-2 code cannot follow). Nothing is renamed any more: SQLite documents renaming
    as a way to corrupt a file another connection holds (https://www.sqlite.org/howtocorrupt.html). The person is told in
    one line where the copy went.
  • A store a newer Studio wrote is refused before anything writes to it, as Android's SQLiteOpenHelper.onDowngrade does
    by default. Its schema, rows and journal mode stay as they were. The journal mode is set only after the version is
    accepted, best effort, as Code-OSS's configureSqliteJournal.
  • Tests: test/storeMigrations.test.ts, which covers a newer store in either journal mode, a failed step rolling
    everything back, schemas 2 and 11 copied aside once, and two real processes behind a barrier racing a current, a fresh
    and a schema 11 store. One more test is in protocolFlow.test.ts: a Chat whose turn still runs across a schema step is
    followed after the step, and its results land. boundFolder.test.ts and the set-aside test in chats.test.ts are
    deleted; what they checked is covered in the new file.

The plan was reviewed by Codex (read-only) in three rounds before coding. The last verdict was "Ready to code".

What I ran

  • Failing first, on the old code: a scratch commit dd614c4 on 2780b80, with SCHEMA_VERSION = 21 and the new
    protocolFlow test. scripts/test-on-pine-dev.sh studio dd614c4… printed tests 330,pass 326,fail 3. The new test
    failed with AssertionError: nothing is set aside (actual
    { schema: 20, path: '…/studio.sqlite.schema20-20261115T215948Z' }). The other two failures assert schema 20, as
    expected on that scratch commit.
  • This head, 3b3a340: scripts/test-on-pine-dev.sh studio 3b3a340 printed (the same on 077ba0b, before the Codex fix) npm test: 19s: tests 336,pass 335,fail 0,cancelled 0,skipped 1, render smoke: 30 of 30 pages rendered, and done: PASSED in 97s. All 9 new tests show ✔ in the run
    log.
  • Locally, npx tsc -p .: no errors in the changed files. The errors it does print come from the main checkout's
    node_modules, which lacks dugite.

Codex on the code (read-only, after the gate)

One finding, B: the child-process test resolved on exit, which can come before the child's stdout has drained. It now
waits on close (https://nodejs.org/api/child_process.html#event-close). Codex's verdict: "Matches revision 4; no
production blocker, vacuous regression assertion, or substantive dead code found."

…a turn still running across an update is followed to its end

Until now a store of another schema was renamed aside and a fresh one opened, so after any schema change the start found
no Chat that was running a turn: its results stayed on the Computer until it idled out.

The schema is now numbered steps (MIGRATIONS), as Code-OSS keeps its own SQLite stores (sessionDatabase.ts,
runMigrations): a change appends the next version, and the steps above the file's user_version run once, in one
begin-immediate transaction, re-read under the lock, with foreign keys off around it and checked before commit
(sqlite.org/lang_altertable.html#otheralter). The first step is 20, the schema staging stores are at.

A store older than that (the released v0.2.x stores are at 16, protocol major 1) is copied aside with VACUUM INTO by the
window holding the write lock, then replaced in place, as Firefox Places replaces schemas it no longer migrates; nothing
is renamed any more, which SQLite documents as a way to corrupt a file another connection holds. A store a newer Studio
wrote is refused before anything writes to it, as Android's SQLiteOpenHelper.onDowngrade does by default. The journal
mode is set only after the version is accepted, best effort as Code-OSS's configureSqliteJournal.

Signed-off-by: SitgesRun <169425442+SitgesRun@users.noreply.github.com>
@SitgesRun
SitgesRun merged commit 3b3a340 into staging Nov 15, 2026
1 check passed
@SitgesRun
SitgesRun deleted the store-migrations branch November 15, 2026 22:06
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.

1 participant