codex icon indicating copy to clipboard operation
codex copied to clipboard

codex queue --resume cannot start a turn while an idle TUI holds the thread

Open mrgrue opened this issue 1 week ago • 4 comments

Summary

When a thread is open in an idle interactive TUI, codex queue --thread <id> --resume --message ... queues the message but cannot start a turn:

Warning: message was queued, but could not resume thread <id>: thread/resume failed: thread <id> already has an active writer (code -32600)
Queued message <msg-id> for thread <id>.

The idle TUI does not drain the daemon queue by itself. The queued message stays unread until someone types into the TUI or it starts a turn for another reason. If the TUI exits, the same codex queue --resume starts a background turn at once, and the agent reads the message.

Repro

  1. Start an interactive session (codex), let it finish a turn, and leave it idle at the prompt.
  2. From another shell, run codex queue --thread <that thread> --resume --message "hello".
  3. Observe the active-writer warning. The TUI stays idle and does not show or act on the message.
  4. Exit the TUI and run the same command again. A background turn starts and handles the message.

Expected

One of these:

  • an idle TUI picks up messages queued for its thread and starts a turn
  • resume can take over a writer that is idle

Versions

codex-cli 0.171.0, app-server daemon 0.172.0, macOS (arm64).

Context

We run several long-lived agent threads and message them with codex queue --resume. Workers left open in a TUI silently missed work until we moved them headless.

mrgrue avatar Nov 25 '26 22:11 mrgrue

Thanks for the clear repro. codex queue connects to the local daemon by default if it’s running. The warning means the daemon saved the message but couldn’t resume the thread because another writer held the lock. A writer can hold that lock even while the thread is idle.

Since exiting the TUI lets the daemon resume the thread, I suspect the TUI is running its own app-server. Are you launching codex with --no-daemon, possibly through a shell alias or wrapper? Is the same thread open in the desktop app?

You can check which process holds the lock on macOS. Right after the warning, leave the TUI open and run this in the shell where you ran codex queue:

thread_id='<thread UUID>'
lsof "${CODEX_HOME:-$HOME/.codex}/thread-writer-locks/$thread_id.lock"

If the process is listed as codex, run ps -ww -p <PID> -o pid,ppid,command with the PID from lsof. Please let us know whether it’s the TUI, a desktop-launched app-server, or the local daemon. No need to share the full command line.

etraut-openai avatar Nov 25 '26 23:11 etraut-openai

Thanks for the diagnosis. On macOS, I confirmed that both the installed CLI and the running local daemon report 0.172.0. In a separate test with an isolated 0.172.0 app-server and a mock model, I pointed both the idle TUI and codex queue at the same explicit Unix socket. Without --resume, one queued message started exactly one turn on the same thread UUID, without typing in or closing the TUI. The turn read a marker that wasn’t in the queued message.

That establishes the same-server case in this setup. It doesn’t identify the lock holder in the original report or establish that the default daemon and Desktop behave the same way.

murillodutt avatar Nov 28 '26 14:11 murillodutt

Additional macOS reproduction: Desktop app-server holds the thread writer (30 November 2026)

Following the request in the earlier maintainer comment to identify the lock-holding process, I checked the target thread on macOS.

  • Target thread: 01a225c9-cb14-77f0-b64a-092137dc4d8e
  • lsof showed the thread-writer lock held by PID 31432 (file descriptor 61u).
  • The process was the ChatGPT Desktop bundled Codex app-server; the thread metadata identified the session originator as Codex Desktop.
  • It was not the CLI codex exec resume process. A separate managed daemon was running under PID 32719, but it was not the process holding this target lock.
  • codex exec resume against this thread failed in about 5 seconds with already has an active writer, exit code 1, and event_lines=0.

This is a related writer-ownership reproduction, but not an exact reproduction of the codex queue --resume command in the issue: my failing command was codex exec resume. The important distinction requested by the earlier comment is that the lock holder was a Desktop-launched app-server, not the local managed daemon or the CLI resume process.

No process was killed and no lock file was deleted. Could you clarify whether Desktop's app-server is expected to retain a thread writer after a turn is complete/idle, and what supported handoff procedure should be used before resuming the same thread from CLI/TUI?

yumf24 avatar Nov 30 '26 14:11 yumf24

OK, thanks for confirming that it was the desktop app holding the lock. Then this is working as intended, and this isn't a bug.

We're looking at switching the desktop app to share the same app server daemon that TUI instances use. That will solve this problem and many similar problems, but it also creates other challenges that we need to work through before switching it over.

I'm going to close this issue since we've confirmed this isn't a bug.

etraut-openai avatar Nov 30 '26 21:11 etraut-openai