fix(tui): poll active sessions for external-writer changes (#31073)#31322
Open
lexlian wants to merge 2 commits into
Open
fix(tui): poll active sessions for external-writer changes (#31073)#31322lexlian wants to merge 2 commits into
lexlian wants to merge 2 commits into
Conversation
…#31073) Closes anomalyco#31073 After the first hydration, `sync.session.sync()` short-circuits via `fullSyncedSessions`, so updates produced by another opencode client / remote runner / `opencode serve` never reach this TUI unless they arrive over the local SSE stream. Add an opt-in `force` option to `sync.session.sync()` that bypasses the once-only cache while still de-duping in-flight calls, and add a bounded polling effect in the session route that re-syncs the active session while its status is `working` or `compacting`. The interval is configurable via the new `external_sync_interval_ms` tui.json key (default 2000ms, range 0-60000, 0 disables). The poll is cleaned up on route change, idle transition, and unmount.
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #31073
Type of change
What does this PR do?
After the first successful hydration of a session,
sync.session.sync()short-circuits via afullSyncedSessionsset, so updates produced by another opencode client, a remote agent, oropencode serverunning the same session never reach this TUI unless they happen to land on its own SSE stream. The session view stays frozen until the user navigates away and back.The fix:
force?: booleanoption tosync.session.sync()(packages/tui/src/context/sync.tsx) that bypasses the once-only cache while still de-duping concurrent in-flight calls viasyncingSessions. Default behavior is unchanged for every existing caller.external_sync_interval_mskey (packages/tui/src/config/index.tsx, range 0-60000, default 2000, 0 disables) so the polling cadence is configurable intui.json.createEffectin the session route (packages/tui/src/routes/session/index.tsx) that pollssync.session.sync(id, { force: true })at the configured interval only while the session's status isworkingorcompacting, and usesonCleanupto clear the interval on route change, idle transition, and unmount.Why it works: the
forceflag lets the polling effect re-fetch the active session's state on a timer, bypassing the once-only cache that previously madesync.session.sync()a no-op forever after first hydration. The poll is bounded — it only runs while a session is being driven (working/compacting) and stops the moment the session goes idle, the route changes, or the interval is set to0. When the SSE stream is healthy the local store already has the latest data and the reconcile is incremental, so the poll is effectively a no-op. It exists purely as a safety net for external writers and dropped events.How did you verify your code works?
bun testinpackages/tui: 190 pass, 1 skip, 0 fail (full suite, no regressions)bun test test/cli/cmd/tui/sync.test.tsx test/config.test.tsx: 15 pass, 0 fail (4 new sync tests + 3 new config tests)bun run typecheckinpackages/tui: cleanbun typecheckinpackages/opencode: cleanThe 4 new tests in
test/cli/cmd/tui/sync.test.tsxcover the regression directly:sync(id)call is a no-op (cache hit)sync(id, { force: true })issues a new round of fetchesforce: truecalls share a single underlying fetch (de-dup)message.updatedSSE event still issues 4 fetches instead of 0Screenshots / recordings
Not applicable. The bug requires two opencode clients (or one client +
opencode serve) writing to the same session, and the fix is invisible to a single TUI running standalone — a screenshot of one TUI cannot show the regression or the fix in action. The change is verified by the 4 new automated tests above.Checklist