Repository navigation
Description
What variant of Codex are you using?
Codex CLI with the managed app-server daemon/proxy (codex-cli 0.145.0) on Linux. A separate read-only monitoring client connects to that daemon over the documented app-server protocol.
What feature would you like to see?
Please expose a supported, read-only way for an app-server client to distinguish:
- a thread that is loaded because an interactive client such as the Codex TUI is currently attached; and
- a thread that remains loaded only as warm runtime state after its last interactive client unsubscribed or disconnected.
A privacy-preserving API could expose aggregate presence only, for example:
{
"threadId": "…",
"subscriberCount": 2,
"interactiveSubscriberCount": 1
}This could be a new thread/presence/list method, optional presence fields on an existing thread metadata response, or another shape the maintainers prefer. A thread/presence/changed notification would be useful, but polling a supported read API would be sufficient.
If client kinds can be derived safely from initialization metadata, counts by broad kind (tui, desktop, remote-control, observer, other) would let an observer answer whether a TUI is still attached without exposing connection IDs. If client-kind classification is not appropriate, even a supported zero-versus-nonzero subscriber count would address the core loaded-versus-attached ambiguity for observers that unsubscribe their own connection.
Additional information
Reproduction
- Start a Codex TUI connected to the managed daemon. A new thread is created and loaded.
- Use
/resumeto continue a previously stored thread. - From a separate initialized app-server connection, call
thread/loaded/listand read metadata for the returned threads. - Both the unused startup thread and the resumed thread can remain loaded and report an idle runtime status.
- Close the TUI. The resumed idle thread can remain in
thread/loaded/listduring the no-subscriber inactivity grace period.
The public protocol exposes the loaded/runtime state, but not whether another interactive client remains subscribed. Therefore idle cannot be interpreted as “ready in an open terminal.”
The desired behavior is not to unload threads immediately or remove the grace period. The requested presence value should simply change promptly when a TUI switches threads, unsubscribes, or disconnects, while the underlying zero-subscriber thread may remain loaded as today.
Why this matters
Read-only integrations such as status bars, accessibility tools, monitoring dashboards, and physical indicators need to answer questions like:
- How many Codex terminals are currently waiting for a prompt?
- Which attached thread is working or waiting for approval/input?
- Did
/resumereplace the unused startup thread in the terminal? - Did the user close the terminal, even though Codex retained its runtime state?
Without a supported presence signal, integrations must guess using private SQLite/rollout formats, process working directories, file modification times, or recency heuristics. Those approaches are fragile across frequent Codex releases and ambiguous when multiple TUI sessions share a working directory.
This feature would also let clients avoid accidentally treating a persisted or warm-cached thread as an active user-facing session.
Non-goals
This request does not require:
- reading transcript content;
- attaching to, steering, or starting turns;
- receiving or answering approvals;
- exposing connection IDs or other client-sensitive metadata;
- changing the existing unload grace period;
- installing a helper or interposing a relay between the TUI and daemon.
It is only a request for aggregate, read-only presence associated with already-loaded threads.
Implementation context
In the 0.145.0 source, app-server already appears to maintain per-thread connection membership internally (connection_ids and thread_ids_by_connection):
codex/codex-rs/app-server/src/thread_state.rs
Lines 283 to 365 in 25af12f
| #[derive(Default)] | |
| struct ThreadStateManagerInner { | |
| live_connections: HashMap<ConnectionId, ConnectionCapabilities>, | |
| threads: HashMap<ThreadId, ThreadEntry>, | |
| thread_ids_by_connection: HashMap<ConnectionId, HashSet<ThreadId>>, | |
| } | |
| #[derive(Clone, Copy, Default)] | |
| pub(crate) struct ConnectionCapabilities { | |
| pub(crate) request_attestation: bool, | |
| } | |
| #[derive(Clone, Default)] | |
| pub(crate) struct ThreadStateManager { | |
| state: Arc<Mutex<ThreadStateManagerInner>>, | |
| // Extension event sinks are synchronous, so they need an await-free way to | |
| // enqueue work on the active per-thread listener. | |
| listener_commands: | |
| Arc<StdMutex<HashMap<ThreadId, mpsc::UnboundedSender<ThreadListenerCommand>>>>, | |
| } | |
| impl ThreadStateManager { | |
| pub(crate) fn new() -> Self { | |
| Self::default() | |
| } | |
| pub(crate) async fn connection_initialized( | |
| &self, | |
| connection_id: ConnectionId, | |
| capabilities: ConnectionCapabilities, | |
| ) { | |
| self.state | |
| .lock() | |
| .await | |
| .live_connections | |
| .insert(connection_id, capabilities); | |
| } | |
| pub(crate) async fn first_attestation_capable_connection_for_thread( | |
| &self, | |
| thread_id: ThreadId, | |
| ) -> Option<ConnectionId> { | |
| let state = self.state.lock().await; | |
| state | |
| .threads | |
| .get(&thread_id)? | |
| .connection_ids | |
| .iter() | |
| .filter_map(|connection_id| { | |
| state | |
| .live_connections | |
| .get(connection_id)? | |
| .request_attestation | |
| .then_some(*connection_id) | |
| }) | |
| .min_by_key(|connection_id| connection_id.0) | |
| } | |
| pub(crate) async fn wait_for_thread_subscriber(&self, thread_id: ThreadId) { | |
| let mut has_connections = { | |
| let mut state = self.state.lock().await; | |
| state | |
| .threads | |
| .entry(thread_id) | |
| .or_default() | |
| .has_connections_watcher | |
| .subscribe() | |
| }; | |
| while !*has_connections.borrow_and_update() { | |
| if has_connections.changed().await.is_err() { | |
| break; | |
| } | |
| } | |
| } | |
| pub(crate) async fn subscribed_connection_ids(&self, thread_id: ThreadId) -> Vec<ConnectionId> { | |
| let state = self.state.lock().await; | |
| state | |
| .threads | |
| .get(&thread_id) | |
| .map(|thread_entry| thread_entry.connection_ids.iter().copied().collect()) | |
| .unwrap_or_default() | |
| } |
The public thread status types expose runtime state but not subscriber presence:
codex/codex-rs/app-server-protocol/src/protocol/v2/thread.rs
Lines 1304 to 1348 in 25af12f
| #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema, TS)] | |
| #[serde(rename_all = "camelCase")] | |
| #[ts(export_to = "v2/")] | |
| pub struct ThreadLoadedListParams { | |
| /// Opaque pagination cursor returned by a previous call. | |
| #[ts(optional = nullable)] | |
| pub cursor: Option<String>, | |
| /// Optional page size; defaults to no limit. | |
| #[ts(optional = nullable)] | |
| pub limit: Option<u32>, | |
| } | |
| #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] | |
| #[serde(rename_all = "camelCase")] | |
| #[ts(export_to = "v2/")] | |
| pub struct ThreadLoadedListResponse { | |
| /// Thread ids for sessions currently loaded in memory. | |
| pub data: Vec<String>, | |
| /// Opaque cursor to pass to the next call to continue after the last item. | |
| /// if None, there are no more items to return. | |
| pub next_cursor: Option<String>, | |
| } | |
| #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] | |
| #[serde(tag = "type", rename_all = "camelCase")] | |
| #[ts(tag = "type")] | |
| #[ts(export_to = "v2/")] | |
| pub enum ThreadStatus { | |
| NotLoaded, | |
| Idle, | |
| SystemError, | |
| #[serde(rename_all = "camelCase")] | |
| #[ts(rename_all = "camelCase")] | |
| Active { | |
| active_flags: Vec<ThreadActiveFlag>, | |
| }, | |
| } | |
| #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)] | |
| #[serde(rename_all = "camelCase")] | |
| #[ts(export_to = "v2/")] | |
| pub enum ThreadActiveFlag { | |
| WaitingOnApproval, | |
| WaitingOnUserInput, | |
| } |
Related but distinct issues:
- Document how app-server clients can discover and attach to the active Codex Desktop thread #25914 requests discovery/attachment for the active Codex Desktop thread. This request is narrower, read-only, and concerns loaded threads on a shared CLI daemon.
- App Server: peer-client co-presence with the live TUI thread (RFC) #21551 discussed writable peer-client co-presence. This request does not ask for co-control or multi-client turn interaction.
- Bug: app-server can retain orphaned threads after last-subscriber disconnect #14137 concerns orphan cleanup after unexpected disconnects. This request also covers the intentional period where a correctly unsubscribed zero-subscriber thread remains loaded.
Suggested acceptance criteria
- A read-only client can distinguish a loaded thread with no interactive subscribers from one with at least one interactive subscriber.
- Presence updates promptly after
/resume, explicit unsubscribe, and connection close. - A zero-subscriber thread may remain loaded during the existing grace period without being reported as interactively attached.
- The API exposes aggregate state only and does not reveal connection identifiers.
Activity
yzcj105 commentedon Sep 26, 2026
Still reproduces on
codex-cli 0.157.1(macOS arm64, native install, managed daemon perCODEX_HOME).thread/loaded/listreturned 3 thread IDs./quit, then checked that its process was gone.thread/loaded/liststill returned all 3 IDs, including the one with no TUI left.Our use case is an observer (tmux pane/session restore) that needs to know whether a thread is still open in a terminal.
loadedcan't answer that, so we can't use it as a liveness signal. Even a zero/non-zero interactive-subscriber count, as proposed above, would be enough for us.Co-authored by AI assistant.
NateChristiansen commentedon Oct 9, 2026
We have the same integration need on macOS and Windows: a simple manager/worker harness should keep an idle, open Codex conversation discoverable and remove its entry promptly when its last interactive frontend closes. Our Mac setup uses CLI 0.161.0 with the separately updated managed daemon 0.162.0. Loaded state and hook-process ancestry cannot answer that.
The proposed aggregate interactive-subscriber presence is sufficient for this liveness requirement, provided it distinguishes actual interactive attachment from observers and retained background state. We do not need connection IDs, frontend PIDs or transcript content from this presence API.
Please preserve the lifecycle cases in the acceptance criteria: presence updates promptly after fresh attachment, resume,
/clear, unsubscribe and connection close; one of several frontends closing does not clear presence while another remains attached; an observer query does not create its own interactive presence or start a turn. A replaced startup thread may later emitSessionEndwithout implying that the resumed conversation is closed, as #51360 reports.Our desired checks are more than one hour open-idle visibility, detection within two minutes of the last interactive frontend closing, and same-thread resume visibility before input on both platforms. Startup hook timing is addressed in #51360; terminal targeting is the separate originating-client context request in #44902. We prefer this supported read over a relay, launch flags or custom builds.