Skip to content

fix: release the title-generation thread after the title turn - #629

Open
shoedog wants to merge 1 commit into
agentclientprotocol:mainfrom
shoedog:fix/release-title-thread
Open

shoedog wants to merge 1 commit into
agentclientprotocol:mainfrom
shoedog:fix/release-title-thread

Conversation

@shoedog

@shoedog shoedog commented Oct 14, 2026

Copy link
Copy Markdown

Problem

After the first turn of a new session, TitleGenerator.generateAndPersist starts an ephemeral thread, runs one turn on it to generate a title, and renames the main thread. Nothing releases that thread: closeSession unsubscribes only the session's own thread id, and it is the only caller of threadUnsubscribe.

Codex unloads a thread only when it has no subscribers and is idle (thread_unload_delay_secs, 60 s by default). So the title thread stays loaded until codex-acp exits, together with every MCP server process Codex started for it from the user's config. A client that opens and closes many sessions over one codex-acp process accumulates one set of those processes per session (#628).

Change

  • TitleGenerator.generateAndPersist unsubscribes the ephemeral thread in a finally around the title turn, so it is released whether the turn succeeds or fails.
  • The unsubscribe runs before the rename, not after the echo wait, so the thread is not held for the extra 5 s.
  • A failed unsubscribe is ignored. Title generation is best-effort, and the title is still written.

Tests

  • TitleGenerator.test.ts: the ephemeral thread is unsubscribed after the title turn and when the title turn fails (both fail without the change); the title is still written when the unsubscribe fails; no unsubscribe when thread/start fails.
  • session-fork-prompt.test.ts asserted that no thread/unsubscribe is sent at all. It now asserts that none is sent for the fork or its source, which is what the test is about.
  • npm run typecheck, npm run build and npm test pass: 121 files and 1728 tests pass, 7 files and 36 tests are skipped.
  • Real Codex 0.160.1, with the repro script from Title-generation thread is never unsubscribed, so its MCP server processes outlive session/close #628 against a build of this branch: the title thread's MCP server process exits about 60 s after the title turn, and none is left after both sessions are closed. On main one is left until codex-acp exits.

Fixes #628

🤖 Generated with Claude Code

https://claude.ai/code/session_017izEynabPeSUBT573AtvaZ

The ephemeral thread that generates a session title was never unsubscribed,
and session/close unsubscribes only the session's own thread. Codex keeps a
subscribed thread loaded, so the title thread and the MCP servers started for
it stayed until codex-acp exited.

Unsubscribe the ephemeral thread once its turn has settled, whether the turn
succeeded or failed.

Fixes agentclientprotocol#628

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017izEynabPeSUBT573AtvaZ

This branch has not been deployed

No deployments
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.

Title-generation thread is never unsubscribed, so its MCP server processes outlive session/close

1 participant