danny-avila/LibreChat · error

Error downloading code environment file stream: ${error.mess

Error message

Error downloading code environment file stream: ${error.message}

What it means

Thrown by getCodeOutputDownloadStream (Code/crud.js) when the axios GET to the code-execution server's /download/{fileIdentifier} endpoint fails. The original axios error is wrapped via logAxiosError which records full request/response diagnostics before re-throwing.

Source

Thrown at api/server/services/Files/Code/crud.js:52

    const authHeaders = await getCodeApiAuthHeaders(req);
    /** @type {import('axios').AxiosRequestConfig} */
    const options = {
      method: 'get',
      url: `${baseURL}/download/${fileIdentifier}${query}`,
      responseType: 'stream',
      headers: {
        'User-Agent': 'LibreChat/1.0',
        ...authHeaders,
      },
      httpAgent: codeServerHttpAgent,
      httpsAgent: codeServerHttpsAgent,
      timeout: 15000,
    };

    const response = await axios(options);
    return response;
  } catch (error) {
    throw new Error(
      logAxiosError({
        message: `Error downloading code environment file stream: ${error.message}`,
        error,
      }),
    );
  }
}

/**
 * Deletes a file from the Code Environment server.
 *
 * @param {ServerRequest} req - Current authenticated request, used to mint Code API auth.
 * @param {MongoFile} file - File metadata containing `metadata.codeEnvRef`.
 * @returns {Promise<void>}
 */
async function deleteCodeEnvFile(req, file) {
  const ref = file?.metadata?.codeEnvRef;
  if (!ref) {

View on GitHub (pinned to 5ff282f900)

Solutions

  1. Confirm getCodeBaseURL() returns the correct, reachable code server URL.
  2. Check server logs for the logAxiosError diagnostics (status, url, responseData) which reveal the underlying cause.
  3. Verify getCodeApiAuthHeaders(req) successfully mints auth and that req.user is populated.
  4. Retry once for transient network/timeout failures; treat 404 as 'file no longer on the sandbox'.
Defensive patterns

Strategy: try-catch

Validate before calling

// Confirm the code server is reachable and fileIdentifier well-formed
const baseURL = getCodeBaseURL();
if (!baseURL) throw new Error('Code server URL not configured');
if (!/^\S+\/\S+$/.test(fileIdentifier)) throw new Error('Malformed fileIdentifier');

Try / catch

try {
  const stream = await getCodeOutputDownloadStream(fileIdentifier, identity, req);
} catch (err) {
  if (/404/.test(err.message)) {
    // treat as gone — no retry
    return null;
  }
  // transient: retry once
  return getCodeOutputDownloadStream(fileIdentifier, identity, req);
}

Prevention

When it happens

Trigger: Network failure, timeout (15s), non-2xx from codeapi, bad fileIdentifier, missing/invalid Code API auth headers, or the code server being unreachable (wrong baseURL).

Common situations: CODE_API_BASE_URL misconfigured or pointing at a downed sandbox service; auth token minting failed (getCodeApiAuthHeaders); the session_id/fileId pair is stale or already expired on the code server; transient network blip.

Related errors


AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12). Data as JSON: /api/errors/a689cb6b45b581ed. Report an issue: GitHub.