{"record":{"id":"91648690736a7c84","repo":"JuliusBrussee/caveman","slug":"cave-conversation-in-use","errorCode":"cave_conversation_in_use","errorMessage":"cave_conversation_in_use","messagePattern":"cave_conversation_in_use","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/agent/src/runtime.ts","lineNumber":305,"sourceCode":"\nexport function createConversation(): Conversation {\n  return new Conversation();\n}\n\ntype ConversationTransaction = {\n  readonly owner: Conversation;\n  readonly sessionId: string;\n  messages: AgentMessage[];\n  fingerprint: string | undefined;\n  cachePrefixDigest: string | undefined;\n  providerFrozen: ProviderFrozenView | undefined;\n  originalFrozen: ProviderFrozenView | undefined;\n};\n\nfunction beginConversation(owner: Conversation): ConversationTransaction {\n  const state = conversationStates.get(owner);\n  if (!state) throw new Error(\"cave_conversation_invalid\");\n  if (state.busy) throw new Error(\"cave_conversation_in_use\");\n  const transaction: ConversationTransaction = {\n    owner,\n    sessionId: state.sessionId,\n    messages: structuredClone(state.messages),\n    fingerprint: state.fingerprint,\n    cachePrefixDigest: state.cachePrefixDigest,\n    providerFrozen: state.providerFrozen === undefined\n      ? undefined\n      : structuredClone(state.providerFrozen),\n    originalFrozen: state.originalFrozen === undefined\n      ? undefined\n      : structuredClone(state.originalFrozen),\n  };\n  state.busy = true;\n  return transaction;\n}\n\nfunction commitConversation(","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/runtime.ts#L287-L323","documentation":"beginConversation found the conversation state but with busy=true, meaning another streaming/transaction is already active on this Conversation. The runtime serializes access per conversation and refuses concurrent transactions.","triggerScenarios":"Calling streamAgentInternal (or any transaction-opening call) on a Conversation while a previous stream/transaction has not been committed or aborted.","commonSituations":"Firing two streamAgent calls on the same conversation concurrently; a prior stream that threw without releasing the busy flag; forgetting to await one stream before starting another.","solutions":["Await the in-flight stream/transaction before starting a new one on the same conversation.","Use a separate Conversation per concurrent request.","If a crashed prior run left the flag set, discard the conversation and create a new one.","Serialize calls with a per-conversation queue/mutex."],"exampleFix":"// before\nstreamAgentInternal(conv, a);\nstreamAgentInternal(conv, b); // throws\n// after\nawait streamAgentInternal(conv, a);\nawait streamAgentInternal(conv, b);","handlingStrategy":"try-catch","validationCode":"// track in-flight streams per conversation\nconst inflight = new Set<Conversation>();\nif (inflight.has(conv)) throw new Error(\"conversation busy\");","typeGuard":"const isConversationBusy = (c: Conversation): boolean =>\n  conversationStates.get(c)?.busy === true;","tryCatchPattern":"try {\n  await streamAgentInternal(conv, input);\n} catch (e) {\n  if (e.message === \"cave_conversation_in_use\") await waitForDrain(conv); // then retry\n  else throw e;\n}","preventionTips":["Await each stream before reusing the conversation.","One conversation per concurrent request.","Wrap streams in abort/finally so busy state is always released."],"tags":["concurrency","conversation","busy"],"backgroundTag":"invalid-state-transition","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}