Skip to content

code-mode: make session shutdown authoritative#29287

Merged
cconger merged 3 commits into
mainfrom
cconger/code-mode-runtime-compact-03e-shutdown-hierarchy
Jun 21, 2026
Merged

code-mode: make session shutdown authoritative#29287
cconger merged 3 commits into
mainfrom
cconger/code-mode-runtime-compact-03e-shutdown-hierarchy

Conversation

@cconger

@cconger cconger commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Give each session and cell a hierarchical cancellation token.
  • Track cell tasks so shutdown waits for admitted actors without polling the registry.
  • Make shutdown authoritative across concurrent admission and non-cooperative callbacks.

Why

A best-effort registry scan can miss cells admitted concurrently or blocked behind the registry lock.

Impact

Session shutdown reliably stops every admitted cell and rejects new work once shutdown begins.

Validation

  • Stack-tip validation: just test -p codex-code-mode -p codex-code-mode-protocol (70 passed).
  • Parent branch: cconger/code-mode-runtime-compact-03c-terminal-state.

@cconger
cconger force-pushed the cconger/code-mode-runtime-compact-03c-terminal-state branch from 2eb9c28 to 82722d4 Compare June 21, 2026 06:24
@cconger
cconger force-pushed the cconger/code-mode-runtime-compact-03e-shutdown-hierarchy branch from 0118f65 to 442d204 Compare June 21, 2026 06:24
Err(error_text) => RuntimeCommand::ToolError { id, error_text },
let command = tokio::select! {
biased;
_ = cancellation_token.cancelled() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid dropping the delegate future as soon as this token fires? The delegate API currently promises cooperative token cancellation, not cancellation-safe Drop, so this can skip async cleanup and let provider-owned work survive after shutdown returns

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I like your proposed structure better. Co-operative cancelation will work better in the split env.

I'm a little stressed that a wedged delegate call can hold open a terminating session indefinitely, but we can perhaps enforce this with timeouts or other forms of exceptional ungraceful termination.

Updated

DelegateEvent::NotificationStarted
);

let shutdown_service = Arc::clone(&service);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could these 3 100ms timeouts use the existing 1s/2s test bound? They include V8 termination and actor scheduling, so 100ms will be flaky

@cconger
cconger force-pushed the cconger/code-mode-runtime-compact-03c-terminal-state branch from 82722d4 to 728e1ad Compare June 21, 2026 18:24
Base automatically changed from cconger/code-mode-runtime-compact-03c-terminal-state to main June 21, 2026 19:05
@cconger
cconger force-pushed the cconger/code-mode-runtime-compact-03e-shutdown-hierarchy branch from 442d204 to ebc9240 Compare June 21, 2026 19:08
@cconger
cconger marked this pull request as ready for review June 21, 2026 19:08
@cconger
cconger requested a review from jif-oai June 21, 2026 19:28
@cconger
cconger merged commit 9c79d87 into main Jun 21, 2026
31 checks passed
@cconger
cconger deleted the cconger/code-mode-runtime-compact-03e-shutdown-hierarchy branch June 21, 2026 20:15
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants