Cloudflare sandbox adapter drops the caller AbortSignal

Open Beginner friendly
#720 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
backend, cloud

Research direction

Start in packages/runtime/src/cloudflare/cf-sandbox.ts at cfSandboxToSandbox.exec and review the CloudflareSandboxStub.exec options. Verify how SessionEnv.exec supplies its AbortSignal, then forward it through the adapter. Done means aborting a running command cancels the container work instead of leaving the sandbox command slot occupied.

Written by the indexing model from the issue text.

Description

@flue/runtime 2.0.8, Cloudflare target.

Summary

cfSandboxToSandbox.exec does not forward the caller's AbortSignal to @cloudflare/sandbox. SessionEnv.exec rejects promptly when the signal aborts, as documented in the 2.0.0 changelog, but the command continues to run in the container.

Observed behaviour

When a caller aborts a running command, Flue's exec abort race releases the tool immediately. The underlying command is not cancelled. With a sandbox that permits one command at a time, reads and commands from the next turn wait until the abandoned command ends.

Cause

In packages/runtime/src/cloudflare/cf-sandbox.ts, the adapter passes only cwd, env, and timeout to sandbox.exec:

const result = await guarded(
  'exec',
  sandbox.exec(command, {
    cwd: execOpts?.cwd,
    env: execOpts?.env,
    timeout: execOpts?.timeoutMs,
  }),
);

@cloudflare/sandbox accepts signal in its exec options, but CloudflareSandboxStub.exec does not declare it and the adapter does not forward it.

Proposed change

 export interface CloudflareSandboxStub {
   exec(command: string, options?: {
     cwd?: string;
     env?: Record<string, string>;
     timeout?: number;
+    signal?: AbortSignal;
   }): Promise<...>;
 }
 sandbox.exec(command, {
   cwd: execOpts?.cwd,
   env: execOpts?.env,
   timeout: execOpts?.timeoutMs,
+  signal: execOpts?.signal,
 })

Impact

An aborted command stops in the container instead of occupying its command slot after the caller has moved on. This lets the next turn use the sandbox without waiting for orphaned work to finish.

Dominant language
TypeScript
Stars
8.3k
Forks
496
Avg merge
4h 7m
Merged PRs (30d)
19

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from withastro/flue

All issues in withastro/flue

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.