{"record":{"id":"b3e949902b7c259a","repo":"danny-avila/LibreChat","slug":"resource-recovery-required","errorCode":"resource_recovery_required","errorMessage":"{\"type\":\"resource_recovery_required\"}","messagePattern":"\\{\"type\":\"resource_recovery_required\"\\}","errorType":"exception","errorClass":"CodeResourceRecoveryError","httpStatus":409,"severity":"error","filePath":"api/server/services/Files/Code/process.js","lineNumber":1115,"sourceCode":"  const allRequiredResourcesFailed =\n    requiredCodeFiles > 0 && primedCodeFiles === 0 && reuploadFailures === requiredCodeFiles;\n  const { requestId, runId } = getPrimingCorrelation(req);\n  logger.debug(\n    `[primeCodeFiles] out: returned=${files.length} ` +\n      `required=${requiredCodeFiles} skippedNoRef=${skippedNoRef} reuploadFailures=${reuploadFailures}`,\n  );\n\n  if (allRequiredResourcesFailed) {\n    const failureCategory =\n      reuploadFailureCategories.size === 1\n        ? Array.from(reuploadFailureCategories)[0]\n        : 'mixed_reupload_failure';\n    logger.warn(\n      `[primeCodeFiles] resource-recovery-required requestId=${requestId} runId=${runId} ` +\n        `required=${requiredCodeFiles} primed=${primedCodeFiles} failed=${reuploadFailures} ` +\n        `category=${failureCategory}`,\n    );\n    throw new CodeResourceRecoveryError({\n      required: requiredCodeFiles,\n      primed: primedCodeFiles,\n      failed: reuploadFailures,\n    });\n  }\n\n  return { files, toolContext };\n};\n\n/**\n * Reads a single file from the code-execution sandbox by shelling `cat`\n * through the sandbox `/exec` endpoint. Used by the `read_file` host\n * handler when the requested path is a code-env path (`/mnt/data/...`)\n * or otherwise not resolvable as a skill file. Resolves to\n * `{ content }` from stdout on success, or `null` when the codeapi base\n * URL isn't configured / the read returns no content (caller turns that\n * into a model-visible error). Throws axios-style errors on transport\n * failure so the caller can surface a meaningful error message.","sourceCodeStart":1097,"sourceCodeEnd":1133,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/server/services/Files/Code/process.js#L1097-L1133","documentation":"Thrown as a CodeResourceRecoveryError by primeCodeFiles (Code/process.js) when allRequiredResourcesFailed is true: there were required code files, zero got primed, and every one failed its reupload. It carries code=resource_recovery_required and a payload ({required, primed, failed}) so the caller can trigger a recovery flow rather than abort the run.","triggerScenarios":"An agent run depends on code files (requiredCodeFiles > 0) that are no longer live in any sandbox session; every reupload attempt to re-establish them failed (reuploadFailures === requiredCodeFiles); primedCodeFiles === 0.","commonSituations":"Sandbox sessions expired and the underlying files were garbage-collected; a storage_session_id is stale and the reupload hits a quota/network error; the user's attached files were deleted between turns; code server storage tier is full.","solutions":["Handle CodeResourceRecoveryError specifically and invoke the resource-recovery flow (re-attach the source files and re-prime) before failing the run.","Inspect the logged category (single vs mixed_reupload_failure) and the reuploadFailures detail to find the dominant cause.","Verify the code server's storage is healthy and sessions are not being reaped prematurely.","Ensure the source files still exist in the primary file store before re-priming."],"exampleFix":"// before\ntry {\n  await primeCodeFiles(params);\n} catch (e) {\n  throw e;\n}\n\n// after\ntry {\n  await primeCodeFiles(params);\n} catch (e) {\n  if (e.code === 'resource_recovery_required') {\n    await recoverCodeResources({ req, required: e.required });\n    return primeCodeFiles(params);\n  }\n  throw e;\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":"/** @param {unknown} e * @returns {e is Error & { code: 'resource_recovery_required'; required: number; primed: number; failed: number }} */\nfunction isCodeResourceRecoveryError(e) {\n  return e instanceof Error && e.code === 'resource_recovery_required';\n}","tryCatchPattern":"try {\n  await primeCodeFiles(params);\n} catch (err) {\n  if (isCodeResourceRecoveryError(err)) {\n    await recoverCodeResources({ req, required: err.required });\n    return primeCodeFiles(params);\n  }\n  throw err;\n}","preventionTips":["Handle CodeResourceRecoveryError by code, not by message string.","Confirm source files still exist in the primary store before re-priming.","Monitor sandbox session TTL so files are re-primed before expiry, not after."],"tags":["code-env","resource-recovery","priming","agents"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}