Skip to content

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

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

improvement(mothership): stream retry state machine, progressive re-rendering#4287
icecrasher321 merged 2 commits intostagingfrom
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
Copy link
Copy Markdown

vercel Bot commented Apr 24, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 24, 2026 6:47pm

Request Review

@icecrasher321 icecrasher321 changed the title improvement(mothership): stream rety state machine, progressive re-renndering improvement(mothership): stream rety state machine, progressive re-rendering Apr 24, 2026
@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 24, 2026

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-apps Bot commented Apr 24, 2026

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

Filename Overview
apps/sim/app/api/copilot/chat/stream/route.ts Hardens 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.ts Refactors 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.tsx Integrates 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.ts Wraps 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.ts Adds mock for encodeSSEComment and asserts ': accepted\n\n' is the first chunk of every replay response.
apps/sim/lib/copilot/request/go/stream.test.ts Adds three no-retry tests for 502, 402, and network errors.

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

Comment thread apps/sim/app/api/copilot/chat/stream/route.ts
Comment thread apps/sim/hooks/use-progressive-list.ts
@icecrasher321 icecrasher321 changed the title improvement(mothership): stream rety state machine, progressive re-rendering improvement(mothership): stream retry state machine, progressive re-rendering Apr 24, 2026
@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

Copy link
Copy Markdown

@cursor cursor Bot left a comment

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 staging Apr 24, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the improvement/mothership-prog-render branch April 24, 2026 20:50
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.

1 participant