Skip to content

fix(native-chat): anchor an unmatched chat echo where it was sent - #16117

Merged
brennanb2025 merged 5 commits into
mainfrom
brennanb2025/native-chat-pending-echo-duplicates
Aug 27, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennanb2025/native-chat-pending-echo-duplicates

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​162 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​162
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​105 $\color{#cf222e}{\Huge{\mathbf{−}}}$​26 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​79

ELI5

You send a message, and the app shows your bubble straight away while it waits for the agent's transcript to confirm it. Some sends never get confirmed — Claude swallows a mid-turn send without writing it down. The unconfirmed bubble used to be pinned to the bottom of the list, so every new turn appeared above it and your old message kept re-reading underneath the newest one. The conversation looked scrambled.

Now the bubble stays where you sent it.

Root cause

Not a matching failure — a placement failure.

Claude consumes a mid-turn send through a queued_command attachment and writes no type:"user" record for it (measured: 1,049 of 1,132 human queued sends produce an attachment and no user row). So some echoes can never match a transcript row, and no amount of better matching changes that.

What made it scrambled was buildMobileNativeChatTransientData appending every pending item after the entire transcript. An echo that never matches therefore re-read below each turn that landed after it.

Fix

Render each echo directly after the transcript row it was sent against, using the baseline the send already captures. An unmatched echo becomes at worst a duplicate in the right position instead of a scrambled one — and it stays visible.

  • echoes sharing an anchor keep send order
  • a tool/noise row folded into an earlier visible turn → anchors to that surviving turn
  • an image-source row folded into its following prompt → anchors after that prompt
  • a folded-away boundary at the start of the loaded window → stays before later visible turns
  • no baseline, or a boundary outside the loaded raw window → falls back to the tail (the previous behaviour)
  • the streaming bubble stays after the transcript

Four files, client-only, no host change, no wire change.

What this deliberately does NOT do

An earlier revision of this PR inferred from send ordering that an echo could never match, and deleted it. That is worse, three ways:

  1. It loses your text. The mid-turn send was delivered and is in the agent's context. Deleting the only rendering of it leaves the agent answering an invisible question.
  2. It could not fire in the common case. The last outstanding entry is exempt and bars everything before it, so nothing retires until a later send lands. Measured drain groups: 1,017 of size 1 against 55 larger. For a single stuck echo — the usual case — the symptom persisted.
  3. It escalated an existing gap into data loss. The count pass has no baseline-tail guard (unlike the glue pass, which carries turn.index <= segment.tail), while messages is a 40-row window that head-trims, resets on reconnect, and grows at the front on loadEarlier. Verified against the current code: an older identical row paged in by loadEarlier retires an echo that never landed — and under the deletion rule that false landing also deleted a genuine outstanding mid-turn send.

That count-pass gap is real and pre-existing. It is left for a separate change; anchoring reduces its worst case from a scrambled conversation to a duplicate in place.

A host-side fix — synthesizing the turn from the queued_command attachment — was investigated and rejected. 6.1% of those attachments (69/1,132) also produce a real user row, verified 607ms apart in one case, and nothing in the record distinguishes them: 68 of the 69 were carried by remove, and dequeue never carries content. Deciding correctly needs cross-record correlation, which the decoder contract forbids ("Each decoder is stateless: it takes a single JSONL line plus a stable fallback id and returns one message or null"). Synthesizing anyway would duplicate the bubble in ~6% of sends — the original complaint in a new form.

Verification

Red-then-green by reverting only the source file:

buildMobileNativeChatTransientData anchoring
  ✗ keeps an unmatched echo where it was sent instead of below later turns
  ✗ reproduces the reported replay: stale echoes stay in place, not stacked at the tail
  ✗ still puts the streaming bubble after the transcript
→ 3 failed | 22 passed   (source reverted)
→ 27 passed              (restored, including tool-fold and image-fold paths)

Confirmed on an iPhone 17 Pro simulator through the real MobileNativeChatView, with later turns landing after the send:

m1 first question           (user)
m2 on it                    (assistant)
MID-TURN SEND — stay HERE   ← the unmatched echo, anchored under m2
m3 landed AFTER the send    (assistant)

The echo holds its position above the turns that landed afterwards. This also confirms the runtime wiring: baselineTailMessageId survives the hand-off to the render type, or the echo would have fallen back to the tail.

Full runs: mobile src/session/ 1,239 tests green, tsc --noEmit clean, oxlint + oxfmt clean, lockfile untouched.

Risk

Client-side only. No NativeChatMessage change, no host change, no Rule 3 exposure. The fallback path is the exact previous behaviour, so a send with no usable anchor renders exactly as it does today.

@brennanb2025
brennanb2025 force-pushed the brennanb2025/native-chat-duplicate-message-echo branch from 33ae874 to bec1529 Compare August 23, 2026 18:38
@brennanb2025
brennanb2025 force-pushed the brennanb2025/native-chat-duplicate-message-echo branch from cfa06a3 to 431a903 Compare August 23, 2026 20:40
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review verification (2026-08-24): no independent review-verification comment or review verdict is available for this PR. The PR is OPEN at ecedde29e593d5aaac8cf2f309c6147c9523aed6, GitHub reports DIRTY, and no checks are present. Review-loop verdict is NOT RUN/BLOCKED; no merge-readiness claim is made.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

QA evidence status (2026-08-24): manual validation is BLOCKED/NOT RUN. The PR is dirty, has no checks, and has no review loop to validate against; no screenshot or visual-proof artifact was captured. No QA pass is claimed and merge-ready remains false.

@brennanb2025
brennanb2025 force-pushed the brennanb2025/native-chat-pending-echo-duplicates branch from ecedde2 to 4791f0e Compare August 25, 2026 20:18
@greptile-apps

greptile-apps Bot commented Aug 25, 2026

Copy link
Copy Markdown

Too many files changed for review (2273 files, 100 file limit).

@brennanb2025
brennanb2025 force-pushed the brennanb2025/native-chat-pending-echo-duplicates branch from 4791f0e to 079340f Compare August 25, 2026 20:20
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Visual proof — user bubble clipping at pinch-zoom

Captured on an isolated iOS 26.5 simulator (iPhone 17 Pro), rendering the real MobileNativeChatMessage through the real ancestor chain (root → GestureHandlerRootView(listWrap) → FlatList(listContent)).

Same message, same config in both frames: fontScale=1.8, 280pt-wide row.

before after
before-clip.png after-clip.png

Before: "Also if you run" has its glyph tops sheared off against the bubble padding, and the lines crowd into each other — 30.6pt glyphs inside a pinned 23pt line box.

After: full ascenders on the top line, even leading throughout.

Onset is 1.4x, the point where fontSize (17 × 1.4 = 23.8) first exceeds the pinned lineHeight of 23 — the same threshold the unit tests assert.

Note for the record: the originally reported symptom was horizontal clipping at the right edge. That did not reproduce — the reported message wraps correctly at 402pt, 320pt and 280pt, and a long unbreakable token wraps rather than overflowing. This is a real clipping bug in the user bubble, but it may not be the one in the original screenshot; see the PR description for what remains unknown.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

QA — blocked (exact pending-echo flow not exercisable)

HEAD: f8301e5cb19819f722e1741b2fb81df3137afc7c (fix(native-chat): keep pending echo retirement scoped)

Scenario requested: native chat, a mid-turn queued send that produces no transcript type:user row, then a later landed send; the stale optimistic echo must not replay below later turns.

Electron (CDP only — not used as proof)

Attached Playwright CDP to the intended instance: Orca: brennanb2025/native-chat-pending-echo-duplicates (renderer 127.0.0.1:5175, CDP 9333, Dock Orca/ brennanb2025-native-chat-pending-echo-duplicates). retireLandedMobileNativeChatPending exists only under mobile/src/session/; the desktop renderer does not import it. The changed path is not exercisable in Electron. No desktop screenshots attached.

iOS (genuine simulator)

  • Device: iPhone 17 Pro, iOS 26.5 (50FD514C-96F6-446E-AC90-D07A24CAB3A0), Orca emulator helper running
  • App: com.stably.orca.mobile loaded from this worktree Metro (iOS Bundled on 10.0.0.41:8081)
  • Pairing: completed in this run to the intended branch Electron (Host 78). App showed the throwaway folder workspace and native-chat composer (not Expo launcher / redbox)
  • Flow driven with orca emulator taps/type only

What happened

  1. Sent a long prompt so Claude entered working (Agent is working on device; store state: working).
  2. While that turn was running, sent Also if you run out of space on my machine — optimistic echo appeared under the first user bubble.
  3. Repeated with a tool-using turn and a second mid-turn send (… QA2).

Backing transcript (same session JSONL): both mid-turn sends were queue-operation enqueue → dequeue → a real type:user row. No remove operation and no queued_command attachment. That is the landable path (#15656-era matching can retire the echo by text). It is not the unlandable path this PR’s stranded-echo rule covers.

Visible evidence

Optimistic echo was visible while Agent is working. After the turn, Claude had treated the queued text as a follow-up prompt and the JSONL contained a user row for it. That is adjacent to, not the same as, a send that never gets a user row.

Remaining gaps — QA blocked

Could not induce Claude Code’s queue-operation remove / no-user-row shape on this host, so the stranded-echo retirement (later landed send draining earlier unlandable echoes) was not entered. Per instructions: not substituting Electron, Expo web, store-only state, or this dequeue-with-user-row scenario as proof. No screenshots attached.

No code, PR body, or merge changes.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Final review status — PASS / CLEAN

Reviewed at exact HEAD f8301e5cb19819f722e1741b2fb81df3137afc7c.

  • Read the existing PR discussion before review; there were no inline review comments.
  • Tightened the stacked diff to the reported pending-echo issue only: 2 files, +152/-2. Removed the unrelated pinch-zoom work and adjacent display/copy control-byte sanitizer. The earlier pinch-zoom visual-proof comment is therefore superseded and does not describe the final diff.
  • Same-model review/fix loop returned CLEAN after those scope corrections; the final readiness-checklist pass found no P0/P1/P2 issues.
  • Focused pending-retirement suite: 53 passed. Full local mobile run: 3,688 passed with 3 pre-existing skips. Mobile typecheck/lint/format/diff checks passed.
  • All applicable GitHub checks are complete and green at this SHA, including Mobile Checks, static analysis, typecheck, Node 24/26 tests, wire compatibility, package, and Windows package. GitHub reports MERGEABLE / CLEAN.
  • Performance remains bounded: one O(P) reverse pass over pending sends, referentially stable on no-op, with no I/O, polling, subprocess, listener, retry, or render fanout.
  • No wire, persistence, RPC, SSH/relay, platform/process, Git-provider, or folder-workspace behavior changed.

QA limitation: Electron CDP verified the intended branch instance, but the changed function is mobile-only. Genuine iOS native-chat QA then attempted the mid-turn flow twice; both attempts produced enqueue → dequeue → type:user, not the target remove / queued_command / no-user-row shape. The exact stranded-echo path was therefore not reproducible on this host, and no adjacent or misleading screenshot was attached. Full details: #16117 (comment)

The stacked base remains brennanb2025/native-chat-duplicate-message-echo; merge #15656 first. This review did not merge the PR.

@brennanb2025
brennanb2025 changed the base branch from brennanb2025/native-chat-duplicate-message-echo to main August 25, 2026 23:20
@brennanb2025
brennanb2025 force-pushed the brennanb2025/native-chat-pending-echo-duplicates branch from f8301e5 to c2e5848 Compare August 25, 2026 23:23
@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The change adds raw transcript input to transient chat data construction. The renderer resolves pending-message anchors across folded transcript rows, including forward anchoring for image-source rows and backward anchoring for other folded rows. Anchored pending messages retain order, unresolved messages use transcript-tail placement, and streaming output remains after transcript and pending content. Tests cover these placement rules.

Merge Risk: 🔵 Low · up to 18bd5

Unresolved pending messages can still appear below the active streaming response, which can make the conversation order look incorrect. This is a bounded UI issue that is mergeable with explicit owner follow-up.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, root cause, implementation, scope, risks, and verification results. However, it omits several required template sections, including Linked Issue, Visual Proof or … Add all required template sections. Include the linked issue after “Fixes #”, provide visual proof or write N/A with a reason, document manual and automated testing, complete the required checkboxes, and address AI Disclosure, Review, Age…
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 6 files. 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 and concisely describes the primary change: anchoring unmatched native-chat echoes at their send position.
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.
Full details: Description check

Explanation

The description explains the problem, root cause, implementation, scope, risks, and verification results. However, it omits several required template sections, including Linked Issue, Visual Proof or an explicit N/A explanation, Testing checkboxes, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist.

Resolution

Add all required template sections. Include the linked issue after “Fixes #”, provide visual proof or write N/A with a reason, document manual and automated testing, complete the required checkboxes, and address AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist.

  • Fix all pre-merge checks with AI
✨ 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.

The reported symptom was old user messages replaying below every new turn, so the
conversation read as scrambled. The cause was not that the echo failed to match a
transcript row. Claude consumes a mid-turn send through a `queued_command`
attachment and writes no `type:"user"` record for it, so some echoes can never
match, and no amount of matching will change that. The cause was WHERE an
unmatched echo rendered: buildMobileNativeChatTransientData appended every pending
item after the entire transcript, so it re-read below each turn that landed
afterwards.

Render each echo directly after the transcript row it was sent against, using the
baseline the send already captures. An unmatched echo is then at worst a duplicate
in the right position rather than a scrambled one, and it stays visible. Echoes
sharing an anchor keep send order; a send with no baseline, or one whose anchor
folding dropped, still falls back to the tail.

Deliberately NOT fixed by deleting the echo. Inferring from send ordering that an
echo can never match, then removing it, loses the user's own text for a message
the agent did receive, and it cannot fire in the common case anyway - measured
drain groups are 1,017 of size 1 against 55 larger. It also escalates an existing
gap: the count pass has no baseline-tail guard, unlike the glue pass, while
`messages` is a 40-row window that head-trims, resets on reconnect and grows at
the front on loadEarlier, so a false landing there would license deleting a
DIFFERENT outstanding message.

That count-pass gap is real and left for a separate change; anchoring makes its
worst case a duplicate in place rather than a scrambled conversation.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/native-chat-pending-echo-duplicates branch from c2e5848 to 0ecfefb Compare August 26, 2026 19:55
@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@brennanb2025 brennanb2025 changed the title fix(native-chat): bound the lifetime of chat echoes that can never land fix(native-chat): anchor an unmatched chat echo where it was sent Aug 26, 2026

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
mobile/src/session/mobile-native-chat-render-data.ts (1)

161-170: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Keep the streaming bubble last. trailingPending renders after streaming, so an unanchored echo becomes the final row. Append trailingPending before the streaming item.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6b360b00-7cb6-4d59-91f1-1495222b0a46

📥 Commits

Reviewing files that changed from the base of the PR and between 0ecfefb and 0aa8c84.

📒 Files selected for processing (4)
  • mobile/src/session/MobileNativeChatView.tsx
  • mobile/src/session/mobile-native-chat-render-data.test.ts
  • mobile/src/session/mobile-native-chat-render-data.ts
  • mobile/src/session/use-mobile-native-chat-drafts-glued-pending.test.ts

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Attachments

orca-pr16117-midturn-before-later.png orca-pr16117-midturn-after-later.png
orca-pr16117-midturn-before-later.png orca-pr16117-midturn-after-later.png

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
mobile/src/session/mobile-native-chat-render-data.ts (1)

174-183: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Keep streaming output last. Move data.push(...trailingPending) before the streaming block; an unresolved pending item currently renders after streaming.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7a8fc829-e438-410b-9e1a-ea2195cb129f

📥 Commits

Reviewing files that changed from the base of the PR and between 0aa8c84 and 3c75920.

📒 Files selected for processing (2)
  • mobile/src/session/mobile-native-chat-render-data.test.ts
  • mobile/src/session/mobile-native-chat-render-data.ts

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Final review status — code CLEAN, CI blocked

Final SHA: e914c09d95145df90ccabe9cd86b19b3c1a66b58

Verdict: the code is ready to land after fixes, and all review-found fixes are pushed. Do not land yet while the required static-analysis check is red for an unrelated base/integration localization failure.

Review result

The same-model senior review loop returned CLEAN at the final SHA, and the required end readiness audit returned PASS/CLEAN with no P0, P1, or P2 findings.

The review found and fixed three in-scope placement edges:

  • tool/noise rows that fold backward now preserve the raw send anchor;
  • image-source rows that fold forward now anchor after the surviving prompt;
  • a folded-away boundary at the start of the loaded raw window now keeps its echo before later visible turns.

The final implementation stays narrowly within pending-echo chronological placement and remains O(messages + pending), with no polling, I/O, listeners, retained caches, wire changes, host changes, or new dependencies.

Verification

  • 1,239/1,239 mobile session tests passed.
  • Focused final native-chat pass: 51 tests.
  • Shared normalization: 33/33 tests.
  • Mobile typecheck, changed-file lint, React Doctor, formatting, and diff checks passed.
  • Stress case: 2,000 raw rows, 1,900 folded rows, and 100 leading pending anchors averaged 0.157 ms per assembly over 1,000 iterations.
  • Worktree is clean; HEAD, upstream, and PR remote all match the SHA above.

Visual QA

Electron identity was verified through CDP, then the native iPhone 17 Pro flow was exercised through the emulator surface. The mid-turn bubble remained above later completed turns and tools.

Screenshot evidence: #16117 (comment)

The provider emitted real user rows during this run, so the provider-specific no-user-row shape was not directly observable. That residual shape is covered by deterministic production-path tests. The screenshot predates the final pure placement edge commits; those commits do not change presentation.

CI

The final workflow completed with 44 successful jobs, e2e correctly skipped by change detection, and no cancellations. static analysis failed only at Verify localization catalog for three existing auto.components.skills.* Japanese translations introduced by the current merge base. This PR changes only four mobile native-chat session files; repairing localization here would expand scope and the diagnostic explicitly calls for a separate localization PR. The final verify job is red only because that required check is red.

Once the base/integration localization catalog is repaired and CI is rerun, this is ready to land.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review verification at exact head e914c09d95145df90ccabe9cd86b19b3c1a66b58:

  • Independent review found one additional ordering edge case: if the raw baseline row was the leading row in the transcript window and folded away, the pending echo fell back to the tail and could replay below later turns.
  • Added a failing regression case and fixed it in e914c09d95 by preserving leading folded-baseline echoes ahead of later visible turns.
  • Focused native-chat validation is green: 4 mobile test files / 78 tests, mobile TypeScript typecheck, oxlint on changed files, oxfmt check, and git diff --check.
  • Performance/lifecycle review is clean: the additional projection is linear over the already bounded transcript window and adds no polling, listeners, or retained resources.
  • No further in-scope review findings remain.

Current GitHub status is truthful but not fully green: Mobile Checks, typecheck, all Node 24/26 test shards, package, package Windows, Git compatibility, wire compatibility, and other PR checks passed. Static analysis failed only in the repository-wide localization catalog check on existing Japanese Agent translations (auto.components.skills.*), outside the four files changed by this PR; the aggregate verify job consequently failed: https://github.com/stablyai/orca/actions/runs/33019760430/job/98347267009

@brennanb2025

Copy link
Copy Markdown
Contributor Author

QA evidence for exact head e914c09d95145df90ccabe9cd86b19b3c1a66b58:

I loaded the mobile bundle from this worktree in the Orca-managed iOS simulator, paired it to an Electron dev instance launched from the same worktree/head, and verified the desktop identity through Playwright CDP. In a real native-chat session I started a long-running tool call, sent Pending echo QA follow up mid-turn through the mobile composer, and observed the optimistic echo remain directly below the active tool row.

In flight — optimistic echo anchored while the agent is working

pending echo in flight

Settled — one user bubble followed by the agent response, with no duplicate or tail replay

pending echo settled

Electron exact-head pairing surface used for the run

Electron pairing

Result: the exercisable pending-echo/native-chat flow passes on the exact PR SHA. No desktop interaction was performed outside Playwright CDP, and all mobile UI interaction used orca emulator.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
mobile/src/session/mobile-native-chat-render-data.ts (1)

182-191: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Keep the streaming bubble last. Move data.push(...trailingPending) before the streaming branch; unresolved pending bubbles currently render after streaming.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8f7630bb-0df3-4d7d-a035-acfd9a29e358

📥 Commits

Reviewing files that changed from the base of the PR and between 3c75920 and 18bd50d.

📒 Files selected for processing (2)
  • mobile/src/session/mobile-native-chat-render-data.test.ts
  • mobile/src/session/mobile-native-chat-render-data.ts

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

@brennanb2025
brennanb2025 merged commit f6e16ba into main Aug 27, 2026
94 of 96 checks passed
brennanb2025 added a commit that referenced this pull request Aug 27, 2026
…6117)

* fix(native-chat): anchor an unmatched chat echo where it was sent

The reported symptom was old user messages replaying below every new turn, so the
conversation read as scrambled. The cause was not that the echo failed to match a
transcript row. Claude consumes a mid-turn send through a `queued_command`
attachment and writes no `type:"user"` record for it, so some echoes can never
match, and no amount of matching will change that. The cause was WHERE an
unmatched echo rendered: buildMobileNativeChatTransientData appended every pending
item after the entire transcript, so it re-read below each turn that landed
afterwards.

Render each echo directly after the transcript row it was sent against, using the
baseline the send already captures. An unmatched echo is then at worst a duplicate
in the right position rather than a scrambled one, and it stays visible. Echoes
sharing an anchor keep send order; a send with no baseline, or one whose anchor
folding dropped, still falls back to the tail.

Deliberately NOT fixed by deleting the echo. Inferring from send ordering that an
echo can never match, then removing it, loses the user's own text for a message
the agent did receive, and it cannot fire in the common case anyway - measured
drain groups are 1,017 of size 1 against 55 larger. It also escalates an existing
gap: the count pass has no baseline-tail guard, unlike the glue pass, while
`messages` is a 40-row window that head-trims, resets on reconnect and grows at
the front on loadEarlier, so a false landing there would license deleting a
DIFFERENT outstanding message.

That count-pass gap is real and left for a separate change; anchoring makes its
worst case a duplicate in place rather than a scrambled conversation.

* fix(native-chat): preserve folded echo anchors

* fix(native-chat): preserve forward-folded echo anchors

* fix(native-chat): keep leading folded echoes in place
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…ablyai#16117)

* fix(native-chat): anchor an unmatched chat echo where it was sent

The reported symptom was old user messages replaying below every new turn, so the
conversation read as scrambled. The cause was not that the echo failed to match a
transcript row. Claude consumes a mid-turn send through a `queued_command`
attachment and writes no `type:"user"` record for it, so some echoes can never
match, and no amount of matching will change that. The cause was WHERE an
unmatched echo rendered: buildMobileNativeChatTransientData appended every pending
item after the entire transcript, so it re-read below each turn that landed
afterwards.

Render each echo directly after the transcript row it was sent against, using the
baseline the send already captures. An unmatched echo is then at worst a duplicate
in the right position rather than a scrambled one, and it stays visible. Echoes
sharing an anchor keep send order; a send with no baseline, or one whose anchor
folding dropped, still falls back to the tail.

Deliberately NOT fixed by deleting the echo. Inferring from send ordering that an
echo can never match, then removing it, loses the user's own text for a message
the agent did receive, and it cannot fire in the common case anyway - measured
drain groups are 1,017 of size 1 against 55 larger. It also escalates an existing
gap: the count pass has no baseline-tail guard, unlike the glue pass, while
`messages` is a 40-row window that head-trims, resets on reconnect and grows at
the front on loadEarlier, so a false landing there would license deleting a
DIFFERENT outstanding message.

That count-pass gap is real and left for a separate change; anchoring makes its
worst case a duplicate in place rather than a scrambled conversation.

* fix(native-chat): preserve folded echo anchors

* fix(native-chat): preserve forward-folded echo anchors

* fix(native-chat): keep leading folded echoes in place
rahuljangirworks pushed a commit to rahuljangirworks/veer that referenced this pull request Aug 27, 2026
…ablyai#16117)

* fix(native-chat): anchor an unmatched chat echo where it was sent

The reported symptom was old user messages replaying below every new turn, so the
conversation read as scrambled. The cause was not that the echo failed to match a
transcript row. Claude consumes a mid-turn send through a `queued_command`
attachment and writes no `type:"user"` record for it, so some echoes can never
match, and no amount of matching will change that. The cause was WHERE an
unmatched echo rendered: buildMobileNativeChatTransientData appended every pending
item after the entire transcript, so it re-read below each turn that landed
afterwards.

Render each echo directly after the transcript row it was sent against, using the
baseline the send already captures. An unmatched echo is then at worst a duplicate
in the right position rather than a scrambled one, and it stays visible. Echoes
sharing an anchor keep send order; a send with no baseline, or one whose anchor
folding dropped, still falls back to the tail.

Deliberately NOT fixed by deleting the echo. Inferring from send ordering that an
echo can never match, then removing it, loses the user's own text for a message
the agent did receive, and it cannot fire in the common case anyway - measured
drain groups are 1,017 of size 1 against 55 larger. It also escalates an existing
gap: the count pass has no baseline-tail guard, unlike the glue pass, while
`messages` is a 40-row window that head-trims, resets on reconnect and grows at
the front on loadEarlier, so a false landing there would license deleting a
DIFFERENT outstanding message.

That count-pass gap is real and left for a separate change; anchoring makes its
worst case a duplicate in place rather than a scrambled conversation.

* fix(native-chat): preserve folded echo anchors

* fix(native-chat): preserve forward-folded echo anchors

* fix(native-chat): keep leading folded echoes in place
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 28, 2026
…ablyai#16117)

* fix(native-chat): anchor an unmatched chat echo where it was sent

The reported symptom was old user messages replaying below every new turn, so the
conversation read as scrambled. The cause was not that the echo failed to match a
transcript row. Claude consumes a mid-turn send through a `queued_command`
attachment and writes no `type:"user"` record for it, so some echoes can never
match, and no amount of matching will change that. The cause was WHERE an
unmatched echo rendered: buildMobileNativeChatTransientData appended every pending
item after the entire transcript, so it re-read below each turn that landed
afterwards.

Render each echo directly after the transcript row it was sent against, using the
baseline the send already captures. An unmatched echo is then at worst a duplicate
in the right position rather than a scrambled one, and it stays visible. Echoes
sharing an anchor keep send order; a send with no baseline, or one whose anchor
folding dropped, still falls back to the tail.

Deliberately NOT fixed by deleting the echo. Inferring from send ordering that an
echo can never match, then removing it, loses the user's own text for a message
the agent did receive, and it cannot fire in the common case anyway - measured
drain groups are 1,017 of size 1 against 55 larger. It also escalates an existing
gap: the count pass has no baseline-tail guard, unlike the glue pass, while
`messages` is a 40-row window that head-trims, resets on reconnect and grows at
the front on loadEarlier, so a false landing there would license deleting a
DIFFERENT outstanding message.

That count-pass gap is real and left for a separate change; anchoring makes its
worst case a duplicate in place rather than a scrambled conversation.

* fix(native-chat): preserve folded echo anchors

* fix(native-chat): preserve forward-folded echo anchors

* fix(native-chat): keep leading folded echoes in place

(cherry picked from commit f6e16ba)
brennanb2025 added a commit that referenced this pull request Aug 28, 2026
* feat(native-chat): port structured Codex sessions from restructure-recovery

Rebuilds the desktop structured native-chat implementation from
brennanb2025/native-chat-restructure-recovery (tip 4e31c08) on top of
current main as a single commit, scoped to the local Codex path.

Ported:
- Structured agent-session core: durable record store + single-writer lease,
  canonical journal, agent-session wire host/attach/eviction/subscribers,
  `agentSession.*` RPC surface (registered via ALL_RPC_METHODS; host-side
  mobile allowlist included for wire compat), pty write gate, transcript
  additions, and the Codex app-server adapter/launch resolution.
- Renderer: NativeChatStructuredSession view/composer stack, structured
  launch path with the single-flight guard, local structured session tabs
  sync, activation gate + structured inventory (read-only
  `agentSession.handoffStatus` probe), agent-session tabs in the tab strip,
  AI-vault structured session activation, and the settings pane with the
  parent Experimental Chat UI toggle plus the nested "Use updated structured
  native chat" toggle. New sessions require both flags, agent codex, no
  prompt, and a local non-WSL, non-Windows-host execution host
  (structured-native-chat-availability).
- Fixes 72c013c (verified Codex launch recovery), 8ddbaf5 (defer
  native terminal view switching affordances), and 4e31c08 (release the
  launch gate after a visibility retry) with their regression tests,
  including the third-launch-after-retry guard case.
- Cross-version agent-session wire test + CI lane, packaging entries
  (proper-lockfile, agent-tooling asar excludes), and the wire-compat doc
  section.

Deliberately not ported: mobile/ changes, the Claude structured runtime
(only the claude-transcript-branch-proof and claude-structured-owner-identity
leaf modules remain, backing the kept TUI-recovery arms), the terminal↔chat
adoption/handoff flow (`agentSession.adoptTerminal`/`requestHandoff`, the
handoff request engine, TUI adoption machinery, orca-runtime adoption
methods), renderer switching affordances and their dead leftovers, the
hook/subagent-status refactor cluster, and unrelated branch changes. The
crash-during-acquisition recovery path (restart handoff adjudication,
restore/reverse re-acquire, lease schema handoff keys) is kept because every
plain direct launch depends on it; a trimmed handoff coordinator exposes
only status/restore/close.

Branch edits that targeted files main has since split (ipc/pty.ts,
worktrees.ts, rpc/methods/terminal.ts, useIpcEvents, pty-connection,
store/slices/terminals.ts, runtime-types, web preload) were re-applied to
the split modules, preserving main's newer logic (Windows CIM fallback,
browser tab close rework, cold-restore resume flow, dispatcher threading).

