HKUDS/Vibe-Trading · error · RuntimeError

No supported file-lock backend for Codex OAuth refresh

Error message

No supported file-lock backend for Codex OAuth refresh

What it means

_lock_token_file provides cross-process locking for Codex OAuth refresh using fcntl (POSIX) or msvcrt (Windows); if neither module is available, no file-lock backend exists and refresh cannot be safely serialized, so it raises.

Source

Thrown at agent/src/providers/openai_codex.py:142

    except OSError:
        pass


def _lock_token_file(handle: Any) -> None:
    """Acquire a cross-process lock on an opened token lock file."""
    if fcntl is not None:
        fcntl.flock(handle.fileno(), fcntl.LOCK_EX)
        return
    if msvcrt is not None:  # pragma: no cover - exercised with a platform mock.
        handle.seek(0, os.SEEK_END)
        if handle.tell() == 0:
            handle.write(b"\0")
            handle.flush()
            os.fsync(handle.fileno())
        handle.seek(0)
        msvcrt.locking(handle.fileno(), msvcrt.LK_LOCK, 1)
        return
    raise RuntimeError("No supported file-lock backend for Codex OAuth refresh")


def _unlock_token_file(handle: Any) -> None:
    """Release the lock acquired by :func:`_lock_token_file`."""
    if fcntl is not None:
        fcntl.flock(handle.fileno(), fcntl.LOCK_UN)
        return
    if msvcrt is not None:  # pragma: no cover - exercised with a platform mock.
        handle.seek(0)
        msvcrt.locking(handle.fileno(), msvcrt.LK_UNLCK, 1)


@contextmanager
def _codex_refresh_lock(storage: Any) -> Iterator[None]:
    """Serialize refresh-token rotation across threads and processes."""
    lock_path = storage.get_token_path().with_name(f"{storage.get_token_path().name}.lock")
    lock_path.parent.mkdir(parents=True, exist_ok=True)
    with _TOKEN_REFRESH_THREAD_LOCK:

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Run on a standard CPython build for your OS (Linux/macOS provide fcntl; Windows provides msvcrt)
  2. If in a sandbox, grant the runtime access to real file-locking syscalls
  3. Check diagnostics: python -c "import fcntl" / python -c "import msvcrt" and switch runtime accordingly
Defensive patterns

Strategy: validation

Validate before calling

import sys
if sys.platform not in ('linux', 'darwin', 'win32'):
    raise SystemExit('Codex OAuth refresh requires a platform with fcntl or msvcrt')

Prevention

When it happens

Trigger: Running on a platform where both fcntl and msvcrt are None (e.g. some restricted WASM/embedded/non-standard Python builds) during a Codex token refresh that needs the lock.

Common situations: Exotic or sandboxed Python runtimes without OS locking primitives; a stubbed-out platform layer in tests; Python builds for platforms lacking fcntl support.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/7c84c5222c2d90f9. Report an issue: GitHub.