Skip to content

refactor(codex): separate exec session transport - #126859

Merged
steipete merged 1 commit into
mainfrom
steipete/codex-exec-server-transport-neutral
Aug 21, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/codex-exec-server-transport-neutral

Conversation

@steipete

@steipete steipete commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

OpenClaw's Codex plugin previously coupled execution-session ownership to its loopback WebSocket adapter, spread connection-owned process, file-handle, notification, and HTTP cleanup across transport-specific helpers, and silently downgraded failed environment registration even though the supported Codex runtime already defines that operation. This made lifecycle ownership harder to verify and could obscure a real startup failure.

Why This Change Was Made

Move JSON-RPC dispatch, ordered process notifications, connection-owned processes and file handles, streamed HTTP cancellation, and idempotent cleanup into the plugin-private CodexSandboxExecSession, behind only a generic { send, isOpen } message transport. The existing loopback WebSocket remains the sole adapter/server owner; connection-local, non-resumable sessions, capability-path authorization, filesystem sandbox policy, subprocess behavior, and local-only transport are preserved. Capture and validate the sandbox backend and filesystem bridge once before publishing the server, then delete the obsolete repeated runtime guards and unsupported-environment/add downgrade. Registration errors now propagate after releasing the acquired lease because OpenClaw supports Codex app-server 0.147.0+ and ships 0.148.0, where environment registration is an owned upstream contract.

This is a maintainer-requested, AI-assisted, plugin-private refactor. It adds no SDK/core/node carrier, transport endpoint, missing RPC, reconnect/resume behavior, changelog entry, or unrelated surface. Production code is +256/-289 (net -33 lines); tests are +137/-49.

User Impact

Existing Codex sandbox execution, loopback WebSocket transport, process/file behavior, notification ordering, and no-resume connection semantics are unchanged. An unsupported or otherwise failed environment registration now reports the actual startup error after deterministic lease cleanup instead of silently degrading. Incomplete sandbox environments fail before exposing a listener.

No visual proof or changelog entry is applicable: this is an internal plugin ownership cleanup with no UI change. The intentional observable difference—registration failure now failing closed—was verified against the real pinned Codex app-server.

Evidence

  • Exact head: 0268d7915be6bdfb563d6c68a6a6458d64f4a64c.
  • Exact-head CI: https://github.com/openclaw/openclaw/actions/runs/32422441572 — green.
  • Real pinned runtime: @openai/codex 0.148.0 app-server over the production stdio client, with an isolated empty home and no inference/auth request.
  • Success path: the real app-server accepted environment/add, independently reported the registered environment ready, and connected to the real OpenClaw loopback exec-server. A real sandbox child started; lease release terminated it, finalized exactly once, removed the registry entry, closed the listener, and subsequent connection returned ECONNREFUSED.
  • Failure path: after a production lease was acquired, the real app-server rejected upstream-invalid execServerUrl=none with JSON-RPC -32600 (remote environment cannot use disabled exec-server url). The error propagated, the environment remained unknown, no thread/start or inference occurred, and OpenClaw removed the registry entry and listener.
  • Frozen proof: 32 source, built-runtime, package, upstream, and native-binary hashes remained unchanged; all proof-owned processes exited; isolated homes/state were removed; sensitive-value inspection passed.
  • Supplemental exact-head registration/session cleanup suite: 6 files, 85 tests passed.
  • Full focused development suite: 9 files, 256 tests passed.
  • pnpm tsgo:extensions, pnpm tsgo:extensions:test, pnpm lint:extensions, and pnpm build — passed.
  • node scripts/check-changed.mjs -- extensions/codex/src/app-server/attempt-startup.test.ts extensions/codex/src/app-server/sandbox-exec-server.json-rpc.test.ts extensions/codex/src/app-server/sandbox-exec-server.lifecycle.test.ts extensions/codex/src/app-server/sandbox-exec-server.test.ts extensions/codex/src/app-server/sandbox-exec-server.ts extensions/codex/src/app-server/sandbox-exec-server/filesystem.ts extensions/codex/src/app-server/sandbox-exec-server/http.ts extensions/codex/src/app-server/sandbox-exec-server/json-rpc.ts extensions/codex/src/app-server/sandbox-exec-server/processes.ts extensions/codex/src/app-server/sandbox-exec-server/runtime.ts extensions/codex/src/app-server/sandbox-exec-server/types.ts extensions/codex/src/app-server/sandbox-exec-server/session.ts — passed.
  • git diff --check origin/main...HEAD — passed.
  • Fresh pre-commit and post-rebase Codex autoreviews — no accepted/actionable findings.
  • Rebase completed without conflicts; range-diff and patch hashes prove byte-identical behavior.
  • Upstream Codex source personally inspected at openai/codex@b5ea64a203ce:

