Skip to content

improvement(mothership): stream retry state machine, progressive re-rendering - #4287

Merged
icecrasher321 merged 2 commits into
stagingfrom
improvement/mothership-prog-render
Apr 24, 2026
Merged

improvement(mothership): stream retry state machine, progressive re-rendering#4287
icecrasher321 merged 2 commits into
stagingfrom
improvement/mothership-prog-render

Conversation

@icecrasher321

Copy link
Copy Markdown
Collaborator

Summary

  • Progressive chat rendering
  • Harden copilot stream/replay handling

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercelBot commented Apr 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
ProjectDeploymentActionsUpdated (UTC)
docsSkippedSkippedApr 24, 2026 6:47pm

Request Review

@icecrasher321icecrasher321 changed the title improvement(mothership): stream rety state machine, progressive re-rennderingimprovement(mothership): stream rety state machine, progressive re-renderingApr 24, 2026
@cursor

cursorBot commented Apr 24, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Medium risk because it changes Copilot SSE replay behavior (new comment frames/keepalives) and refactors progressive message rendering state, which can affect reconnect reliability and chat UI scrolling/rendering under load.

Overview
Copilot stream replay now writes SSE comments: an immediate : accepted acknowledgment plus periodic : keepalive comments during idle replay polling, with replay enqueue helpers updated to track last-write time and stop cleanly on enqueue failures.

Chat UI now progressively stages message rendering via useProgressiveList, including scroll-to-bottom behavior during staging and a memoized lookup for the preceding user message used by MessageActions.

Go stream fetch instrumentation is hardened by ending the fetch span and recording header timing when fetchGo throws before a response is available; tests were added to assert stream loops do not retry on HTTP errors or network failures.

Reviewed by Cursor Bugbot for commit 7bba0c5. Configure here.

@greptile-apps

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR hardens the copilot stream/replay state machine with three improvements: (1) the replay route now immediately emits an accepted SSE comment and periodic keepalive comments to prevent proxy timeouts, (2) the gap-replay loop correctly advances cursor, currentRequestId, and sawTerminalEvent per envelope (a real bug fix from the prior code that silently dropped these updates), and (3) the chat UI renders messages progressively using a refactored useProgressiveList hook backed by a structured state machine instead of scattered mutable refs.

Confidence Score: 5/5

Safe to merge — all findings are P2 informational notes; no functional regressions identified.

The gap-replay cursor/state fix is a genuine correctness improvement. The two P2 notes are both self-correcting and do not affect user-visible behaviour.

No files require special attention beyond the noted P2 items in route.ts and use-progressive-list.ts.

Important Files Changed

FilenameOverview
apps/sim/app/api/copilot/chat/stream/route.tsHardens replay stream: adds accepted SSE comment on open, keepalive comments every 15 s, and fixes the gap-replay loop to correctly advance cursor, currentRequestId, and sawTerminalEvent.
apps/sim/hooks/use-progressive-list.tsRefactors progressive list hook to a structured state machine with two separate effects; a stale closure in the rAF step can cause one frame of premature caughtUp but the sync effect corrects it immediately.
apps/sim/app/workspace/[workspaceId]/home/components/mothership-chat/mothership-chat.tsxIntegrates useProgressiveList for staged message rendering and replaces per-message O(n) .reverse().find() with a single O(n) useMemo pass.
apps/sim/lib/copilot/request/go/stream.tsWraps fetchGo in try/catch so network-level errors properly close the fetch OTel span before re-throwing.
apps/sim/app/api/copilot/chat/stream/route.test.tsAdds mock for encodeSSEComment and asserts ': accepted\n\n' is the first chunk of every replay response.
apps/sim/lib/copilot/request/go/stream.test.tsAdds three no-retry tests for 502, 402, and network errors.

Reviews (1): Last reviewed commit: "improvement(mothership): stream rety sta..." | Re-trigger Greptile

Comment threadapps/sim/app/api/copilot/chat/stream/route.ts
Comment threadapps/sim/hooks/use-progressive-list.ts
@icecrasher321icecrasher321 changed the title improvement(mothership): stream rety state machine, progressive re-renderingimprovement(mothership): stream retry state machine, progressive re-renderingApr 24, 2026
@icecrasher321

Copy link
Copy Markdown
CollaboratorAuthor

bugbot run

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 7bba0c5. Configure here.

@icecrasher321
icecrasher321 merged commit 5604477 into stagingApr 24, 2026
14 checks passed
@waleedlatif1
waleedlatif1 deleted the improvement/mothership-prog-render branch April 24, 2026 20:50
Sign up for freeto 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.

1 participant

@icecrasher321