Skip to content

refactor(sandbox): canonicalize backend ownership - #126828

Merged
steipete merged 1 commit into
mainfrom
steipete/sandbox-adapter-canonicalization
Aug 20, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/sandbox-adapter-canonicalization

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Maintainer-requested sandbox adapter cleanup: OpenShell constructed duplicate backend handle objects, so remote and mirror filesystem bridges could retain a different object from the backend returned by the factory. OpenShell and Codex also duplicated the same existing shell-argument quoting contract.

Why This Change Was Made

The OpenShell implementation now memoizes one canonical backend handle, returns that handle from the factory, and gives the same lifecycle owner to both filesystem bridge modes. OpenShell and the Codex sandbox exec-server reuse the existing openclaw/plugin-sdk/sandbox command builder; remote execution, mirror synchronization, SSH behavior, working-directory validation, and finalization contracts are unchanged. The assertion-safety baseline is ratcheted down solely for the removed assertion.

User Impact

No user-visible behavior changes. Existing OpenShell remote/mirror, SSH sandbox, and Codex process/HTTP/lifecycle behavior and public Plugin SDK contracts are preserved. The internal implementation removes duplicate ownership and quoting paths: production +14/-68 (net -54), regression tests +58/-0, and shrink-only baseline maintenance +1/-1.

Evidence

  • OpenShell owner identity, remote/mirror bridges, workdir handling, and existing E2E discovery: node scripts/run-vitest.mjs extensions/openshell/src/openshell-core.test.ts extensions/openshell/src/backend.exec-workdir.test.ts extensions/openshell/src/backend.e2e.test.ts — 52 passed; 1 live integration intentionally skipped.
  • Codex sandbox process, lifecycle/finalization, and HTTP contracts: node scripts/run-vitest.mjs extensions/codex/src/app-server/sandbox-exec-server.test.ts extensions/codex/src/app-server/sandbox-exec-server.lifecycle.test.ts extensions/codex/src/app-server/sandbox-exec-server.http.test.ts — 48 passed.
  • SSH backend, remote filesystem bridge, and shared command-quoting siblings: node scripts/run-vitest.mjs src/agents/sandbox/ssh-backend.test.ts src/agents/sandbox/remote-fs-bridge.test.ts src/agents/sandbox/ssh.test.ts — 71 passed.
  • Exact changed-file gate: node scripts/check-changed.mjs -- extensions/openshell/src/backend.ts extensions/openshell/src/cli.ts extensions/openshell/src/openshell-core.test.ts extensions/codex/src/app-server/sandbox-exec-server/processes.ts config/assertion-safety-baseline.txt — passed, including 5 plugin-contract tests, assertion-safety ratchets, extension production/test typechecks, lint, boundaries, dead exports, dependency/patch guards, and zero runtime import cycles.
  • git diff --check origin/main...HEAD — passed.
  • Fresh AI-assisted Codex branch autoreview: .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main --stream-engine-output — clean; no actionable findings.
  • The worktree dependency install was refreshed to lockfile-pinned [email protected] without changing any tracked dependency, manifest, patch, or lockfile. Live proof was intentionally not run because this is an internal, behavior-preserving refactor.

@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 20:20
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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, 4:26 PM ET / 20:26 UTC.

ClawSweeper review

What this changes

The PR makes OpenShell return one memoized sandbox backend handle for both filesystem bridge modes and replaces duplicate OpenShell/Codex argv quoting with the existing Plugin SDK command builder.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this maintainer-owned PR open: current main still has the split backend wrappers and duplicated quoting helper, while the proposed canonical-handle refactor preserves the existing shared SDK contract with no actionable defect found.

Priority: P3
Reviewed head: 8d7b4921b71768b7987b8beede0ce3b469ac9926

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-negative refactor with credible owner-boundary coverage and no supported correctness or security finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored internal refactor is not subject to the external contributor real-behavior-proof gate; the PR body supplies focused automated validation as supplemental evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal refactor is not subject to the external contributor real-behavior-proof gate; the PR body supplies focused automated validation as supplemental evidence.
Evidence reviewed 7 items Current-main behavior: Current main returns an outer OpenShell backend wrapper, but its filesystem bridge receives a separate handle created from the implementation; the PR makes the factory return the memoized implementation handle instead.
Canonical owner repair: The proposed handle is memoized and both remote and mirror bridge constructors capture that same factory-returned object.
Caller and bridge boundary: The sandbox context installs the factory backend and calls its bridge factory; each bridge retains and invokes the supplied runtime/backend, so object identity is an owner-boundary invariant.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw --help

