Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): reconcile client state when a settle does not land #4593

Closedcolonelpanic8(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/4593/headopened View on GitHub

What Changed

Settle can now recover a client whose view has drifted from the server, instead of requiring a client restart.

  • New resync-requested ConnectionWakeup. Snapshot-backed subscriptions (shell, threads) already reconcile on a foreground wake — reload the HTTP snapshot, resume the stream from its sequence — but nothing could ask for that on demand. They now resubscribe on this reason too, via a shared wakeupResubscribes predicate.
  • New ResyncRequests emitter in client-runtime, merged into the web app's wakeups layer.
  • settleThread requests a reconcile when it observes a disagreement:
    • when the local canSettle guard blocks the send, and
    • when a settle the server accepted never lands in the local view (checked at 150/500/1200 ms, then escalated).
  • Requests are coalesced behind a 5 s window, so bulk settle asks once rather than once per thread.

Why

Settling acts on the client's local view, and when that view is stale the action becomes unrecoverable in both directions:

  • canSettle (threadSettled.ts) refuses to send while the client's copy of session.status is starting | running, even if the server has since moved the session to ready.
  • A settle the server accepts against an already-settled thread is a deliberate idempotent no-op — it re-emits thread.settled with the original settledAt and the existing updatedAt (decider.ts) so bulk-settle and double-click stay quiet. If the local view never applies the resulting thread-upserted, every subsequent click succeeds while changing nothing visible.

Either way the control reads as dead and the thread cannot be moved to settled at all. The only known fix was restarting the client — which works precisely because it reloads the snapshot and resubscribes. This makes that same reconciliation reachable in place.

The server side already publishes what a client needs to converge: threadUpsertOrRemove re-reads the current projected row and emits thread-upserted after any thread event, including the idempotent re-emit. The gap is that nothing on the client notices when its view has stopped tracking that.

Reported in #4589.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes — no visual change; this only affects when a reconcile is requested
  • I included a video for animation/interaction changes — n/a

Validation (scoped per AGENTS.md, which reserves repo-wide vp check / vp run typecheck for CI):

vitest run apps/web/src/lib/ packages/client-runtime/src/state/    # 429 passed
tsgo --noEmit                                                      # apps/web, packages/client-runtime — clean
vp lint --report-unused-disable-directives                         # no findings in changed files

Note on verification honesty: the underlying desync has no deterministic repro yet, so the new escalation path is covered by unit tests rather than an end-to-end reproduction. The happy path is unchanged — the convergence check reads once and exits.


Note

Medium Risk Touches live subscription reconciliation and thread lifecycle UX; behavior is guarded by throttling and unit tests but the underlying desync has no deterministic E2E repro.

Overview Fixes settle appearing broken when the local thread view is stale: the server may accept the command (or the client may block on canSettle) while the UI never updates until a restart.

Adds an on-demand resync-requested connection wakeup (via ResyncRequests in client-runtime, merged into the web wakeups layer). Shell and thread snapshot subscriptions now resubscribe on that reason as well as foreground activation, using shared wakeupResubscribes.

settleThread requests a coalesced reconcile (5s trailing-edge throttle in resyncRequests.ts) when the local canSettle guard blocks, and after a successful settle runs confirmSettleConverged polling; if settled state still does not appear, it escalates to another resync.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 5fc3aefd627cc5417544dc99c0ead5399ac6115a. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Reconcile client state when a thread settle does not land locally

  • Adds a resync-requested wakeup type to ConnectionWakeup and wires it into the wakeups layer via a new ResyncRequests.resyncRequestStream in platform.ts.
  • Adds settleConvergence.ts, which polls the local thread shell after a successful settle and calls requestResync if the settled state never converges.
  • Adds resyncRequests.ts, a trailing-edge coalescing wrapper that fires at most one immediate and one trailing resync per 5-second window.
  • Updates settleThread in useThreadActions.ts to request a resync when a local canSettle check fails, and to run convergence polling after a successful mutation.
  • foregroundResubscriptions in shell.ts and threads.ts now resubscribe on resync-requested in addition to application-active.
Macroscope summarized 5fc3aef.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      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: 7aafa55e-231f-4def-b5dd-92cf8e16bd20

      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
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      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.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      This PR introduces new client-side state reconciliation logic including a new wakeup type, throttled resync requests, and convergence polling after settle operations. While well-tested, these changes significantly affect runtime behavior around client/server state synchronization and warrant human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 95aa50540a0bea279dcbf26b81e3f7669155aede. Configure [here](https://www.cursor.com/dashboard/bugbot).
    5. Note

      🤖 GPT-5.6 Sol responding on behalf of Theo

      We're closing this PR as we clean up the T3 Code backlog. Thank you for taking the time to put this together.

      Closing the settle-specific polling workaround. It adds another recovery loop and global resync signal around one client action. The underlying subscription failure should be repaired in shared recovery. The related recovery PR is still open, so this closure does not mean the desynchronization bug is already fixed. Related work: #4602.

      If you believe we closed this in error, please reopen the PR and leave a comment explaining what we missed. If GitHub does not let you reopen it, leave a comment here and we'll take another look.

Sign in to join this conversation.