t3code icon indicating copy to clipboard operation
t3code copied to clipboard

fix(clients): sync thread modes across devices

Open Lucenx9 opened this issue 3 months ago • 2 comments

Closes #5278

Problem

Runtime and interaction mode changes on an existing thread were stored as device-local composer overrides until the next message was sent. Other clients could therefore keep showing and using a different mode for the same server-backed thread.

Fix

  • Dispatch the existing thread mode commands immediately from web/desktop and mobile.
  • Keep the composer value only as a guarded optimistic override, then remove it on confirmation or command completion so later remote updates remain visible.
  • Clear stale server-thread mode overrides on web entry and during mobile draft hydration while preserving new-task settings and unsent draft content.
  • Avoid duplicate mobile commands when the selected mode is already active.

Impact

Mode changes now persist as thread state and propagate across local, remote, and multi-device clients without requiring a prompt. Web and desktop share the web implementation; mobile uses the same server commands. Provider adapters and wire contracts are unchanged.

There are no visual changes, so before/after screenshots would be identical.

Validation

  • vp test run apps/web/src/composerDraftStore.test.ts apps/mobile/src/state/use-composer-drafts.test.ts (86 tests)
  • Targeted format and lint, including type-aware lint
  • Web typecheck
  • Mobile typecheck
  • React Doctor changed-scope scan (0 errors, 0 warnings)

Model: OpenAI Codex (GPT-5) Harness: Codex desktop app


[!NOTE] Medium Risk Touches shared thread mode state and multi-client consistency, but reuses existing server commands and guarded optimistic UI rather than new wire contracts.

Overview Runtime and interaction mode changes on server-backed threads now persist immediately via existing threadEnvironment commands on web (ChatView) and mobile (use-thread-composer-state), instead of staying device-local until the next message.

Composer drafts still hold short-lived optimistic overrides; those are cleared when the server thread state matches or after a successful command, and web also resets stale mode overrides when entering a server thread route. Failures surface as toasts (web) or pendingConnectionError (mobile), with no-op when the selected mode is already active.

On mobile, hydration of persisted drafts strips runtimeMode / interactionMode from existing thread keys (not new-task: or pending-task:), so restarted sessions don’t resurrect stale local mode overrides while unsent text and new-task/pending-task modes are preserved.

Reviewed by Cursor Bugbot for commit c4d5af50f16a5e352b3cec8b942d6cfd26f3839f. Bugbot is set up for automated code reviews on this repo. Configure here.

[!NOTE]

Sync thread runtime and interaction modes across devices via server-side persistence

  • On web (ChatView.tsx) and mobile (use-thread-composer-state.ts), changing runtime or interaction mode on a server thread now issues a server-side mutation via threadEnvironment commands.
  • Local draft overrides for runtimeMode and interactionMode are cleared once the server confirms the value, keeping the draft from re-applying stale overrides on next load.
  • Draft hydration (use-composer-drafts.ts, composerDraftStore) strips runtimeMode/interactionMode from existing thread drafts (non-new-task:/pending-task: keys) so server-owned values are not restored from local storage.
  • Errors from failed server mutations surface as toast notifications (web) or a pending connection error state (mobile); interrupted commands are silently ignored.
  • Behavioral Change: mode changes on existing server threads no longer apply only locally — they now trigger server mutations and previously persisted mode overrides in drafts will be dropped on hydration.

Macroscope summarized c4d5af5.

Lucenx9 avatar Aug 06 '26 13:08 Lucenx9

[!IMPORTANT]

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b77e542b-94e6-4bd7-b900-ed96a0ae39de

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • [ ] 🔍 Trigger review

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[bot] avatar Aug 06 '26 13:08 coderabbitai[bot]

Approvability

Verdict: Needs human review

This PR introduces cross-device thread mode synchronization - a new feature with significant new logic across mobile and web clients. The scope of changes (new files, new state management, retry logic) combined with unresolved review comments identifying potential bugs (mode overrides not clearing properly on draft routes) warrants human review.

You can customize Macroscope's approvability policy. Learn more.

macroscopeapp[bot] avatar Aug 06 '26 13:08 macroscopeapp[bot]