Commit Graph

26 Commits

Author SHA1 Message Date
Channing Conger
b3cc217378 Add a health endpoint to the code-mode gRPC listener (#38806)
## What changed

- Serve `GET /healthz` with a `200 OK` response over HTTP/1.1 and HTTP/2.
- Continue requiring HTTP/2 for all other requests so gRPC methods are not exposed over HTTP/1.1.

## Testing

- Add TCP listener integration coverage for HTTP/1.1 and HTTP/2 health checks and rejection of HTTP/1.1 gRPC requests.

GitOrigin-RevId: ae7bbf56323fbc76769375a6d8e90653e8adc860
2026-08-15 21:26:28 +00:00
Adam Perry @ OpenAI
ff6e7c77a3 Canonicalize default namespaces in gRPC subscription filters (#38650)
## What changed

- Normalize both tool invocations and subscription filters before matching them.
- Treat missing and empty namespaces as aliases for the `functions` namespace while preserving the namespace reported with each invocation.

## Testing

- Add a gRPC service test covering missing, empty, and explicit default namespaces on both sides of a filtered subscription.

GitOrigin-RevId: 409326f8ee6b3ab9a6ff5ceca0693558bc9c364d
2026-08-14 21:03:00 +00:00
Adam Perry @ OpenAI
fe556c4b6c Deliver gRPC code-mode notifications without truncation (#38645)
## What changed

- Forward notification text to the session delegate without applying the previous 1,024-byte limit or appending a truncation suffix.
- Update the gRPC host integration test to verify that oversized multibyte notification text is delivered unchanged.

GitOrigin-RevId: 9a9e24b359a07540f70ec4e98b28524db3f7a4a0
2026-08-14 20:42:35 +00:00
Adam Perry @ OpenAI
6595071e65 Remove the gRPC code-mode open session limit (#38630)
## What changed

Allow the gRPC code-mode host to register more than
`MAX_IN_FLIGHT_REQUESTS` open sessions. Existing limits on in-flight
requests, control requests, and active cells remain unchanged.

GitOrigin-RevId: 126c5088868e7783f8592f3f9250f5c8573df51f
2026-08-14 19:26:36 +00:00
Adam Perry @ OpenAI
478215c5c1 Preserve large gRPC code-mode tool errors (#38621)
## Why

Code-mode tool failure messages larger than 64 KiB were truncated before they
reached the host.

## What changed

- Remove the tool error size limit from the gRPC protocol and host validation.
- Forward failed tool completion messages without truncation.

## Testing

- Verify that a multibyte error larger than 64 KiB is preserved exactly.

GitOrigin-RevId: 264ae4ba4adea5c19b669e4f41ccfd41a0c30fb5
2026-08-14 18:30:45 +00:00
Adam Perry @ OpenAI
0fce933290 Remove the gRPC code-mode enabled tool limit (#38615)
## What changed

Stop rejecting code-mode execute requests solely because `enabled_tools`
contains more than 1,024 definitions. Continue validating each tool definition
while converting the request.

GitOrigin-RevId: da83b61c5f659e6aa221ed663821edcdfc29d3f1
2026-08-14 17:50:01 +00:00
Adam Perry @ OpenAI
a3cb1c14fb Allow larger gRPC code mode tool descriptions (#38606)
## What changed

Stop rejecting gRPC execute requests when an enabled tool's description exceeds
16 KiB. Identifier, tool-count, and subscription-filter limits remain in place.

GitOrigin-RevId: c30dbf555e691b02bd6d6a835a0c40f671b0d172
2026-08-14 16:42:32 +00:00
Channing Conger
e0de12a126 Make gRPC code-mode yield tests deterministic (#38321)
## What changed

- Use a never-resolving promise when verifying that a session continues to
  enforce its yield limit after terminating a cell.
- Use `yield_control()` to create the yielded cell in the notification-draining
  test instead of relying on timer scheduling.

GitOrigin-RevId: 01cdaa94e5b8b5c89c6fa98c4bbdb28a690678e0
2026-08-13 07:26:27 +00:00
Channing Conger
5104cb649e Support gRPC code-mode hosts in app server (#38288)
## What changed

- Accept root `http://` and `https://` URLs in `--code-mode-host` and use the
  shared gRPC session provider for those endpoints.
- Keep `ws://` and `wss://` URLs on the existing WebSocket transport.
- Reject paths, queries, fragments, and credentials where unsupported, without
  exposing gRPC URL credentials in command-line validation errors.

## Testing

- Cover argument parsing and transport selection for both remote protocols.
- Exercise a gRPC host shared across app-server threads and verify credential
  rejection does not disclose usernames or passwords.

GitOrigin-RevId: b6516a85cf76db5c4cea620f89ef866d8af30cf0
2026-08-13 01:32:42 +00:00
Channing Conger
bde723ae7d Reconnect gRPC code-mode sessions after host restarts (#38257)
## What changed

- Reopen a cached code-mode session when its gRPC host stops, while
  serializing concurrent reconnection attempts and coordinating shutdown.
- Scope cell IDs to the new host generation so callbacks remain consistent
  and stale `wait` or `terminate` requests are rejected.
- Accept both `unix://` and `unix:` endpoints for gRPC hosts on Unix systems.

## Testing

- Cover host restart recovery, concurrent execution after reconnection,
  generation-aware callbacks and cell operations, stale cell rejection, and
  Unix socket execution.

GitOrigin-RevId: 548e168fdcef7f7d54bd32262e614886bf7bdd32
2026-08-12 22:00:20 +00:00
Channing Conger
ba2fb48319 Forward gRPC code-mode callbacks to session delegates (#38072)
## What changed

- Subscribe each gRPC code-mode session to nested tool calls and forward tool and notification callbacks to its delegate.
- Complete tool calls through the host while bounding oversized results and errors.
- Track callback ownership and cancellation so completed cells drain notifications, terminated cells cancel them, and shutdown revokes outstanding work.
- Validate callback identifiers, cell ownership, enabled tools, and pending callback limits without serializing independent callbacks or sessions.

## Testing

- Add integration and state tests for callback forwarding, completion ordering, cancellation, malformed callbacks, delegate panics, oversized results, and concurrent work.

GitOrigin-RevId: 005afbb90eea0eb77d746b930a1a96ca6dfcd4e7
2026-08-11 20:40:26 +00:00
Channing Conger
1e557a554e Add gRPC-backed code-mode sessions (#38041)
## What changed

- Add `GrpcCodeModeSessionProvider` for opening code-mode sessions over HTTP/2 or an existing `tonic` channel.
- Support execution, waiting, termination, per-session limits, cell-closure callbacks, and graceful shutdown over the gRPC protocol.
- Bound transport waits and error messages, validate host identifiers and responses, and clean up abandoned executions and observers.

## Testing

- Add end-to-end TCP tests covering session persistence, cancellation, concurrent waits, shutdown, cell cleanup, and independent yield limits.
- Add unit coverage for protocol conversion, deadlines, and session lifecycle state.

GitOrigin-RevId: d4729ce608ad4b42a99744b07e1f230e46cb24ec
2026-08-11 17:31:11 +00:00
Channing Conger
f8821d85eb Extract reusable code-mode host test support (#37922)
## What changed

- Move the host process harness and common session delegates into shared test
  support modules.
- Allow the host harness to start either WebSocket or gRPC listeners and
  validate the endpoint scheme they publish.
- Update the stdio and WebSocket integration tests to use the shared fixtures.

GitOrigin-RevId: a0408be7c88e4eb9ad1832b6d2698781de77168a
2026-08-11 03:06:53 +00:00
Channing Conger
9be95745fb Make gRPC code-mode notifications fire-and-forget (#37906)
## What changed

- Send notification events without waiting for client acknowledgment, so an
  unacknowledged notification no longer delays cell completion.
- Keep the notification acknowledgment RPC as a compatibility no-op after
  validating the session and notification ID.
- Remove pending-notification tracking and cancellation events from the gRPC
  session routing path.

## Testing

- Verify that a cell completes after emitting an unacknowledged notification
  and that a later acknowledgment is still accepted.

GitOrigin-RevId: 19cf3ed5ce82cf45d84fa75f238c2afa4e83acb5
2026-08-11 00:52:35 +00:00
Channing Conger
c0ad3ab014 Add gRPC TCP transport to the code-mode host (#37745)
## What changed

- Accept `grpc://IP:PORT` endpoints through `--listen` and serve the existing
  code-mode gRPC service over TCP.
- Print the bound HTTP endpoint to stdout so callers can discover the port when
  binding to port `0`.
- Apply the protocol frame-size limits and disable Nagle's algorithm on accepted
  connections.

## Testing

- Add an end-to-end test that starts the host on an ephemeral port, connects a
  gRPC client, and opens a session.
- Verify accepted gRPC sockets have `TCP_NODELAY` enabled.

GitOrigin-RevId: 51d6c21dff8cffb47068c0677ba10ff370385cec
2026-08-09 23:39:25 +00:00
Channing Conger
61a3dd4387 Implement the gRPC code-mode host service (#37530)
## What changed

- Export `GrpcCodeModeHost` as a transport-independent implementation of the
  code-mode gRPC API.
- Support leased sessions, execution and wait lifecycle operations, filtered
  nested tool-call subscriptions, tool completions, and notification
  acknowledgements.
- Share host-wide request and active-cell limits across the existing and gRPC
  transports, and bound identifiers, metadata, subscriptions, and pending
  callbacks.

## Testing

- Add coverage for request conversion, ordered callback routing, cancellation,
  session cleanup, backpressure, malformed input, and resource-limit handling.

GitOrigin-RevId: f146ba7e6fe4e4aa02f25dd3f961120980516d0e
2026-08-08 04:13:55 +00:00
Sean Huang
abc5d0b552 Disable Nagle's algorithm for code-mode WebSockets (#37504)
## Why

Code-mode WebSocket connections are latency-sensitive, so buffering small TCP
writes can delay request and response traffic.

## What changed

- Enable `TCP_NODELAY` on outbound remote-session WebSocket connections.
- Enable `TCP_NODELAY` on sockets accepted by the code-mode host, logging a
  warning if the socket option cannot be set.

## Testing

- Add a listener test that connects to the host and verifies the accepted
  socket has `TCP_NODELAY` enabled.

GitOrigin-RevId: e51c781c4b47c6a4ae1c32c93cd79768719a68d9
2026-08-07 21:10:49 +00:00
Sean Huang
9d00bb01c0 Add per-session code-mode execution limits (#37114)
## What changed

- Add `create_session_with_limits` and session-scoped cell execution limits.
- Clamp execute and wait yield times to the session's `max_yield_time_ms`
  without terminating the running cell.
- Negotiate support with remote code-mode hosts and include non-default limits
  in `session/open`, while keeping unlimited sessions compatible with hosts and
  providers that do not support limits.

## Testing

- Cover yield-time clamping, zero-timeout behavior, and isolation between
  sessions.
- Cover wire serialization, capability negotiation, unsupported hosts, and
  shared process-host execution.

GitOrigin-RevId: 9517321cd605bb87f93eeaa6ba331cc2e346e582
2026-08-05 16:09:01 +00:00
Channing Conger
60c722e075 Add a dual-WebSocket transport for code mode (#36812)
## Why

Large nested-tool callbacks can occupy a WebSocket and delay unrelated session
operations on the same code-mode connection.

## What changed

- Negotiate the optional `dual-websocket-v1` capability and pair a second,
  token-scoped WebSocket with the control connection.
- Route nested-tool callbacks and their results over the bulk socket while
  keeping session operations, notifications, and execution responses on the
  control socket. Reject messages sent on the wrong lane.
- Preserve the single-connection transport when the capability is unavailable,
  and bound pairing, queued callbacks, and deferred cross-socket messages.
- Defer callbacks that arrive before their execution-started response, and
  return delegate errors without disconnecting the connection.

## Testing

Add protocol, transport, driver, and WebSocket integration coverage for
capability negotiation, lane routing, pairing failures, out-of-order messages,
and progress during large concurrent tool results.

GitOrigin-RevId: fa4504653e7cbf3c4ec930ae57aa0a41345bad66
2026-08-03 23:48:28 +00:00
Channing Conger
97576b1794 Run code mode exclusively through the standalone host (#36217)
## What changed

- Move the V8 implementation into a dedicated `codex-code-mode-runtime` crate used by `codex-code-mode-host`, removing the embedded runtime fallback from the Codex process.
- Resolve the host executable from the active installation layout and check its availability before selecting tools.
- Fall back to direct tools with a one-time warning when optional code mode is unavailable. Keep `code_mode_only` and `disable_in_process_fallback` configurations fail-closed.

## Testing

- Cover host discovery for standalone and package layouts, including missing hosts and symlinks.
- Verify direct-tool fallback, one-time warnings, and fail-closed code-mode-only behavior.

GitOrigin-RevId: 5aa3c6f1db148b2231fc24089a2ee0e2b00dbddb
2026-07-30 20:24:29 +00:00
Channing Conger
f61b51ddd9 Support remote code-mode hosts in app-server (#35098)
## What changed

- Add `--code-mode-host ws://...` and `wss://...` support to `codex app-server`, gated by the `code_mode_host` feature. When omitted, app-server continues to start a local host.
- Share one remote WebSocket connection across the process's threads, using the configured HTTP client's proxy and TLS policy and preserving the existing framed host protocol.
- Reject invalid host URLs, bound WebSocket frame sizes, close connections cleanly, and return an error when a connection exceeds 1,024 pending delegate calls without disconnecting it.

## Testing

- Cover CLI validation, WebSocket protocol execution and shutdown, connection sharing across app-server threads, and delegate-call capacity recovery.

GitOrigin-RevId: 715e82d4d9db1e7e2f91b754a777dcab504e2ae4
2026-07-24 04:37:01 +00:00
Channing Conger
0dfa778dae Add WebSocket transport to the code-mode host (#35078)
## What changed

- Add a `--listen` option that accepts `stdio`, `stdio://`, or a
  `ws://IP:PORT` endpoint, while retaining stdio as the default.
- Serve the existing length-prefixed protocol in binary WebSocket messages,
  with isolated connections, shared host limits, and a `/readyz` endpoint.
- Reject browser-origin handshakes and contain malformed frames to the affected
  connection.

## Testing

- Cover listen URL parsing and complete-frame encoding and decoding.
- Exercise readiness, cell execution, tool callbacks, large frames, concurrent
  connections, malformed frames, and origin rejection through the WebSocket
  listener.

GitOrigin-RevId: 01c8be4c6256b8ce4a3a0002440dcb3294e5f887
2026-07-24 02:40:11 +00:00
Channing Conger
9732b406e7 fix: update crossbeam-epoch for RUSTSEC-2026-0204 (#31308)
Bump our crossbeam-epoch dep to fix cargo-deny.
2026-07-06 16:26:56 -07:00
Channing Conger
ab16046c88 [codex] add process-owned code-mode session client (#30112)
## Summary

- add `ProcessOwnedCodeModeSessionProvider` and logical session
generation/rebinding state
- add the supervised child-process connection, reader/writer tasks, and
driver state machine
- make dropped execute/wait/open callers cancellation-safe with explicit
ownership handoff and durable cleanup
- validate cell/delegate lifecycle state and reject invalid protocol
transitions
- add end-to-end stdio coverage for delegates, cancellation, frame
limits, child loss, stale generations, replacement, and long-lived
sessions

## Why

This final stage exposes the process-owned client only after the wire
protocol, host-safe runtime, and standalone host are independently in
place. Transport failure is fail-stop: the client closes local state,
cancels callbacks, reaps the child, and lazily rebuilds a fresh host
generation rather than transactionally recovering the old connection.

## Stack

This is **4 of 4** in the process-owned code-mode session stack.

- Depends on #30111
- Full stack: #30108#30110#30111 → this PR

## Validation

- `just test -p codex-code-mode -p codex-code-mode-host` — 86 passed
- `just fix -p codex-code-mode`
- `just fix -p codex-code-mode-host`
- `just bazel-lock-update`
- `just bazel-lock-check`
- `bazel test //codex-rs/code-mode:code-mode-unit-tests
//codex-rs/code-mode-host:code-mode-host-unit-tests
//codex-rs/code-mode-host:code-mode-host-stdio-test
//codex-rs/code-mode-protocol:code-mode-protocol-unit-tests` — 4/4
passed
- `just fmt`
2026-06-25 23:46:17 -07:00
Channing Conger
da78d5fdc5 [codex] implement standalone code-mode process host (#30111)
## Summary

- implement the standalone `codex-code-mode-host` stdio service
- route sessions, cells, delegate requests, responses, and cancellation
through a bounded host peer
- supervise request, writer, cell-forwarding, actor, and V8 failure
boundaries
- bound request/session tombstones and fail-stop the connection on
invalid protocol state
- add host-only duplex protocol tests and local Cargo/Bazel run recipes

## Why

This stage makes the host process independently runnable and reviewable
before exposing any remote client in Codex. Transport or runtime failure
closes the connection and relies on process replacement rather than
transactional recovery.

## Stack

This is **3 of 4** in the process-owned code-mode session stack.

- Depends on #30110
- The final client PR targets this branch

## Validation

- `just test -p codex-code-mode-host` — 7 host-only tests passed
- `just fix -p codex-code-mode-host`
- `just bazel-lock-update`
- `just bazel-lock-check`
- `just fmt`
2026-06-25 18:00:39 -07:00
Channing Conger
aa46f2debf code-mode standalone: extract protocol and add host crate (#27724)
This is phase 1 of a 4 phase stack:
1. **Add protocol and host crates for new IPC code mode implementation**
2. Create the new standalone binary
3. Create a new IPC `CodeModeSessionProvider` to use new binary
4. Remove v8 from core and only use IPC provider


## Add protocol and host crates for new IPC code mode implementation
Establish a clean process boundary without changing the existing
in-process behavior.

- Add the codex-code-mode-protocol crate for shared session, runtime,
response, and tool-definition types.
- Move protocol-facing code out of the V8-backed implementation.
- Add a buildable codex-code-mode-host crate as the foundation for the
standalone process.
- Keep the existing in-process runtime as the active implementation.
2026-06-11 22:37:26 -07:00