Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.
Record a Bot callback that could not prove which Bot it was (#136)
David McKayf2689a97ce11
diff --git a/app/src/routes/_authed/admin/audit.tsx b/app/src/routes/_authed/admin/audit.tsxindex e18600d0..4bf3dd1c 100644--- a/app/src/routes/_authed/admin/audit.tsx+++ b/app/src/routes/_authed/admin/audit.tsx@@ -35,9 +35,16 @@ const FILTERS = [{ label: "Computer actions", search: "?eventType=computer.action_allowed" },{label: "Blocked",- // Include every refusal family, not only browser policy refusals.+ /*+ * Include every refusal family, not only browser policy refusals.+ *+ * `mcp.callback_refused` is here because it is a refusal, even though nothing about a Bot was+ * judged: a caller could not prove which Bot it was. Somebody filtering for what this deployment+ * turned away wants that in the list, and it is the one refusal with no policy behind it, so+ * leaving it out would hide the only evidence that anything was attempted.+ */search:- "?eventType=computer.action_refused,mcp.call_rejected,component.refused,component.function_refused",+ "?eventType=computer.action_refused,mcp.call_rejected,mcp.callback_refused,component.refused,component.function_refused",},{label: "Did not happen",@@ -140,7 +147,13 @@ function Row({event.eventType === "computer.action_refused" ||event.eventType === "component.refused" ||event.eventType === "component.function_refused" ||- event.eventType === "mcp.call_rejected";+ event.eventType === "mcp.call_rejected" ||+ /*+ * A caller that could not prove which Bot it was. Refused like the others, and it has to read+ * that way here: the fallback below calls anything it does not recognise "Allowed", which for a+ * refusal is the one wrong answer. A trail that is confidently wrong is worse than a silent one.+ */+ event.eventType === "mcp.callback_refused";const stalled = event.eventType === "agent.stream_stalled";// Allowed by policy but not carried out. A stalled turn belongs in the same family: the Bot was// asked and the answer never arrived. Colour is how this table is read, and a row left in the@@ -228,6 +241,12 @@ function Row({{payload.reason}</div>) : null}+ {event.eventType === "mcp.callback_refused" &&+ typeof payload.refusal === "string" ? (+ <div className="mt-0.5 text-xs text-muted-foreground">+ {payload.refusal}+ </div>+ ) : null}{event.eventType === "bot.declined" &&typeof payload.reason === "string" ? (<div className="mt-0.5 text-xs text-muted-foreground">@@ -308,6 +327,8 @@ const DECISIONS: Record<string, string> = {"mcp.call_succeeded": "Called on this Bot's behalf","mcp.call_rejected": "Blocked","mcp.call_failed": "The server did not answer",+ // Not "Blocked": nothing about the Bot was judged, because nothing proved which Bot it was.+ "mcp.callback_refused": "Could not prove which Bot it was","configuration.changed": "Configuration changed","credential.created": "Credential saved",diff --git a/server/src/app.ts b/server/src/app.tsindex 2301d633..327430d3 100644--- a/server/src/app.ts+++ b/server/src/app.ts@@ -734,6 +734,36 @@ export function createApp((await agentProfileStore?.agentForCallbackToken(hash)) ?? null,});if (!verdict.ok) {+ /*+ * Recorded, because this is a boundary being held and every other one here leaves a row.+ *+ * The three outcomes inside `callTool` are all written after the caller has proved which Bot+ * it is. A caller that fails to prove it never reaches them, so this refusal used to leave+ * nothing at all — and it is the refusal behind the product's most confusing failure: a Bot+ * whose token no longer matches the deployment's has every call rejected here, returns+ * nothing to its own model, and the model tells the person there were no results. A false+ * negative delivered as an answer, with the trail agreeing nothing had happened.+ *+ * No Bot id and no actor. Both live in the credential that just failed to verify, so writing+ * them down would put an unproven claim in the record. The tool name comes from the body and+ * is capped for the same reason: it is untrusted input, kept because "which tool was being+ * reached for" is the useful half of the question.+ */+ if (auditStore) {+ await recordAuditEvent(auditStore, {+ eventType: "mcp.callback_refused",+ targetType: "mcp_tool",+ targetId:+ typeof body?.name === "string"+ ? body.name.slice(0, 120)+ : "unknown",+ payload: {+ refusal: verdict.reason,+ status: verdict.status,+ note: "A caller could not prove which Bot it was, so no grant was consulted.",+ },+ });+ }return context.json({ error: verdict.reason }, verdict.status);}diff --git a/server/src/audit.ts b/server/src/audit.tsindex 880f98b6..3be5e620 100644--- a/server/src/audit.ts+++ b/server/src/audit.ts@@ -82,6 +82,29 @@ export const auditEventTypes = [* out.*/"mcp.call_failed",+ /*+ * Something presenting itself as a Bot asked to spend a grant and was turned away at the door.+ *+ * The fourth outcome, and the only one that used to leave nothing behind. The three above are all+ * written inside `callTool`, which is reached only after the caller has proved which Bot it is.+ * A caller that fails THAT check never reaches `callTool`, so a refused callback was invisible:+ * no row, no log, nothing to count.+ *+ * Which made the most confusing failure in the product completely silent. A Bot holding a stale+ * token — the deployment's secret rotated, a container not recreated with it — has every call+ * rejected at this line, returns nothing to its own model, and the model tells the person "no+ * files were found". A false negative, delivered as an answer, about a Drive that has the files.+ * Every place a person would look to check agreed that nothing had happened.+ *+ * It is a security row as much as a diagnostic one. This endpoint is how a Bot spends grants, and+ * an unauthenticated caller probing it generated no evidence at all.+ *+ * The row deliberately does NOT name a Bot or an actor. Both arrive in the credential that just+ * failed to verify, so writing them down would be recording an unproven claim in the one place+ * that is supposed to be believed. What is recorded is what is known: that a call was attempted,+ * which tool it named, and why it was refused.+ */+ "mcp.callback_refused",/** An administrator registered this deployment's OAuth client with a vendor.*diff --git a/server/tests/agent-callback-token.test.ts b/server/tests/agent-callback-token.test.tsindex 3bf63473..29b18327 100644--- a/server/tests/agent-callback-token.test.ts+++ b/server/tests/agent-callback-token.test.ts@@ -186,3 +186,72 @@ describe("who may call a tool back, and as whom", () => {});});});++/**+ * A refused callback leaves a row, because it is a boundary being held.+ *+ * The three MCP call outcomes are all written inside `callTool`, which is reached only once the+ * caller has proved which Bot it is. A caller that fails that check never gets there, so this+ * refusal used to leave nothing behind at all: no row, no log, nothing to count.+ *+ * Which made the product's most confusing failure silent. A Bot holding a token the deployment no+ * longer accepts — a secret rotated, a container not recreated with it — has every call refused+ * here, returns nothing to its own model, and the model tells the person "no files were found". A+ * false negative delivered as an answer, with every place somebody would check agreeing that+ * nothing had happened. That is how it was found: by driving Drive and getting "no results" from a+ * Drive that had them.+ *+ * These assert the shape the row must keep. `authoriseAgentCall` is the decision the route acts on,+ * so a verdict that stops being a refusal is the thing that would silently drop the row again.+ */+describe("a callback that cannot prove which Bot it is", () => {+ test("is refused, with a reason and a status to record", async () => {+ const verdict = await authoriseAgentCall({+ presented: "obot_agt_not_a_token_this_deployment_issued",+ run: await mintRunAssertion(RUN, KEY),+ encryptionKey: KEY,+ legacyToken: "the-deployment-secret",+ lookup: async () => null,+ });++ expect(verdict.ok).toBe(false);+ if (verdict.ok) return;+ // Both are written onto the audit row, so both have to exist.+ expect(typeof verdict.reason).toBe("string");+ expect(verdict.reason.length).toBeGreaterThan(0);+ expect(verdict.status).toBeGreaterThanOrEqual(400);+ });++ test("is refused when the token is right and the run assertion is not", async () => {+ // The other half of the pair. A shared secret alone must not be enough to spend a Bot's grants:+ // without a run this deployment signed, there is no statement of who it is acting for.+ const verdict = await authoriseAgentCall({+ presented: "the-deployment-secret",+ run: "not-an-assertion-this-deployment-signed",+ encryptionKey: KEY,+ legacyToken: "the-deployment-secret",+ lookup: async () => null,+ });++ expect(verdict.ok).toBe(false);+ });++ test("carries no Bot or actor to record, which is why the row names neither", async () => {+ /*+ * The row deliberately records no bot and no actor. Both arrive inside the credential that just+ * failed to verify, so writing them down would put an unproven claim in the one place that is+ * supposed to be believed. This holds that there is nothing trustworthy to write.+ */+ const verdict = await authoriseAgentCall({+ presented: "",+ run: undefined,+ encryptionKey: KEY,+ legacyToken: "the-deployment-secret",+ lookup: async () => null,+ });++ expect(verdict.ok).toBe(false);+ expect(verdict).not.toHaveProperty("botId");+ expect(verdict).not.toHaveProperty("actorId");+ });+});