danny-avila/LibreChat · error
"${file_path}" changed while being read from the sandbox
Error message
"${file_path}" changed while being read from the sandbox What it means
Thrown by the chunked image reader (Code/process.js) when the file's total byte count changed between chunks — i.e. parsed.total on a later chunk differs from the total captured on the first chunk. Splicing the buffers would mix two versions of the file, so the read aborts rather than return corrupt data.
Source
Thrown at api/server/services/Files/Code/process.js:1313
if (parsed.error) {
throw new Error(String(parsed.error));
}
if (parsed.too_large === true) {
return { tooLarge: true, bytes: Number(parsed.bytes) || 0 };
}
if (typeof parsed.b64 !== 'string' || typeof parsed.n !== 'number') {
return null;
}
if (total == null) {
total = Number(parsed.total) || 0;
if (total > limit) {
return { tooLarge: true, bytes: total };
}
} else if (Number(parsed.total) !== total) {
/* The file changed underneath us; a spliced-together buffer would be
* a mix of two versions rather than any real image. */
throw new Error(`"${file_path}" changed while being read from the sandbox`);
}
parts.push(Buffer.from(parsed.b64, 'base64'));
offset += parsed.n;
if (parsed.n === 0 || offset >= total) {
break;
}
}
const buffer = Buffer.concat(parts);
if (total == null) {
return null;
}
if (buffer.length !== total) {
/* Ran out of chunk budget (or short reads); returning a partial image
* would render as a corrupt file, so surface it as unreadable-inline. */
return { tooLarge: true, bytes: total };View on GitHub (pinned to 5ff282f900)
Solutions
- Retry the read when the file is quiescent — ensure no concurrent writer is appending to the same path.
- If the file is expected to grow, snapshot it (cp) in the sandbox before reading the snapshot.
- Use a stable, write-once filename convention for agent outputs to avoid in-flight mutation.
Defensive patterns
Strategy: retry
Try / catch
try {
const img = await readSandboxImage({ file_path, session_id, req });
} catch (err) {
if (/changed while being read/.test(err.message)) {
// snapshot then read the snapshot
return readSandboxImage({ file_path: `${file_path}.snap`, session_id, req });
}
throw err;
} Prevention
- Avoid concurrent appends to files being read — use write-once filenames.
- Snapshot (cp) append-prone files in the sandbox before reading.
- Retry once when the file is expected to stabilize.
When it happens
Trigger: A concurrent process in the sandbox is writing/appending the file while the multi-chunk base64 read is in flight; the file was replaced between two chunk requests.
Common situations: An agent tool is logging/appending to the same file the read_file handler is reading; an output redirect overwrote the file mid-read; the sandbox re-used a path across runs.
Related errors
- ${parsed.error}
- Reading "${file_path}" exceeded the sandbox stdout limit (ch
- Unexpected output while reading image bytes from the sandbox
- ${result.stderr}
- Error downloading code environment file stream: ${error.mess
AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12).
Data as JSON: /api/errors/4793036a49e21ddc.
Report an issue: GitHub.