JuliusBrussee/caveman · error · Error
cave_conversation_in_use
cave_conversation_in_use
Error message
cave_conversation_in_use
What it means
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.
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.
Example fix
// before streamAgentInternal(conv, a); streamAgentInternal(conv, b); // throws // after await streamAgentInternal(conv, a); await streamAgentInternal(conv, b);
Defensive patterns
Strategy: try-catch
Validate before calling
// track in-flight streams per conversation
const inflight = new Set<Conversation>();
if (inflight.has(conv)) throw new Error("conversation busy"); Type guard
const isConversationBusy = (c: Conversation): boolean => conversationStates.get(c)?.busy === true;
Try / catch
try {
await streamAgentInternal(conv, input);
} catch (e) {
if (e.message === "cave_conversation_in_use") await waitForDrain(conv); // then retry
else throw e;
} Prevention
- Await each stream before reusing the conversation.
- One conversation per concurrent request.
- Wrap streams in abort/finally so busy state is always released.
When it happens
Trigger: Calling streamAgentInternal (or any transaction-opening call) on a Conversation while a previous stream/transaction has not been committed or aborted.
Common situations: 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.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- MCP transaction state kept changing; refusing mutation
- changed while planning MCP update; refusing overwrite
- capacity
- capacity
- Cave Build lock changed during validation; refusing Claude…
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/91648690736a7c84.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/runtime.ts:305
export function createConversation(): Conversation {
return new Conversation();
}
type ConversationTransaction = {
readonly owner: Conversation;
readonly sessionId: string;
messages: AgentMessage[];
fingerprint: string | undefined;
cachePrefixDigest: string | undefined;
providerFrozen: ProviderFrozenView | undefined;
originalFrozen: ProviderFrozenView | undefined;
};
function beginConversation(owner: Conversation): ConversationTransaction {
const state = conversationStates.get(owner);
if (!state) throw new Error("cave_conversation_invalid");
if (state.busy) throw new Error("cave_conversation_in_use");
const transaction: ConversationTransaction = {
owner,
sessionId: state.sessionId,
messages: structuredClone(state.messages),
fingerprint: state.fingerprint,
cachePrefixDigest: state.cachePrefixDigest,
providerFrozen: state.providerFrozen === undefined
? undefined
: structuredClone(state.providerFrozen),
originalFrozen: state.originalFrozen === undefined
? undefined
: structuredClone(state.originalFrozen),
};
state.busy = true;
return transaction;
}
function commitConversation(View on GitHub (pinned to 3ee70a1026)