{"record":{"id":"e1b8d87429f4db0a","repo":"louislam/dockge","slug":"agent-not-found","errorCode":null,"errorMessage":"Agent not found","messagePattern":"Agent not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"backend/agent-manager.ts","lineNumber":107,"sourceCode":"    }\n\n    /**\n     *\n     * @param url\n     */\n    async remove(url : string) {\n        let bean = await R.findOne(\"agent\", \" url = ? \", [\n            url,\n        ]);\n\n        if (bean) {\n            await R.trash(bean);\n            let endpoint = bean.endpoint;\n            this.disconnect(endpoint);\n            this.sendAgentList();\n            delete this.agentSocketList[endpoint];\n        } else {\n            throw new Error(\"Agent not found\");\n        }\n    }\n\n    /**\n     *\n     * @param url\n     * @param updatedName\n     */\n    async update(url: string, updatedName: string) {\n        const agent = await R.findOne(\"agent\", \" url = ? \", [\n            url,\n        ]);\n        if (agent) {\n            agent.name = updatedName;\n            await R.store(agent);\n        } else {\n            throw new Error(\"Agent not found\");\n        }","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/louislam/dockge/blob/f809ae192b571944ad773e9866d3e67064ae8043/backend/agent-manager.ts#L89-L125","documentation":"AgentManager.remove(url) looks up the agent row in the database by exact URL via R.findOne('agent', ' url = ? ', [url]). If no agent bean is stored with that URL, it throws new Error(\"Agent not found\") instead of silently returning. It is a guard against operating on (and disconnecting sockets for) an agent that was never added or was already removed.","triggerScenarios":"Calling agentManager.remove(url) with a URL that is not in the agent table: the agent was never added via add(), was already removed in a previous call, or the URL string differs from the stored one (trailing slash, http vs https, localhost vs 127.0.0.1, port mismatch).","commonSituations":"Double-clicking a delete button so remove() fires twice; the frontend passing a normalized/display URL while add() stored the raw input; the agent row deleted in another Dockge instance/session sharing the same database; stale UI list after another user removed the agent.","solutions":["Check R.findOne('agent', ' url = ? ', [url]) before calling remove(), or treat the error as already-deleted and ignore it","Make sure the URL passed matches exactly the URL used in add() (same scheme, host, and port)","Refresh the agent list from the server before rendering delete actions to avoid operating on stale entries"],"exampleFix":"// before\nawait agentManager.remove(url);\n// after\nconst bean = await R.findOne(\"agent\", \" url = ? \", [url]);\nif (bean) {\n    await agentManager.remove(url);\n}","handlingStrategy":"validation","validationCode":"import { R } from \"redbean-node\";\nconst bean = await R.findOne(\"agent\", \" url = ? \", [url]);\nif (!bean) throw new Error(`Agent with url ${url} does not exist`);","typeGuard":"function agentExists(agent: unknown): agent is { url: string } {\n    return !!agent && typeof (agent as any).url === \"string\";\n}","tryCatchPattern":"try {\n    await agentManager.remove(url);\n} catch (e) {\n    if (e.message === \"Agent not found\") {\n        // already deleted; refresh list and continue\n    } else throw e;\n}","preventionTips":["Always pass the exact same URL string used in add()","Refresh the agent list before delete/rename actions","Treat removal idempotently: ignore Agent not found on repeated deletes"],"tags":["agent-manager","lookup-failed","database"],"backgroundTag":"agent-not-found","analyzedSha":"f809ae192b571944ad773e9866d3e67064ae8043","analyzedAt":"2026-08-31T19:13:50.919Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}