Skip to content

fix(native-chat): match glue against each pending send's own boundary - #14927

Closed
brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/native-chat-glue-send-boundary
Closed

brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/native-chat-glue-send-boundary

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​50 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​43
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​193 $\color{#cf222e}{\Huge{\mathbf{−}}}$​149 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​44

Fixes STA-4477. Follow-up to #14663 — not a revert of it (reverting would re-open #14262).

The bug

Desktop native chat renders an optimistic "queued" bubble per composer send and prunes it once the real transcript row lands. When a lost Enter glues two rapid sends into ONE transcript row, neither exact key matches, so #14663 added a glue matcher.

That matcher filtered candidate rows against the oldest still-open send's boundary (gluedCandidateMessages reads open[0] only) and then matched the entire open queue against them. A prompt queued after a row landed could therefore be consumed by that row and pruned — the bubble vanishes and the prompt is treated as delivered when it is still in flight.

Minimal repro (this is a test in the PR, and it was reproduced independently by a separate codex session given only the two files):

pending  = [ {id: p1, text: 'joke',     afterMessageId: 'm0'}   // sent before m1
           , {id: p2, text: 'continue', afterMessageId: 'm2'} ] // sent after  m1
messages = [ m0 assistant, m1 user 'jokecontinue', m2 assistant ]

prunePendingSends(pending, messages)  →  []      // p2 silently dropped

p2's exact path correctly keeps it (messagesAfterPendingBoundary(messages, p2) is empty). The glue path overrides that.

The fix

Every send carries its own boundary into the match.

  • gluedCandidateRows tags each candidate row with the set of pending indices whose boundary it landed after, using the existing messagesAfterPendingBoundary per entry.
  • selectPendingIndicesRepresentedByUserRows ends the glue run at the first send the row predates. Glue is an adjacency claim, so an ineligible entry is a stop, not a skip — skipping it would let a row glue across a gap.
  • Sends with no recorded message boundary are anchored to their send time (as the exact path already does), so a fuzzy match can never reach further back than an exact one. Previously only the oldest entry got that treatment.

advancedNativeChatUserTexts / matchingNativeChatUserTexts became …UserRows so rows keep their id and eligibility can be computed per row.

The mobile matcher already enforced this per-send (matchGluedRun checks each segment's own tail); desktop was the outlier.

Tests (RED → GREEN)

Both new tests were run against origin/main first and fail there:

FAIL > glued rapid sends > keeps a queued send whose own boundary is newer than the glued row (STA-4477)
AssertionError: expected [] to deeply equal [ { id: 'p1', …(4) }, …(1) ]

With the fix: 73 files / 768 tests passed across src/renderer/src/components/native-chat/. typecheck:web and oxlint clean.

Note on the file split

native-chat-pending.ts was at its 300-line budget, so the slash-command marker cache (a separate concern that happened to live there) moved to native-chat-command-marker.ts. No behavior change; no max-lines disable or baseline bump.

🤖 Generated with Claude Code

Desktop glue matching filtered candidate transcript rows against the OLDEST
still-open send's boundary and then matched the ENTIRE open queue against them.
A prompt queued after a row landed could be consumed by that row and pruned, so
a real queued prompt disappeared with no bubble and no delivery.

Carry every send's own boundary into the match: `gluedCandidateRows` tags each
candidate row with the pending indices it landed after, and the matcher ends the
glue run at the first send the row predates (adjacency is what makes it glue, so
an ineligible entry is a stop, not a skip). Sends with no recorded message
boundary fall back to their send time, as the exact path already does.

Splits the slash-command marker cache out to native-chat-command-marker.ts to
keep native-chat-pending.ts under its line budget; no behavior change there.

Fixes STA-4477
Refs #14663, #14262
@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Native chat command-marker handling moved into a dedicated module with scoped caching, /clear transcript boundaries, system-message conversion, and marker ID detection. Pending-send matching now uses structured user rows that preserve message IDs and track representable pending entries in glued transcript rows. Pending pruning and optimistic rendering use this metadata. Regression tests cover boundary-specific visibility and pruning behavior.

Merge Risk: 🔵 Low · up to 4c92c

The change fixes pending-message matching, but it also adds a command marker that is hard-coded in English, so users in other locales may see untranslated text. The PR is otherwise mergeable with explicit owner awareness or a follow-up localization fix.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug, fix, linked issue, and tests, but omits most required template sections and visual proof. Add the missing template sections, include Visual Proof or N/A with a reason, document testing platforms, and complete the review and checklist items.
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: matching glued transcript rows against each pending send's own boundary.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a59f0d02-280e-402d-b922-d2ee58b73d9e

📥 Commits

Reviewing files that changed from the base of the PR and between 516a269 and 4c92c34.

📒 Files selected for processing (6)
  • src/renderer/src/components/native-chat/NativeChatInteractiveCard.test.tsx
  • src/renderer/src/components/native-chat/NativeChatView.tsx
  • src/renderer/src/components/native-chat/native-chat-command-marker.ts
  • src/renderer/src/components/native-chat/native-chat-pending-occurrence.ts
  • 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 includes up to 10 reviews per rolling hour; 6 remain after this review.

Comment on lines +99 to +105
return markers.map((marker) => ({
id: `command:${marker.id}`,
role: 'system' as const,
blocks: [{ type: 'text' as const, text: `Ran ${marker.command}` }],
timestamp: marker.sentAt,
source: 'scrape' as const
}))

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Localize the command marker text.

Ran ${marker.command} is new user-visible text. Register and use a renderer locale key for the template instead of rendering English directly.

Based on learnings: renderer locale keys use the first 10 SHA-1 characters of <filePath>:<text>.

Source: Learnings

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Superseded by #14935, which covers the same ticket (STA-4477, per-send boundary in glue matching) from a branch cut fresh off current main and carrying the verification this one lacks: a surgical mutation with both call sites independently guarded, and the lint gate confirmed live via an injected violation rather than inferred from a silent clean run.

Same change, verified. Closing this to keep one review surface per ticket.

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