Skip to content

fix(sandbox-adapter): stop Pi env calls when the run aborts - #339

Merged
eersnington merged 1 commit into
fix/pi-credential-single-readfrom
fix/pi-env-abort
Oct 8, 2026
Merged

eersnington merged 1 commit into
fix/pi-credential-single-readfrom
fix/pi-env-abort

Conversation

@eersnington

@eersnington eersnington commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Pi passes the run's Context to every env call, and context.abortSignal fires when the run stops (an abort action, a destroy, or the end of the sleep grace period). Only exec read it. A Stop during a sandbox cold start still wrote the file once the sandbox came up, and Pi's abort waited for it.

sequenceDiagram
    participant Client
    participant Pi as Pi Durable
    participant Env as sandboxEnv
    participant Sandbox
    Pi->>Env: writeFile("hello.txt", context)
    Env->>Sandbox: connect() (cold start)
    Client->>Pi: conversation.abort()
    Pi-->>Env: context.abortSignal fires
    Sandbox-->>Env: connected
    Note over Env: before: writes hello.txt<br/>after: returns FileError("aborted")
Loading

Sandbox env (sandbox-env.ts):

-const withSandbox = async (fail, use) => {
+const withSandbox = async (context, fail, use) => {
+	if (context.abortSignal?.aborted) return err(fail(new Error("aborted")));
 	let sandbox;
 	try { sandbox = await connect(); } catch (error) { return err(fail(toError(error))); }
+	if (context.abortSignal?.aborted) return err(fail(new Error("aborted")));
 	return use(sandbox);
 };
  • The connect itself keeps going. It is shared by every call of the Actor generation, so other calls can still use it.
  • A failure while the signal is aborted gets the code aborted, as exec already did.

Database env (database-env.ts):

  • Each operation and each reader call checks the signal before its query.
  • scanLines checks it before each 64 KiB chunk, so a scan of a large file stops early.

This is part 2 of 9 in a stack:

@eersnington eersnington changed the title fix(sandbox-adapter): stop Pi env operations when the run is aborted fix(sandbox-adapter): stop Pi env calls when the run aborts Oct 8, 2026
@eersnington
eersnington added this pull request to stack #347 October 8, 2026 16:05
@eersnington
eersnington merged commit c0ebd7f into main Oct 8, 2026
0 of 3 checks passed
@eersnington
eersnington deleted the fix/pi-env-abort branch October 8, 2026 16:11
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