{"record":{"id":"3b9fb5468a6902b1","repo":"vercel/ai","slug":"deep-agents-runtime-was-not-initialized","errorCode":null,"errorMessage":"Deep Agents runtime was not initialized","messagePattern":"Deep Agents runtime was not initialized","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/harness-deepagents/src/bridge/index.ts","lineNumber":296,"sourceCode":"    agent = createDeepAgent({\n      tools: [...mcpTools, ...hostTools],\n      backend: createLocalShellBackend({ rootDir: workdir }),\n      systemPrompt: start.instructions\n        ? { suffix: start.instructions }\n        : undefined,\n      // Native skills loaded from the source dirs ($HOME-materialized + <workDir> for repo-provided skills).\n      ...(start.skillsPaths?.length ? { skills: start.skillsPaths } : {}),\n      ...(middleware.length > 0 ? { middleware } : {}),\n      // Gate built-in tools behind HITL approval when the permission mode requires it.\n      ...(interruptOn ? { interruptOn } : {}),\n      // Real instance (LangGraph rejects `true` for root graphs); gives multi-turn memory.\n      checkpointer,\n    });\n    agentConfigurationSignature = nextAgentConfigurationSignature;\n  }\n  const activeAgent = agent;\n  if (activeAgent == null) {\n    throw new Error('Deep Agents runtime was not initialized');\n  }\n\n  const hostToolNames = new Set((start.tools ?? []).map(t => t.name));\n  const streamEventState = createDeepAgentsStreamEventState();\n  const emitStreamEvent = createEmitStreamEvent({\n    state: streamEventState,\n    configuredModel: activeModel,\n    hostToolNames,\n    mcpToolNames,\n    structuredOutputToolNames: new Set(\n      currentResponseFormat?.map(format => format.name) ?? [],\n    ),\n    emit,\n  });\n\n  // After a stream segment ends, return the tool calls paused by HITL interrupts (empty when the turn is truly done).\n  const readPendingApprovals = async () => {\n    try {","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/harness-deepagents/src/bridge/index.ts#L278-L314","documentation":"`runTurn` reads the module-level `agent` variable after a possible rebuild and throws if it is still undefined. Since `rebuildAgent` is true whenever `agent == null`, reaching this throw means agent creation silently failed to assign the variable or the code path was bypassed. It is a defensive invariant check that the Deep Agents runtime exists before streaming.","triggerScenarios":"`runTurn` reaching the streaming phase with `agent` still undefined — practically only if agent construction (`createDeepAgent`) was skipped or an exception path left the variable unset while execution continued.","commonSituations":"A corrupted bridge process state after a failed rebuild; race between concurrent turns mutating the module-level `agent`; a bug where the rebuild branch was not entered despite a null agent.","solutions":["Restart the bridge process (start a fresh harness session) so the agent is rebuilt from the start message.","Check logs above this error for a swallowed exception during `createDeepAgent` (e.g. MCP tool loading or middleware creation failures).","Avoid running turns concurrently against the same bridge process; turns share the module-level `agent`.","If reproducible, file a bug — this throw is an invariant guard and should be unreachable in normal operation."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await runTurn(start);\n} catch (error) {\n  if (error instanceof Error && error.message.includes('runtime was not initialized')) {\n    // restart the bridge process and retry once\n  }\n  throw error;\n}","preventionTips":["Restart the bridge on initialization errors","Run one turn at a time per bridge process","Watch logs for swallowed createDeepAgent failures"],"tags":["lifecycle","initialization","internal-state"],"backgroundTag":"runtime-not-initialized","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}