fix(ts): surface incomplete sandbox run instead of silent success#718
Open
sgirones wants to merge 1 commit into
Open
fix(ts): surface incomplete sandbox run instead of silent success#718sgirones wants to merge 1 commit into
sgirones wants to merge 1 commit into
Conversation
`Sandbox.run()` streams `POST /api/v1/processes/run` and only sets
`exitCode` when it sees an `exit_code`/`signal` event. If the stream ends
without one — e.g. the sandbox is unreachable and the proxy closes the
stream after a timeout — it returned `{ exitCode: -1, stdout: "", stderr: "" }`
and never threw. Callers saw a fake success for a command that never ran.
Track whether a terminal event arrived and throw `SandboxConnectionError`
when it didn't. This matches the canonical behavior in the Rust CLI
(`crates/cli/src/commands/sbx/exec.rs`), which treats a missing exit event
as failure (`exit_code.unwrap_or(1)`).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Sandbox.run()(the method behindrunCommand) streamsPOST /api/v1/processes/runand only setsexitCodewhen it observes anexit_code/signalevent. When the SSE stream ends without a terminal event, it fell through to:…and never threw. Callers got a successful
CommandResultwith empty output for a command that never actually ran.How it shows up
Running a sandbox benchmark against a dev endpoint, every
execreturned "success" with empty stdout after a fixed ~48s. Tracing it end-to-end:node -vin ~11ms (direct and via the dataplane's own http_proxy).Failed to send signal: No processes spawned).sandbox.<env>), which couldn't route to the executor; it closed the stream after a timeout without anyexit_code.{ exitCode: -1, stdout: "" }→ the harness counted 100/100 "ok" for commands that never executed.The underlying routing problem is dev infrastructure (separate issue), but the SDK masking it as success is a real correctness bug.
Fix
Track whether a terminal (
exit_code/signal) event arrived; if the stream ends without one, throwSandboxConnectionErrorinstead of returning a misleading success.This matches the canonical behavior already in the repo's Rust CLI (
crates/cli/src/commands/sbx/exec.rs), which treats a missing exit event as failure (exit_code.unwrap_or(1)→ non-zero → error).Tests
tests/sandbox.test.tsreproducing the unreachable case (run stream with noexit_code) → assertsrun()rejects.tsc --noEmitclean; full suite green (189 tests, unit + integration).Out of scope
-signalwhile the Rust CLI uses128 + signal; worth aligning separately.🤖 Generated with Claude Code