[BUG] Durable 代理在重新启动后立即返回 403 "属于不同的资源",原因是重新启动发生在批准事件之后
作者: roaminro创建于 2026年9月29日更新于 2026年9月30日
标签bugAgentsMastra Servercustomer-engeffort:lowimpact:mediumInngestDurable Agents
src/mastra/index.ts:
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:
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',
…内容来源: mastra-ai/mastra