Known seam: the mobile clipboard image-provenance CONSUMER gate ships
(agentSession.send refuses unproven mobile image refs with
agent_session_image_untrusted) but the producer hunk in
rpc/methods/clipboard.ts stays with the unported mobile cluster, so mobile
image sends into structured chat fail closed until that side ports.

* fix(native-chat): trust only authenticated local image uploads

* fix(build): preserve Windows process-tree patch application

* test(windows): include process creation time in addon fixture

* fix(build): run windows-process-tree node-gyp from the physical package dir

gyp expands the node-addon-api dependency by probing node, whose cwd
resolves to the package's physical directory in the store, so the emitted
target is a store-relative ../../../../node-addon-api@... hop. gyp then
resolves that hop against the rebuild cwd; from the node_modules
symlink/junction it escapes the store and configure fails with
"node_addon_api.gyp not found" (run 32999886072).

Rebuild from realpath(package dir) so both bases agree, matching how the
package manager itself runs native install scripts. The regression test
replays gyp's expansion+resolution against the planned cwd and fails
without the fix.

* fix(native-chat): keep chat tabs visible through terminal closes and empty-worktree launches

Two proven blockers in the native Codex tab contract:

closeTerminalTab pre-empted the canonical unified close. With one terminal
left it deactivated the worktree on a terminal/editor/browser-only check,
blanking a workspace that still held a renderable agent-session tab; with
two or more it pre-picked a successor from terminal entities only,
re-stamping the group active before closeUnifiedTab's MRU/neighbor repair
could land on the chat tab. Successor choice now defers to the unified
contract whenever the terminal has a unified row, and deactivation is
gated on the unified renderable count (matching leaveWorktreeIfEmpty),
with the legacy pre-pick kept only for terminals without a unified row.

