Skip to content

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

refactor(limits): no narrating comments in the hand-off limits module

Absterrg04425b3077d5e
diff --git a/server/host/handoff-limits.ts b/server/host/handoff-limits.ts
index 0115c362f1..9af6b26c57 100644
--- a/server/host/handoff-limits.ts
+++ b/server/host/handoff-limits.ts
@@ -1,6 +1,7 @@
import type { ModelSelection } from "../../shared/wire.ts";
import type { HandoffView, HostTurnResult } from "../coordinator.ts";
import type { LimitResetClock } from "../limit-resets.ts";
+import type { TurnEvidence } from "../runtime/types.ts";
import type { Store } from "../store.ts";
import type { LimitTakeover } from "./limit-takeover.ts";
@@ -8,18 +9,20 @@ const LIMIT_CARRIED_NOTE = "Your previous turn stopped because its AI reached it
type Refusal = NonNullable<HostTurnResult["refusedBy"]>;
+function progressUnknownUnlessMade(evidence: TurnEvidence | undefined): TurnEvidence {
+ const { okToolCalls, ...rest } = evidence ?? {};
+ return okToolCalls ? { ...rest, okToolCalls } : rest;
+}
+
export interface HandoffLimitsDeps {
store: Pick<Store, "projectBotForTask" | "bot">;
limitClock: Pick<LimitResetClock, "noteLimit">;
takeover: Pick<LimitTakeover, "noteSignedOut" | "holdModel" | "heldAtStart">;
- /** OMB_QUOTA_SWITCH: off, nothing carries on by itself. */
enabled(): boolean;
engineName(instanceId: string): string;
}
export function createHandoffLimits(deps: HandoffLimitsDeps) {
- /** A refusal recorded as one at a turn's start is: every turn of that AI while it holds, this job's next run included,
- * starts on an AI that can carry it on. */
const hold = (selection: ModelSelection, refusal: Refusal): void => {
if (refusal.scope === "signed-out") deps.takeover.noteSignedOut(selection.instanceId);
else if (refusal.scope === "engine") deps.limitClock.noteLimit(selection.instanceId, refusal.resetsAt);
@@ -27,21 +30,16 @@ export function createHandoffLimits(deps: HandoffLimitsDeps) {
};
return {
- /** The AI a job's conversation ran on, for its evidence, when it is not its bot's own. */
servedBy(node: HandoffView): { servedBy?: string } {
const ran = deps.store.projectBotForTask(node.botId, node.threadId)?.modelSelection, own = deps.store.bot(node.botId)?.modelSelection;
return ran && own && (ran.instanceId !== own.instanceId || ran.model !== own.model) ? { servedBy: `${deps.engineName(ran.instanceId)} ${ran.model}` } : {};
},
- /** A hand-off job its AI's usage limit or sign-out refused runs again while another AI can carry it on: its next
- * turn's start moves its conversation alone there, as for any turn of that AI. Undefined for any other outcome. */
carriedOn(node: HandoffView, result: HostTurnResult): HostTurnResult | undefined {
const refusal = result.refusedBy, thread = deps.store.projectBotForTask(node.botId, node.threadId);
if (result.ok || !refusal || !node.parentId || node.groupId || !thread || !deps.enabled()) return undefined;
hold(thread.modelSelection, refusal);
if (deps.takeover.heldAtStart(thread, thread.modelSelection) === null) return undefined;
- // A refusal is not the job stalling: no tool call that worked is progress-unknown, never a no-progress strike.
- const { okToolCalls, ...rest } = result.evidence ?? {};
- return { ...result, evidence: okToolCalls ? { ...rest, okToolCalls } : rest, cap: { note: LIMIT_CARRIED_NOTE } };
+ return { ...result, evidence: progressUnknownUnlessMade(result.evidence), cap: { note: LIMIT_CARRIED_NOTE } };
},
};
}
diff --git a/server/host/limit-takeover.ts b/server/host/limit-takeover.ts
index 34080c6f15..2b3a3dc646 100644
--- a/server/host/limit-takeover.ts
+++ b/server/host/limit-takeover.ts
@@ -83,14 +83,11 @@ interface SavedHolds { models?: Record<string, ModelHold>; signedOut?: Record<st
export function signedOutStop(stopReason: string | null | undefined, said: string | undefined): boolean {
return stopReason === "auth_required" && !(said && (engineFailureKind(said) === "credits" || classifyError({ text: said }).reason === "quota"));
}
-/** What refused a turn another AI may carry on: its AI's usage limit (`limit`, when the engine said which one) or its
- * sign-out; undefined for any other failure. A tool call's failure names the tool, never the engine's own limit,
- * whatever its words. */
export function takeoverRefusal(stopReason: string | null | undefined, said: string | undefined, limit: LimitScope | undefined): TakeoverScope | undefined {
if (signedOutStop(stopReason, said)) return "signed-out";
+ // A tool call's failure names the tool, never the engine's own limit, whatever its words.
return limit ?? (stopReason !== "tool_error" && classifyError({ text: said ?? "" }).reason === "quota" ? "engine" : undefined);
}
-/** That refusal as a job's outcome carries it: which one, and when the limit said it resets. */
export function turnRefusal(stopReason: string | null | undefined, said: string | undefined,
flags: { limit?: LimitScope; limitResetsAt?: number } | undefined): { scope: TakeoverScope; resetsAt?: number } | undefined {
const scope = takeoverRefusal(stopReason, said, flags?.limit);