Skip to content

fix(sandbox): initialize API client in Command before reading output#130

Merged
QuiiBz merged 1 commit intomainfrom
nr/fix-command-ensure-client
Apr 2, 2026
Merged

fix(sandbox): initialize API client in Command before reading output#130
QuiiBz merged 1 commit intomainfrom
nr/fix-command-ensure-client

Conversation

@TooTallNate
Copy link
Copy Markdown
Member

@TooTallNate TooTallNate commented Apr 2, 2026

Summary

  • Fixes stdout(), stderr(), and output() failing with "logs() requires an API client" on deserialized Command/CommandFinished instances
  • After workflow deserialization, _client is null. getCachedOutput() calls logs() which is synchronous and throws immediately if _client is not set. The fix calls ensureClient() before logs() to lazily initialize the client.
  • Adds throwIfAborted() guard before ensureClient() to short-circuit on already-aborted signals, matching the pattern in wait()
  • Adds a test for deserialized CommandFinished without cached output to exercise the fix

Copilot AI review requested due to automatic review settings April 2, 2026 08:19
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 2, 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 2, 2026 4:07pm
sandbox-cli Ready Ready Preview, Comment, Open in v0 Apr 2, 2026 4:07pm
sandbox-sdk Ready Ready Preview, Comment, Open in v0 Apr 2, 2026 4:07pm
sandbox-sdk-ai-example Ready Ready Preview, Comment, Open in v0 Apr 2, 2026 4:07pm
workflow-code-runner Ready Ready Preview, Comment, Open in v0 Apr 2, 2026 4:07pm

Request Review

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a workflow deserialization edge-case in @vercel/sandbox where Command/CommandFinished instances lose their _client, causing stdout()/stderr()/output() to fail when getCachedOutput() synchronously calls logs().

Changes:

  • Initialize the API client inside Command.getCachedOutput() before invoking logs().
  • Add a patch changeset describing the fix for deserialized Command instances.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/vercel-sandbox/src/command.ts Ensures _client is lazily initialized before logs() is called during cached output retrieval.
.changeset/fix-command-ensure-client.md Publishes the fix as a patch with a clear user-facing note.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@QuiiBz QuiiBz merged commit b91b9e4 into main Apr 2, 2026
14 checks passed
@QuiiBz QuiiBz deleted the nr/fix-command-ensure-client branch April 2, 2026 18:05
QuiiBz pushed a commit that referenced this pull request Apr 2, 2026
…tion (#129)

## Summary

- Removes `steps/sandbox.ts` — the wrapper functions (`createSandbox`,
`execute`, `stopSandbox`) were redundant since `Sandbox.create()` and
all instance methods already have `"use step"` built in
- Inlines all Sandbox calls directly in the `"use workflow"` function in
`workflows/code-runner.ts`
- Passes code as a string to `writeFiles()` instead of wrapping with
`Buffer.from()` (which is unavailable in the workflow runtime)

Depends on #130.
@github-actions github-actions bot mentioned this pull request Apr 2, 2026
QuiiBz pushed a commit that referenced this pull request Apr 2, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## sandbox@2.5.8

### Patch Changes

- Updated dependencies
\[[`b91b9e49fb7d2c5a4b601c07c125e6e5a2c43441`](b91b9e4)]:
    -   @vercel/sandbox@1.9.2

## @vercel/sandbox@1.9.2

### Patch Changes

- Fix `stdout()`/`stderr()`/`output()` failing on deserialized `Command`
instances with "logs() requires an API client" error.
([#130](#130))

## sandbox-filesystem-snapshots@0.0.13

### Patch Changes

- Updated dependencies
\[[`b91b9e49fb7d2c5a4b601c07c125e6e5a2c43441`](b91b9e4)]:
    -   @vercel/sandbox@1.9.2

## workflow-code-runner@0.1.2

### Patch Changes

- Updated dependencies
\[[`b91b9e49fb7d2c5a4b601c07c125e6e5a2c43441`](b91b9e4)]:
    -   @vercel/sandbox@1.9.2

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

3 participants