{"record":{"id":"6d6a6a7d4ebc12fc","repo":"ruvnet/ruflo","slug":"darwin-failed-closed-error-as-error-message","errorCode":null,"errorMessage":"Darwin failed closed: ${(error as Error).message}","messagePattern":"Darwin failed closed: (.+?)","errorType":"exception","errorClass":"DarwinUnavailableError","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/services/flywheel-proposer.ts","lineNumber":247,"sourceCode":"      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  }\n}\n","sourceCodeStart":229,"sourceCodeEnd":252,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/services/flywheel-proposer.ts#L229-L252","documentation":"If the darwinInvoker throws something other than DarwinUnavailableError, the catch block wraps the original message as DarwinUnavailableError('Darwin failed closed: <original>'). In mode 'darwin' this rethrows (the caller demanded Darwin and must see the failure); in other modes it would fall back to the local proposer with a 'darwin-error:...' substitution. 'Failed closed' signals an unexpected Darwin-side fault that the proposer will not silently mask.","triggerScenarios":"The darwinInvoker rejects with an arbitrary error (network failure, serialization error, unhandled exception inside Darwin, timeout from a non-budget source) that is not already a DarwinUnavailableError.","commonSituations":"Darwin service is unreachable (DNS/connection refused); Darwin threw a TypeError/RangeError internally; the invoker's response failed schema parsing; an upstream dependency of Darwin crashed.","solutions":["Read the wrapped message: the original error's text is preserved after 'Darwin failed closed:'.","Stabilize the Darwin backend (network, service health) and retry.","If Darwin is unreliable, run with mode 'auto' so failures fall back to local instead of surfacing.","Harden the darwinInvoker to translate known transient errors into retries or DarwinUnavailableError with a clear reason."],"exampleFix":"// before\ntry { await proposeFlywheelCandidates({ mode: 'darwin', darwinInvoker, ... }); }\ncatch (e) { /* 'Darwin failed closed: <x>' — surface to user */ }\n\n// after — fall back when Darwin is flaky\nconst archive = await proposeFlywheelCandidates({ mode: 'auto', darwinInvoker, ... });\n// archive.effective === 'local', archive.substitution === 'darwin-error:<x>' on failure","handlingStrategy":"try-catch","validationCode":"// Pre-validate by health-checking Darwin before the run:\nif (darwinInvoker && !(await isDarwinHealthy(darwinInvoker))) {\n  // run local instead, or surface a clear message\n  await proposeFlywheelCandidates({ mode: 'local', ... });\n} else {\n  await proposeFlywheelCandidates({ mode: 'darwin', darwinInvoker, ... });\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await proposeFlywheelCandidates({ mode: 'darwin', darwinInvoker, ... });\n} catch (e) {\n  if (e instanceof DarwinUnavailableError) {\n    // original cause is in the message after 'Darwin failed closed:'\n    return await proposeFlywheelCandidates({ mode: 'local', ... });\n  }\n  throw e;\n}","preventionTips":["Use mode 'auto' so unexpected Darwin errors fall back to local.","Health-check Darwin (network/service) before requesting mode 'darwin'.","Read the wrapped original message to diagnose the underlying fault.","Harden the darwinInvoker to translate transient errors into retries or clear reasons."],"tags":["darwin","flywheel","error-handling","typescript"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}