Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Cancel queued app-event runs when the bot loses the account
Bugfixer 264ba5ebeda09
diff --git a/server/app-triggers.test.ts b/server/app-triggers.test.tsindex a3e276477c..1ddfe0472f 100644--- a/server/app-triggers.test.ts+++ b/server/app-triggers.test.ts@@ -564,6 +564,18 @@ describe("a bot limited to some accounts of an app", () => {expect(triggers.get(trigger.id)?.problem).toBeUndefined();});+ it("cancels runs still queued when the bot loses the account", async () => {+ let allowed: string[] | undefined;+ const triggers = manager({ accountLimit: () => allowed });+ const trigger = await triggers.create({ botId: "bot-1", name: "Sales", prompt: "Draft a reply.", app: "gmail", event: "GMAIL_NEW_GMAIL_MESSAGE", account: "sales" });+ await broker.deliver(trigger.remote.triggerId!, { subject: "Hello", sender: "[email protected]" }, "msg_q1");+ await drain(triggers);+ expect(runsOf(trigger.id)).toMatchObject([{ status: "queued" }]);+ allowed = [support];+ await triggers.reconcile();+ expect(runsOf(trigger.id)).toMatchObject([{ status: "cancelled", error: expect.stringContaining("may no longer use this account") }]);+ });+it("lists only the accounts the bot may use in its event list", async () => {const client = brokerClient(() => ({ url: broker.url, token: owner.token }));const bot = { connectorScopes: { apps: { gmail: "read" as const }, accounts: { gmail: [support] } } };diff --git a/server/app-triggers.ts b/server/app-triggers.tsindex bc0b13406c..4fd864e87e 100644--- a/server/app-triggers.ts+++ b/server/app-triggers.ts@@ -647,6 +647,8 @@ export class AppTriggerManager {private async reconcileOne(trigger: StoredTrigger, bindings: Map<string, BrokerInventory["triggers"][number]>, accounts: ConnectedApps | null): Promise<void> {// Its bot is gone: paused here, so Composio stops sending what no one would run.if (trigger.enabled && this.options.botState(trigger.botId) === "missing") trigger.enabled = false;+ const allowed = this.botMayUse(trigger.botId, trigger.app, trigger.accountId);+ if (!allowed) this.options.runs.cancelQueued(trigger.id, "Its bot may no longer use this account, so this event's run did not start");const account = accounts?.[trigger.app]?.accounts.find((candidate) => candidate.id === trigger.accountId);if (accounts && (!account || !active(account.status))) {if (trigger.problem?.kind !== "reconnect") trigger.problem = { kind: "reconnect", at: this.now() };@@ -662,7 +664,6 @@ export class AppTriggerManager {}trigger.remote = { triggerId: binding.triggerId, state: "active", syncedAt: this.now() };// Kept, not re-stamped, while the account stays off the bot's list, so each pass does not announce it again.- const allowed = this.botMayUse(trigger.botId, trigger.app, trigger.accountId);if (trigger.problem?.kind === "error" && (allowed || trigger.problem.text !== ACCOUNT_NOT_ALLOWED)) delete trigger.problem;if (!allowed && !trigger.problem) trigger.problem = { kind: "error", text: ACCOUNT_NOT_ALLOWED, at: this.now() };}