Skip to content

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

fix(handoffs): ask the requester's engine whether a reply needs it, never the teammate's

milind-soni73334f8b2ba1
diff --git a/server/coordinator.ts b/server/coordinator.ts
index 63999e33f5..7554a90526 100644
--- a/server/coordinator.ts
+++ b/server/coordinator.ts
@@ -149,8 +149,10 @@ export interface CoordinatorHost {
shareAnswer?(first: HandoffView, joiner: HandoffView): boolean;
/** `node` waits for `first`'s answer instead of running its own turn (only ever a request outside a room). */
joined?(node: HandoffView, first: HandoffView): void;
- /** One word from a small model about `node`'s reply (runtime/status-reply.ts). Absent, undefined or a throw: its requester wakes. */
- statusReply?(node: HandoffView, prompt: string, signal: AbortSignal): Promise<string | undefined>;
+ /** One word from a small model about a teammate's reply (runtime/status-reply.ts), on `requesterBotId`'s own engine: the
+ * requester's turn is what the answer may save, and the teammate's engine is busy with the teammate's work. Absent,
+ * undefined or a throw: the requester wakes. */
+ statusReply?(requesterBotId: string, prompt: string, signal: AbortSignal): Promise<string | undefined>;
}
export interface Coordinator {
diff --git a/server/index.ts b/server/index.ts
index 167f5425e6..e7d8adf833 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -3958,7 +3958,7 @@ const handoffTicks = createHandoffTicks(), coordinator: Coordinator = createCoor
standingThreadOf: botId => botMainThread(botId) ?? store.bot(botId)?.threadId,
botOfThread: threadId => store.botByThread(threadId)?.id,
},
- host: { statusReply: (node, prompt, signal) => sideJobs.text("status-reply", node.botId)?.generateText(prompt, { signal, timeoutMs: STATUS_REPLY_TIMEOUT_MS }) ?? Promise.resolve(undefined),
+ host: { statusReply: (requester, prompt, signal) => sideJobs.text("status-reply", requester)?.generateText(prompt, { signal, timeoutMs: STATUS_REPLY_TIMEOUT_MS }) ?? Promise.resolve(undefined),
validate: (node, parent) => node.mode === "notify" && node.status !== "queued" ? undefined
: !node.parentId && node.groupId ? roomRootProblem(node)
: roomHandoffProblem(node, parent) ??
diff --git a/server/runtime-coordinator.test.ts b/server/runtime-coordinator.test.ts
index 04282c8a1e..8d861d5a1e 100644
--- a/server/runtime-coordinator.test.ts
+++ b/server/runtime-coordinator.test.ts
@@ -30,6 +30,7 @@ interface Host extends CoordinatorHost {
levels: Record<string, { level: Level; driverKind?: string }>;
chiefs: Set<string>;
statusAsks?: string[];
+ statusAskers?: string[];
release(id: string, outcome: Outcome): Promise<void>;
}
@@ -899,12 +900,14 @@ describe("RuntimeCoordinator: modes and openers", () => {
handoff(w, chief, "gen-1", undefined, tester, "FYI: the mailbox moved.", ask);
ended(w, "gen-1");
w.coordinator.tick(); await flush(); w.coordinator.tick(); await flush();
- return { resumed: w.host.runs.some(run => run.node.id === "gen-1"), asked: w.host.statusAsks };
+ return { resumed: w.host.runs.some(run => run.node.id === "gen-1"), asked: w.host.statusAsks, askers: w.host.statusAskers };
};
const asking = (answer: string | undefined | Error) => {
const w = world();
w.host.statusAsks = [];
- w.host.statusReply = async (_node, prompt) => {
+ w.host.statusAskers = [];
+ w.host.statusReply = async (asker, prompt) => {
+ w.host.statusAskers!.push(asker);
w.host.statusAsks!.push(prompt);
if (answer instanceof Error) throw answer;
return answer;
@@ -913,8 +916,10 @@ describe("RuntimeCoordinator: modes and openers", () => {
};
it("spends no requester turn on a plain ACK, and shows the helper both messages as data", async () => {
- const { resumed, asked } = await after(asking("ACK"), {}, {});
+ const { resumed, asked, askers } = await after(asking("ACK"), {}, {});
expect(resumed).toBe(false);
+ // The requester's engine answers, never the teammate's, whose engine is busy with the work itself.
+ expect(askers).toEqual(["chief"]);
expect(asked).toHaveLength(1);
expect(asked![0]).toContain("<sender_message>\nFYI: the mailbox moved.\n</sender_message>");
expect(asked![0]).toContain("<teammate_reply>\nNoted, thanks.\n</teammate_reply>");
diff --git a/server/runtime-coordinator.ts b/server/runtime-coordinator.ts
index 491aeb3be6..9e9adb1be2 100644
--- a/server/runtime-coordinator.ts
+++ b/server/runtime-coordinator.ts
@@ -511,10 +511,10 @@ export class RuntimeCoordinator implements Coordinator {
};
}
- private async statusOnly(a: Assignment, parent: Assignment | undefined, turn: RunInput["turn"], result: HostTurnResult, node: HandoffView, signal: AbortSignal): Promise<boolean> {
+ private async statusOnly(a: Assignment, parent: Assignment | undefined, turn: RunInput["turn"], result: HostTurnResult, signal: AbortSignal): Promise<boolean> {
if (turn !== "first" || !this.host.statusReply || !mayBeStatusOnly(a, parent, result.text, result.evidence)) return false;
try {
- return isStatusOnly(await this.host.statusReply(node, statusReplyPrompt(a.brief, result.text), signal));
+ return a.requester.botId !== undefined && isStatusOnly(await this.host.statusReply(a.requester.botId, statusReplyPrompt(a.brief, result.text), signal));
} catch (error) {
this.log(`status reply check failed: ${String(error)}`);
return false;
@@ -549,7 +549,7 @@ export class RuntimeCoordinator implements Coordinator {
if (result.cards) return { kind: "needs_input", question: result.cards.question, cards: result.cards.ids, ...evidence(result) };
if (!result.ok) return { kind: "failed", outcome: result.stalled ? "stalled" : "provider_error", text: result.text, ...evidence(result) };
const question = root ? undefined : needsInputQuestion(result.text);
- if (question === undefined) return { kind: "completed", text: result.text, ...(await this.statusOnly(a, parent, input.turn, result, node, signal) ? { statusOnly: true } : {}), ...evidence(result) };
+ if (question === undefined) return { kind: "completed", text: result.text, ...(await this.statusOnly(a, parent, input.turn, result, signal) ? { statusOnly: true } : {}), ...evidence(result) };
const named = withDefault(question);
const decide = requesterDecides(a) && !result.privateQuestion && !personOnly(named.question) ? { decide: named.default ? { default: named.default } : {} } : {};
return { kind: "needs_input", question, ...decide, ...evidence(result) };