Skip to content

fix(native-chat): stream an idle-agent reply below the prompt that caused it - #15617

Closed
yzxcj797 wants to merge 1 commit into
stablyai:mainfrom
yzxcj797:fix/native-chat-stream-order-15608
Closed

yzxcj797 wants to merge 1 commit into
stablyai:mainfrom
yzxcj797:fix/native-chat-stream-order-15608

Conversation

@yzxcj797

Copy link
Copy Markdown
Contributor

Summary

What

The desktop native-chat view now renders the streaming reply bubble below an optimistic user echo that was sent while the agent was idle, and keeps it above echoes that were queued while the agent was already working.

A pending send records queuedWhileWorking at issue time (session.status === 'working'), and the transcript merge splits the rendered echoes around the streaming bubble via a new pure helper, splitPendingMessagesAroundStreaming (native-chat-pending.ts).

Why

#15608 — sending a prompt to an idle agent rendered the streaming reply above the optimistic echo of that prompt, so the sent message sat stranded at the bottom of the transcript while its answer built above it. The old merge unconditionally placed the bubble before all echoes (the code comment even documented that order), which is correct only for sends queued behind an in-flight turn — for an idle-time send, the echo is the newest turn and the bubble is its answer.

Scope

Desktop chat view only, as called out in the issue: the mobile view reaches the same wrong order through its own mechanism and needs a separate change. This PR does not touch mobile.

Testing

  • New unit cases in native-chat-pending.test.ts (pure module, no React): idle-time echo sorts before the bubble; queued-behind-work echo stays after; a mixed pending list splits while preserving relative order on both sides. 73/73 in the two pending suites.
  • NativeChatView.test.tsx 5/5 unchanged; pnpm run typecheck clean.

Fixes the desktop half of #15608.

…used it

The streaming preview bubble always rendered before every optimistic
user echo. For a send issued while the agent was idle the echo IS the
newest turn and the bubble is its answer, so the reply built above the
prompt that caused it and the sent message stayed stranded at the
bottom until the transcript's user row landed (stablyai#15608).

A pending send now records whether the agent was already working when
it was issued. Sends into an idle agent render before the streaming
bubble; sends queued behind live work keep their previous position
below it, which was already correct for them. The split is a pure
helper over the pending list so the ordering rule is unit-tested
without the view.

Desktop chat view only — the mobile view reaches the same wrong order
through its own mechanism and is left for a follow-up.
@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Native chat marks optimistic sends made during an active agent turn with queuedWhileWorking. A new helper splits pending messages into groups before and after the streaming preview while preserving order within each group. NativeChatView uses these groups when assembling session messages. Tests cover idle sends, queued sends, and mixed ordering.

Merge Risk: ⚪ Minimal · up to 196da

This PR corrects desktop chat message ordering for idle-agent replies without changing mobile behavior, with targeted tests and type checking reported clean. No actionable merge-blocking risk remains beyond normal review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change, rationale, scope, linked issue, and tests, but it omits required template sections and visual proof. Use the repository template, add the required Visual Proof section with screenshots or N/A justification, and complete the checklist and remaining required sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the primary native-chat ordering fix for streaming replies and idle-agent prompts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
src/renderer/src/components/native-chat/native-chat-pending.ts (1)

43-47: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shorten the new renderer comments.

Keep only the non-obvious invariant. The surrounding identifiers and code show the placement behavior.

  • src/renderer/src/components/native-chat/native-chat-pending.ts#L43-L47: reduce the field documentation to one concise sentence.
  • src/renderer/src/components/native-chat/native-chat-pending.ts#L276-L284: reduce the helper documentation to its ordering invariant.
  • src/renderer/src/components/native-chat/NativeChatView.tsx#L242-L244: reduce the send-time classification comment to one line.
  • src/renderer/src/components/native-chat/NativeChatView.tsx#L294-L297: reduce the placement comment to one line.

As per coding guidelines, comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2045045b-6d90-42d3-adf7-dce3e478821c

📥 Commits

Reviewing files that changed from the base of the PR and between 0f26ff4 and 196daae.

📒 Files selected for processing (3)
  • src/renderer/src/components/native-chat/NativeChatView.tsx
  • src/renderer/src/components/native-chat/native-chat-pending.test.ts
  • src/renderer/src/components/native-chat/native-chat-pending.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@AmoabaKelvin

Copy link
Copy Markdown
Collaborator

Thanks for the fix! #37773 is now merged and covers this desktop ordering repair plus the phone path, so this PR is superseded.

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.

2 participants