Skip to content

fix(sandbox): Preserve unknown command outcomes - #915

Merged
dcramer merged 1 commit into
mainfrom
fix/unknown-sandbox-command-outcome
Jul 15, 2026
Merged

dcramer merged 1 commit into
mainfrom
fix/unknown-sandbox-command-outcome

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Treat agent-cancelled sandbox commands as having an unknown outcome instead of reporting an ordinary nonzero exit. Commands interrupted after an upstream mutation may still have completed, so continuations must see that ambiguity and reconcile external state before retrying or reporting failure.

Outcome contract

The bash result now preserves the sandbox runner's aborted signal, returns error.kind: "outcome_unknown", and emits matching telemetry. The result remains non-retryable so the model does not blindly repeat a potentially completed mutation.

Regression coverage

Adds a component scenario where a simulated git push applies its remote side effect as cancellation arrives. The test verifies that Junior reports the outcome as unknown rather than a definitive command failure.

Requested by immutable dcramer via Junior.

--

View Junior Session in Sentry

@vercel

vercel Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
junior-docs Ready Ready Preview Jul 15, 2026 5:37pm

Request Review

@dcramer
dcramer marked this pull request as ready for review July 15, 2026 17:38
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Jul 15, 2026
@dcramer
dcramer merged commit 6fb73cc into main Jul 15, 2026
34 checks passed
@dcramer
dcramer deleted the fix/unknown-sandbox-command-outcome branch July 15, 2026 17:42
dcramer added a commit that referenced this pull request Nov 22, 2026
…ns (#3710)

When a Vercel Sandbox session stops during a Turn, two things go wrong
today:

1. The provider kills the running command with a signal and returns a
normal command result, so the call reads as an ordinary non-zero exit
and never reaches the sandbox-unavailable tool error.
2. The next call reacquires the sandbox. A non-persistent sandbox
resumes into a new session from its source snapshot, and the agent is
not told. Local commits and other files are gone. An agent that then
pushes `HEAD` can push an old commit over its own work.

Vercel stops a session 24 hours after it starts, so a long conversation
can lose its session in the middle of a Turn.

Context: #3047. #3703 is the push-guard
backstop for the same failure.

## Change

- **Kill path.** After a SIGTERM or SIGKILL exit, the bash executor
probes the session with the probe that cached sessions already use. A
stopped session throws the provider error. That marks the session
unavailable and goes through the existing
`createSandboxUnavailableToolError` path, which says the outcome is not
reliable and the next call uses a fresh session. When the session is
live, or the probe fails for another reason, the command's own exit
stands.
- **Replacement notice.** `SandboxRef.toolSession` stores the sandbox
and session id of the last sandbox tool call (`bash`, `readFile`,
`writeFile`, `editFile`). It is saved in thread state next to
`app_sandbox_id`, so it survives Run and execution slice boundaries. A
call on a different session gets a `sandbox_notice` in its result when
the earlier files are gone: the Sandbox changed, or a new session
started on a Sandbox that does not keep files across sessions. The
notice says that files and local commits are gone and to check HEAD and
the branch before acting. This also covers a conversation that stayed
idle past the keepalive and resumes into a new session.
- `SandboxSession.keepsFilesAcrossSessions` reports this. Vercel maps it
from `sandbox.persistent`. Docker is always `false`, because a restarted
container keeps its id, so a new session id is a new container.
- Only tool calls update the stored session, so the between-step
AGENTS.md read cannot hide a replacement.
- `switchWorkspace` clears it, because the switch result already says
that files do not carry over.
- **Session rotation at Turn start.** `SandboxSession.startedAtMs` gives
the session start time. On Vercel it comes from the session's
`startedAt`, or `createdAt` when `startedAt` is not set. On Docker it
comes from the container's `StartedAt`. When the first Run of a Turn
reopens a stored sandbox whose session is older than 20 hours, it stops
that session and resumes a new one before any work starts. A Run that
resumes a paused Turn keeps its session, so rotation does not drop
unpushed work in the middle of a Turn. A sandbox that does not keep
files gets the replacement notice on its next tool call.
- The bash, file, and command executors move to
`sandbox/tool-executors.ts` to keep `session.ts` under the file length
limit. The only behavior change there is the probe.

Reused: the sandbox-unavailable tool error and session invalidation, the
probe from the reacquire path in #3515, and the stored
`SandboxRef` with its existing `onSandboxRefChanged` persistence.
Unknown outcomes from cancelled commands (#915) stay as
they are.

## Limits and open questions

- **Turn start after recovery.** "Turn start" means the Turn has no
paused record. When recovery restarts a Turn after a lost worker without
a paused record, that Run can still rotate an old session.
- **Persistent sandboxes.** Rotation stops the session and resumes it
right away. Conversation sandboxes are non-persistent today. For a
persistent sandbox, a resume while the stop still snapshots has not been
checked against the live API.
- **Plugin tools.** A plugin tool that runs a command through the
sandbox records the new session too, and it drops `sandbox_notice`. If
the first call after a replacement is a plugin tool, the agent does not
see the notice.
- **Stop timing.** The kill check assumes the session API rejects the
probe right after the provider kills the command. If a stopping session
still accepts the probe, the kill is reported as a normal exit, and the
next call still gets the replacement notice.

<!-- junior-request-attribution:start -->
via @dcramer.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A2129e94419c987dc504daaf71f9cea79 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A2129e94419c987dc504daaf71f9cea79)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A2129e94419c987dc504daaf71f9cea79/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: David Cramer <[email protected]>

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 945cc32b Deployed Jul 15, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant