Skip to content

SessionStart (source: resume) fires only with the first prompt after /resume, and the replaced startup session gets SessionEnd without SessionStart #51360

Open

Description

@bubakanov

Version: codex-cli 0.160.1, macOS 26, interactive TUI

Steps:

  1. Configure SessionStart, UserPromptSubmit, and SessionEnd hooks that log hook_event_name, source, and session_id.
  2. Start codex, then run /resume and pick an earlier conversation.
  3. Wait, then send a prompt.

Expected: SessionStart with source: "resume" fires when the conversation is resumed, so integrations can show that conversation's state before the user types anything.

Actual

  • No hook fires on /resume. SessionStart (source: "resume") arrives in the same second as the first UserPromptSubmit; if no prompt is sent, it never fires.
  • The blank startup session that /resume replaced gets no SessionStart, yet its SessionEnd (reason: "other") arrives 60 seconds after /resume, while the resumed conversation is already mid-turn. A consumer that treats SessionEnd as "the agent in this terminal exited" tears down the live conversation's state.

Log (session truncated):
+0s SessionEnd session=01a11105-3861 reason=other ← replaced startup session, 60s after /resume
...
SessionStart source=resume session=01a110e4-52e2 ← only with the first prompt
UserPromptSubmit session=01a110e4-52e2

Ask: fire SessionStart (source: "resume") when /resume selects a conversation, and either pair the startup session's SessionEnd with a SessionStart or skip it for a session that never started a turn.

Activity

  1. added
    bug
    CLI
    hooks
    session
    on Oct 6, 2026
  2. NateChristiansen commented on Oct 9, 2026

    @NateChristiansen

    This timing matters for lightweight peer/status integrations: opening or resuming a Codex terminal should register it before the user sends a greeting solely to trigger hooks. SessionStart already exists and is wired in our harness; the needed guarantee is execution before first input.

    Could the fix cover fresh interactive launch, direct codex resume <id> and in-TUI /resume, with the exact addressable thread ID? If fresh threads intentionally remain lazy, a frontend-ready event needs an explicit join to a supported addressable thread before the first model turn. The allowlisted originating-client client_env proposed in #44902 can carry a per-launch terminal marker; timing correlation between readiness and a later thread is insufficient with several terminals sharing one daemon and directory.

    Please also distinguish replacing a thread from exiting its frontend. A delayed end for an unused startup thread must not unregister the resumed conversation in the same terminal; /clear needs equivalent behavior.

    Evidence scope: this issue's report is 0.160.1 macOS in-TUI /resume. Our harness has older 0.155/0.156 direct-resume omissions and a 0.159.2 Windows lazy-thread observation. Our current Mac pair is CLI 0.161.0 plus daemon 0.162.0, but we have not completed a current-version pre-input hook-timing repro and are not claiming these reports prove it. This comment states the required behavior. Read-only interactive presence is the separate request in #35676.

  3. liby commented on Oct 28, 2026

    @liby

    On codex-cli 0.165.0 (macOS 27), a direct codex resume <thread-id> launch in a new terminal ran no SessionStart hook in the first 15 seconds. SessionStart ran when the first prompt was submitted. An integration that routes messages to a conversation using its SessionStart report cannot deliver messages to the resumed conversation until someone types into it.

  4. hag03521 commented on Nov 4, 2026

    @hag03521

    Still reproducible on codex-cli 0.166.0, Linux x86_64 (WSL2), with the TUI attached to the shared app-server daemon. There is also one case that I don't think has been described here yet.

    1. Direct codex resume <id>: no SessionStart until the first turn. With a hook that only records its input, SessionStart (source: "resume") was logged at the start of the first turn, together with the first UserPromptSubmit, and never while the resumed TUI sat idle. A turn started by a message queued with thread/queue/add (not by typing) also runs it at that point.

    2. Resuming a thread that the daemon still has loaded: SessionEnd runs inside thread/resume.

    1. Exit the TUI.
    2. Run codex resume <id> before the daemon unloads the idle thread. In our environment, the unload happened about 60 s after exit; we resumed after 26–38 s.

    In our attempts, the daemon then shut down the old run as part of the resume request, so SessionEnd ran before the new run was created. The new run had no SessionStart until its first turn. For an integration that registers in SessionStart and unregisters in SessionEnd, the resumed conversation is therefore unregistered from the moment of resume until someone types.

    Daemon log for case 2 (identifiers replaced)
    08:44:35.384  app-server request: thread/unsubscribe connection_id=<conn> request_id=Integer(10)
    08:45:01.549  app-server request: thread/resume connection_id=<conn> request_id=Integer(8)
    08:45:01.553  session_loop{thread_id=<thread-A>}: Submission thread_id=<thread-A> submission_id=<sub> operation="shutdown" parent_turn_id=None root_turn_id=None op=Shutdown
    08:45:01.589  session_loop{thread_id=<thread-A>}:submission_dispatch{otel.name="op.dispatch.shutdown" submission.id="<sub>" codex.op="shutdown"}: Shutting down Codex instance
    08:45:01.593  session_loop{thread_id=<thread-A>}: Agent loop exited
    08:45:01.593  app_server.request{rpc.method="thread/resume"}:resume_running_thread: clearing thread listener during thread-state teardown thread_id=<thread-A> listener_generation=1 had_listener=true had_active_turn=false
    08:45:01.680  app_server.request{rpc.method="thread/resume"}:startup_prewarm{otel.name="startup_prewarm" thread.id=<thread-A> prewarm.input="base"}: …
    

    The integration's SessionEnd handler recorded the end at 08:45:01.587, inside this request.

    From reading rust-v0.166.0 app-server/src/request_processors/thread_processor.rs, our understanding (please correct us) is:

    • resume_running_thread shuts the loaded thread down only when the resume overrides differ from the loaded thread; otherwise it rejoins.
    • We did not identify which override differed in our case.

    It would help integrations if:

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

    CLIbughookssession

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions