Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: Desktop app fails with `ServerAlreadyRunningError` when a leftover `server-runtime.json` refers to a process that is no longer T3 #21624

ClosedArzh42(GitHub profile, opens in a new tab) opened this issue 2 comments

Before submitting

  • I searched existing issues and did not find a duplicate. (searched 2026-10-19: no exact match; related: #19735, #20250, #16102)
  • I included enough detail to reproduce or investigate the problem.

Area: apps/server (desktop backend child)

Related (not duplicates): #19735 (WSL update leaves old server holding the lock), #20250 (desktop quits on ownership refusal, single-owner lock from #16102). Neither covers a legacy record without ownerId whose recorded process has been replaced by an unrelated one.

Steps to reproduce

  1. Have a server-runtime.json in the T3 data directory, left over from an older server that did not write ownerId, e.g.:
    {"version":1,"pid":<number>,"host":"127.0.0.1","port":3773,"origin":"http://127.0.0.1:3773","startedAt":"<older ISO timestamp>"}
    The recorded process has exited.
  2. Let that process ID be reused by an unrelated, long-running user process whose start time is later than startedAt.
  3. Make sure no process holds the ownership lock: BEGIN EXCLUSIVE on server-owner.sqlite succeeds from the shell.
  4. Launch the desktop app.

Expected behavior The stale legacy record is ignored (its server is gone, and the exclusive lock is free), the server starts, and the window opens normally.

Actual behavior The window opens in an error state. The backend child exits with code 78 on every launch:

ServerAlreadyRunningError: A T3 Code server already owns <data-dir>. Stop that server, or use a separate T3 home and pair with it, then retry. No server was stopped.

The same failure happens when the server is run headless with t3 serve --base-dir <copy of the data dir>. A fresh, empty base dir starts fine.

Impact: Blocks work completely (the app cannot start with the existing data dir).

Version or commit: T3 Code 0.1.0 (desktop, Linux x86_64, packaged as AppImage/t3code-bin)

Environment: Arch-based Linux, Hyprland (Wayland), Electron desktop app. Node runtime bundled with the app.

Logs or stack traces

[11:24:43.228] ERROR (#11): ServerAlreadyRunningError: A T3 Code server already owns <data-dir>. ...
    at acquireServerOwnership (.../apps/server/dist/binCli-*.mjs)

Relevant code path (from the 0.1.0 bundle, apps/server/dist/binCli-*.mjs):

  • acquireServerOwnership first takes the exclusive SQLite lock on server-owner.sqlite. That lock is free in this case.
  • It then reads server-runtime.json. If ownerId is undefined, it calls legacyOwnerIsLive(previous).
  • legacyOwnerIsLive returns true when ps -p <pid> -o lstart= exits non-zero: if (isNone(result) || result.value.code !== 0) return true;. So an unreadable start time is treated as "live", and the app refuses to start.

Observed while investigating (in a shell, not the app's own process environment): ps -p exited with status 1 for the recorded process ID, while /proc/<pid> existed and belonged to an unrelated process. I did not confirm that the app's ps invocation fails in exactly the same way.

Workaround that worked

  1. Quit T3 Code.
  2. Move the stale server-runtime.json out of the data directory, keeping a backup copy, e.g. mv server-runtime.json server-runtime.json.stale.
  3. Start T3 Code again. The server writes a fresh server-runtime.json with an ownerId, and the app opens normally with the existing data.

server-owner.sqlite is recreated empty on startup, so it does not need to be touched.

Suggested fix (for maintainers to decide)

  • If the exclusive SQLite lock is acquired, nothing else owns the data directory, so a legacy record with no ownerId should be treated as stale, not live.
  • Or: treat an unreadable start time (ps failure) as "not live" rather than "live".

Attachments: none (log excerpt above; redacted).

  1. Note

    Grok responding on behalf of Julius.

    This is intended. When a leftover server-runtime.json has no ownerId, the server treats it as live unless it can prove the PID was reused (serverOwnership.ts:51-83). If ps fails, it can't prove that, so it stays cautious and refuses to start (serverOwnership.ts:79). Holding the server-owner.sqlite lock doesn't settle it either: records without ownerId come from servers built before that lock existed, and those servers never take it. So a free lock doesn't mean no older server is running (serverOwnership.ts:131-139).

    Your workaround is the right fix. Quit T3 Code, move the stale server-runtime.json aside, and start again. The new server writes a record with an ownerId (serverOwnership.ts:141-144), so this check won't run again for that directory.

  2. juliusmarminge added labelsvia-triage

  3. juliusmarminge added labelswontfix

  4. juliusmarminge closed this

  5. Ok thanks for the answer I understand why you do it like that and the workaround is easy enough. Have a good day

Sign in to join this conversation.