Skip to content

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

Grok: report a provider's transient throttle as a rate limit, not the plan's quota

skygunnerc7b2af0bb5fc
diff --git a/server/drivers/acp/grok-signals.test.ts b/server/drivers/acp/grok-signals.test.ts
index c450de2744..66374fec3b 100644
--- a/server/drivers/acp/grok-signals.test.ts
+++ b/server/drivers/acp/grok-signals.test.ts
@@ -20,6 +20,8 @@ import { grokReportedFailure } from "./grok-signals.ts";
const FAKE_CLI = join(dirname(fileURLToPath(import.meta.url)), "../../testing/fake-acp-cli.ts");
const TOKIO = "grok: failed to start tokio runtime: blocking pool pre-warm stalled after 14 of 16 threads";
+// A provider the Grok CLI serves (an OpenAI-compatible router) throttling for a moment, as issue #7635 read it.
+const ROUTER_THROTTLE = "Rate limited: stream error (rate_limit_error): openai/gpt-5.2: rate limit - Semaphore timeout after 2000ms, waiting before retry";
const scratches: string[] = [];
const instances: ProviderInstance[] = [];
@@ -129,6 +131,35 @@ describe("Grok's rate-limit stop", () => {
expect(of(events, "runtime.error")[0]).not.toHaveProperty("limit");
expect(of(events, "runtime.error")[0]!.message).toMatch(/^Grok had a temporary server problem/);
});
+
+ it("leaves a router's own transient throttle a rate limit a retry can clear, and holds no quota", async () => {
+ const events = await (await start({ FAKE_ACP_MODE: "grok-complete", FAKE_ACP_COMPLETE_STOP: "rate_limit", FAKE_ACP_COMPLETE_REPLY: "never",
+ FAKE_ACP_COMPLETE_RESULT: ROUTER_THROTTLE })).ask();
+ expect(of(events, "turn.completed")).toEqual([expect.objectContaining({ ok: false, stopReason: "rpc_error" })]);
+ const [error] = of(events, "runtime.error");
+ expect(error).not.toHaveProperty("limit");
+ expect(error!.message).toMatch(/^Grok hit a rate limit/);
+ });
+});
+
+describe("Grok's rate-limit words", () => {
+ const said = (text: string): AcpReportedFailure => grokReportedFailure(Object.assign(new Error(text), { code: -32003 })) as AcpReportedFailure;
+
+ it("keeps a provider's own transient throttle a rate limit, not the account's quota", () => {
+ const throttle = said(ROUTER_THROTTLE);
+ expect(throttle.facts.message).toMatch(/^Grok hit a rate limit/);
+ expect(throttle.acpUsageLimit).toBe(false);
+ expect(said("HTTP 429: Too Many Requests").acpUsageLimit).toBe(false);
+ });
+
+ it("still reads its own usage-limit wording, and a bare rate-limit stop, as the account's quota", () => {
+ const limit = said("Rate limited: you have reached your usage limit");
+ expect(limit.facts.message).toMatch(/^This Grok account has reached its usage limit/);
+ expect(limit.acpUsageLimit).toBe(true);
+ const bare = said("Rate limited");
+ expect(bare.facts.message).toMatch(/^This Grok account has reached its usage limit/);
+ expect(bare.acpUsageLimit).toBe(true);
+ });
});
describe("what Grok is told at start and at Stop", () => {
diff --git a/server/drivers/acp/grok-signals.ts b/server/drivers/acp/grok-signals.ts
index fe29f40a6e..8908461306 100644
--- a/server/drivers/acp/grok-signals.ts
+++ b/server/drivers/acp/grok-signals.ts
@@ -34,11 +34,17 @@ export const GROK_PROMPT_COMPLETION: AcpPromptCompletion = {
},
};
+/** A provider the Grok CLI serves (say an OpenAI-compatible router) can throttle for a moment on its own; these words say
+ * so, where the Grok plan's quota would not. */
+const TRANSIENT_RATE_LIMIT = /\brate_limit_error\b|\bsemaphore timeout\b|\btoo many requests\b/i;
+
/** A prompt Grok ended for a rate limit, after its own retries: the account's usage limit, unless its words name another
- * cause (a server error, an overload, no credit), which then keeps its own words. */
+ * cause (a server error, an overload, no credit), which keeps its own words — or a provider's own transient throttle, which
+ * stays a rate limit a retry can clear, not a quota to wait out. */
function grokLimitFailure(said: string): AcpReportedFailure | undefined {
const kind = engineFailureKind(said);
if (kind !== null && kind !== "usage_limit" && kind !== "rate_limit") return undefined;
+ if (kind !== "usage_limit" && TRANSIENT_RATE_LIMIT.test(said)) return new AcpReportedFailure(engineFailure("Grok", said, { kind: "rate_limit", status: null })!, false);
return new AcpReportedFailure(engineFailure("Grok", said, { kind: "usage_limit", status: null })!, true);
}