Skip to content

App Server: expose read-only subscriber presence separately from loaded-thread state #35676

Open

Description

@jchy20

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:

  1. a thread that is loaded because an interactive client such as the Codex TUI is currently attached; and
  2. 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

  1. Start a Codex TUI connected to the managed daemon. A new thread is created and loaded.
  2. Use /resume to continue a previously stored thread.
  3. From a separate initialized app-server connection, call thread/loaded/list and read metadata for the returned threads.
  4. Both the unused startup thread and the resumed thread can remain loaded and report an idle runtime status.
  5. Close the TUI. The resumed idle thread can remain in thread/loaded/list during 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 /resume replace 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):

#[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:

#[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:

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

  1. added
    enhancement
    CLI
    app-server
    on Jul 27, 2026
  2. yzcj105 commented on Sep 26, 2026

    @yzcj105

    Still reproduces on codex-cli 0.157.1 (macOS arm64, native install, managed daemon per CODEX_HOME).

    1. Three TUIs attached to one daemon. thread/loaded/list returned 3 thread IDs.
    2. Quit one TUI with /quit, then checked that its process was gone.
    3. thread/loaded/list still 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. loaded can'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.

  3. NateChristiansen commented on Oct 9, 2026

    @NateChristiansen

    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 emit SessionEnd without 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.

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

    CLIapp-serverenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions