Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai-claude-code): write and remove the run's temp files in parallel #2257

Mergedjbpionnier(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/2257/headmerged by AlemTuzlak View on GitHub

Showing 3 changed files with 188 additions and 12 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/claude-code-parallel-temp-files.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/ai-claude-code': patch
+---
+​
+Write the run's temp files (MCP bridge config, output schema, runner, argv, prompt) in parallel before the spawn, and remove them in parallel after the run. On a remote sandbox each `fs` call is a round trip, so a turn used to wait for up to five writes and five removes one after the other. A failed remove is still ignored.
27 additions and 12 deletionspackages/ai-claude-code/src/adapters/text.tsModified
View file
@@ -546,6 +546,10 @@
// id spells. Computed once so the two filenames cannot drift apart.
const runIdSegment = encodeRunId(runId)
​
+ // The files below are independent, so write them in parallel: on a remote
+ // sandbox each write is a round trip.
+ const pendingWrites: Array<Promise<void>> = []
+​
// The bridge MCP config carries the per-run bearer token. Write it to a
// file and pass claude the PATH, so the token never appears in argv (where
// any process in the sandbox could read it via `ps` / `/proc/<pid>/cmdline`).
@@ -559,7 +563,9 @@
// found". The bare filename resolves correctly on every provider.
const mcpConfigFile = `.tanstack-mcp-bridge-${runIdSegment}.json`
const mcpConfigPath = `${cwd}/${mcpConfigFile}`
- await sandbox.fs.write(mcpConfigPath, bridgeToMcpConfig(bridge))
+ pendingWrites.push(
+ sandbox.fs.write(mcpConfigPath, bridgeToMcpConfig(bridge)),
+ )
tempFiles.push(mcpConfigPath)
mcpConfigArg = mcpConfigFile