louislam/dockge · warning · Error

Agent not found

Error message

Agent not found

What it means

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.

Source

Thrown at backend/agent-manager.ts:107

    }

    /**
     *
     * @param url
     */
    async remove(url : string) {
        let bean = await R.findOne("agent", " url = ? ", [
            url,
        ]);

        if (bean) {
            await R.trash(bean);
            let endpoint = bean.endpoint;
            this.disconnect(endpoint);
            this.sendAgentList();
            delete this.agentSocketList[endpoint];
        } else {
            throw new Error("Agent not found");
        }
    }

    /**
     *
     * @param url
     * @param updatedName
     */
    async update(url: string, updatedName: string) {
        const agent = await R.findOne("agent", " url = ? ", [
            url,
        ]);
        if (agent) {
            agent.name = updatedName;
            await R.store(agent);
        } else {
            throw new Error("Agent not found");
        }

View on GitHub (pinned to f809ae192b)

Solutions

  1. Check R.findOne('agent', ' url = ? ', [url]) before calling remove(), or treat the error as already-deleted and ignore it
  2. Make sure the URL passed matches exactly the URL used in add() (same scheme, host, and port)
  3. Refresh the agent list from the server before rendering delete actions to avoid operating on stale entries

Example fix

// before
await agentManager.remove(url);
// after
const bean = await R.findOne("agent", " url = ? ", [url]);
if (bean) {
    await agentManager.remove(url);
}
Defensive patterns

Strategy: validation

Validate before calling

import { R } from "redbean-node";
const bean = await R.findOne("agent", " url = ? ", [url]);
if (!bean) throw new Error(`Agent with url ${url} does not exist`);

Type guard

function agentExists(agent: unknown): agent is { url: string } {
    return !!agent && typeof (agent as any).url === "string";
}

Try / catch

try {
    await agentManager.remove(url);
} catch (e) {
    if (e.message === "Agent not found") {
        // already deleted; refresh list and continue
    } else throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of louislam/dockge@f809ae192b (2026-08-31). Data as JSON: /api/errors/e1b8d87429f4db0a. Report an issue: GitHub.