Repository navigation
perf(agents): reuse unchanged remote thread items across polls - #1435
Conversation
Presence polls rebuild every remote ThreadItem, so the WeakMap render cache missed for all remote items each second even when nothing render-relevant changed. Sanitize tool items before equality and reuse the prior object when deeply equal at the same position; any delta keeps a fresh identity so cached renderings never go stale.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughRemote thread refreshes now reuse prior item objects when sanitized item values match. Regression tests check identity reuse across presence polls, changed-item identities, unchanged siblings, and sanitized tool arguments. ChangesRemote Thread Item Identity
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested reviewers: Merge Risk: ⚪ Minimal · up to No merge-blocking issue is identified for the presence-poll identity change; merge after normal checks. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Linked Issues checkExplanation Issue [ Resolution Complete the remaining [
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Resolve the CodeRabbit outside-diff finding on Gentleman-Programming#1123: an elapsed-only presence-poll change must request a render while unchanged remote thread items keep their cached identities. Identity reuse comes from the Gentleman-Programming#1435 slice merged into this chain; the new gate test advances the clock and asserts items survive the elapsed render, and the identity suite now advances the displayed clock so unchanged-content polls still apply under the render gate.
|
Excellent work @danielgap! Really clean performance optimization. Reusing prior The regression suite in |
|
Thanks Carlos! Really glad the Your read matches the intent exactly: thread logs are append-only, so positional comparison is safe, and the worst case on drops is a cache miss rather than stale rendering. Sanitizing tool args before comparison was the defensive gap I wanted closed for good. Merging it now. |
|
Small correction from my side: I don't have merge permissions on this repo, so the merge button is maintainer-side. @carlosmoradev when you get a chance, could you merge this one? Everything is green on my end. |
🔗 Linked Issue
Part of #1011 (status:approved) — first slice of the redesigned presence-poll delivery discussed on #1123. Deliberately does not close #1011: the elapsed-render-gate slice retargeted on top of this PR completes it.
🏷️ PR Type
type:bug— Bug fixtype:feature— New feature (perf →type:feature; label is maintainer-side, pull-only author)type:question— Question requiring tracked worktype:docs— Documentation onlytype:refactor— Code refactoringtype:chore— Maintenance/toolingtype:breaking-change— Breaking change📝 Summary
refreshPresence()rebuilt every remoteThreadItemobject on each 1-second poll, so theWeakMap<ThreadItem, string[]>render cache inthreadLinesmissed for all remote items even when nothing render-relevant changed.args: {}) before a plain-JSON deep-equality check; when the new item equals the prior item at the same position, the prior object is reused so its cached rendering hits. Any delta keeps a fresh identity, so changed content can never be served stale (rendering depends only on item content and width).📦 Size decision
Measured: 192 changed lines (191+/1−) against
main— within the 400-line review budget.📋 Changes
lib/agents-view.tssameItemValuedeep-equality helper;refreshPresenceitem mapping sanitizes first and reuses the priorThreadItemwhen deeply equal at the same positiontests/agents-view-thread-identity.test.ts✅ Test Plan
node --experimental-strip-types --test tests/agents-view-thread-identity.test.ts— RED observed (3 identity-assertion failures) on pristine source, then 3/3 pass after the fixnode --experimental-strip-types --test tests/agents-view.test.ts— 27/27 passpnpm run typecheck— 188 recorded diagnostics, no regressions (10 file/code pairs improved)pnpm test— 3406 pass / 0 failed assertions / 41 skipped; unit stage exits 1 on 36 cancellations that reproduce identically on currentmain(unref'dAbortSignal.timeoutfixture liveness: 26 intests/inprocess-reviewer.test.tsfirst at :274, 10 intests/rdd-status-line.test.tsfirst at :169) — environmental, not introduced here65466d52: PASS, no blockers (reuse compares sanitized-vs-sanitized both directions; growth/shrink/insertion-shift edges are conservative — worst case a cache miss, never staleness)🧾 Review provenance
Native review approved for this exact candidate: lineage
review-2bd0fed047a44611(medium,review-reliability), closure approved and acknowledgement burned (sha256:a4e9657494d4b0f6e8d8f04127a5ef6043906b21a87630422a682f38e9e3faf6). Four advisory findings were explicitly informational and non-blocking; recorded as follow-up work, not corrections to this candidate:lib/agents-view.ts:220) — naturally fits the perf(agents): skip renders for unchanged presence polls #1123 test slice:216-224)tests/agents-view-thread-identity.test.ts:89-97):223) — keeprenderThreadItemdependent only on item content + width🏷️ Labels (maintainer-side, pull-only author)
type:feature(exactly one type)✅ Contributor Checklist
type:*label — maintainer-side (pull-only)perf(agents): ...)Summary by CodeRabbit