Skip to content

Let integrations know which thread is active when it is opened, resumed, or reconnected, without waiting for a prompt #52907

Open

Description

@4piu

What we want

An integration (a hook or an MCP server) should learn which thread a user has open as soon as that thread is started or resumed in a client. It should also learn this again after the app-server restarts (for example on auto-update) or after an MCP server is reloaded. The user should not have to send a prompt first.

Why it matters

Integrations that route messages to a conversation, or show its state, must bind to the thread the user is actually working in. Today they cannot do that until the user types:

So after a restart or an auto-update, an integration has no reliable way to reconnect to the conversations that are still open.

Any of these would solve it

  • Fire SessionStart when a thread is started or resumed in the client, not at the first prompt.
  • Give each MCP server instance the thread it serves.
  • Expose which threads currently have a live client subscribed.

Observed on codex-cli 0.162.1, Linux.

Related: #51360, #23817, #9550

Activity

  1. added
    enhancement
    CLI
    app-server
    hooks
    mcp
    on Oct 10, 2026
  2. github-actions commented on Oct 10, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  3. gpgkd906 commented on Oct 17, 2026

    @gpgkd906

    Additional evidence: TUI lifecycle and resume results (--no-daemon)

    What variant of Codex are you using?

    CLI / interactive TUI (--no-daemon), macOS; tested Codex 0.163.0.

    What feature would you like to see?

    A terminal session manager needs to restore the exact Codex conversation the user was interacting with when the user confirms a terminal-service restart, and then confirm the outcome. The integration keeps the native interactive TUI, without controlling model work, sending an extra chat message, or taking over the app-server transport. This matches this issue's current-thread/before-prompt requirement; the evidence below adds an embedded-client case and concrete lifecycle ambiguities.

    An opt-in observation interface dedicated to TUI lifecycle could provide three outcomes:

    1. The current input target as a structured fact. Identify the exact thread on initialization, selection changes and exit; distinguish the root/session tree from the current input target, and writable interaction from read-only viewing. Document ordering, client/lifecycle correlation and invalidation so a delayed event cannot restore a previously selected thread.
    2. A resume result independent of model turns. Report success or the applicable failure once determined, distinguishing cancellation and read-only fallback. No extra prompt should be necessary, and the result should not depend on whether a restored goal or queue starts a turn. Consumers need to separate requesting a resume from observing its outcome.
    3. Verifiable association with the interactive client. Start with embedded --no-daemon: a TUI-spawned observer helper, or another supported mechanism whose association can be checked through the operating system, could work. A PID asserted in a payload is not itself OS-verified process provenance. Solving every shared-daemon attribution case is outside this narrower request.

    Event names and transport are suggestions, not requirements. Simply moving existing SessionStart hooks earlier could affect hooks that inject context or influence turns; a separate observation surface would avoid assuming that change is compatible.

    Additional information

    Executed experiments (2026-10-17). Interactive 0.163.0 TUIs used isolated HOME/CODEX_HOME, --no-daemon, no real authentication, and individually trusted hooks. Control turns used a loopback stub provider, not a real model service.

    • No SessionStart was observed in 15 resume windows without additional prompts: three 30-second windows and twelve 20-second windows. Subsequent minimal test turns produced source=resume. These are bounded observations, not proof across all configurations.
    • A switch/exit reproduction was: start a TUI, use /new, then /quit. One TUI process emitted SessionEnd for two different root sessions, both with reason=other; the old session could arrive last. Neither one received event nor the last event establishes the current input target.

    Source findings, checked separately from runtime observations. The experiment revision was 83086188ae0614bd882818ff1aa23f3194962012; main was also inspected at fixed commit 3b8f43a06bb3105e81406b35ff69f94977d18ae4. These identify the October 17 investigation, not a claim about the latest release at publication. Relevant behavior was present in both:

    Source also shows active-writer conflicts falling back to read-only viewing, and archived-session cancellation exiting normally. Process survival or exit code zero therefore cannot distinguish writable success, read-only fallback and cancellation. These paths and goal/queue continuation were source-reviewed, not newly runtime-tested; no Codex tests were run for this analysis.

    Related: #51360 covers delayed hooks; #44902 and #48500 discuss client attribution. The client-side preference and multi-client concerns in #44774 are consistent with starting here at TUI observation.

    This asks only for observation: no automatic continuation prompts, tool approvals, goal/queue changes, headless orchestration, or guarantee that resumed work stays paused. Terminal text, private databases and writer-lock files are not requested substitutes; even demonstrated writer ownership would not establish the current TUI input target.

  4. flyryan commented on Nov 21, 2026

    @flyryan

    I reproduced this on macOS with the Codex Desktop bundled engine 0.169.0-alpha.11.1.

    1. Enable a trusted plugin that records when its SessionStart hook runs. Use a saved chat that previously ran the hook, and let the chat unload.
    2. Reopen that chat in Desktop. Leave the input empty.
    3. Compare the chat status, last completed turn, and plugin registration before and after reopening.

    Desktop changed the chat from notLoaded to idle. Its last completed turn stayed the same. An independent client still could not see it in the plugin’s directory. Starting one ordinary turn in a separate reproduction restored registration.

    I also tested the bundled engine with a disposable local app server and a plugin with a stdio MCP server. Two cold resumes of the same saved thread returned idle with zero new turns. MCP started in the correct working directory, but neither its environment nor its initialize request identified the thread. Two chats in one checkout would therefore be ambiguous. A client attached to the owning app server could observe the thread-specific status change.

    In this build, the engine queues the resume event and dispatches it in the turn path. A trusted, thread-scoped callback on interactive reopen would let a plugin register the correct chat before the first prompt. A useful regression test would open two chats in the same checkout and verify the callback identifies only the one actually reopened.

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-serverenhancementhooksmcp

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions