{"record":{"id":"2915cfc24e1649ae","repo":"paperclipai/paperclip","slug":"host-services-have-been-disposed","errorCode":null,"errorMessage":"Host services have been disposed","messagePattern":"Host services have been disposed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/src/services/plugin-host-services.ts","lineNumber":3278,"sourceCode":"              eq(agentTaskSessionsTable.agentId, params.agentId),\n              eq(agentTaskSessionsTable.companyId, companyId),\n              like(agentTaskSessionsTable.taskKey, `plugin:${pluginKey}:session:%`),\n            ),\n          )\n          .orderBy(desc(agentTaskSessionsTable.createdAt));\n\n        return rows.map((row) => ({\n          sessionId: row.id,\n          agentId: row.agentId,\n          companyId: row.companyId,\n          status: \"active\" as const,\n          createdAt: row.createdAt.toISOString(),\n        }));\n      },\n\n      async sendMessage(params) {\n        if (disposed) {\n          throw new Error(\"Host services have been disposed\");\n        }\n\n        const companyId = ensureCompanyId(params.companyId);\n        await ensurePluginAvailableForCompany(companyId);\n\n        // Verify session exists and belongs to this plugin\n        const session = await db\n          .select()\n          .from(agentTaskSessionsTable)\n          .where(\n            and(\n              eq(agentTaskSessionsTable.id, params.sessionId),\n              eq(agentTaskSessionsTable.companyId, companyId),\n              like(agentTaskSessionsTable.taskKey, `plugin:${pluginKey}:session:%`),\n            ),\n          )\n          .then((rows) => rows[0] ?? null);\n        if (!session) throw new Error(`Session not found: ${params.sessionId}`);","sourceCodeStart":3260,"sourceCodeEnd":3296,"githubUrl":"https://github.com/paperclipai/paperclip/blob/a7e689b3c35347b529cb9f54c9b9a8575a3dcab6/server/src/services/plugin-host-services.ts#L3260-L3296","documentation":"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.","triggerScenarios":"Thrown at server/src/services/plugin-host-services.ts:3269 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["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."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a7e689b3c35347b529cb9f54c9b9a8575a3dcab6","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}