Skip to content

fix(tui): preserve live parts during session hydration - #30300

Merged
kitlangton merged 4 commits into
devfrom
fix/tui-live-hydration-race
Jun 2, 2026
Merged

kitlangton merged 4 commits into
devfrom
fix/tui-live-hydration-race

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

Summary

  • preserve live message and part updates that arrive while initial TUI session history hydration is still in flight
  • merge individual live parts over the stale response instead of replacing them with older HTTP snapshot data
  • add a regression test reproducing live assistant text being replaced with an empty hydrated part

Root Cause

SyncProvider.session.sync() fetched session history asynchronously and then replaced message/part state wholesale. If a live message.part.updated event arrived before that response completed, the older response could overwrite visible assistant text with stale content until a later reload.

This is an independently reproduced TUI data race; it does not claim to fully explain or fix the separately observed OpenTUI blank-region report.

Verification

  • bun run test -- test/cli/cmd/tui/sync-live-hydration.test.tsx test/cli/cmd/tui/sync.test.tsx test/cli/cmd/tui/sync-undefined-messages.test.tsx
  • bun typecheck
  • bunx oxlint packages/opencode/src/cli/cmd/tui/context/sync.tsx packages/opencode/test/cli/cmd/tui/sync-live-hydration.test.tsx (existing warnings in sync.tsx, no lint errors)

@kitlangton

Copy link
Copy Markdown
Contributor Author

/review

}),
)
break
}

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.

Suggestion: consider only calling touchPart after this delta is actually applied. Right now a delta for a part that is not in local state still marks the part as live, then the hydration merge treats the HTTP snapshot as stale and drops it because there is no current part to preserve. Moving the revision touch below the !parts / !result.found guards would keep discarded deltas from deleting the hydrated part.

@kitlangton
kitlangton merged commit 1cae8f8 into dev Jun 2, 2026
10 checks passed
@kitlangton
kitlangton deleted the fix/tui-live-hydration-race branch June 2, 2026 01:40
isaacfinnegan pushed a commit to isaacfinnegan/whispercode that referenced this pull request Jun 15, 2026
leduyphuc1702 pushed a commit to leduyphuc1702/opencode-workflow that referenced this pull request Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant