Skip to content

fix: handle empty response body from background commands in runCommand#123

Open
johnlindquist wants to merge 1 commit intonamed-sandboxesfrom
fix/runcommand-background-zod-crash
Open

fix: handle empty response body from background commands in runCommand#123
johnlindquist wants to merge 1 commit intonamed-sandboxesfrom
fix/runcommand-background-zod-crash

Conversation

@johnlindquist
Copy link
Copy Markdown

@johnlindquist johnlindquist commented Apr 1, 2026

Note: I ran across this issue working on an openclaw project. I had this repo checked out and the agent offered to create a PR, so I just let it. Not sure if this is a legit issue or a good solution, but thought I'd let the PR through since I was struggling with it.

Summary

When runCommand executes a bash command containing & (background process), the v2 API endpoint /v2/sandboxes/sessions/{id}/cmd returns 200 with an empty body. The non-detached code path passes this to parseOrThrow(CommandResponse, ...), which fails because the command field is required:

[{"code":"invalid_type","expected":"object","received":"undefined","path":[],"message":"Required"}]

This affects any command that backgrounds a process:

  • sb.runCommand("bash", ["-c", "node server.js &"])
  • sb.runCommand("bash", ["/path/to/script-with-ampersand.sh"])

detached: true is unaffected (uses the NDJSON streaming path).

Fix

Before calling parseOrThrow, check if the response body is empty. If it is (and status is OK), return a synthetic CommandResponse populated from the request params instead of trying to parse undefined.

Test plan

  • New test: empty body returns synthetic command with correct fields
  • New test: normal non-wait response still parses correctly (regression)
  • All 82 existing package tests pass

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sandbox Ready Ready Preview, Comment, Open in v0 Apr 1, 2026 6:11am
sandbox-cli Ready Ready Preview, Comment, Open in v0 Apr 1, 2026 6:11am
sandbox-sdk Ready Ready Preview, Comment, Open in v0 Apr 1, 2026 6:11am
sandbox-sdk-ai-example Ready Ready Preview, Comment, Open in v0 Apr 1, 2026 6:11am

Request Review

johnlindquist added a commit to vercel-labs/vercel-openclaw that referenced this pull request Apr 1, 2026
…fined

Revert the beta SDK + detached bootstrap changes (357593f) to restore
production stability. The beta SDK works correctly for basic ops but the
startup script's pkill replacement (ps|grep|kill pattern) fails under
set -euo pipefail in the beta sandbox's v2 session API.

Progress saved in sandbox-beta-migration-wip.patch and the SDK fix PR
at vercel/sandbox#123 is still open.

Key findings from this session:
- Beta SDK (2.0.0-beta.9) basic ops work (create, runCommand, detached, domain)
- pkill returns exit 255 in v2 API (kills parent script)
- runCommand with & background processes crashes with Zod validation error
- detached:true mode works perfectly as replacement
- openclaw@latest config schema is compatible with our buildGatewayConfig()
- openclaw gateway --port 3000 (old syntax) still works
@LukeSheard LukeSheard changed the base branch from main to named-sandboxes April 1, 2026 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant