Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Full access with no sending rule sends at most 25 a day without asking

milind-soni95de9d8f0f5e
diff --git a/server/index.ts b/server/index.ts
index 8d66da0e6f..28e585a376 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -14661,11 +14661,11 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {
}
const opaque = connectorCalls.some(call => call.slug === "COMPOSIO_PROXY_EXECUTE");
if (opaque && currentSender.connectorTools !== undefined) return refuseOutbound("OpenMausBot cannot verify this code against this bot's tool grants. Use a direct app tool.");
- // Full access sends freely unless someone set this bot a sending rule. A room turn can run at a Chief's delegated level, which only the room handoff carries.
- const sendsFreely = () => store.bot(internalCapability.botId)?.outbound === undefined && roomTurnLevels.forRequest(internalCapability.threadId, internalCapability.botId,
+ // At Full access a send asks nobody (outbound-hold.ts sets its daily cap). A room turn can run at a Chief's delegated level, which only the room handoff carries.
+ const sendsFreely = () => roomTurnLevels.forRequest(internalCapability.threadId, internalCapability.botId,
() => sourceApprovalMode(internalCapability.botId, internalCapability.threadId)) === "full";
const fullAccess = outboundTool !== null && sendsFreely();
- const held: OutboundHoldAnswer = outboundTool && !fullAccess
+ const held: OutboundHoldAnswer = outboundTool
? await outboundHold.hold({
bot: currentSender, threadId: internalCapability.threadId, tool: outboundTool, calls: outboundCalls, opaque, fullAccess,
active: () => internalCapabilityIsActive(internalCapability),
diff --git a/server/outbound-hold.test.ts b/server/outbound-hold.test.ts
index 1346fca2cb..6967c5743d 100644
--- a/server/outbound-hold.test.ts
+++ b/server/outbound-hold.test.ts
@@ -147,12 +147,62 @@ describe("createOutboundHold", () => {
});
it("reserve refuses when the hold was not approved and the policy is ask", async () => {
- const { hold, dataDir, input } = setup(bot({ policy: "ask", dailyCap: 10 }));
+ const { hold, input } = setup(bot({ policy: "ask", dailyCap: 10 }));
expect(() => hold.reserve({ ...input, fullAccess: false, approved: false })).toThrow(/outbound policy changed/);
+ });
+});
- // Full access sends freely and logs it.
- expect(() => hold.reserve({ ...input, fullAccess: true, approved: false })).not.toThrow();
- await flushDecisionLog(dataDir);
- expect(readDecisions(dataDir, 10)).toMatchObject([{ decision: "auto-approved", source: "outbound", rule: "full-access" }]);
+describe("Full access with no sending rule of its own", () => {
+ const send = async (held: ReturnType<typeof setup>) => {
+ const answer = await held.hold.hold({ ...held.input, fullAccess: true, active: () => true });
+ if (answer.ok) held.hold.reserve({ ...held.input, fullAccess: true, approved: answer.approved });
+ return answer;
+ };
+
+ it("sends 25 a day without a card and refuses the 26th, sending nothing", async () => {
+ const held = setup(bot(undefined));
+ for (let sent = 0; sent < 25; sent++) await expect(send(held)).resolves.toEqual({ ok: true, approved: false });
+ await expect(send(held)).resolves.toEqual({ ok: false, text: expect.stringMatching(/did not send this\. Scout has reached its daily limit of 25 outbound actions at Full access\. Tell the user it was not sent/) });
+ expect(held.appended, "never a card").toEqual([]);
+ expect(held.notified).toEqual([]);
+ expect(held.outboundRequests.pending("t1")).toEqual([]);
+ // A send that passed the hold just before the 25th was spent is still stopped at dispatch.
+ expect(() => held.hold.reserve({ ...held.input, fullAccess: true, approved: false })).toThrow(/daily outbound limit\. Nothing was sent/);
+ await flushDecisionLog(held.dataDir);
+ const rules = readDecisions(held.dataDir, 100).map((row) => row.rule);
+ expect(rules[0]).toBe("full-access:1/25");
+ expect(rules[24]).toBe("full-access:25/25");
+ expect(rules[25]).toBe("full-access-cap:25");
+ });
+
+ it("starts the count again the next day", async () => {
+ vi.useFakeTimers({ toFake: ["Date"] });
+ vi.setSystemTime(new Date(2026, 10, 4, 23, 30));
+ const held = setup(bot(undefined));
+ for (let sent = 0; sent < 25; sent++) await send(held);
+ await expect(send(held)).resolves.toMatchObject({ ok: false });
+ vi.setSystemTime(new Date(2026, 10, 5, 0, 5));
+ await expect(send(held)).resolves.toEqual({ ok: true, approved: false });
+ await flushDecisionLog(held.dataDir);
+ expect(readDecisions(held.dataDir, 100).map((row) => row.rule).at(-1)).toBe("full-access:1/25");
+ });
+
+ it("keeps a stored rule exactly as set: ask still asks, allow keeps its own cap", async () => {
+ const asking = setup(bot({ policy: "ask", dailyCap: 100 }));
+ const pending = asking.hold.hold({ ...asking.input, fullAccess: true, active: () => true });
+ expect(asking.appended).toHaveLength(1);
+ asking.outboundRequests.resolve({ threadId: "t1", requestId: asking.appended[0].message.card!.requestId as string, behavior: "allow" });
+ await expect(pending).resolves.toEqual({ ok: true, approved: true });
+
+ const allowing = setup(bot({ policy: "allow", dailyCap: 30 }));
+ for (let sent = 0; sent < 30; sent++) await expect(send(allowing)).resolves.toEqual({ ok: true, approved: false });
+ await expect(send(allowing)).resolves.toEqual({ ok: false, text: expect.stringMatching(/daily limit of 30 outbound actions\. Tell the user it was not sent, and ask them to raise the limit/) });
+ });
+
+ it("counts a call it cannot inspect too, and never turns it into a card", async () => {
+ const held = setup(bot(undefined));
+ for (let sent = 0; sent < 25; sent++) await held.hold.hold({ ...held.input, opaque: true, fullAccess: true, active: () => true }).then((answer) => answer.ok && held.hold.reserve({ ...held.input, opaque: true, fullAccess: true, approved: false }));
+ await expect(held.hold.hold({ ...held.input, opaque: true, fullAccess: true, active: () => true })).resolves.toMatchObject({ ok: false });
+ expect(held.appended).toEqual([]);
});
});
diff --git a/server/outbound-hold.ts b/server/outbound-hold.ts
index 29ee4d9df1..df982e08a3 100644
--- a/server/outbound-hold.ts
+++ b/server/outbound-hold.ts
@@ -1,5 +1,5 @@
-import type { ConnectorCall } from "../shared/outbound.ts";
-import { DEFAULT_OUTBOUND_POLICY } from "../shared/outbound.ts";
+import type { ConnectorCall, OutboundPolicy } from "../shared/outbound.ts";
+import { DEFAULT_OUTBOUND_POLICY, OUTBOUND_DEFAULT_CAP } from "../shared/outbound.ts";
import type { Notification } from "../shared/notification.ts";
import { HELD_NOTE } from "./auto-approve.ts";
import { appendDecision } from "./decision-log.ts";
@@ -29,10 +29,18 @@ export interface OutboundHoldDeps {
export type OutboundHoldAnswer = { ok: true; approved: boolean } | { ok: false; text: string };
+/** How many sends a day go out on their own, or null when each waits on the card. At Full access a bot with no sending
+ * rule of its own sends without asking, up to the default cap; a stored rule is kept exactly as set. */
+function outboundDailyCap(rule: OutboundPolicy | undefined, fullAccess: boolean, opaque: boolean): { cap: number; fullAccess: boolean } | null {
+ if (fullAccess && rule === undefined) return { cap: OUTBOUND_DEFAULT_CAP, fullAccess: true };
+ const policy = rule ?? DEFAULT_OUTBOUND_POLICY;
+ return policy.policy === "allow" && !opaque ? { cap: policy.dailyCap, fullAccess: false } : null;
+}
+
export interface OutboundHold {
- /** Below Full access, a send waits on the "Send on your behalf?" card or spends the daily allowance. */
+ /** A send spends the day's allowance (Full access with no rule of its own, or "allow") or waits on the "Send on your behalf?" card. `fullAccess`: the turn runs at Full access. */
hold(input: { bot: OutboundHoldBot; threadId: string; tool: string; calls: ConnectorCall[]; opaque: boolean; fullAccess: boolean; active: () => boolean }): Promise<OutboundHoldAnswer>;
- /** At dispatch time: Full access logs auto-approved; "allow" reserves against the cap; otherwise the hold must have been approved. Throws the refusal text. */
+ /** At dispatch time: a send with an allowance reserves against its cap; otherwise the hold must have been approved. Throws the refusal text. */
reserve(input: { bot: OutboundHoldBot; threadId: string; tool: string; calls: ConnectorCall[]; opaque: boolean; fullAccess: boolean; approved: boolean }): void;
}
@@ -44,19 +52,20 @@ export function createOutboundHold(deps: OutboundHoldDeps): OutboundHold {
return {
async hold({ bot: currentSender, threadId, tool: outboundTool, calls: outboundCalls, opaque, fullAccess, active }) {
const refuseOutbound = (text: string): OutboundHoldAnswer => ({ ok: false, text });
- if (fullAccess) return { ok: true, approved: false };
- const policy = currentSender.outbound ?? DEFAULT_OUTBOUND_POLICY;
+ const allowance = outboundDailyCap(currentSender.outbound, fullAccess, opaque);
const { app, calls, summary } = outboundCard(outboundCalls);
- const capNote = (count: number) =>
- `OpenMausBot did not send this. ${currentSender.name} has reached its daily limit of ${count} outbound action${count === 1 ? "" : "s"}. Ask the user to raise the limit under the bot's Permissions before trying again.`;
- if (policy.policy === "allow" && !opaque) {
- const today = outboundCounts.today(currentSender.id);
- if (today + outboundCalls.length > policy.dailyCap) {
+ const capNote = (count: number, full: boolean) =>
+ `OpenMausBot did not send this. ${currentSender.name} has reached its daily limit of ${count} outbound action${count === 1 ? "" : "s"}${full ? " at Full access" : ""}. Tell the user it was not sent, and ask them to ${full ? "set a sending rule" : "raise the limit"} under the bot's Permissions before trying again.`;
+ if (allowance) {
+ let today: number;
+ try { today = outboundCounts.today(currentSender.id); }
+ catch { return refuseOutbound("OpenMausBot did not send this: the daily allowance could not be read. Nothing was sent."); }
+ if (today + outboundCalls.length > allowance.cap) {
appendDecision(DATA_DIR, {
threadId, botId: currentSender.id, botName: currentSender.name,
- tool: outboundTool, summary, decision: "auto-denied", source: "outbound", rule: `daily-cap:${policy.dailyCap}`,
+ tool: outboundTool, summary, decision: "auto-denied", source: "outbound", rule: `${allowance.fullAccess ? "full-access-cap" : "daily-cap"}:${allowance.cap}`,
});
- return refuseOutbound(capNote(policy.dailyCap));
+ return refuseOutbound(capNote(allowance.cap, allowance.fullAccess));
}
} else {
const owner = connectorThread(currentSender.id, threadId);
@@ -117,21 +126,16 @@ export function createOutboundHold(deps: OutboundHoldDeps): OutboundHold {
const refuseDispatch: (text: string) => never = (text) => {
throw new Error(text);
};
- if (fullAccess) {
+ const allowance = outboundDailyCap(fresh.outbound, fullAccess, opaque);
+ if (allowance) {
+ let reserved: number | null;
+ try { reserved = outboundCounts.reserve(fresh.id, outboundCalls.length, allowance.cap); }
+ catch { refuseDispatch("The daily allowance could not be saved. Nothing was sent."); }
+ if (reserved === null) refuseDispatch("This bot has reached its daily outbound limit. Nothing was sent.");
appendDecision(DATA_DIR, { threadId, botId: fresh.id, botName: fresh.name,
- tool: outboundTool, decision: "auto-approved", source: "outbound", rule: "full-access" });
- } else {
- const policy = fresh.outbound ?? DEFAULT_OUTBOUND_POLICY;
- if (policy.policy === "allow" && !opaque) {
- let reserved: number | null;
- try { reserved = outboundCounts.reserve(fresh.id, outboundCalls.length, policy.dailyCap); }
- catch { refuseDispatch("The daily allowance could not be saved. Nothing was sent."); }
- if (reserved === null) refuseDispatch("This bot has reached its daily outbound limit. Nothing was sent.");
- appendDecision(DATA_DIR, { threadId, botId: fresh.id, botName: fresh.name,
- tool: outboundTool, decision: "auto-approved", source: "outbound", rule: `daily-allowance:${reserved}/${policy.dailyCap}` });
- } else if (!outboundApproved) {
- refuseDispatch("The outbound policy changed. Ask for approval again before sending.");
- }
+ tool: outboundTool, decision: "auto-approved", source: "outbound", rule: `${allowance.fullAccess ? "full-access" : "daily-allowance"}:${reserved}/${allowance.cap}` });
+ } else if (!outboundApproved) {
+ refuseDispatch("The outbound policy changed. Ask for approval again before sending.");
}
},
};
diff --git a/server/trust-controls.e2e.test.ts b/server/trust-controls.e2e.test.ts
index 8c448ca033..2548d2c202 100644
--- a/server/trust-controls.e2e.test.ts
+++ b/server/trust-controls.e2e.test.ts
@@ -18,6 +18,7 @@ let fullBot: any;
let draftBot: any;
let draftHelper: any;
let outboundPolicyBot: any;
+let capBot: any;
const gmailDrafts = new Map<string, Record<string, unknown>>();
let brokerOrigin = "";
const relayed: unknown[] = [];
@@ -114,11 +115,14 @@ beforeAll(async () => {
const policyCreated = await fetch(fixture.info.url + "/api/bots", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ name: "Full outbound policy fixture" }) });
expect(policyCreated.status).toBe(201);
outboundPolicyBot = (await policyCreated.json() as any).bot;
+ const capCreated = await fetch(fixture.info.url + "/api/bots", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ name: "Full default cap fixture" }) });
+ expect(capCreated.status).toBe(201);
+ capBot = (await capCreated.json() as any).bot;
await waitForExit(fixture.child, { signal: "SIGTERM" });
const botsFile = join(fixture.info.dataDir, "bots.json");
const bots = JSON.parse(readFileSync(botsFile, "utf8"));
const saved = bots.find((row: any) => row.id === fullBot.id);
- for (const full of [saved, ...[draftBot, draftHelper, outboundPolicyBot].map(bot => bots.find((row: any) => row.id === bot.id))]) {
+ for (const full of [saved, ...[draftBot, draftHelper, outboundPolicyBot, capBot].map(bot => bots.find((row: any) => row.id === bot.id))]) {
full.approvalMode = "full";
full.autoApprove = false;
for (const task of full.tasks) { task.approvalMode = "full"; task.autoApprove = false; }
@@ -375,6 +379,34 @@ it("honors Ask every time on Full-access delegated and resumed turns without rel
evidence.push({ outboundPolicyDelegation: readFileSync(join(fixture.info.dataDir, "gmail-plan.json.evidence.jsonl"), "utf8") });
}, 90_000);
+it("sends 25 a day at Full access with no sending rule, refuses the 26th, and a routine at the cap reports it with no card", async () => {
+ const b = capBot;
+ const email = (to: string) => ({ recipient_email: to, subject: "Reminder", body: "See you at nine." });
+ const token = await mint(b.id, b.threadId);
+ const before = relayed.length;
+ for (let sent = 0; sent < 25; sent++) expect((await relay(token, "GMAIL_SEND_EMAIL", email(`person${sent}@example.test`))).body.result.isError).not.toBe(true);
+ expect(relayed).toHaveLength(before + 25);
+ expect((await api("GET", `/api/bots/${b.id}/outbound`)).body.today).toBe(25);
+ const refused = (await relay(token, "GMAIL_SEND_EMAIL", email("[email protected]"))).body.result;
+ expect(refused.isError).toBe(true);
+ expect(refused.content[0].text).toMatch(/did not send this\. Full default cap fixture has reached its daily limit of 25 outbound actions at Full access/);
+ expect(relayed, "nothing was sent").toHaveLength(before + 25);
+
+ expect((await api("PATCH", `/api/bots/${b.id}`, { modelSelection: { instanceId: "gmailFixture", model: "claude-sonnet-5" }, threadId: b.threadId })).status).toBe(200);
+ writeFileSync(join(fixture.info.dataDir, "gmail-plan.json"), JSON.stringify({ [b.id]: { timeoutMs: 60_000,
+ steps: [{ server: "composio", tool: "GMAIL_SEND_EMAIL", arguments: email("[email protected]"), expectError: true }],
+ reply: "Report: the reminder was not sent, the daily sending limit is reached." } }));
+ const created = await api("POST", "/api/routines", { name: "Morning reminder", prompt: "Send the morning reminder email to the team.", botId: b.id, schedule: { type: "interval", everyMinutes: 1440 } });
+ expect(created.status, JSON.stringify(created.body)).toBe(201);
+ const { run } = (await api("POST", `/api/routines/${created.body.routine.id}/run`)).body;
+ let finished: any;
+ await expect.poll(async () => (finished = (await api("GET", "/api/routines")).body.runs.find((item: any) => item.id === run.id))?.status, { timeout: 45_000 }).toBe("completed");
+ expect(finished.output).toContain("Report: the reminder was not sent");
+ expect(relayed).toHaveLength(before + 25);
+ const threads = (await api("GET", "/api/bots")).body.bots.find((bot: any) => bot.id === b.id).tasks.map((task: any) => task.threadId);
+ for (const thread of threads) expect((await cards(thread)).filter((row: any) => row.card?.outboundRequest), "no card waits on anyone").toEqual([]);
+}, 90_000);
+
it("shows each outbound batch recipient and amount with explicit preview truncation before consent", async () => {
const b = await bot("Batch consent preview");
const token = await mint(b.id, b.threadId);
diff --git a/shared/outbound.ts b/shared/outbound.ts
index d9fec95a53..95f92681b5 100644
--- a/shared/outbound.ts
+++ b/shared/outbound.ts
@@ -1,6 +1,7 @@
// Outbound actions: calls that reach a person outside the app or move money.
// Below Full access they get their own confirmation, or spend an optional daily
-// allowance per bot; at Full access they run. A read-and-draft routine run never
+// allowance per bot; at Full access they run, up to OUTBOUND_DEFAULT_CAP a day
+// unless the bot has a rule of its own. A read-and-draft routine run never
// reaches them: the relay refuses every send there. Shared by the harness (which
// enforces it) and the app.
import { isConnectedAppsServer } from "./own-apps.ts";