GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||
GeezerVison is showing github.com — fix(client-runtime): large threads no longer freeze the renderer on every cache save by juliusmarminge · Pull Request #29446 · pingdotgg/t3code Conversation
Member
ProblemThe desktop and web renderer freezes for 1.5–2 s every 20–30 s while Change
Web, desktop and mobile share this code, so all three get the fix. Scope and approvalFixes #29417 Verification
Triaged and fixed by Claude Opus 5.5 (claude-opus-5-5) in Claude Code, running inside T3 Code; reviews by GPT-6.1 Sol (Codex) and Claude Opus 5.5. 🤖 Generated with Claude Code
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsA mounted thread appends every streamed event to its projection and saves the whole projection to the cache once it settles, so the cached snapshot grows past the server's bounded snapshot window. This test streams 600 completed items onto a bounded cached thread and asserts no cache save holds more rows than a bounded snapshot (502). It fails on main with 600. Co-Authored-By: Claude Opus 5.5 <[email protected]> …shot A mounted thread appends every streamed event to its projection and saved the whole projection whenever no run was active. The saved copy seeded the next mount, so the cache grew across sessions and saveThread encoded tens of megabytes on the renderer's main thread, freezing it every save. Treat a projection holding more local rows than a bounded server snapshot (THREAD_HISTORY_TURN_SNAPSHOT_ROW_LIMIT, 502) like an expanded one: it is not saved, queued repairs still flush, and the last bounded snapshot stays as the warm-cache seed. Fixes #29417 Co-Authored-By: Claude Opus 5.5 <[email protected]> …pshot A cache saved before the row limit kept loading, and the stop-repair path wrote it back. Treat an oversized cached snapshot as a miss so the server's bounded snapshot replaces it, and skip repairs of one. Co-Authored-By: Claude Opus 5.5 <[email protected]> …kipping the cache Snapshots can carry a few rows past the server's 502-row window, and servers before the row limit send whole-turn windows. A 1,000-row cap still keeps the streamed growth that caused the freeze out of the cache. Co-Authored-By: Claude Opus 5.5 <[email protected]> Rows can carry large command inputs and file diffs, so a thread under any row cap could still encode tens of megabytes. Estimate the JSON length without encoding, memoized per shared object, and keep threads past 4 MiB out of the cache. Co-Authored-By: Claude Opus 5.5 <[email protected]> …luded A Stop repair could merge large results into the saved snapshot after its size check, and escaped characters were counted once. Check the snapshot in persist, dropping the entry when a repair outgrows the limit, and count strings by their JSON length. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
There was an error while loading. Please reload this page.
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — Caps oversized thread-cache writes to reduce renderer freezes and drops oversized cached copies. Authoritative thread data remains unchanged, with existing server snapshot loading handling cache misses. You can add or adjust custom eligibility rules. Learn more. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Enforce and test thread snapshot size limits packages/client-runtime/src/state/threads.ts, packages/client-runtime/src/state/threads-sync.test.ts |
Thread projections over the estimated 4 MiB JSON limit are rejected for persistence. Oversized cached snapshots are removed during loading or before saving. Tests cover streamed growth, JSON-escaped control characters, oversized cached snapshots, and oversized repaired snapshots. The size estimate is memoized by object identity. |
Estimated code review effort: 2 (Simple) | ~12 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
#9661 — The PR adds a size limit for thread cache entries. It does not add age-based eviction.Suggested reviewers: t3dotgg
90de8Near the cache limit, web entries may slightly exceed the bound and mobile may discard a usable offline cache; the impact is recoverable and not merge-blocking.
Explanation
Issue #29417 is the only directly linked issue. Its coding requirement is to stop large thread snapshots from causing repeated main-thread encode and write freezes in storage.saveThread. Suggestion 1 of the issue is to skip or cap the thread cache for very large snapshots. The whole-PR diff of packages/client-runtime/src/state/threads.ts implements that suggestion. It adds CACHED_THREAD_MAX_JSON_LENGTH (4 MiB) and approximateJsonLength, a memoized per-object JSON length estimate in a WeakMap. shouldPersistThread now also requires isBoundedProjection, so oversized projections are not written. loadThread drops an oversized cached entry through removeThread. persist removes the entry instead of saving when a repair is oversized. The whole-PR diff of threads-sync.test.ts adds tests for event-grown projections (plain and escaped text), replacement of an oversized cache with a bounded HTTP snapshot, and removal of a cache whose repair would exceed the limit. Because the incremental diff from the previous reviewed head was unavailable, the current-head verdict rests on the whole-PR diffs of these two files. The previous PASS conclusion is still supported by the code read here. Unresolved: the PR does not profile a real Electron renderer. That is a verification gap, not a missing coding requirement.
Explanation
The whole-PR diffs of threads.ts and threads-sync.test.ts touch only the thread cache persistence path and its tests. The size estimate, load filter, write guard, repair removal, and shouldPersistThread change all serve issue #29417. The comment edits in threads.ts replace the word 'expanded' with 'unsaved' where the logic now also covers oversized timelines. These comment edits match the changed behavior and do not change unrelated product or platform code. The incremental diff from the previous reviewed head was unavailable, so this verdict rests on the whole-PR diffs of the two files named above. No other changed file was inspected.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Thread transfer impact
This comment will update automatically after the next completed run. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Otherwise every open decodes it again while the server snapshot is unavailable. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Dismissing prior approval to re-evaluate d5e0b8b
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks @juliusmarminge for investigating and fixing the large-thread freeze. #33503 (077fd62) now caps and chunks cache saves, removing oversized entries on save. I’m closing this as covered. If rejecting oversized legacy entries immediately on load still matters, a smaller follow-up focused on that is welcome. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[Bug]: Desktop typing freezes 1.5–2 s every ~30 s while storage.saveThread re-encodes a large thread snapshot on the main thread
There was an error while loading. Please reload this page.