Skip to content

perf: event-driven CDP readiness detection (−55s startup)#1452

Open
lennney wants to merge 1 commit into
BigPizzaV3:mainfrom
lennney:perf/cdp-event-driven-v2
Open

perf: event-driven CDP readiness detection (−55s startup)#1452
lennney wants to merge 1 commit into
BigPizzaV3:mainfrom
lennney:perf/cdp-event-driven-v2

Conversation

@lennney

@lennney lennney commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Replaces the 120×1s polling loop in ensure_injection with three-phase progressive CDP readiness detection. Typical startup drops from ~55s to 0-2s.

Design

Phase Mechanism Time
1 Monitor stderr for DevTools listening on ws:// → immediate injection 2-5s
2 Exponential backoff TCP probe (100ms→10s) up to ~21s
3 1s polling (30 attempts) — original behaviour safety net up to 30s

Phase 1 follows Playwright's Electron launcher pattern (92k★): pipe child stderr, match DevTools signal line. All Chromium-based apps print this when launched with --remote-debugging-port.

Key correctness detail

wait_for_cdp_ready returns Ok(()) only when the magic line is found; EOF returns Err. The spawn calls tx.send(()) only on success. This ensures Phase 1's fast path is genuinely reachable — distinct from EOF / I/O errors.

Also eliminates nested retry: self.inject() internally called retry_injection() (20×500ms), creating a hidden 10s delay. Phases 2 & 3 use try_inject() for a single TCP probe per attempt.

Performance

Metric Before After
Typical startup ~55s ~0-2s
Worst case ~446s ~66s

Test Coverage

4 mock tests for wait_for_cdp_ready:

  • Magic line detection ✅
  • Noise before magic line ✅
  • EOF without magic line → Err ✅
  • Empty stderr → Err ✅

All 64 launcher tests pass.

@BigPizzaV3

Copy link
Copy Markdown
Owner

当前 PR 的 Windows artifacts 检查仍然失败,暂时不能合并。最新 main 已包含 ChatGPT Desktop watcher 相关修复,请先 rebase/merge 最新 main,然后重新运行完整 CI;如果同步后仍失败,请根据失败日志修复并在 PR 中说明根因。合并前需要确保 Windows、macOS x64、macOS arm64 全部通过。

Replaces the 120×1s polling loop with three-phase progressive
detection, cutting typical startup from ~55s to 0-2s.

Phase 1: Monitor stderr for Chrome/Electron's
  'DevTools listening on ws://' signal (Playwright pattern).
  Magic line found → immediate injection attempt via oneshot.

Phase 2: Exponential backoff TCP probing (100ms→10s) for
  packaged apps where stderr is unavailable.

Phase 3: 1s-interval polling (30 attempts) as safety net —
  matches original behaviour.

Also eliminates nested retry: self.inject() called retry_injection
(20×500ms loop), creating a hidden 10s barrier. Phases 2 & 3 now
use try_inject() for a single TCP probe per attempt.

Key design: wait_for_cdp_ready returns Ok(()) ONLY on magic line,
Err on EOF.  The spawn calls tx.send(()) only on success, ensuring
Phase 1 fast path is genuinely reachable (distinct from EOF).
4 mock tests cover detection, noise tolerance, EOF, and empty input.
@lennney lennney force-pushed the perf/cdp-event-driven-v2 branch from 68cf7b7 to 63e337d Compare July 13, 2026 08:51
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.

2 participants