Skip to content

[Bug]: Migration 95 (TurnItemInlineWorkOutput) never finishes on a large database: 21 GB row rewrite with the undo journal held in RAM #37961

Open

Description

@stefanofa

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Use the macOS desktop app with a large statev2.sqlite (46 GB here; orchestration_v2_projection_turn_items has 265,477 dynamic_tool rows holding 25 GB of payload_json).
  2. Update from 0.1.10-nightly.20261115.4723 (migration head 94) to 0.1.10-nightly.20261116.4787.
  3. Open the app. Migration 95_TurnItemInlineWorkOutput starts.

Expected behavior

Migration 95 finishes and the server becomes ready.

Actual behavior

Migration 95 never finishes. Seen twice, the second time after a full reboot:

  • For about 6 minutes the server writes heavily, and statev2.sqlite-wal grows to 16 GB.
  • Then all disk I/O stops (0 bytes read or written over 10 s samples), but the process keeps 2 to 3 cores busy, mostly in kernel time, and its memory footprint stays at 15 GB (footprint shows 15 GB dirty in about 269k regions).
  • No new trace spans after the ALTER TABLE and no commit. The first run sat like this for over an hour.
  • /.well-known/t3/environment first returns 503, then stops answering at all.

Diagnosis

The WHERE clause is not the problem. Run alone and read-only in the sqlite3 CLI, it takes 2 min 42 s and matches 138,554 rows totalling 21 GB of payload_json.

The cost is the rewrite. ADD COLUMN ... DEFAULT 0 doesn't touch existing rows, but SET inline_work_output = 1 rewrites each matched record, including every overflow page of its payload. So the UPDATE rewrites about 21 GB of data.

It runs inside the migrator's transaction, so SQLite most likely keeps a statement journal (an undo copy of every page the statement changes). The server sets PRAGMA temp_store = MEMORY, so that journal lives in RAM. On a 36 GB machine the process reaches 15 GB, roughly the size of the WAL written so far, and then stops making progress. I couldn't confirm what it spins on: the bundled binaries are stripped, and stack samples show the SQLite worker thread mostly inside signal handlers.

Supporting evidence: the same statements in one transaction in the sqlite3 CLI (3.54.0), with PRAGMA temp_store = FILE and the server stopped, completed normally:

BEGIN IMMEDIATE;
INSERT INTO effect_sql_migrations (migration_id, name) VALUES (95, 'TurnItemInlineWorkOutput');
ALTER TABLE ... ADD COLUMN inline_work_output ...;   -- instant
UPDATE ... SET inline_work_output = 1 WHERE ...;      -- 562 s, 138,554 rows
COMMIT;                                               -- 199 s
PRAGMA wal_checkpoint(TRUNCATE);                      -- 4 s
PRAGMA quick_check;                                   -- ok

Suggestions

  • Don't rewrite large payload rows to set a flag. For example, keep the flag in a small side table keyed by item id, or compute it on read.
  • If it has to be a column, backfill in batches (for example by rowid range) in separate transactions after the server is ready, instead of one statement inside the startup transaction.
  • Consider not forcing temp_store = MEMORY while migrations run.

Impact

Blocks work completely

Version or commit

0.1.10-nightly.20261116.4787 (desktop, bundled server)

Environment

macOS 27.2.1, Apple M3 Max, 36 GB RAM, desktop app (Nightly), Local environment on

Logs or stack traces

server.trace.ndjson, second attempt (after reboot), local time
20:33:21  INSERT INTO effect_sql_migrations ... (95)
20:33:21  ALTER TABLE orchestration_v2_projection_turn_items ADD COLUMN inline_work_output ...
          (no further spans)
20:39     statev2.sqlite-wal stops growing at 16 GB
20:44     process: 200% CPU, footprint 15.2 GiB, disk read and write 0 MiB over 10 s

Workaround

Quit the app, make sure the backend has exited, then run migration 95 by hand in the sqlite3 CLI as above (same SQL, one transaction, temp_store = FILE), including the effect_sql_migrations row. Make sure there's free disk space of about twice the size of the rewritten rows first (WAL plus temp journal). The app then runs only migration 96 on the next launch.

Related issues

