← Back to Pull requests

[History Server] Cache snapshot struct in the session LRU instead of JSON bytes #5208

Closed
unknown closed this pull request without merging on Sep 11, 2026 19:36 UTC
View on GitHub
unknown unknown commented on Aug 28, 2026 07:18 UTC
Author

Why are these changes needed?

SessionLoader cached dead-session snapshots as JSON bytes and ran json.Unmarshal on every GetSnapshot call, so each HTTP request paid a full decode and allocated a complete new SessionSnapshot. This PR stores the SessionSnapshot struct directly and returns the shared pointer, making the read path zero-decode / zero-alloc.

Changes:

  • SessionLoader:

  • - LRU now holds cacheEntry{snap, size}
    - putSnapshot marshals once only to estimate size for the byte budget.
    - GetSnapshot returns the cached pointer.
  • size held in cacheEntry is the marshaled JSON size * sessionSnapshotHeapFactor (2.5). The value is based on the discussion here https://github.com/ray-project/kuberay/pull/5208#discussion_r3890261932

  • Snapshots are now shared across requests and must be treated as immutable (documented on SessionSnapshot and GetSnapshot).

  • utils.ApplyTaskFilters: This was the only consumer that mutated the snapshot in place. Updated to clone before sorting.
  • Benchmark

  • Before: on master branch

  • After: this branch
  • Columns:

  • n: snapshot size -> n tasks, n actors, and n log events

  • ns/op time (ns) per operation (lower is better)

  • B/op heap bytes allocated per op (lower is better)

  • allocs/op heap allocations per op (lower is better)
  • Read path (GetSnapshot, one HTTP request)

  • Read cost is now O(1) regardless of snapshot size
  • | n | ns/op before | ns/op after | B/op before | B/op after | allocs/op before | allocs/op after |
    |---|---|---|---|---|---|---|
    | 100 | 605.5k | 140 | 354.0k | 0 | 5.6k | 0 |
    | 1000 | 5.8M | 140 | 3.7M | 0 | 55.1k | 0 |
    | 10000 | 57.6M | 140 | 45.9M | 0 | 550.2k | 0 |

    Write path (putSnapshot, one cold load)

  • No meaningful change, as we still need to encode to get the size
  • | n | ns/op before | ns/op after | B/op before | B/op after | allocs/op before | allocs/op after |
    |---|---|---|---|---|---|---|
    | 100 | 239.0k | 231.9k | 215.4k | 215.4k | 2.6k | 2.6k |
    | 1000 | 2.4M | 2.3M | 2.1M | 2.1M | 26.0k | 26.0k |
    | 10000 | 24.2M | 22.9M | 21.8M | 21.7M | 260.0k | 260.0k |

    Related issue number

    <!-- For example: "Closes #1234" -->

    Labels

    <!-- Please add the appropriate labels to this PR. -->

  • If this PR has user-facing changes that require documentation updates at release time, I have added the doc-updates-required label.

  • If this PR contains breaking changes, I have added the breaking-change label.
  • Checks

  • I've made sure the tests are passing.

  • Testing Strategy

  • - [x] Unit tests
    - [ ] Manual tests
    - [ ] This PR is not tested :(

    <!-- If you selected "Manual tests" above, please fill in the section below. Otherwise you can remove it. -->

    Manual test instructions

    <!--
    Provide step-by-step instructions so reviewers can verify your changes.
    Include any relevant screenshots or logs demonstrating the behavior.
    -->

    Diff: 375 lines (+281 / -94) across 4 files Reviewer: chiayi Review duration: 20897m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 375 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.355
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #5208"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.9% (MEDIUM) · Higher = larger blast radius
    42.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.9% · Safe to merge
    16.9%