Skip to content

fix(mcp): harden Chrome timeline renderer timeouts, pixel cap, and warm session reuse - #1316

Open
kyasbal wants to merge 2 commits into
push-zxtpyqnnnxrrfrom
push-yyqtuxrlvmvt
Open

kyasbal wants to merge 2 commits into
push-zxtpyqnnnxrrfrom
push-yyqtuxrlvmvt

Conversation

@kyasbal

@kyasbal kyasbal commented Dec 1, 2026

Copy link
Copy Markdown
Member

Summary

Part 3/5 of the render_timelines visual clarity, evidence manifest, and khi-investigation skill stack.

  • Raises defaultTimelineRenderTimeout to 120s so cold large-inspection loads and annotated SwiftShader renders complete reliably.
  • Caps total 2x Retina backing-store area at 16M physical pixels (maxTimelinePhysicalPixels), cleanly falling back to 1x scale on oversized wide/tall scenes.
  • Short-circuits screenshot capture when measure.RenderedCount == 0.
  • Probes and reuses the warm /render/mcp-timeline CDP page across non-transport failures instead of tearing down and re-navigating unnecessarily.
  • Extracts realistic headless browser E2E tests into pkg/server/mcp/timeline_renderer_e2e_test.go and hardens deterministic mock CDP unit tests in pkg/server/mcp/timeline_renderer_test.go.

Stack

  1. fix(workbench): exempt KHI synthetic IDs, globs, and K8s refs in validate_report (main <- push-qylzxxkzxpry)
  2. feat(mcp): unify annotation string IDs, fix subtree highlights, and emit resolved evidence manifest (push-qylzxxkzxpry <- push-zxtpyqnnnxrr)
  3. This PR: fix(mcp): harden Chrome timeline renderer timeouts, pixel cap, and warm session reuse (push-zxtpyqnnnxrr <- push-yyqtuxrlvmvt)
  4. feat(web): improve static timeline export clarity, leader routing, and inspection caching (push-yyqtuxrlvmvt <- push-yowxrnppozmk)
  5. feat(skills): guide visual-first two-layer reporting in khi-investigation skill #1313: feat(skills): guide visual-first two-layer reporting in khi-investigation skill (push-yowxrnppozmk <- push-nywmlvytopkk)

Verification

  • go test -race ./pkg/server/mcp/... — PASS
  • make qa-fast-must QA_LANG=go — PASS (0 mustfix, 0 advisory, 0 skipped)
  • make lint-go — PASS (0 issues)

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request optimizes the timeline renderer by increasing the render timeout, capping the total backing store pixel area, and returning early when there are no rendered timelines. It also improves resilience by reconnecting and probing the bridge state on transport errors instead of unconditionally reloading. A new end-to-end test suite has been added to verify these behaviors. The review feedback identifies a critical issue where the renderer can get stuck in a permanently broken state if the page reloads while the CDP connection remains open, and suggests probing the bridge even when r.pageReady is true to recover gracefully.

Comment on lines +169 to 171
if r.pageReady {
return nil
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

If the frontend page navigates away or reloads (e.g., due to memory pressure or a frontend bug) while the CDP connection remains open, r.pageReady remains true. However, the bridge (window.__khiCDPBridge) will be undefined or uninitialized.

When RenderTimeline is called in this state:

  1. ensurePageReadyLocked returns nil immediately because r.pageReady is true.
  2. executeRenderLocked fails with a non-transport JavaScript evaluation error (e.g., TypeError: Cannot read properties of undefined).
  3. Since it is a non-transport error, closeLocked() is not called, and r.pageReady remains true.
  4. All subsequent render requests will fail with the same error indefinitely, leaving the renderer in a permanently broken state.

To prevent this, we should probe the bridge even when r.pageReady is true. If the probe fails, we reset the state and re-initialize the page.

	if r.pageReady {
		ready, err := r.probeBridgeReadyLocked(ctx)
		if err == nil && ready {
			return nil
		}
		_ = r.closeLocked()
	}
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Go Quality Report (origin/push-zxtpyqnnnxrr) — ✅ PASS

Metric Result
Changed Scope 1 prod file(s), 2 test file(s), 20 unit(s)
Patch Coverage 100.0% (34/34 lines)
Mutation Score 100.0% (18/18 killed, 0 survived)
Function Similarity OK (1 new unit(s), 0 matches across 3222 corpus units)

Commit: b6e7d5fc1881 · Cloud Build Logs

@kyasbal
kyasbal added this pull request to stack #1322 December 1, 2026 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant