{"record":{"id":"51a5b9281ea2b8e4","repo":"paperclipai/paperclip","slug":"wiki-maintainer-agent-could-not-be-loaded","errorCode":null,"errorMessage":"Wiki Maintainer agent could not be loaded.","messagePattern":"Wiki Maintainer agent could not be loaded\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/plugins/plugin-llm-wiki/src/wiki/core.ts","lineNumber":3879,"sourceCode":"    await ctx.issues.update(operation.issue.id, { status: \"blocked\" }, input.companyId);\n    await ctx.issues.createComment(operation.issue.id, warning, input.companyId);\n    throw new Error(warning);\n  }\n\n  const agent = await ctx.agents.get(agentId, input.companyId);\n  if (!agent || agent.status === \"paused\" || agent.status === \"terminated\" || agent.status === \"pending_approval\") {\n    const warning = agent\n      ? `Wiki Maintainer agent is not invokable while status is ${agent.status}.`\n      : \"Wiki Maintainer agent could not be loaded.\";\n    await markOperation(ctx, {\n      companyId: input.companyId,\n      operationId: operation.operationId,\n      status: \"blocked\",\n      warning,\n    });\n    await ctx.issues.update(operation.issue.id, { status: \"blocked\" }, input.companyId);\n    await ctx.issues.createComment(operation.issue.id, warning, input.companyId);\n    throw new Error(warning);\n  }\n\n  const session = await ctx.agents.sessions.create(agentId, input.companyId, {\n    taskKey: `plugin:${PLUGIN_ID}:session:wiki:${wikiId}:query:${operation.operationId}`,\n    reason: \"LLM Wiki query session\",\n  });\n  await ctx.db.execute(\n    `INSERT INTO ${tableName(ctx.db.namespace, \"wiki_query_sessions\")}\n       (id, company_id, wiki_id, space_id, hidden_issue_id, agent_session_id, status, filed_outputs)\n     VALUES ($1, $2, $3, $6, $4, $5, 'active', '[]'::jsonb)`,\n    [operation.operationId, input.companyId, wikiId, operation.issue.id, session.sessionId, space.id],\n  );\n\n  const prompt = buildQueryPrompt({ companyId: input.companyId, wikiId, space, question });\n  ctx.streams.open(channel, input.companyId);\n  ctx.streams.emit(channel, {\n    type: \"query.started\",\n    operationId: operation.operationId,","sourceCodeStart":3861,"sourceCodeEnd":3897,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/packages/plugins/plugin-llm-wiki/src/wiki/core.ts#L3861-L3897","documentation":"Thrown when agentId is truthy but ctx.agents.get(agentId, companyId) returns null/undefined, i.e. the configured selection points to an agent that no longer exists in the company. The operation is marked blocked, the issue set to blocked, and a comment posted before throwing.","triggerScenarios":"The stored Wiki Maintainer agent selection references an agentId that ctx.agents.get cannot load (deleted, wrong company, data corruption, stale selection after agent re-creation).","commonSituations":"Agent was deleted but the managed-resource selection was never reset; agentId was copied across environments; company-scoping mismatch where the agent belongs to a different company.","solutions":["Re-select a valid agent via select-managed-agent with an agentId that exists for this company.","Run reset-managed-skills / reconcile-managed-skills to clear stale managed resource selections.","Verify the agentId with ctx.agents.get at the caller and clear the selection automatically when it returns null."],"exampleFix":"// before: stored agentId no longer resolves -> 'could not be loaded'\n// after: re-select an existing agent\nworker.actions['select-managed-agent']({ companyId, agentId: existingAgent.id });","handlingStrategy":"validation","validationCode":"async function resolveWikiAgent(ctx: PluginContext, companyId: string) {\n  const agentId = await getWikiAgentSelection(ctx, companyId);\n  if (!agentId) throw new Error('No Wiki Maintainer selected');\n  const agent = await ctx.agents.get(agentId, companyId);\n  if (!agent) {\n    await worker.actions['reset-managed-skills']({ companyId });\n    throw new Error('Stale agent selection; reset and re-select');\n  }\n  return agent;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runWikiQuery(ctx, input);\n} catch (err) {\n  if (err instanceof Error && /could not be loaded/.test(err.message)) {\n    await worker.actions['select-managed-agent']({ companyId, agentId: existingAgent.id });\n  } else throw err;\n}","preventionTips":["When an agent is deleted, clear its managed-resource selection immediately.","Run reconcile-managed-skills after agent lifecycle changes."],"tags":["paperclip","wiki","agent","data-integrity"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}