tui: "Data migration failed" toast on every launch when the server returns 503 during boot
Summary
Every time the TUI launches, it shows a red toast titled "Data migration failed" for 10 seconds, even though no migration is pending and the database is fully migrated. The migration status poll fires once, 1 second after mount, and any non-2xx response is treated as fatal instead of being retried. Because the server answers 503 Service Unavailable for the first ~13 seconds of boot, the poll reliably lands inside that window and the user is told their data migration failed.
Environment
- opencode version: 2.3.0
- OS: Linux TEOHVPS-1 7.0.0-1015-oracle #16-Ubuntu SMP (aarch64)
- Terminal: TERM=xterm-256color, COLORTERM unset
- Shell: /bin/bash
- Install/channel: latest (standalone binary at ~/.opencode/bin/opencode, launched via a wrapper that exports provider env vars)
- Active plugins: none (
"plugin": [])
Reproduction
- Launch the TUI with
opencodeon a data directory that already completed all migrations (in this case 59 rows in themigrationtable, all withtime_completedset). - The CLI spawns
opencode serve --serviceand the TUI mounts immediately. - Observe the toast "Data migration failed" roughly 1 second after launch, lasting 10 seconds.
GET /api/experimental/migration/v1returns{"status":"completed"}once the server finishes booting, and no subsequent toast appears for that session.
Expected Behavior
The migration status check should retry on transient transport failures (503 / connection refused) while the server is still booting, and should only surface an error when the endpoint reports status: "error" or when retries are exhausted after the server is reachable.
Actual Behavior
Server log for a single launch:
08:57:00.168 GET /api/info 503
08:57:00.295 GET /api/info 503
08:57:13.554 GET /api/model 503 (span 9368ms)
08:57:13.607 GET /api/provider 503 (span 9417ms)
So the HTTP listener is bound before services are ready and returns 503 for roughly the first 13 seconds.
The TUI code path behaves like this (reconstructed from the bundled client):
await Bun.sleep(1000)
while (true) {
const w = await api.experimental.migration.v1.status({ signal })
if (w.status === "running") showProgress(w.progress)
if (w.status === "completed") return
if (w.status === "error") throw Error(w.error)
await Bun.sleep(1000)
}
// .catch(...) => toast({ variant: "error", title: "Data migration failed", duration: 10000 })
The catch is attached to the whole loop, so the first thrown HTTP error exits the loop permanently and is rendered as a migration failure. Any 503, 401 or network error during boot produces a false "Data migration failed" message, and there is no retry.
Additional Context
Evidence that this is a client-side false positive and not a real migration problem:
migrationtable contains 59 rows, all with a non-nulltime_completed; newest id20261030054400_job.PRAGMA integrity_checkreturnsok.- Only v2 tables are present (
session_v2,session_message,session_part,session_inbox); no v1 tables remain. - The strings
database migration failedandV1 migration failedexist in the binary but never appear in the 36 MB debug log across the whole install lifetime. - Earlier occurrences of the same failure line up with the same boot window:
GET /api/experimental/migration/v1returned 503 on 2026-10-26T01:43 and 2026-11-17T04:48.
Suggested fix, either is sufficient:
- Wrap the individual
status()call in a retry that tolerates5xxand network errors for a bounded period (for example 30 to 60 seconds) before giving up, and only raise when the endpoint itself returnsstatus: "error". - Do not poll at a fixed 1 second offset. Wait for
/api/infoto succeed (or for a health200) before the first migration status request.
Secondary observation, may be related to the same readiness gate: /api/model and /api/provider also return 503 during this window, and the first successful responses land around 13 to 15 seconds after launch, which suggests the provider and model catalog loading blocks readiness more than the migration check.
Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.
Thanks for the detailed report. I reproduced this on 2.3.0, and it still happens on the latest dev (22377659a).
What I did: I started the TUI on a fresh project with no pending migration. Right after it came up, I made the server unreachable for about 3 seconds, so its single migration status check (about 1 s after launch) failed. I used a simulated network drop in place of the 503 the server returns while booting; I did not reproduce your slow boot itself. The TUI showed the red Data migration failed toast (Transport: ... socket connection was closed unexpectedly) and never checked again once the server was reachable. The recording and screenshots below show this, and the script below reproduces it.
This matches your reading of packages/tui/src/component/migration-overlay.tsx: one .catch wraps the whole polling loop, so the first failed request ends polling and is shown as a migration failure. Before it is ready, the server answers 503 service_starting for every route except /api/info, so a 503 during boot takes the same path.
Related: #56155 asked for the same retry and was closed for lack of a real case; this report is one.
https://github.com/user-attachments/assets/49cb2f36-eac1-46c9-a159-e4c6631d500b
Reproduction script (drive.ts)
// Reproduces #64621: a single failed migration-status poll right after the TUI
// mounts (here: the server briefly unreachable, standing in for the 503 the
// server sends while it is still booting) shows "Data migration failed" on a
// database with no pending migration, and polling never resumes.
import { Effect } from "effect"
import { OpenCodeDriver } from "opencode-drive"
export default OpenCodeDriver.use(
{
...(process.env.OC_DEV ? { opencode: { dev: process.env.OC_DEV } } : {}),
network: true,
tui: { recording: true },
},
({ ui, network, tui }) =>
Effect.gen(function* () {
// The TUI polls GET /api/experimental/migration/v1 once, ~1s after mount.
// Make the server unreachable for that first poll only.
yield* network.set({ refuseNew: true })
yield* network.killConnections()
yield* tui.recording!.mark("server unreachable for ~3s")
yield* Effect.sleep("3 seconds")
yield* network.clear()
yield* tui.recording!.mark("server reachable again")
yield* ui.waitFor("Data migration failed", { timeout: 10_000 } as any)
yield* ui.screenshot("migration-failed-toast")
yield* Effect.sleep("2 seconds")
}),
)
Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.
Hi, I'd like to work on this if it's available.
I'll first reproduce the startup failure on dev, then add bounded retries for temporary 503 and connection errors while still reporting actual migration failures immediately. I'll also add regression tests for recovery, retry timeout, and cancellation.
Does this approach sound reasonable? If so, could you assign this issue to me?
Hi @xun082 , feel free to divide the work; even if small, happy to contribute 🙂
Real-world data from an affected host (no simulation)
Adding field evidence to this thread, since the reproduction above used a simulated network drop. On the host where I first hit this, the server itself returned the 503, so the failure path is the production one.
Server log (~/.local/share/opencode/log/opencode.log), one launch on 2026-11-18:
08:57:00.168 GET /api/info 503
08:57:00.295 GET /api/info 503
08:57:13.554 GET /api/model 503 (span 9368ms)
08:57:13.607 GET /api/provider 503 (span 9417ms)
And on the endpoint in question, from the same log:
2026-10-26T01:43:12.278 GET /api/experimental/migration/v1 503
2026-11-17T04:48:15.656 GET /api/experimental/migration/v1 503
So this is not only reachable by making the server unreachable. During boot the server answers 503 to the migration status endpoint on its own, and the toast fires.
The toast is a false positive on that host
State of the database the toast was complaining about at the time:
migrationtable: 59 rows, every one with a non-nulltime_completed(now 62 after the 2.3.2 automation migrations).PRAGMA integrity_checkreturnsok.- Only v2 tables present (
session_v2,session_message,session_part,session_inbox), no v1 tables. - The server log contains zero occurrences of
database migration failedorV1 migration failedacross its entire 36 MB history, and zero occurrences oflevel=ERRORmentioning a migration.
In other words the report says "migration failed" on a database that had nothing left to migrate.
Still present in 2.3.2
I auto-upgraded to 2.3.2 while this was open, so I checked the shipped bundle. The polling code is unchanged, there is still no retry, and the single .catch still wraps the whole loop. Unminified from the 2.3.2 binary:
function ms() {
let r = dr(), u = wo(), m = Be(), [f, p] = J(), b = new AbortController();
ho(async () => {
await Bun.sleep(1000),
(async () => {
while (!0) {
let w = await r.api.experimental.migration.v1.status({ signal: b.signal });
if (p(w.status === "running" ? w.progress : void 0), w.status === "completed") return;
if (w.status === "error") throw Error(w.error);
await Bun.sleep(1000);
}
})().catch((w) => {
if (b.signal.aborted) return;
p(void 0), u.show({ variant: "error", title: "Data migration failed", message: ro(w), duration: 1e4 });
});
}), _e(() => b.abort());
...
}
The 2.3.0 bundle I hit first is logically identical, so the fix is still needed on the release channel, not only on dev.
New finding: the length of the 503 window is driven by the model catalog load
This is the part that makes the bug look intermittent, and it may be worth covering in the fix.
The readiness gate stays closed for as long as the models.dev catalog is being loaded. On a cold catalog the window is about 13 seconds, and /api/model and /api/provider each hold the gate for roughly 9.4 seconds:
08:57:13.554 GET /api/model 503 (span 9368ms)
08:57:13.607 GET /api/provider 503 (span 9417ms)
On a launch with a warm catalog cache, the same host produced exactly one 503 (the initial /api/info probe) and the migration status request was never even reached, so no toast appeared:
10:58:04.435 GET /api/info 503 <- only 503 in the whole launch
So the toast frequency tracks catalog refresh rather than launches. That explains why some users see it every time (cold or expired catalog, first launch of the day, slow network) and others never see it (warm cache).
Two consequences worth separating:
- For the roughly 13 seconds that the gate is closed, the TUI has no models and no providers available, because
/api/modeland/api/providerreturn the same 503. That looks like a separate UX problem to me, but it is the same gate. - A second reproduction lever for testing, no network simulation needed: clear the
models-dev:v2:catalogentry from thekvtable to force a cold catalog, and the window reopens to its full width on a real server.
Suggested shape of the fix
Any of these would remove the false positive, and they compose well:
- Treat the boot 503 as retryable inside the polling loop instead of letting it escape to the outer
.catch. Retry with a bounded budget (30 to 60 seconds is generous for a readiness gate) and only raise the toast when the endpoint reportsstatus: "error"or the budget is exhausted while the server is reachable. - Do not start the poll at a fixed 1 second offset. Gate the first request on the server being reachable (the readiness probe is the natural signal), then poll.
- As a safety net, distinguish "the endpoint failed" from "the migration failed". The current code conflates a transport error with a migration error, and the toast title asserts the latter.
Thanks @xun082 for picking this up, and @amrsorne for the nudge. Happy to test a build once there is one, I can reproduce on a real server reliably by forcing a cold catalog.
Thanks for the cold-catalog details, @piemanny, and for offering to help, @amrsorne. I opened draft PR #64670.
I reproduced the false toast on dev with a local HTTP server returning a startup 503. With the patch, the TUI retries 503s and connection errors. After 30 seconds without a status response, it reports that the status check timed out. An explicit migration failure still shows up immediately.
The regression tests cover recovery, timeout, and cancellation. If you get a chance to try the PR branch against your cold-catalog setup, I’d appreciate hearing whether it fixes the false toast there too.