Result: PASS (completed)

pnpm openclaw --help
runner@runnervm76f27:/tmp/clawsweeper-live-proof-126828-CqdUT8/target$ pnpm openclaw --help
$ node scripts/run-node.mjs --help
pnpm openclaw --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 99.12 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.7s
node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

[tsdown-build] invocation 2/2 finished in 13.6s
[plugin-control-plane-loads] verified 35 built modules with native require and checked doctor closures
runtime-postbuild: 10 phases completed in 4180ms (slowest: built plugin control-plane loads 3441ms)

OpenClaw 2026.8.1 (8d7b492) — All your chats, one OpenClaw.

Usage: openclaw [options] [command]

Options:
  --container ‹name›   Run the CLI inside a running Podman/Docker container named ‹name› (default: env OPENCLAW_CONTAINER)
  --dev                Dev profile: isolate state under ~/.openclaw-dev, default gateway port 19001, and shift derived ports (browser/canvas)
  -h, --help           Display help for command
  --log-level ‹level›  Global log level override for file + console 
… output truncated …

Assertions:

  • PASS expect_output: Usage: openclaw

How this fits together

Sandbox factories supply a backend to the agent runtime, which then creates an execution specification and a filesystem bridge from that backend. OpenShell uses SSH-backed remote or mirror workspaces, while the Codex extension routes app-server process requests through the same sandbox backend contract.

flowchart LR
A[Sandbox configuration] --> B[OpenShell backend factory]
B --> C[Canonical backend handle]
C --> D[Process execution]
C --> E[Remote or mirror filesystem bridge]
D --> F[SSH-backed sandbox]
E --> F
G[Codex process request] --> D
Loading

Before merge

  • Resolve merge risk (P1) - Exact-head CI was still in progress; landing should use the completed result for the rebased merge head.
  • Complete next step (P2) - No concrete repair remains from review; await normal exact-head CI and merge handling.
Agent review details

Security

None.

PR surface

Source -54, Tests +58, Other 0. Total +4 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 14 68 -54
Tests 1 58 0 +58
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 5 73 69 +4

Review metrics

Metric Value Why it matters
Production versus test delta production -54 net, tests +58, baseline 0 net The refactor removes duplicated production wrappers and quoting code while adding focused owner-boundary coverage.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the canonical-handle refactor after exact-head CI completes, preserving the single shared Plugin SDK quoting path and the factory-to-bridge identity regression coverage.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the canonical-handle refactor after exact-head CI completes, preserving the single shared Plugin SDK quoting path and the factory-to-bridge identity regression coverage.

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

Not applicable; this is a refactor PR, and the stated former split-owner behavior is directly established by current-main source plus focused regression coverage.

Is this the best way to solve the issue?

Yes; reusing the existing public sandbox command builder and making the factory-returned handle canonical removes duplicate paths without expanding the Plugin SDK.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a behavior-preserving internal cleanup with focused regression coverage and no demonstrated user-facing regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored internal refactor is not subject to the external contributor real-behavior-proof gate; the PR body supplies focused automated validation as supplemental evidence.

Label justifications:

  • P3: This is a behavior-preserving internal cleanup with focused regression coverage and no demonstrated user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored internal refactor is not subject to the external contributor real-behavior-proof gate; the PR body supplies focused automated validation as supplemental evidence.

Evidence

