Skip to content

code-mode: expose transport-neutral session runtime#29292

Closed
cconger wants to merge 1 commit into
cconger/code-mode-runtime-compact-03g1-retry-safe-operationsfrom
cconger/code-mode-runtime-compact-03h-public-runtime
Closed

code-mode: expose transport-neutral session runtime#29292
cconger wants to merge 1 commit into
cconger/code-mode-runtime-compact-03g1-retry-safe-operationsfrom
cconger/code-mode-runtime-compact-03h-public-runtime

Conversation

@cconger

@cconger cconger commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Why

An out-of-process code-mode host needs the same transport-neutral runtime used by the in-process adapter, without depending on actor internals. Cancellation also must not let a non-cooperative callback wedge cell termination or session shutdown indefinitely.

What

  • Expose SessionRuntime, its request/event types, cell capability types, and delegate contract as public crate API.
  • Keep the protocol adapter layered on that public runtime API; the wire ObserveOutcome and TerminateOutcome types from code-mode: expose create and observe operations #29291 do not change here.
  • Give canceled callback tasks a bounded 100 ms grace period, then abort their local tasks.
  • Remove the old actor-close cell_closed delegate callback from both runtime and session delegate surfaces at this layer.
  • Add whole-value delegate-forwarding and event-mapping tests for the public adapter contract.

Host/Core callback sequence

sequenceDiagram
    participant Host as SessionRuntime host
    participant Core as Core delegate
    alt nested tool callback
        Host->>Core: invoke_tool(NestedToolCall, CancellationToken)
        Core-->>Host: Result<JsonValue, String>
    else notification callback
        Host->>Core: notify(call_id, CellId, text, CancellationToken)
        Core-->>Host: Result<(), String>
    end
    opt cell/session cancellation
        Host-->>Core: CancellationToken is canceled
        Host->>Host: wait up to 100 ms
        Host->>Host: abort unfinished callback task
    end
    Note over Host,Core: cell_closed is absent in this commit
Loading

Stack boundary

Removing cell_closed is intentional here: actor shutdown is not the terminal-state signal Core needs. #29310 reintroduces it with precise semantics—once the terminal outcome is committed, even if its result remains buffered.

Validation

  • just test -p codex-code-mode
  • just test -p codex-code-mode-protocol
  • Contract tests cover delegate field mapping, callback cancellation, runtime events, errors, and image details.

Stack parent: #29397.

@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03g-create-observe-api branch from d573397 to 8fe1bf1 Compare June 21, 2026 05:33
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03h-public-runtime branch from df3758f to 2bbab3a Compare June 21, 2026 05:34
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03g-create-observe-api branch from 8fe1bf1 to b29a55b Compare June 21, 2026 06:24
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03h-public-runtime branch from 2bbab3a to ccffcce Compare June 21, 2026 06:24
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03g-create-observe-api branch from b29a55b to e81e125 Compare June 21, 2026 07:23
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03h-public-runtime branch from ccffcce to 18fb5ed Compare June 21, 2026 07:23
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03g-create-observe-api branch from e81e125 to f3f8aa4 Compare June 21, 2026 19:24
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03h-public-runtime branch from 18fb5ed to 5ff1f52 Compare June 21, 2026 19:24
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03g-create-observe-api branch from f3f8aa4 to fbf545e Compare June 21, 2026 22:44
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03h-public-runtime branch from 5ff1f52 to f3de9a8 Compare June 21, 2026 22:44
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03g-create-observe-api branch from fbf545e to bf52c09 Compare June 22, 2026 05:34
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03h-public-runtime branch from f3de9a8 to 7545b94 Compare June 22, 2026 05:34
@cconger cconger changed the base branch from cconger/code-mode-runtime-compact-03g-create-observe-api to cconger/code-mode-runtime-compact-03g1-retry-safe-operations June 22, 2026 05:34
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03h-public-runtime branch from 7545b94 to 2f2de77 Compare June 22, 2026 06:48
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03g1-retry-safe-operations branch 2 times, most recently from 4a76c0a to 457f6f2 Compare June 22, 2026 06:53
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03h-public-runtime branch 2 times, most recently from 56dffe9 to df256e8 Compare June 22, 2026 07:02
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03g1-retry-safe-operations branch 2 times, most recently from 1152f3f to 5df525b Compare June 22, 2026 07:09
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03h-public-runtime branch 2 times, most recently from 5baec19 to b79d2d5 Compare June 22, 2026 07:22
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03g1-retry-safe-operations branch from 5df525b to a6be94f Compare June 22, 2026 07:22
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03h-public-runtime branch from b79d2d5 to f12f4c9 Compare June 22, 2026 07:49
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03h-public-runtime branch from f12f4c9 to fb775b6 Compare June 22, 2026 08:37
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03g1-retry-safe-operations branch from a6be94f to 3081aba Compare June 22, 2026 08:37
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03h-public-runtime branch from fb775b6 to 1b0c2f7 Compare June 22, 2026 08:56
@cconger cconger force-pushed the cconger/code-mode-runtime-compact-03g1-retry-safe-operations branch from 3081aba to 098e9f0 Compare June 22, 2026 08:56
@@ -53,10 +56,13 @@ pub(super) async fn finish_callbacks(
) {
if matches!(completion, CallbackCompletion::Cancel) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: Cancellation can still wedge shutdown if it arrives after we enter DrainNotifications

if matches!(completion, CallbackCompletion::Cancel) {
cancellation_token.cancel();
finish_cancelled_tasks(notification_tasks, "notification").await;
finish_cancelled_tasks(tool_tasks, "tool").await;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could we make those 2 wait concurrent or share one deadline? Sounds odd to run them serially... mainly in a tokio runtime

@cconger cconger closed this Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants