Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(threads): a carried question doesn't take a message steered to another own thread
AdityaUmalef508e44277f9
diff --git a/server/host/question-routing.test.ts b/server/host/question-routing.test.tsindex 608ebed798..d50a16a937 100644--- a/server/host/question-routing.test.ts+++ b/server/host/question-routing.test.ts@@ -122,6 +122,16 @@ describe("an answer passed on by another bot", () => {expect(w.answeredNodes.map((one) => one.text)).toEqual(["Excel"]);});+ it("leaves a carried question alone when the sender chose another thread itself, and still answers it unnamed when it chose none", async () => {+ const w = world();+ const node = parked(w);+ const turn = { id: "root", carrying: [node.id] } as HandoffView;+ expect(await w.routing.relay({ sender: FUCHS, senderThreadId: "inbox", senderNode: turn, target: DACHS, message: "Also check the tests.", threadId: "other-work", selected: true })).toBeUndefined();+ expect(w.answeredNodes).toEqual([]);+ expect(await w.routing.relay({ sender: FUCHS, senderThreadId: "inbox", senderNode: turn, target: DACHS, message: "Excel", threadId: "other-work" })).toMatchObject({ outcome: "injected", requestId: node.id });+ expect(w.answeredNodes.map((one) => one.text)).toEqual(["Excel"]);+ });+it("takes the requester's message to the thread its earlier work waits in as the answer, in a later turn and unnamed", async () => {const w = world();const node = parked(w);diff --git a/server/host/question-routing.ts b/server/host/question-routing.tsindex caa17696cb..cca94a1ceb 100644--- a/server/host/question-routing.ts+++ b/server/host/question-routing.ts@@ -92,15 +92,16 @@ export function createQuestionRouting(deps: QuestionRoutingDeps) {* that question, or when it goes to the thread (`threadId`) where work the sender handed on in an earlier turn waits on* a question (not on a sign-in only the person can do). Otherwise, to the thread where such work is running, it is* handed to that running turn. Work handed out in this very turn (`sentThisTurn`) stays apart: a second assignment is its- * own. Undefined when it goes into no work; a failed receipt when `answers` names work that no longer asks. */+ * own. When the sender chose `threadId` itself (`selected`: a report-back thread it steers), a question it carries from another+ * thread does not take the message. Undefined when it goes into no work; a failed receipt when `answers` names work that no longer asks. */async function relay(input: { sender: BotRecord; senderThreadId: string; senderNode?: HandoffView; target: BotRecord; message: string; answers?: string;- threadId?: string; sentThisTurn?: ReadonlySet<string> }): Promise<PeerDeliveryReceipt | undefined> {+ threadId?: string; selected?: boolean; sentThisTurn?: ReadonlySet<string> }): Promise<PeerDeliveryReceipt | undefined> {const { sender, target, message } = input;const waiting = waitingOn(target).filter((one) => deps.mayReach(input.senderThreadId, one.threadId));const ownWork = (node: HandoffView | undefined): node is HandoffView => node !== undefined && node.threadId === input.threadId&& !input.sentThisTurn?.has(node.id) && handedOnBy(node, sender.id) && deps.mayReach(input.senderThreadId, node.threadId);const pick = input.answers !== undefined ? waiting.find((one) => one.node?.id === input.answers)- : waiting.find((one) => one.node !== undefined && input.senderNode?.carrying?.includes(one.node.id) === true)+ : waiting.find((one) => one.node !== undefined && input.senderNode?.carrying?.includes(one.node.id) === true && (!input.selected || one.threadId === input.threadId))?? waiting.find((one) => ownWork(one.node) && (one.card !== undefined || !one.node.cards?.length));const refused = () => input.answers === undefined ? undefined : peerDeliveryReceipt({ botId: target.id, botName: target.name, outcome: "failed",detail: `nothing of ${target.name}'s waits on an answer as ${input.answers}: it was answered or its work ended. Send it without answers if it still needs doing` });diff --git a/server/index.ts b/server/index.tsindex 2601db7f91..b8f3371f2a 100644--- a/server/index.ts+++ b/server/index.ts@@ -13800,7 +13800,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {const continued = room || fresh ? undefined : workThreadFor(store, { botId: target.botId, botName: recipient.name, fromBotId: internalSender.id, fromThreadId: address.threadId, thread: call.thread, notice: mode === "notify",answering: coordinator.answersTo(internalCapability.roomHandoffId ?? generation), also: (task) => !CLOUD_TEAM || threadStarters.get(task.threadId) === opener, reach: (task) => outsideLineage.mayReach(address.threadId, task.threadId) });const relayed = EXTERNAL || (!call.answers && (room || fresh || mode === "consult")) ? undefined : await questionRouting.relay({ sender: internalSender, senderThreadId: address.threadId,- senderNode: coordinator.node(internalCapability.roomHandoffId ?? generation), target: recipient, message: call.message, ...(call.answers ? { answers: call.answers } : {}), ...(continued ? { threadId: continued.threadId } : {}),+ senderNode: coordinator.node(internalCapability.roomHandoffId ?? generation), target: recipient, message: call.message, ...(call.answers ? { answers: call.answers } : {}), ...(continued ? { threadId: continued.threadId, ...(steersOwn ? { selected: true } : {}) } : {}),...(internalCapability.delegatedThisTurn ? { sentThisTurn: internalCapability.delegatedThisTurn } : {}) });if (relayed) { if (relayed.outcome === "failed") refused.push(relayed.detail); receipts.push(relayed); continue; }const lane = room && lanes ? roomJobs.openLane(room, target.threadId, target.botId, internalSender, call.message) : undefined;