[1/N] [History Server Beta] [Feat] Lazy loading #4795
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #4795"
general
weight: 0.35
JiangJiaWei1103
Why are these changes needed?
Alpha Problems
EventHandlerre-parsed all raw events every hour (bounded byO(#sessions))Process restart wiped all in-memory maps and the next startup repeated the entire warm-up cycle.
Beta Strategy
In this PR, we remove startup processing/ticker and introduce lazy loading to process raw events on user requests and records processed dead sessions in in-memory maps (inherited from alpha).
Overview
System Architecture
``
┌──────────────────┐
│ Dashboard UI │ ◄── user browser
└────────┬─────────┘
│ HTTP
▼
┌──────────────────┐
│ Load Balancer │
└────────┬─────────┘
│
▼
┌── Ray Cluster ────────┐ ┌── History Server (replicas, single binary) ─────┐
│ │ │ │
│ Head pod │ │ HTTP Router │
│ ray-head+collector │ │ /enter_cluster (blocking on dead) │
│ │ │ │ │ │
│ │ │ │ ▼ │
│ │ │ │ SessionLoader │
│ │ │ │ (singleflight + loaded set) │
│ │ raw │ │ │ │
│ │ events │ │ ┌─┴──────────┐ │
│ │ (PUT) │ │ ▼ ▼ │
│ ▼ │ │ EventHandler SessionProcessor ── isDead? (RayCluster) ┼──┐
└───────────┼───────────┘ │ in-mem maps (parse only) HTTPLiveSessionResolver │
│ │ (Tasks/ │ │ ▼
│ │ Actors/ │ ProcessSingleSession │ ┌─────────┐
│ │ Jobs/ │ (writes events into maps) │ │ K8s │
│ │ Nodes/ │ │ │ API │
│ │ LogEvents) │ │ └─────────┘
│ │ ▲ │ │
│ │ └───────────┘ │
│ └─────────────────────────────────────────────────┘
│ ▲
▼ │ raw events (GET)
┌──────────────────────────────────────────────────────────┐
│ Object Storage (S3 / GCS / Azure / Aliyun OSS) │
│ │
│ {rootDir}/{cluster}_{ns}/{session}/ │
│ node_events/, job_events/, logs/, fetched_endpoints/ │
└──────────────────────────────────────────────────────────┘
mermaid
sequenceDiagram
actor User as Winner
actor User2 as Follower
participant HS as HS handler
participant Loader as SessionLoader (singleflight + loaded set)
participant Proc as SessionProcessor
participant Resolver as HTTPLiveSessionResolver
participant K8s as K8s API
participant Dash as Ray Dashboard
participant S3 as Object Storage
participant EH as EventHandler maps
User->>HS: GET /enter_cluster (cold, dead session)
User2->>HS: GET /enter_cluster (concurrent, same session)
HS->>Loader: LoadSession (winner)
HS->>Loader: LoadSession (follower)
Note over Loader: same singleflight key →<br/>follower joins winner's group
Loader->>Loader: loaded set check → not found
Loader->>Proc: ProcessSession(serverCtx)
Note over Proc,Loader: serverCtx (NOT reqCtx) —<br/>winner disconnect cannot cancel<br/>work followers still depend on
Proc->>K8s: Get RayCluster
alt CR NotFound
K8s-->>Proc: NotFound → dead
else CR exists
K8s-->>Proc: RayCluster (Status.Head.ServiceName set)
Proc->>Resolver: FetchSessionName(ns, headSvcName)
Resolver->>Dash: GET /api/version
Dash-->>Resolver: { session_name: "<live_session>" }
Resolver-->>Proc: "<live_session>"
Note over Proc: queried != live → dead
end
Proc->>S3: List + GET event files
Proc->>EH: ProcessSingleSession (writes into Tasks/Actors/Jobs/Nodes/LogEvents)
Proc-->>Loader: SessionStatusProcessed, nil
Loader->>Loader: mark session in loaded set
Loader-->>HS: nil (winner)
Loader-->>HS: nil (follower, shared result)
HS-->>User: 200 OK
HS-->>User2: 200 OK
Note over User,EH: subsequent /api/v0/* calls read from EventHandler maps directly<br/>repeat /enter_cluster returns immediately via loaded set fast-path<br/>(no re-parse on this replica)
bashecho "=== Build ===" && \
go build -o /tmp/hs-bin ./cmd/historyserver/ && rm -f /tmp/hs-bin && echo "BUILD OK"
echo && echo "=== Vet ===" && go vet ./... && echo "VET OK"
Directly affected packages
echo && echo "=== Tests in packages touched by this PR (must PASS) ===" && \
go test -race -cover ./pkg/historyserver/...
Verbose run of NEW tests added by this PR
echo && echo "=== New tests (verbose) ===" && \
go test -race -v -run "TestEnsure_PipelineError" ./pkg/historyserver/
echo && echo "=== eventserver tests (must PASS) ===" && \
go test -race ./pkg/eventserver/types/... && \
go test -race ./pkg/eventserver/ 2>&1 | tail -5 || true
``
Checks
- [x] Unit tests
- [x] Manual tests
- [ ] This PR is not tested :(