What I checked:

  • Current-main behavior: Current main returns an outer OpenShell backend wrapper, but its filesystem bridge receives a separate handle created from the implementation; the PR makes the factory return the memoized implementation handle instead. (extensions/openshell/src/backend.ts:280, ddf73d4ca2ef)
  • Canonical owner repair: The proposed handle is memoized and both remote and mirror bridge constructors capture that same factory-returned object. (extensions/openshell/src/backend.ts:302, 8d7b4921b717)
  • Caller and bridge boundary: The sandbox context installs the factory backend and calls its bridge factory; each bridge retains and invokes the supplied runtime/backend, so object identity is an owner-boundary invariant. (src/agents/sandbox/context.ts:341, ddf73d4ca2ef)
  • Shared command-builder contract: The Codex extension now consumes the existing public Plugin SDK builder, whose implementation single-quotes each literal argv item exactly as the removed local helpers did; this is an OpenClaw SDK contract, not an upstream Codex runtime dependency. (src/agents/sandbox/ssh.ts:80, 9dc391c75bd9)
  • Behavioral regression coverage: The new table-driven test invokes the factory, creates both bridge modes, and verifies that remote stat and mirror sync call methods on the factory-returned handle; it would fail against the current-main split-wrapper behavior. (extensions/openshell/src/openshell-core.test.ts:872, 8d7b4921b717)
  • Existing Codex execution coverage: The existing app-server test exercises a sandboxed process through the backend and asserts the exact quoted command, process output, lifecycle notifications, and secret scrubbing. (extensions/codex/src/app-server/sandbox-exec-server.test.ts:162, 8d7b4921b717)

Likely related people:

  • steipete: Recent merged work owns the exact Codex process surface and broader OpenShell/Codex sandbox area. (role: recent sandbox and Codex process contributor; confidence: high; commits: fd8326c5bf6f, 0a6b95a3df9f, 8d7b4921b717; files: extensions/codex/src/app-server/sandbox-exec-server/processes.ts, extensions/openshell/src/backend.ts)
  • vincentkoc: The workspace-scoping repair touched the exact OpenShell backend factory and its core test boundary. (role: historic OpenShell factory contributor; confidence: medium; commits: 30346f97883c; files: extensions/openshell/src/backend.ts, extensions/openshell/src/openshell-core.test.ts)

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.

@steipete
steipete merged commit 1362490 into main Aug 20, 2026
255 checks passed
@steipete
steipete deleted the steipete/sandbox-adapter-canonicalization branch August 20, 2026 20:52
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 21, 2026
Rorqualx pushed a commit to Rorqualx/cortex that referenced this pull request Aug 25, 2026
… advance 80)

Resolution (13 raw conflicts; 12 ui resolved by fork-ownership policy):

- pnpm-lock.yaml: regenerated via pnpm install (derived file).
- extensions/openshell/src/openshell-core.test.ts (merge=ours drift): ADOPT-UPSTREAM
  openclaw#129258 fixture dedup + openclaw#120996 tempWorkspace migration + openclaw#126828 canonical-owner
  test (fork's makeTempDir shape + missing test were stale freezes of older upstream
  code, not fork intent). Grafted fork's one genuine delta: required
  SandboxConfig.osSandbox block into createOpenShellBackendSandboxConfig.
- src/agents/cli-runner.reliability.test.ts (merge=ours drift): clean 3-way
  merge-file. Kept fork tests + upstream openclaw#125085 (codex->agent-cli literals,
  watchdog resume tuning test; math verified against merged reliability.ts).
- src/agents/embedded-agent-runner/run/incomplete-turn-recovery.ts: ADOPT-UPSTREAM
  (preflight tsgo-core=1 catch: upstream consumer openclaw#128970 imports
  resolveSettledToolBatchEvidence which merge churn had dropped from the fork
  provider; export surface differs by exactly this extraction; fork toolMetas
  type carries toolCallId?/terminate?/isError?).
- ui/src/ui/markdown.ts: explicit param types on the linkify www plugin callbacks
  (validate/normalize). @types/markdown-it 14.1.2->14.2.0 (upstream dep bump)
  dropped contextual typing for them; the fork-owned ui copy now types them inline
  per linkify-it's Validate/Match signatures (upstream adapted its own ui tree the
  same way). Only ui file needed it; tsgo:test:ui 3->0 locally.

Note: ui tree-hash invariant vs main intentionally broken by this one adaptation —
main's ui does not compile against the new lockfile (baseline 0 was measured with
@types 14.1.2).

No product-collision: no codex/** residuals.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex extensions: openshell maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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