Tracked by #713.
Background
Web Inspector socket discovery can run lsof, ps, and filesystem scans repeatedly during proxy startup. This is valid work, but repeated discovery increases startup latency.
Objective
Reduce repeated socket discovery cost while preserving correctness for booted simulator selection.
Scope
- Add short TTL cache for UDID-to-socket path results.
- Invalidate cache after failed socket probe.
- Use exponential or staged backoff during wait loops.
- Keep existing lsof and mtime fallback behavior.
Target files and paths
src/simulator/socket-finder.ts
src/simulator/proxy.ts
tests/unit/socket-finder.test.ts
tests/unit/proxy-timing.test.ts if proxy wait behavior changes
Implementation steps
- Add a cache keyed by target UDID and no-target lookup separately.
- Store only socket paths that pass
probeSocket.
- Invalidate cached path on failed probe.
- Replace fixed 500ms retry with staged backoff.
- Add tests for cache hit, stale cache invalidation, and no-target behavior.
Acceptance criteria
Verification
npm run lint -- --quiet
npm test -- --runInBand tests/unit/socket-finder.test.ts
- Manual macOS smoke: boot simulator, start proxy twice, confirm second discovery is faster or avoids repeated expensive commands in debug logs.
Dependencies / recommended order
Run after proxy readiness split if both touch startup timing. This issue is independent of HTTP/security work.
Risks and cautions
- Do not return unprobed socket paths from cache.
- Do not cache failures for so long that newly booted simulators are missed.
- Do not delete stale sockets unless they were explicitly probed stale.
Non-goals
- Do not change proxy port allocation.
- Do not replace lsof fallback entirely.
- Do not introduce platform support beyond macOS/Xcode simulator needs.
Ambiguity reducers
- “Cache hit” requires a live probe success within the TTL.
- “Backoff” must still respect the configured overall timeout.
- Target-specific and target-agnostic cache entries are separate.
Validity review
Proceed as a focused speed issue. It supports startup responsiveness without changing automation semantics.
Implementation detail refinements
- Make TTL configurable for tests.
- Keep cache in module or finder instance with a reset hook for tests.
- Expose debug counters only in tests or verbose logs.
Verification checklist reinforcement
Tracked by #713.
Background
Web Inspector socket discovery can run
lsof,ps, and filesystem scans repeatedly during proxy startup. This is valid work, but repeated discovery increases startup latency.Objective
Reduce repeated socket discovery cost while preserving correctness for booted simulator selection.
Scope
Target files and paths
src/simulator/socket-finder.tssrc/simulator/proxy.tstests/unit/socket-finder.test.tstests/unit/proxy-timing.test.tsif proxy wait behavior changesImplementation steps
probeSocket.Acceptance criteria
Verification
npm run lint -- --quietnpm test -- --runInBand tests/unit/socket-finder.test.tsDependencies / recommended order
Run after proxy readiness split if both touch startup timing. This issue is independent of HTTP/security work.
Risks and cautions
Non-goals
Ambiguity reducers
Validity review
Proceed as a focused speed issue. It supports startup responsiveness without changing automation semantics.
Implementation detail refinements
Verification checklist reinforcement
lsofin unit test mock.