Skip to content

fix(station-host): use 5000 ms SQLite busy_timeout for foreground host writes - #10468

Merged
CommaBot merged 1 commit into
mainfrom
fix/host-sessions-db-busy-timeout
Dec 6, 2026
Merged

CommaBot merged 1 commit into
mainfrom
fix/host-sessions-db-busy-timeout

Conversation

@CommaBot

@CommaBot CommaBot commented Dec 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

station-host CI failed in pion/station-host/tests/uploads.mjs:76 (500 !== 200, database is locked) on POST /admin-api/sessions 0.46 s after startup (job 145895759915).

Root Cause

  • pion/station-host/host_sessions/src/app.pion hardcoded sql_db::Db::attach(path, 250) (250 ms busy_timeout), and actor.pion / turns.pion (SessionEngine::store) execute foreground writes (open_local, message, set_thread_title, startTurnFor, endTurn, etc.) directly on engine.app.gen().resources.db without a SQLITE_BUSY retry loop (unlike #remote/#jobs actors in remote.pion that go through sessions_actors::local_store_retry_k).
  • Immediately after startup, background threads (UsageCounter::serve running counter_schema, ReadIndexBuilder, run_usage_maintenance, run_remote_runs_backfill) touch stillfail.db. Under parallel CI runner load (5 concurrent host_main processes in Phase 3), a background write lock held past 250 ms caused open_local's db.tx(...) to fail with SQLITE_BUSY and return HTTP 500 database is locked.
  • Two foreground write paths in host_main/src/admin_parts.pion (save_profile_check and /parts/hub/newSession) also used sql_db::Db::attach with the default 250 ms timeout.

Fix

  • pion/station-host/host_sessions/src/app.pion: Extract HOST_DB_BUSY_TIMEOUT_MS = 5000 and attach_host_db(path) to match Node station/src/store/store.ts (5000 ms) and the other foreground/helper stillfail.db connections across station-host (host_devices, host_upkeep, host_vault, transcript_usage, etc.). Stays below ActorWatch's 8 s stop-enter and 10 s stall thresholds; non-blocking ticks (actor_card_tick) continue using station_store::try_now_db (PRAGMA busy_timeout = 0).
  • pion/station-host/host_main/src/admin_parts.pion: Pass wait_ms=5000 to the two foreground stillfail.db write attachments.
  • pion/station-host/host_sessions/src/app_test.pion: Unit test verifying attach_host_db sets PRAGMA busy_timeout = 5000.
  • pion/station-host/tests/uploads.mjs: Real-binary regression test holding BEGIN IMMEDIATE for 400 ms (> former 250 ms timeout) while POST /admin-api/sessions runs, asserting it waits and returns 200.

Verification

  • pionc fmt --check on modified Pion files (app.pion, app_test.pion, admin_parts.pion)
  • node --check pion/station-host/tests/uploads.mjs
  • Independent Opus 5.5 review: APPROVE (0 P0 / 0 P1)
  • Full pion-station-main CI (station-host, station-host-e2e, station-host-macos, including member-reads.test.ts and overview-workspaces.test.ts handover-lock tests)

Model: Gemini 4 Neon (agy) + independent Opus 5.5 review; test frameworks: pionc test, Node node:assert / uploads.mjs.

…t writes

In `pion/station-host`, `host_sessions` borrowed `engine.app.gen().resources.db`
from `app.pion`, where `attach_db` hardcoded a `250 ms` `busy_timeout`. Unlike
`sessions_actors`'s `store_k` (which retries `SQLITE_BUSY` with exponential
backoff), `host_sessions`'s foreground handlers (`open_local`, `message`,
`set_thread_title`, `SessionEngine::store`, etc.) run directly on this
connection without retry. Under concurrent background SQLite writers on
startup (`UsageCounter::serve` running `counter_schema`, `ReadIndexBuilder`,
`run_usage_maintenance`, `run_remote_runs_backfill`), `POST /admin-api/sessions`
returned HTTP 500 `database is locked` in CI (`station-host` `uploads.mjs:76`).

Match Node `station/src/store/store.ts` and the rest of `station-host` by
attaching the foreground `host_sessions` connection (and the two write paths in
`host_main/src/admin_parts.pion`) with `wait_ms = 5000`. Non-blocking actor
ticks (`actor_card_tick`) already override `busy_timeout` to `0` via
`station_store::try_now_db`.

Add a unit test verifying `attach_host_db` sets `PRAGMA busy_timeout = 5000`
and a real-binary regression check in `pion/station-host/tests/uploads.mjs`
holding `BEGIN IMMEDIATE` for 400 ms while `POST /admin-api/sessions` runs.

Co-authored-by: zuozijian <26162189+zuozijian@users.noreply.github.com>
@CommaBot
CommaBot merged commit 1d68f28 into main Dec 6, 2026
81 checks passed
@CommaBot
CommaBot deleted the fix/host-sessions-db-busy-timeout branch December 6, 2026 01:29
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.

2 participants