Skip to content

fix(dashboard): two quick socket drops no longer mark a chat unread - #35640

Closed
bolichen97 wants to merge 1 commit into
mainfrom
fix/34420-reconnect-catchup-flag
Closed

bolichen97 wants to merge 1 commit into
mainfrom
fix/34420-reconnect-catchup-flag

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A dashboard reconnect never marks a chat unread or chimes for replayed old frames, however many reconnects overlap.

After one socket drop, the reconnect replays the gap's frames quietly, as designed. After two drops a few hundred milliseconds apart, an old turn end in the replay marks a chat unread, so the user sees an unread dot for nothing new (#34420).

Why it matters

Anyone on a flaky network, a sleeping laptop or a restarting gateway can get two drops close together. Each time, chats light up as unread and the turn-done or approval chimes can play for work that finished long ago, which teaches the user to ignore the unread dot.

Not a goal

  • Changing how long the quiet window lasts after a single reconnect, or what it suppresses.
  • A server-sent "replay done" marker or any gateway change.
  • How the reconnect backoff schedules sockets.

What changed (motivation → approach → change)

After two socket drops close together, old replayed frames no longer mark chats unread or chime: the dashboard stays quiet until the second reconnect has caught up, the same as after one drop.

Each reconnect sets one shared "catching up" flag (reconnectingRef) and clears it when its slot list read settles. With two reconnects in flight, the first read settling cleared the flag while the second socket was still replaying, so its old frames counted as news.

Reconnects are now counted (catchUpGenerationRef in website/src/hooks/websocket/connection.ts), and in website/src/hooks/websocket/reconnectCatchUp.ts a read clears the flag only when it belongs to the newest reconnect.

Backwards compatibility

Compatible: a single reconnect behaves exactly as before; only an older reconnect's read stops ending a newer one's quiet window.

Removes nothing: no field, frame, route or setting is removed or renamed.

Tests

  • website/src/hooks/websocket/reconnectCatchUp.overlap.test.ts: two reconnects in flight, the first one's slot list read settles first; the flag stays set until the second read settles. Red with the two changed files at origin/main (expected false to be true at the middle check), green on this branch and on this branch merged onto origin/main; 10 repeated runs green, and green in a shuffled run beside the other socket hook specs (--sequence.shuffle --sequence.seed=4242).

Proof: not provable -- frontend test (prove.py runs Python only)

Manual verification