A structured session created on an empty worktree was published into the
host's headless group while preserveLocalLayout froze the local layout,
leaving the tab in store but permanently off screen. A preserveLocalLayout
owner now always takes client-owned placement — repairing a rendered
leaf whose group record is missing, or materializing a rendered group on a
truly empty worktree — and applies the client-derived layout repair while
still rejecting host-authored layout.

Regression tests drive the real store through closeTerminalTab (git
worktree and folder workspace) and the real snapshot applier for the
empty-worktree adoption states; all fail without the fixes.

* fix(native-chat): close stale turns and retry rejected sends

* fix(native-chat): retire hosted rows on structured tab activation

* fix(native-chat): preserve rpc defaults across main merge

* chore: format remote wire compatibility guide

* test(native-chat): cover retry after unconfirmed send

* fix(native-chat): reload outbox on session switch

* docs(settings): disclose structured chat platform limits

* fix(native-chat): await Codex launch-home preparation

* fix(codex): align child-process allowlist with async trust bridge

* test(identity): update inventory for tab surface refactor

* fix(windows): preserve process-tree CRLF patch sources

* fix(native-chat): anchor an unmatched chat echo where it was sent (#16117)

* fix(native-chat): anchor an unmatched chat echo where it was sent

The reported symptom was old user messages replaying below every new turn, so the
conversation read as scrambled. The cause was not that the echo failed to match a
transcript row. Claude consumes a mid-turn send through a `queued_command`
attachment and writes no `type:"user"` record for it, so some echoes can never
match, and no amount of matching will change that. The cause was WHERE an
unmatched echo rendered: buildMobileNativeChatTransientData appended every pending
item after the entire transcript, so it re-read below each turn that landed
afterwards.

Render each echo directly after the transcript row it was sent against, using the
baseline the send already captures. An unmatched echo is then at worst a duplicate
in the right position rather than a scrambled one, and it stays visible. Echoes
sharing an anchor keep send order; a send with no baseline, or one whose anchor
folding dropped, still falls back to the tail.

Deliberately NOT fixed by deleting the echo. Inferring from send ordering that an
echo can never match, then removing it, loses the user's own text for a message
the agent did receive, and it cannot fire in the common case anyway - measured
drain groups are 1,017 of size 1 against 55 larger. It also escalates an existing
gap: the count pass has no baseline-tail guard, unlike the glue pass, while
`messages` is a 40-row window that head-trims, resets on reconnect and grows at
the front on loadEarlier, so a false landing there would license deleting a
DIFFERENT outstanding message.

That count-pass gap is real and left for a separate change; anchoring makes its
worst case a duplicate in place rather than a scrambled conversation.

* fix(native-chat): preserve folded echo anchors

* fix(native-chat): preserve forward-folded echo anchors

* fix(native-chat): keep leading folded echoes in place

* fix(workspace-cleanup): show git status for every row (#16690)

* fix(native-chat): refuse structured chat on every Windows execution path

canUseStructuredNativeChat only refused win32 when a project runtime
resolved, so folder-workspace keys (and other keys with no project
runtime) failed open into structured chat on Windows. Fail closed on
win32 unconditionally after the host check, matching the settings copy:
local macOS/Linux only; Windows/WSL/SSH stay on terminal chat.

* fix(native-chat): restore runtime refusals behind the win32 gate

506d375 replaced the project-runtime checks with a bare platform test,
so a WSL or repair-required runtime resolution would no longer refuse
structured chat off-win32. Keep the unconditional win32 refusal and
re-run the runtime resolution after it, so the gate does not depend on
the resolver's own platform guard. Tests inject WSL and repair-required
resolutions on darwin/linux and fail against the regressed gate.

* fix structured session journal durability

* fix structured tab active pointer after restart

* fix(native-chat): await optional lease renewal callbacks

* refactor(skills): extract install error messages

* fix(agent-session): harden recovery ownership

* fix(native-chat): retain panes across tab activation

* fix(native-chat): address round-one review findings

* test(native-chat): align integration coverage after main merge

* fix(native-chat): harden round-two reliability

* fix(native-chat): harden round-three reliability

* fix(native-chat): close round-four recovery gaps

* fix(native-chat): separate bounded journal key forms

* fix(native-chat): reset outbox error in render on session switch

The switch effect adjusted error state after the sessionId prop changed,
tripping react-doctor's no-adjust-state-on-prop-change on the changed-code
gate and flashing the old session's banner for a frame. Reset it with the
render-time previous-value guard instead.

* fix(native-chat): invalidate stale outbox settlements

* test(native-chat): restore settled-error session-switch regression

a6e2379 replaced this test with the in-flight settlement race test,
leaving the render-time error reset unpinned: deleting the reset block
still passed the whole native-chat suite. Keep both scenarios pinned;
they are distinct (settled error clears on switch vs stale settlement
invalidated in the commit-to-passive window).

* test(wire): make release checkouts race safe

* test(wire): pin cross-process checkout single-flight and importer specifier contract

* test(wire): harden release checkout lifecycle

* fix(build): drop CR-byte residue from windows-process-tree patch

The two trailing CR bytes on the patch's deletion lines are a proven
no-op: pnpm hashes patches CRLF-normalized (both forms hash to the
lockfile's 946ffb2b) and materializes this package without applying the
patch in either form, so the load-bearing build edits come solely from
applyWindowsProcessTreeBuildFixes() (#16947), which handles both source
EOL forms. Restore byte-identity with main and repin the contract test
to the post-#16947 reality: LF-only patch bytes plus lockfile hash sync.

* fix(native-chat): skip empty startup recovery
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 30, 2026
…#16729)

* feat(native-chat): port structured Codex sessions from restructure-recovery

Rebuilds the desktop structured native-chat implementation from
brennanb2025/native-chat-restructure-recovery (tip 4e31c08) on top of
current main as a single commit, scoped to the local Codex path.

Ported:
- Structured agent-session core: durable record store + single-writer lease,
  canonical journal, agent-session wire host/attach/eviction/subscribers,
  `agentSession.*` RPC surface (registered via ALL_RPC_METHODS; host-side
  mobile allowlist included for wire compat), pty write gate, transcript
  additions, and the Codex app-server adapter/launch resolution.
- Renderer: NativeChatStructuredSession view/composer stack, structured
  launch path with the single-flight guard, local structured session tabs
  sync, activation gate + structured inventory (read-only
  `agentSession.handoffStatus` probe), agent-session tabs in the tab strip,
  AI-vault structured session activation, and the settings pane with the
  parent Experimental Chat UI toggle plus the nested "Use updated structured
  native chat" toggle. New sessions require both flags, agent codex, no
  prompt, and a local non-WSL, non-Windows-host execution host
  (structured-native-chat-availability).
- Fixes 72c013c (verified Codex launch recovery), 8ddbaf5 (defer
  native terminal view switching affordances), and 4e31c08 (release the
  launch gate after a visibility retry) with their regression tests,
  including the third-launch-after-retry guard case.
- Cross-version agent-session wire test + CI lane, packaging entries
  (proper-lockfile, agent-tooling asar excludes), and the wire-compat doc
  section.

Deliberately not ported: mobile/ changes, the Claude structured runtime
(only the claude-transcript-branch-proof and claude-structured-owner-identity
leaf modules remain, backing the kept TUI-recovery arms), the terminal↔chat
adoption/handoff flow (`agentSession.adoptTerminal`/`requestHandoff`, the
handoff request engine, TUI adoption machinery, orca-runtime adoption
methods), renderer switching affordances and their dead leftovers, the
hook/subagent-status refactor cluster, and unrelated branch changes. The
crash-during-acquisition recovery path (restart handoff adjudication,
restore/reverse re-acquire, lease schema handoff keys) is kept because every
plain direct launch depends on it; a trimmed handoff coordinator exposes
only status/restore/close.

Branch edits that targeted files main has since split (ipc/pty.ts,
worktrees.ts, rpc/methods/terminal.ts, useIpcEvents, pty-connection,
store/slices/terminals.ts, runtime-types, web preload) were re-applied to
the split modules, preserving main's newer logic (Windows CIM fallback,
browser tab close rework, cold-restore resume flow, dispatcher threading).

Known seam: the mobile clipboard image-provenance CONSUMER gate ships
(agentSession.send refuses unproven mobile image refs with
agent_session_image_untrusted) but the producer hunk in
rpc/methods/clipboard.ts stays with the unported mobile cluster, so mobile
image sends into structured chat fail closed until that side ports.

* fix(native-chat): trust only authenticated local image uploads

* fix(build): preserve Windows process-tree patch application

* test(windows): include process creation time in addon fixture

* fix(build): run windows-process-tree node-gyp from the physical package dir

gyp expands the node-addon-api dependency by probing node, whose cwd
resolves to the package's physical directory in the store, so the emitted
target is a store-relative ../../../../node-addon-api@... hop. gyp then
resolves that hop against the rebuild cwd; from the node_modules
symlink/junction it escapes the store and configure fails with
"node_addon_api.gyp not found" (run 32999886072).

Rebuild from realpath(package dir) so both bases agree, matching how the
package manager itself runs native install scripts. The regression test
replays gyp's expansion+resolution against the planned cwd and fails
without the fix.

* fix(native-chat): keep chat tabs visible through terminal closes and empty-worktree launches

Two proven blockers in the native Codex tab contract:

closeTerminalTab pre-empted the canonical unified close. With one terminal
left it deactivated the worktree on a terminal/editor/browser-only check,
blanking a workspace that still held a renderable agent-session tab; with
two or more it pre-picked a successor from terminal entities only,
re-stamping the group active before closeUnifiedTab's MRU/neighbor repair
could land on the chat tab. Successor choice now defers to the unified
contract whenever the terminal has a unified row, and deactivation is
gated on the unified renderable count (matching leaveWorktreeIfEmpty),
with the legacy pre-pick kept only for terminals without a unified row.

A structured session created on an empty worktree was published into the
host's headless group while preserveLocalLayout froze the local layout,
leaving the tab in store but permanently off screen. A preserveLocalLayout
owner now always takes client-owned placement — repairing a rendered
leaf whose group record is missing, or materializing a rendered group on a
truly empty worktree — and applies the client-derived layout repair while
still rejecting host-authored layout.

Regression tests drive the real store through closeTerminalTab (git
worktree and folder workspace) and the real snapshot applier for the
empty-worktree adoption states; all fail without the fixes.

* fix(native-chat): close stale turns and retry rejected sends

* fix(native-chat): retire hosted rows on structured tab activation

* fix(native-chat): preserve rpc defaults across main merge

* chore: format remote wire compatibility guide

* test(native-chat): cover retry after unconfirmed send

* fix(native-chat): reload outbox on session switch

* docs(settings): disclose structured chat platform limits

* fix(native-chat): await Codex launch-home preparation

* fix(codex): align child-process allowlist with async trust bridge

* test(identity): update inventory for tab surface refactor

* fix(windows): preserve process-tree CRLF patch sources

* fix(native-chat): anchor an unmatched chat echo where it was sent (stablyai#16117)

* fix(native-chat): anchor an unmatched chat echo where it was sent

The reported symptom was old user messages replaying below every new turn, so the
conversation read as scrambled. The cause was not that the echo failed to match a
transcript row. Claude consumes a mid-turn send through a `queued_command`
attachment and writes no `type:"user"` record for it, so some echoes can never
match, and no amount of matching will change that. The cause was WHERE an
unmatched echo rendered: buildMobileNativeChatTransientData appended every pending
item after the entire transcript, so it re-read below each turn that landed
afterwards.

Render each echo directly after the transcript row it was sent against, using the
baseline the send already captures. An unmatched echo is then at worst a duplicate
in the right position rather than a scrambled one, and it stays visible. Echoes
sharing an anchor keep send order; a send with no baseline, or one whose anchor
folding dropped, still falls back to the tail.

Deliberately NOT fixed by deleting the echo. Inferring from send ordering that an
echo can never match, then removing it, loses the user's own text for a message
the agent did receive, and it cannot fire in the common case anyway - measured
drain groups are 1,017 of size 1 against 55 larger. It also escalates an existing
gap: the count pass has no baseline-tail guard, unlike the glue pass, while
`messages` is a 40-row window that head-trims, resets on reconnect and grows at
the front on loadEarlier, so a false landing there would license deleting a
DIFFERENT outstanding message.

That count-pass gap is real and left for a separate change; anchoring makes its
worst case a duplicate in place rather than a scrambled conversation.

* fix(native-chat): preserve folded echo anchors

* fix(native-chat): preserve forward-folded echo anchors

* fix(native-chat): keep leading folded echoes in place

* fix(workspace-cleanup): show git status for every row (stablyai#16690)

* fix(native-chat): refuse structured chat on every Windows execution path

canUseStructuredNativeChat only refused win32 when a project runtime
resolved, so folder-workspace keys (and other keys with no project
runtime) failed open into structured chat on Windows. Fail closed on
win32 unconditionally after the host check, matching the settings copy:
local macOS/Linux only; Windows/WSL/SSH stay on terminal chat.

* fix(native-chat): restore runtime refusals behind the win32 gate

506d375 replaced the project-runtime checks with a bare platform test,
so a WSL or repair-required runtime resolution would no longer refuse
structured chat off-win32. Keep the unconditional win32 refusal and
re-run the runtime resolution after it, so the gate does not depend on
the resolver's own platform guard. Tests inject WSL and repair-required
resolutions on darwin/linux and fail against the regressed gate.

* fix structured session journal durability

* fix structured tab active pointer after restart

* fix(native-chat): await optional lease renewal callbacks

* refactor(skills): extract install error messages

* fix(agent-session): harden recovery ownership

* fix(native-chat): retain panes across tab activation

* fix(native-chat): address round-one review findings

* test(native-chat): align integration coverage after main merge

* fix(native-chat): harden round-two reliability

* fix(native-chat): harden round-three reliability

* fix(native-chat): close round-four recovery gaps

* fix(native-chat): separate bounded journal key forms

* fix(native-chat): reset outbox error in render on session switch

The switch effect adjusted error state after the sessionId prop changed,
tripping react-doctor's no-adjust-state-on-prop-change on the changed-code
gate and flashing the old session's banner for a frame. Reset it with the
render-time previous-value guard instead.

* fix(native-chat): invalidate stale outbox settlements

* test(native-chat): restore settled-error session-switch regression

a6e2379 replaced this test with the in-flight settlement race test,
leaving the render-time error reset unpinned: deleting the reset block
still passed the whole native-chat suite. Keep both scenarios pinned;
they are distinct (settled error clears on switch vs stale settlement
invalidated in the commit-to-passive window).

* test(wire): make release checkouts race safe

* test(wire): pin cross-process checkout single-flight and importer specifier contract

* test(wire): harden release checkout lifecycle

* fix(build): drop CR-byte residue from windows-process-tree patch

The two trailing CR bytes on the patch's deletion lines are a proven
no-op: pnpm hashes patches CRLF-normalized (both forms hash to the
lockfile's 946ffb2b) and materializes this package without applying the
patch in either form, so the load-bearing build edits come solely from
applyWindowsProcessTreeBuildFixes() (stablyai#16947), which handles both source
EOL forms. Restore byte-identity with main and repin the contract test
to the post-stablyai#16947 reality: LF-only patch bytes plus lockfile hash sync.

* fix(native-chat): skip empty startup recovery

(cherry picked from commit fd9125e)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ablyai#16117)

* fix(native-chat): anchor an unmatched chat echo where it was sent

The reported symptom was old user messages replaying below every new turn, so the
conversation read as scrambled. The cause was not that the echo failed to match a
transcript row. Claude consumes a mid-turn send through a `queued_command`
attachment and writes no `type:"user"` record for it, so some echoes can never
match, and no amount of matching will change that. The cause was WHERE an
unmatched echo rendered: buildMobileNativeChatTransientData appended every pending
item after the entire transcript, so it re-read below each turn that landed
afterwards.

Render each echo directly after the transcript row it was sent against, using the
baseline the send already captures. An unmatched echo is then at worst a duplicate
in the right position rather than a scrambled one, and it stays visible. Echoes
sharing an anchor keep send order; a send with no baseline, or one whose anchor
folding dropped, still falls back to the tail.

Deliberately NOT fixed by deleting the echo. Inferring from send ordering that an
echo can never match, then removing it, loses the user's own text for a message
the agent did receive, and it cannot fire in the common case anyway - measured
drain groups are 1,017 of size 1 against 55 larger. It also escalates an existing
gap: the count pass has no baseline-tail guard, unlike the glue pass, while
`messages` is a 40-row window that head-trims, resets on reconnect and grows at
the front on loadEarlier, so a false landing there would license deleting a
DIFFERENT outstanding message.

That count-pass gap is real and left for a separate change; anchoring makes its
worst case a duplicate in place rather than a scrambled conversation.

* fix(native-chat): preserve folded echo anchors

* fix(native-chat): preserve forward-folded echo anchors

* fix(native-chat): keep leading folded echoes in place
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…#16729)

* feat(native-chat): port structured Codex sessions from restructure-recovery

Rebuilds the desktop structured native-chat implementation from
brennanb2025/native-chat-restructure-recovery (tip 4e31c08) on top of
current main as a single commit, scoped to the local Codex path.

Ported:
- Structured agent-session core: durable record store + single-writer lease,
  canonical journal, agent-session wire host/attach/eviction/subscribers,
  `agentSession.*` RPC surface (registered via ALL_RPC_METHODS; host-side
  mobile allowlist included for wire compat), pty write gate, transcript
  additions, and the Codex app-server adapter/launch resolution.
- Renderer: NativeChatStructuredSession view/composer stack, structured
  launch path with the single-flight guard, local structured session tabs
  sync, activation gate + structured inventory (read-only
  `agentSession.handoffStatus` probe), agent-session tabs in the tab strip,
  AI-vault structured session activation, and the settings pane with the
  parent Experimental Chat UI toggle plus the nested "Use updated structured
  native chat" toggle. New sessions require both flags, agent codex, no
  prompt, and a local non-WSL, non-Windows-host execution host
  (structured-native-chat-availability).
- Fixes 72c013c (verified Codex launch recovery), 8ddbaf5 (defer
  native terminal view switching affordances), and 4e31c08 (release the
  launch gate after a visibility retry) with their regression tests,
  including the third-launch-after-retry guard case.
- Cross-version agent-session wire test + CI lane, packaging entries
  (proper-lockfile, agent-tooling asar excludes), and the wire-compat doc
  section.

Deliberately not ported: mobile/ changes, the Claude structured runtime
(only the claude-transcript-branch-proof and claude-structured-owner-identity
leaf modules remain, backing the kept TUI-recovery arms), the terminal↔chat
adoption/handoff flow (`agentSession.adoptTerminal`/`requestHandoff`, the
handoff request engine, TUI adoption machinery, orca-runtime adoption
methods), renderer switching affordances and their dead leftovers, the
hook/subagent-status refactor cluster, and unrelated branch changes. The
crash-during-acquisition recovery path (restart handoff adjudication,
restore/reverse re-acquire, lease schema handoff keys) is kept because every
plain direct launch depends on it; a trimmed handoff coordinator exposes
only status/restore/close.

Branch edits that targeted files main has since split (ipc/pty.ts,
worktrees.ts, rpc/methods/terminal.ts, useIpcEvents, pty-connection,
store/slices/terminals.ts, runtime-types, web preload) were re-applied to
the split modules, preserving main's newer logic (Windows CIM fallback,
browser tab close rework, cold-restore resume flow, dispatcher threading).

Known seam: the mobile clipboard image-provenance CONSUMER gate ships
(agentSession.send refuses unproven mobile image refs with
agent_session_image_untrusted) but the producer hunk in
rpc/methods/clipboard.ts stays with the unported mobile cluster, so mobile
image sends into structured chat fail closed until that side ports.

* fix(native-chat): trust only authenticated local image uploads

* fix(build): preserve Windows process-tree patch application

* test(windows): include process creation time in addon fixture

* fix(build): run windows-process-tree node-gyp from the physical package dir

gyp expands the node-addon-api dependency by probing node, whose cwd
resolves to the package's physical directory in the store, so the emitted
target is a store-relative ../../../../node-addon-api@... hop. gyp then
resolves that hop against the rebuild cwd; from the node_modules
symlink/junction it escapes the store and configure fails with
"node_addon_api.gyp not found" (run 32999886072).

Rebuild from realpath(package dir) so both bases agree, matching how the
package manager itself runs native install scripts. The regression test
replays gyp's expansion+resolution against the planned cwd and fails
without the fix.

* fix(native-chat): keep chat tabs visible through terminal closes and empty-worktree launches

Two proven blockers in the native Codex tab contract:

closeTerminalTab pre-empted the canonical unified close. With one terminal
left it deactivated the worktree on a terminal/editor/browser-only check,
blanking a workspace that still held a renderable agent-session tab; with
two or more it pre-picked a successor from terminal entities only,
re-stamping the group active before closeUnifiedTab's MRU/neighbor repair
could land on the chat tab. Successor choice now defers to the unified
contract whenever the terminal has a unified row, and deactivation is
gated on the unified renderable count (matching leaveWorktreeIfEmpty),
with the legacy pre-pick kept only for terminals without a unified row.

A structured session created on an empty worktree was published into the
host's headless group while preserveLocalLayout froze the local layout,
leaving the tab in store but permanently off screen. A preserveLocalLayout
owner now always takes client-owned placement — repairing a rendered
leaf whose group record is missing, or materializing a rendered group on a
truly empty worktree — and applies the client-derived layout repair while
still rejecting host-authored layout.

Regression tests drive the real store through closeTerminalTab (git
worktree and folder workspace) and the real snapshot applier for the
empty-worktree adoption states; all fail without the fixes.

* fix(native-chat): close stale turns and retry rejected sends

* fix(native-chat): retire hosted rows on structured tab activation

* fix(native-chat): preserve rpc defaults across main merge

* chore: format remote wire compatibility guide

* test(native-chat): cover retry after unconfirmed send

* fix(native-chat): reload outbox on session switch

* docs(settings): disclose structured chat platform limits

* fix(native-chat): await Codex launch-home preparation

* fix(codex): align child-process allowlist with async trust bridge

* test(identity): update inventory for tab surface refactor

* fix(windows): preserve process-tree CRLF patch sources

* fix(native-chat): anchor an unmatched chat echo where it was sent (stablyai#16117)

* fix(native-chat): anchor an unmatched chat echo where it was sent

The reported symptom was old user messages replaying below every new turn, so the
conversation read as scrambled. The cause was not that the echo failed to match a
transcript row. Claude consumes a mid-turn send through a `queued_command`
attachment and writes no `type:"user"` record for it, so some echoes can never
match, and no amount of matching will change that. The cause was WHERE an
unmatched echo rendered: buildMobileNativeChatTransientData appended every pending
item after the entire transcript, so it re-read below each turn that landed
afterwards.

Render each echo directly after the transcript row it was sent against, using the
baseline the send already captures. An unmatched echo is then at worst a duplicate
in the right position rather than a scrambled one, and it stays visible. Echoes
sharing an anchor keep send order; a send with no baseline, or one whose anchor
folding dropped, still falls back to the tail.

Deliberately NOT fixed by deleting the echo. Inferring from send ordering that an
echo can never match, then removing it, loses the user's own text for a message
the agent did receive, and it cannot fire in the common case anyway - measured
drain groups are 1,017 of size 1 against 55 larger. It also escalates an existing
gap: the count pass has no baseline-tail guard, unlike the glue pass, while
`messages` is a 40-row window that head-trims, resets on reconnect and grows at
the front on loadEarlier, so a false landing there would license deleting a
DIFFERENT outstanding message.

That count-pass gap is real and left for a separate change; anchoring makes its
worst case a duplicate in place rather than a scrambled conversation.

* fix(native-chat): preserve folded echo anchors

* fix(native-chat): preserve forward-folded echo anchors

* fix(native-chat): keep leading folded echoes in place

* fix(workspace-cleanup): show git status for every row (stablyai#16690)

* fix(native-chat): refuse structured chat on every Windows execution path

canUseStructuredNativeChat only refused win32 when a project runtime
resolved, so folder-workspace keys (and other keys with no project
runtime) failed open into structured chat on Windows. Fail closed on
win32 unconditionally after the host check, matching the settings copy:
local macOS/Linux only; Windows/WSL/SSH stay on terminal chat.

* fix(native-chat): restore runtime refusals behind the win32 gate

506d375 replaced the project-runtime checks with a bare platform test,
so a WSL or repair-required runtime resolution would no longer refuse
structured chat off-win32. Keep the unconditional win32 refusal and
re-run the runtime resolution after it, so the gate does not depend on
the resolver's own platform guard. Tests inject WSL and repair-required
resolutions on darwin/linux and fail against the regressed gate.

* fix structured session journal durability

* fix structured tab active pointer after restart

* fix(native-chat): await optional lease renewal callbacks

* refactor(skills): extract install error messages

* fix(agent-session): harden recovery ownership

* fix(native-chat): retain panes across tab activation

* fix(native-chat): address round-one review findings

* test(native-chat): align integration coverage after main merge

* fix(native-chat): harden round-two reliability

* fix(native-chat): harden round-three reliability

* fix(native-chat): close round-four recovery gaps

* fix(native-chat): separate bounded journal key forms

* fix(native-chat): reset outbox error in render on session switch

The switch effect adjusted error state after the sessionId prop changed,
tripping react-doctor's no-adjust-state-on-prop-change on the changed-code
gate and flashing the old session's banner for a frame. Reset it with the
render-time previous-value guard instead.

* fix(native-chat): invalidate stale outbox settlements

* test(native-chat): restore settled-error session-switch regression

a6e2379 replaced this test with the in-flight settlement race test,
leaving the render-time error reset unpinned: deleting the reset block
still passed the whole native-chat suite. Keep both scenarios pinned;
they are distinct (settled error clears on switch vs stale settlement
invalidated in the commit-to-passive window).

* test(wire): make release checkouts race safe

* test(wire): pin cross-process checkout single-flight and importer specifier contract

* test(wire): harden release checkout lifecycle

* fix(build): drop CR-byte residue from windows-process-tree patch

The two trailing CR bytes on the patch's deletion lines are a proven
no-op: pnpm hashes patches CRLF-normalized (both forms hash to the
lockfile's 946ffb2b) and materializes this package without applying the
patch in either form, so the load-bearing build edits come solely from
applyWindowsProcessTreeBuildFixes() (stablyai#16947), which handles both source
EOL forms. Restore byte-identity with main and repin the contract test
to the post-stablyai#16947 reality: LF-only patch bytes plus lockfile hash sync.

* fix(native-chat): skip empty startup recovery
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