Activity

  1. lol2x commented on Nov 17, 2026

    @lol2x

    Same failure on Windows, still present in 0.1.11-nightly.20261117.4825

    Environment: Windows 11 Pro (10.0.26200) x64, 125.6 GB RAM, desktop app (Nightly) running its bundled local server. Version installed: 0.1.11-nightly.20261117.4825 (the latest nightly when this was written). Updated from 0.1.10-nightly.20261113.4630.

    Database: statev2.sqlite is 27.5 GB, and statev2.sqlite-wal is 16.7 GB after the failed attempts.

    Symptom difference from macOS: the backend does not hang. On Windows it exits by itself 3–5 minutes into migration 95 with exit code 4294930435 (0xFFFF7003). Its stderr only shows crashpad_client_win.cc:867] not connected, and the Windows Application event log has no crash entry. The desktop shell behaves as designed (backend is still migrating its database; waiting) and restarts the backend. Migration 95 then starts from scratch every time, so the app stays on the logo screen indefinitely.

    server-child.log (3 consecutive runs):

    migration: 95_TurnItemInlineWorkOutput  progress: 1 of 3
    [...crashpad_client_win.cc:867] not connected
    backend child process failure output end  code=4294930435
    

    The last span in server.trace.ndjson is the ALTER TABLE ... ADD COLUMN inline_work_output. No UPDATE/COMMIT span follows.

    Workaround confirmed on Windows: the manual sqlite3 run from the issue body (3.54.1, PRAGMA temp_store = FILE, app fully quit, DB backed up first) completed normally in one transaction. 65,816 rows were flagged, COMMIT succeeded, wal_checkpoint(TRUNCATE) shrank the WAL from 16.7 GB to 0, and quick_check returned ok. The migration head is now 95.

    Posted via t3 triage by Claude Code (Claude Opus 5.5).

  2. CountMyBands commented on Nov 21, 2026

    @CountMyBands

    Another Windows data point: migration 95 completed when left alone

    Environment: Windows 11 Pro (10.0.26200) x64, desktop app with its bundled local server. Last recorded server before the update was 0.1.10-nightly.20261114.4682. The exact nightly it updated to is unknown. The user then reinstalled, and the migration completed on stable 0.1.11.

    Database: statev2.sqlite is about 40 GB, with about 10 GB of that on the freelist.

    Symptom: logo-only window, /.well-known/t3/environment returning 503, and the server trace ending at the ALTER TABLE for inline_work_output. Reinstalling did not help because the database is kept. Attempts that were closed partway through rolled back, and migration 95 restarted on the next launch.

    Result: unlike the hang and crash reports above, the run completed without intervention:

    • Migration 95 took about 9.5 minutes (18:01:15 to 18:10:43 UTC).
    • Migrations 96 to 102 finished by 18:12:36 UTC, and the server returned 200 shortly after.
    • The desktop readiness check timed out at 180 s several times during the run, but the backend kept running.
    • About 8 minutes in, the backend had read 26.7 GB and written 2.5 GB, with a 2.7 GB WAL and a 2.7 GB working set.

    This suggests that at least some affected users are only blocked by the logo-only screen giving no sign that they should wait. A visible "upgrading database, don't quit" state would have prevented the restarts here, even before #37995 lands.

    Produced with t3 triage by Claude Code (Claude Opus 5.5).

  3. antoniooo12 commented on Nov 23, 2026

    @antoniooo12
    Contributor

    Linux data point: when 095 completes, the server keeps the memory afterwards

    Setup: a Linux server (32 cores) updated from 0.1.10-nightly.20261114.4682 to 0.1.11-nightly.20261119.4941. Its statev2.sqlite is 35.8 GB, and migration 95 matched 38,501 dynamic_tool rows holding 5.66 GB of payload. Here the migration finished, in about 4 minutes, but the server kept the memory it used:

    • During 095: RSS reached 5.7 GB. The journal shows 095 ran from 23:26:32 to 23:30:40, and a sample at 23:30:13 read 5,689 MB, before the server was listening.

    • Four days later: the server still holds about 6.2 GB, almost all of it in swap. It sits in 130 glibc thread-arena slots of 64 MiB each. The live JS heap is about 0.4 GB.

    • Replay on a copy of this database (node:sqlite in a worker thread, same statements):

      temp_store Peak RSS Held after COMMIT Temp file peak
      MEMORY 5,982 MiB 5,972 MiB, of which 1.5 MiB in use none
      FILE 95 MiB — 5.75 GB

      With MEMORY, malloc_trim(0) dropped RSS to 93 MiB, so the memory is freed but not returned to the OS.

    • Why it matters after the migration: the retained arena slows every child_process.spawn, because fork copies the page tables, swap entries included.

      • In a synthetic Node 26.13.1 process holding 6 GiB of freed worker-arena memory, T3-shaped spawn p50 was 84 ms resident, 53 ms swapped and 5 ms after malloc_trim(0). It was 0.4 ms at 0 GiB.
      • On the live server under similar load, spawn p50 went from about 30–65 ms before the update to about 220–490 ms after.

    So besides the hang on large databases, a migration 95 that completes still leaves the server several GB larger for as long as it runs.

    #37995 removes this for 095. In a 1.2 GB rewrite (40,000 × 30 KB rows), current main peaked at 1,532 MB, while #37995's per-row 095 peaked at 236–238 MB.

    The "Not in this change" note in #37995 still applies: any future large rewrite under temp_store = MEMORY on the writer worker leaves the same retained arena. Running migrations under temp_store = FILE capped the peak at 230–238 MB in the same test. It costs temp disk roughly equal to the rewritten size. If the temp directory is too small, startup then fails with SQLITE_FULL; the migration rolls back cleanly and the next start completes.

    Side note: the test "keeps a write transaction's statement journal off the temp directory" looks for etilqs_ file names. On Node 26.13.1 on Linux, SQLite opens the journal with O_TMPFILE, so the test still passes with PRAGMA temp_store = MEMORY removed.

    Measured with Claude Opus 5.5, GPT-6.2 Sol and Gemini 4 Neon in T3 Code.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions