[GH-ISSUE #5897] Flaky e2e: live-stream-row test times out in cleanup deleting its chat (unguarded delete racing client stream teardown) #3254

Closed
opened 2026-10-21 06:01:16 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @kolacheee on GitHub (Sep 6, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5897

Originally assigned to: @SpicyMarinara on GitHub.

What happened

On PR #5894's CI (run 34052213005, job desktop-chromium 1/3), the test editing the preceding Roleplay message keeps one live stream row (e2e/core-flows.e2e.ts:7100) failed once with:

Test timeout of 60000ms exceeded.
Error: apiRequestContext.delete: Test timeout of 60000ms exceeded.
  > 7192 |     await page.request.delete(`/api/chats/${chat.id}`);

The failure is in the test's finally cleanup, not its assertions. The PR's changes (Mari workspace sandbox) don't touch anything on this path, and the same suite passed on the commit before; a rerun of the shard was started. Filing this so the flake shape is on record — one observation so far.

Why this test's cleanup is fragile by construction

Tracing the test end to end turned up a cleanup contract that guarantees a race every run; the only question is whether the race costs enough time to blow the budget.

  • The mock at e2e/core-flows.e2e.ts:7133 fulfills **/api/generate with the entire SSE body in one buffered response via page.route. The server never registers a generation for this chat — there is no server-side stream at any point.
  • The "live stream" being asserted is purely the client typewriter. The test sets streamingSpeed=55 (55 visible chars/second — packages/client/src/hooks/use-generate.ts:1554) over a ~4,500-char body, which needs ~82 seconds. The Playwright per-test budget is 60s (playwright.config.ts:33). So the typewriter cannot finish before the test ends, by design — the stream row is always live at teardown.
  • Because streaming is still live, the send-button click at :7190 is actually a Stop click (packages/client/src/components/chat/ChatInput.tsx:2162 — the button swaps to stopGeneration while streaming), which fires a local abort plus an un-awaited POST /api/generate/abort (packages/client/src/stores/chat.store.ts:144).
  • The very next line is a bare page.request.delete('/api/chats/…') — no .catch, no timeout guard, no settle-first. It races the in-flight abort POST and the client teardown with whatever budget the test has left.

The immediately preceding test ("rewrite-scroll", :7094-7096) shares the identical stop-click-then-bare-delete pattern and is presumably one bad day away from the same failure.

What it is not

To rule out the obvious suspect: DELETE /api/chats/:id (packages/server/src/routes/chats.routes.ts:1785) has no wait path. It aborts any active generation fire-and-forget (:1811), takes no per-chat lock shared with generation, and there is no 60-second constant anywhere on the route. The abort is fully wired down to the provider's fetch/reader cancel. So this is not "delete waits on the stream" — server-side, there was no stream to wait on. The remaining candidate mechanisms are all environmental (a slow file-store flush/transaction ahead of the delete's transaction, or CI runner starvation), which is exactly what a cleanup with no timeout guard is defenseless against.

Suggested fix (test-side)

Sibling tests already model the right contract:

  • The reasoning test settles streaming state before deleting (updateLiveReasoningState(page, chat.id, "stop") at :6993, then a delete with .catch).
  • bestEffortDelete (:228) wraps cleanup deletes in a 5s timeout + catch, so cleanup can never consume the test budget.

Applying either (or both) to this test and its twin at :7094-7096 makes the cleanup unable to fail the test regardless of what the delete does. Not started on a fix — just recording the diagnosis.

Noticed in passing (server-side, separate concerns)

Two small gaps in the chat-delete route surfaced while tracing, neither the cause of this flake; noting them here so they aren't lost, happy to split them into their own issues if wanted:

  1. DELETE /api/chats/:id aborts only activeGenerations, not activeAgentRuns — the dedicated POST /api/generate/abort aborts both (packages/server/src/routes/generate.routes.ts:10726). A generation that has moved into its agent tail (moveToActiveAgentRuns, :942) survives chat deletion un-aborted.
  2. The delete route removes the activeGenerations map entry immediately (chats.routes.ts:1812), which the abort route deliberately avoids — its comment (generate.routes.ts:10765) calls immediate deletion a same-chat re-registration race.

Prior art checked

No existing issue or PR mentions this test, a chat-delete hang, or apiRequestContext.delete (searched issues + PRs; read the flake ledgers #5589, #5633, #5642 and their fix PRs — all cover different tests). Closest relative is #5254 (closed): a different core-flows test whose cleanup DELETE silently 409'd — same bug class (e2e chat-deletion cleanup contract), different test and failure shape.

Originally created by @kolacheee on GitHub (Sep 6, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5897 Originally assigned to: @SpicyMarinara on GitHub. ## What happened On PR #5894's CI (run 34052213005, job `desktop-chromium 1/3`), the test **`editing the preceding Roleplay message keeps one live stream row`** (`e2e/core-flows.e2e.ts:7100`) failed once with: ``` Test timeout of 60000ms exceeded. Error: apiRequestContext.delete: Test timeout of 60000ms exceeded. > 7192 | await page.request.delete(`/api/chats/${chat.id}`); ``` The failure is in the test's `finally` cleanup, not its assertions. The PR's changes (Mari workspace sandbox) don't touch anything on this path, and the same suite passed on the commit before; a rerun of the shard was started. Filing this so the flake shape is on record — one observation so far. ## Why this test's cleanup is fragile by construction Tracing the test end to end turned up a cleanup contract that guarantees a race every run; the only question is whether the race costs enough time to blow the budget. - The mock at `e2e/core-flows.e2e.ts:7133` fulfills `**/api/generate` with the **entire SSE body in one buffered response** via `page.route`. The server never registers a generation for this chat — there is no server-side stream at any point. - The "live stream" being asserted is purely the **client typewriter**. The test sets `streamingSpeed=55` (55 visible chars/second — `packages/client/src/hooks/use-generate.ts:1554`) over a ~4,500-char body, which needs ~82 seconds. The Playwright per-test budget is 60s (`playwright.config.ts:33`). So the typewriter **cannot finish before the test ends, by design** — the stream row is always live at teardown. - Because streaming is still live, the send-button click at `:7190` is actually a **Stop** click (`packages/client/src/components/chat/ChatInput.tsx:2162` — the button swaps to `stopGeneration` while streaming), which fires a local abort plus an **un-awaited** `POST /api/generate/abort` (`packages/client/src/stores/chat.store.ts:144`). - The very next line is a **bare** `page.request.delete('/api/chats/…')` — no `.catch`, no timeout guard, no settle-first. It races the in-flight abort POST and the client teardown with whatever budget the test has left. The immediately preceding test ("rewrite-scroll", `:7094-7096`) shares the identical stop-click-then-bare-delete pattern and is presumably one bad day away from the same failure. ## What it is *not* To rule out the obvious suspect: `DELETE /api/chats/:id` (`packages/server/src/routes/chats.routes.ts:1785`) has **no wait path**. It aborts any active generation fire-and-forget (`:1811`), takes no per-chat lock shared with generation, and there is no 60-second constant anywhere on the route. The abort is fully wired down to the provider's fetch/reader cancel. So this is not "delete waits on the stream" — server-side, there was no stream to wait on. The remaining candidate mechanisms are all environmental (a slow file-store flush/transaction ahead of the delete's transaction, or CI runner starvation), which is exactly what a cleanup with no timeout guard is defenseless against. ## Suggested fix (test-side) Sibling tests already model the right contract: - The reasoning test settles streaming state **before** deleting (`updateLiveReasoningState(page, chat.id, "stop")` at `:6993`, then a delete with `.catch`). - `bestEffortDelete` (`:228`) wraps cleanup deletes in a 5s timeout + catch, so cleanup can never consume the test budget. Applying either (or both) to this test and its twin at `:7094-7096` makes the cleanup unable to fail the test regardless of what the delete does. Not started on a fix — just recording the diagnosis. ## Noticed in passing (server-side, separate concerns) Two small gaps in the chat-delete route surfaced while tracing, neither the cause of this flake; noting them here so they aren't lost, happy to split them into their own issues if wanted: 1. `DELETE /api/chats/:id` aborts only `activeGenerations`, not `activeAgentRuns` — the dedicated `POST /api/generate/abort` aborts both (`packages/server/src/routes/generate.routes.ts:10726`). A generation that has moved into its agent tail (`moveToActiveAgentRuns`, `:942`) survives chat deletion un-aborted. 2. The delete route removes the `activeGenerations` map entry immediately (`chats.routes.ts:1812`), which the abort route deliberately avoids — its comment (`generate.routes.ts:10765`) calls immediate deletion a same-chat re-registration race. ## Prior art checked No existing issue or PR mentions this test, a chat-delete hang, or `apiRequestContext.delete` (searched issues + PRs; read the flake ledgers #5589, #5633, #5642 and their fix PRs — all cover different tests). Closest relative is #5254 (closed): a different core-flows test whose cleanup DELETE silently 409'd — same bug class (e2e chat-deletion cleanup contract), different test and failure shape.
bsakaguchi 2026-10-21 06:01:16 +07:00
Author
Owner

@shoaibyazdani commented on GitHub (Sep 6, 2026):

e2e/core-flows.e2e.ts:7100 looks like where this lives — walking through the bug shape, the symptom is: flaky e2e: live-stream-row test times out in cleanup deleting its chat (unguarded….

Can put together a PR against this branch if it's still open.

—
Filed by @shoaibyazdani — happy to be un-assigned if you prefer.

<!-- gh-comment-id:5561445235 --> @shoaibyazdani commented on GitHub (Sep 6, 2026): `e2e/core-flows.e2e.ts:7100` looks like where this lives — walking through the bug shape, the symptom is: flaky e2e: live-stream-row test times out in cleanup deleting its chat (unguarded…. Can put together a PR against this branch if it's still open. — Filed by @shoaibyazdani — happy to be un-assigned if you prefer.
Author
Owner

@kolacheee commented on GitHub (Sep 6, 2026):

@shoaibyazdani thank you for the offer, however, @SpicyMarinara's presence is still intermittent at this time due to vacation, so it's better if outside contributors don't submit PRs at this time. SpicyMarinara is the only one able to merge PRs from outside contributors, unfortunately.

<!-- gh-comment-id:5561459147 --> @kolacheee commented on GitHub (Sep 6, 2026): @shoaibyazdani thank you for the offer, however, @SpicyMarinara's presence is still intermittent at this time due to vacation, so it's better if outside contributors don't submit PRs at this time. SpicyMarinara is the only one able to merge PRs from outside contributors, unfortunately.
Author
Owner

@SpicyMarinara commented on GitHub (Sep 7, 2026):

Owner: @SpicyMarinara; Codex is taking this in draft issue-sweep PR #5929. Existing issue-linked branches and open/draft PRs were checked before starting. I will verify the reported behavior against current staging and keep the fix and regression proof focused.

<!-- gh-comment-id:5573739772 --> @SpicyMarinara commented on GitHub (Sep 7, 2026): Owner: @SpicyMarinara; Codex is taking this in draft issue-sweep PR #5929. Existing issue-linked branches and open/draft PRs were checked before starting. I will verify the reported behavior against current staging and keep the fix and regression proof focused.
Author
Owner

@SpicyMarinara commented on GitHub (Sep 7, 2026):

Fixed in #5929, merged into staging as 4f67630e6. Stream cleanup now stops the test stream before deleting its chat; the full regression matrix passed.

<!-- gh-comment-id:5574822999 --> @SpicyMarinara commented on GitHub (Sep 7, 2026): Fixed in #5929, merged into staging as 4f67630e6. Stream cleanup now stops the test stream before deleting its chat; the full regression matrix passed.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#3254
No description provided.