Skip to content

Add codex send to deliver a message to a running session without waiting for its turn to end - #18

Open
astral303 wants to merge 1 commit into
qol/persistent-task-listfrom
qol/ipc-send
Open

astral303 wants to merge 1 commit into
qol/persistent-task-listfrom
qol/ipc-send

Conversation

@astral303

@astral303 astral303 commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

The change

A message can now be delivered to a running Codex TUI session while it is working. codex queue only delivers after the recipient's current turn ends, so an agent that wants to tell another agent something had to wait for that agent to go idle.

After this change

codex send --thread 01a05483-980f-7f13-80a8-a6efb95dd407 --message "Ghidra is available. You can acquire the lock."

The recipient treats the text as typed into its composer and submitted with Enter: a running turn is steered, an idle session starts a turn. The command prints Delivered message to thread … when the text entered the turn pipeline and … accepted the message and will submit it when it can take input when the session held it in its follow-up queue. A thread with no live session, or one that opted out, exits 1 with no live session is listening for thread ….

Every session listens by default. Opt out with:

[ipc]
enabled = false

Mechanism

  • Each TUI session binds $CODEX_HOME/ipc/<thread-id>.sock (new crate codex-send, on codex_uds, so Windows uses the same AF_UNIX path). The directory is owner-only and the socket is 0600 on Unix. A socket that still answers a connection belongs to another live session and is not replaced; one that does not answer is stale and is removed. The socket moves with the primary thread and is removed on exit.
  • One JSON line each way: {"id","text"} in, {"result":"submitted"|"queued"|"rejected"} out. Connections are served one at a time, so concurrent senders are submitted in arrival order; a connection that sends nothing for 5 seconds is closed. A repeated id within the session's last 64 requests returns the original result without a second submission.
  • The TUI runs the text through the same gate as the composer's Enter key (submit_or_queue_user_message). Steer versus start, the turn-transition race, and retention during /review or /compact are the app layer's existing turn/steer fallback to turn/start and its rejected-steer queue; no new state machine. Sent text is delivered as plain text in both the submit and the queued path: ! and / prefixes are not interpreted.
  • A sent message leaves the model's pending questions in place. A typed prompt clears them as the user moving on to new work; sent messages carry UserMessageSource::SentMessage, which skips that clear in both paths.
  • A message is rejected with the session is displaying another thread while /agents or /multi-agents shows a subagent thread: the chat widget submits to the displayed thread, not to the endpoint's thread. Queued messages live in the primary thread's input state, which is stored on a view switch and restored on return.

Limitations

  • --thread takes a UUID. Session names would require an app-server lookup, which the command avoids.
  • Unix socket paths are limited to about 104 bytes on macOS; a long CODEX_HOME disables the endpoint with a logged error.
  • A sender inside a Codex sandbox with network disabled needs $CODEX_HOME/ipc in that sandbox's unix_sockets allowlist.
  • Any process running as the same OS user can send; the socket is not a privilege boundary within the account, the same boundary as codex queue and the app-server daemon socket.

Validation

  • Crate tests: socket round trip and lifecycle (multiline text, missing, stale, live, and silent connections).
  • Chat widget tests: submit-versus-queue outcomes, duplicate ids, ! and / text staying plain in both paths, pending questions surviving a sent message.
  • App tests: the endpoint moves with the primary thread, survives a same-thread rebind, is removed on reset, and is not bound when [ipc] is disabled; a message is rejected while a subagent thread is displayed.
  • Live macOS run: send to an idle and then a working session, model reply received, socket removed on /quit.
  • Windows smoke test by hand: all eight steps in codex-rs/send/README.md pass (socket created, idle and working recipient, /review, multiline text, cleanup on /quit, opt-out).

@astral303

Copy link
Copy Markdown
Owner Author

This implements openai#15355.

@astral303
astral303 force-pushed the qol/persistent-task-list branch from 204e97b to 264f69a Compare October 19, 2026 16:23
@astral303
astral303 force-pushed the qol/persistent-task-list branch from 264f69a to 6ea0ffe Compare October 26, 2026 22:10
@astral303
astral303 force-pushed the qol/ipc-send branch 2 times, most recently from b467a54 to d058d4d Compare October 28, 2026 01:43
@astral303
astral303 force-pushed the qol/persistent-task-list branch 2 times, most recently from fa81090 to a5bd886 Compare October 30, 2026 23:30
@astral303
astral303 force-pushed the qol/ipc-send branch 2 times, most recently from 52a5030 to 84653c0 Compare October 31, 2026 00:38
@astral303
astral303 force-pushed the qol/persistent-task-list branch from a5bd886 to 7396174 Compare October 31, 2026 00:38
@astral303
astral303 force-pushed the qol/persistent-task-list branch from 7396174 to 1bf7c3e Compare October 31, 2026 00:53
@astral303
astral303 force-pushed the qol/persistent-task-list branch from 1bf7c3e to 088f9e7 Compare November 1, 2026 01:54
@astral303
astral303 force-pushed the qol/persistent-task-list branch from 088f9e7 to 7ee5671 Compare November 19, 2026 06:15
@astral303
astral303 force-pushed the qol/ipc-send branch 2 times, most recently from 14f76ff to 5ffecaf Compare November 20, 2026 08:17
@astral303
astral303 force-pushed the qol/persistent-task-list branch from 7ee5671 to 23737ad Compare November 20, 2026 08:17
`codex send --thread <uuid> --message <text>` steers the recipient's
active turn or starts a new one, as Enter in its composer would. A sender
that wants to steer the active turn needs a direct endpoint: `codex queue`
writes a SQLite row that the recipient polls every 10 s and dispatches
when idle.

- Each TUI session binds `$CODEX_HOME/ipc/<thread-id>.sock` (new crate
  `codex-send`, on `codex_uds`) while it owns its primary thread. A socket
  that still answers a connection belongs to another live session and is
  not replaced; a socket that does not answer is stale and is replaced.
  Rebinding the same thread waits for the previous task's cleanup so the
  two cannot race on one path. `[ipc] enabled = false` opts out.
- A received message takes the composer's Enter gate,
  `submit_or_queue_user_message`: submitted now when the session takes
  input, otherwise held in the local follow-up queue, and the reply
  reports which. Steer versus start, the turn-transition race, and
  retention during `/review` or `/compact` are the app layer's existing
  `turn/steer` fallback to `turn/start` and its rejected-steer queue.
- A message is rejected while the session displays a subagent thread
  (`/agents`, `/multi-agents`): the chat widget submits to the displayed
  thread, not to the endpoint's thread.
- Sent text is delivered as a plain user message in both paths: queued
  text is stored as `Literal` so a drained `!` prefix is not run as a
  shell command. It carries `UserMessageSource::SentMessage`, which leaves
  the model's pending questions in place; a typed prompt clears them as
  the user moving on to new work. A repeated request id within the session's last 64
  requests returns the original result without a second submission.
- Connections are served one at a time so concurrent senders are
  submitted in arrival order; a silent connection is closed after 5 s so
  it cannot hold the accept loop.
- Tests cover the socket round trip and lifecycle (multiline text,
  missing, stale, live, and silent connections), submit-versus-queue
  outcomes with `!` and `/` text staying plain in both paths, duplicate
  ids, pending questions surviving a sent message in the submit, steer,
  and drained-queue paths, rejection while a subagent thread is displayed, the endpoint
  moving with the primary thread and surviving a same-thread rebind, and
  the `[ipc]` opt-out.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant