{"record":{"id":"c12cf0b824273318","repo":"Mintplex-Labs/anything-llm","slug":"this-agent-invocation-is-already-closed","errorCode":null,"errorMessage":"This agent invocation is already closed","messagePattern":"This agent invocation is already closed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/agents/index.js","lineNumber":553,"sourceCode":"      },\n      { user, thread }\n    );\n\n    this.provider = router.resolvedRoute.provider;\n    this.model = router.resolvedRoute.model;\n    this.routingMetadata = router.routingMetadata;\n    // Held so the model-router-cooldown plugin can restart the cooldown when\n    // the agent stops responding. Routing re-resolves per turn, so this always\n    // points at the router for the current route.\n    this._modelRouter = router;\n  }\n\n  async #validInvocation() {\n    const invocation = await WorkspaceAgentInvocation.getWithWorkspace({\n      uuid: String(this.#invocationUUID),\n    });\n    if (invocation?.closed)\n      throw new Error(\"This agent invocation is already closed\");\n    this.invocation = invocation ?? null;\n  }\n\n  parseCallOptions(args, config = {}, pluginName) {\n    const callOpts = {};\n    for (const [param, definition] of Object.entries(config)) {\n      if (\n        definition.required &&\n        (!Object.prototype.hasOwnProperty.call(args, param) ||\n          args[param] === null)\n      ) {\n        this.log(\n          `'${param}' required parameter for '${pluginName}' plugin is missing. Plugin may not function or crash agent.`\n        );\n        continue;\n      }\n      callOpts[param] = Object.prototype.hasOwnProperty.call(args, param)\n        ? args[param]","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/20f6d3546c1938bfea1ad304f58a592dddcc5948/server/utils/agents/index.js#L535-L571","documentation":"Guard in #validInvocation(): the WorkspaceAgentInvocation record for the given invocation UUID cannot be found (it was deleted or already terminated), so the in-memory agent instance is pointing at a closed session. Initialization is aborted rather than resuming a stale invocation.","triggerScenarios":"A call was made on an agent invocation that had already been closed.","commonSituations":"This error is raised at runtime in server/utils/agents/index.js. It occurs when the required configuration for this provider is missing or invalid (unset environment variables, empty API key or base path), when the external service is unreachable or returns an unexpected response, or when invalid input reaches the call site. To prevent it, validate the relevant provider settings and environment variables at startup and confirm the service is reachable before this code path executes.","solutions":["Start a new agent invocation; the current one is already closed."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"20f6d3546c1938bfea1ad304f58a592dddcc5948","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}