{"record":{"id":"051eb127f8dec03c","repo":"CherryHQ/cherry-studio","slug":"internalerror-051eb1","errorCode":"InternalError","errorMessage":"Agent not found: ${this.agentId}","messagePattern":"Agent not found: (.+?)","errorType":"error_code","errorClass":"McpError","httpStatus":null,"severity":"critical","filePath":"src/main/ai/mcp/servers/cherryAutonomyTools.ts","lineNumber":508,"sourceCode":"    // A requested payload that reached nobody because every attempt failed is a failed\n    // tool call — otherwise the agent sees success while the user received nothing\n    // (unsupported adapter, platform size reject, etc.). Zero recipients with no failed\n    // attempts (no chats configured) stays a normal result.\n    const messageFailed = sanitizedMessage !== undefined && messagesSent === 0\n    const fileFailed = file !== undefined && filesSent === 0\n    const deliveryFailed = errors.length > 0 && (messageFailed || fileFailed)\n\n    return {\n      content: [{ type: 'text' as const, text: parts.join(' ') }],\n      ...(deliveryFailed ? { isError: true } : {})\n    }\n  }\n\n  // ── Config tool handlers ──────────────────────────────────────────\n\n  private configStatus() {\n    const agent = agentService.getAgent(this.agentId)\n    if (!agent) throw new McpError(ErrorCode.InternalError, `Agent not found: ${this.agentId}`)\n\n    const config = agent.configuration\n    const channels = channelService.listChannels({ agentId: this.agentId })\n\n    const adapterStatuses = application.get('ChannelManager').getAdapterStatuses(this.agentId)\n    const statusMap = new Map(adapterStatuses.map((s) => [s.channelId, s.connected]))\n\n    const channelSummary = channels.map((ch) => ({\n      id: ch.id,\n      type: ch.type,\n      name: ch.name,\n      enabled: ch.isActive,\n      connected: statusMap.get(ch.id) ?? false\n    }))\n\n    const result = {\n      agentId: agent.id,\n      name: agent.name,","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/src/main/ai/mcp/servers/cherryAutonomyTools.ts#L490-L526","documentation":"The only non-InvalidParams error in this set: a config `status` call could not find the session's own agent in AgentService. This is MCP InternalError, meaning the server state is inconsistent rather than the caller's parameters being wrong. It implies the agent record was deleted while the MCP session was still bound to it, or the session's `agentId` is corrupt.","triggerScenarios":"Agent deleted via UI/DB while its MCP session is live; a database reset/restore between session creation and a config call; session constructed with a stale or wrong agentId.","commonSituations":"User removes the agent from settings mid-conversation; test fixtures wiped the agents table while a long-lived session lingered; race between session teardown and an in-flight tool call.","solutions":["Recreate the agent or reselect it in the UI, then start a fresh MCP session.","Verify the session context's `agentId` still resolves via `agentService.getAgent(id)` before issuing config calls.","If this recurs, inspect logs for agent deletion events timestamped near the failure."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Not fully preventable client-side, but you can pre-check the agent still exists if you have\n// access to the same AgentService in-process:\nif (!agentService.getAgent(sessionAgentId)) {\n  throw new Error('Session agent no longer exists; recreate the agent and restart the session.');\n}","typeGuard":null,"tryCatchPattern":"const result = await autonomy.call('config', { action: 'status' });\nif (result.isError && result.content[0].text.startsWith('Error: Agent not found')) {\n  // unrecoverable for this session — surface to the user, do not retry with the same agentId\n}","preventionTips":["Do not delete an agent while its MCP session is active; tear the session down first.","On DB restore/reset, discard all lingering sessions — their agentIds may no longer resolve."],"tags":["mcp","config","agent","internal-error","lifecycle"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}