An open-source, faster Devin alternative
TypeScript
Review fixes: stream-upload opt-out, exec 404 fallback, proxy comment
Brian Reardonb86e96750752
diff --git a/internal/proxy/sandbox_api_proxy.go b/internal/proxy/sandbox_api_proxy.goindex 0812e075..0b13f8f8 100644--- a/internal/proxy/sandbox_api_proxy.go+++ b/internal/proxy/sandbox_api_proxy.go@@ -260,10 +260,10 @@ func (p *SandboxAPIProxy) ProxyHandler(c echo.Context) error {// If hibernated, wake on demand.if session.Status == "hibernated" {- // Async exec path (POST /exec/run, GET …/result): never hold the+ // Async exec path (POST /exec/run-async, GET …/result): never hold the// connection on the restore — a large cold checkpoint can exceed// Cloudflare's 100s and 524. Claim a worker (atomic CAS) and forward- // immediately; the worker's execRun returns a handle right away and+ // immediately; the worker's execRunAsync returns a handle right away and// self-restores in the background (router doWake), off the connection.// /result is DB-routed to that worker, so this is correct across// multiple control planes. Other (synchronous) ops keep the inline wake.diff --git a/sdks/typescript/src/exec.ts b/sdks/typescript/src/exec.tsindex a764b68a..a54232fc 100644--- a/sdks/typescript/src/exec.ts+++ b/sdks/typescript/src/exec.ts@@ -367,12 +367,25 @@ export class Exec {if (opts.cwd) body.cwd = opts.cwd;body.timeout = opts.timeout != null ? opts.timeout : 60;- const resp = await fetch(`${this.apiUrl}/sandboxes/${this.sandboxId}/exec/run-async`, {+ let resp = await fetch(`${this.apiUrl}/sandboxes/${this.sandboxId}/exec/run-async`, {method: "POST",headers: this.headers,body: JSON.stringify(body),});+ // Graceful degradation: a server (CP or worker) that predates the async+ // endpoint returns 404. Fall back to the legacy synchronous /exec/run, which+ // returns the full result directly — what older SDKs always used. (A genuine+ // "sandbox not found" 404s here too and re-404s below, surfacing the same+ // error.)+ if (resp.status === 404) {+ resp = await fetch(`${this.apiUrl}/sandboxes/${this.sandboxId}/exec/run`, {+ method: "POST",+ headers: this.headers,+ body: JSON.stringify(body),+ });+ }+if (!resp.ok) {const text = await resp.text();throw new Error(`Failed to run command: ${resp.status} ${text}`);@@ -380,8 +393,8 @@ export class Exec {const handle = (await resp.json()) as ExecRunHandle;- // Back-compat: a worker without the async endpoint (synchronous origin)- // returns the full result directly.+ // Legacy synchronous origin (the 404 fallback above) returns the full result+ // directly, with no execId to poll.if (handle.execId == null && handle.exitCode != null) {return {exitCode: handle.exitCode,diff --git a/sdks/typescript/src/filesystem.ts b/sdks/typescript/src/filesystem.tsindex 1be18e23..f55d882d 100644--- a/sdks/typescript/src/filesystem.ts+++ b/sdks/typescript/src/filesystem.ts@@ -62,14 +62,22 @@ export class Filesystem {}async write(path: string, content: string | Uint8Array | ReadableStream<Uint8Array>): Promise<void> {+ const isStream = content instanceof ReadableStream;+ const headers = { ...this.headers };+ if (isStream) {+ // A stream body can't be replayed across a 503-waking retry, so opt out of+ // the async-wake flow (drop X-OSB-Async-Wake): on a cold box the control+ // plane wakes synchronously on this connection, as it did before, rather+ // than returning a 503 we couldn't retry.+ delete headers["X-OSB-Async-Wake"];+ }const opts: RequestInit & Record<string, unknown> = {method: "PUT",- headers: this.headers,+ headers,body: content as BodyInit,};// duplex: "half" is required for ReadableStream bodies in Node.js fetch,// but must NOT be set for Uint8Array/Buffer/string bodies.- const isStream = content instanceof ReadableStream;if (isStream) {opts.duplex = "half";}