Skip to content

Bound custom agent SVG classification cache - #1192

Open
kogekiplay wants to merge 2 commits into
spacering-net:mainfrom
kogekiplay:fix/bound-custom-agent-svg-cache
Open

kogekiplay wants to merge 2 commits into
spacering-net:mainfrom
kogekiplay:fix/bound-custom-agent-svg-cache

Conversation

@kogekiplay

Copy link
Copy Markdown
Contributor

Replacing or previewing a custom agent SVG leaves its full base64 data URL in the monochrome classification cache until the renderer exits. Repeating this retains old icons even after they are no longer displayed.

Cap the cache at 128 entries and 512 Ki UTF-16 code units of URL keys. Evict the oldest entries when either limit would be exceeded, and classify an oversized URL without caching it. SVG classification is unchanged.

Both regression cases fail on main and pass with the fix: many small icons and a few large icons evict the old classification while the newest still hits the cache. The full frontend test suite, changed-file lint and formatting, and the static build pass.

@kogekiplay

Copy link
Copy Markdown
Contributor Author

The Ubuntu desktop jobs on #1192, #1193, and #1194 each report a runner shutdown signal and exit 143. Could someone with Actions write access rerun those jobs once the runs finish?

The separate frontend failure on this PR is the existing login expiry test. A one-millisecond gap between its two clock reads reproduces the observed redirect using the actual storage helpers. #1194 fixes the test clock independently; the icon cache PR does not change the login path.

The bounded monochrome classification cache evicted in insertion order with a
512 Ki-unit budget, smaller than two maximum-size (256 KiB) icons. Two such
icons on screen evicted each other, re-decoding on every render. Refresh
entries on hit (LRU) and raise the budget to 2 Mi units.

The login test's expiry case read Date.now() before the stamp was written; a
millisecond on a slow runner left the item at the limit instead of past it.
Freeze the clock for the stamp.
@xintaofei

Copy link
Copy Markdown
Collaborator

Verdict: the approach holds. Ready once the follow-up commit is included.

Bounding the per-URL classification cache in isMonochromeSvgDataUrl is warranted. Before this change, every replaced or previewed icon stayed in the cache for the rest of the session, and a small size-capped cache is the right fix.

Findings and fixes (follow-up commit on this branch)

  • Important – re-decoding on every render (src/lib/custom-agents.ts:187). Icons can be up to 256 KiB, which is about 350 Ki characters as a data URL. The 512 Ki-unit budget can't hold two icons that large. With two such icons on screen, they evict each other and get decoded again on every CustomAgentIcon render. That breaks the old rule that an icon on screen is classified only once. Fix: a cache hit now moves the entry to the newest position (least-recently-used eviction instead of first-in-first-out), and the budget is now 2 Mi units. Two new tests cover this: an icon that keeps being shown is never decoded again while 300 new icons pass through the cache, and four max-size icons drawn in turn are never decoded again. Both fail on the original PR commit and pass with the fix. The PR's "a few large icons" test now uses 12 icons to fit the new budget.
  • The red test check is not caused by this PR. The failing test, src/app/login/page.test.tsx "does not bring back an item kept too long ago", is timing-dependent. It reads Date.now() before the item gets its own timestamp. If even 1 ms passes on a slow runner, the item lands exactly at the age limit instead of past it, so it is still treated as fresh. Fix: the test now freezes the clock before the item is stored, then moves it past the limit. With a 5 ms delay injected, the old test fails the same way CI did and the fixed one passes.
  • The red Rust desktop job on ubuntu was the runner being shut down, not a test failure.

Verification: prettier, eslint and tsc --noEmit are clean, and the full vitest suite passes (13,129 tests). An independent review found no blocking issues.

The changes were pushed to this pull request (3 files, +58/-6).


🤖 Generated with Codeg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants