GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@juliusmarminge

@juliusmarminge juliusmarminge commented Nov 2, 2026

Copy link
Copy Markdown
Member

Problem

The desktop and web renderer freezes for 1.5–2 s every 20–30 s while storage.saveThread Schema-encodes and writes a ~47 MB thread snapshot to IndexedDB on the main thread. This happens even for a thread the user is not viewing. The server sends bounded snapshots, but a mounted thread state adds every streamed event to its projection and never trims it. It saves the whole projection whenever no run is active, and that copy seeds the next mount, so the cache grows without bound. Web keeps every running thread mounted, so a thread running many short turns re-saves after each one. On main the encode alone costs 4 ms at 0.8 MiB, 25–50 ms at 4 MiB and 250–450 ms at 46.6 MiB in Node, in one synchronous step. The renderer adds the IndexedDB write on top.

Change

packages/client-runtime now keeps a thread whose JSON would pass 4 MiB out of the monolithic cache. Threads that loaded older pages are already kept out the same way.

  • The size estimate. It adds up string JSON lengths (escapes included) and key overhead without building the document. It is memoized per object in a WeakMap, and projection versions share unchanged rows, so a repeat check only walks new rows. The check runs only once no run is active.
  • 4 MiB leaves room for a fresh server snapshot: a 1 MiB turn window plus runs and checkpoints.
  • The existing unsaved-thread paths now apply. The scope finalizer writes only queued repairs, and the last bounded saved copy stays as the warm-cache seed.
  • An oversized cache already on disk is ignored on load, so the server's bounded snapshot replaces it.
  • Every write is checked in persist. A Stop repair that would grow the saved copy past the limit deletes the entry instead of writing it, so stale running rows cannot reload.

Web, desktop and mobile share this code, so all three get the fix.

Scope and approval

Fixes #29417

Verification

  • vp test run packages/client-runtime/src/state/threads-sync.test.ts: 50 passed. The four new cases, with what each fails with on main:
    • does not cache a thread that events grew far past a bounded snapshot (plain text): expected 10336579 to be less than or equal to 4194304
    • … (escaped text): expected 17828139 to be less than or equal to 4194304
    • replaces an oversized cache with a fresh bounded snapshot: expected +0 to be 1, because the oversized cache was used and the server was never asked
    • drops the cache when its repair would pass the size limit: a snapshot of more than 4 MiB was written
  • vp run check:changed (format, lint, knip, typecheck of 7 packages, tests): all pass.
  • Runtime transcript from a scratch Node driver with a synthetic 2,000-row projection. It times the exact encoder storage.saveThread runs on main, then the new size estimate:
main, encode 46.6 MiB:   250–450 ms per save (one synchronous step)
main, encode  4.0 MiB:    25–50 ms
main, encode  0.8 MiB:     4–10 ms
fix, estimate 46.7 MiB vs JSON 46.6 MiB: first walk 41–140 ms, after one new row 0.10–0.19 ms
  • No visible surface changes, so there are no captures. The driver scripts are not linked because no uploader was available on the VM that did the work.
  • Not checked:
    • a profile of the real 30-second cycle in an Electron renderer;
    • the reporter's own Wayland session (the mechanism is in shared client code, not platform code, and the tests above reproduce it);
    • Hermes timings on mobile.

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 reactions
juliusmarminge and others added 8 commits November 2, 2026 15:54
@juliusmarminge @claude
test(client-runtime): reproduce #29417 unbounded thread cache saves
98a6671
A 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]>
@juliusmarminge @claude
fix(client-runtime): stop caching threads that outgrow a bounded snap…
74f79fd
…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]>
@juliusmarminge @claude
fix(client-runtime): replace thread caches that outgrew a bounded sna…
a63d8cc
…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]>
@juliusmarminge @claude
fix(client-runtime): leave headroom above a bounded snapshot before s…
df4e7f8
…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]>
@juliusmarminge @claude
fix(client-runtime): bound the thread cache by size instead of rows
1e1c7b7
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]>
@juliusmarminge @claude
fix(client-runtime): size-check every thread cache write, escapes inc…
b8e3744
…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]>
@juliusmarminge @claude
perf(client-runtime): skip the cache size walk while a run is active
068baea
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@juliusmarminge
Merge remote-tracking branch 'origin/main' into fix/issue-29417
9463f67
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Nov 2, 2026
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Nov 2, 2026
View reviewed changes
@macroscopeapp

macroscopeapp Bot commented Nov 2, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 90de82a

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: pingdotgg/t3code
  • Branch: fix/issue-29417
  • File: .coderabbit.config.ts
  • Commit: 90de82a
  • Layers: Repository TS config
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 34fe4be2-8d75-4ebe-9e7e-812f43d2a702
Commits

Reviewing files that changed from the base of the PR and between 9463f67 and 90de82a.

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; 6 remain after this review.

Walkthrough

Thread cache persistence now uses an estimated 4 MiB JSON-size limit. Oversized cached snapshots are removed during loading or persistence. Tests cover oversized snapshots from streamed events and pending-work reconciliation.

Changes: Thread cache size bounds

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

Merge Risk: Low · up to 90de8

Near 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.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly identifies the client-runtime fix for renderer freezes caused by large threads being saved to the cache.
Description check Passed The description covers the problem, change, linked issue and scope, and verification results. It also states which checks were not performed.
Linked Issues check Passed 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 …
Out of Scope Changes check Passed 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 shouldPersistThre…
Full details: Linked Issues check

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.

Full details: Out of Scope Changes check

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.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

coderabbitai[bot]
coderabbitai Bot reviewed Nov 2, 2026
View reviewed changes

@coderabbitai coderabbitai Bot left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/client-runtime/src/state/threads.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Nov 2, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Thread transfer impact

⚠️ The latest CI run did not produce a thread transfer result for 90de82a.

This comment will update automatically after the next completed run.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@juliusmarminge @claude
fix(client-runtime): delete an oversized thread cache when rejecting it
d5e0b8b
Otherwise every open decodes it again while the server snapshot is unavailable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@macroscopeapp
macroscopeapp Bot dismissed their stale review November 2, 2026 16:48

Dismissing prior approval to re-evaluate d5e0b8b

@juliusmarminge @claude
refactor(client-runtime): reject oversized caches with filterOrElse
90de82a
Co-Authored-By: Claude Opus 5.5 <[email protected]>
macroscopeapp[bot]
macroscopeapp Bot approved these changes Nov 2, 2026
View reviewed changes
@juliusmarminge juliusmarminge added bugfix Fix PR opened by an issue lead; enters the PR loop pr:gate-failed A land gate failed labels Nov 2, 2026
@Pyseph Pyseph mentioned this pull request Nov 5, 2026
perf(web): left threads give up their memory past a 50 MB budget #31484
Closed
@juliusmarminge GitCafe Production

juliusmarminge commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@juliusmarminge juliusmarminge closed this Nov 9, 2026
@juliusmarminge juliusmarminge removed the pr:gate-failed A land gate failed label Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@coderabbitai coderabbitai[bot] coderabbitai[bot] left review comments
@macroscopeapp macroscopeapp[bot] macroscopeapp[bot] approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

bugfix Fix PR opened by an issue lead; enters the PR loop size:M 30-99 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Milestone

No milestone

Development

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

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@juliusmarminge
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.