Skip to content

fix(chat): keep a send made while the opened slot's page is still loading - #18658

Merged
iamwhatever merged 1 commit into
mainfrom
fix/e2e-member-memory-flake
Oct 10, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/e2e-member-memory-flake

Conversation

@CrysisDeu

@CrysisDeu CrysisDeu commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A message you send right after opening a chat stays on screen.

Open a session by link (/chat?sid=…) and send at once. The bubble shows, then vanishes. It only comes back when the reply ends. The E2E spec member-memory.spec.ts › a legacy configured default member keeps V1 … does exactly this and fails on expect(messages.getByText(prompt)).toBeVisible() (line 439) on unrelated branches, passing only on a retry (#18485).

A second, rarer shape in the same spec: the text query finds the bubble twice for a few frames and fails Playwright's strict mode.

Why it matters

A sent message that disappears looks lost. People send it again and the agent does the work twice. The E2E gate has a zero-flaky ceiling, so this one spec also reddens any PR it lands on.

Not a goal

What changed (motivation → approach → change)

Opening a slot runs switchSlot: pending makes the slot active (the composer is live), the page fetch goes out, fulfilled replaces the view with the page. A send in that window appends the bubble (and its echo gives it the server mid), but the page was read before the send, so fulfilled wiped it. The reducer already re-attached a reply that streamed in during the fetch; it never re-attached the user's own row.

pending now records how many rows the view held when the fetch went out (_switchLiveFrom, website/src/store/chat/state.ts). fulfilled (website/src/store/chat/slotSwitch.ts) keeps the user rows past that mark that carry a sendId and are not on the page by identity (tailNotInPage), in send order, ahead of the re-attached reply. Rows from the restored cache are below the mark, so a row the server dropped cannot ride back in; a page that already caught the send is matched by mid/sendId and not doubled.

The double bubble comes from the off-screen measure farm. A tail append reaches its count one commit before the window mounts the row, so a tick in that gap read the row as unmeasured and unmounted and rendered a hidden copy into the transcript column. The farm (website/src/hooks/virtualizer/MeasureFarm.tsx) now holds indices appended since its last count for one idle window (FARM_IDLE_MS): an appended row is either about to mount (the observer measures it) or sits below a reader who scrolled up (the farm reaches it after the hold).

The spec itself is unchanged: it was right to expect its bubble.

Backwards compatibility

Compatible: one optional transient field on ChatState; every existing switchSlot.fulfilled path produces the same transcript when nothing was sent during the fetch (liveSends is empty), and the farm only delays picking appended rows by 900 ms.

Removes nothing: additive guards only.

Tests

  • website/src/test/chatSlice.switchSlotLiveSend.test.ts (new): still-optimistic bubble kept when the page predates it; kept after its echo set the server mid; not doubled when the page already carries it; kept ahead of a reply that streamed in during the fetch; a cached row the page dropped is not resurrected. On the parent tree 3 of the 5 fail (toEqual([['user', …]]) gets []).
  • website/src/test/measureFarm.test.tsx: new case — an appended tail index is held for one idle window, then swept; a later append holds only the appended index while rows above keep sweeping. Fails on the parent (renderItem called with 0 inside the window).

Determinism proof, forced condition: a local Playwright spec routes the slot-detail response to be fetched at once and delivered 4 s later, then sends. Parent: 2/2 fail with count=0 and only the reply row on screen. Fix: 3/3 pass, count=1 (log excerpt in a PR comment). Double-bubble shape under Emulation.setCPUThrottlingRate(4), 4 workers: parent 3/30 and 1/16 runs show a second <p> under the farm's data-farm-index="0" box; fix 0/30 (twice).

Manual verification

Both specs against the same ephemeral gateway test_playwright_e2e.py boots, --repeat-each 30, --retries 0, one worker (a local harness seeds 30 legacy aliases and indexes them per repetition; that harness is not part of this PR): results posted in a PR comment (idle run; and a 2-CPU taskset run with four busy loops, where line 439 passed 30/30 and the only misses were the Capabilities editor dialog taking over 5 s to paint under that load — not a race, not seen in CI).

Related Issues

Closes #18485

Pattern harvest

Rule candidate: review-prompt
Pattern: a reducer that replaces a view with a fetched snapshot must carry forward every local row appended after the fetch was issued, not just the last one of one role.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@CrysisDeu
CrysisDeu requested review from a team and KiroCrewCaptain as code owners October 9, 2026 23:23
@CrysisDeu
CrysisDeu requested a review from bolichen97 October 9, 2026 23:23
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of a59b55dc398820b9e46093bbad7e2bdcb69f79e2 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check that the farm's 900 ms hold, which is time-based, still covers the gap between count and mount on a slow, CPU-throttled client, not just the 4× throttling the PR measured.

[DESIGN-REVIEWED] a59b55d

Description read

[DESCRIPTION-READ] 3af723e75a7df232e33a741de76230b0499263499b963d4dc9662983f386c560

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of a59b55dc398820b9e46093bbad7e2bdcb69f79e2 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: PASS

Check that a reader scrolled up mid-transcript sees no scroll jump when the held tail row is measured about 900 ms after it is appended.

[UX-REVIEWED] a59b55d

Description read

[DESCRIPTION-READ] 2bf3039c03cf90155f5422f5977a4519c64b6f4fe6c783d2087e91401d676337

That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of a59b55dc398820b9e46093bbad7e2bdcb69f79e2 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

Check that the farm's 900 ms hold on newly appended rows is the right level: the cause is that the farm's count updates a commit before the window mounts the row.

What this change ships

Inventory (3 items) — 3 justified

Intent: a message the user sends right after opening a chat by link stays on screen (a FIX, closes #18485).

  1. A message sent while the opened chat's history is still loading no longer disappears until the reply ends — justified
  2. A newly appended transcript row is no longer drawn twice for a few frames, because the off-screen measurer waits one idle window (900 ms) before measuring rows just added at the end — justified
  3. A new transient reducer marker records how many rows the view held when the slot fetch went out — justified

[FIRST-PRINCIPLES-REVIEWED] a59b55d

Description read

[DESCRIPTION-READ] cb30db1c39373180a9c233d5d068849d21cd93fee847c4548860cca01bb28e70

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of a59b55dc398820b9e46093bbad7e2bdcb69f79e2 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] a59b55d

False positive or not applicable? A repository writer can comment:
/ai-review override gpt a59b55dc398820b9e46093bbad7e2bdcb69f79e2: <one-sentence reason>

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Verification evidence for the two shapes this PR fixes. All runs drive the real dashboard against the same ephemeral gateway test/test_playwright_e2e.py boots (fake ACP backend, seeded legacy members), --retries 0.

1. The user bubble vanishes (CI line 439, "element(s) not found")

Forced condition: a local-only spec opens /chat?sid=<fresh slot>, routes GET /api/chat/slots/<key>?limit=… so the response is fetched at once but delivered 4 s later, then sends. The page is therefore read before the send and lands after it — the same ordering a loaded CI runner produces on its own.

Parent (97fdb002), 2/2 fail — the bubble is gone once the stale page lands; only the reply row is on screen:

 1506ms route: fetched slot detail early (164b), holding 4000ms
 1827ms filled
 2098ms clicked send
 2150ms input cleared
 5546ms <- 200 GET /api/chat/slots/chat-2-1791584134 msgs= running=false
11242ms FAIL expect(locator).toBeVisible() failed  Locator: getByLabel('Chat messages').getByText('Explain the next step…')
11246ms count=0
11296ms row idx=0 text="pong from the fake ACP backend…"
12814ms late count=0

Fix (aefee939), 3/3 pass — the bubble survives the page landing:

 1756ms route: fetched slot detail early (164b), holding 4000ms
 2090ms filled
 2322ms clicked send
 2334ms input cleared
 5789ms <- 200 GET /api/chat/slots/chat-1-1791584586 msgs= running=false
 6430ms count=1
 7994ms late count=1

2. The bubble is found twice (strict-mode violation)

Same spec without the delay, Emulation.setCPUThrottlingRate(4), 4 workers, a 15 ms DOM poll that dumps the transcript the moment the prompt text matches two <p> elements.

Parent: 3/30 and 1/16 runs hit it. The second copy sits inside the measure farm's hidden box (data-farm-index="0") while the real row 0 is mounted beside it:

 9676ms DUPDUMP DUP at poll 5: 2 matches
  row=0 role=user  chain=p < … < div.px-4.mx-auto.w-full[data-display-index=0]
  row=undefined role=user  chain=p < … < div.px-4.mx-auto.w-full < div < div[data-farm-index=0] < div[aria-hidden style="height:0; visibility:hidden"]
  rows=[0:Explain the next step for this]

Fix: 0/30 (and 0/30 on a second run).

3. The two flaky specs, repeated

member-memory.spec.ts › a legacy configured default member keeps V1 … and … an empty private memory opens its exact member conversation …, --repeat-each 30 --workers 1 --retries 0 (the legacy spec mutates the gateway's default agent, so one worker, as CI runs it):

  61 passed (15.0m)
stats={'expected': 61, 'skipped': 0, 'unexpected': 0, 'flaky': 0}

(61 = the auth setup project + 30 + 30.)

The same 30× under heavy load — taskset -c 0,1 for the gateway, browser and runner, plus four busy loops on the same two cores: line 439 passed 30/30. Eleven repetitions of the legacy spec missed at line 449 (/capabilities?tab=crews&crew=… editor dialog not visible within 5 s); a timing probe of that page alone under the same load shows the dialog painting 2.0–2.9 s after goto returns, so with the spec's heavier page state it crosses the 5 s assertion budget. That is load, not a race, and it has not appeared in any CI log I pulled (all 28 E2E failures of today that name this spec: line 439 on unrelated branches, or line 428 on PR #18342 only).

Unit tests on the parent

  • chatSlice.switchSlotLiveSend.test.ts: 3 of 5 fail without the reducer change ([] where the user row is expected).
  • measureFarm.test.tsx › holds rows appended at the tail…: fails without the farm change (renderItem called with 0).

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed a59b55dc398820b9e46093bbad7e2bdcb69f79e2 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] a59b55d

Verdict parsed from the review's SHA-scoped output markers for commit a59b55dc398820b9e46093bbad7e2bdcb69f79e2.

False positive or not applicable? A repository writer can comment:
/ai-review override fable a59b55dc398820b9e46093bbad7e2bdcb69f79e2: <one-sentence reason>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 9, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/e2e-member-memory-flake branch from aefee93 to 2d1143b Compare October 9, 2026 23:46
@CrysisDeu
CrysisDeu force-pushed the fix/e2e-member-memory-flake branch from 2d1143b to a59b55d Compare October 9, 2026 23:47
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 10, 2026

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a sent bubble that vanished when you sent a message right after opening a slot by deep link. The cause is fixed at its root: switchSlot.fulfilled replaced the view with a page that was read before the send. pending now records a baseline (_switchLiveFrom), and fulfilled keeps only user rows past that baseline that carry a sendId and are not already on the page by identity. A cached row the server dropped is not brought back, and a send the page already caught is not doubled. The MeasureFarm change holds rows appended since the last count for one idle window. That closes the double-render gap, and its only side effect is that an appended row is measured up to 900 ms later. I read the full diff and both new tests. They cover the optimistic case, the echoed case, the no-double case, the ordering with a streamed reply and the no-resurrection case, and the description shows 3 of 5 failing on the parent. The Design, UX and First Principles lanes all PASS on head a59b55d, checks are green, base is main, and no change request is open. — crew-pr-reviewer

@iamwhatever
iamwhatever enabled auto-merge (squash) October 10, 2026 07:57
@iamwhatever
iamwhatever merged commit 75d5edd into main Oct 10, 2026
105 of 113 checks passed
@iamwhatever
iamwhatever deleted the fix/e2e-member-memory-flake branch October 10, 2026 07:57
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 10, 2026
mbriones98 pushed a commit to mbriones98/KiroCrew that referenced this pull request Oct 12, 2026
…state

refreshSlot.fulfilled rebuilt the transcript from a count-matched page and
kept only the head above the page's first row (olderHeadAbovePage), then
copied the page's run verdict. A send made while the fetch was in flight
(the refresh fires on socket reconnect and on chat_done) is newer than the
page, so the rebuild dropped the user's row, and the page -- read before the
send -- idled the slot (slotRunning, pendingTurnSlot) under the turn the send
opened, offering Resume on a running turn. The liveFrameSeq guard protected
only slotState.

Give refreshSlot a dispatch-time baseline (liveFromAtDispatch), keep the user
rows past it with a sendId the page does not carry (tailNotInPage), and skip
the page's idle run verdict when such rows exist -- the pagePredatesLiveSend
guard switchSlot.fulfilled already uses (kirodotdev#18658 / kirodotdev#19263).

Fixes kirodotdev#19267
mbriones98 pushed a commit that referenced this pull request Oct 12, 2026
…state

refreshSlot.fulfilled rebuilt the transcript from a count-matched page and
kept only the head above the page's first row (olderHeadAbovePage), then
copied the page's run verdict. A send made while the fetch was in flight
(the refresh fires on socket reconnect and on chat_done) is newer than the
page, so the rebuild dropped the user's row, and the page -- read before the
send -- idled the slot (slotRunning, pendingTurnSlot) under the turn the send
opened, offering Resume on a running turn. The liveFrameSeq guard protected
only slotState.

Give refreshSlot a dispatch-time baseline (liveFromAtDispatch), keep the user
rows past it with a sendId the page does not carry (tailNotInPage), and skip
the page's idle run verdict when such rows exist -- the pagePredatesLiveSend
guard switchSlot.fulfilled already uses (#18658 / #19263).

Fixes #19267
mbriones98 pushed a commit that referenced this pull request Oct 12, 2026
…state

refreshSlot.fulfilled rebuilt the transcript from a count-matched page and
kept only the head above the page's first row (olderHeadAbovePage), then
copied the page's run verdict. A send made while the fetch was in flight
(the refresh fires on socket reconnect and on chat_done) is newer than the
page, so the rebuild dropped the user's row, and the page -- read before the
send -- idled the slot (slotRunning, pendingTurnSlot) under the turn the send
opened, offering Resume on a running turn. The liveFrameSeq guard protected
only slotState.

Give refreshSlot a dispatch-time baseline (liveFromAtDispatch), keep the user
rows past it with a sendId the page does not carry (tailNotInPage), and skip
the page's idle run verdict when such rows exist -- the pagePredatesLiveSend
guard switchSlot.fulfilled already uses (#18658 / #19263).

Fixes #19267
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky: a legacy configured default member keeps V1 while new members receive independent V2 memory (member-memory.spec.ts)

2 participants