Skip to content

[Bug]: Codex provider probe permanently deadlocks when state_5.sqlite backfill_state is stuck in 'running' (20s probe timeout vs 30s Codex wait) #44629

Backlog

Description

@KissFeng

Area

apps/server

Summary

When codex app-server runs against a CODEX_HOME (such as a separate cockpit-home that symlinks ~/.codex/sessions and archived_sessions while keeping its own state_5.sqlite), a 20s-vs-30s deadlock can permanently lock the Codex provider in Unavailable:

  1. On initial probe with thousands of historical sessions (~3,000 in my case), codex app-server begins backfilling state_5.sqlite.
  2. If initial backfill takes longer than T3 Code's default 20s probe deadline (CODEX_AUTH_PROBE_TIMEOUT_MS in apps/server/src/provider/CodexProvider.ts), T3 Code terminates codex app-server mid-backfill.
  3. The killed process leaves backfill_state.status = 'running' in state_5.sqlite with partial progress (e.g., 1,642 / 3,006 threads indexed).
  4. On every subsequent status check or restart, codex app-server sees backfill_state.status = 'running' and blocks for up to 30 seconds before retrying startup initialization (state db backfill is running at <home>; waiting up to 30s before retrying startup initialization).
  5. T3 Code kills it again at 20 seconds, so Codex never reaches its 30s retry window and the provider stays permanently Unavailable.

Relation to existing issues/PRs

Steps to reproduce

  1. Have a CODEX_HOME with a state_5.sqlite whose backfill_state.status is left at 'running' while no codex app-server process is running (naturally triggered when initial backfill of thousands of symlinked sessions exceeds the 20s probe timeout and gets killed).
  2. Open Settings → Providers → Codex (or restart T3 Code) to trigger checkCodexProviderStatus.

Expected behavior

Codex provider status checks should not permanently deadlock on a stale backfill_state = 'running' lock caused by a killed probe, and when codex app-server reports that state db backfill is running, T3 Code should allow it to recover / complete rather than repeatedly killing it at 20s before Codex's 30s retry window.

Actual behavior

T3 Code repeatedly reports:

Timed out while checking Codex app-server provider status.

Every probe is killed at 20s while codex app-server is waiting up to 30s on the stale backfill claim, so the provider never recovers even after restarting T3 Code. Running codex directly against ~/.codex works immediately.

Impact

Blocks work completely

Version or commit

0.1.12 (also verified on main: CODEX_AUTH_PROBE_TIMEOUT_MS = 20_000 in apps/server/src/provider/CodexProvider.ts)

Environment

macOS 27.2.1 (26B131), Node v22.22.2, codex-cli 0.172.0, T3 Code 0.1.12, ChatGPT Pro

Logs or stack traces

# T3 Code UI / provider status error
Timed out while checking Codex app-server provider status.

# Codex app-server stderr when running manually against cockpit-home
state db backfill is running at ~/.t3/userdata/providers/codex/codex/cockpit-home; waiting up to 30s before retrying startup initialization

# SQLite state observed before recovery
sqlite> SELECT * FROM backfill_state;
-- status = 'running' (stuck), with no codex app-server process running
sqlite> SELECT count(*) FROM threads;
-- 1642 (vs 3006 in ~/.codex/state_5.sqlite where status = 'complete')

Workaround

  1. Confirm no codex app-server process is running against that CODEX_HOME.
  2. Back up state_5.sqlite using sqlite3 "$DB" ".backup '${DB}.bak'".
  3. Reset the stale claim: UPDATE backfill_state SET status = 'pending', updated_at = 0 WHERE id = 1;.
  4. Run CODEX_HOME="$COCKPIT_HOME" codex app-server directly outside T3 Code until backfill_state.status becomes 'complete' (took 10.90s to finish the remaining sessions).
  5. Refresh the Codex provider in T3 Code; initialize then returns in ~0.05s and the provider immediately becomes ready.
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