Skip to content

Point-window cache (T13) + resolvability gate (#225)#227

Draft
masenf wants to merge 2 commits into
claude/density-mean-colorfrom
claude/point-caching-sampling-av37m7
Draft

Point-window cache (T13) + resolvability gate (#225)#227
masenf wants to merge 2 commits into
claude/density-mean-colorfrom
claude/point-caching-sampling-av37m7

Conversation

@masenf

@masenf masenf commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements two interconnected LOD improvements: a per-trace LRU cache of retired exact point windows (T13) that eliminates re-requests on pan/zoom sequences, and a resolvability gate (#225) that prevents sample overlays from drawing above the direct point budget where they misrepresent the dataset.

Key Changes

Point-Window Cache (T13)

  • Added LOD_POINT_CACHE_WINDOWS = 3 constant to bound retired window memory
  • Introduced lodRetireDrill(), lodPromoteCachedDrill(), and supporting functions to manage the per-trace LRU cache of exact point windows
  • When a new points reply arrives for a different window, the previous exact window retires into the cache instead of being freed
  • Views covered by any cached window promote it back to the live drill with zero kernel round-trip
  • Cached windows obey geometry-only retirement (T11): once a view outgrows a window past the drill budget, its buffers free with no kernel reply
  • Extracted lodWindowServesView() as a shared containment check for both live drill and cached windows

Resolvability Gate (#225)

  • Added lodOverlayResolvable() function that gates sample overlay drawing on estimated in-view count
  • Sample overlays now draw only when overlay.sample.visible * (viewArea / windowArea) <= LOD_DIRECT_POINT_BUDGET
  • Above the budget, a fixed-size sample reads as individual data points at sub-pixel zoom, misrepresenting the dataset; the density surface stands alone
  • Interactive density_view replies no longer ship point samples at all (only the first-payload sample is retained for the standalone re-bin worker)
  • Updated lodSampleForView() to apply the gate before considering overlay candidates

Padded Aligned Windows (T13 support)

  • Drill windows now ship as padded ALIGNED superset of the view (within budget) to maximize cache reuse across pans
  • Consecutive pans resolve to the same aligned bounds, enabling client-side deduplication
  • Added aligned_window() and _padded_drill_window() to compute the widest aligned window that fits the budget
  • Span is capped relative to the view (DRILL_PAD_SPAN_CAP) to keep deep zooms inside the §16 re-encode ladder
  • Falls back to raw view window when padding would exceed budget

Drill Subset History

  • Added drill_history dict to Trace to remember recent shipped subsets (bounded by DRILL_HISTORY_KEEP)
  • Cached point windows outlive the kernel's current-tier choice; picks against them translate through the remembered subset
  • drill_history() returns the shipped subset for a given drill_seq, or None when expired (drops the pick)
  • clear_drill_history() forgets subsets after data changes

Identical-Request Suppression (T13)

  • Added _densityRequestDup() to detect when the same window at the same screen size is already in flight or answered
  • Prevents the "constantly re-requesting the same points" loop by keeping the original seq instead of arming a duplicate
  • Checked both at request scheduling and at send time

Client-Side Changes

Notable Implementation Details

  • The cache is per-trace (not global) to respect data independence
  • Window comparison uses relative tolerance (span * 1e-9 + 1e-300) to handle floating-point slop
  • Retired windows on drill death (zoom-out to density) are cached the same way as on new-window retirement, enabling zero-cost revive
  • The resolvability gate requires finite visible count on the sample metadata; overlays without recorded counts (hand-built/legacy specs) keep drawing
  • Padded windows snap to power-of-two grid over the trace extent, making them stable

https://claude.ai/code/session_01XQT3v7NdL4dmC6S3g8HjJt

…dows

Fixes #225: zooming out from a drilled window brought fixed-rate "sampled
points" back over the density surface — individual marks at a zoom where
real points are sub-pixel, misrepresenting the dataset. Now:

- Interactive density_view replies ship no point sample at all. The
  mean-color density surface (LOD doc §2) stands alone above the drill
  budget; real points still arrive the moment a window fits it. The
  retained first-payload sample (the standalone re-bin worker's CPU
  source) draws only below a resolvable-count gate: estimated in-view
  count <= LOD_DIRECT_POINT_BUDGET (lodOverlayResolvable, T9). Datasets
  under the budget keep the hybrid look everywhere.

Point caching (LOD doc T13) so pan/zoom stops re-shipping the same points:

- Kernel: a points-tier reply ships the largest ALIGNED window around the
  view whose exact count fits the budget (lod.aligned_window: bounds snap
  outward to a power-of-two grid over the trace's extent, per dimension;
  DRILL_PAD_TARGETS ladder, pyramid-count-gated, exact-verified,
  DRILL_PAD_SPAN_CAP guards the §16 re-encode ladder). Consecutive pans
  resolve to the SAME window; lod_blend stays keyed on the view's own
  count. Nonlinear axes keep the exact view window.
- Client: a reply for a new window retires the previous exact drill into
  a bounded per-trace cache (lodRetireDrill/LOD_POINT_CACHE_WINDOWS)
  instead of overwriting its buffers — so does a drill dying outside its
  window — and any later view covered by a cached window promotes it back
  alpha-continuously with zero round-trips (lodPromoteCachedDrill).
  Outgrown windows free geometry-only (T11 rule, §27).
- Kernel keeps a bounded drill-subset history (Trace.drill_history,
  DRILL_HISTORY_KEEP) so picks against a promoted retired window still
  translate exactly; expired seqs drop the pick, data changes clear it.
- Client suppresses identical density_view requests (same window, screen,
  unchanged data) and accepts the suppressed duplicate's in-flight reply
  per-trace instead of killing it with the bumped seq — ending the
  re-request loop at gesture end.

Spec: lod-architecture T9 rewritten + new T13, wire-protocol
density_view/points/pick contracts, dossier constants table, CHANGELOG,
README representation labels, docs ladder table.

Tests: new test_drill_window_padding (alignment, budget, span cap,
nonlinear skip, history clear), test_density_sample_resolvability_gate
and test_drill_point_window_cache (headless-Chromium client probes),
elision test extended for duplicate suppression; drill tests updated to
the padded-window contract.
@masenf
masenf marked this pull request as draft July 23, 2026 12:50
@greptile-apps

greptile-apps Bot commented Jul 23, 2026

Copy link
Copy Markdown

Greptile Summary

This PR improves dense scatter rendering with reusable point windows and resolution-aware overlays. The main changes are:

  • Bounded caching and promotion of retired exact point windows.
  • Padded, aligned drill windows for reuse across nearby views.
  • Density request deduplication and cached-texture elision.
  • Resolution gating for sampled point overlays.
  • Drill subset history for picks against cached windows.

Confidence Score: 4/5

The in-place tier update path can leave density rendering stale and needs a fix before merging.

Answered request memos do not expire. A tier update can change trace data without replacing the GPU record or clearing its memo. A matching view can therefore suppress the density request needed for the new data.

js/src/54_kernel.ts

T-Rex T-Rex Logs

What T-Rex did

  • I reproduced the tier-update verification in a headless Chromium run against the real client and production message handlers, observing that the initial density request was answered and the in-place tier_update retained the same GPU record, density texture, and answered memo.
  • I queried density memo again with _densityRequestDup about 100 seconds later and confirmed it returned the retained answered memo, showing suppression is unbounded and not just a short timeout.
  • I scheduled the same window and plot size and observed zero fresh density_view requests, with the trace containing only the original request, so the repro failed its correctness assertion.
  • I reached the maximum step budget and concluded that no further verification tasks remain, and the plan is to invalidate the density memo when tier_update changes data.
  • In the after-browser payload, all required fields reported true and artifact validation confirmed the presence and integrity of video, poster frames, standalone HTML, logs, and checksums.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
js/src/54_kernel.ts Adds request deduplication, cache elision, cached-drill promotion, and stale-reply handling; in-place tier updates can leave the answered request memo stale.
js/src/45_lod.ts Adds point-window caching, sample resolvability checks, density detail layering, and cache adequacy checks.
js/src/50_chartview.ts Extends trace cleanup to release cached drill windows and all drill buffers.
python/xy/interaction.py Adds padded drill selection, density source-resolution metadata, and historical subset lookup.
python/xy/lod.py Adds aligned-window calculations and bounded drill subset history.

Reviews (2): Last reviewed commit: "Bound density wire traffic: source-clamp..." | Re-trigger Greptile

Comment thread js/src/54_kernel.ts
Comment on lines +160 to +169
// duplicate-suppressed requests leave their traces waiting on the ORIGINAL
// request's seq (T13 — identical window and screen). Accept it only when
// every trace it updates is still waiting on exactly this seq AND that seq
// names the trace's last actually-SENT request — a pending marker can
// outlive a debounce-cancelled send, and a reply matching such a phantom
// request is stale, not suppressed-current (T5).
_densityReplyCurrent(msg) {
const ids = (msg.traces || []).map((u) => Number(u.id));
if (!ids.length && msg.trace !== undefined) ids.push(Number(msg.trace));
if (!ids.length) return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 One Trace Rejects Whole Reply

When a batched request for traces A and B is followed by a view that A can serve from its point cache but B cannot, only B keeps waiting for the original sequence. _densityReplyCurrent then returns false because A no longer has that pending sequence, so the handler discards the whole response, including B's current update. B remains stale until the request times out and is sent again; reply currentness must be applied per trace rather than requiring every trace in the batch to remain pending.

Comment thread js/src/54_kernel.ts
Comment on lines +152 to +157
_densityRequestDup(g, view, plotW, plotH, now) {
const last = g._lastDensityReq;
if (!last || last.key !== this._densityRequestKey(g, view, plotW, plotH)) return null;
if (last.answered) return last;
return now - last.sentAt < 1200 ? last : null;
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Answered Memo Survives Data Rebuild

The duplicate check treats an answered key as permanently current for the lifetime of the GPU trace record, but trace resource rebuilds do not clear _lastDensityReq. If new data is applied while the record is retained, returning to the same window and screen size matches the old answered key and suppresses the density request, leaving the view rendered from stale data.

Artifacts

Repro: focused executable lifecycle harness

  • Evidence file captured while the check ran.

Repro: runtime output showing retained answered memo, suppressed second request, and stale response

  • The full command output behind this check.

View artifacts

T-Rex Ran code and verified through T-Rex

…yered draw

Field HAR from the 100M live drilldown (PR #227 review): every pan/zoom
step at 200-450% zoom re-requested a ~2.7 MB full-screen density grid —
including back-to-back windows differing by sub-pixel amounts — and the
frame dropped to the blurriest cached texture whenever a pan left the
freshest window. Three fixes, all recorded under LOD doc T13:

- Kernel: pyramid-served grids are clamped to the source cells the finest
  level resolves under the window (interaction._pyramid_source_shape,
  ceil(base*frac)+1 per axis) — composing to full screen resolution just
  upsamples blocky cells the client's texture filtering reproduces from
  the source-resolution grid at a fraction of the bytes. The attainable
  per-axis cell size rides the reply as density.min_cell; exact and
  spatial grids (true full-detail bins) omit it. The HAR's 2.7 MB replies
  drop to ~0.5-1.4 MB in its zoom range and ~200 KB deeper.

- Client request elision (lodDensityCacheServes): a cached texture that
  contains the view and is as detailed as anything the kernel could
  return — one texel per screen pixel, or already at min_cell (zooming
  into a source-limited texture cannot sharpen it) — answers with no
  round-trip. Guarded so the kernel stays in charge where it can do
  better: estimated in-view count must exceed budget x
  LOD_DENSITY_ELIDE_EST_FACTOR, and the cached window may be at most
  LOD_DENSITY_ELIDE_MAX_AREA_RATIO x the view area (uniform-density
  estimates overshoot in sparse corners). Entries without recorded
  counts never elide; lodRememberDensity now supersedes an unpinned
  same-window twin so elision always reads current facts.

- Sub-texel request dedup: the identical-request memo compares windows
  numerically within half an output texel per edge (gesture-end and
  settle emit sub-pixel twins; a grid shifted below half a texel is the
  same picture) instead of exact string equality.

- Finer-detail layering (lodDensityDetailForView): when no fine cached
  window contains the view, the smallest cached texture overlapping >= 5%
  of it draws on top of the broad backdrop after every crossfade layer,
  so the already-fetched region stays sharp while the request for the
  rest is in flight — a resolution seam beats uniform blur.

Spec: lod-architecture T13 extended, wire-protocol density_view/density
contracts (min_cell, clamped grids, elision), dossier constants table,
CHANGELOG.

Tests: test_density_wire_economy (source-shape math, min_cell presence/
absence, 20M-point clamp integration), test_density_request_economy
(headless-Chromium probe: source-resolution elision + guards, sub-texel
dedup, fine-over-broad layering).
Comment thread js/src/54_kernel.ts
if (!last || !this._densityRequestSame(last, this._densityRequestWindow(g, view), plotW, plotH)) {
return null;
}
if (last.answered) return last;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Tier Update Leaves Answered Memo

After a request for window W is marked answered, an in-place tier_update can replace the trace data without clearing _lastDensityReq. Returning to W then takes this unbounded answered branch and suppresses the new density request, so the chart can keep rendering a texture built from the old data.

Artifacts

Repro: focused headless-browser pytest harness exercising the real client runtime

  • Evidence file captured while the check ran.

Repro: verbose failing pytest output with answered memo state, in-place tier update, duplicate decision, and request trace

  • The full command output behind this check.

View artifacts

T-Rex Ran code and verified through T-Rex

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.

1 participant