Skip to content

Preserve the reply prefix when opening a streaming session - #35

Merged
Tarquinen merged 7 commits into
devfrom
fix/session-streaming-prefix
Nov 12, 2026
Merged

Tarquinen merged 7 commits into
devfrom
fix/session-streaming-prefix

Conversation

@jlongster

@jlongster jlongster commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Opening a session after a reply had started streaming showed only the words that arrived after opening, until the reply finished. The event batcher now attaches a part's accumulated text to each delta when it saw the part from its start, and the session adopts it, so the reply shows from its first word.

Port of anomalyco/opencode-ios#323, limited to what that PR changes.

Verified:

  • scripts/check.sh passes, including the ported iOS #323 tests.
  • Emulator on a real OpenCode server, opening a reply about 2 s after its first words: before, the reply starts mid-word until it ends; after, it starts at its first word and keeps streaming.
  • Emulator on session-lab, which returns unfinished text over REST: the reply shows from its start and streams to the end.

The batcher can see the start before the selected detail exists. Carry the complete same-connection text with its delta so history and the next flush converge on one row. Preserve the reconnect guard when the start is unknown.

Verified the Kotlin batcher, decoding and session resume suites (29 tests) and 223 Statecheck checkpoints against the Kotlin reducers.

User decisions:
- Bring the streaming-prefix fix to Android.
- Check late opens, history races, reconnect gaps and duplicate rows.
@jlongster
jlongster marked this pull request as ready for review November 11, 2026 20:34
User decisions:
- Implement the Android streaming review fixes on PR 35.
User decisions:
- Implement the Android streaming review fixes on PR 35.
@jlongster

Copy link
Copy Markdown
Contributor Author

The review fixes are on this branch through 8229c5ce. The batcher protects active parts and bounds retained offscreen prefixes. History reads now retire settled accumulators, and cached unfinished rows survive an early open refresh. Added regression cases for eviction, pressure, a buffered delta arriving after settled REST text, and reopening across a stream gap. Static diff checks passed; Android verification runs in remote CI.

User decisions:
- Implement the Android streaming fixes on PR 35.
@Tarquinen
Tarquinen changed the base branch from main to dev November 12, 2026 01:12
The streamed-prefix fix is now the iOS change and nothing more: the
batcher attaches a part's accumulated text, the reducer adopts it, live
rows are marked in progress, and reads keep unfinished rows while a
session runs.

Removed (no counterpart in iOS #323, and not needed for the bug):
- settlingText: a REST text row no longer settles the part. The lab
  serves unfinished text over REST, so opening mid-reply froze the row
  until TextEnded.
- the settled-row checks in TextStarted/TextDelta/TextEnded, and the
  liveText re-apply loops in applyAuthoritative and
  applyAuthoritativeMessage are back as iOS has them.
- SessionFeatureHistory's earlier-history reconciliation.
- mergeTranscript's dropping of in-progress rows, its new default, and
  the AssistantMarkdown exclusion from projected-message protection.
- selectedTranscriptFetch in streamFocusSessionIDs.
- the batcher's Dispatchers.Default scope (onOverflow stays: it is
  iOS's finish(throwing:)).

Tests follow iOS #323: the raced-TextEnded test in
SessionRefreshReviewTests is restored to the iOS assertion; streaming
rows expect inProgress where iOS does; ported
openingMidReplyProjectsThePrefixIncludingShedDeltas,
cachedReplySurvivesAnOmittingOpenReadBeforeItsFirstDelta,
offscreenHistoryRefreshKeepsTheUnfinishedReplyForReopening and the
batcher half of openingAfterAnOffscreenFlushShowsThePrefixFromTheQueuedBatch
(replacing the Android-only shed-prefix test). The Android-only read-path
tests are dropped with the code they covered. Parity rows updated.

Verified: scripts/check.sh :server :feature:session :feature:drawer
passes on the Android VM, and the 7 new or ported tests ran.
@Tarquinen

Copy link
Copy Markdown
Member

I trimmed this to a straight port of iOS #323 and merged dev to clear the conflict (a8ab5d2, 2376bb7).

Removed, since iOS #323 doesn't have them and the bug doesn't need them: settlingText (REST text settling a part), the settled-row checks in the text events, the earlier-history reconciliation, the mergeTranscript drop logic and default, selectedTranscriptFetch in stream focus, and the Dispatchers.Default batcher scope. The liveText re-apply loops are back as on iOS.

Treating REST text as settled froze a reply opened mid-stream whenever a read returned unfinished text: on session-lab no new words appeared until the reply ended.

The ported raced-TextEnded test is back to the iOS assertion, and the new iOS #323 tests are ported. The commit message has the full list.

@Tarquinen
Tarquinen merged commit b810ddb into dev Nov 12, 2026
3 checks passed
@Tarquinen Tarquinen mentioned this pull request Nov 12, 2026

This branch was previously deployed

1 inactive deployment
release — 2376bb73 Deployed Nov 12, 2026 by Tarquinen via check #149
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