11import { AppError } from '@agent-device/kernel/errors' ;
22import type { DeviceInfo } from '@agent-device/kernel/device' ;
33import { Deadline , emitDiagnostic , withDiagnosticTimer } from './host.ts' ;
4- import { waitForRunner , RUNNER_STARTUP_TIMEOUT_MS } from './runner-startup-transport.ts' ;
4+ import {
5+ waitForRunner ,
6+ RUNNER_STARTUP_TIMEOUT_MS ,
7+ type RunnerConnectionSession ,
8+ } from './runner-startup-transport.ts' ;
59import { sendRunnerCommandOnce } from './runner-transport.ts' ;
610import {
711 buildRunnerResponseError ,
@@ -29,6 +33,12 @@ import {
2933} from './runner-failure-diagnostics.ts' ;
3034import { advanceRunnerSessionState , type RunnerSession } from './runner-session-types.ts' ;
3135
36+ type RunnerExchangeSession = RunnerConnectionSession &
37+ Pick <
38+ RunnerSession ,
39+ 'port' | 'commandCharges' | 'lastHealthyMutation' | 'runnerMainThreadBusy' | 'launchDeadline'
40+ > ;
41+
3242const RUNNER_READY_PREFLIGHT_TIMEOUT_MS = 1_000 ;
3343const RUNNER_PREFLIGHT_SKIP_FRESHNESS_MS = 5_000 ;
3444
@@ -63,7 +73,7 @@ type RunnerReadinessPreflightDecision =
6373 */
6474export async function executeRunnerExchange (
6575 device : DeviceInfo ,
66- session : RunnerSession ,
76+ session : RunnerExchangeSession ,
6777 command : RunnerCommand ,
6878 logPath : string | undefined ,
6979 timeoutMs : number ,
@@ -137,7 +147,7 @@ export async function executeRunnerExchange(
137147 * runner's occupancy report, and applies what the payload says about the session.
138148 */
139149async function settleRunnerAnsweredExchange (
140- session : RunnerSession ,
150+ session : RunnerExchangeSession ,
141151 runnerCommand : RunnerCommand ,
142152 data : Record < string , unknown > ,
143153 invalidateFatalSession : ( reason : string ) => Promise < void > ,
@@ -169,7 +179,7 @@ async function settleRunnerAnsweredExchange(
169179 * runner answered it.
170180 */
171181function recordUnansweredRunnerExchange (
172- session : RunnerSession ,
182+ session : RunnerExchangeSession ,
173183 runnerCommand : RunnerCommand ,
174184 error : unknown ,
175185) : boolean {
@@ -199,7 +209,7 @@ function readRunnerMainThreadBusy(data: Record<string, unknown>): boolean | unde
199209
200210function markSkippedPreflightTransportError (
201211 error : unknown ,
202- session : RunnerSession ,
212+ session : RunnerExchangeSession ,
203213 preflightDecision : RunnerReadinessPreflightDecision ,
204214) : unknown {
205215 if (
@@ -218,7 +228,7 @@ function markSkippedPreflightTransportError(
218228
219229async function sendRunnerCommandAfterPreflight ( params : {
220230 device : DeviceInfo ;
221- session : RunnerSession ;
231+ session : RunnerExchangeSession ;
222232 runnerCommand : RunnerCommand ;
223233 logPath : string | undefined ;
224234 deadline : Deadline ;
@@ -282,7 +292,7 @@ async function sendRunnerCommandAfterPreflight(params: {
282292
283293async function runRunnerReadinessPreflight ( params : {
284294 device : DeviceInfo ;
285- session : RunnerSession ;
295+ session : RunnerExchangeSession ;
286296 runnerCommand : RunnerCommand ;
287297 logAttempt : RunnerLogAttempt | undefined ;
288298 deadline : Deadline ;
@@ -325,7 +335,7 @@ async function runRunnerReadinessPreflight(params: {
325335
326336function emitRunnerReadinessPreflightSkipped (
327337 runnerCommand : RunnerCommand ,
328- session : RunnerSession ,
338+ session : RunnerExchangeSession ,
329339 decision : Extract < RunnerReadinessPreflightDecision , { action : 'skip' } > ,
330340) : void {
331341 emitDiagnostic ( {
@@ -392,7 +402,7 @@ function resolveRunnerFatalReason(data: Record<string, unknown>): string | undef
392402}
393403
394404function resolveRunnerReadinessPreflightDecision (
395- session : RunnerSession ,
405+ session : RunnerExchangeSession ,
396406 command : RunnerCommand ,
397407) : RunnerReadinessPreflightDecision {
398408 const readOnlyCommand = isReadOnlyRunnerCommand ( command ) ;
0 commit comments