Mintplex-Labs/anything-llm · error · Error

This agent invocation is already closed

Error message

This agent invocation is already closed

What it means

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.

Solutions

  1. Start a new agent invocation; the current one is already closed.
Defensive patterns

Strategy: validation

When it happens

Trigger: A call was made on an agent invocation that had already been closed.

Common situations: 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.


AI-assisted analysis of Mintplex-Labs/anything-llm@20f6d3546c (2026-08-18). Data as JSON: /api/errors/c12cf0b824273318. Report an issue: GitHub.

Appendix: source

Thrown at server/utils/agents/index.js:553

      },
      { user, thread }
    );

    this.provider = router.resolvedRoute.provider;
    this.model = router.resolvedRoute.model;
    this.routingMetadata = router.routingMetadata;
    // Held so the model-router-cooldown plugin can restart the cooldown when
    // the agent stops responding. Routing re-resolves per turn, so this always
    // points at the router for the current route.
    this._modelRouter = router;
  }

  async #validInvocation() {
    const invocation = await WorkspaceAgentInvocation.getWithWorkspace({
      uuid: String(this.#invocationUUID),
    });
    if (invocation?.closed)
      throw new Error("This agent invocation is already closed");
    this.invocation = invocation ?? null;
  }

  parseCallOptions(args, config = {}, pluginName) {
    const callOpts = {};
    for (const [param, definition] of Object.entries(config)) {
      if (
        definition.required &&
        (!Object.prototype.hasOwnProperty.call(args, param) ||
          args[param] === null)
      ) {
        this.log(
          `'${param}' required parameter for '${pluginName}' plugin is missing. Plugin may not function or crash agent.`
        );
        continue;
      }
      callOpts[param] = Object.prototype.hasOwnProperty.call(args, param)
        ? args[param]

View on GitHub (pinned to 20f6d3546c)