Skip to content

fix(chat): stop the transcript settle effect from looping - #840

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixai-chat-stop-the-transcript-sync-bddca0
Draft

posthog[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixai-chat-stop-the-transcript-sync-bddca0

Conversation

@posthog

@posthog posthog Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

  • Every open chat thread burns CPU re-rendering the whole message list, and a thread left open long enough crashes the panel with React error Workspace instruction modal for autogen and new workspace #185.
  • The settle effect in useWorkspaceAiChat.ts calls setMessages(transcriptData) with no equality guard. The AI SDK copies the array on every set, so messages identity changes, the effect (which lists messages) re-fires, and the two feed each other forever.
  • experimental_throttle: 100 paces the loop at roughly ten passive-effect updates per second, so React only throws once the nested passive-update count crosses fifty — about five seconds in.
  • The guard passes for any settled thread that has a transcript, so this is the normal idle state of the core chat surface, not an edge case. The recorded exception count is a floor: most sessions leave the thread before the limit trips and only pay the wasted renders.

Changes

  • Deep-compare the server snapshot against the local messages before setting. After the first set the two match, so the next effect run returns early and the cycle breaks.
  • Added transcriptsEqual next to serverTranscriptAdvanced, reusing the same JSON.stringify comparison the recovery path already relies on.
  • The compare runs only when the thread is settled and ready. During streaming the effect still returns early before the compare, so there is no per-chunk cost.
  • Added two unit tests: a fresh copy of the same transcript reads equal (the effect stops), and durable metadata missing from the local row reads as a difference (the snapshot still wins).

Test plan

  • pnpm test for the affected file (6 passed)
  • pnpm check (format, lint, types — clean)

Why

Users with a chat thread open sit in a passive-effect render loop that wastes CPU on the product's core chat surface and eventually crashes the panel.


Created with PostHog Desktop from this inbox report.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Review in cubic

The settle effect called setMessages(transcriptData) with no equality
guard. The AI SDK copies the array on every set, so messages identity
changed, the effect (which lists messages) re-fired, and the two fed each
other. experimental_throttle paced it at about ten passive-effect updates
per second until React threw error #185.

The guard passes for any settled thread that has a transcript, so this was
the normal idle state of the chat surface, not an edge case.

Deep-compare transcriptData against messages before setting. After the
first set the two match, so the next effect run returns early. The compare
runs only when the thread is settled and ready, never during streaming.

Generated-By: PostHog Desktop
Task-Id: a0af39e0-b4ce-4fc6-8d9d-e99ec5e3bdef
@coderabbitai

coderabbitai Bot commented Sep 10, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 1ad6184c-c05f-42e6-9bb1-0e86447f3047

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit 03e318b.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

0 participants