paperclipai/paperclip · error

Host services have been disposed

Error message

Host services have been disposed

What it means

A plugin host service call (e.g. sendMessage) was made after buildHostServices was disposed. The disposed flag guard prevents use of DB handles, event buses, and subscriptions that have already been torn down during plugin shutdown.

Source

Thrown at server/src/services/plugin-host-services.ts:3278

              eq(agentTaskSessionsTable.agentId, params.agentId),
              eq(agentTaskSessionsTable.companyId, companyId),
              like(agentTaskSessionsTable.taskKey, `plugin:${pluginKey}:session:%`),
            ),
          )
          .orderBy(desc(agentTaskSessionsTable.createdAt));

        return rows.map((row) => ({
          sessionId: row.id,
          agentId: row.agentId,
          companyId: row.companyId,
          status: "active" as const,
          createdAt: row.createdAt.toISOString(),
        }));
      },

      async sendMessage(params) {
        if (disposed) {
          throw new Error("Host services have been disposed");
        }

        const companyId = ensureCompanyId(params.companyId);
        await ensurePluginAvailableForCompany(companyId);

        // Verify session exists and belongs to this plugin
        const session = await db
          .select()
          .from(agentTaskSessionsTable)
          .where(
            and(
              eq(agentTaskSessionsTable.id, params.sessionId),
              eq(agentTaskSessionsTable.companyId, companyId),
              like(agentTaskSessionsTable.taskKey, `plugin:${pluginKey}:session:%`),
            ),
          )
          .then((rows) => rows[0] ?? null);
        if (!session) throw new Error(`Session not found: ${params.sessionId}`);

View on GitHub (pinned to a7e689b3c3)

Solutions

  1. The plugin's host service bridge was disposed (plugin unloaded/reloaded). Re-acquire host services after reload and do not cache them across lifecycle events.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at server/src/services/plugin-host-services.ts:3269 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of paperclipai/paperclip@a7e689b3c3 (2026-08-18). Data as JSON: /api/errors/2915cfc24e1649ae. Report an issue: GitHub.