Skip to content

Commit c8c44a0

Browse files
thymikeeclaude
andcommitted
refactor(ios): keep the runner journal vocabulary in runner-session-types
The journal states and terminal-evidence settlement moved to a new module that the Apple facade entries now evaluated eagerly through runner-lifecycle -> runner-command-recovery, growing their closures. They live beside RunnerCommandAccounting in runner-session-types.ts, which those entries already evaluate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent eb197e9 commit c8c44a0

4 files changed

Lines changed: 39 additions & 39 deletions

File tree

‎packages/platform-apple/src/runner/runner-command-journal.ts‎

Lines changed: 0 additions & 36 deletions
This file was deleted.

‎packages/platform-apple/src/runner/runner-command-recovery.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { RUNNER_REPLY_LOST_REASON } from './runner-error-classification.ts';
1515
import {
1616
RUNNER_IN_FLIGHT_LIFECYCLE_STATES,
1717
settleRunnerChargeForTerminalStatus,
18-
} from './runner-command-journal.ts';
18+
} from './runner-session-types.ts';
1919
import type { AppleRunnerCommandOptions } from './runner-provider.ts';
2020
import { executeRunnerCommandWithSession, type RunnerSession } from './runner-session.ts';
2121

‎packages/platform-apple/src/runner/runner-exchange.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ import {
3232
enrichRunnerFailureFromLog,
3333
type RunnerLogAttempt,
3434
} from './runner-failure-diagnostics.ts';
35-
import { advanceRunnerSessionState, type RunnerSession } from './runner-session-types.ts';
3635
import {
36+
advanceRunnerSessionState,
3737
RUNNER_IN_FLIGHT_LIFECYCLE_STATES,
3838
settleRunnerChargeForTerminalStatus,
39-
} from './runner-command-journal.ts';
39+
type RunnerSession,
40+
} from './runner-session-types.ts';
4041

4142
type RunnerExchangeSession = RunnerConnectionSession &
4243
Pick<

‎packages/platform-apple/src/runner/runner-session-types.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Deadline } from './host.ts';
55
import type { RunnerXctestrunArtifact } from './runner-xctestrun.ts';
66
import type { RunnerLease } from './runner-lease.ts';
77
import type { IosRunnerDeviceStates } from './runner-error-classification.ts';
8+
import type { RunnerCommand } from './runner-contract.ts';
89

910
/**
1011
* Where one runner process stands in the lifecycle of the session that owns it (#2662). The state
@@ -321,6 +322,40 @@ export class RunnerCommandAccounting {
321322
}
322323
}
323324

325+
/**
326+
* The runner journal vocabulary, so charge settlement, status recovery, and the drain of a canceled
327+
* command cannot disagree about what a state means. `runner-swift-settlement-fixtures.ts` pins these
328+
* names to `RunnerCommandLifecycleState`, and the recovery wiring rows are derived from that same
329+
* declaration, so a state the runner gains has to be ruled here before it can decide a handoff.
330+
*
331+
* `completed` and `failed` close an entry — from the response's `ok` in `finish`, or a thrown error in
332+
* `fail` — so execution ended. `accepted` and `started` are written as execution opens, so they share
333+
* one in-flight verdict. `notAccepted` is what `status` reports for an id the journal never held,
334+
* which this daemon cannot read as terminal.
335+
*/
336+
const RUNNER_TERMINAL_LIFECYCLE_STATES: ReadonlySet<string> = new Set(['completed', 'failed']);
337+
export const RUNNER_IN_FLIGHT_LIFECYCLE_STATES: ReadonlySet<string> = new Set([
338+
'accepted',
339+
'started',
340+
]);
341+
342+
/**
343+
* Discharges the abandoned charge terminal status proves landed (#2965). A status reply is served
344+
* inline, so it is no evidence that queued work finished; this is the only place a status answer may
345+
* settle a charge, and only the one its `statusCommandId` names.
346+
*
347+
* @returns whether the evidence paid a debt, or `undefined` when the state is not terminal and no
348+
* settlement was attempted.
349+
*/
350+
export function settleRunnerChargeForTerminalStatus(
351+
session: Pick<RunnerSession, 'commandCharges'>,
352+
command: Pick<RunnerCommand, 'commandId'>,
353+
lifecycleState: string,
354+
): boolean | undefined {
355+
if (!RUNNER_TERMINAL_LIFECYCLE_STATES.has(lifecycleState)) return undefined;
356+
return session.commandCharges.settleTerminalEvidence(command.commandId);
357+
}
358+
324359
/** Ids match exactly as sent. */
325360
function normalizeRunnerChargeId(commandId: string | undefined): string {
326361
return commandId?.trim() ?? '';

0 commit comments

Comments
 (0)