Repository navigation
fix(sandbox): Report a replaced sandbox session and rotate old sessions - #3710
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
5 screenshot changes — 5 changed · 0 added · 0 removed Review screenshots in Frameshift |
A command killed by a session stop came back as a normal exit (143), and the next call ran on a new sandbox without the old files and said nothing. - After a 137 or 143 exit, probe the session. A stopped session fails the call through the existing sandbox-unavailable tool error. - When a sandbox tool call runs on a new sandbox that lost the earlier files, its result gets a sandbox_notice that says so and asks the agent to check its checkout first. Refs #3047, #3703 Co-Authored-By: David Cramer <[email protected]>
|
With persistence, how do we clean up the persistent volumes? Does that automatically happen, or is there some kind of garbage collection we're going to need or something else Also, given we have execution slice boundaries, that is the heartbeat and requeuing and everything regularly, any kind of limitation around that is a concern |
|
Cleanup: there are no persistent volumes. Conversation sandboxes are created with Slice boundaries: storing the tool session is what removes the slice limitation. Before, the "last tool session" lived in per-Run memory, so a requeue or a new slice forgot it, and the notice could only fire inside one slice. Now every Run reads it from the stored sandbox ref, and the first tool call of any slice compares against it. Resuming a new session after the keepalive lapses, or after a requeue, still produces the notice. One behavior to know about: the ~20h session rotation happens the first time each Run acquires the sandbox, so at the start of every slice, not only at the start of a Turn. A Turn that crosses 20h therefore rotates at its next slice boundary, before any command runs. For a non-persistent sandbox, that drops files in the middle of the Turn, but the agent gets the replaced-sandbox notice on its next call. The alternative is losing them at the 24h cap while a command is running. Checking only at Turn start would leave a long Turn exposed to the cap, so I think the slice boundary is the right point. If you want Turn start only, tell me and I'll change it. These two pieces aren't pushed yet. They're in the next commit on this branch. |
Store the sandbox and session id of the last sandbox tool call in the conversation's sandbox ref, so a later Run still reports a new session that lost the earlier files. Replace a resumed session older than 20 hours before work starts, so the provider's 24-hour session cap does not stop a command mid-Turn.
82708a9 to
5faa7fd
Compare
A Run that resumes a paused Turn keeps its session, so rotation cannot drop unpushed work in the middle of the Turn.
|
Is this sufficiently and correctly covered by integration tests? I want to make sure that whatever the behavior here that we were seeing, we're actually able to regression test against in the future |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b9a86cf. Configure here.
|
I'm not sure what the open questions are |
|
Short answer: each part of the failure has a regression test now, but at the component layer, not integration. One link in the chain is only covered by an opt-in suite. Why component: What fails if it regresses (
Gap I closed in 3ac87cd: nothing checked that the agent run passes Still not covered in CI:
|
|
Fair, that section heading oversells it. None of the four items under "Limits and open questions" needs a decision from you. They're known limits:
The one real open question came from Bugbot's inline comment "Rotation proceeds after a failed stop". Right now, if stopping the old session fails at Turn start, the Turn keeps running on the old session. That's how it worked before this PR, and the kill path plus the notice cover a later cap kill. The alternative is to fail the Turn start when the stop fails. Do you want it to fall back (current) or fail closed? |
Co-Authored-By: David Cramer <[email protected]>
|
I don't totally love the way we're passing this information around, but the core is quite a lot of complexity right now, and I don't have an obvious better solution |

When a Vercel Sandbox session stops during a Turn, two things go wrong today:
HEADcan 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
createSandboxUnavailableToolErrorpath, 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.SandboxRef.toolSessionstores the sandbox and session id of the last sandbox tool call (bash,readFile,writeFile,editFile). It is saved in thread state next toapp_sandbox_id, so it survives Run and execution slice boundaries. A call on a different session gets asandbox_noticein 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.keepsFilesAcrossSessionsreports this. Vercel maps it fromsandbox.persistent. Docker is alwaysfalse, because a restarted container keeps its id, so a new session id is a new container.switchWorkspaceclears it, because the switch result already says that files do not carry over.SandboxSession.startedAtMsgives the session start time. On Vercel it comes from the session'sstartedAt, orcreatedAtwhenstartedAtis not set. On Docker it comes from the container'sStartedAt. 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.sandbox/tool-executors.tsto keepsession.tsunder 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
SandboxRefwith its existingonSandboxRefChangedpersistence. Unknown outcomes from cancelled commands (#915) stay as they are.Limits and open questions
sandbox_notice. If the first call after a replacement is a plugin tool, the agent does not see the notice.via @dcramer.
--
View Session [Sentry]