Gate the autovacuum tuning on the dialect, not on SQLDatabase #209

Merged
paulhitt merged 1 commits from fix/autovacuum-dialect-guard into fix/user-data-autovacuum-gap 2026-09-14 21:22:20 +00:00
paulhitt commented 2026-09-14 20:55:04 +00:00 (Migrated from gitlab.com)

Targets fix/user-data-autovacuum-gap so the fix lands before !145 reaches main.

The bug

TuneUserDataAutovacuum guarded with database as? any SQLDatabase before running a PL/pgSQL DO block. SQLite conforms to SQLDatabase too, so the guard passed and SQLite received SQL it cannot parse:

[Migrator] Failed prepare [database-id: sqlite, error: error: near "DO": syntax error,
  migration: FlamenetRelay.TuneUserDataAutovacuum]
Fatal error: Error raised at top level

Fluent treats that as a failed migration and the process exits during boot, so the relay crash-loops. The three test relays on the box (relays-relay1/2/3-1) had 15 restarts each and could not boot at all.

This was not confined to test

messenger-relay-1 carries FN_DB=/data/relay.sqlite alongside FN_POSTGRES_URL, so it has a sqlite database-id registered. Merging !145 as-is would have crash-looped production the same way.

The fix

prepare and revert now share one helper that checks the dialect rather than the protocol.

I read both literals out of the resolved sources instead of assuming them, because a wrong string fails in the more dangerous direction: it would skip Postgres too, and the tuning would silently never apply with nothing to indicate it. PostgresDialect.name is "postgresql"; SQLiteDialect.name is "sqlite".

Tests

AutovacuumDialectTests.swift, four cases: the boot schema migrates cleanly on SQLite (the shape that broke), the migration alone is a no-op rather than an error there, the dialect literal is pinned, and the migration is still registered in the boot schema.

Verification

  • Swift Testing: 702 tests in 64 suites, passed.
  • XCTest: 57 tests, 0 failures.

Worth flagging for this repo: a plain swift test on this toolchain runs only the Swift Testing suites and reports Test run with 702 tests ... passed while silently skipping all 57 XCTest cases. The XCTest half needs --enable-xctest --disable-swift-testing. A green Swift Testing summary on its own is not a green suite.

Side note

CI already caught this: !145's pipeline is red, because the harness runs autoMigrate() on SQLite. What went wrong is that the red branch was deployed to the test relays anyway, where the crash loop and Swift's default backtracer (--unwind precise, 221s, 3-4 GB each) filled the box's RAM and swap and caused 18 OOM kills, including an unrelated CI build in another repo.

Targets `fix/user-data-autovacuum-gap` so the fix lands before !145 reaches `main`. ## The bug `TuneUserDataAutovacuum` guarded with `database as? any SQLDatabase` before running a PL/pgSQL `DO` block. **SQLite conforms to `SQLDatabase` too**, so the guard passed and SQLite received SQL it cannot parse: ``` [Migrator] Failed prepare [database-id: sqlite, error: error: near "DO": syntax error, migration: FlamenetRelay.TuneUserDataAutovacuum] Fatal error: Error raised at top level ``` Fluent treats that as a failed migration and the process exits during boot, so the relay crash-loops. The three test relays on the box (`relays-relay1/2/3-1`) had **15 restarts each** and could not boot at all. ## This was not confined to test `messenger-relay-1` carries `FN_DB=/data/relay.sqlite` alongside `FN_POSTGRES_URL`, so it has a sqlite database-id registered. Merging !145 as-is would have crash-looped **production** the same way. ## The fix `prepare` and `revert` now share one helper that checks the dialect rather than the protocol. I read both literals out of the resolved sources instead of assuming them, because a wrong string fails in the more dangerous direction: it would skip Postgres too, and the tuning would silently never apply with nothing to indicate it. `PostgresDialect.name` is `"postgresql"`; `SQLiteDialect.name` is `"sqlite"`. ## Tests `AutovacuumDialectTests.swift`, four cases: the boot schema migrates cleanly on SQLite (the shape that broke), the migration alone is a no-op rather than an error there, the dialect literal is pinned, and the migration is still registered in the boot schema. ## Verification - Swift Testing: **702 tests in 64 suites**, passed. - XCTest: **57 tests, 0 failures**. Worth flagging for this repo: a plain `swift test` on this toolchain runs only the Swift Testing suites and reports `Test run with 702 tests ... passed` while silently skipping all 57 XCTest cases. The XCTest half needs `--enable-xctest --disable-swift-testing`. A green Swift Testing summary on its own is not a green suite. ## Side note CI already caught this: !145's pipeline is red, because the harness runs `autoMigrate()` on SQLite. What went wrong is that the red branch was deployed to the test relays anyway, where the crash loop and Swift's default backtracer (`--unwind precise`, 221s, 3-4 GB each) filled the box's RAM and swap and caused 18 OOM kills, including an unrelated CI build in another repo.
paulhitt commented 2026-09-14 21:22:21 +00:00 (Migrated from gitlab.com)

mentioned in commit 65db60e5a5

mentioned in commit 65db60e5a5cffda539c797081dd3c507a96924d6
paulhitt (Migrated from gitlab.com) merged commit 65db60e5a5 into fix/user-data-autovacuum-gap 2026-09-14 21:22:21 +00:00
Sign in to join this conversation.