Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

chore(scripts): add stop-mid-turn debug script

Steven Enamakel39afbe96441b
diff --git a/scripts/debug/web-scripts/stop-mid-turn.mjs b/scripts/debug/web-scripts/stop-mid-turn.mjs
new file mode 100644
index 0000000000..e48550fdb4
--- /dev/null
+++ b/scripts/debug/web-scripts/stop-mid-turn.mjs
@@ -0,0 +1,35 @@
+// Example `pnpm debug web --script` scenario: stream a slow reasoning turn
+// from the mock LLM, click the composer's Stop button mid-stream, and check
+// the turn really ends (Stop disappears, no final answer lands).
+//
+// pnpm debug web --script scripts/debug/web-scripts/stop-mid-turn.mjs
+const SLOW_THINKING = [
+ ...Array.from({ length: 30 }, (_, i) => ({ thinking: `step ${i}. `, delayMs: 1000 })),
+ { text: "FINAL-ANSWER", delayMs: 10 },
+ { finish: "stop" },
+];
+
+export default async function stopMidTurn({ page, mock, screenshot, log }) {
+ mock.set("llmStreamScript", SLOW_THINKING);
+
+ await page.getByRole("button", { name: "New Conversation" }).click();
+ const composer = page.getByRole("textbox", { name: "Message input" });
+ await composer.click();
+ await composer.pressSequentially("think about this for a long time");
+ await page.getByRole("button", { name: "Send message" }).click();
+
+ const stop = page.getByTestId("stop-generation-button");
+ await stop.waitFor({ state: "visible", timeout: 30_000 });
+ await page.waitForTimeout(3_000); // let a few reasoning chunks stream
+ await screenshot("before-stop");
+ await stop.click();
+ log("clicked Stop");
+
+ await stop.waitFor({ state: "hidden", timeout: 10_000 });
+ await page.waitForTimeout(3_000);
+ await screenshot("after-stop");
+ if (await page.getByText("FINAL-ANSWER").isVisible()) {
+ throw new Error("the turn kept running after Stop: its final answer landed");
+ }
+ log("Stop ended the turn");
+}