{"record":{"id":"a689cb6b45b581ed","repo":"danny-avila/LibreChat","slug":"error-downloading-code-environment-file-stream","errorCode":null,"errorMessage":"Error downloading code environment file stream: ${error.message}","messagePattern":"Error downloading code environment file stream: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/server/services/Files/Code/crud.js","lineNumber":52,"sourceCode":"    const authHeaders = await getCodeApiAuthHeaders(req);\n    /** @type {import('axios').AxiosRequestConfig} */\n    const options = {\n      method: 'get',\n      url: `${baseURL}/download/${fileIdentifier}${query}`,\n      responseType: 'stream',\n      headers: {\n        'User-Agent': 'LibreChat/1.0',\n        ...authHeaders,\n      },\n      httpAgent: codeServerHttpAgent,\n      httpsAgent: codeServerHttpsAgent,\n      timeout: 15000,\n    };\n\n    const response = await axios(options);\n    return response;\n  } catch (error) {\n    throw new Error(\n      logAxiosError({\n        message: `Error downloading code environment file stream: ${error.message}`,\n        error,\n      }),\n    );\n  }\n}\n\n/**\n * Deletes a file from the Code Environment server.\n *\n * @param {ServerRequest} req - Current authenticated request, used to mint Code API auth.\n * @param {MongoFile} file - File metadata containing `metadata.codeEnvRef`.\n * @returns {Promise<void>}\n */\nasync function deleteCodeEnvFile(req, file) {\n  const ref = file?.metadata?.codeEnvRef;\n  if (!ref) {","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/server/services/Files/Code/crud.js#L34-L70","documentation":"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.","triggerScenarios":"Network failure, timeout (15s), non-2xx from codeapi, bad fileIdentifier, missing/invalid Code API auth headers, or the code server being unreachable (wrong baseURL).","commonSituations":"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.","solutions":["Confirm getCodeBaseURL() returns the correct, reachable code server URL.","Check server logs for the logAxiosError diagnostics (status, url, responseData) which reveal the underlying cause.","Verify getCodeApiAuthHeaders(req) successfully mints auth and that req.user is populated.","Retry once for transient network/timeout failures; treat 404 as 'file no longer on the sandbox'."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Confirm the code server is reachable and fileIdentifier well-formed\nconst baseURL = getCodeBaseURL();\nif (!baseURL) throw new Error('Code server URL not configured');\nif (!/^\\S+\\/\\S+$/.test(fileIdentifier)) throw new Error('Malformed fileIdentifier');","typeGuard":null,"tryCatchPattern":"try {\n  const stream = await getCodeOutputDownloadStream(fileIdentifier, identity, req);\n} catch (err) {\n  if (/404/.test(err.message)) {\n    // treat as gone — no retry\n    return null;\n  }\n  // transient: retry once\n  return getCodeOutputDownloadStream(fileIdentifier, identity, req);\n}","preventionTips":["Verify getCodeBaseURL() and getCodeApiAuthHeaders(req) resolve before calling.","Treat 404 from the code server as 'file gone' rather than retrying.","Read the logAxiosError output to get the exact status before deciding retry vs surface."],"tags":["network","code-env","download","axios"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}