mirror of
https://github.com/andrewyng/openworker.git
synced 2026-09-11 06:30:25 +00:00
Keep interrupted partial streams in the transcript
GUI flushes the streaming buffer into a durable item on interrupted/error. Engine persists partial text on the provider-error path like the stop path. e2e red-green verified; full suites pass.
This commit is contained in:
@@ -567,6 +567,7 @@ export async function mockApi(page: import("@playwright/test").Page) {
|
||||
ws.send(JSON.stringify({ type, data }));
|
||||
send("ready");
|
||||
let pendingTool = "run_shell"; // which proposal the next approval decision resolves
|
||||
let epicTimer: ReturnType<typeof setInterval> | null = null; // the slow stream, stoppable via interrupt
|
||||
ws.onMessage((raw) => {
|
||||
const msg = JSON.parse(String(raw));
|
||||
if (msg.type === "user_message") {
|
||||
@@ -651,11 +652,12 @@ export async function mockApi(page: import("@playwright/test").Page) {
|
||||
if (/stream the epic/i.test(msg.text)) {
|
||||
let ticks = 0;
|
||||
const line = "The epic scrolls ever onward, line upon line upon line. ";
|
||||
const timer = setInterval(() => {
|
||||
epicTimer = setInterval(() => {
|
||||
ticks += 1;
|
||||
send("assistant_delta", { text: line.repeat(3) + "\n\n" });
|
||||
if (ticks >= 40) {
|
||||
clearInterval(timer);
|
||||
clearInterval(epicTimer!);
|
||||
epicTimer = null;
|
||||
send("assistant_message", { text: ("The epic concludes. " + line).repeat(20) });
|
||||
send("turn_done");
|
||||
}
|
||||
@@ -686,6 +688,15 @@ export async function mockApi(page: import("@playwright/test").Page) {
|
||||
send("assistant_message", { text: `Done via ${pendingTool} [decision=${msg.decision}]` });
|
||||
}
|
||||
send("turn_done");
|
||||
} else if (msg.type === "interrupt") {
|
||||
// Stop mid-stream: like the real engine, end the turn with `interrupted` and
|
||||
// NO assistant_message — the client owns promoting the partial into the transcript.
|
||||
if (epicTimer) {
|
||||
clearInterval(epicTimer);
|
||||
epicTimer = null;
|
||||
}
|
||||
send("interrupted", {});
|
||||
send("turn_done");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// Owner-hit 2026-07-22: Stop mid-stream kept the partial visible — until the NEXT message's
|
||||
// turn_start wiped it, because the partial only ever lived in the ephemeral streaming buffer
|
||||
// (assistant_message is what promotes text into the transcript, and an interrupted turn never
|
||||
// emits one). The fix flushes the buffer into a durable assistant item on interrupted/error.
|
||||
import { expect } from "@playwright/test";
|
||||
import { test } from "./fixtures";
|
||||
|
||||
test("interrupted partial stream survives the next turn", async ({ page }) => {
|
||||
await page.goto("/");
|
||||
await page.getByText("Draft the launch note").first().click();
|
||||
const box = page.getByPlaceholder(/Ask the coworker/);
|
||||
await box.fill("stream the epic");
|
||||
await box.press("Enter");
|
||||
|
||||
// Let a few deltas land, then stop the turn.
|
||||
await expect(page.getByText("The epic scrolls ever onward").first()).toBeVisible({
|
||||
timeout: 10_000,
|
||||
});
|
||||
await page.getByRole("button", { name: /Stop/ }).click();
|
||||
await expect(page.getByText("Interrupted.").first()).toBeVisible({ timeout: 5_000 });
|
||||
|
||||
// The partial is still on screen after the stop…
|
||||
await expect(page.getByText("The epic scrolls ever onward").first()).toBeVisible();
|
||||
|
||||
// …and — the regression — still there after the next turn starts and completes.
|
||||
await box.fill("continue please");
|
||||
await box.press("Enter");
|
||||
await expect(page.getByText("Echo: continue please", { exact: false }).first()).toBeVisible({
|
||||
timeout: 10_000,
|
||||
});
|
||||
await expect(page.getByText("The epic scrolls ever onward").first()).toBeVisible();
|
||||
});
|
||||
Reference in New Issue
Block a user