Skip to content

perf(client): keep latestTurn and checkpoint refs stable while streaming - #227

Open
leoisadev1 wants to merge 2 commits into
mainfrom
leoisadev1/t3-port-thread-ref-stability
Open

perf(client): keep latestTurn and checkpoint refs stable while streaming#227
leoisadev1 wants to merge 2 commits into
mainfrom
leoisadev1/t3-port-thread-ref-stability

Conversation

@leoisadev1

@leoisadev1 leoisadev1 commented Sep 10, 2026

Copy link
Copy Markdown
Member

Problem

Every assistant streaming delta rebuilt latestTurn as a new object even when nothing in it changed. Selectors and memos keyed on that record reran for no reason during a reply.

Adaptation

reuseLatestTurn returns the previous object when turn identity, state, timestamps, assistant message id, request/responding-bot ids, and proposed-plan ids all match. thread.message-sent and thread.session-set go through that helper. Checkpoints already kept the input array when no rebind was needed. Same-turn recomputes also keep an existing sourceProposedPlan so Akeru plan links are not dropped.

Messages still get a new array on each delta, as they must.

Upstream credits

Reviewed adaptation of T3 Code #9145.

Scope

Client reducer reference stability only. Server replay, subscription lifetime, config bootstrap, and static caching are separate PRs.

Verification

Head e3f241faad09c6547413bcc1322cf822335ed559 on leoisadev1/t3-port-thread-ref-stability. Isolated home /tmp/akeru-227-verify.QyRxU8 (populated fixture plus a second bot, Crew group, bound checkpoints, and later live Mastra turns). Web on this branch only. #216 stills were not reused.

  • vp test run packages/client-runtime/src/state/threadReducer.test.ts: 36 passed, including streaming-reference and first-bind cases
  • vp run --filter @t3tools/client-runtime typecheck passed
  • Targeted lint on the two changed files passed

Integrated web pass on BotThreadLanding and GroupThreadLanding:

  • First bind after pairing loaded Scout, Ranger, and Crew. Scout's latest chat was the streaming fixture thread.
  • Sending "Ping the reconnect path." started a live Mastra turn. The roster showed a working dot and the chat showed "Scout is working", then settled to the fallback "I could not complete that request."
  • Reload of /bots/ui-scout kept both user lines and the fallback reply. No re-pair.
  • Crew accepted "Crew ping for reconnect." Scout answered with the same fallback. Retry after a group reload restored that transcript.

Scout live turn working
Scout turn settled to fallback
Scout reload kept the settled turn
Crew live send settled to fallback

What this did not prove

  • Provider streaming of a real assistant delta. The isolated home has no provider credentials. Both live turns are mastra-turn-* in error with no new checkpoint_ref.
  • Checkpoint UI. Snapshots for ui-thread-0 and ui-group-thread-0 return bound checkpointRef + README.md files, and the live threads still carry the seeded checkpoint row. Bot/group landing does not mount DiffPanel. Ctrl+D did nothing there.
  • Command palette conversation search. "Make remote coding" returned no matches. Projection fixture chats are not in that index.

Group reload crash (not this diff)

A full reload of /groups/ui-crew hit "This view failed to load": Rendered more hooks than during the previous render from useReplyPlaybackThread in GroupThreadLanding. Retry restored the chat. useReplyPlaybackThread runs after if (!group) return null, so the first paint with a missing group uses fewer hooks than the next one. This PR only changes threadReducer.ts. Scout reload did not hit it.

Group reload hooks crash
Crew transcript after Retry

vp run dev --share failed with tailscale serve permission denied, so there is no tailnet pairing URL from this run.

Grok 4.6 High in Grok Build via Orca.

Assistant text deltas rebuilt latestTurn as a new object on every event, even when every field matched. Selectors and memos keyed on that record then reran for no reason. Checkpoints already reused the input array when nothing needed rebinding.

reuseLatestTurn now returns the previous object when identity, state, timestamps, assistant message id, and proposed-plan ids match. The same-turn recompute also keeps an existing sourceProposedPlan so Akeru plan links are not dropped. Tests cover a streaming delta that must keep both references and the first assistant message that must replace them.

Adapted from T3 Code pingdotgg#9145.

Grok 4.6 High in Grok Build via Orca.
@vercel

vercel Bot commented Sep 10, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
akeru-bot-landing Skipped Skipped Sep 10, 2026 6:00pm UTC

Request Review

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:M labels Sep 10, 2026
@greptile-apps

greptile-apps Bot commented Sep 10, 2026

Copy link
Copy Markdown

Greptile Summary

This update improves reducer reference stability during assistant streaming while retaining current same-turn metadata. Request-message, responding-bot, proposed-plan, and checkpoint identities are preserved and compared so consumers receive accurate latest-turn state.

Confidence Score: 5/5

Safe to merge.

No outstanding findings remain. The previously reported stale-turn-metadata issue is fully addressed: request-message and responding-bot identities are now retained for the active turn and included in the latest-turn equality comparison.

Reviews (2): Last reviewed commit: "fix(client): keep request and responding..." | Re-trigger Greptile

Comment thread packages/client-runtime/src/state/threadReducer.ts
reuseLatestTurn compared only a subset of latestTurn. Same-turn session and streaming updates rebuilt a candidate without requestMessageId or respondingBotId, then kept the old object anyway. Copy those identities onto the candidate and compare them so selectors cannot see a stale bot or request id.

Grok 4.6 High in Grok Build via Orca.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant