{"record":{"id":"21f11173bcc60a5b","repo":"ruvnet/ruflo","slug":"darwin-archive-exceeded-evaluation-cost-budget","errorCode":null,"errorMessage":"Darwin archive exceeded evaluation-cost budget","messagePattern":"Darwin archive exceeded evaluation-cost budget","errorType":"exception","errorClass":"DarwinUnavailableError","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/services/flywheel-proposer.ts","lineNumber":232,"sourceCode":"        timeout = setTimeout(() => reject(new DarwinUnavailableError('Darwin exceeded wall-time budget')), maxWallTimeMs);\n        timeout.unref?.();\n      }),\n    ]).finally(() => {\n      if (timeout) clearTimeout(timeout);\n    });\n    if (!result.completed) {\n      if (input.mode === 'darwin') throw new DarwinUnavailableError(result.reason ?? 'Darwin archive incomplete');\n      return runLocal(`darwin-incomplete:${result.reason ?? 'unknown'}`);\n    }\n    if (result.candidates.length > (input.maxCandidates ?? 256)) {\n      throw new DarwinUnavailableError('Darwin archive exceeded candidate-count budget');\n    }\n    const evaluationCost = result.candidates.reduce(\n      (sum, candidate) => sum + candidate.resources.evaluationCostMicros,\n      0,\n    );\n    if (evaluationCost > input.safetyEnvelope.maxEvaluationCostMicros) {\n      throw new DarwinUnavailableError('Darwin archive exceeded evaluation-cost budget');\n    }\n    return finalizeArchive({\n      requested: input.mode,\n      effective: 'darwin',\n      promotionAllowed: true,\n      baselineRef,\n      safetyEnvelope: input.safetyEnvelope,\n      seed: input.seed,\n      candidates: result.candidates,\n      completed: true,\n    });\n  } catch (error) {\n    if (input.mode === 'darwin') {\n      if (error instanceof DarwinUnavailableError) throw error;\n      throw new DarwinUnavailableError(`Darwin failed closed: ${(error as Error).message}`);\n    }\n    return runLocal(`darwin-error:${(error as Error).message}`);\n  }","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/services/flywheel-proposer.ts#L214-L250","documentation":"proposeFlywheelCandidates sums evaluationCostMicros across all Darwin candidates and throws DarwinUnavailableError if the total exceeds safetyEnvelope.maxEvaluationCostMicros. This enforces the caller-declared evaluation spend ceiling before any candidate is evaluated downstream.","triggerScenarios":"The combined per-candidate evaluation cost of Darwin's archive is larger than the safety envelope's maxEvaluationCostMicros — many candidates each with non-trivial evaluationCostMicros, or a few very expensive candidates.","commonSituations":"safetyEnvelope.maxEvaluationCostMicros set too low for the candidate volume; Darwin candidates carry high evaluationCostMicros (expensive models/large evals); the envelope was sized for the local proposer's smaller output.","solutions":["Raise safetyEnvelope.maxEvaluationCostMicros to match the expected Darwin archive cost.","Reduce the candidate count (lower maxCandidates) so the summed cost fits.","Filter cheap candidates only inside the darwinInvoker wrapper before returning.","Switch to mode 'auto' so a cost overrun falls back to local instead of throwing."],"exampleFix":"// before\nproposeFlywheelCandidates({ mode: 'darwin', darwinInvoker, safetyEnvelope: { maxEvaluationCostMicros: 1_000_000, ... }, ... }); // throws on cost overrun\n\n// after — size the envelope to the archive, or trim expensive candidates\nconst trimmed = async (req) => {\n  const r = await darwinInvoker(req);\n  let cost = 0; const keep = [];\n  for (const c of r.candidates) {\n    if (cost + c.resources.evaluationCostMicros > req.budget.maxEvaluationCostMicros) break;\n    cost += c.resources.evaluationCostMicros; keep.push(c);\n  }\n  return { ...r, candidates: keep };\n};\nproposeFlywheelCandidates({ mode: 'darwin', darwinInvoker: trimmed, ... });","handlingStrategy":"validation","validationCode":"const safetyEnvelope = { ...input.safetyEnvelope, maxEvaluationCostMicros: Math.max(input.safetyEnvelope.maxEvaluationCostMicros, expectedArchiveCost) };\nawait proposeFlywheelCandidates({ mode: 'darwin', darwinInvoker, safetyEnvelope, ... });","typeGuard":null,"tryCatchPattern":"try {\n  return await proposeFlywheelCandidates({ mode: 'darwin', darwinInvoker, safetyEnvelope, ... });\n} catch (e) {\n  if (e instanceof DarwinUnavailableError && /evaluation-cost budget/.test(e.message)) {\n    // raise the envelope or trim expensive candidates and retry\n    return await proposeFlywheelCandidates({ mode: 'auto', darwinInvoker, safetyEnvelope: { ...safetyEnvelope, maxEvaluationCostMicros: safetyEnvelope.maxEvaluationCostMicros * 2 }, ... });\n  }\n  throw e;\n}","preventionTips":["Size maxEvaluationCostMicros to the expected summed Darwin archive cost.","Trim expensive candidates inside the darwinInvoker wrapper before returning.","Keep maxCandidates and per-candidate evaluationCostMicros within the envelope.","Use mode 'auto' to fall back to local on cost overruns."],"tags":["darwin","flywheel","budget","safety-envelope","typescript"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}