mastra-ai/mastra · error
Cannot approve a tool call without a current thread
Error message
Cannot approve a tool call without a current thread
What it means
Thrown when approving a tool call while the session has no current conversation thread. `agent.sendToolApproval` requires both `threadId` and `resourceId` to persist the approval decision; the session resolves the thread via `this.thread.getId()`, and when no thread has been created/selected the approval cannot be recorded, so the library throws.
Source
Thrown at packages/core/src/agent-controller/session.ts:3757
*/
async approveToolCall({
toolCallId,
requestContext: requestContextInput,
}: {
toolCallId?: string;
requestContext?: RequestContext;
}): Promise<void> {
const runId = this.run.getRunId();
if (!runId) {
throw new Error('No active run to approve tool call for');
}
const agent = this.machinery.getAgent();
const requestContext = await this.machinery.buildRequestContext(requestContextInput);
const isYolo = (this.state.get() as Record<string, unknown>).yolo === true;
const threadId = this.thread.getId();
if (!threadId) {
throw new Error('Cannot approve a tool call without a current thread');
}
const resourceId = this.identity.getResourceId();
await agent.sendToolApproval({
threadId,
resourceId,
runId,
toolCallId,
approved: true,
requireToolApproval: !isYolo,
memory: { thread: threadId, resource: resourceId },
abortSignal: this.run.ensureAbortController().signal,
requestContext,
toolsets: await this.machinery.buildToolsets(requestContext),
});
}
/**
* Decline a parked tool call: drive the agent to reject it. Throws when thereView on GitHub (pinned to 75dd419e61)
Solutions
- Ensure the session has a current thread before approving — start the run normally so the thread is created, or explicitly select/create a thread.
- Verify thread lifecycle code isn't clearing the current thread while a run awaiting approval is still active.
- If using multiple sessions, route the approval to the session instance that owns the originating thread.
Example fix
// before
await session.approveToolCall({ toolCallId }); // thread may be unset
// after
if (session.getCurrentThreadId?.()) {
await session.approveToolCall({ toolCallId });
} else {
await session.selectThread(existingThreadId);
await session.approveToolCall({ toolCallId });
} Defensive patterns
Strategy: validation
Validate before calling
// before approving
const threadId = session.getCurrentThreadId?.();
if (!threadId) {
throw new Error('Select or create a thread before approving tool calls');
} Type guard
function hasThread(session: { getCurrentThreadId?: () => string | undefined }): boolean {
return typeof session.getCurrentThreadId === 'function' && typeof session.getCurrentThreadId() === 'string';
} Try / catch
try {
await session.approveToolCall({ toolCallId });
} catch (err) {
if (err instanceof Error && err.message.includes('without a current thread')) {
await session.selectThread(fallbackThreadId);
await session.approveToolCall({ toolCallId });
} else throw err;
} Prevention
- Always start runs within an established thread context.
- Don't clear thread state while tool approvals are pending.
- Keep a single session instance per conversation to avoid routing approvals to the wrong session.
When it happens
Trigger: Calling the approve-tool-call method on a session where `this.thread.getId()` returns undefined — i.e., no thread was created, selected, or the thread was cleared before approving.
Common situations: Creating a fresh session and approving a tool call without first starting a conversation that establishes a thread; clearing/resetting thread state mid-run; multi-session apps where the approval is routed to a session that never had its thread set.
Related errors
- Cannot decline a tool call without a current thread
- AGENT_SEND_TOOL_APPROVAL_AMBIGUOUS_SUSPENDED_RUNS
- AGENT_SEND_TOOL_APPROVAL_NO_ACTIVE_THREAD_RUN
- Received input message with wrong threadId. Input ${message.
- No active run to approve tool call for
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/8168144e1d4c5249.
Report an issue: GitHub.