Skip to content

Conversation

@ghostwriternr
Copy link
Member

Commands executing concurrently within the same session could cause race conditions and interleaved output. This adds per-session mutexes using async-mutex to serialize execution within each session while preserving parallelism across different sessions.

The withSession API enables atomic multi-command operations where the lock is held for the entire callback. Background streaming mode allows long-running processes like servers to release the lock after startup so other commands can proceed.

Commands executing concurrently within the same session could cause
race conditions and interleaved output. This adds per-session mutexes
using async-mutex to serialize execution within each session while
preserving parallelism across different sessions.

The withSession API enables atomic multi-command operations where the
lock is held for the entire callback. Background streaming mode allows
long-running processes like servers to release the lock after startup
so other commands can proceed.
@changeset-bot
Copy link

changeset-bot bot commented Dec 10, 2025

🦋 Changeset detected

Latest commit: 386ce36

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/sandbox Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 10, 2025

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/sandbox-sdk/@cloudflare/sandbox@290

commit: 386ce36

@github-actions
Copy link
Contributor

github-actions bot commented Dec 10, 2025

🐳 Docker Images Published

Default (no Python):

FROM cloudflare/sandbox:0.0.0-pr-290-2efc48e

With Python:

FROM cloudflare/sandbox:0.0.0-pr-290-2efc48e-python

With OpenCode:

FROM cloudflare/sandbox:0.0.0-pr-290-2efc48e-opencode

Version: 0.0.0-pr-290-2efc48e

Use the -python variant for Python code execution, or -opencode for the OpenCode AI coding agent.

claude[bot]

This comment was marked as outdated.

Reduced unit test file from 303 to 197 lines by removing tests that
checked timing measurements and implicit behaviors. Added E2E test
for concurrent same-session access to the session isolation test file.
agents-git-bot bot pushed a commit to cloudflare/cloudflare-docs that referenced this pull request Dec 10, 2025
Add documentation explaining that commands within the same session execute
serially while commands across different sessions run in parallel. This
prevents race conditions and ensures predictable output within sessions.

Key additions:
- New "Concurrency and execution order" section explaining serial vs parallel execution
- Examples demonstrating session-based parallelism for independent tasks
- Best practices for choosing when to use same vs different sessions
- Guidance on using multiple sessions for concurrent task execution

Related to cloudflare/sandbox-sdk#290

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
claude[bot]

This comment was marked as outdated.

Fix setEnvVars to throw proper ServiceError with COMMAND_EXECUTION_ERROR
code and CommandErrorContext details instead of generic Error. Expand
deadlock warning to cover both withSession and executeInSession.
claude[bot]

This comment was marked as outdated.

Clarify getOrCreateSession JSDoc to explain why callers must hold the
session lock. Add cleanup of sessionLocks when session creation fails
to prevent minor memory leaks.
claude[bot]

This comment was marked as outdated.

GitManager.determineErrorCode() was returning custom strings like
'REPO_NOT_FOUND' that aren't in the ErrorCode enum. This caused
withSession's error validation to reject them as unknown errors.
Map all return values to proper ErrorCode constants.
claude[bot]

This comment was marked as outdated.

@ghostwriternr ghostwriternr merged commit 2322c80 into main Dec 11, 2025
19 of 22 checks passed
@ghostwriternr ghostwriternr deleted the parallel-exec branch December 11, 2025 05:36
@github-actions github-actions bot mentioned this pull request Dec 11, 2025
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