Ran the built dashboard in headless Chromium, once from origin/main and once from this branch merged onto it, with /api/** stubbed and the dashboard socket routed by a script: drop the socket, reconnect with its slot list read held, drop again 300 ms later, release the first read, then replay an old turn end for a chat that is not on screen. On main that chat gets an unread dot; on this branch it does not. A live turn end sent after both reads settle still marks it unread, so the quiet window still ends.

Screenshots / video

Sidebar after the two drops and the replayed old turn end, dark theme, cropped to the session list.

Main: "Summarize the incident review" shows the unread dot (and the nav and filter badges) for an hour-old turn.

main: replayed old turn end marks the chat unread

This branch: no dot for the replayed turn end.

fix: replayed old turn end stays read

Control on this branch: a live turn end after both reads settle still shows the dot.

fix: live turn end after the window still marks unread

Related Issues

Closes #34420

#33825 replaces this slot list read with the socket's connect snapshot and ends the window the same way (only the newest reconnect's), so whichever lands second keeps that rule.

Sibling sweep

Swept: git grep -n "reconnectingRef.current =" -- website/src
Siblings: none -- reconnectingRef is written only in runReconnectCatchUp, set on open and cleared by that reconnect's read

Pattern harvest

Not generalizable: the reconnect window is the one flag here shared by overlapping runs of the same step; a rule matching every async finally that clears a ref would mostly flag ordinary single-run guards.

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

Each reconnect set one shared catch-up flag and cleared it when its own
slot list read settled. With two reconnects in flight, the first read
settling ended the quiet window while the second socket was still
replaying, so an old turn end marked a chat unread and could chime.

Count reconnect catch-ups and let only the newest one's read clear the
flag.

Closes #34420
@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 11, 2026 22:52
@bolichen97
bolichen97 requested a review from buluoray November 11, 2026 22:52
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 3a0f3dc490f814f2220ad213c4ec4398156b0b6c — 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 does not.

First-Principles-Verdict: PASS

Nothing to check.

What this change ships

Inventory (2 items) — 2 justified

Intent: after two quick socket drops, the dashboard should not mark chats unread or chime for old replayed frames. FIX (#34420).

  1. After two overlapping reconnects, old replayed frames stay quiet until the second reconnect's slot-list read settles — justified
  2. A reconnect counter on the socket connection (catchUpGenerationRef, one writer and one reader, both in runReconnectCatchUp) — justified

[FIRST-PRINCIPLES-REVIEWED] 3a0f3dc

Description read

[DESCRIPTION-READ] 68d4f164db01ac2a151a87aeebde5479964373827a20d80a104fa1b4a18b5d94

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

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 3a0f3dc490f814f2220ad213c4ec4398156b0b6c — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Generation-scoping the existing flag fixes the root cause with the smallest change, and a single reconnect behaves exactly as before.

[DESIGN-REVIEWED] 3a0f3dc

Description read

[DESCRIPTION-READ] ab4a96a6a40228cc9fd911c97e39686b0582b50c40b7d5eb19750c0435db2af5

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

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of 3a0f3dc490f814f2220ad213c4ec4398156b0b6c — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing blocks: the diff adds or changes no control, label or string, only when the existing unread dot appears after overlapping reconnects. The screenshots show the dot in the old and new behaviour.

[UX-REVIEWED] 3a0f3dc

Description read

[DESCRIPTION-READ] 7628735eb3259f3d8606e9f23254006ac8dfcb6f79b56d38d7994a786263d26e

That sha256 names everything this verdict read: the PR description, plus the 6 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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 3a0f3dc

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable 3a0f3dc490f814f2220ad213c4ec4398156b0b6c false-positive: <reason, 20 to 500 characters>

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 3a0f3dc

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 3a0f3dc490f814f2220ad213c4ec4398156b0b6c false-positive: <reason, 20 to 500 characters>

@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: Approve

Why: the decider estimates a 7% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes.

Each reconnect now takes a number from a new counter (catchUpGenerationRef), and only the newest reconnect's slot-list read can clear reconnectingRef. This fixes #34420, where an older reconnect's read ended the quiet window while a newer socket was still replaying. fetchSlots has no dedup condition, so both reads really run and the newest one is always there to end the window. Only runReconnectCatchUp writes the flag and the counter; the other files only read the flag, and its meaning for them is unchanged. A single reconnect behaves as before, the first connect and the update-restart reload never touch the counter, and the flag can only stay set if the newest read never finishes, which was already true on main. The new overlap test would fail on main at its middle check and waits on a signal rather than sleeping.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit 3a0f3dc490 · 79 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@bolichen97
bolichen97 enabled auto-merge (squash) November 11, 2026 23:18

@buluoray buluoray 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.

Approve on 3a0f3dc. After two socket drops close together, the dashboard used to mark a chat unread and could chime for an old turn that ended long ago. Each reconnect turns on a "catching up" flag and turns it off when its slot list read settles. With two reconnects in flight, the first read turned the flag off while the second socket was still replaying old frames. This change numbers each reconnect, and only the newest reconnect's read turns the flag off. A single reconnect behaves as before. The window always ends when the newest read settles, so a chat cannot stay quiet for good, and the flag lives in each tab's own socket hook, so no other tab or person is touched. I ran the new test and the other socket hook tests at this head (3 files, 18 tests, all pass). Two mutations each turn the new test red: clearing the flag on any read fails it at line 52, and never clearing the flag fails it at line 55. Non-blocking follow-ups: (1) as the existing comment says, a real reply that arrives inside the window is still not marked unread; with overlapping drops that window now lasts until the newest read, the same length one drop gets today. (2) The middle check in the test waits on the store's in-flight list, which the store updates a few microtasks before the .finally that it checks. It goes red on the bug today, but awaiting the first dispatch's own promise would make that ordering explicit. Decisive lines: website/src/hooks/websocket/reconnectCatchUp.ts:127-133, website/src/hooks/websocket/connection.ts:71, website/src/hooks/websocket/reconnectCatchUp.overlap.test.ts:52,55

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running labels Nov 11, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Superseded by #33825, which merged after this PR was opened. Its connect-snapshot wait ends the reconnect quiet window only for the newest reconnect (the same rule this PR adds), and its test a read of an earlier socket cannot end the next socket's window covers the two-drop case from #34420. This branch now conflicts with main in those same lines and would add nothing on top, so I am not re-syncing it, and #34420 is closed against #33825. This PR can be closed.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Closing as superseded: #33825 merged the same newest-reconnect rule into the same lines, with the same overlap test, so this branch now only conflicts and adds nothing (details: #35640 (comment)). #34420 is closed as completed by that merge.

[operator: bolichen97]

@bolichen97 bolichen97 closed this Nov 13, 2026
auto-merge was automatically disabled November 13, 2026 23:45

Pull request was closed

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Nov 13, 2026
@bolichen97
bolichen97 deleted the fix/34420-reconnect-catchup-flag branch November 20, 2026 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Two quick socket drops mark a chat unread from a replayed old turn end

3 participants