Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai-sandbox-vercel): write files with one writeFiles upload instead of one exec per 32 KiB chunk #2256

Mergedjbpionnier(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/2256/headmerged by AlemTuzlak View on GitHub

Showing 4 changed files with 25 additions and 44 deletions (loading 1).

x
0 of 4 viewed, 4 left
5 additions and 0 deletions.changeset/vercel-fs-write-single-upload.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/ai-sandbox-vercel': patch
+---
+​
+`fs.write` now uploads the file with one `sandbox.writeFiles` call. It used to run one `exec` per 32 KiB chunk, so a 1 MiB file took 33 round trips, and a failed write left a truncated file. The abort signal now reaches the upload. A failed upload throws `write failed: <path>: <reason>`, with the SDK error as `cause`.
0 additions and 35 deletionspackages/ai-sandbox-vercel/src/fs-write.tsDeleted
@@ -1,35 +0,0 @@
-/**
- * Build in-container `sh -c` commands that write a file without putting the
- * whole payload on one argv.
- *
- * Linux `MAX_ARG_STRLEN` is 128 KiB for a single argument. A snapshot restore
- * of a lockfile or generated source exceeds that when the bytes are quoted
- * into `printf`.
- */
-​
-/** Stay well under `MAX_ARG_STRLEN` after base64 and quoting. */
-export const FS_WRITE_BYTE_CHUNK = 32_768
-​
-function quote(value: string): string {
- return `'${value.replace(/'/g, `'\\''`)}'`
-}
-​
-export function fsWriteCommands(
- abs: string,
- data: string | Uint8Array,
-): Array<string> {
- const bytes =
- typeof data === 'string' ? Buffer.from(data, 'utf8') : Buffer.from(data)