Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(client-runtime): cache running threads when their view closes #25213

Mergedmaria-rcksmerged 2 commits intomain fromrefs/pull/25213/headmerged by juliusmarminge View on GitHub

maria-rckscommented

Problem

Closing a running thread skips its disk-cache save, so reopening it after a client relaunch can show "Loading messages..." until the server responds.

Change

Save the latest committed snapshot once when the view closes, including active runs. Keep the streaming-write guard, expanded-history guard, queued cache repairs, and persistence deduplication unchanged. The shared client runtime serves web, desktop, and mobile.

Verification

  • The regression test fails on main (zero saved snapshots), then passes with the fix. All 39 existing-file thread-sync tests pass.
  • Blacksmith vp run check:changed passes format, lint, knip, affected-package typechecks, and tests. Lint reports two pre-existing polling warnings outside the added test.
  • Real web client, system Chrome, Codex GPT-6-Astra: open a running turn, navigate away, close the browser, relaunch, reopen. Separate threads use the same prompt and sleep 120 command. Snapshot HTTP responses are held only in the browser for both reopens. Main shows a blank timeline until release; the fix displays the saved messages and running command without requesting a snapshot. Clips are functional evidence, not latency measurements.
  • CodeRabbit reported its review limit and posted no findings; its check is green.
  • Unverified: native iOS/Android and Electron runtime, remote/relay/tunnel, and very large cache-write cost. No provider adapter or wire contract changes.

Before, main 3ca62a564457:

Before: reopening the running thread waits for server messages

After, e86f36682a17:

After: the matching prompt and running command appear from cache

Reopen recording, main followed by the fix. Conversation crops match; startup splash frames are trimmed.

Before and after: reopening a running thread after browser relaunch

Takeover

Replaces #24210, with thanks to @shivamhwp for the original implementation.

Built with GPT-6.1-Sol in the Codex harness on T3 Code.

    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      The thread finalizer now saves non-expanded projections even when a run is preparing, starting, or running. A test verifies that the latest thread snapshot is saved when the view scope closes.

      Changes: Running thread persistence

      Layer / File(s)Summary
      Persist running thread snapshots
      packages/client-runtime/src/state/threads.ts, packages/client-runtime/src/state/threads-sync.test.ts
      The finalizer saves the current projection when history is not expanded. The test checks that no cache save occurs during the open scope and that scope closure saves one snapshot with the latest sequence, title, and running status.

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Bug fix

      Suggested reviewers: shivamhwp, juliusmarminge

      Merge Risk: Minimal · up to d5d40

      Reopening a running thread after a relaunch now shows cached messages instead of "Loading messages...". The change is small and covered by a regression test, so merge-readiness risk is minimal.

      Pre-merge checks: Passed 3 · Inconclusive 1

      Failed Failed checks: 1 inconclusive
      Check nameStatusExplanationResolution
      Description checkInconclusiveThe description follows the template. It has Problem, Change, and Verification sections, and it states the bug, the fix, and the test results. It also includes before and after evidence and notes what…Add a Scope section. Link the issue that shows the bug. If no issue exists, explain why this small fix of an obvious bug needs none. If a maintainer asked for this PR, link that request. The Takeover note about #24210 may stay, but it does …
      Passed Passed checks: 3 passed

      Check nameStatusExplanation
      Title checkPassedThe title names the main change: running threads are now cached when their view closes, which matches the summary's finalizer change and the new test. It uses the conventional commit format and a spec…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Title check

      Explanation

      The title names the main change: running threads are now cached when their view closes, which matches the summary's finalizer change and the new test. It uses the conventional commit format and a specific scope. The title does not mention the relaunch symptom, but it still identifies the primary change.

      Full details: Description check

      Explanation

      The description follows the template. It has Problem, Change, and Verification sections, and it states the bug, the fix, and the test results. It also includes before and after evidence and notes what remains unverified. The Scope section is missing: the description does not link an issue or explain why no issue is needed. It also does not state a reason for skipping one. The description also replaces PR #24210 and credits its original author, which the template does not require. The author gives no explicit statement about the Scope requirement for a bug fix.

      Resolution

      Add a Scope section. Link the issue that shows the bug. If no issue exists, explain why this small fix of an obvious bug needs none. If a maintainer asked for this PR, link that request. The Takeover note about #24210 may stay, but it does not replace the Scope section.

      Finishing Touches

      Generate unit tests (beta)

      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between 759f67aed383ed5e29483893926d934a9bfd9a78 and d5d407ab6e8f23f71852101e507f832bf01a265f.

      Files selected for processing: 2

      • packages/client-runtime/src/state/threads-sync.test.ts
      • packages/client-runtime/src/state/threads.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

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

      Approvability

      Verdict: Approved at 759f67a

      Macroscope's review found this PR approvable — Running threads now save their latest committed snapshot when their view closes, allowing cached messages to appear on reopening. Existing streaming-write, expanded-history, and persistence safeguards remain unchanged.

      No code changes detected at d5d407a. Prior analysis still applies.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. 🤖 Generated by an LLM on behalf of Tomasz Tórz.

      Native iOS data for the "not verified" note. We landed on the identical change independently.

      Scenario: a thread is running when the reader opens it and leaves; the app is relaunched; the reader reopens it. iOS simulator, T3 server on a copy of a real 6 GB database, 5G profile (120 ms RTT, 10/5 Mbps) through a shaping proxy, server CPU limited to 10 % to match a loaded host. The run was frozen mid-turn (dev replay agent paused), so the thread was confirmed running, Stop button visible, when left.

      Touch-down → first committed feed after the relaunch:

      • main: 1.45 s median (1.32–1.58, n=4), loaded from the host
      • this change: 0.69 s median (0.67–0.69, n=4), from the device cache

      Happy to share the harness (proxy, CPU throttle, timing marks) if useful.

    4. tanstack-source added labelsbug

    5. juliusmarminge added labelstakeover:in-progress

    6. Evidence

      Real Chromium web client, 1280×800, light theme, fresh synthetic data per commit. Load an approval-waiting replay thread, leave it for a finished control, wait 6 seconds, restart the page runtime with server delivery delayed 5 seconds, then reopen the running thread and capture after 1.5 seconds. The finished control restores on both sides. The base running timeline is blank; the head restores its prompt, running command and approval request while reconnecting. scenarios:prove exited 0.

      CaptureBefore — 4c47315538After — d5d407ab6e
      Running before leavingBefore: running approvalAfter: running approval
      Finished control restoredBefore: control restoredAfter: control restored
      Running thread reopenedBefore: blank timelineAfter: cached running timeline
      Assertion failureBefore: missing cached timeline at assertionPassed
      RecordingBefore recordingAfter recording

      Scenario source

      Restart used a full page reload preserving IndexedDB, rather than terminating the browser process.

      Not shown:

      • Browser process termination and relaunch were not exercised; the scenario recreated the page and client runtime through reload while retaining IndexedDB.
      • Native mobile and desktop clients were not run; proof covers the shared cache behavior through the web client.
      • Preparing and starting run states were not separately exercised; the captured run was running and waiting for approval.
    7. juliusmarminge added labelstakeover:ready

    8. juliusmarminge removed labelstakeover:in-progress

    9. juliusmarminge merged thiscf60628

    10. juliusmarminge closed this

    11. juliusmarminge removed labelstakeover:ready

Sign in to join this conversation.