#25510·mastra

[BUG] Durable agent resume-stream returns 403 "belongs to a different resource" when resumed right after the approval event

Author: roaminroCreated Sep 29, 2026Updated Sep 30, 2026
LabelsbugAgentsMastra Servercustomer-engeffort:lowimpact:mediumInngestDurable Agents

Describe the bug

Since #25169 (the fix for #24850), POST /agents/:agentId/resume-stream on a durable agent first checks the stored run in validateDurableToolCallAccess. That check reads storage once, without waiting for the suspended snapshot to be saved. The tool-approval chunk is published before the snapshot is saved; that is why #24770 added a snapshot wait to InngestAgent.resume(). So an HTTP client that resumes as soon as it receives the approval gets:

403 {"error":"Access denied: durable run belongs to a different resource"}

The run belongs to the same caller; its row just doesn't exist yet. The same request succeeds about 500 ms later. The agent's own snapshot wait never runs, because the route rejects the request first.

A second form shows up with two sequential approvals in one turn. Resuming the first with closeOnSuspend: true emits the second approval. Resuming the second by its toolCallId right away returns 403 "Access denied: tool call is not suspended on this durable run", because the stored snapshot still describes the first suspension. We saw this 3/3 in our own test suite; the reproduction below covers only the single-approval case.

Reproduction

src/mastra/index.ts:

typescript
import { appendFileSync } from 'node:fs';
import { Agent } from '@mastra/core/agent';
import { Mastra } from '@mastra/core/mastra';
import { createTool } from '@mastra/core/tools';
import { createInngestAgent, serve } from '@mastra/inngest';
import { LibSQLStore } from '@mastra/libsql';
import { Inngest } from 'inngest';
import { z } from 'zod';

const inngest = new Inngest({ id: 'repro', isDev: true, baseUrl: 'http://localhost:8898' });

const sendMoney = createTool({
  id: 'send_money', description: 'Send money to a recipient.', requireApproval: true,
  inputSchema: z.object({ recipient: z.string(), amount: z.number() }),
  execute: async ({ recipient, amount }, ctx) => {
    appendFileSync(process.env.REPRO_EXECUTIONS ?? 'executions.jsonl', JSON.stringify({ toolCallId: ctx?.agent?.toolCallId }) + '\n');
    return { sent: true, recipient, amount };
  },
});

const repro = createInngestAgent({
  inngest,
  agent: new Agent({
    id: 'repro', name: 'Repro', model: 'openai/gpt-4o-mini', tools: { sendMoney },
    instructions: 'Call send_money exactly once with the recipient and amount from the user message.',
  }),
});

export const mastra = new Mastra({
  agents: { repro },
  storage: new LibSQLStore({ id: 'repro', url: 'file:./repro.db' }),
  server: {
    apiRoutes: [{ path: '/inngest/api', method: 'ALL', createHandler: async ({ mastra }) => serve({ mastra, inngest }) }],
  },
});

reproduce.mjs:

javascript
import { existsSync, readFileSync } from 'node:fs';
const api = 'http://localhost:4812/api/agents/repro';
const pause = ms => new Promise(r => setTimeout(r, ms));
const executions = id => existsSync('executions.jsonl')
  ? readFileSync('executions.jsonl', 'utf8').trim().split('\n').filter(Boolean).map(JSON.parse).filter(r => r.toolCallId === id).length : 0;
async function stream(path, body) {
  const res = await fetch(api + path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
  const raw = await res.text();
  const chunks = raw.split('\n').filter(l => l.startsWith('data:')).map(l => l.slice(5).trim()).filter(s => s && s !== '[DONE]').map(JSON.parse);
  return { status: res.status, raw, chunks };
}
async function resume(label, delayMs) {
  const start = await stream('/stream', { messages: [{ role: 'user', content: 'send 5 to alice' }], closeOnSuspend: true });
  const approval = start.chunks.find(c => c.type === 'tool-call-approval');
  if (start.status !== 200 || !approval) throw new Error('setup: no approval ' + start.raw.slice(0, 300));
  const { runId } = approval;
  const { toolCallId } = approval.payload;
  await pause(delayMs);
  const res = await stream('/resume-stream', { runId, toolCallId, resumeData: { approved: true } });
  await pause(3000);
  console.log(JSON.stringify({ label, status: res.status, error: res.status === 200 ? undefined : res.raw, executions: executions(toolCallId) }));
}
for (let trial = 1; trial <= 3; trial++) {
  for (const delayMs of [0, 100, 250, 500, 1000, 2000]) await resume(`resume ${delayMs}ms after the approval stream closes`, delayMs);
}

Start mastra dev on port 4812 (PORT=4812) with OPENAI_API_KEY set, and npx inngest-cli dev -u http://localhost:4812/inngest/api --port 8898, then run node reproduce.mjs.

Results (3 trials per delay)

Delay after the approval stream closes Status Tool executions
0 ms 403 "durable run belongs to a different resource" (3/3) 0
100 ms 403 (3/3) 0
250 ms 403 (2/3), 200 (1/3) 0 / 1
500 ms 200 (3/3) 1
1000 ms 200 (3/3) 1
2000 ms 200 (3/3) 1

With local SQLite and the local Inngest dev server, the window is roughly 250–500 ms. Human approvals are unlikely to land inside it, but automated approvers (policy engines, agent-to-agent flows, scripts) hit it every time. Slower storage or Inngest Cloud latency would likely widen it.

Expected behavior

A resume sent as soon as the approval arrives should succeed, as InngestAgent.resume() does when called directly. The route should wait for the snapshot the same way, or leave that wait to the agent. It should also not report "belongs to a different resource" when the run simply doesn't exist yet.

Likely cause

validateDurableToolCallAccess in packages/server/src/server/handlers/agents.ts (unchanged on main at c327d633d5):

  • if (!workflowRun) throw new HTTPException(403, { message: 'Access denied: durable run belongs to a different resource' }): a missing row is reported as an ownership failure.
  • hasSuspendedToolCall(snapshot, toolCallId) checks the snapshot as currently stored, which can still be the previous suspension.

Neither waits for persistence the way the resume guard from #24770 does (RESUME_SNAPSHOT_WAIT_MS in workflows/inngest/src/durable-agent/create-inngest-agent.ts).

Environment

  • @mastra/core 1.72.0-alpha.9, @mastra/server 1.72.0-alpha.9 (via mastra 1.31.4-alpha.9), @mastra/inngest 1.10.1-alpha.4, @mastra/libsql 1.24.0-alpha.2, inngest 4.21.0, inngest-cli 1.45.1
  • Node 22, macOS, openai/gpt-4o-mini

Related

  • #24850 / #25169: added this check to the resume routes
  • #24770: the same snapshot-persistence race on resume, fixed inside the agent
  • #25154 / #25167: the approve/decline routes use the same check