Skip to content

Prevent SessionEnd from killing shared Codex tasks#491

Open
liby wants to merge 1 commit into
openai:mainfrom
liby:bugfix/preserve-broker-across-session-exits
Open

Prevent SessionEnd from killing shared Codex tasks#491
liby wants to merge 1 commit into
openai:mainfrom
liby:bugfix/preserve-broker-across-session-exits

Conversation

@liby

@liby liby commented Jul 13, 2026

Copy link
Copy Markdown

A Claude SessionEnd hook previously requested shutdown of the workspace
broker whenever any session exited. When two Claude sessions used the same
workspace, ending one session could stop the broker serving another session's
active Codex task. That task then lost its app-server transport and remained
running without a result, while the ending hook could be cancelled waiting for
shutdown.

The broker now owns the shutdown decision:

  • Reject broker/shutdown while another client, request, or stream is active.
  • Stop accepting new clients as soon as shutdown is accepted.
  • Exit after five minutes with no clients, active requests, or active streams.

The hook bounds shutdown requests to one second and removes only the resources
captured from a broker that accepted shutdown. Task execution races completion
against transport exit so a disconnected worker records a failure instead of
waiting indefinitely. Broker initialization falls back to a direct client only
for errors marked as broker transport failures.

Related to #490, which independently addresses orphaned brokers and the
shutdown connection race. This change also covers cross-session SessionEnd
ownership, bounded shutdown responses, stale broker reuse, and task failure on
transport loss.

Validation

  • Full test suite in an isolated config environment: 101 passed
  • npm run build
  • npm run check-version
  • git diff --check

SessionEnd treated the workspace broker as owned by the exiting Claude
session, so it could terminate another session's active Codex task and
leave the caller waiting forever after the transport disappeared.

Let the broker reject shutdown while requests, streams, or other clients
are active, then exit after five minutes of complete idleness so crashed
sessions cannot leave it alive indefinitely.

Bound shutdown RPCs to one second and only tear down resources after an
accepted response. Race task completion against transport exit, and fall
back to a direct client only for marked broker connection failures.
@liby
liby requested a review from a team July 13, 2026 08:33
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.

1 participant