fix(apple-runner): recycle lost-listener runner and restart on ready-session early exit

KH
4d ago
+305-74

Summary

Fixes #5276. When the iOS runner app dies (listener socket closed) while xcodebuild stays alive, isRunnerSessionServing previously only checked session state and xcodebuild PID, reusing the dead runner and failing with xcodebuild exited early.

  • packages/apple-runner/src/runner-session.ts: refuse to reuse sessions with listenerWatch?.lost via stopInvalidatedSession.
  • packages/apple-runner/src/runner-error-classification.ts & runner-lifecycle.ts: allow xcodebuild_exited_early to restart before send when the session was already ready at entry.
  • packages/apple-runner/src/runner-session-types.ts: moved normalizeRunnerLogicalLeaseContext to keep files under 1000 lines.

Before / after

  • Before: a command after SpringBoard kills the runner app reuses the session with listenerWatch.lost = true and fails with COMMAND_FAILED (xcodebuild_exited_early).
  • After: ensureRunnerSession invalidates and stops the lost-listener session to start a fresh runner; an already-ready session that hits xcodebuild_exited_early before send restarts and replays.

Validation

Tested at 1024e4694d on 59a640c08d:

  • vitest run on runner-error-classification, runner-lifecycle-readiness-preflight, runner-session-lifecycle: 3 files, 83 tests passed.
  • tsc -b tsconfig.typecheck.json examples/sdk/tsconfig.json: passed.
  • oxlint . --deny-warnings: 0 warnings, 0 errors.

CI obligations: full unit, Apple smoke, and repo-guard lanes. Risks: none known.