@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 20, 2026 22:03
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 20, 2026
@clawsweeper

clawsweeper Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 20, 2026, 7:16 PM ET / 23:16 UTC.

ClawSweeper review

What this changes

This PR moves one Codex sandbox execution connection’s JSON-RPC dispatch, resource ownership, notifications, and cleanup from the loopback WebSocket adapter into a transport-neutral session object.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for maintainer review: the code inspection found no discrete patch defect, but the removal of the supported-version fallback depends on an upstream Codex contract that could not be directly inspected because the required sibling checkout is absent and network access is unavailable.

Priority: P2
Reviewed head: 0268d7915be6bdfb563d6c68a6a6458d64f4a64c
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is a focused, well-covered owner-boundary refactor, with real-runtime evidence limited by the unavailable direct upstream-contract check.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Evidence reviewed 6 items Changed owner boundary: The new session owns connection-local process and file state, dispatch, notification delivery, and idempotent cleanup; the WebSocket adapter only normalizes messages and invokes it.
Startup caller and failure cleanup: The startup path acquires the environment before thread start, and the changed tests assert that a registration error releases the registry entry and prevents thread start.
Supported-version compatibility surface: Current main accepts external Codex app-server versions from 0.147.0 onward, while the bundled plugin pins 0.148.0; removing the unsupported-method downgrade therefore relies on that upstream contract across the supported range.
Findings None None.
Security None None.

Live Verification

Command: pnpm exec vitest run extensions/codex/src/app-server/sandbox-exec-server.test.ts

Result: FAIL (partial) — step 2 expect_output OpenClaw Codex sandbox exec-server: expected terminal output was not visible within 30 seconds: "OpenClaw Codex sandbox exec-server"

pnpm exec vitest run extensions/codex/src/app-server/sandbox-exec-server.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-126859-Xc4zi1/target$ pnpm exec vitest run extensions/codex/src/app-server/sandbox-exec-server.test.ts
pnpm exec vitest run extensions/codex/src/app-server/sandbox-exec-server.test.ts
[PLUGIN_TIMINGS] Your build spent significant time in plugin ˋinject-file-scope-variablesˋ. See https://rolldown.rs/reference/InputOptions.checks#plugintimings
for more details.

[PLUGIN_TIMINGS] Your build spent significant time in plugin ˋexternalize-depsˋ. See https://rolldown.rs/reference/InputOptions.checks#plugintimings for more de
tails.

[PLUGIN_TIMINGS] Your build spent significant time in plugin ˋexternalize-depsˋ. See https://rolldown.rs/reference/InputOptions.checks#plugintimings for more de
tails.


 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126859-Xc4zi1/target





































Assertions:

  • FAIL expect_output: OpenClaw Codex sandbox exec-server

How this fits together

The Codex plugin registers a local sandbox exec server with the Codex app-server. Its loopback WebSocket receives JSON-RPC requests, while the session owns sandbox processes, file handles, streamed HTTP work, responses, and connection cleanup.

flowchart LR
  A[Codex app-server] --> B[Loopback WebSocket]
  B --> C[Execution session]
  C --> D[Sandbox backend and filesystem]
  C --> E[Processes and HTTP]
  C --> F[JSON-RPC responses and notifications]
Loading

Decision needed

Question Recommendation
Should this PR land on the contributor’s pinned-0.148.0 evidence, or wait for direct source verification that environment/add and the connection lifecycle are supported across OpenClaw’s declared 0.147.0–0.148.0 range? Verify upstream contract first: Restore or provide the required Codex source checkout, inspect the relevant protocol and processor paths, and then re-evaluate the existing real-runtime proof.

Why: The patch intentionally changes startup behavior for a compatibility-supported external runtime, and repository policy requires the acting reviewer to inspect the exact Codex source before a verdict or proof-sufficiency claim.

Before merge

  • Resolve merge risk (P1) - Existing custom app-server installations at the declared 0.147.0 floor can now fail startup rather than silently continue if their environment/add behavior differs from the pinned 0.148.0 runtime; the direct upstream source check required to settle that compatibility claim was unavailable.
  • Complete next step (P2) - A maintainer must resolve the direct upstream-contract proof gate before merge; there is no narrow code repair to dispatch.
