paperclipai/paperclip · error · ToolGatewayHttpError

run_agent_mismatch

run_agent_mismatch

Error message

Run does not belong to agent

What it means

Ownership guard following the company check: the run exists in the right company but belongs to a different agent than the caller. Prevents agents from reading or attaching to other agents' runs; the mismatched agentId/run pair is at fault.

Solutions

  1. Use a run that belongs to the calling agent; an agent cannot act on runs of other agents.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at server/src/services/tool-gateway.ts:1066 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of paperclipai/paperclip@3f1d897a7c (2026-09-18). Data as JSON: /api/errors/54e4be9770bc2474. Report an issue: GitHub.

Appendix: source

Thrown at server/src/services/tool-gateway.ts:1492

      .select({
        companyId: heartbeatRuns.companyId,
        agentId: heartbeatRuns.agentId,
        status: heartbeatRuns.status,
        contextSnapshot: heartbeatRuns.contextSnapshot,
      })
      .from(heartbeatRuns)
      .where(eq(heartbeatRuns.id, input.runId))
      .limit(1);

    if (!run || run.companyId !== input.companyId) {
      throw new ToolGatewayHttpError(
        403,
        "Run does not belong to company",
        "run_company_mismatch",
      );
    }
    if (run.agentId !== input.agentId) {
      throw new ToolGatewayHttpError(
        403,
        "Run does not belong to agent",
        "run_agent_mismatch",
      );
    }
    if (!ACTIVE_GATEWAY_RUN_STATUSES.has(run.status)) {
      throw new ToolGatewayHttpError(403, "Run is not active", "run_inactive");
    }

    const snapshot = asRecord(run.contextSnapshot);
    const snapshotIssueId = stringValue(snapshot?.issueId);
    const snapshotProjectId = stringValue(snapshot?.projectId);
    if (
      (input.issueId && snapshotIssueId && input.issueId !== snapshotIssueId) ||
      (input.projectId &&
        snapshotProjectId &&
        input.projectId !== snapshotProjectId)
    ) {

View on GitHub (pinned to 3f1d897a7c)