@evalops/maestro 0.10.43 → 0.10.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +46 -1
- package/dist/node_modules/@evalops/contracts/package.json +1 -1
- package/dist/node_modules/@evalops/tui/package.json +1 -1
- package/dist/server/handlers/hosted-runner-drain.d.ts +28 -0
- package/dist/server/handlers/hosted-runner-drain.d.ts.map +1 -1
- package/dist/server/handlers/hosted-runner-drain.js +55 -2
- package/dist/server/handlers/hosted-runner-drain.js.map +1 -1
- package/dist/version.json +2 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -166271,6 +166271,28 @@ function buildHostedRunnerRetentionPolicy() {
|
|
|
166271
166271
|
}
|
|
166272
166272
|
};
|
|
166273
166273
|
}
|
|
166274
|
+
function buildHostedRunnerRuntimeContinuity(input) {
|
|
166275
|
+
return {
|
|
166276
|
+
protocol_version: HOSTED_RUNNER_RUNTIME_CONTINUITY_VERSION,
|
|
166277
|
+
handoff: "drain_restore",
|
|
166278
|
+
source_runner_session_id: input.hostedRunner.runnerSessionId,
|
|
166279
|
+
...input.hostedRunner.ownerInstanceId ? { source_owner_instance_id: input.hostedRunner.ownerInstanceId } : {},
|
|
166280
|
+
source_process_id: process.pid,
|
|
166281
|
+
source_runtime_lease: {
|
|
166282
|
+
protocol_version: HOSTED_RUNNER_LEASE_PROTOCOL_VERSION,
|
|
166283
|
+
state: input.leaseSnapshot.state,
|
|
166284
|
+
generation: input.leaseSnapshot.generation,
|
|
166285
|
+
...input.leaseSnapshot.maestroSessionId ? { maestro_session_id: input.leaseSnapshot.maestroSessionId } : {},
|
|
166286
|
+
updated_at: input.leaseSnapshot.updatedAt
|
|
166287
|
+
},
|
|
166288
|
+
restore_environment_key: "MAESTRO_REMOTE_RUNNER_RESTORE_MANIFEST",
|
|
166289
|
+
restore_manifest_path: input.manifestPath,
|
|
166290
|
+
evidence_refs: [
|
|
166291
|
+
`remote-runner://sessions/${input.hostedRunner.runnerSessionId}/drain#snapshot`,
|
|
166292
|
+
`maestro://headless/sessions/${input.maestroSessionId}#cursor:${input.runtime.cursor ?? 0}`
|
|
166293
|
+
]
|
|
166294
|
+
};
|
|
166295
|
+
}
|
|
166274
166296
|
function buildHostedRunnerPlatformEvidence(input) {
|
|
166275
166297
|
const edges = input.workContinuity.codex_subagent_edges ?? [];
|
|
166276
166298
|
return {
|
|
@@ -166302,6 +166324,18 @@ function buildHostedRunnerPlatformEvidence(input) {
|
|
|
166302
166324
|
codex_subagent_thread_ids: input.workContinuity.codex_subagent_thread_ids,
|
|
166303
166325
|
...edges.length > 0 ? { codex_subagent_edges: edges } : {}
|
|
166304
166326
|
},
|
|
166327
|
+
runtime_continuity: {
|
|
166328
|
+
protocol_version: input.runtimeContinuity.protocol_version,
|
|
166329
|
+
handoff: input.runtimeContinuity.handoff,
|
|
166330
|
+
...input.runtimeContinuity.source_owner_instance_id ? {
|
|
166331
|
+
source_owner_instance_id: input.runtimeContinuity.source_owner_instance_id
|
|
166332
|
+
} : {},
|
|
166333
|
+
source_process_id: input.runtimeContinuity.source_process_id,
|
|
166334
|
+
...input.runtimeContinuity.source_runtime_lease ? {
|
|
166335
|
+
source_runtime_lease_generation: input.runtimeContinuity.source_runtime_lease.generation
|
|
166336
|
+
} : {},
|
|
166337
|
+
restore_manifest_path: input.runtimeContinuity.restore_manifest_path
|
|
166338
|
+
},
|
|
166305
166339
|
retention: {
|
|
166306
166340
|
policy_version: input.retentionPolicy.policy_version,
|
|
166307
166341
|
control_plane_metadata_visibility: input.retentionPolicy.visibility.control_plane_metadata,
|
|
@@ -166439,7 +166473,7 @@ async function drainHostedRunner(input, options) {
|
|
|
166439
166473
|
return null;
|
|
166440
166474
|
}
|
|
166441
166475
|
const requestedAtDate = options.now?.() ?? /* @__PURE__ */ new Date();
|
|
166442
|
-
markHostedRunnerLeaseDraining(hostedRunner, requestedAtDate);
|
|
166476
|
+
const leaseSnapshot = markHostedRunnerLeaseDraining(hostedRunner, requestedAtDate);
|
|
166443
166477
|
const requestedAt = requestedAtDate.toISOString();
|
|
166444
166478
|
const workspaceRoot = await resolveWorkspaceRoot2(hostedRunner);
|
|
166445
166479
|
const snapshotRoot = resolve54(workspaceRoot, hostedRunner.snapshotRoot ?? ".maestro/runner-snapshots");
|
|
@@ -166495,6 +166529,13 @@ async function drainHostedRunner(input, options) {
|
|
|
166495
166529
|
const snapshot = runtimeSnapshot ?? buildHostedRunnerSnapshot(maestroSessionId, workspaceRoot, runtime);
|
|
166496
166530
|
const workContinuity = collectHostedRunnerWorkContinuity(snapshot);
|
|
166497
166531
|
const retentionPolicy = buildHostedRunnerRetentionPolicy();
|
|
166532
|
+
const runtimeContinuity = buildHostedRunnerRuntimeContinuity({
|
|
166533
|
+
hostedRunner,
|
|
166534
|
+
maestroSessionId,
|
|
166535
|
+
manifestPath: snapshotPath,
|
|
166536
|
+
runtime,
|
|
166537
|
+
leaseSnapshot
|
|
166538
|
+
});
|
|
166498
166539
|
const platformEvidence = buildHostedRunnerPlatformEvidence({
|
|
166499
166540
|
hostedRunner,
|
|
166500
166541
|
status,
|
|
@@ -166502,6 +166543,7 @@ async function drainHostedRunner(input, options) {
|
|
|
166502
166543
|
createdAt: requestedAt,
|
|
166503
166544
|
manifestPath: snapshotPath,
|
|
166504
166545
|
runtime,
|
|
166546
|
+
runtimeContinuity,
|
|
166505
166547
|
workContinuity,
|
|
166506
166548
|
retentionPolicy,
|
|
166507
166549
|
reason: input.reason,
|
|
@@ -166522,6 +166564,7 @@ async function drainHostedRunner(input, options) {
|
|
|
166522
166564
|
mode: "local_path_contract",
|
|
166523
166565
|
paths: exportPaths
|
|
166524
166566
|
},
|
|
166567
|
+
runtime_continuity: runtimeContinuity,
|
|
166525
166568
|
work_continuity: workContinuity,
|
|
166526
166569
|
platform_evidence: platformEvidence,
|
|
166527
166570
|
snapshot,
|
|
@@ -166553,6 +166596,7 @@ async function drainHostedRunner(input, options) {
|
|
|
166553
166596
|
createdAt: requestedAt,
|
|
166554
166597
|
manifestPath: snapshotPath,
|
|
166555
166598
|
runtime,
|
|
166599
|
+
runtimeContinuity,
|
|
166556
166600
|
workContinuity,
|
|
166557
166601
|
retentionPolicy,
|
|
166558
166602
|
reason: input.reason,
|
|
@@ -166661,6 +166705,7 @@ var HOSTED_RUNNER_SNAPSHOT_MANIFEST_VERSION = "evalops.remote-runner.snapshot-ma
|
|
|
166661
166705
|
var HOSTED_RUNNER_RETENTION_POLICY_VERSION = "evalops.remote-runner.retention.v1";
|
|
166662
166706
|
var HOSTED_RUNNER_WORK_CONTINUITY_VERSION = "evalops.remote-runner.work-continuity.v1";
|
|
166663
166707
|
var HOSTED_RUNNER_PLATFORM_EVIDENCE_VERSION = "evalops.remote-runner.platform-evidence.v1";
|
|
166708
|
+
var HOSTED_RUNNER_RUNTIME_CONTINUITY_VERSION = "evalops.remote-runner.runtime-continuity.v1";
|
|
166664
166709
|
var HostedRunnerRuntimeDrainError;
|
|
166665
166710
|
var init_hosted_runner_drain = __esm2(() => {
|
|
166666
166711
|
init_headless_protocol();
|
|
@@ -2,12 +2,14 @@ import type { IncomingMessage, ServerResponse } from "node:http";
|
|
|
2
2
|
import { CODEX_SUBAGENT_WORK_GRAPH_SCHEMA, type HeadlessCodexSubagentContinuityEdge } from "../../cli/headless-protocol.js";
|
|
3
3
|
import type { HostedRunnerContext, WebServerContext } from "../app-context.js";
|
|
4
4
|
import type { HeadlessRuntimeSnapshot } from "../headless-runtime-service.js";
|
|
5
|
+
import { HOSTED_RUNNER_LEASE_PROTOCOL_VERSION, type HostedRunnerLeaseSnapshot } from "../hosted-runner-lease.js";
|
|
5
6
|
export declare const HOSTED_RUNNER_DRAIN_PATH = "/.well-known/evalops/remote-runner/drain";
|
|
6
7
|
export declare const HOSTED_RUNNER_DRAIN_PROTOCOL_VERSION = "evalops.remote-runner.drain.v1";
|
|
7
8
|
export declare const HOSTED_RUNNER_SNAPSHOT_MANIFEST_VERSION = "evalops.remote-runner.snapshot-manifest.v1";
|
|
8
9
|
export declare const HOSTED_RUNNER_RETENTION_POLICY_VERSION = "evalops.remote-runner.retention.v1";
|
|
9
10
|
export declare const HOSTED_RUNNER_WORK_CONTINUITY_VERSION = "evalops.remote-runner.work-continuity.v1";
|
|
10
11
|
export declare const HOSTED_RUNNER_PLATFORM_EVIDENCE_VERSION = "evalops.remote-runner.platform-evidence.v1";
|
|
12
|
+
export declare const HOSTED_RUNNER_RUNTIME_CONTINUITY_VERSION = "evalops.remote-runner.runtime-continuity.v1";
|
|
11
13
|
export declare enum HostedRunnerDrainStatusValue {
|
|
12
14
|
Drained = "drained",
|
|
13
15
|
Interrupted = "interrupted"
|
|
@@ -94,6 +96,7 @@ export interface HostedRunnerSnapshotManifest {
|
|
|
94
96
|
mode: HostedRunnerWorkspaceExportMode;
|
|
95
97
|
paths: HostedRunnerWorkspaceExportPath[];
|
|
96
98
|
};
|
|
99
|
+
runtime_continuity: HostedRunnerRuntimeContinuity;
|
|
97
100
|
work_continuity: HostedRunnerWorkContinuity;
|
|
98
101
|
platform_evidence: HostedRunnerPlatformEvidence;
|
|
99
102
|
snapshot: HeadlessRuntimeSnapshot;
|
|
@@ -104,6 +107,23 @@ export interface HostedRunnerSnapshotManifest {
|
|
|
104
107
|
dirty?: boolean;
|
|
105
108
|
};
|
|
106
109
|
}
|
|
110
|
+
export interface HostedRunnerRuntimeContinuity {
|
|
111
|
+
protocol_version: typeof HOSTED_RUNNER_RUNTIME_CONTINUITY_VERSION;
|
|
112
|
+
handoff: "drain_restore";
|
|
113
|
+
source_runner_session_id: string;
|
|
114
|
+
source_owner_instance_id?: string;
|
|
115
|
+
source_process_id: number;
|
|
116
|
+
source_runtime_lease?: {
|
|
117
|
+
protocol_version: typeof HOSTED_RUNNER_LEASE_PROTOCOL_VERSION;
|
|
118
|
+
state: HostedRunnerLeaseSnapshot["state"];
|
|
119
|
+
generation: number;
|
|
120
|
+
maestro_session_id?: string;
|
|
121
|
+
updated_at: string;
|
|
122
|
+
};
|
|
123
|
+
restore_environment_key: "MAESTRO_REMOTE_RUNNER_RESTORE_MANIFEST";
|
|
124
|
+
restore_manifest_path: string;
|
|
125
|
+
evidence_refs: string[];
|
|
126
|
+
}
|
|
107
127
|
export interface HostedRunnerWorkContinuity {
|
|
108
128
|
protocol_version: typeof HOSTED_RUNNER_WORK_CONTINUITY_VERSION;
|
|
109
129
|
codex_subagent_schema_version: typeof CODEX_SUBAGENT_WORK_GRAPH_SCHEMA;
|
|
@@ -144,6 +164,14 @@ export interface HostedRunnerPlatformEvidence {
|
|
|
144
164
|
codex_subagent_thread_ids: string[];
|
|
145
165
|
codex_subagent_edges?: HeadlessCodexSubagentContinuityEdge[];
|
|
146
166
|
};
|
|
167
|
+
runtime_continuity: {
|
|
168
|
+
protocol_version: typeof HOSTED_RUNNER_RUNTIME_CONTINUITY_VERSION;
|
|
169
|
+
handoff: "drain_restore";
|
|
170
|
+
source_owner_instance_id?: string;
|
|
171
|
+
source_process_id: number;
|
|
172
|
+
source_runtime_lease_generation?: number;
|
|
173
|
+
restore_manifest_path: string;
|
|
174
|
+
};
|
|
147
175
|
retention: {
|
|
148
176
|
policy_version: typeof HOSTED_RUNNER_RETENTION_POLICY_VERSION;
|
|
149
177
|
control_plane_metadata_visibility: "operator";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hosted-runner-drain.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/hosted-runner-drain.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAGjE,OAAO,EAEN,gCAAgC,EAEhC,KAAK,mCAAmC,EAQxC,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"hosted-runner-drain.d.ts","source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CAezC;AAED,wBAAsB,uBAAuB,CAC5C,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,gBAAgB,GACvB,OAAO,CAAC,IAAI,CAAC,CAsCf"}
|
|
@@ -3,7 +3,7 @@ import { mkdir, realpath, stat, writeFile } from "node:fs/promises";
|
|
|
3
3
|
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
5
|
import { CODEX_SUBAGENT_TOOL_PREFIX, CODEX_SUBAGENT_WORK_GRAPH_SCHEMA, HEADLESS_PROTOCOL_VERSION, activeCodexSubagentStatus, buildCodexSubagentContinuityEdges, codexSubagentEdgeKey, codexSubagentOperation, codexSubagentStatusIsTerminal, createHeadlessRuntimeState, stringArray, } from "../../cli/headless-protocol.js";
|
|
6
|
-
import { markHostedRunnerLeaseDraining } from "../hosted-runner-lease.js";
|
|
6
|
+
import { HOSTED_RUNNER_LEASE_PROTOCOL_VERSION, markHostedRunnerLeaseDraining, } from "../hosted-runner-lease.js";
|
|
7
7
|
import { ApiError, readJsonBody, sendJson } from "../server-utils.js";
|
|
8
8
|
const execFileAsync = promisify(execFile);
|
|
9
9
|
export const HOSTED_RUNNER_DRAIN_PATH = "/.well-known/evalops/remote-runner/drain";
|
|
@@ -12,6 +12,7 @@ export const HOSTED_RUNNER_SNAPSHOT_MANIFEST_VERSION = "evalops.remote-runner.sn
|
|
|
12
12
|
export const HOSTED_RUNNER_RETENTION_POLICY_VERSION = "evalops.remote-runner.retention.v1";
|
|
13
13
|
export const HOSTED_RUNNER_WORK_CONTINUITY_VERSION = "evalops.remote-runner.work-continuity.v1";
|
|
14
14
|
export const HOSTED_RUNNER_PLATFORM_EVIDENCE_VERSION = "evalops.remote-runner.platform-evidence.v1";
|
|
15
|
+
export const HOSTED_RUNNER_RUNTIME_CONTINUITY_VERSION = "evalops.remote-runner.runtime-continuity.v1";
|
|
15
16
|
export var HostedRunnerDrainStatusValue;
|
|
16
17
|
(function (HostedRunnerDrainStatusValue) {
|
|
17
18
|
HostedRunnerDrainStatusValue["Drained"] = "drained";
|
|
@@ -237,6 +238,32 @@ function buildHostedRunnerRetentionPolicy() {
|
|
|
237
238
|
},
|
|
238
239
|
};
|
|
239
240
|
}
|
|
241
|
+
function buildHostedRunnerRuntimeContinuity(input) {
|
|
242
|
+
return {
|
|
243
|
+
protocol_version: HOSTED_RUNNER_RUNTIME_CONTINUITY_VERSION,
|
|
244
|
+
handoff: "drain_restore",
|
|
245
|
+
source_runner_session_id: input.hostedRunner.runnerSessionId,
|
|
246
|
+
...(input.hostedRunner.ownerInstanceId
|
|
247
|
+
? { source_owner_instance_id: input.hostedRunner.ownerInstanceId }
|
|
248
|
+
: {}),
|
|
249
|
+
source_process_id: process.pid,
|
|
250
|
+
source_runtime_lease: {
|
|
251
|
+
protocol_version: HOSTED_RUNNER_LEASE_PROTOCOL_VERSION,
|
|
252
|
+
state: input.leaseSnapshot.state,
|
|
253
|
+
generation: input.leaseSnapshot.generation,
|
|
254
|
+
...(input.leaseSnapshot.maestroSessionId
|
|
255
|
+
? { maestro_session_id: input.leaseSnapshot.maestroSessionId }
|
|
256
|
+
: {}),
|
|
257
|
+
updated_at: input.leaseSnapshot.updatedAt,
|
|
258
|
+
},
|
|
259
|
+
restore_environment_key: "MAESTRO_REMOTE_RUNNER_RESTORE_MANIFEST",
|
|
260
|
+
restore_manifest_path: input.manifestPath,
|
|
261
|
+
evidence_refs: [
|
|
262
|
+
`remote-runner://sessions/${input.hostedRunner.runnerSessionId}/drain#snapshot`,
|
|
263
|
+
`maestro://headless/sessions/${input.maestroSessionId}#cursor:${input.runtime.cursor ?? 0}`,
|
|
264
|
+
],
|
|
265
|
+
};
|
|
266
|
+
}
|
|
240
267
|
function buildHostedRunnerPlatformEvidence(input) {
|
|
241
268
|
const edges = input.workContinuity.codex_subagent_edges ?? [];
|
|
242
269
|
return {
|
|
@@ -272,6 +299,22 @@ function buildHostedRunnerPlatformEvidence(input) {
|
|
|
272
299
|
codex_subagent_thread_ids: input.workContinuity.codex_subagent_thread_ids,
|
|
273
300
|
...(edges.length > 0 ? { codex_subagent_edges: edges } : {}),
|
|
274
301
|
},
|
|
302
|
+
runtime_continuity: {
|
|
303
|
+
protocol_version: input.runtimeContinuity.protocol_version,
|
|
304
|
+
handoff: input.runtimeContinuity.handoff,
|
|
305
|
+
...(input.runtimeContinuity.source_owner_instance_id
|
|
306
|
+
? {
|
|
307
|
+
source_owner_instance_id: input.runtimeContinuity.source_owner_instance_id,
|
|
308
|
+
}
|
|
309
|
+
: {}),
|
|
310
|
+
source_process_id: input.runtimeContinuity.source_process_id,
|
|
311
|
+
...(input.runtimeContinuity.source_runtime_lease
|
|
312
|
+
? {
|
|
313
|
+
source_runtime_lease_generation: input.runtimeContinuity.source_runtime_lease.generation,
|
|
314
|
+
}
|
|
315
|
+
: {}),
|
|
316
|
+
restore_manifest_path: input.runtimeContinuity.restore_manifest_path,
|
|
317
|
+
},
|
|
275
318
|
retention: {
|
|
276
319
|
policy_version: input.retentionPolicy.policy_version,
|
|
277
320
|
control_plane_metadata_visibility: input.retentionPolicy.visibility.control_plane_metadata,
|
|
@@ -423,7 +466,7 @@ export async function drainHostedRunner(input, options) {
|
|
|
423
466
|
return null;
|
|
424
467
|
}
|
|
425
468
|
const requestedAtDate = options.now?.() ?? new Date();
|
|
426
|
-
markHostedRunnerLeaseDraining(hostedRunner, requestedAtDate);
|
|
469
|
+
const leaseSnapshot = markHostedRunnerLeaseDraining(hostedRunner, requestedAtDate);
|
|
427
470
|
const requestedAt = requestedAtDate.toISOString();
|
|
428
471
|
const workspaceRoot = await resolveWorkspaceRoot(hostedRunner);
|
|
429
472
|
const snapshotRoot = resolve(workspaceRoot, hostedRunner.snapshotRoot ?? ".maestro/runner-snapshots");
|
|
@@ -495,6 +538,13 @@ export async function drainHostedRunner(input, options) {
|
|
|
495
538
|
buildHostedRunnerSnapshot(maestroSessionId, workspaceRoot, runtime);
|
|
496
539
|
const workContinuity = collectHostedRunnerWorkContinuity(snapshot);
|
|
497
540
|
const retentionPolicy = buildHostedRunnerRetentionPolicy();
|
|
541
|
+
const runtimeContinuity = buildHostedRunnerRuntimeContinuity({
|
|
542
|
+
hostedRunner,
|
|
543
|
+
maestroSessionId,
|
|
544
|
+
manifestPath: snapshotPath,
|
|
545
|
+
runtime,
|
|
546
|
+
leaseSnapshot,
|
|
547
|
+
});
|
|
498
548
|
const platformEvidence = buildHostedRunnerPlatformEvidence({
|
|
499
549
|
hostedRunner,
|
|
500
550
|
status,
|
|
@@ -502,6 +552,7 @@ export async function drainHostedRunner(input, options) {
|
|
|
502
552
|
createdAt: requestedAt,
|
|
503
553
|
manifestPath: snapshotPath,
|
|
504
554
|
runtime,
|
|
555
|
+
runtimeContinuity,
|
|
505
556
|
workContinuity,
|
|
506
557
|
retentionPolicy,
|
|
507
558
|
reason: input.reason,
|
|
@@ -526,6 +577,7 @@ export async function drainHostedRunner(input, options) {
|
|
|
526
577
|
mode: HostedRunnerWorkspaceExportModeValue.LocalPathContract,
|
|
527
578
|
paths: exportPaths,
|
|
528
579
|
},
|
|
580
|
+
runtime_continuity: runtimeContinuity,
|
|
529
581
|
work_continuity: workContinuity,
|
|
530
582
|
platform_evidence: platformEvidence,
|
|
531
583
|
snapshot,
|
|
@@ -557,6 +609,7 @@ export async function drainHostedRunner(input, options) {
|
|
|
557
609
|
createdAt: requestedAt,
|
|
558
610
|
manifestPath: snapshotPath,
|
|
559
611
|
runtime,
|
|
612
|
+
runtimeContinuity,
|
|
560
613
|
workContinuity,
|
|
561
614
|
retentionPolicy,
|
|
562
615
|
reason: input.reason,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hosted-runner-drain.js","sourceRoot":"","sources":["../../../src/server/handlers/hosted-runner-drain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,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F,OAAO;IACR,CAAC;IAED,QAAQ,CACP,GAAG,EACH,MAAM,CAAC,MAAM,KAAK,4BAA4B,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EACtE;QACC,gBAAgB,EAAE,oCAAoC;QACtD,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;QAC3C,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,QAAQ,EAAE,MAAM,CAAC,QAAQ;KACzB,EACD,OAAO,CAAC,WAAW,EACnB,GAAG,CACH,CAAC;AACH,CAAC","sourcesContent":["import { execFile } from \"node:child_process\";\nimport { mkdir, realpath, stat, writeFile } from \"node:fs/promises\";\nimport type { IncomingMessage, ServerResponse } from \"node:http\";\nimport { isAbsolute, join, relative, resolve } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport {\n\tCODEX_SUBAGENT_TOOL_PREFIX,\n\tCODEX_SUBAGENT_WORK_GRAPH_SCHEMA,\n\tHEADLESS_PROTOCOL_VERSION,\n\ttype HeadlessCodexSubagentContinuityEdge,\n\tactiveCodexSubagentStatus,\n\tbuildCodexSubagentContinuityEdges,\n\tcodexSubagentEdgeKey,\n\tcodexSubagentOperation,\n\tcodexSubagentStatusIsTerminal,\n\tcreateHeadlessRuntimeState,\n\tstringArray,\n} from \"../../cli/headless-protocol.js\";\nimport type { HostedRunnerContext, WebServerContext } from \"../app-context.js\";\nimport type { HeadlessRuntimeSnapshot } from \"../headless-runtime-service.js\";\nimport { markHostedRunnerLeaseDraining } from \"../hosted-runner-lease.js\";\nimport { ApiError, readJsonBody, sendJson } from \"../server-utils.js\";\n\nconst execFileAsync = promisify(execFile);\n\nexport const HOSTED_RUNNER_DRAIN_PATH =\n\t\"/.well-known/evalops/remote-runner/drain\";\n\nexport const HOSTED_RUNNER_DRAIN_PROTOCOL_VERSION =\n\t\"evalops.remote-runner.drain.v1\";\n\nexport const HOSTED_RUNNER_SNAPSHOT_MANIFEST_VERSION =\n\t\"evalops.remote-runner.snapshot-manifest.v1\";\n\nexport const HOSTED_RUNNER_RETENTION_POLICY_VERSION =\n\t\"evalops.remote-runner.retention.v1\";\n\nexport const HOSTED_RUNNER_WORK_CONTINUITY_VERSION =\n\t\"evalops.remote-runner.work-continuity.v1\";\n\nexport const HOSTED_RUNNER_PLATFORM_EVIDENCE_VERSION =\n\t\"evalops.remote-runner.platform-evidence.v1\";\n\nexport enum HostedRunnerDrainStatusValue {\n\tDrained = \"drained\",\n\tInterrupted = \"interrupted\",\n}\n\nexport enum HostedRunnerRuntimeFlushStatusValue {\n\tCompleted = \"completed\",\n\tFailed = \"failed\",\n\tSkipped = \"skipped\",\n}\n\nexport enum HostedRunnerWorkspaceExportPathTypeValue {\n\tFile = \"file\",\n\tDirectory = \"directory\",\n\tOther = \"other\",\n}\n\nexport enum HostedRunnerWorkspaceExportModeValue {\n\tLocalPathContract = \"local_path_contract\",\n}\n\nexport enum HostedRunnerDrainReasonValue {\n\tKubernetesPreStop = \"kubernetes_prestop\",\n\tProcessShutdown = \"process_shutdown\",\n}\n\nexport enum HostedRunnerDrainRequestedByValue {\n\tKubernetesPreStop = \"kubernetes_prestop\",\n\tMaestroWebServer = \"maestro_web_server\",\n}\n\nexport type HostedRunnerDrainStatus = HostedRunnerDrainStatusValue;\nexport type HostedRunnerRuntimeFlushStatus =\n\tHostedRunnerRuntimeFlushStatusValue;\nexport type HostedRunnerWorkspaceExportPathType =\n\tHostedRunnerWorkspaceExportPathTypeValue;\nexport type HostedRunnerWorkspaceExportMode =\n\tHostedRunnerWorkspaceExportModeValue;\nexport type HostedRunnerDrainReason = HostedRunnerDrainReasonValue | string;\nexport type HostedRunnerDrainRequestedBy =\n\t| HostedRunnerDrainRequestedByValue\n\t| string;\n\nexport interface HostedRunnerRetentionPolicy {\n\tpolicy_version: typeof HOSTED_RUNNER_RETENTION_POLICY_VERSION;\n\tmanaged_by: \"platform\";\n\tvisibility: {\n\t\tcontrol_plane_metadata: \"operator\";\n\t\tworkspace_export: \"tenant\";\n\t\truntime_snapshot: \"internal\";\n\t\truntime_logs: \"operator\";\n\t};\n\tredaction: {\n\t\trequired_before_external_persistence: Array<\n\t\t\t\"runtime_snapshot\" | \"runtime_logs\"\n\t\t>;\n\t\tforbidden_plaintext: Array<\n\t\t\t| \"provider_credentials\"\n\t\t\t| \"tool_secrets\"\n\t\t\t| \"attach_tokens\"\n\t\t\t| \"artifact_access_tokens\"\n\t\t\t| \"raw_environment\"\n\t\t>;\n\t};\n}\n\nexport interface HostedRunnerDrainInput {\n\treason?: HostedRunnerDrainReason;\n\trequestedBy?: HostedRunnerDrainRequestedBy;\n\texportPaths?: string[];\n}\n\nexport interface HostedRunnerRuntimeDrainResult {\n\tsessionId: string;\n\tsessionFile?: string;\n\tprotocolVersion?: string;\n\tcursor?: number;\n\tsnapshot?: HeadlessRuntimeSnapshot;\n\trecordPlatformDrain?: (\n\t\tinput: HostedRunnerPlatformDrainRecordInput,\n\t) => Promise<void>;\n}\n\nclass HostedRunnerRuntimeDrainError extends Error {\n\treadonly sessionId: string;\n\treadonly sessionFile?: string;\n\treadonly protocolVersion?: string;\n\treadonly cursor?: number;\n\treadonly snapshot?: HeadlessRuntimeSnapshot;\n\treadonly recordPlatformDrain?: (\n\t\tinput: HostedRunnerPlatformDrainRecordInput,\n\t) => Promise<void>;\n\n\tconstructor(message: string, runtime: HostedRunnerRuntimeDrainResult) {\n\t\tsuper(message);\n\t\tthis.name = \"HostedRunnerRuntimeDrainError\";\n\t\tthis.sessionId = runtime.sessionId;\n\t\tthis.sessionFile = runtime.sessionFile;\n\t\tthis.protocolVersion = runtime.protocolVersion;\n\t\tthis.cursor = runtime.cursor;\n\t\tthis.snapshot = runtime.snapshot;\n\t\tthis.recordPlatformDrain = runtime.recordPlatformDrain;\n\t}\n}\n\nexport interface HostedRunnerWorkspaceExportPath {\n\tinput: string;\n\tpath: string;\n\trelative_path: string;\n\ttype: HostedRunnerWorkspaceExportPathType;\n}\n\nexport interface HostedRunnerSnapshotManifest {\n\tprotocol_version: typeof HOSTED_RUNNER_SNAPSHOT_MANIFEST_VERSION;\n\trunner_session_id: string;\n\tworkspace_id?: string;\n\tagent_run_id?: string;\n\tmaestro_session_id: string;\n\treason?: string;\n\trequested_by?: string;\n\tcreated_at: string;\n\tworkspace_root: string;\n\truntime: {\n\t\tflush_status: HostedRunnerRuntimeFlushStatus;\n\t\terror?: string;\n\t\tsession_id: string;\n\t\tsession_file?: string;\n\t\tprotocol_version?: string;\n\t\tcursor?: number;\n\t};\n\tworkspace_export: {\n\t\tmode: HostedRunnerWorkspaceExportMode;\n\t\tpaths: HostedRunnerWorkspaceExportPath[];\n\t};\n\twork_continuity: HostedRunnerWorkContinuity;\n\tplatform_evidence: HostedRunnerPlatformEvidence;\n\tsnapshot: HeadlessRuntimeSnapshot;\n\tretention_policy: HostedRunnerRetentionPolicy;\n\tgit?: {\n\t\tcommit?: string;\n\t\tbranch?: string;\n\t\tdirty?: boolean;\n\t};\n}\n\nexport interface HostedRunnerWorkContinuity {\n\tprotocol_version: typeof HOSTED_RUNNER_WORK_CONTINUITY_VERSION;\n\tcodex_subagent_schema_version: typeof CODEX_SUBAGENT_WORK_GRAPH_SCHEMA;\n\tactive_tool_count: number;\n\ttracked_tool_count: number;\n\tpending_request_count: number;\n\tcodex_subagent_tool_call_ids: string[];\n\tcodex_subagent_child_run_ids: string[];\n\tcodex_subagent_thread_ids: string[];\n\tcodex_subagent_edges?: HeadlessCodexSubagentContinuityEdge[];\n}\n\nexport interface HostedRunnerPlatformEvidence {\n\tprotocol_version: typeof HOSTED_RUNNER_PLATFORM_EVIDENCE_VERSION;\n\tevent_type: \"hosted_runner_drain_manifest_recorded\";\n\trunner_session_id: string;\n\tworkspace_id?: string;\n\tagent_run_id?: string;\n\tmaestro_session_id: string;\n\tstatus: HostedRunnerDrainStatus;\n\truntime_flush_status: HostedRunnerRuntimeFlushStatus;\n\tmanifest_path: string;\n\tmanifest_protocol_version: typeof HOSTED_RUNNER_SNAPSHOT_MANIFEST_VERSION;\n\tcreated_at: string;\n\treason?: string;\n\trequested_by?: string;\n\twork_continuity: {\n\t\tprotocol_version: typeof HOSTED_RUNNER_WORK_CONTINUITY_VERSION;\n\t\tcodex_subagent_schema_version: typeof CODEX_SUBAGENT_WORK_GRAPH_SCHEMA;\n\t\tactive_tool_count: number;\n\t\ttracked_tool_count: number;\n\t\tpending_request_count: number;\n\t\tcodex_subagent_tool_call_count: number;\n\t\tcodex_subagent_child_run_count: number;\n\t\tcodex_subagent_thread_count: number;\n\t\tcodex_subagent_edge_count: number;\n\t\tcodex_subagent_tool_call_ids: string[];\n\t\tcodex_subagent_child_run_ids: string[];\n\t\tcodex_subagent_thread_ids: string[];\n\t\tcodex_subagent_edges?: HeadlessCodexSubagentContinuityEdge[];\n\t};\n\tretention: {\n\t\tpolicy_version: typeof HOSTED_RUNNER_RETENTION_POLICY_VERSION;\n\t\tcontrol_plane_metadata_visibility: \"operator\";\n\t\truntime_snapshot_visibility: \"internal\";\n\t\tredaction_required_before_external_persistence: Array<\n\t\t\t\"runtime_snapshot\" | \"runtime_logs\"\n\t\t>;\n\t};\n\tevidence_refs: string[];\n}\n\nexport interface HostedRunnerPlatformDrainRecordInput {\n\tstatus: HostedRunnerDrainStatus;\n\treason?: string;\n\trequestedBy?: string;\n\tflushStatus: HostedRunnerRuntimeFlushStatus;\n\tmanifestPath: string;\n\tplatformEvidence: HostedRunnerPlatformEvidence;\n\terrorMessage?: string;\n}\n\nexport interface HostedRunnerDrainResult {\n\tstatus: HostedRunnerDrainStatus;\n\trunner_session_id: string;\n\treason?: string;\n\trequested_by?: string;\n\tmanifest_path: string;\n\tmanifest: HostedRunnerSnapshotManifest;\n}\n\nexport interface DrainHostedRunnerOptions {\n\thostedRunner?: HostedRunnerContext;\n\tdrainRuntime?: (\n\t\tsessionId: string,\n\t\tterminal: HostedRunnerRuntimeTerminalInput,\n\t) => Promise<HostedRunnerRuntimeDrainResult | null>;\n\tnow?: () => Date;\n}\n\ninterface HostedRunnerDrainRuntimeContext {\n\thostedRunner?: HostedRunnerContext;\n\theadlessRuntimeService: Pick<\n\t\tWebServerContext[\"headlessRuntimeService\"],\n\t\t\"getRuntimeBySessionId\"\n\t>;\n}\n\nexport interface DrainHostedRunnerForShutdownOptions {\n\tnow?: () => Date;\n\treason?: HostedRunnerDrainReason;\n\trequestedBy?: HostedRunnerDrainRequestedBy;\n}\n\ninterface HostedRunnerRuntimeTerminalInput {\n\treason?: HostedRunnerDrainReason;\n\trequestedBy?: HostedRunnerDrainRequestedBy;\n\tmanifestPath?: string;\n}\n\nfunction getString(value: unknown, field: string): string | undefined {\n\tif (value === undefined || value === null) {\n\t\treturn undefined;\n\t}\n\tif (typeof value !== \"string\") {\n\t\tthrow new ApiError(400, `${field} must be a string`);\n\t}\n\tconst trimmed = value.trim();\n\treturn trimmed || undefined;\n}\n\nfunction getStringArray(value: unknown, field: string): string[] | undefined {\n\tif (value === undefined || value === null) {\n\t\treturn undefined;\n\t}\n\tif (!Array.isArray(value)) {\n\t\tthrow new ApiError(400, `${field} must be an array of strings`);\n\t}\n\tconst strings = value.map((entry, index) => {\n\t\tif (typeof entry !== \"string\" || !entry.trim()) {\n\t\t\tthrow new ApiError(400, `${field}[${index}] must be a non-empty string`);\n\t\t}\n\t\tif (entry.includes(\"\\0\")) {\n\t\t\tthrow new ApiError(400, `${field}[${index}] contains a null byte`);\n\t\t}\n\t\treturn entry.trim();\n\t});\n\treturn strings.length ? strings : undefined;\n}\n\nexport function parseHostedRunnerDrainInput(\n\tbody: unknown,\n): HostedRunnerDrainInput {\n\tif (body === undefined || body === null) {\n\t\treturn {};\n\t}\n\tif (typeof body !== \"object\" || Array.isArray(body)) {\n\t\tthrow new ApiError(400, \"Drain payload must be a JSON object\");\n\t}\n\tconst record = body as Record<string, unknown>;\n\treturn {\n\t\treason:\n\t\t\tgetString(record.reason, \"reason\") ??\n\t\t\tgetString(record.stop_reason, \"stop_reason\"),\n\t\trequestedBy:\n\t\t\tgetString(record.requested_by, \"requested_by\") ??\n\t\t\tgetString(record.requestedBy, \"requestedBy\"),\n\t\texportPaths:\n\t\t\tgetStringArray(record.export_paths, \"export_paths\") ??\n\t\t\tgetStringArray(record.exportPaths, \"exportPaths\"),\n\t};\n}\n\nfunction isWithinPath(root: string, target: string): boolean {\n\tconst rel = relative(root, target);\n\treturn rel === \"\" || (!rel.startsWith(\"..\") && !isAbsolute(rel));\n}\n\nfunction safeManifestFileName(\n\trunnerSessionId: string,\n\trequestedAt: string,\n): string {\n\tconst safeSession = runnerSessionId.replace(/[^A-Za-z0-9_.-]/g, \"_\");\n\tconst safeTimestamp = requestedAt.replace(/[^A-Za-z0-9_.-]/g, \"_\");\n\treturn `${safeSession}-${safeTimestamp}.json`;\n}\n\nasync function resolveWorkspaceRoot(\n\thostedRunner: HostedRunnerContext,\n): Promise<string> {\n\ttry {\n\t\tconst workspaceRoot = await realpath(hostedRunner.workspaceRoot);\n\t\tconst stats = await stat(workspaceRoot);\n\t\tif (!stats.isDirectory()) {\n\t\t\tthrow new ApiError(\n\t\t\t\t503,\n\t\t\t\t\"Hosted runner workspace root is not a directory\",\n\t\t\t);\n\t\t}\n\t\treturn workspaceRoot;\n\t} catch (error) {\n\t\tif (error instanceof ApiError) {\n\t\t\tthrow error;\n\t\t}\n\t\tthrow new ApiError(\n\t\t\t503,\n\t\t\t`Hosted runner workspace root is unavailable: ${\n\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t}`,\n\t\t);\n\t}\n}\n\nasync function resolveWorkspaceExportPaths(\n\tworkspaceRoot: string,\n\texportPaths: readonly string[] | undefined,\n): Promise<HostedRunnerWorkspaceExportPath[]> {\n\tconst requested = exportPaths?.length ? exportPaths : [\".\"];\n\tconst paths: HostedRunnerWorkspaceExportPath[] = [];\n\tfor (const input of requested) {\n\t\tconst logicalPath = isAbsolute(input)\n\t\t\t? resolve(input)\n\t\t\t: resolve(workspaceRoot, input);\n\t\tlet realPath: string;\n\t\ttry {\n\t\t\trealPath = await realpath(logicalPath);\n\t\t} catch (error) {\n\t\t\tthrow new ApiError(\n\t\t\t\t400,\n\t\t\t\t`Export path is unavailable: ${input} (${\n\t\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t\t})`,\n\t\t\t);\n\t\t}\n\t\tif (!isWithinPath(workspaceRoot, realPath)) {\n\t\t\tthrow new ApiError(\n\t\t\t\t400,\n\t\t\t\t`Export path escapes hosted runner workspace root: ${input}`,\n\t\t\t);\n\t\t}\n\t\tconst pathStat = await stat(realPath);\n\t\tpaths.push({\n\t\t\tinput,\n\t\t\tpath: realPath,\n\t\t\trelative_path: relative(workspaceRoot, realPath) || \".\",\n\t\t\ttype: pathStat.isDirectory()\n\t\t\t\t? HostedRunnerWorkspaceExportPathTypeValue.Directory\n\t\t\t\t: pathStat.isFile()\n\t\t\t\t\t? HostedRunnerWorkspaceExportPathTypeValue.File\n\t\t\t\t\t: HostedRunnerWorkspaceExportPathTypeValue.Other,\n\t\t});\n\t}\n\treturn paths;\n}\n\nasync function gitOutput(\n\tworkspaceRoot: string,\n\targs: readonly string[],\n): Promise<string | undefined> {\n\ttry {\n\t\tconst { stdout } = await execFileAsync(\n\t\t\t\"git\",\n\t\t\t[\"-C\", workspaceRoot, ...args],\n\t\t\t{\n\t\t\t\tencoding: \"utf8\",\n\t\t\t\ttimeout: 1000,\n\t\t\t},\n\t\t);\n\t\tconst output = stdout.trim();\n\t\treturn output || undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nasync function collectGitState(\n\tworkspaceRoot: string,\n): Promise<HostedRunnerSnapshotManifest[\"git\"] | undefined> {\n\tconst [commit, branch, status] = await Promise.all([\n\t\tgitOutput(workspaceRoot, [\"rev-parse\", \"HEAD\"]),\n\t\tgitOutput(workspaceRoot, [\"rev-parse\", \"--abbrev-ref\", \"HEAD\"]),\n\t\tgitOutput(workspaceRoot, [\"status\", \"--porcelain\"]),\n\t]);\n\tif (!commit && !branch && status === undefined) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\t...(commit ? { commit } : {}),\n\t\t...(branch && branch !== \"HEAD\" ? { branch } : {}),\n\t\tdirty: Boolean(status),\n\t};\n}\n\nfunction buildHostedRunnerSnapshot(\n\tsessionId: string,\n\tworkspaceRoot: string,\n\truntime: HostedRunnerSnapshotManifest[\"runtime\"],\n): HeadlessRuntimeSnapshot {\n\tconst state = createHeadlessRuntimeState();\n\tstate.protocol_version =\n\t\truntime.protocol_version ?? HEADLESS_PROTOCOL_VERSION;\n\tstate.session_id = sessionId;\n\tstate.cwd = workspaceRoot;\n\tstate.provider = \"typescript\";\n\tstate.model = \"typescript-hosted-runner\";\n\tstate.is_ready =\n\t\truntime.flush_status === HostedRunnerRuntimeFlushStatusValue.Completed;\n\tstate.last_status =\n\t\truntime.flush_status === HostedRunnerRuntimeFlushStatusValue.Completed\n\t\t\t? \"Drained\"\n\t\t\t: runtime.flush_status === HostedRunnerRuntimeFlushStatusValue.Failed\n\t\t\t\t? \"Drain interrupted before runtime flush completed\"\n\t\t\t\t: \"Drain skipped: no runtime activity was available\";\n\tif (runtime.error) {\n\t\tstate.last_error = runtime.error;\n\t\tstate.last_error_type = \"protocol\";\n\t}\n\treturn {\n\t\tprotocolVersion: runtime.protocol_version ?? HEADLESS_PROTOCOL_VERSION,\n\t\tsession_id: sessionId,\n\t\tcursor: runtime.cursor ?? 0,\n\t\tlast_init: null,\n\t\tstate,\n\t};\n}\n\nfunction buildHostedRunnerRetentionPolicy(): HostedRunnerRetentionPolicy {\n\treturn {\n\t\tpolicy_version: HOSTED_RUNNER_RETENTION_POLICY_VERSION,\n\t\tmanaged_by: \"platform\",\n\t\tvisibility: {\n\t\t\tcontrol_plane_metadata: \"operator\",\n\t\t\tworkspace_export: \"tenant\",\n\t\t\truntime_snapshot: \"internal\",\n\t\t\truntime_logs: \"operator\",\n\t\t},\n\t\tredaction: {\n\t\t\trequired_before_external_persistence: [\n\t\t\t\t\"runtime_snapshot\",\n\t\t\t\t\"runtime_logs\",\n\t\t\t],\n\t\t\tforbidden_plaintext: [\n\t\t\t\t\"provider_credentials\",\n\t\t\t\t\"tool_secrets\",\n\t\t\t\t\"attach_tokens\",\n\t\t\t\t\"artifact_access_tokens\",\n\t\t\t\t\"raw_environment\",\n\t\t\t],\n\t\t},\n\t};\n}\n\nfunction buildHostedRunnerPlatformEvidence(input: {\n\thostedRunner: HostedRunnerContext;\n\tstatus: HostedRunnerDrainStatus;\n\tmaestroSessionId: string;\n\tcreatedAt: string;\n\tmanifestPath: string;\n\truntime: HostedRunnerSnapshotManifest[\"runtime\"];\n\tworkContinuity: HostedRunnerWorkContinuity;\n\tretentionPolicy: HostedRunnerRetentionPolicy;\n\treason?: string;\n\trequestedBy?: string;\n}): HostedRunnerPlatformEvidence {\n\tconst edges = input.workContinuity.codex_subagent_edges ?? [];\n\treturn {\n\t\tprotocol_version: HOSTED_RUNNER_PLATFORM_EVIDENCE_VERSION,\n\t\tevent_type: \"hosted_runner_drain_manifest_recorded\",\n\t\trunner_session_id: input.hostedRunner.runnerSessionId,\n\t\t...(input.hostedRunner.workspaceId\n\t\t\t? { workspace_id: input.hostedRunner.workspaceId }\n\t\t\t: {}),\n\t\t...(input.hostedRunner.agentRunId\n\t\t\t? { agent_run_id: input.hostedRunner.agentRunId }\n\t\t\t: {}),\n\t\tmaestro_session_id: input.maestroSessionId,\n\t\tstatus: input.status,\n\t\truntime_flush_status: input.runtime.flush_status,\n\t\tmanifest_path: input.manifestPath,\n\t\tmanifest_protocol_version: HOSTED_RUNNER_SNAPSHOT_MANIFEST_VERSION,\n\t\tcreated_at: input.createdAt,\n\t\t...(input.reason ? { reason: input.reason } : {}),\n\t\t...(input.requestedBy ? { requested_by: input.requestedBy } : {}),\n\t\twork_continuity: {\n\t\t\tprotocol_version: input.workContinuity.protocol_version,\n\t\t\tcodex_subagent_schema_version:\n\t\t\t\tinput.workContinuity.codex_subagent_schema_version,\n\t\t\tactive_tool_count: input.workContinuity.active_tool_count,\n\t\t\ttracked_tool_count: input.workContinuity.tracked_tool_count,\n\t\t\tpending_request_count: input.workContinuity.pending_request_count,\n\t\t\tcodex_subagent_tool_call_count:\n\t\t\t\tinput.workContinuity.codex_subagent_tool_call_ids.length,\n\t\t\tcodex_subagent_child_run_count:\n\t\t\t\tinput.workContinuity.codex_subagent_child_run_ids.length,\n\t\t\tcodex_subagent_thread_count:\n\t\t\t\tinput.workContinuity.codex_subagent_thread_ids.length,\n\t\t\tcodex_subagent_edge_count: edges.length,\n\t\t\tcodex_subagent_tool_call_ids:\n\t\t\t\tinput.workContinuity.codex_subagent_tool_call_ids,\n\t\t\tcodex_subagent_child_run_ids:\n\t\t\t\tinput.workContinuity.codex_subagent_child_run_ids,\n\t\t\tcodex_subagent_thread_ids: input.workContinuity.codex_subagent_thread_ids,\n\t\t\t...(edges.length > 0 ? { codex_subagent_edges: edges } : {}),\n\t\t},\n\t\tretention: {\n\t\t\tpolicy_version: input.retentionPolicy.policy_version,\n\t\t\tcontrol_plane_metadata_visibility:\n\t\t\t\tinput.retentionPolicy.visibility.control_plane_metadata,\n\t\t\truntime_snapshot_visibility:\n\t\t\t\tinput.retentionPolicy.visibility.runtime_snapshot,\n\t\t\tredaction_required_before_external_persistence:\n\t\t\t\tinput.retentionPolicy.redaction.required_before_external_persistence,\n\t\t},\n\t\tevidence_refs: [\n\t\t\t`remote-runner://sessions/${input.hostedRunner.runnerSessionId}/drain#manifest`,\n\t\t\t`maestro://headless/sessions/${input.maestroSessionId}#drain`,\n\t\t\t...(input.hostedRunner.agentRunId\n\t\t\t\t? [`platform-agent-run:${input.hostedRunner.agentRunId}`]\n\t\t\t\t: []),\n\t\t],\n\t};\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn Boolean(value && typeof value === \"object\" && !Array.isArray(value));\n}\n\nfunction collectCodexSubagentEdgesFromSource(\n\tsource: {\n\t\tcall_id: string;\n\t\ttool_execution_id?: string;\n\t\ttool: string;\n\t\targs?: unknown;\n\t},\n\tedges: Map<string, HeadlessCodexSubagentContinuityEdge>,\n): void {\n\tconst operation = codexSubagentOperation(source.tool);\n\tif (!operation) {\n\t\treturn;\n\t}\n\tconst status = activeCodexSubagentStatus(operation);\n\tfor (const edge of buildCodexSubagentContinuityEdges({\n\t\tcall_id: source.call_id,\n\t\ttool_execution_id: source.tool_execution_id,\n\t\ttool: source.tool,\n\t\targs: source.args,\n\t\tstatus,\n\t})) {\n\t\tedges.set(codexSubagentEdgeKey(edge), edge);\n\t}\n}\n\nfunction collectCodexWorkArgs(\n\targs: unknown,\n\tchildRunIds: Set<string>,\n\tthreadIds: Set<string>,\n\tincludeLooseArgs = false,\n): boolean {\n\tif (!isRecord(args)) {\n\t\treturn false;\n\t}\n\tconst graph = args.codexWorkGraph ?? args.codex_work_graph;\n\tconst hasCodexGraph =\n\t\tisRecord(graph) &&\n\t\t(graph.schemaVersion === CODEX_SUBAGENT_WORK_GRAPH_SCHEMA ||\n\t\t\tgraph.schema_version === CODEX_SUBAGENT_WORK_GRAPH_SCHEMA);\n\tif (!includeLooseArgs && !hasCodexGraph) {\n\t\treturn false;\n\t}\n\tfor (const childRunId of stringArray(\n\t\targs.childRunIds ?? args.child_run_ids,\n\t)) {\n\t\tchildRunIds.add(childRunId);\n\t}\n\tfor (const threadId of stringArray(\n\t\targs.receiverThreadIds ?? args.receiver_thread_ids,\n\t)) {\n\t\tthreadIds.add(threadId);\n\t}\n\tif (isRecord(graph)) {\n\t\tconst graphChildRuns = graph.childRuns ?? graph.child_runs;\n\t\tfor (const childRun of Array.isArray(graphChildRuns)\n\t\t\t? graphChildRuns\n\t\t\t: []) {\n\t\t\tif (!isRecord(childRun)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst childRunId = childRun.childRunId ?? childRun.child_run_id;\n\t\t\tif (typeof childRunId === \"string\" && childRunId) {\n\t\t\t\tchildRunIds.add(childRunId);\n\t\t\t}\n\t\t\tconst threadId = childRun.threadId ?? childRun.thread_id;\n\t\t\tif (typeof threadId === \"string\" && threadId) {\n\t\t\t\tthreadIds.add(threadId);\n\t\t\t}\n\t\t}\n\t}\n\treturn includeLooseArgs || hasCodexGraph;\n}\n\nfunction collectHostedRunnerWorkContinuity(\n\tsnapshot: HeadlessRuntimeSnapshot,\n): HostedRunnerWorkContinuity {\n\tconst state = snapshot.state;\n\tconst codexToolCallIds = new Set<string>();\n\tconst childRunIds = new Set<string>();\n\tconst threadIds = new Set<string>();\n\tconst codexSubagentEdges = new Map<\n\t\tstring,\n\t\tHeadlessCodexSubagentContinuityEdge\n\t>();\n\tfor (const edge of state.codex_subagent_edges ?? []) {\n\t\tcodexSubagentEdges.set(codexSubagentEdgeKey(edge), edge);\n\t\tif (edge.spawn_tool_call_id) {\n\t\t\tcodexToolCallIds.add(edge.spawn_tool_call_id);\n\t\t}\n\t\tif (edge.wait_tool_call_id) {\n\t\t\tcodexToolCallIds.add(edge.wait_tool_call_id);\n\t\t}\n\t\tif (edge.child_run_id) {\n\t\t\tchildRunIds.add(edge.child_run_id);\n\t\t}\n\t\tif (edge.thread_id) {\n\t\t\tthreadIds.add(edge.thread_id);\n\t\t}\n\t}\n\tconst trackedSources = [\n\t\t...state.tracked_tools,\n\t\t...state.pending_approvals,\n\t\t...state.pending_client_tools,\n\t\t...state.pending_mcp_elicitations,\n\t\t...state.pending_user_inputs,\n\t\t...state.pending_tool_retries,\n\t];\n\tconst codexTrackedSourceCallIds = new Set<string>();\n\tfor (const source of trackedSources) {\n\t\tconst tool = source.tool;\n\t\tconst isCodexSubagentTool = tool.startsWith(CODEX_SUBAGENT_TOOL_PREFIX);\n\t\tconst hasCodexWorkArgs = collectCodexWorkArgs(\n\t\t\tsource.args,\n\t\t\tchildRunIds,\n\t\t\tthreadIds,\n\t\t\tisCodexSubagentTool,\n\t\t);\n\t\tif (isCodexSubagentTool || hasCodexWorkArgs) {\n\t\t\tcodexTrackedSourceCallIds.add(source.call_id);\n\t\t\tcodexToolCallIds.add(source.call_id);\n\t\t\tcollectCodexSubagentEdgesFromSource(source, codexSubagentEdges);\n\t\t}\n\t}\n\tfor (const activeTool of state.active_tools) {\n\t\tif (activeTool.tool.startsWith(CODEX_SUBAGENT_TOOL_PREFIX)) {\n\t\t\tconst hasTrackedSource = codexToolCallIds.has(activeTool.call_id);\n\t\t\tcodexToolCallIds.add(activeTool.call_id);\n\t\t\tif (!hasTrackedSource) {\n\t\t\t\tcollectCodexSubagentEdgesFromSource(\n\t\t\t\t\t{ call_id: activeTool.call_id, tool: activeTool.tool },\n\t\t\t\t\tcodexSubagentEdges,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\tconst sortedEdges = [...codexSubagentEdges.values()].sort((left, right) =>\n\t\tcodexSubagentEdgeKey(left).localeCompare(codexSubagentEdgeKey(right)),\n\t);\n\tconst activeCodexSubagentEdgeCount = sortedEdges.filter(\n\t\t(edge) => !codexSubagentStatusIsTerminal(edge.status),\n\t).length;\n\tconst nonCodexActiveToolCount = state.active_tools.filter(\n\t\t(tool) => !tool.tool.startsWith(CODEX_SUBAGENT_TOOL_PREFIX),\n\t).length;\n\tconst nonCodexTrackedToolCount = state.tracked_tools.filter(\n\t\t(tool) => !codexTrackedSourceCallIds.has(tool.call_id),\n\t).length;\n\tconst trackedCodexSubagentCount = Math.max(\n\t\tcodexToolCallIds.size,\n\t\tsortedEdges.length,\n\t);\n\treturn {\n\t\tprotocol_version: HOSTED_RUNNER_WORK_CONTINUITY_VERSION,\n\t\tcodex_subagent_schema_version: CODEX_SUBAGENT_WORK_GRAPH_SCHEMA,\n\t\tactive_tool_count:\n\t\t\tsortedEdges.length > 0\n\t\t\t\t? nonCodexActiveToolCount + activeCodexSubagentEdgeCount\n\t\t\t\t: state.active_tools.length,\n\t\ttracked_tool_count:\n\t\t\tsortedEdges.length > 0\n\t\t\t\t? nonCodexTrackedToolCount + trackedCodexSubagentCount\n\t\t\t\t: state.tracked_tools.length,\n\t\tpending_request_count:\n\t\t\tstate.pending_approvals.length +\n\t\t\tstate.pending_client_tools.length +\n\t\t\tstate.pending_mcp_elicitations.length +\n\t\t\tstate.pending_user_inputs.length +\n\t\t\tstate.pending_tool_retries.length,\n\t\tcodex_subagent_tool_call_ids: [...codexToolCallIds].sort(),\n\t\tcodex_subagent_child_run_ids: [...childRunIds].sort(),\n\t\tcodex_subagent_thread_ids: [...threadIds].sort(),\n\t\t...(sortedEdges.length > 0 ? { codex_subagent_edges: sortedEdges } : {}),\n\t};\n}\n\nexport async function drainHostedRunner(\n\tinput: HostedRunnerDrainInput,\n\toptions: DrainHostedRunnerOptions,\n): Promise<HostedRunnerDrainResult | null> {\n\tconst hostedRunner = options.hostedRunner;\n\tif (!hostedRunner?.enabled || !hostedRunner.runnerSessionId) {\n\t\treturn null;\n\t}\n\n\tconst requestedAtDate = options.now?.() ?? new Date();\n\tmarkHostedRunnerLeaseDraining(hostedRunner, requestedAtDate);\n\tconst requestedAt = requestedAtDate.toISOString();\n\tconst workspaceRoot = await resolveWorkspaceRoot(hostedRunner);\n\tconst snapshotRoot = resolve(\n\t\tworkspaceRoot,\n\t\thostedRunner.snapshotRoot ?? \".maestro/runner-snapshots\",\n\t);\n\tawait mkdir(snapshotRoot, { recursive: true });\n\tconst snapshotPath = join(\n\t\tsnapshotRoot,\n\t\tsafeManifestFileName(hostedRunner.runnerSessionId, requestedAt),\n\t);\n\tconst exportPaths = await resolveWorkspaceExportPaths(\n\t\tworkspaceRoot,\n\t\tinput.exportPaths,\n\t);\n\tconst activeSessionId =\n\t\thostedRunner.activeMaestroSessionId ??\n\t\thostedRunner.configuredMaestroSessionId;\n\tconst maestroSessionId = activeSessionId ?? hostedRunner.runnerSessionId;\n\n\tlet status: HostedRunnerDrainStatus = HostedRunnerDrainStatusValue.Drained;\n\tlet runtime: HostedRunnerSnapshotManifest[\"runtime\"] = {\n\t\tflush_status: HostedRunnerRuntimeFlushStatusValue.Skipped,\n\t\tsession_id: maestroSessionId,\n\t};\n\tlet runtimeSnapshot: HeadlessRuntimeSnapshot | undefined;\n\tlet recordPlatformDrain:\n\t\t| ((input: HostedRunnerPlatformDrainRecordInput) => Promise<void>)\n\t\t| undefined;\n\n\tif (activeSessionId && options.drainRuntime) {\n\t\ttry {\n\t\t\tconst runtimeResult = await options.drainRuntime(activeSessionId, {\n\t\t\t\treason: input.reason,\n\t\t\t\trequestedBy: input.requestedBy,\n\t\t\t\tmanifestPath: snapshotPath,\n\t\t\t});\n\t\t\tconst runtimeProtocolVersion =\n\t\t\t\truntimeResult?.protocolVersion ??\n\t\t\t\truntimeResult?.snapshot?.protocolVersion;\n\t\t\tconst runtimeCursor =\n\t\t\t\truntimeResult?.cursor ?? runtimeResult?.snapshot?.cursor;\n\t\t\truntime = runtimeResult\n\t\t\t\t? {\n\t\t\t\t\t\tflush_status: HostedRunnerRuntimeFlushStatusValue.Completed,\n\t\t\t\t\t\tsession_id: runtimeResult.sessionId,\n\t\t\t\t\t\t...(runtimeResult.sessionFile\n\t\t\t\t\t\t\t? { session_file: runtimeResult.sessionFile }\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t...(runtimeProtocolVersion\n\t\t\t\t\t\t\t? { protocol_version: runtimeProtocolVersion }\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t...(runtimeCursor !== undefined ? { cursor: runtimeCursor } : {}),\n\t\t\t\t\t}\n\t\t\t\t: {\n\t\t\t\t\t\tflush_status: HostedRunnerRuntimeFlushStatusValue.Skipped,\n\t\t\t\t\t\tsession_id: activeSessionId,\n\t\t\t\t\t};\n\t\t\truntimeSnapshot = runtimeResult?.snapshot;\n\t\t\trecordPlatformDrain = runtimeResult?.recordPlatformDrain;\n\t\t} catch (error) {\n\t\t\tstatus = HostedRunnerDrainStatusValue.Interrupted;\n\t\t\tconst interruptedRuntime =\n\t\t\t\terror instanceof HostedRunnerRuntimeDrainError ? error : undefined;\n\t\t\truntimeSnapshot = interruptedRuntime?.snapshot;\n\t\t\trecordPlatformDrain = interruptedRuntime?.recordPlatformDrain;\n\t\t\truntime = {\n\t\t\t\tflush_status: HostedRunnerRuntimeFlushStatusValue.Failed,\n\t\t\t\tsession_id: interruptedRuntime?.sessionId ?? activeSessionId,\n\t\t\t\t...(interruptedRuntime?.sessionFile\n\t\t\t\t\t? { session_file: interruptedRuntime.sessionFile }\n\t\t\t\t\t: {}),\n\t\t\t\t...(interruptedRuntime?.protocolVersion\n\t\t\t\t\t? { protocol_version: interruptedRuntime.protocolVersion }\n\t\t\t\t\t: {}),\n\t\t\t\t...(interruptedRuntime?.cursor !== undefined\n\t\t\t\t\t? { cursor: interruptedRuntime.cursor }\n\t\t\t\t\t: {}),\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t};\n\t\t}\n\t}\n\n\tconst git = await collectGitState(workspaceRoot);\n\tconst snapshot =\n\t\truntimeSnapshot ??\n\t\tbuildHostedRunnerSnapshot(maestroSessionId, workspaceRoot, runtime);\n\tconst workContinuity = collectHostedRunnerWorkContinuity(snapshot);\n\tconst retentionPolicy = buildHostedRunnerRetentionPolicy();\n\tconst platformEvidence = buildHostedRunnerPlatformEvidence({\n\t\thostedRunner,\n\t\tstatus,\n\t\tmaestroSessionId,\n\t\tcreatedAt: requestedAt,\n\t\tmanifestPath: snapshotPath,\n\t\truntime,\n\t\tworkContinuity,\n\t\tretentionPolicy,\n\t\treason: input.reason,\n\t\trequestedBy: input.requestedBy,\n\t});\n\tconst manifest: HostedRunnerSnapshotManifest = {\n\t\tprotocol_version: HOSTED_RUNNER_SNAPSHOT_MANIFEST_VERSION,\n\t\trunner_session_id: hostedRunner.runnerSessionId,\n\t\t...(hostedRunner.workspaceId\n\t\t\t? { workspace_id: hostedRunner.workspaceId }\n\t\t\t: {}),\n\t\t...(hostedRunner.agentRunId\n\t\t\t? { agent_run_id: hostedRunner.agentRunId }\n\t\t\t: {}),\n\t\tmaestro_session_id: maestroSessionId,\n\t\t...(input.reason ? { reason: input.reason } : {}),\n\t\t...(input.requestedBy ? { requested_by: input.requestedBy } : {}),\n\t\tcreated_at: requestedAt,\n\t\tworkspace_root: workspaceRoot,\n\t\truntime,\n\t\tworkspace_export: {\n\t\t\tmode: HostedRunnerWorkspaceExportModeValue.LocalPathContract,\n\t\t\tpaths: exportPaths,\n\t\t},\n\t\twork_continuity: workContinuity,\n\t\tplatform_evidence: platformEvidence,\n\t\tsnapshot,\n\t\tretention_policy: retentionPolicy,\n\t\t...(git ? { git } : {}),\n\t};\n\n\ttry {\n\t\tawait writeFile(\n\t\t\tsnapshotPath,\n\t\t\t`${JSON.stringify(manifest, null, 2)}\\n`,\n\t\t\t\"utf8\",\n\t\t);\n\t\thostedRunner.lastDrain = {\n\t\t\tstatus,\n\t\t\tmanifestPath: snapshotPath,\n\t\t\tdrainedAt: requestedAt,\n\t\t\t...(input.reason ? { reason: input.reason } : {}),\n\t\t\t...(input.requestedBy ? { requestedBy: input.requestedBy } : {}),\n\t\t};\n\t} catch (error) {\n\t\tconst errorMessage = `Hosted runner drain manifest persistence failed: ${\n\t\t\terror instanceof Error ? error.message : String(error)\n\t\t}`;\n\t\tawait recordPlatformDrain?.({\n\t\t\tstatus: HostedRunnerDrainStatusValue.Interrupted,\n\t\t\treason: input.reason,\n\t\t\trequestedBy: input.requestedBy,\n\t\t\tflushStatus: runtime.flush_status,\n\t\t\tmanifestPath: snapshotPath,\n\t\t\tplatformEvidence: buildHostedRunnerPlatformEvidence({\n\t\t\t\thostedRunner,\n\t\t\t\tstatus: HostedRunnerDrainStatusValue.Interrupted,\n\t\t\t\tmaestroSessionId,\n\t\t\t\tcreatedAt: requestedAt,\n\t\t\t\tmanifestPath: snapshotPath,\n\t\t\t\truntime,\n\t\t\t\tworkContinuity,\n\t\t\t\tretentionPolicy,\n\t\t\t\treason: input.reason,\n\t\t\t\trequestedBy: input.requestedBy,\n\t\t\t}),\n\t\t\terrorMessage,\n\t\t});\n\t\tthrow error;\n\t}\n\tawait recordPlatformDrain?.({\n\t\tstatus,\n\t\treason: input.reason,\n\t\trequestedBy: input.requestedBy,\n\t\tflushStatus: runtime.flush_status,\n\t\tmanifestPath: snapshotPath,\n\t\tplatformEvidence,\n\t\terrorMessage: runtime.error,\n\t});\n\n\treturn {\n\t\tstatus,\n\t\trunner_session_id: hostedRunner.runnerSessionId,\n\t\t...(input.reason ? { reason: input.reason } : {}),\n\t\t...(input.requestedBy ? { requested_by: input.requestedBy } : {}),\n\t\tmanifest_path: snapshotPath,\n\t\tmanifest,\n\t};\n}\n\nasync function drainActiveRuntime(\n\tcontext: HostedRunnerDrainRuntimeContext,\n\tsessionId: string,\n\t_terminal: HostedRunnerRuntimeTerminalInput,\n): Promise<HostedRunnerRuntimeDrainResult | null> {\n\tconst runtime =\n\t\tcontext.headlessRuntimeService.getRuntimeBySessionId(sessionId);\n\tif (!runtime) {\n\t\treturn null;\n\t}\n\tconst snapshot = runtime.getSnapshot();\n\tconst sessionFile = runtime.getSessionFile();\n\tconst recordPlatformDrain = async (\n\t\tinput: HostedRunnerPlatformDrainRecordInput,\n\t) => {\n\t\tawait runtime.recordHostedAgentRuntimeDrain({\n\t\t\tstatus: input.status,\n\t\t\treason: input.reason,\n\t\t\trequestedBy: input.requestedBy,\n\t\t\tflushStatus: input.flushStatus,\n\t\t\tmanifestPath: input.manifestPath,\n\t\t\tplatformEvidence: input.platformEvidence,\n\t\t\terrorMessage: input.errorMessage\n\t\t\t\t? `Hosted runner drain failed: ${input.errorMessage}`\n\t\t\t\t: undefined,\n\t\t});\n\t};\n\ttry {\n\t\tawait runtime.dispose();\n\t} catch (error) {\n\t\tthrow new HostedRunnerRuntimeDrainError(\n\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t{\n\t\t\t\tsessionId: snapshot.session_id,\n\t\t\t\tsessionFile,\n\t\t\t\tprotocolVersion: snapshot.protocolVersion,\n\t\t\t\tcursor: snapshot.cursor,\n\t\t\t\tsnapshot,\n\t\t\t\trecordPlatformDrain,\n\t\t\t},\n\t\t);\n\t}\n\treturn {\n\t\tsessionId: snapshot.session_id,\n\t\tsessionFile,\n\t\tprotocolVersion: snapshot.protocolVersion,\n\t\tcursor: snapshot.cursor,\n\t\tsnapshot,\n\t\trecordPlatformDrain,\n\t};\n}\n\nexport async function drainHostedRunnerForShutdown(\n\tcontext: HostedRunnerDrainRuntimeContext,\n\toptions: DrainHostedRunnerForShutdownOptions = {},\n): Promise<HostedRunnerDrainResult | null> {\n\treturn drainHostedRunner(\n\t\t{\n\t\t\treason: options.reason ?? HostedRunnerDrainReasonValue.ProcessShutdown,\n\t\t\trequestedBy:\n\t\t\t\toptions.requestedBy ??\n\t\t\t\tHostedRunnerDrainRequestedByValue.MaestroWebServer,\n\t\t},\n\t\t{\n\t\t\thostedRunner: context.hostedRunner,\n\t\t\tdrainRuntime: (sessionId, terminal) =>\n\t\t\t\tdrainActiveRuntime(context, sessionId, terminal),\n\t\t\tnow: options.now,\n\t\t},\n\t);\n}\n\nexport async function handleHostedRunnerDrain(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n): Promise<void> {\n\tres.setHeader(\"Cache-Control\", \"no-store\");\n\tconst body = await readJsonBody<Record<string, unknown>>(req, 64_000);\n\tconst input = parseHostedRunnerDrainInput(body);\n\tconst result = await drainHostedRunner(input, {\n\t\thostedRunner: context.hostedRunner,\n\t\tdrainRuntime: (sessionId, terminal) =>\n\t\t\tdrainActiveRuntime(context, sessionId, terminal),\n\t});\n\n\tif (!result) {\n\t\tsendJson(\n\t\t\tres,\n\t\t\t404,\n\t\t\t{\n\t\t\t\terror: \"hosted runner drain unavailable\",\n\t\t\t},\n\t\t\tcontext.corsHeaders,\n\t\t\treq,\n\t\t);\n\t\treturn;\n\t}\n\n\tsendJson(\n\t\tres,\n\t\tresult.status === HostedRunnerDrainStatusValue.Interrupted ? 503 : 200,\n\t\t{\n\t\t\tprotocol_version: HOSTED_RUNNER_DRAIN_PROTOCOL_VERSION,\n\t\t\tstatus: result.status,\n\t\t\trunner_session_id: result.runner_session_id,\n\t\t\trequested_by: result.requested_by,\n\t\t\treason: result.reason,\n\t\t\tmanifest_path: result.manifest_path,\n\t\t\tmanifest: result.manifest,\n\t\t},\n\t\tcontext.corsHeaders,\n\t\treq,\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hosted-runner-drain.js","sourceRoot":"","sources":["../../../src/server/handlers/hosted-runner-drain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACN,0BAA0B,EAC1B,gCAAgC,EAChC,yBAAyB,EAEzB,yBAAyB,EACzB,iCAAiC,EACjC,oBAAoB,EACpB,sBAAsB,EACtB,6BAA6B,EAC7B,0BAA0B,EAC1B,WAAW,GACX,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EACN,oCAAoC,EAEpC,6BAA6B,GAC7B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEtE,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C,MAAM,CAAC,MAAM,wBAAwB,GACpC,0CAA0C,CAAC;AAE5C,MAAM,CAAC,MAAM,oCAAoC,GAChD,gCAAgC,CAAC;AAElC,MAAM,CAAC,MAAM,uCAAuC,GACnD,4CAA4C,CAAC;AAE9C,MAAM,CAAC,MAAM,sCAAsC,GAClD,oCAAoC,CAAC;AAEtC,MAAM,CAAC,MAAM,qCAAqC,GACjD,0CAA0C,CAAC;AAE5C,MAAM,CAAC,MAAM,uCAAuC,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CAAC,YAAY;QACjC,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,QAAQ,EAAE,MAAM,CAAC,QAAQ;KACzB,EACD,OAAO,CAAC,WAAW,EACnB,GAAG,CACH,CAAC;AACH,CAAC","sourcesContent":["import { execFile } from \"node:child_process\";\nimport { mkdir, realpath, stat, writeFile } from \"node:fs/promises\";\nimport type { IncomingMessage, ServerResponse } from \"node:http\";\nimport { isAbsolute, join, relative, resolve } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport {\n\tCODEX_SUBAGENT_TOOL_PREFIX,\n\tCODEX_SUBAGENT_WORK_GRAPH_SCHEMA,\n\tHEADLESS_PROTOCOL_VERSION,\n\ttype HeadlessCodexSubagentContinuityEdge,\n\tactiveCodexSubagentStatus,\n\tbuildCodexSubagentContinuityEdges,\n\tcodexSubagentEdgeKey,\n\tcodexSubagentOperation,\n\tcodexSubagentStatusIsTerminal,\n\tcreateHeadlessRuntimeState,\n\tstringArray,\n} from \"../../cli/headless-protocol.js\";\nimport type { HostedRunnerContext, WebServerContext } from \"../app-context.js\";\nimport type { HeadlessRuntimeSnapshot } from \"../headless-runtime-service.js\";\nimport {\n\tHOSTED_RUNNER_LEASE_PROTOCOL_VERSION,\n\ttype HostedRunnerLeaseSnapshot,\n\tmarkHostedRunnerLeaseDraining,\n} from \"../hosted-runner-lease.js\";\nimport { ApiError, readJsonBody, sendJson } from \"../server-utils.js\";\n\nconst execFileAsync = promisify(execFile);\n\nexport const HOSTED_RUNNER_DRAIN_PATH =\n\t\"/.well-known/evalops/remote-runner/drain\";\n\nexport const HOSTED_RUNNER_DRAIN_PROTOCOL_VERSION =\n\t\"evalops.remote-runner.drain.v1\";\n\nexport const HOSTED_RUNNER_SNAPSHOT_MANIFEST_VERSION =\n\t\"evalops.remote-runner.snapshot-manifest.v1\";\n\nexport const HOSTED_RUNNER_RETENTION_POLICY_VERSION =\n\t\"evalops.remote-runner.retention.v1\";\n\nexport const HOSTED_RUNNER_WORK_CONTINUITY_VERSION =\n\t\"evalops.remote-runner.work-continuity.v1\";\n\nexport const HOSTED_RUNNER_PLATFORM_EVIDENCE_VERSION =\n\t\"evalops.remote-runner.platform-evidence.v1\";\n\nexport const HOSTED_RUNNER_RUNTIME_CONTINUITY_VERSION =\n\t\"evalops.remote-runner.runtime-continuity.v1\";\n\nexport enum HostedRunnerDrainStatusValue {\n\tDrained = \"drained\",\n\tInterrupted = \"interrupted\",\n}\n\nexport enum HostedRunnerRuntimeFlushStatusValue {\n\tCompleted = \"completed\",\n\tFailed = \"failed\",\n\tSkipped = \"skipped\",\n}\n\nexport enum HostedRunnerWorkspaceExportPathTypeValue {\n\tFile = \"file\",\n\tDirectory = \"directory\",\n\tOther = \"other\",\n}\n\nexport enum HostedRunnerWorkspaceExportModeValue {\n\tLocalPathContract = \"local_path_contract\",\n}\n\nexport enum HostedRunnerDrainReasonValue {\n\tKubernetesPreStop = \"kubernetes_prestop\",\n\tProcessShutdown = \"process_shutdown\",\n}\n\nexport enum HostedRunnerDrainRequestedByValue {\n\tKubernetesPreStop = \"kubernetes_prestop\",\n\tMaestroWebServer = \"maestro_web_server\",\n}\n\nexport type HostedRunnerDrainStatus = HostedRunnerDrainStatusValue;\nexport type HostedRunnerRuntimeFlushStatus =\n\tHostedRunnerRuntimeFlushStatusValue;\nexport type HostedRunnerWorkspaceExportPathType =\n\tHostedRunnerWorkspaceExportPathTypeValue;\nexport type HostedRunnerWorkspaceExportMode =\n\tHostedRunnerWorkspaceExportModeValue;\nexport type HostedRunnerDrainReason = HostedRunnerDrainReasonValue | string;\nexport type HostedRunnerDrainRequestedBy =\n\t| HostedRunnerDrainRequestedByValue\n\t| string;\n\nexport interface HostedRunnerRetentionPolicy {\n\tpolicy_version: typeof HOSTED_RUNNER_RETENTION_POLICY_VERSION;\n\tmanaged_by: \"platform\";\n\tvisibility: {\n\t\tcontrol_plane_metadata: \"operator\";\n\t\tworkspace_export: \"tenant\";\n\t\truntime_snapshot: \"internal\";\n\t\truntime_logs: \"operator\";\n\t};\n\tredaction: {\n\t\trequired_before_external_persistence: Array<\n\t\t\t\"runtime_snapshot\" | \"runtime_logs\"\n\t\t>;\n\t\tforbidden_plaintext: Array<\n\t\t\t| \"provider_credentials\"\n\t\t\t| \"tool_secrets\"\n\t\t\t| \"attach_tokens\"\n\t\t\t| \"artifact_access_tokens\"\n\t\t\t| \"raw_environment\"\n\t\t>;\n\t};\n}\n\nexport interface HostedRunnerDrainInput {\n\treason?: HostedRunnerDrainReason;\n\trequestedBy?: HostedRunnerDrainRequestedBy;\n\texportPaths?: string[];\n}\n\nexport interface HostedRunnerRuntimeDrainResult {\n\tsessionId: string;\n\tsessionFile?: string;\n\tprotocolVersion?: string;\n\tcursor?: number;\n\tsnapshot?: HeadlessRuntimeSnapshot;\n\trecordPlatformDrain?: (\n\t\tinput: HostedRunnerPlatformDrainRecordInput,\n\t) => Promise<void>;\n}\n\nclass HostedRunnerRuntimeDrainError extends Error {\n\treadonly sessionId: string;\n\treadonly sessionFile?: string;\n\treadonly protocolVersion?: string;\n\treadonly cursor?: number;\n\treadonly snapshot?: HeadlessRuntimeSnapshot;\n\treadonly recordPlatformDrain?: (\n\t\tinput: HostedRunnerPlatformDrainRecordInput,\n\t) => Promise<void>;\n\n\tconstructor(message: string, runtime: HostedRunnerRuntimeDrainResult) {\n\t\tsuper(message);\n\t\tthis.name = \"HostedRunnerRuntimeDrainError\";\n\t\tthis.sessionId = runtime.sessionId;\n\t\tthis.sessionFile = runtime.sessionFile;\n\t\tthis.protocolVersion = runtime.protocolVersion;\n\t\tthis.cursor = runtime.cursor;\n\t\tthis.snapshot = runtime.snapshot;\n\t\tthis.recordPlatformDrain = runtime.recordPlatformDrain;\n\t}\n}\n\nexport interface HostedRunnerWorkspaceExportPath {\n\tinput: string;\n\tpath: string;\n\trelative_path: string;\n\ttype: HostedRunnerWorkspaceExportPathType;\n}\n\nexport interface HostedRunnerSnapshotManifest {\n\tprotocol_version: typeof HOSTED_RUNNER_SNAPSHOT_MANIFEST_VERSION;\n\trunner_session_id: string;\n\tworkspace_id?: string;\n\tagent_run_id?: string;\n\tmaestro_session_id: string;\n\treason?: string;\n\trequested_by?: string;\n\tcreated_at: string;\n\tworkspace_root: string;\n\truntime: {\n\t\tflush_status: HostedRunnerRuntimeFlushStatus;\n\t\terror?: string;\n\t\tsession_id: string;\n\t\tsession_file?: string;\n\t\tprotocol_version?: string;\n\t\tcursor?: number;\n\t};\n\tworkspace_export: {\n\t\tmode: HostedRunnerWorkspaceExportMode;\n\t\tpaths: HostedRunnerWorkspaceExportPath[];\n\t};\n\truntime_continuity: HostedRunnerRuntimeContinuity;\n\twork_continuity: HostedRunnerWorkContinuity;\n\tplatform_evidence: HostedRunnerPlatformEvidence;\n\tsnapshot: HeadlessRuntimeSnapshot;\n\tretention_policy: HostedRunnerRetentionPolicy;\n\tgit?: {\n\t\tcommit?: string;\n\t\tbranch?: string;\n\t\tdirty?: boolean;\n\t};\n}\n\nexport interface HostedRunnerRuntimeContinuity {\n\tprotocol_version: typeof HOSTED_RUNNER_RUNTIME_CONTINUITY_VERSION;\n\thandoff: \"drain_restore\";\n\tsource_runner_session_id: string;\n\tsource_owner_instance_id?: string;\n\tsource_process_id: number;\n\tsource_runtime_lease?: {\n\t\tprotocol_version: typeof HOSTED_RUNNER_LEASE_PROTOCOL_VERSION;\n\t\tstate: HostedRunnerLeaseSnapshot[\"state\"];\n\t\tgeneration: number;\n\t\tmaestro_session_id?: string;\n\t\tupdated_at: string;\n\t};\n\trestore_environment_key: \"MAESTRO_REMOTE_RUNNER_RESTORE_MANIFEST\";\n\trestore_manifest_path: string;\n\tevidence_refs: string[];\n}\n\nexport interface HostedRunnerWorkContinuity {\n\tprotocol_version: typeof HOSTED_RUNNER_WORK_CONTINUITY_VERSION;\n\tcodex_subagent_schema_version: typeof CODEX_SUBAGENT_WORK_GRAPH_SCHEMA;\n\tactive_tool_count: number;\n\ttracked_tool_count: number;\n\tpending_request_count: number;\n\tcodex_subagent_tool_call_ids: string[];\n\tcodex_subagent_child_run_ids: string[];\n\tcodex_subagent_thread_ids: string[];\n\tcodex_subagent_edges?: HeadlessCodexSubagentContinuityEdge[];\n}\n\nexport interface HostedRunnerPlatformEvidence {\n\tprotocol_version: typeof HOSTED_RUNNER_PLATFORM_EVIDENCE_VERSION;\n\tevent_type: \"hosted_runner_drain_manifest_recorded\";\n\trunner_session_id: string;\n\tworkspace_id?: string;\n\tagent_run_id?: string;\n\tmaestro_session_id: string;\n\tstatus: HostedRunnerDrainStatus;\n\truntime_flush_status: HostedRunnerRuntimeFlushStatus;\n\tmanifest_path: string;\n\tmanifest_protocol_version: typeof HOSTED_RUNNER_SNAPSHOT_MANIFEST_VERSION;\n\tcreated_at: string;\n\treason?: string;\n\trequested_by?: string;\n\twork_continuity: {\n\t\tprotocol_version: typeof HOSTED_RUNNER_WORK_CONTINUITY_VERSION;\n\t\tcodex_subagent_schema_version: typeof CODEX_SUBAGENT_WORK_GRAPH_SCHEMA;\n\t\tactive_tool_count: number;\n\t\ttracked_tool_count: number;\n\t\tpending_request_count: number;\n\t\tcodex_subagent_tool_call_count: number;\n\t\tcodex_subagent_child_run_count: number;\n\t\tcodex_subagent_thread_count: number;\n\t\tcodex_subagent_edge_count: number;\n\t\tcodex_subagent_tool_call_ids: string[];\n\t\tcodex_subagent_child_run_ids: string[];\n\t\tcodex_subagent_thread_ids: string[];\n\t\tcodex_subagent_edges?: HeadlessCodexSubagentContinuityEdge[];\n\t};\n\truntime_continuity: {\n\t\tprotocol_version: typeof HOSTED_RUNNER_RUNTIME_CONTINUITY_VERSION;\n\t\thandoff: \"drain_restore\";\n\t\tsource_owner_instance_id?: string;\n\t\tsource_process_id: number;\n\t\tsource_runtime_lease_generation?: number;\n\t\trestore_manifest_path: string;\n\t};\n\tretention: {\n\t\tpolicy_version: typeof HOSTED_RUNNER_RETENTION_POLICY_VERSION;\n\t\tcontrol_plane_metadata_visibility: \"operator\";\n\t\truntime_snapshot_visibility: \"internal\";\n\t\tredaction_required_before_external_persistence: Array<\n\t\t\t\"runtime_snapshot\" | \"runtime_logs\"\n\t\t>;\n\t};\n\tevidence_refs: string[];\n}\n\nexport interface HostedRunnerPlatformDrainRecordInput {\n\tstatus: HostedRunnerDrainStatus;\n\treason?: string;\n\trequestedBy?: string;\n\tflushStatus: HostedRunnerRuntimeFlushStatus;\n\tmanifestPath: string;\n\tplatformEvidence: HostedRunnerPlatformEvidence;\n\terrorMessage?: string;\n}\n\nexport interface HostedRunnerDrainResult {\n\tstatus: HostedRunnerDrainStatus;\n\trunner_session_id: string;\n\treason?: string;\n\trequested_by?: string;\n\tmanifest_path: string;\n\tmanifest: HostedRunnerSnapshotManifest;\n}\n\nexport interface DrainHostedRunnerOptions {\n\thostedRunner?: HostedRunnerContext;\n\tdrainRuntime?: (\n\t\tsessionId: string,\n\t\tterminal: HostedRunnerRuntimeTerminalInput,\n\t) => Promise<HostedRunnerRuntimeDrainResult | null>;\n\tnow?: () => Date;\n}\n\ninterface HostedRunnerDrainRuntimeContext {\n\thostedRunner?: HostedRunnerContext;\n\theadlessRuntimeService: Pick<\n\t\tWebServerContext[\"headlessRuntimeService\"],\n\t\t\"getRuntimeBySessionId\"\n\t>;\n}\n\nexport interface DrainHostedRunnerForShutdownOptions {\n\tnow?: () => Date;\n\treason?: HostedRunnerDrainReason;\n\trequestedBy?: HostedRunnerDrainRequestedBy;\n}\n\ninterface HostedRunnerRuntimeTerminalInput {\n\treason?: HostedRunnerDrainReason;\n\trequestedBy?: HostedRunnerDrainRequestedBy;\n\tmanifestPath?: string;\n}\n\nfunction getString(value: unknown, field: string): string | undefined {\n\tif (value === undefined || value === null) {\n\t\treturn undefined;\n\t}\n\tif (typeof value !== \"string\") {\n\t\tthrow new ApiError(400, `${field} must be a string`);\n\t}\n\tconst trimmed = value.trim();\n\treturn trimmed || undefined;\n}\n\nfunction getStringArray(value: unknown, field: string): string[] | undefined {\n\tif (value === undefined || value === null) {\n\t\treturn undefined;\n\t}\n\tif (!Array.isArray(value)) {\n\t\tthrow new ApiError(400, `${field} must be an array of strings`);\n\t}\n\tconst strings = value.map((entry, index) => {\n\t\tif (typeof entry !== \"string\" || !entry.trim()) {\n\t\t\tthrow new ApiError(400, `${field}[${index}] must be a non-empty string`);\n\t\t}\n\t\tif (entry.includes(\"\\0\")) {\n\t\t\tthrow new ApiError(400, `${field}[${index}] contains a null byte`);\n\t\t}\n\t\treturn entry.trim();\n\t});\n\treturn strings.length ? strings : undefined;\n}\n\nexport function parseHostedRunnerDrainInput(\n\tbody: unknown,\n): HostedRunnerDrainInput {\n\tif (body === undefined || body === null) {\n\t\treturn {};\n\t}\n\tif (typeof body !== \"object\" || Array.isArray(body)) {\n\t\tthrow new ApiError(400, \"Drain payload must be a JSON object\");\n\t}\n\tconst record = body as Record<string, unknown>;\n\treturn {\n\t\treason:\n\t\t\tgetString(record.reason, \"reason\") ??\n\t\t\tgetString(record.stop_reason, \"stop_reason\"),\n\t\trequestedBy:\n\t\t\tgetString(record.requested_by, \"requested_by\") ??\n\t\t\tgetString(record.requestedBy, \"requestedBy\"),\n\t\texportPaths:\n\t\t\tgetStringArray(record.export_paths, \"export_paths\") ??\n\t\t\tgetStringArray(record.exportPaths, \"exportPaths\"),\n\t};\n}\n\nfunction isWithinPath(root: string, target: string): boolean {\n\tconst rel = relative(root, target);\n\treturn rel === \"\" || (!rel.startsWith(\"..\") && !isAbsolute(rel));\n}\n\nfunction safeManifestFileName(\n\trunnerSessionId: string,\n\trequestedAt: string,\n): string {\n\tconst safeSession = runnerSessionId.replace(/[^A-Za-z0-9_.-]/g, \"_\");\n\tconst safeTimestamp = requestedAt.replace(/[^A-Za-z0-9_.-]/g, \"_\");\n\treturn `${safeSession}-${safeTimestamp}.json`;\n}\n\nasync function resolveWorkspaceRoot(\n\thostedRunner: HostedRunnerContext,\n): Promise<string> {\n\ttry {\n\t\tconst workspaceRoot = await realpath(hostedRunner.workspaceRoot);\n\t\tconst stats = await stat(workspaceRoot);\n\t\tif (!stats.isDirectory()) {\n\t\t\tthrow new ApiError(\n\t\t\t\t503,\n\t\t\t\t\"Hosted runner workspace root is not a directory\",\n\t\t\t);\n\t\t}\n\t\treturn workspaceRoot;\n\t} catch (error) {\n\t\tif (error instanceof ApiError) {\n\t\t\tthrow error;\n\t\t}\n\t\tthrow new ApiError(\n\t\t\t503,\n\t\t\t`Hosted runner workspace root is unavailable: ${\n\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t}`,\n\t\t);\n\t}\n}\n\nasync function resolveWorkspaceExportPaths(\n\tworkspaceRoot: string,\n\texportPaths: readonly string[] | undefined,\n): Promise<HostedRunnerWorkspaceExportPath[]> {\n\tconst requested = exportPaths?.length ? exportPaths : [\".\"];\n\tconst paths: HostedRunnerWorkspaceExportPath[] = [];\n\tfor (const input of requested) {\n\t\tconst logicalPath = isAbsolute(input)\n\t\t\t? resolve(input)\n\t\t\t: resolve(workspaceRoot, input);\n\t\tlet realPath: string;\n\t\ttry {\n\t\t\trealPath = await realpath(logicalPath);\n\t\t} catch (error) {\n\t\t\tthrow new ApiError(\n\t\t\t\t400,\n\t\t\t\t`Export path is unavailable: ${input} (${\n\t\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t\t})`,\n\t\t\t);\n\t\t}\n\t\tif (!isWithinPath(workspaceRoot, realPath)) {\n\t\t\tthrow new ApiError(\n\t\t\t\t400,\n\t\t\t\t`Export path escapes hosted runner workspace root: ${input}`,\n\t\t\t);\n\t\t}\n\t\tconst pathStat = await stat(realPath);\n\t\tpaths.push({\n\t\t\tinput,\n\t\t\tpath: realPath,\n\t\t\trelative_path: relative(workspaceRoot, realPath) || \".\",\n\t\t\ttype: pathStat.isDirectory()\n\t\t\t\t? HostedRunnerWorkspaceExportPathTypeValue.Directory\n\t\t\t\t: pathStat.isFile()\n\t\t\t\t\t? HostedRunnerWorkspaceExportPathTypeValue.File\n\t\t\t\t\t: HostedRunnerWorkspaceExportPathTypeValue.Other,\n\t\t});\n\t}\n\treturn paths;\n}\n\nasync function gitOutput(\n\tworkspaceRoot: string,\n\targs: readonly string[],\n): Promise<string | undefined> {\n\ttry {\n\t\tconst { stdout } = await execFileAsync(\n\t\t\t\"git\",\n\t\t\t[\"-C\", workspaceRoot, ...args],\n\t\t\t{\n\t\t\t\tencoding: \"utf8\",\n\t\t\t\ttimeout: 1000,\n\t\t\t},\n\t\t);\n\t\tconst output = stdout.trim();\n\t\treturn output || undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nasync function collectGitState(\n\tworkspaceRoot: string,\n): Promise<HostedRunnerSnapshotManifest[\"git\"] | undefined> {\n\tconst [commit, branch, status] = await Promise.all([\n\t\tgitOutput(workspaceRoot, [\"rev-parse\", \"HEAD\"]),\n\t\tgitOutput(workspaceRoot, [\"rev-parse\", \"--abbrev-ref\", \"HEAD\"]),\n\t\tgitOutput(workspaceRoot, [\"status\", \"--porcelain\"]),\n\t]);\n\tif (!commit && !branch && status === undefined) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\t...(commit ? { commit } : {}),\n\t\t...(branch && branch !== \"HEAD\" ? { branch } : {}),\n\t\tdirty: Boolean(status),\n\t};\n}\n\nfunction buildHostedRunnerSnapshot(\n\tsessionId: string,\n\tworkspaceRoot: string,\n\truntime: HostedRunnerSnapshotManifest[\"runtime\"],\n): HeadlessRuntimeSnapshot {\n\tconst state = createHeadlessRuntimeState();\n\tstate.protocol_version =\n\t\truntime.protocol_version ?? HEADLESS_PROTOCOL_VERSION;\n\tstate.session_id = sessionId;\n\tstate.cwd = workspaceRoot;\n\tstate.provider = \"typescript\";\n\tstate.model = \"typescript-hosted-runner\";\n\tstate.is_ready =\n\t\truntime.flush_status === HostedRunnerRuntimeFlushStatusValue.Completed;\n\tstate.last_status =\n\t\truntime.flush_status === HostedRunnerRuntimeFlushStatusValue.Completed\n\t\t\t? \"Drained\"\n\t\t\t: runtime.flush_status === HostedRunnerRuntimeFlushStatusValue.Failed\n\t\t\t\t? \"Drain interrupted before runtime flush completed\"\n\t\t\t\t: \"Drain skipped: no runtime activity was available\";\n\tif (runtime.error) {\n\t\tstate.last_error = runtime.error;\n\t\tstate.last_error_type = \"protocol\";\n\t}\n\treturn {\n\t\tprotocolVersion: runtime.protocol_version ?? HEADLESS_PROTOCOL_VERSION,\n\t\tsession_id: sessionId,\n\t\tcursor: runtime.cursor ?? 0,\n\t\tlast_init: null,\n\t\tstate,\n\t};\n}\n\nfunction buildHostedRunnerRetentionPolicy(): HostedRunnerRetentionPolicy {\n\treturn {\n\t\tpolicy_version: HOSTED_RUNNER_RETENTION_POLICY_VERSION,\n\t\tmanaged_by: \"platform\",\n\t\tvisibility: {\n\t\t\tcontrol_plane_metadata: \"operator\",\n\t\t\tworkspace_export: \"tenant\",\n\t\t\truntime_snapshot: \"internal\",\n\t\t\truntime_logs: \"operator\",\n\t\t},\n\t\tredaction: {\n\t\t\trequired_before_external_persistence: [\n\t\t\t\t\"runtime_snapshot\",\n\t\t\t\t\"runtime_logs\",\n\t\t\t],\n\t\t\tforbidden_plaintext: [\n\t\t\t\t\"provider_credentials\",\n\t\t\t\t\"tool_secrets\",\n\t\t\t\t\"attach_tokens\",\n\t\t\t\t\"artifact_access_tokens\",\n\t\t\t\t\"raw_environment\",\n\t\t\t],\n\t\t},\n\t};\n}\n\nfunction buildHostedRunnerRuntimeContinuity(input: {\n\thostedRunner: HostedRunnerContext;\n\tmaestroSessionId: string;\n\tmanifestPath: string;\n\truntime: HostedRunnerSnapshotManifest[\"runtime\"];\n\tleaseSnapshot: HostedRunnerLeaseSnapshot;\n}): HostedRunnerRuntimeContinuity {\n\treturn {\n\t\tprotocol_version: HOSTED_RUNNER_RUNTIME_CONTINUITY_VERSION,\n\t\thandoff: \"drain_restore\",\n\t\tsource_runner_session_id: input.hostedRunner.runnerSessionId,\n\t\t...(input.hostedRunner.ownerInstanceId\n\t\t\t? { source_owner_instance_id: input.hostedRunner.ownerInstanceId }\n\t\t\t: {}),\n\t\tsource_process_id: process.pid,\n\t\tsource_runtime_lease: {\n\t\t\tprotocol_version: HOSTED_RUNNER_LEASE_PROTOCOL_VERSION,\n\t\t\tstate: input.leaseSnapshot.state,\n\t\t\tgeneration: input.leaseSnapshot.generation,\n\t\t\t...(input.leaseSnapshot.maestroSessionId\n\t\t\t\t? { maestro_session_id: input.leaseSnapshot.maestroSessionId }\n\t\t\t\t: {}),\n\t\t\tupdated_at: input.leaseSnapshot.updatedAt,\n\t\t},\n\t\trestore_environment_key: \"MAESTRO_REMOTE_RUNNER_RESTORE_MANIFEST\",\n\t\trestore_manifest_path: input.manifestPath,\n\t\tevidence_refs: [\n\t\t\t`remote-runner://sessions/${input.hostedRunner.runnerSessionId}/drain#snapshot`,\n\t\t\t`maestro://headless/sessions/${input.maestroSessionId}#cursor:${\n\t\t\t\tinput.runtime.cursor ?? 0\n\t\t\t}`,\n\t\t],\n\t};\n}\n\nfunction buildHostedRunnerPlatformEvidence(input: {\n\thostedRunner: HostedRunnerContext;\n\tstatus: HostedRunnerDrainStatus;\n\tmaestroSessionId: string;\n\tcreatedAt: string;\n\tmanifestPath: string;\n\truntime: HostedRunnerSnapshotManifest[\"runtime\"];\n\truntimeContinuity: HostedRunnerRuntimeContinuity;\n\tworkContinuity: HostedRunnerWorkContinuity;\n\tretentionPolicy: HostedRunnerRetentionPolicy;\n\treason?: string;\n\trequestedBy?: string;\n}): HostedRunnerPlatformEvidence {\n\tconst edges = input.workContinuity.codex_subagent_edges ?? [];\n\treturn {\n\t\tprotocol_version: HOSTED_RUNNER_PLATFORM_EVIDENCE_VERSION,\n\t\tevent_type: \"hosted_runner_drain_manifest_recorded\",\n\t\trunner_session_id: input.hostedRunner.runnerSessionId,\n\t\t...(input.hostedRunner.workspaceId\n\t\t\t? { workspace_id: input.hostedRunner.workspaceId }\n\t\t\t: {}),\n\t\t...(input.hostedRunner.agentRunId\n\t\t\t? { agent_run_id: input.hostedRunner.agentRunId }\n\t\t\t: {}),\n\t\tmaestro_session_id: input.maestroSessionId,\n\t\tstatus: input.status,\n\t\truntime_flush_status: input.runtime.flush_status,\n\t\tmanifest_path: input.manifestPath,\n\t\tmanifest_protocol_version: HOSTED_RUNNER_SNAPSHOT_MANIFEST_VERSION,\n\t\tcreated_at: input.createdAt,\n\t\t...(input.reason ? { reason: input.reason } : {}),\n\t\t...(input.requestedBy ? { requested_by: input.requestedBy } : {}),\n\t\twork_continuity: {\n\t\t\tprotocol_version: input.workContinuity.protocol_version,\n\t\t\tcodex_subagent_schema_version:\n\t\t\t\tinput.workContinuity.codex_subagent_schema_version,\n\t\t\tactive_tool_count: input.workContinuity.active_tool_count,\n\t\t\ttracked_tool_count: input.workContinuity.tracked_tool_count,\n\t\t\tpending_request_count: input.workContinuity.pending_request_count,\n\t\t\tcodex_subagent_tool_call_count:\n\t\t\t\tinput.workContinuity.codex_subagent_tool_call_ids.length,\n\t\t\tcodex_subagent_child_run_count:\n\t\t\t\tinput.workContinuity.codex_subagent_child_run_ids.length,\n\t\t\tcodex_subagent_thread_count:\n\t\t\t\tinput.workContinuity.codex_subagent_thread_ids.length,\n\t\t\tcodex_subagent_edge_count: edges.length,\n\t\t\tcodex_subagent_tool_call_ids:\n\t\t\t\tinput.workContinuity.codex_subagent_tool_call_ids,\n\t\t\tcodex_subagent_child_run_ids:\n\t\t\t\tinput.workContinuity.codex_subagent_child_run_ids,\n\t\t\tcodex_subagent_thread_ids: input.workContinuity.codex_subagent_thread_ids,\n\t\t\t...(edges.length > 0 ? { codex_subagent_edges: edges } : {}),\n\t\t},\n\t\truntime_continuity: {\n\t\t\tprotocol_version: input.runtimeContinuity.protocol_version,\n\t\t\thandoff: input.runtimeContinuity.handoff,\n\t\t\t...(input.runtimeContinuity.source_owner_instance_id\n\t\t\t\t? {\n\t\t\t\t\t\tsource_owner_instance_id:\n\t\t\t\t\t\t\tinput.runtimeContinuity.source_owner_instance_id,\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\tsource_process_id: input.runtimeContinuity.source_process_id,\n\t\t\t...(input.runtimeContinuity.source_runtime_lease\n\t\t\t\t? {\n\t\t\t\t\t\tsource_runtime_lease_generation:\n\t\t\t\t\t\t\tinput.runtimeContinuity.source_runtime_lease.generation,\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\trestore_manifest_path: input.runtimeContinuity.restore_manifest_path,\n\t\t},\n\t\tretention: {\n\t\t\tpolicy_version: input.retentionPolicy.policy_version,\n\t\t\tcontrol_plane_metadata_visibility:\n\t\t\t\tinput.retentionPolicy.visibility.control_plane_metadata,\n\t\t\truntime_snapshot_visibility:\n\t\t\t\tinput.retentionPolicy.visibility.runtime_snapshot,\n\t\t\tredaction_required_before_external_persistence:\n\t\t\t\tinput.retentionPolicy.redaction.required_before_external_persistence,\n\t\t},\n\t\tevidence_refs: [\n\t\t\t`remote-runner://sessions/${input.hostedRunner.runnerSessionId}/drain#manifest`,\n\t\t\t`maestro://headless/sessions/${input.maestroSessionId}#drain`,\n\t\t\t...(input.hostedRunner.agentRunId\n\t\t\t\t? [`platform-agent-run:${input.hostedRunner.agentRunId}`]\n\t\t\t\t: []),\n\t\t],\n\t};\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn Boolean(value && typeof value === \"object\" && !Array.isArray(value));\n}\n\nfunction collectCodexSubagentEdgesFromSource(\n\tsource: {\n\t\tcall_id: string;\n\t\ttool_execution_id?: string;\n\t\ttool: string;\n\t\targs?: unknown;\n\t},\n\tedges: Map<string, HeadlessCodexSubagentContinuityEdge>,\n): void {\n\tconst operation = codexSubagentOperation(source.tool);\n\tif (!operation) {\n\t\treturn;\n\t}\n\tconst status = activeCodexSubagentStatus(operation);\n\tfor (const edge of buildCodexSubagentContinuityEdges({\n\t\tcall_id: source.call_id,\n\t\ttool_execution_id: source.tool_execution_id,\n\t\ttool: source.tool,\n\t\targs: source.args,\n\t\tstatus,\n\t})) {\n\t\tedges.set(codexSubagentEdgeKey(edge), edge);\n\t}\n}\n\nfunction collectCodexWorkArgs(\n\targs: unknown,\n\tchildRunIds: Set<string>,\n\tthreadIds: Set<string>,\n\tincludeLooseArgs = false,\n): boolean {\n\tif (!isRecord(args)) {\n\t\treturn false;\n\t}\n\tconst graph = args.codexWorkGraph ?? args.codex_work_graph;\n\tconst hasCodexGraph =\n\t\tisRecord(graph) &&\n\t\t(graph.schemaVersion === CODEX_SUBAGENT_WORK_GRAPH_SCHEMA ||\n\t\t\tgraph.schema_version === CODEX_SUBAGENT_WORK_GRAPH_SCHEMA);\n\tif (!includeLooseArgs && !hasCodexGraph) {\n\t\treturn false;\n\t}\n\tfor (const childRunId of stringArray(\n\t\targs.childRunIds ?? args.child_run_ids,\n\t)) {\n\t\tchildRunIds.add(childRunId);\n\t}\n\tfor (const threadId of stringArray(\n\t\targs.receiverThreadIds ?? args.receiver_thread_ids,\n\t)) {\n\t\tthreadIds.add(threadId);\n\t}\n\tif (isRecord(graph)) {\n\t\tconst graphChildRuns = graph.childRuns ?? graph.child_runs;\n\t\tfor (const childRun of Array.isArray(graphChildRuns)\n\t\t\t? graphChildRuns\n\t\t\t: []) {\n\t\t\tif (!isRecord(childRun)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst childRunId = childRun.childRunId ?? childRun.child_run_id;\n\t\t\tif (typeof childRunId === \"string\" && childRunId) {\n\t\t\t\tchildRunIds.add(childRunId);\n\t\t\t}\n\t\t\tconst threadId = childRun.threadId ?? childRun.thread_id;\n\t\t\tif (typeof threadId === \"string\" && threadId) {\n\t\t\t\tthreadIds.add(threadId);\n\t\t\t}\n\t\t}\n\t}\n\treturn includeLooseArgs || hasCodexGraph;\n}\n\nfunction collectHostedRunnerWorkContinuity(\n\tsnapshot: HeadlessRuntimeSnapshot,\n): HostedRunnerWorkContinuity {\n\tconst state = snapshot.state;\n\tconst codexToolCallIds = new Set<string>();\n\tconst childRunIds = new Set<string>();\n\tconst threadIds = new Set<string>();\n\tconst codexSubagentEdges = new Map<\n\t\tstring,\n\t\tHeadlessCodexSubagentContinuityEdge\n\t>();\n\tfor (const edge of state.codex_subagent_edges ?? []) {\n\t\tcodexSubagentEdges.set(codexSubagentEdgeKey(edge), edge);\n\t\tif (edge.spawn_tool_call_id) {\n\t\t\tcodexToolCallIds.add(edge.spawn_tool_call_id);\n\t\t}\n\t\tif (edge.wait_tool_call_id) {\n\t\t\tcodexToolCallIds.add(edge.wait_tool_call_id);\n\t\t}\n\t\tif (edge.child_run_id) {\n\t\t\tchildRunIds.add(edge.child_run_id);\n\t\t}\n\t\tif (edge.thread_id) {\n\t\t\tthreadIds.add(edge.thread_id);\n\t\t}\n\t}\n\tconst trackedSources = [\n\t\t...state.tracked_tools,\n\t\t...state.pending_approvals,\n\t\t...state.pending_client_tools,\n\t\t...state.pending_mcp_elicitations,\n\t\t...state.pending_user_inputs,\n\t\t...state.pending_tool_retries,\n\t];\n\tconst codexTrackedSourceCallIds = new Set<string>();\n\tfor (const source of trackedSources) {\n\t\tconst tool = source.tool;\n\t\tconst isCodexSubagentTool = tool.startsWith(CODEX_SUBAGENT_TOOL_PREFIX);\n\t\tconst hasCodexWorkArgs = collectCodexWorkArgs(\n\t\t\tsource.args,\n\t\t\tchildRunIds,\n\t\t\tthreadIds,\n\t\t\tisCodexSubagentTool,\n\t\t);\n\t\tif (isCodexSubagentTool || hasCodexWorkArgs) {\n\t\t\tcodexTrackedSourceCallIds.add(source.call_id);\n\t\t\tcodexToolCallIds.add(source.call_id);\n\t\t\tcollectCodexSubagentEdgesFromSource(source, codexSubagentEdges);\n\t\t}\n\t}\n\tfor (const activeTool of state.active_tools) {\n\t\tif (activeTool.tool.startsWith(CODEX_SUBAGENT_TOOL_PREFIX)) {\n\t\t\tconst hasTrackedSource = codexToolCallIds.has(activeTool.call_id);\n\t\t\tcodexToolCallIds.add(activeTool.call_id);\n\t\t\tif (!hasTrackedSource) {\n\t\t\t\tcollectCodexSubagentEdgesFromSource(\n\t\t\t\t\t{ call_id: activeTool.call_id, tool: activeTool.tool },\n\t\t\t\t\tcodexSubagentEdges,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\tconst sortedEdges = [...codexSubagentEdges.values()].sort((left, right) =>\n\t\tcodexSubagentEdgeKey(left).localeCompare(codexSubagentEdgeKey(right)),\n\t);\n\tconst activeCodexSubagentEdgeCount = sortedEdges.filter(\n\t\t(edge) => !codexSubagentStatusIsTerminal(edge.status),\n\t).length;\n\tconst nonCodexActiveToolCount = state.active_tools.filter(\n\t\t(tool) => !tool.tool.startsWith(CODEX_SUBAGENT_TOOL_PREFIX),\n\t).length;\n\tconst nonCodexTrackedToolCount = state.tracked_tools.filter(\n\t\t(tool) => !codexTrackedSourceCallIds.has(tool.call_id),\n\t).length;\n\tconst trackedCodexSubagentCount = Math.max(\n\t\tcodexToolCallIds.size,\n\t\tsortedEdges.length,\n\t);\n\treturn {\n\t\tprotocol_version: HOSTED_RUNNER_WORK_CONTINUITY_VERSION,\n\t\tcodex_subagent_schema_version: CODEX_SUBAGENT_WORK_GRAPH_SCHEMA,\n\t\tactive_tool_count:\n\t\t\tsortedEdges.length > 0\n\t\t\t\t? nonCodexActiveToolCount + activeCodexSubagentEdgeCount\n\t\t\t\t: state.active_tools.length,\n\t\ttracked_tool_count:\n\t\t\tsortedEdges.length > 0\n\t\t\t\t? nonCodexTrackedToolCount + trackedCodexSubagentCount\n\t\t\t\t: state.tracked_tools.length,\n\t\tpending_request_count:\n\t\t\tstate.pending_approvals.length +\n\t\t\tstate.pending_client_tools.length +\n\t\t\tstate.pending_mcp_elicitations.length +\n\t\t\tstate.pending_user_inputs.length +\n\t\t\tstate.pending_tool_retries.length,\n\t\tcodex_subagent_tool_call_ids: [...codexToolCallIds].sort(),\n\t\tcodex_subagent_child_run_ids: [...childRunIds].sort(),\n\t\tcodex_subagent_thread_ids: [...threadIds].sort(),\n\t\t...(sortedEdges.length > 0 ? { codex_subagent_edges: sortedEdges } : {}),\n\t};\n}\n\nexport async function drainHostedRunner(\n\tinput: HostedRunnerDrainInput,\n\toptions: DrainHostedRunnerOptions,\n): Promise<HostedRunnerDrainResult | null> {\n\tconst hostedRunner = options.hostedRunner;\n\tif (!hostedRunner?.enabled || !hostedRunner.runnerSessionId) {\n\t\treturn null;\n\t}\n\n\tconst requestedAtDate = options.now?.() ?? new Date();\n\tconst leaseSnapshot = markHostedRunnerLeaseDraining(\n\t\thostedRunner,\n\t\trequestedAtDate,\n\t);\n\tconst requestedAt = requestedAtDate.toISOString();\n\tconst workspaceRoot = await resolveWorkspaceRoot(hostedRunner);\n\tconst snapshotRoot = resolve(\n\t\tworkspaceRoot,\n\t\thostedRunner.snapshotRoot ?? \".maestro/runner-snapshots\",\n\t);\n\tawait mkdir(snapshotRoot, { recursive: true });\n\tconst snapshotPath = join(\n\t\tsnapshotRoot,\n\t\tsafeManifestFileName(hostedRunner.runnerSessionId, requestedAt),\n\t);\n\tconst exportPaths = await resolveWorkspaceExportPaths(\n\t\tworkspaceRoot,\n\t\tinput.exportPaths,\n\t);\n\tconst activeSessionId =\n\t\thostedRunner.activeMaestroSessionId ??\n\t\thostedRunner.configuredMaestroSessionId;\n\tconst maestroSessionId = activeSessionId ?? hostedRunner.runnerSessionId;\n\n\tlet status: HostedRunnerDrainStatus = HostedRunnerDrainStatusValue.Drained;\n\tlet runtime: HostedRunnerSnapshotManifest[\"runtime\"] = {\n\t\tflush_status: HostedRunnerRuntimeFlushStatusValue.Skipped,\n\t\tsession_id: maestroSessionId,\n\t};\n\tlet runtimeSnapshot: HeadlessRuntimeSnapshot | undefined;\n\tlet recordPlatformDrain:\n\t\t| ((input: HostedRunnerPlatformDrainRecordInput) => Promise<void>)\n\t\t| undefined;\n\n\tif (activeSessionId && options.drainRuntime) {\n\t\ttry {\n\t\t\tconst runtimeResult = await options.drainRuntime(activeSessionId, {\n\t\t\t\treason: input.reason,\n\t\t\t\trequestedBy: input.requestedBy,\n\t\t\t\tmanifestPath: snapshotPath,\n\t\t\t});\n\t\t\tconst runtimeProtocolVersion =\n\t\t\t\truntimeResult?.protocolVersion ??\n\t\t\t\truntimeResult?.snapshot?.protocolVersion;\n\t\t\tconst runtimeCursor =\n\t\t\t\truntimeResult?.cursor ?? runtimeResult?.snapshot?.cursor;\n\t\t\truntime = runtimeResult\n\t\t\t\t? {\n\t\t\t\t\t\tflush_status: HostedRunnerRuntimeFlushStatusValue.Completed,\n\t\t\t\t\t\tsession_id: runtimeResult.sessionId,\n\t\t\t\t\t\t...(runtimeResult.sessionFile\n\t\t\t\t\t\t\t? { session_file: runtimeResult.sessionFile }\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t...(runtimeProtocolVersion\n\t\t\t\t\t\t\t? { protocol_version: runtimeProtocolVersion }\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t...(runtimeCursor !== undefined ? { cursor: runtimeCursor } : {}),\n\t\t\t\t\t}\n\t\t\t\t: {\n\t\t\t\t\t\tflush_status: HostedRunnerRuntimeFlushStatusValue.Skipped,\n\t\t\t\t\t\tsession_id: activeSessionId,\n\t\t\t\t\t};\n\t\t\truntimeSnapshot = runtimeResult?.snapshot;\n\t\t\trecordPlatformDrain = runtimeResult?.recordPlatformDrain;\n\t\t} catch (error) {\n\t\t\tstatus = HostedRunnerDrainStatusValue.Interrupted;\n\t\t\tconst interruptedRuntime =\n\t\t\t\terror instanceof HostedRunnerRuntimeDrainError ? error : undefined;\n\t\t\truntimeSnapshot = interruptedRuntime?.snapshot;\n\t\t\trecordPlatformDrain = interruptedRuntime?.recordPlatformDrain;\n\t\t\truntime = {\n\t\t\t\tflush_status: HostedRunnerRuntimeFlushStatusValue.Failed,\n\t\t\t\tsession_id: interruptedRuntime?.sessionId ?? activeSessionId,\n\t\t\t\t...(interruptedRuntime?.sessionFile\n\t\t\t\t\t? { session_file: interruptedRuntime.sessionFile }\n\t\t\t\t\t: {}),\n\t\t\t\t...(interruptedRuntime?.protocolVersion\n\t\t\t\t\t? { protocol_version: interruptedRuntime.protocolVersion }\n\t\t\t\t\t: {}),\n\t\t\t\t...(interruptedRuntime?.cursor !== undefined\n\t\t\t\t\t? { cursor: interruptedRuntime.cursor }\n\t\t\t\t\t: {}),\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t};\n\t\t}\n\t}\n\n\tconst git = await collectGitState(workspaceRoot);\n\tconst snapshot =\n\t\truntimeSnapshot ??\n\t\tbuildHostedRunnerSnapshot(maestroSessionId, workspaceRoot, runtime);\n\tconst workContinuity = collectHostedRunnerWorkContinuity(snapshot);\n\tconst retentionPolicy = buildHostedRunnerRetentionPolicy();\n\tconst runtimeContinuity = buildHostedRunnerRuntimeContinuity({\n\t\thostedRunner,\n\t\tmaestroSessionId,\n\t\tmanifestPath: snapshotPath,\n\t\truntime,\n\t\tleaseSnapshot,\n\t});\n\tconst platformEvidence = buildHostedRunnerPlatformEvidence({\n\t\thostedRunner,\n\t\tstatus,\n\t\tmaestroSessionId,\n\t\tcreatedAt: requestedAt,\n\t\tmanifestPath: snapshotPath,\n\t\truntime,\n\t\truntimeContinuity,\n\t\tworkContinuity,\n\t\tretentionPolicy,\n\t\treason: input.reason,\n\t\trequestedBy: input.requestedBy,\n\t});\n\tconst manifest: HostedRunnerSnapshotManifest = {\n\t\tprotocol_version: HOSTED_RUNNER_SNAPSHOT_MANIFEST_VERSION,\n\t\trunner_session_id: hostedRunner.runnerSessionId,\n\t\t...(hostedRunner.workspaceId\n\t\t\t? { workspace_id: hostedRunner.workspaceId }\n\t\t\t: {}),\n\t\t...(hostedRunner.agentRunId\n\t\t\t? { agent_run_id: hostedRunner.agentRunId }\n\t\t\t: {}),\n\t\tmaestro_session_id: maestroSessionId,\n\t\t...(input.reason ? { reason: input.reason } : {}),\n\t\t...(input.requestedBy ? { requested_by: input.requestedBy } : {}),\n\t\tcreated_at: requestedAt,\n\t\tworkspace_root: workspaceRoot,\n\t\truntime,\n\t\tworkspace_export: {\n\t\t\tmode: HostedRunnerWorkspaceExportModeValue.LocalPathContract,\n\t\t\tpaths: exportPaths,\n\t\t},\n\t\truntime_continuity: runtimeContinuity,\n\t\twork_continuity: workContinuity,\n\t\tplatform_evidence: platformEvidence,\n\t\tsnapshot,\n\t\tretention_policy: retentionPolicy,\n\t\t...(git ? { git } : {}),\n\t};\n\n\ttry {\n\t\tawait writeFile(\n\t\t\tsnapshotPath,\n\t\t\t`${JSON.stringify(manifest, null, 2)}\\n`,\n\t\t\t\"utf8\",\n\t\t);\n\t\thostedRunner.lastDrain = {\n\t\t\tstatus,\n\t\t\tmanifestPath: snapshotPath,\n\t\t\tdrainedAt: requestedAt,\n\t\t\t...(input.reason ? { reason: input.reason } : {}),\n\t\t\t...(input.requestedBy ? { requestedBy: input.requestedBy } : {}),\n\t\t};\n\t} catch (error) {\n\t\tconst errorMessage = `Hosted runner drain manifest persistence failed: ${\n\t\t\terror instanceof Error ? error.message : String(error)\n\t\t}`;\n\t\tawait recordPlatformDrain?.({\n\t\t\tstatus: HostedRunnerDrainStatusValue.Interrupted,\n\t\t\treason: input.reason,\n\t\t\trequestedBy: input.requestedBy,\n\t\t\tflushStatus: runtime.flush_status,\n\t\t\tmanifestPath: snapshotPath,\n\t\t\tplatformEvidence: buildHostedRunnerPlatformEvidence({\n\t\t\t\thostedRunner,\n\t\t\t\tstatus: HostedRunnerDrainStatusValue.Interrupted,\n\t\t\t\tmaestroSessionId,\n\t\t\t\tcreatedAt: requestedAt,\n\t\t\t\tmanifestPath: snapshotPath,\n\t\t\t\truntime,\n\t\t\t\truntimeContinuity,\n\t\t\t\tworkContinuity,\n\t\t\t\tretentionPolicy,\n\t\t\t\treason: input.reason,\n\t\t\t\trequestedBy: input.requestedBy,\n\t\t\t}),\n\t\t\terrorMessage,\n\t\t});\n\t\tthrow error;\n\t}\n\tawait recordPlatformDrain?.({\n\t\tstatus,\n\t\treason: input.reason,\n\t\trequestedBy: input.requestedBy,\n\t\tflushStatus: runtime.flush_status,\n\t\tmanifestPath: snapshotPath,\n\t\tplatformEvidence,\n\t\terrorMessage: runtime.error,\n\t});\n\n\treturn {\n\t\tstatus,\n\t\trunner_session_id: hostedRunner.runnerSessionId,\n\t\t...(input.reason ? { reason: input.reason } : {}),\n\t\t...(input.requestedBy ? { requested_by: input.requestedBy } : {}),\n\t\tmanifest_path: snapshotPath,\n\t\tmanifest,\n\t};\n}\n\nasync function drainActiveRuntime(\n\tcontext: HostedRunnerDrainRuntimeContext,\n\tsessionId: string,\n\t_terminal: HostedRunnerRuntimeTerminalInput,\n): Promise<HostedRunnerRuntimeDrainResult | null> {\n\tconst runtime =\n\t\tcontext.headlessRuntimeService.getRuntimeBySessionId(sessionId);\n\tif (!runtime) {\n\t\treturn null;\n\t}\n\tconst snapshot = runtime.getSnapshot();\n\tconst sessionFile = runtime.getSessionFile();\n\tconst recordPlatformDrain = async (\n\t\tinput: HostedRunnerPlatformDrainRecordInput,\n\t) => {\n\t\tawait runtime.recordHostedAgentRuntimeDrain({\n\t\t\tstatus: input.status,\n\t\t\treason: input.reason,\n\t\t\trequestedBy: input.requestedBy,\n\t\t\tflushStatus: input.flushStatus,\n\t\t\tmanifestPath: input.manifestPath,\n\t\t\tplatformEvidence: input.platformEvidence,\n\t\t\terrorMessage: input.errorMessage\n\t\t\t\t? `Hosted runner drain failed: ${input.errorMessage}`\n\t\t\t\t: undefined,\n\t\t});\n\t};\n\ttry {\n\t\tawait runtime.dispose();\n\t} catch (error) {\n\t\tthrow new HostedRunnerRuntimeDrainError(\n\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t{\n\t\t\t\tsessionId: snapshot.session_id,\n\t\t\t\tsessionFile,\n\t\t\t\tprotocolVersion: snapshot.protocolVersion,\n\t\t\t\tcursor: snapshot.cursor,\n\t\t\t\tsnapshot,\n\t\t\t\trecordPlatformDrain,\n\t\t\t},\n\t\t);\n\t}\n\treturn {\n\t\tsessionId: snapshot.session_id,\n\t\tsessionFile,\n\t\tprotocolVersion: snapshot.protocolVersion,\n\t\tcursor: snapshot.cursor,\n\t\tsnapshot,\n\t\trecordPlatformDrain,\n\t};\n}\n\nexport async function drainHostedRunnerForShutdown(\n\tcontext: HostedRunnerDrainRuntimeContext,\n\toptions: DrainHostedRunnerForShutdownOptions = {},\n): Promise<HostedRunnerDrainResult | null> {\n\treturn drainHostedRunner(\n\t\t{\n\t\t\treason: options.reason ?? HostedRunnerDrainReasonValue.ProcessShutdown,\n\t\t\trequestedBy:\n\t\t\t\toptions.requestedBy ??\n\t\t\t\tHostedRunnerDrainRequestedByValue.MaestroWebServer,\n\t\t},\n\t\t{\n\t\t\thostedRunner: context.hostedRunner,\n\t\t\tdrainRuntime: (sessionId, terminal) =>\n\t\t\t\tdrainActiveRuntime(context, sessionId, terminal),\n\t\t\tnow: options.now,\n\t\t},\n\t);\n}\n\nexport async function handleHostedRunnerDrain(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n): Promise<void> {\n\tres.setHeader(\"Cache-Control\", \"no-store\");\n\tconst body = await readJsonBody<Record<string, unknown>>(req, 64_000);\n\tconst input = parseHostedRunnerDrainInput(body);\n\tconst result = await drainHostedRunner(input, {\n\t\thostedRunner: context.hostedRunner,\n\t\tdrainRuntime: (sessionId, terminal) =>\n\t\t\tdrainActiveRuntime(context, sessionId, terminal),\n\t});\n\n\tif (!result) {\n\t\tsendJson(\n\t\t\tres,\n\t\t\t404,\n\t\t\t{\n\t\t\t\terror: \"hosted runner drain unavailable\",\n\t\t\t},\n\t\t\tcontext.corsHeaders,\n\t\t\treq,\n\t\t);\n\t\treturn;\n\t}\n\n\tsendJson(\n\t\tres,\n\t\tresult.status === HostedRunnerDrainStatusValue.Interrupted ? 503 : 200,\n\t\t{\n\t\t\tprotocol_version: HOSTED_RUNNER_DRAIN_PROTOCOL_VERSION,\n\t\t\tstatus: result.status,\n\t\t\trunner_session_id: result.runner_session_id,\n\t\t\trequested_by: result.requested_by,\n\t\t\treason: result.reason,\n\t\t\tmanifest_path: result.manifest_path,\n\t\t\tmanifest: result.manifest,\n\t\t},\n\t\tcontext.corsHeaders,\n\t\treq,\n\t);\n}\n"]}
|
package/dist/version.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.10.
|
|
3
|
-
"notes": "Maestro by EvalOps - Deterministic coding agent with TUI/CLI and Web UI for AI-assisted development v0.10.
|
|
2
|
+
"version": "0.10.44",
|
|
3
|
+
"notes": "Maestro by EvalOps - Deterministic coding agent with TUI/CLI and Web UI for AI-assisted development v0.10.44 is now available."
|
|
4
4
|
}
|
package/package.json
CHANGED