{"record":{"id":"5e616571eb054a39","repo":"paperclipai/paperclip","slug":"selected-wiki-maintainer-agent-was-not-found-or-is","errorCode":null,"errorMessage":"Selected Wiki Maintainer agent was not found or is terminated.","messagePattern":"Selected Wiki Maintainer agent was not found or is terminated\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/plugins/plugin-llm-wiki/src/wiki/core.ts","lineNumber":2063,"sourceCode":"export async function resetWikiAgentResource(ctx: PluginContext, companyId: string): Promise<WikiAgentResource> {\n  const resolved = await ctx.agents.managed.reset(WIKI_MAINTAINER_AGENT_KEY, companyId);\n  if (resolved.agentId) {\n    await upsertResourceBinding(ctx, {\n      companyId,\n      wikiId: DEFAULT_WIKI_ID,\n      resourceKind: \"agent\",\n      resourceKey: WIKI_MAINTAINER_AGENT_KEY,\n      resolvedId: resolved.agentId,\n      metadata: { source: \"managed-default\", updatedBy: \"reset\" },\n    });\n  }\n  return agentResource({ status: resolved.status, source: \"managed\", agent: resolved.agent, defaultDrift: resolved.defaultDrift ?? null });\n}\n\nexport async function selectWikiAgentResource(ctx: PluginContext, input: { companyId: string; agentId: string }): Promise<WikiAgentResource> {\n  const agent = await ctx.agents.get(input.agentId, input.companyId);\n  if (!agent || agent.status === \"terminated\") {\n    throw new Error(\"Selected Wiki Maintainer agent was not found or is terminated.\");\n  }\n  await upsertResourceBinding(ctx, {\n    companyId: input.companyId,\n    wikiId: DEFAULT_WIKI_ID,\n    resourceKind: \"agent\",\n    resourceKey: WIKI_MAINTAINER_AGENT_KEY,\n    resolvedId: agent.id,\n    metadata: { source: \"selected-existing\", updatedBy: \"settings\" },\n  });\n  return agentResource({ status: \"resolved\", source: \"selected\", agent });\n}\n\nexport async function reconcileWikiProjectResource(ctx: PluginContext, companyId: string): Promise<WikiProjectResource> {\n  const resolved = await ctx.projects.managed.reconcile(WIKI_PROJECT_KEY, companyId);\n  if (resolved.projectId) {\n    await upsertResourceBinding(ctx, {\n      companyId,\n      wikiId: DEFAULT_WIKI_ID,","sourceCodeStart":2045,"sourceCodeEnd":2081,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/packages/plugins/plugin-llm-wiki/src/wiki/core.ts#L2045-L2081","documentation":"Thrown by selectWikiAgentResource when ctx.agents.get(agentId, companyId) returns nullish or returns an agent whose status is 'terminated'. The Wiki Maintainer binding must point at a live agent in the same company.","triggerScenarios":"Calling selectWikiAgentResource with an agentId that does not exist, is terminated, or belongs to a different company.","commonSituations":"Selecting a previously terminated agent from a stale dropdown; cross-company agent id; agent deleted between UI load and selection; test fixture referencing a removed agent.","solutions":["Refresh the agent options via listWikiAgentOptions and only pick a non-terminated agent.","If the desired agent is terminated, restart/recreate it before selecting.","Fall back to resetWikiAgentResource to bind the managed default agent.","Verify the companyId owns the agentId before submitting."],"exampleFix":"// before\nawait selectWikiAgentResource(ctx, { companyId, agentId: pickedAgentId });\n\n// after\nconst opts = await listWikiAgentOptions(ctx, companyId);\nconst live = opts.find((o) => o.id === pickedAgentId && o.status !== \"terminated\");\nif (!live) {\n  return selectWikiAgentResource(await resetWikiAgentResource(ctx, companyId));\n}\nawait selectWikiAgentResource(ctx, { companyId, agentId: live.id });","handlingStrategy":"validation","validationCode":"async function ensureSelectableAgent(ctx, companyId, agentId) {\n  const opts = await listWikiAgentOptions(ctx, companyId);\n  const live = opts.find((o) => o.id === agentId && o.status !== \"terminated\");\n  if (!live) throw new Error(\"Selected Wiki Maintainer agent was not found or is terminated.\");\n  return live.id;\n}","typeGuard":"function isLiveAgent(agent) {\n  return !!agent && agent.status !== \"terminated\";\n}","tryCatchPattern":"try {\n  await selectWikiAgentResource(ctx, { companyId, agentId });\n} catch (err) {\n  if (/was not found or is terminated/.test(err.message)) {\n    return resetWikiAgentResource(ctx, companyId);\n  }\n  throw err;\n}","preventionTips":["Populate the picker from listWikiAgentOptions and hide terminated agents.","Restart terminated agents before binding.","Fall back to the managed default via resetWikiAgentResource."],"tags":["validation","wiki","agents","company-scope","paperclip"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}