Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(waits): leave no wait behind when its card cannot be written
DeryFerd705d21f49b0b
diff --git a/server/waits.test.ts b/server/waits.test.tsindex ff6c42c1a6..21de9e77b6 100644--- a/server/waits.test.ts+++ b/server/waits.test.ts@@ -286,6 +286,31 @@ describe("WaitManager", () => {expect(h.showCard).toHaveBeenCalledTimes(1);});+ it("stores no wait when its card could not be written, so a failed call leaves nothing behind", async () => {+ const error = vi.spyOn(console, "error").mockImplementation(() => undefined);+ const h = harness();+ // A message database that refuses the append: the tool call fails, and the model will ask again.+ h.showCard.mockImplementation(() => { throw new Error("disk full"); });+ await expect(h.create({ kind: "file_exists", path: "/r.txt" }, { followUp: "Summarise it." })).rejects.toThrow("disk full");+ expect(h.manager.list("bot-1")).toEqual([]);+ expect(h.reload().owners()).toEqual([]);+ error.mockRestore();+ });++ it("reports the card's own error when taking the wait back out also fails", async () => {+ const error = vi.spyOn(console, "error").mockImplementation(() => undefined);+ const h = harness();+ h.showCard.mockImplementation(() => { throw new Error("card append failed"); });+ // The first save stores the wait; the cleanup save fails too, as a full disk would.+ let saves = 0;+ vi.spyOn(h.manager as unknown as { save(): void }, "save").mockImplementation(() => {+ saves += 1;+ if (saves === 2) throw new Error("cleanup save failed");+ });+ await expect(h.create({ kind: "file_exists", path: "/r.txt" }, { followUp: "Summarise it." })).rejects.toThrow("card append failed");+ error.mockRestore();+ });+it("fires once: one line, one follow-up, the card settled, and the wait gone", async () => {const h = harness();await h.create({ kind: "file_exists", path: "/r.txt" }, { label: "the report", followUp: "Summarise it." });diff --git a/server/waits.ts b/server/waits.tsindex 7177a809b9..bdf2157366 100644--- a/server/waits.ts+++ b/server/waits.ts@@ -223,7 +223,20 @@ export class WaitManager {};this.commit(() => this.waits.push(wait));if (wait.followUp) {- const cardMessageId = this.options.showCard(wait as WaitRecord & { followUp: string });+ let cardMessageId: string | undefined;+ try {+ cardMessageId = this.options.showCard(wait as WaitRecord & { followUp: string });+ } catch (error) {+ // The card is how the person cancels this wait, so a call whose card cannot be written must leave nothing+ // behind: the tool call fails and the model asks again, instead of a wait nobody can see. When that cleanup+ // also fails, the caller still needs the reason the card could not be written.+ try {+ this.commit(() => { this.waits = this.waits.filter((w) => w !== wait); });+ } catch (cleanupError) {+ console.error(`wait ${wait.id}: could not take the wait back out`, cleanupError);+ }+ throw error;+ }if (cardMessageId) {try { this.commit(() => { wait.cardMessageId = cardMessageId; }); } catch (error) { console.error(`wait ${wait.id}: could not store the card id`, error); }}