Agent review details

Security

None.

PR surface

Source -33, Tests +88. Total +55 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 8 256 289 -33
Tests 4 137 49 +88
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 393 338 +55

Review metrics

Metric Value Why it matters
Production versus test LOC production +256/-289 (net -33); tests +137/-49 The refactor reduces production code while adding focused lifecycle and registration coverage.

Stored data model

Persistent data-model change detected: serialized state: extensions/codex/src/app-server/sandbox-exec-server.json-rpc.test.ts, serialized state: extensions/codex/src/app-server/sandbox-exec-server.ts, serialized state: extensions/codex/src/app-server/sandbox-exec-server/json-rpc.ts, serialized state: extensions/codex/src/app-server/sandbox-exec-server/processes.ts, serialized state: extensions/codex/src/app-server/sandbox-exec-server/session.ts, unknown-data-model-change: extensions/codex/src/app-server/sandbox-exec-server/session.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Verify the supported runtime range (recommended)
    Inspect the Codex protocol and environment processor sources for 0.147.0–0.148.0 before merging the fallback removal.
  2. Accept pinned-runtime-only evidence
    Merge with the documented 0.148.0 proof and explicitly own the remaining custom-runtime compatibility uncertainty.

Technical review

Best possible solution:

Keep the single session owner and fail-closed registration behavior after a direct Codex-source check confirms the environment-registration contract for the supported 0.147.0–0.148.0 range.

Do we have a high-confidence way to reproduce the issue?

Not applicable as an issue reproduction: this is a refactor PR, though its body describes a real pinned-runtime success and registration-failure exercise.

Is this the best way to solve the issue?

Unclear: the session extraction is the clean owner-boundary shape, but the fail-closed registration change is not yet independently proven against the declared upstream compatibility range.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against e78b9d3ce4aa.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: The PR changes a bounded optional-plugin execution lifecycle and needs normal maintainer review.
  • merge-risk: 🚨 compatibility: It removes a fallback on an app-server API while OpenClaw still accepts external Codex binaries from version 0.147.0.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.

Evidence

What I checked:

Likely related people:

  • steipete: Current-main blame and the recent exec-server history attribute the central implementation and this refactor to Peter Steinberger. (role: recent area contributor; confidence: high; commits: 0e781ea8d281, fd8326c5bf6f, 0268d7915be6; files: extensions/codex/src/app-server/sandbox-exec-server.ts, extensions/codex/src/app-server/sandbox-exec-server/processes.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Make the required Codex source checkout or equivalent directly inspectable source available, then verify the environment-registration contract across the supported version range.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-20T22:42:18.308Z sha 0268d79 :: needs maintainer review before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

The requested upstream contract and real registration proof is complete on exact head 0268d7915be6bdfb563d6c68a6a6458d64f4a64c.

  • CI: https://github.com/openclaw/openclaw/actions/runs/32422441572 — green.
  • Actual pinned @openai/codex app-server: 0.148.0, started through the production stdio client with isolated empty auth/home state.
  • Upstream source inspected directly at openai/codex@b5ea64a203ce, including the environment/add protocol, processor, environment connection, and exec-server transport/session owners.
  • Success: the real app-server accepted environment/add, reported the environment ready, and connected to the real OpenClaw loopback exec-server. The real WebSocket completed initialize and environment/status. A sandbox child started; release terminated it, finalized once, removed the registry entry, and closed the listener.
  • Failure: the real app-server rejected upstream-invalid execServerUrl=none with JSON-RPC -32600 (remote environment cannot use disabled exec-server url). The error propagated; no thread/start or inference occurred; the environment remained unknown; the OpenClaw lease, registry entry, listener, and owned child state were cleaned up.
  • Supplemental exact-head coverage: 85 tests across registration, session ownership, startup propagation, and cleanup.
  • All relevant source/runtime/package/native hashes remained unchanged, all proof-owned processes exited, isolated state was removed, and sensitive-value inspection passed.

The sandbox backend/fs bridge in the proof were safe synthetic fixtures; the pinned app-server, stdio transport, environment registration, loopback WebSocket, sandbox child, failure response, and cleanup boundaries were real.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 20, 2026
@steipete
steipete merged commit 500fd2c into main Aug 21, 2026
264 checks passed
@steipete
steipete deleted the steipete/codex-exec-server-transport-neutral branch August 21, 2026 00:10
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant