Repository navigation
perf(dashboard): reuse unchanged rows in the slot-detail render - #20153
Conversation
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. [UX-REVIEWED] a4db64d Description read[DESCRIPTION-READ] e2e16202b384451f132f5100167ddde0c335637781cb56963ea37b7b73a0bac9 That sha256 names everything this verdict read: the PR description, plus the 13 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS The description says [DESIGN-REVIEWED] a4db64d Description read[DESCRIPTION-READ] 4a5db538768d00fce22251678f7f70c81e51e254183a4a913f061d294d2ec040 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The memo key carries an OAuth live-child slot that can never be filled, and the bench measures a smaller "hoisted" fix without reporting the result. Not justified as shipped
What this change shipsInventory (7 items) — 4 justifiedIntent: open session details faster without changing what they show or redact. This is an ADDITION (perf).
[FIRST-PRINCIPLES-REVIEWED] a4db64d Description read[DESCRIPTION-READ] 5fc78e5f02bca1f26ed5d18dc44b9ba82a8efe90cda0a3589969ac64f064e0d6 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
6be14cf to
c1c18ae
Compare
Reuse bounded rendered row JSON after a deferred page fill. Keep the ordinary renderer for unfilled pages and detect changed source rows with keyed digests. A hit avoids per-string redaction and output encoding, while source encoding and hashing still occur. Derive context from the existing string-cache key and distinguish the workspace-only link restoration scope. Never memoize OAuth rows, so a revoked endpoint approval is checked on every read. Owner view bypasses the memo. Classify this internal projection under the existing dashboard output sink without changing the security posture's egress count. Add cache-context and OAuth revocation regressions, row-oracle tests, and a reproducible interleaved render benchmark. Document cache limits and leave chat_utils unchanged for compatibility with stored verdicts.
c1c18ae to
7002f11
Compare
…e role cannot 500 A hand-edited transcript row whose role is a list or dict made the memoized render raise TypeError on the set-membership test once the page was filled. The unmemoized path compares role with == and renders the row; do the same.
Sensitive change review
|
mbriones98
left a comment
There was a problem hiding this comment.
Checks green and readiness passed at a4db64d; no behavior change.
Problem / Motivation
Goal: Make session details faster to open without changing displayed content or redaction.
The slot-detail read (
GET /api/chat/slots/{slot}) re-rendered every row on every request: a keyed HMAC per string for the display-redaction cache, the redaction pass, and ajson.dumpsof the whole history. The independent perf review measured this as the largest remaining GIL consumer (Figures 5.1 and 5.7:_display_redaction_cache_keyover every message, plus the full-history dump). A reader re-reads the same page many times (tab switch, reconnect, the refetch after each turn), and almost every row is unchanged between reads.Why it matters
Repeated reads of unchanged history spend CPU on the same redaction and serialization work, delaying session detail responses.
Not a goal
What changed (motivation → approach → change)
Repeated per-string hashing and whole-history serialization → reuse rendered row JSON under a bounded cache, with deferred filling.
dashboard/wire_render.pykeeps each rendered row's JSON text, keyed by a keyed BLAKE2b digest (random per-process key) of the exact source row plus everything else the render reads: the exempt-host set (policy hosts and the workspace's allowed hosts), the token-parameter exempt prefixes, and the live child id formcp_oauthrows. An unchanged row costs one row encode and one hash; no per-string HMAC, no redaction, no second serialization.beforecursor, whole-history flag) has been filled, every read of it is the unmemoized render, exactly as before. The first read schedules a fill that runs in a worker thread 1 s later (at most two at once). A fill that cannot start or fails leaves the page unfilled; its next read asks again.slot_detail._renderserializes the messages array separately and splices it between the fields before and after it. The body is byte-for-byte the previousjson.dumps.chat_utils.pyis unchanged.Security
mcp_oauth.credential_pass_bypassed()) neither read nor write the memo.json.loadsof the exact bytes that were hashed, not from the live dict. A window row the event loop changes during the render therefore can't store its output under another row's key.jsoncan't encode is rendered as before, without the memo.Relation to #19753 (redaction verdicts stored on write)
This PR leaves out every
chat_utils.pyhunk of #19753 (_display_redaction_cache_key,_redact_for_display). The only overlap is the_renderclosure inslot_detail.py, where #19753 wraps_prepare_messagesindisplay_verdicts.session(verdict_key). Whichever lands second resolves that by wrapping both render branches (_prepare_messagesandwire_render.prepare_messages_json) in the samesession(...). Then a cold first read still uses the stored verdicts, and memo misses use them too. A memo hit never reaches_redact_for_display, so #19753's read scope counts fewerfrom_memoryhits on such a render. That counter only feeds its cold-open heuristic, so after both land a mostly-hit render may load the sidecar a little earlier. Output is unaffected.Measured
Synthetic corpus: 3 sessions × 3,000 rows (~3.1 MB each). The rows mix prose, code blocks, tool output and fake credentials. Isolated in-process gateway (
aiohttptest server, realConversationLogunder a scratch dir). base =origin/main, new = this branch. Six alternating base/new runs; medians, ms.Request latency:
The first two rows run the same code on both sides (the unmemoized render). A second batch of six runs on a busier host put those rows anywhere from −10 % to +5 %, so I read them as noise.
Render time on its own (the work that holds the GIL in the render thread), medians over 15 interleaved iterations:
Memo memory, filled past its cap (16 MiB of charged output): 16.0 MB charged, 15.7 MB traced by tracemalloc, 22 MB of RSS freed when cleared.
Byte-for-byte oracle (
turn_gen, which is random per process, masked):json.dumps(_prepare_messages(...))over 4,000 edge rows. These cover every role, structured,Noneand empty content, lone surrogates, NUL, CJK, RTL, full-width digits,mcp_oauthwith live/dead/no child andjavascript:URLs, variants,blocked_linkswith and without the host allowed, unknown row fields, and chunk/done runs. Each was run under 3 live-child values × 2 host sets, cold, at the fill and warm: 18 renders, 0 differences.Not measured: the review's own load mix (its
load.pyharness isn't available here), so its GIL-share figures are not reproduced. The numbers above come from the synthetic corpus described.Tests
test/test_slot_detail_render_memo.py(new):json.dumps(_prepare_messages)cold and warm;origin/mainthis test fails: 376 digests for limit=100 and 2,626 for the whole history, against at most 1 (the title).python3 scripts/local-gate.py: backend related tests and 362 frontend test files pass.test_flake_pattern_ratchet.pypasses.semgrep/on the diff: 0 findings.Risks
Backwards compatibility
Compatible: response bodies and redaction behavior are unchanged.
Removes nothing: all existing fields, pagination and whole-history reads remain available.
Manual verification
The measured endpoint and render oracles above check the display byte for byte. The original review load harness was not available.
Related Issues
Related PR: #19753; the integration boundary is described above.