@vehicle-sil/gui-client 0.2.0 → 0.4.0-rc.1

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/index.js CHANGED
@@ -448,7 +448,6 @@ function severityRank(severity) {
448
448
  var readFinding = (value, path, u) => {
449
449
  const f = object(value, path);
450
450
  return withRaw(f, {
451
- ...Number.isSafeInteger(f["event_seq"]) && f["event_seq"] >= 0 ? { event_seq: f["event_seq"] } : {},
452
451
  severity: field(f, path, "severity", string),
453
452
  code: field(f, path, "code", lenient(string, "", u)),
454
453
  file: field(f, path, "file", soft(nullable(string), null, u)),
@@ -632,22 +631,22 @@ var readRunParticipant = (value, path, u) => {
632
631
  };
633
632
  var readRunTiming = (value, path, u) => {
634
633
  const f = object(value, path);
635
- const count2 = (key) => field(f, path, key, soft(nullable(number), null, u));
634
+ const count = (key) => field(f, path, key, soft(nullable(number), null, u));
636
635
  return withRaw(f, {
637
636
  speed: field(f, path, "speed", soft(readSpeed, null, u)),
638
- time_step_ms: count2("time_step_ms"),
639
- ecu_step_ms: count2("ecu_step_ms"),
640
- step_delay_ms: count2("step_delay_ms"),
641
- late_tolerance_ms: count2("late_tolerance_ms"),
642
- sim_ms: count2("sim_ms"),
643
- wall_ms: count2("wall_ms"),
644
- actual_speed: count2("actual_speed"),
645
- paced_steps: count2("paced_steps"),
646
- late_steps: count2("late_steps"),
647
- max_late_ms: count2("max_late_ms"),
648
- slipped_ms: count2("slipped_ms"),
649
- late_ms: count2("late_ms"),
650
- paused_ms: count2("paused_ms")
637
+ time_step_ms: count("time_step_ms"),
638
+ ecu_step_ms: count("ecu_step_ms"),
639
+ step_delay_ms: count("step_delay_ms"),
640
+ late_tolerance_ms: count("late_tolerance_ms"),
641
+ sim_ms: count("sim_ms"),
642
+ wall_ms: count("wall_ms"),
643
+ actual_speed: count("actual_speed"),
644
+ paced_steps: count("paced_steps"),
645
+ late_steps: count("late_steps"),
646
+ max_late_ms: count("max_late_ms"),
647
+ slipped_ms: count("slipped_ms"),
648
+ late_ms: count("late_ms"),
649
+ paused_ms: count("paused_ms")
651
650
  });
652
651
  };
653
652
  var readTrafficUnplaced = (value, path, u) => {
@@ -780,14 +779,14 @@ var readRunResult = (value, path, u) => {
780
779
  };
781
780
  var PHASES = ["checking", "starting", "waiting", "running", "stopping", "ended"];
782
781
  function readTimeFields(f, path, u) {
783
- const count2 = (key) => field(f, path, key, soft(nullable(number), null, u));
782
+ const count = (key) => field(f, path, key, soft(nullable(number), null, u));
784
783
  return {
785
784
  sim_ms: field(f, path, "sim_ms", number),
786
- actual_speed: count2("actual_speed"),
787
- late_steps: count2("late_steps"),
788
- max_late_ms: count2("max_late_ms"),
789
- slipped_ms: count2("slipped_ms"),
790
- late_ms: count2("late_ms")
785
+ actual_speed: count("actual_speed"),
786
+ late_steps: count("late_steps"),
787
+ max_late_ms: count("max_late_ms"),
788
+ slipped_ms: count("slipped_ms"),
789
+ late_ms: count("late_ms")
791
790
  };
792
791
  }
793
792
  function readCommandFields(f, path, u) {
@@ -896,6 +895,13 @@ function readEventFields(f, path, kind, base, u) {
896
895
  file: field(f, path, "file", soft(nullable(string), null, u)),
897
896
  arguments: field(f, path, "arguments", soft(items(string, u), [], u))
898
897
  };
898
+ case "run_start":
899
+ return {
900
+ ...base,
901
+ event: kind,
902
+ id: field(f, path, "id", soft(nullable(integer), null, u)),
903
+ run: field(f, path, "run", soft(nullable(string), null, u))
904
+ };
899
905
  case "phase":
900
906
  return { ...base, event: kind, phase: field(f, path, "phase", string) };
901
907
  case "check":
@@ -977,15 +983,17 @@ function readEventFields(f, path, kind, base, u) {
977
983
  }
978
984
 
979
985
  // ../client/src/protocol/server.ts
980
- var PROTOCOL_VERSION = 3;
986
+ var PROTOCOL_VERSION = 4;
987
+ var nonEmptyString = (value, path) => {
988
+ if (typeof value !== "string" || !value) throw new ProtocolError(path, "a non-empty string");
989
+ return value;
990
+ };
981
991
  var readServerProblem = (value, path) => {
982
992
  const f = object(value, path);
983
993
  const problem = {
984
994
  code: field(f, path, "code", string),
985
995
  message: field(f, path, "message", string)
986
996
  };
987
- if (Number.isSafeInteger(f["problem_seq"]) && f["problem_seq"] >= 0)
988
- problem.problem_seq = f["problem_seq"];
989
997
  const detail = f["detail"];
990
998
  if (typeof detail === "object" && detail !== null && "skipped" in detail) {
991
999
  const skipped = detail.skipped;
@@ -1101,7 +1109,7 @@ var readRecording = (value) => {
1101
1109
  if (r === null) return null;
1102
1110
  const path = "response.recording";
1103
1111
  return {
1104
- session_id: field(r, path, "session_id", integer),
1112
+ run_id: field(r, path, "run_id", nonEmptyString),
1105
1113
  file: field(r, path, "file", string),
1106
1114
  state: field(r, path, "state", string),
1107
1115
  available: field(r, path, "available", boolean),
@@ -1157,10 +1165,33 @@ var readSummaryParticipant = (value, path, u) => {
1157
1165
  )
1158
1166
  };
1159
1167
  };
1168
+ var readRuntimeStatus = (value, path) => {
1169
+ const f = object(value, path);
1170
+ return {
1171
+ mode: field(f, path, "mode", string),
1172
+ state: field(f, path, "state", string),
1173
+ config: field(f, path, "config", nullable(string)),
1174
+ reason: field(f, path, "reason", nullable(string)),
1175
+ message: field(f, path, "message", nullable(string))
1176
+ };
1177
+ };
1178
+ var readPrepareResponse = (value) => {
1179
+ const path = "response";
1180
+ const f = object(value, path);
1181
+ const runtime = field(f, path, "runtime", optional(readRuntimeStatus, void 0));
1182
+ return {
1183
+ instance: field(f, path, "instance", nonEmptyString),
1184
+ ...runtime === void 0 ? {} : { runtime }
1185
+ };
1186
+ };
1160
1187
  var readSummaryLauncher = (value, path) => {
1161
1188
  const f = object(value, path);
1189
+ const mode = field(f, path, "mode", optional(string, void 0));
1190
+ const processAlive = field(f, path, "process_alive", optional(boolean, void 0));
1162
1191
  return {
1163
1192
  running: field(f, path, "running", boolean),
1193
+ ...mode === void 0 ? {} : { mode },
1194
+ ...processAlive === void 0 ? {} : { process_alive: processAlive },
1164
1195
  exit_code: field(f, path, "exit_code", nullable(integer)),
1165
1196
  signal: field(f, path, "signal", nullable(integer)),
1166
1197
  silent_s: field(f, path, "silent_s", optional(nullable(integer), null))
@@ -1195,8 +1226,8 @@ var readSessionSummary = (value, path) => {
1195
1226
  const timePath = `${path}.time`;
1196
1227
  const stopAt = field(f, path, "stop_at_ms", soft(nullable(integer), void 0, u));
1197
1228
  const summary = {
1198
- id: field(f, path, "id", integer),
1199
- ...f["snapshot_rev"] === void 0 ? {} : { snapshot_rev: field(f, path, "snapshot_rev", soft(nullable(integer), null, u)) },
1229
+ id: field(f, path, "id", nonEmptyString),
1230
+ ...f["run_t0_ms"] === void 0 ? {} : { run_t0_ms: field(f, path, "run_t0_ms", soft(nullable(number), null, u)) },
1200
1231
  state: field(f, path, "state", string),
1201
1232
  launcher: field(f, path, "launcher", readSummaryLauncher),
1202
1233
  stop: field(f, path, "stop", string),
@@ -1280,7 +1311,6 @@ var readSessionSummary = (value, path) => {
1280
1311
  log: field(f, path, "log", soft(partlyRecord(readLogCounts, u), {}, u)),
1281
1312
  problems: field(f, path, "problems", items(readServerProblem, u)),
1282
1313
  problems_omitted: field(f, path, "problems_omitted", soft(integer, 0, u)),
1283
- ...f["problem_seq"] === void 0 ? {} : { problem_seq: field(f, path, "problem_seq", soft(nullable(integer), null, u)) },
1284
1314
  scenario: field(
1285
1315
  f,
1286
1316
  path,
@@ -1309,7 +1339,6 @@ var readServerSaveItem = (value, path) => ({
1309
1339
  var readServerAllowed = (value, path) => {
1310
1340
  const f = object(value, path);
1311
1341
  return {
1312
- rev: field(f, path, "rev", optional(integer, 0)),
1313
1342
  start: field(f, path, "start", readServerAllowedItem),
1314
1343
  stop: field(f, path, "stop", readServerAllowedItem),
1315
1344
  force: field(f, path, "force", readServerAllowedItem),
@@ -1317,6 +1346,7 @@ var readServerAllowed = (value, path) => {
1317
1346
  };
1318
1347
  };
1319
1348
  function partlyRecord(read2, u) {
1349
+ if (!u) return record(read2);
1320
1350
  return (value, path) => {
1321
1351
  const out = {};
1322
1352
  for (const [key, item] of Object.entries(object(value, path))) {
@@ -1332,110 +1362,174 @@ var readSessionInstance = (value) => field(object(value, "response"), "response"
1332
1362
  throw new ProtocolError(path, "a server instance ID. Use the GUI server from this release");
1333
1363
  return instance;
1334
1364
  });
1365
+ var readRunResponse = (value) => {
1366
+ const path = "response";
1367
+ const f = object(value, path);
1368
+ return {
1369
+ instance: readSessionInstance(value),
1370
+ run_id: field(f, path, "run_id", nonEmptyString)
1371
+ };
1372
+ };
1335
1373
  var readSessionAllowed = (value) => field(
1336
1374
  object(value, "response"),
1337
1375
  "response",
1338
1376
  "allowed",
1339
1377
  optional(nullable(readServerAllowed), null)
1340
1378
  );
1379
+ var readSessionRuntime = (value) => field(
1380
+ object(value, "response"),
1381
+ "response",
1382
+ "runtime",
1383
+ optional(nullable(readRuntimeStatus), void 0)
1384
+ );
1341
1385
  var readTimeResponse = (value) => {
1342
1386
  const path = "response";
1343
1387
  const f = object(value, path);
1344
1388
  const command = field(f, path, "command", object);
1345
1389
  return {
1346
- session_id: field(f, path, "session_id", integer),
1390
+ run_id: field(f, path, "run_id", nonEmptyString),
1347
1391
  command: field(command, `${path}.command`, "command", string),
1348
1392
  id: field(command, `${path}.command`, "id", optional(nullable(integer), null))
1349
1393
  };
1350
1394
  };
1351
1395
  var readAvailability = (value) => value === "unknown" || value === "inactive" ? value : "active";
1352
- var readOperationReport = (value, path) => {
1396
+ var safeInteger = (value, path) => {
1397
+ if (!Number.isSafeInteger(value)) throw new ProtocolError(path, "an integer");
1398
+ return value;
1399
+ };
1400
+ var nonNegativeInteger = (value, path) => {
1401
+ const n = safeInteger(value, path);
1402
+ if (n < 0) throw new ProtocolError(path, "a non-negative integer");
1403
+ return n;
1404
+ };
1405
+ var readOperationReport = (value, path, u) => {
1353
1406
  const f = object(value, path);
1354
1407
  return {
1355
- seq: field(f, path, "seq", integer),
1408
+ seq: field(f, path, "seq", safeInteger),
1356
1409
  state: field(f, path, "state", string),
1357
- done: field(f, path, "done", boolean),
1410
+ done: field(f, path, "done", lenient(boolean, false, u)),
1358
1411
  peers: field(
1359
1412
  f,
1360
1413
  path,
1361
1414
  "peers",
1362
- record((v, p) => {
1363
- const t = object(v, p);
1364
- return {
1365
- state: field(t, p, "state", string),
1366
- applied_at_ms: field(t, p, "applied_at_ms", optional(nullable(number), null)),
1367
- late: field(t, p, "late", optional(boolean, false)),
1368
- reason: field(t, p, "reason", optional(nullable(string), null)),
1369
- applied_writes: field(t, p, "applied_writes", optional(nullable(integer), null)),
1370
- failed_write: field(t, p, "failed_write", optional(nullable(integer), null))
1371
- };
1372
- })
1415
+ soft(
1416
+ partlyRecord((v, p) => {
1417
+ const t = object(v, p);
1418
+ return {
1419
+ state: field(t, p, "state", lenient(string, "unknown", u)),
1420
+ applied_at_ms: field(t, p, "applied_at_ms", soft(nullable(number), null, u)),
1421
+ late: field(t, p, "late", soft(boolean, false, u)),
1422
+ reason: field(t, p, "reason", soft(nullable(string), null, u)),
1423
+ applied_writes: field(
1424
+ t,
1425
+ p,
1426
+ "applied_writes",
1427
+ soft(nullable(nonNegativeInteger), null, u)
1428
+ ),
1429
+ failed_write: field(t, p, "failed_write", soft(nullable(nonNegativeInteger), null, u))
1430
+ };
1431
+ }, u),
1432
+ {},
1433
+ u
1434
+ )
1373
1435
  )
1374
1436
  };
1375
1437
  };
1376
- var readVariableSummary = (value, path) => {
1438
+ var readEnumItem = (value, path) => {
1439
+ const item = object(value, path);
1440
+ return { name: field(item, path, "name", string), value: field(item, path, "value", number) };
1441
+ };
1442
+ var readVariableSummary = (value, path, u) => {
1377
1443
  const f = object(value, path);
1378
1444
  return {
1379
1445
  name: field(f, path, "name", string),
1380
- type: field(f, path, "type", string),
1381
- role: field(f, path, "role", optional(string, "output")),
1382
- writable: field(f, path, "writable", optional(boolean, false)),
1383
- unit: field(f, path, "unit", optional(string, "")),
1384
- min: field(f, path, "min", optional(nullable(number), null)),
1385
- max: field(f, path, "max", optional(nullable(number), null)),
1386
- step: field(f, path, "step", optional(nullable(number), null)),
1387
- description: field(f, path, "description", optional(string, "")),
1446
+ type: field(f, path, "type", lenient(string, "", u)),
1447
+ role: field(f, path, "role", soft(string, "output", u)),
1448
+ writable: field(f, path, "writable", soft(boolean, false, u)),
1449
+ unit: field(f, path, "unit", soft(string, "", u)),
1450
+ min: field(f, path, "min", soft(nullable(number), null, u)),
1451
+ max: field(f, path, "max", soft(nullable(number), null, u)),
1452
+ step: field(f, path, "step", soft(nullable(number), null, u)),
1453
+ description: field(f, path, "description", soft(string, "", u)),
1388
1454
  enum: field(
1389
1455
  f,
1390
1456
  path,
1391
1457
  "enum",
1392
- optional(
1393
- nullable(
1394
- array((v, p) => {
1395
- const item = object(v, p);
1396
- return { name: field(item, p, "name", string), value: field(item, p, "value", number) };
1397
- })
1398
- ),
1399
- null
1458
+ soft(
1459
+ nullable((v, p) => {
1460
+ if (!Array.isArray(v)) throw new ProtocolError(p, "an array");
1461
+ return items(readEnumItem, u)(v, p);
1462
+ }),
1463
+ null,
1464
+ u
1400
1465
  )
1401
1466
  ),
1402
1467
  availability: readAvailability(f["availability"])
1403
1468
  };
1404
1469
  };
1405
- var readVariablesSummary = (value) => readVariables(value, "variables");
1406
- var readVariables = (value, path) => {
1470
+ var readVariablesSummary = (value) => readVariablesReport(value, "variables");
1471
+ var readVariablesReport = (value, path, u) => {
1407
1472
  const f = object(value, path);
1408
1473
  return {
1409
- ...f["rev"] === void 0 ? {} : { rev: field(f, path, "rev", optional(nullable(integer), null)) },
1410
- state: field(f, path, "state", string),
1411
- reason: field(f, path, "reason", optional(nullable(string), null)),
1474
+ state: field(f, path, "state", lenient(string, "unknown", u)),
1475
+ reason: field(f, path, "reason", soft(nullable(string), null, u)),
1412
1476
  peers: field(
1413
1477
  f,
1414
1478
  path,
1415
1479
  "peers",
1416
- optional(
1417
- array((v, p) => {
1480
+ soft(
1481
+ items((v, p) => {
1418
1482
  const peer = object(v, p);
1419
1483
  return {
1420
1484
  name: field(peer, p, "name", string),
1421
- connected: field(peer, p, "connected", optional(boolean, false)),
1422
- variables: field(peer, p, "variables", optional(array(readVariableSummary), []))
1485
+ connected: field(peer, p, "connected", soft(boolean, false, u)),
1486
+ variables: field(
1487
+ peer,
1488
+ p,
1489
+ "variables",
1490
+ soft(
1491
+ items((item, ip) => readVariableSummary(item, ip, u), u),
1492
+ [],
1493
+ u
1494
+ )
1495
+ )
1423
1496
  };
1424
- }),
1425
- []
1497
+ }, u),
1498
+ [],
1499
+ u
1426
1500
  )
1427
1501
  ),
1428
- peers_omitted: field(f, path, "peers_omitted", optional(integer, 0)),
1429
- variables_omitted: field(f, path, "variables_omitted", optional(integer, 0)),
1430
- operations: field(f, path, "operations", optional(array(readOperationReport), [])),
1431
- operations_from_seq: field(f, path, "operations_from_seq", optional(integer, null)),
1432
- operations_open_omitted: field(f, path, "operations_open_omitted", optional(integer, 0))
1502
+ peers_omitted: field(f, path, "peers_omitted", soft(nonNegativeInteger, 0, u)),
1503
+ variables_omitted: field(f, path, "variables_omitted", soft(nonNegativeInteger, 0, u)),
1504
+ operations: field(
1505
+ f,
1506
+ path,
1507
+ "operations",
1508
+ soft(
1509
+ items((item, ip) => readOperationReport(item, ip, u), u),
1510
+ [],
1511
+ u
1512
+ )
1513
+ ),
1514
+ operations_from_seq: field(
1515
+ f,
1516
+ path,
1517
+ "operations_from_seq",
1518
+ soft(nullable(safeInteger), null, u)
1519
+ ),
1520
+ operations_open_omitted: field(
1521
+ f,
1522
+ path,
1523
+ "operations_open_omitted",
1524
+ soft(nonNegativeInteger, 0, u)
1525
+ )
1433
1526
  };
1434
1527
  };
1528
+ var readVariables = readVariablesReport;
1435
1529
  var readWriteResponse = (value) => {
1436
1530
  const f = object(value, "response");
1437
1531
  return {
1438
- session_id: field(f, "response", "session_id", integer),
1532
+ run_id: field(f, "response", "run_id", nonEmptyString),
1439
1533
  operation: field(f, "response", "operation", integer)
1440
1534
  };
1441
1535
  };
@@ -1522,44 +1616,55 @@ var readDashboardResponse = (value) => {
1522
1616
  };
1523
1617
  var readReplay = (value, path) => {
1524
1618
  const f = object(value, path);
1525
- return { from_seq: field(f, path, "from_seq", nullable(integer)) };
1619
+ return { after_stream_seq: field(f, path, "after_stream_seq", nullable(integer)) };
1526
1620
  };
1527
1621
  var readServerMessage = (value) => {
1528
1622
  const path = "message";
1529
1623
  const f = object(value, path);
1530
1624
  const type = field(f, path, "type", string);
1625
+ const streamSeq = f["stream_seq"] === void 0 ? void 0 : field(f, path, "stream_seq", nonNegativeInteger);
1626
+ const seqField = streamSeq === void 0 ? {} : { stream_seq: streamSeq };
1531
1627
  switch (type) {
1532
- case "hello":
1628
+ case "hello": {
1533
1629
  version(f, path, "vehicle_sil_gui", PROTOCOL_VERSION);
1630
+ const runtime = field(f, path, "runtime", optional(nullable(readRuntimeStatus), void 0));
1534
1631
  return {
1535
1632
  type,
1536
- instance: field(f, path, "instance", string),
1633
+ ...seqField,
1634
+ instance: field(f, path, "instance", nonEmptyString),
1537
1635
  session: field(f, path, "session", nullable(readSessionSummary)),
1538
1636
  allowed: field(f, path, "allowed", optional(nullable(readServerAllowed), null)),
1539
- replay: field(f, path, "replay", nullable(readReplay))
1637
+ replay: field(f, path, "replay", nullable(readReplay)),
1638
+ ...runtime === void 0 ? {} : { runtime }
1540
1639
  };
1640
+ }
1641
+ case "runtime":
1642
+ return { type, ...seqField, runtime: field(f, path, "runtime", readRuntimeStatus) };
1541
1643
  case "event": {
1542
1644
  const event = field(f, path, "event", (v, p) => readLauncherEvent(v, p, true));
1543
- return event && { type, session: field(f, path, "session", integer), event };
1645
+ return event && { type, ...seqField, run_id: field(f, path, "run_id", nonEmptyString), event };
1544
1646
  }
1545
1647
  case "synced":
1546
1648
  return {
1547
1649
  type,
1548
- session: field(f, path, "session", nullable(integer)),
1650
+ ...seqField,
1651
+ run_id: field(f, path, "run_id", nullable(nonEmptyString)),
1549
1652
  last_seq: field(f, path, "last_seq", nullable(integer))
1550
1653
  };
1551
1654
  case "session":
1552
- return { type, session: field(f, path, "session", readSessionSummary) };
1655
+ return { type, ...seqField, session: field(f, path, "session", readSessionSummary) };
1553
1656
  case "error":
1554
1657
  return {
1555
1658
  type,
1556
- session: field(f, path, "session", nullable(integer)),
1659
+ ...seqField,
1660
+ run_id: field(f, path, "run_id", nullable(nonEmptyString)),
1557
1661
  ...readServerProblem(value, path)
1558
1662
  };
1559
1663
  case "dropped":
1560
1664
  return {
1561
1665
  type,
1562
- session: field(f, path, "session", nullable(integer)),
1666
+ ...seqField,
1667
+ run_id: field(f, path, "run_id", nullable(nonEmptyString)),
1563
1668
  reason: field(f, path, "reason", string),
1564
1669
  log: field(f, path, "log", record(integer)),
1565
1670
  at_least: field(f, path, "at_least", array(string)),
@@ -1568,7 +1673,8 @@ var readServerMessage = (value) => {
1568
1673
  case "allowed":
1569
1674
  return {
1570
1675
  type,
1571
- session: field(f, path, "session", nullable(integer)),
1676
+ ...seqField,
1677
+ run_id: field(f, path, "run_id", nullable(nonEmptyString)),
1572
1678
  allowed: field(f, path, "allowed", readServerAllowed)
1573
1679
  };
1574
1680
  case "resync":
@@ -1576,14 +1682,17 @@ var readServerMessage = (value) => {
1576
1682
  case "variables":
1577
1683
  return {
1578
1684
  type,
1579
- session: field(f, path, "session", integer),
1685
+ ...seqField,
1686
+ run_id: field(f, path, "run_id", nonEmptyString),
1580
1687
  variables: field(f, path, "variables", readVariables)
1581
1688
  };
1582
- case "values":
1689
+ case "values": {
1690
+ const watchId = f["watch_id"] !== void 0 ? field(f, path, "watch_id", integer) : field(f, path, "id", integer);
1583
1691
  return {
1584
1692
  type,
1585
- id: field(f, path, "id", integer),
1586
- session: field(f, path, "session", integer),
1693
+ id: watchId,
1694
+ watch_id: watchId,
1695
+ run_id: field(f, path, "run_id", nonEmptyString),
1587
1696
  sim_ms: field(f, path, "sim_ms", nullable(number)),
1588
1697
  paused: field(f, path, "paused", boolean),
1589
1698
  peers: field(
@@ -1607,17 +1716,19 @@ var readServerMessage = (value) => {
1607
1716
  })
1608
1717
  )
1609
1718
  };
1719
+ }
1610
1720
  case "operation":
1611
1721
  return {
1612
1722
  type,
1613
- session: field(f, path, "session", integer),
1723
+ ...seqField,
1724
+ run_id: field(f, path, "run_id", nonEmptyString),
1614
1725
  ...readOperationReport(value, path)
1615
1726
  };
1616
1727
  case "availability":
1617
1728
  return {
1618
1729
  type,
1619
- session: field(f, path, "session", integer),
1620
- ...f["rev"] === void 0 ? {} : { rev: field(f, path, "rev", optional(nullable(integer), null)) },
1730
+ ...seqField,
1731
+ run_id: field(f, path, "run_id", nonEmptyString),
1621
1732
  peers: field(
1622
1733
  f,
1623
1734
  path,
@@ -1719,231 +1830,6 @@ function fetchTransport(options) {
1719
1830
  };
1720
1831
  }
1721
1832
 
1722
- // ../client/src/run.ts
1723
- function answerMissing(path, error) {
1724
- if (!error.timedOut) return null;
1725
- return path === "api/run" ? `${error.message}: the server may still start the run (it checks the file again when it has changed); whether it did shows in the session over the WebSocket` : `${error.message}: the server may have done it; the session over the WebSocket shows what happened`;
1726
- }
1727
- var RunControl = class {
1728
- constructor(feed, transport, onError = rethrowLater, startTimeoutMs = () => 0) {
1729
- this.feed = feed;
1730
- this.transport = transport;
1731
- this.startTimeoutMs = startTimeoutMs;
1732
- this.startSending = new Writable(false, Object.is, onError);
1733
- this.stopSending = new Writable(null, Object.is, onError);
1734
- this.pendingRevision = new Writable(0, Object.is, onError);
1735
- this.stopAskedWhileStarting = new Writable(false, Object.is, onError);
1736
- this.failure = new Writable(null, Object.is, onError);
1737
- this.starting = this.startSending.readonly();
1738
- this.stopping = this.stopSending.readonly();
1739
- this.currentStopping = derived(
1740
- [this.pendingRevision, this.startSending, feed.session],
1741
- () => {
1742
- const key = this.startSending.get() ? this.startOperation : JSON.stringify(feed.currentTarget());
1743
- return [...this.pendingStops].filter((pending) => pending.key === key).at(-1)?.action ?? null;
1744
- },
1745
- Object.is,
1746
- onError
1747
- );
1748
- this.stopWhileStarting = this.stopAskedWhileStarting.readonly();
1749
- this.error = derived(
1750
- [this.failure, feed.session],
1751
- () => {
1752
- const failure = this.failure.get();
1753
- const session = feed.session.get();
1754
- if (!failure) return null;
1755
- const same = failure.session === (session?.id ?? null) && failure.running === (session?.launcher.running ?? false);
1756
- return same ? failure.message : null;
1757
- },
1758
- Object.is,
1759
- onError
1760
- );
1761
- }
1762
- feed;
1763
- transport;
1764
- startTimeoutMs;
1765
- startOperation = null;
1766
- pendingStops = /* @__PURE__ */ new Set();
1767
- pendingRevision;
1768
- startSending;
1769
- stopSending;
1770
- stopAskedWhileStarting;
1771
- failure;
1772
- starting;
1773
- stopping;
1774
- currentStopping;
1775
- stopWhileStarting;
1776
- error;
1777
- /** Starts a run. */
1778
- start(request) {
1779
- if (this.startSending.get()) return Promise.reject(new Error("a start is already pending"));
1780
- let resolveStart;
1781
- let rejectStart;
1782
- const operation = new Promise(
1783
- (resolve, reject) => {
1784
- resolveStart = resolve;
1785
- rejectStart = reject;
1786
- }
1787
- );
1788
- this.startOperation = operation;
1789
- this.stopAskedWhileStarting.set(false);
1790
- this.startSending.set(true);
1791
- let instance = null;
1792
- this.send(
1793
- "api/run",
1794
- request,
1795
- this.startTimeoutMs() || void 0,
1796
- () => {
1797
- this.startSending.set(false);
1798
- },
1799
- (seen) => {
1800
- instance = seen;
1801
- }
1802
- ).then((summary) => resolveStart({ summary, instance }), rejectStart);
1803
- return operation.then(({ summary }) => summary);
1804
- }
1805
- /** Stops in order (waits for the participants to end). Asking again never turns it into a stop without waiting. */
1806
- stop() {
1807
- return this.requestStop(false);
1808
- }
1809
- /** Stops without waiting (kills the participants). */
1810
- forceStop() {
1811
- return this.requestStop(true);
1812
- }
1813
- captureStop() {
1814
- const starting = this.startSending.get() ? this.startOperation : null;
1815
- const target = starting ? null : this.feed.currentTarget();
1816
- return {
1817
- key: starting ?? JSON.stringify(target),
1818
- send: (force) => this.requestStop(force, starting, target)
1819
- };
1820
- }
1821
- requestStop(force, starting = this.startSending.get() ? this.startOperation : null, target = starting ? null : this.feed.currentTarget()) {
1822
- const session = this.feed.session.get();
1823
- const pending = {
1824
- action: force ? "force" : "stop",
1825
- starting: !!starting,
1826
- key: starting ?? JSON.stringify(target)
1827
- };
1828
- this.pendingStops.add(pending);
1829
- this.pendingRevision.update((n) => n + 1);
1830
- this.stopSending.set(pending.action);
1831
- const done = () => {
1832
- this.pendingStops.delete(pending);
1833
- this.pendingRevision.update((n) => n + 1);
1834
- const remaining = [...this.pendingStops];
1835
- this.stopAskedWhileStarting.set(remaining.some((p) => p.starting));
1836
- this.stopSending.set(remaining.at(-1)?.action ?? null);
1837
- };
1838
- if (!starting) {
1839
- if (!target) {
1840
- const message = "no session and server instance are known: no stop was sent; reconnect and check the current run";
1841
- this.failure.set({
1842
- message,
1843
- session: session?.id ?? null,
1844
- running: session?.launcher.running ?? false
1845
- });
1846
- done();
1847
- return Promise.reject(new Error(message));
1848
- }
1849
- return this.send("api/stop-session", { force, ...target }, void 0, done);
1850
- }
1851
- this.stopAskedWhileStarting.set(true);
1852
- return starting.then(
1853
- ({ summary, instance }) => {
1854
- if (!summary || !instance) {
1855
- const message = "the start answer did not identify the run; no stop was sent";
1856
- const session2 = this.feed.session.get();
1857
- this.failure.set({
1858
- message,
1859
- session: session2?.id ?? null,
1860
- running: session2?.launcher.running ?? false
1861
- });
1862
- throw new Error(message);
1863
- }
1864
- pending.key = JSON.stringify({ session: summary.id, instance });
1865
- this.pendingRevision.update((n) => n + 1);
1866
- return this.send(
1867
- "api/stop-session",
1868
- { force, session: summary.id, instance },
1869
- void 0,
1870
- () => void 0
1871
- );
1872
- },
1873
- (error) => {
1874
- const message = `the start was not confirmed; no stop was sent: ${errorMessage(error)}`;
1875
- const session2 = this.feed.session.get();
1876
- this.failure.set({
1877
- message,
1878
- session: session2?.id ?? null,
1879
- running: session2?.launcher.running ?? false
1880
- });
1881
- throw new Error(message);
1882
- }
1883
- ).finally(done);
1884
- }
1885
- /**
1886
- * Sends and applies the summary in the answer. done is called after the answer (failures too), before the Promise
1887
- * settles.
1888
- */
1889
- send(path, body, timeoutMs, done, onInstance) {
1890
- const incompatible = this.feed.incompatible.get();
1891
- if (incompatible) {
1892
- done();
1893
- return Promise.reject(new Error(incompatible));
1894
- }
1895
- this.failure.set(null);
1896
- return new Promise((resolve, reject) => {
1897
- this.transport({ method: "POST", path, body, timeoutMs }, (outcome) => {
1898
- if (!outcome.ok) {
1899
- const failure = path === "api/stop-session" && outcome.error.status === 404 ? new HttpError(404, outcome.error.statusText, {
1900
- code: "targeted-stop-unsupported",
1901
- message: "the GUI server cannot stop a particular session: no stop was sent; use the GUI server of this release"
1902
- }) : outcome.error;
1903
- const session = this.feed.session.get();
1904
- this.failure.set({
1905
- message: answerMissing(path, failure) ?? errorMessage(failure),
1906
- session: session?.id ?? null,
1907
- running: session?.launcher.running ?? false
1908
- });
1909
- done();
1910
- reject(failure);
1911
- return;
1912
- }
1913
- let summary = null;
1914
- try {
1915
- const instance = path === "api/stop-session" ? body.instance : readSessionInstance(outcome.body);
1916
- summary = readSessionResponse(outcome.body);
1917
- if (path === "api/stop-session" && (!summary || summary.id !== body.session)) {
1918
- throw new Error("the stop answer did not identify the requested session");
1919
- }
1920
- onInstance?.(instance);
1921
- this.feed.adopt(summary, instance);
1922
- } catch (error) {
1923
- this.feed.report(
1924
- error instanceof ProtocolError ? `unreadable answer: ${error.message}` : String(error)
1925
- );
1926
- const missingInstance = error instanceof ProtocolError && error.path === "response.instance";
1927
- if (path === "api/stop-session" || missingInstance) {
1928
- const message = missingInstance ? `${error.message}. The run may have started. Check the current run before retrying` : "the stop answer was unreadable: check the session before trying again";
1929
- const session = this.feed.session.get();
1930
- this.failure.set({
1931
- message,
1932
- session: session?.id ?? null,
1933
- running: session?.launcher.running ?? false
1934
- });
1935
- done();
1936
- reject(new Error(message));
1937
- return;
1938
- }
1939
- }
1940
- done();
1941
- resolve(summary);
1942
- });
1943
- });
1944
- }
1945
- };
1946
-
1947
1833
  // ../client/src/session-state.ts
1948
1834
  function launcherAnswer(state, name) {
1949
1835
  if (!state) {
@@ -2008,40 +1894,31 @@ function scenarioView(summary) {
2008
1894
  timelineUrl: summary.timeline_url
2009
1895
  };
2010
1896
  }
2011
- function fullStepText(incoming, current) {
2012
- if (incoming === null || current === null) return incoming;
2013
- const cut = /^(.*)\.\.\. \((\d+) more characters\)$/s.exec(incoming);
2014
- if (!cut) return incoming;
2015
- const prefix = cut[1];
2016
- return current.startsWith(prefix) && Array.from(current).length === Array.from(prefix).length + Number(cut[2]) ? current : incoming;
2017
- }
2018
- function mergeScenarioStep(current, incoming) {
2019
- return {
2020
- ...incoming,
2021
- text: fullStepText(incoming.text, current.text) ?? incoming.text,
2022
- message: fullStepText(incoming.message, current.message)
2023
- };
2024
- }
2025
- var stepPositions = /* @__PURE__ */ new WeakMap();
2026
- function mergeScenarioSteps(current, incoming, merge = (_old, next) => next) {
2027
- const steps = new Map(current.map((step) => [step.index, step]));
2028
- for (const step of incoming) {
2029
- const old = steps.get(step.index);
2030
- steps.set(step.index, old ? merge(old, step) : step);
2031
- }
2032
- return [...steps.values()].sort((a, b) => a.index - b.index);
2033
- }
2034
1897
  function withStep(steps, step) {
2035
1898
  const i = steps.findIndex((s) => s.index >= step.index);
2036
1899
  if (i < 0) return [...steps, step];
2037
1900
  if (steps[i].index === step.index) return steps.map((s, j) => j === i ? step : s);
2038
1901
  return [...steps.slice(0, i), step, ...steps.slice(i)];
2039
1902
  }
1903
+ function isSessionRunning(session) {
1904
+ return !!session && session.state === "running";
1905
+ }
1906
+ function isRunActive(session) {
1907
+ return !!session && session.state === "running" && session.launcher.running;
1908
+ }
1909
+ function isLauncherFinishing(session) {
1910
+ return !!session && isRunActive(session) && session.result !== null;
1911
+ }
1912
+ function isLauncherAlive(session) {
1913
+ if (!session) return false;
1914
+ const launcher = session.launcher;
1915
+ return launcher.processAlive ?? launcher.process_alive ?? launcher.running;
1916
+ }
2040
1917
  function isHolding(session) {
2041
- return !!session && session.launcher.running && session.launcherState?.holding === true;
1918
+ return isRunActive(session) && session.launcherState?.holding === true;
2042
1919
  }
2043
1920
  function runOutcome(session) {
2044
- if (session.launcher.running) {
1921
+ if (isRunActive(session)) {
2045
1922
  if (session.result) return "finishing";
2046
1923
  if (session.stopRequests >= 2) return "forcing";
2047
1924
  return session.stopRequests >= 1 ? "stopping" : "running";
@@ -2051,13 +1928,14 @@ function runOutcome(session) {
2051
1928
  function sessionFromSummary(summary) {
2052
1929
  const blank = {
2053
1930
  id: summary.id,
2054
- ...summary.snapshot_rev == null ? {} : { snapshotRev: summary.snapshot_rev },
2055
1931
  lastSeq: -1,
1932
+ runT0Ms: summary.run_t0_ms ?? 0,
2056
1933
  file: summary.file,
2057
1934
  disable: summary.disable,
2058
1935
  manual: summary.manual,
2059
1936
  speed: summary.speed,
2060
1937
  startPaused: summary.start_paused,
1938
+ state: summary.state,
2061
1939
  phase: null,
2062
1940
  phaseRank: -1,
2063
1941
  check: null,
@@ -2081,31 +1959,27 @@ function sessionFromSummary(summary) {
2081
1959
  droppedMarks: 0,
2082
1960
  scenario: null
2083
1961
  };
2084
- const adopted = applySummary(blank, summary, true);
2085
- return summary.last_seq == null ? adopted : {
2086
- ...adopted,
2087
- pendingFindings: { through: summary.last_seq, keys: summary.findings.map(findingIdentity) }
2088
- };
1962
+ return applySummary(blank, summary);
2089
1963
  }
2090
1964
  function addDropped(session, dropped) {
2091
- const counts = Object.entries(dropped.log).filter(([, count2]) => count2 > 0);
1965
+ const counts = Object.entries(dropped.log).filter(([, count]) => count > 0);
2092
1966
  if (counts.length === 0) return session;
2093
1967
  const mark = session.droppedMarks + 1;
2094
- const gaps = counts.map(([source, count2]) => ({
1968
+ const gaps = counts.map(([source, count]) => ({
2095
1969
  seq: session.lastSeq + 0.5,
2096
1970
  key: `dropped ${mark} ${source}`,
2097
1971
  source,
2098
1972
  line: "",
2099
1973
  gap: {
2100
- count: count2,
1974
+ count,
2101
1975
  atLeast: dropped.at_least.includes(source),
2102
1976
  ...dropped.reason === "not-kept" ? { notKept: true } : {}
2103
1977
  }
2104
1978
  }));
2105
1979
  const next = { ...appendLogs(session, gaps), droppedMarks: mark };
2106
1980
  const sources = { ...next.logSources };
2107
- for (const [source, count2] of counts) {
2108
- sources[source] = { ...sources[source], dropped: sources[source].dropped + count2 };
1981
+ for (const [source, count] of counts) {
1982
+ sources[source] = { ...sources[source], dropped: sources[source].dropped + count };
2109
1983
  }
2110
1984
  return { ...next, logSources: sources };
2111
1985
  }
@@ -2116,56 +1990,21 @@ function stopRequestsOf(stop) {
2116
1990
  function launcherOf(summary) {
2117
1991
  return {
2118
1992
  running: summary.launcher.running,
1993
+ ...summary.launcher.mode === void 0 ? {} : { mode: summary.launcher.mode },
1994
+ ...summary.launcher.process_alive === void 0 ? {} : { processAlive: summary.launcher.process_alive },
2119
1995
  exitCode: summary.launcher.exit_code,
2120
1996
  signal: summary.launcher.signal,
2121
1997
  silentSeconds: summary.launcher.silent_s
2122
1998
  };
2123
1999
  }
2124
- function applySummary(session, summary, force = false, controlOnly = false) {
2125
- const incomingRev = summary.snapshot_rev ?? null;
2126
- const currentRev = session.snapshotRev ?? null;
2127
- const staleControl = currentRev !== null && (incomingRev === null || incomingRev < currentRev);
2128
- const projectionRev = session.projectionRev ?? null;
2129
- const staleProjection = projectionRev !== null && (incomingRev === null || incomingRev < projectionRev);
2130
- if (staleControl && (staleProjection || !force && controlOnly)) return session;
2131
- const newer = force || (summary.last_seq ?? -1) > Math.max(session.lastSeq, session.observedSeq ?? -1, session.projectionSeq ?? -1);
2132
- const launcher = !force && !session.launcher.running && summary.launcher.running ? session.launcher : launcherOf(summary);
2133
- const notLess = summary.problems.length + summary.problems_omitted >= session.problems.length + session.problemsOmitted;
2134
- const mergedProblems = [...summary.problems];
2135
- let omitted = summary.problems_omitted;
2136
- if (summary.problem_seq != null) {
2137
- const included = new Set(mergedProblems.map((problem) => problem.problem_seq));
2138
- for (const problem of session.problems) {
2139
- if (problem.problem_seq === void 0 || included.has(problem.problem_seq)) continue;
2140
- if (mergedProblems.length >= MAX_PROBLEMS) break;
2141
- mergedProblems.push(problem);
2142
- if (problem.problem_seq <= summary.problem_seq && omitted > 0) omitted--;
2143
- }
2144
- }
2145
- if (mergedProblems.every((problem) => problem.problem_seq !== void 0))
2146
- mergedProblems.sort((a, b) => a.problem_seq - b.problem_seq);
2147
- const next = staleControl ? session : {
2148
- ...session,
2149
- ...incomingRev === null ? {} : { snapshotRev: incomingRev },
2150
- ...summary.stop_at_ms === void 0 ? {} : { stopAtMs: summary.stop_at_ms },
2151
- ...summary.problem_seq == null ? {} : { problemSeq: Math.max(session.problemSeq ?? 0, summary.problem_seq) },
2152
- launcher,
2153
- stopRequests: Math.max(session.stopRequests, stopRequestsOf(summary.stop)),
2154
- logSources: withSources(session.logSources, Object.keys(summary.log)),
2155
- ...summary.scenario?.timeline_url ? {
2156
- scenario: session.scenario ? { ...session.scenario, timelineUrl: summary.scenario.timeline_url } : scenarioView(summary.scenario)
2157
- } : {},
2158
- ...force || notLess ? { problems: mergedProblems, problemsOmitted: omitted } : {}
2159
- };
2160
- if (!newer || staleProjection || !force && controlOnly) {
2161
- return next;
2162
- }
2163
- const phase = summary.phase ?? next.phase;
2000
+ function applySummary(session, summary) {
2001
+ if (summary.id !== session.id) return sessionFromSummary(summary);
2002
+ const runT0Ms = summary.run_t0_ms ?? session.runT0Ms;
2003
+ const elapsedMs = summary.last_t_ms === null ? session.elapsedMs : Math.max(session.elapsedMs, Math.max(0, summary.last_t_ms - runT0Ms));
2004
+ const phase = summary.phase ?? session.phase;
2164
2005
  const rank = phaseIndex(phase);
2165
- const preserveEvents = force && controlOnly;
2166
- const behind = (...kinds) => summary.last_seq !== null && kinds.some((kind) => (session.eventSeqs?.[kind] ?? -1) > summary.last_seq);
2167
- const check = (preserveEvents ? next.check : null) ?? summary.check ?? next.check ?? summary.result?.check ?? null;
2168
- const result = (preserveEvents ? next.result : null) ?? summary.result ?? next.result;
2006
+ const check = summary.check ?? session.check ?? summary.result?.check ?? null;
2007
+ const result = summary.result ?? session.result;
2169
2008
  const known = new Map(session.participants.map((p) => [p.name, p]));
2170
2009
  const participants = summary.participants.map((p) => ({
2171
2010
  name: p.name,
@@ -2175,66 +2014,66 @@ function applySummary(session, summary, force = false, controlOnly = false) {
2175
2014
  exitCode: p.exit_code,
2176
2015
  signal: p.signal,
2177
2016
  failure: p.reason,
2178
- message: p.message ?? (preserveEvents ? known.get(p.name)?.message ?? null : null),
2017
+ message: p.message ?? known.get(p.name)?.message ?? null,
2179
2018
  // A stop the launcher asked for is kept even in summaries of later states (ended and so on)
2180
2019
  stopRequested: p.stop_requested || p.state === "stop_requested" || !!known.get(p.name)?.stopRequested,
2181
2020
  omittedFields: p.omitted_fields,
2182
2021
  controlLink: p.control_link ?? known.get(p.name)?.controlLink ?? null,
2183
2022
  manual: p.state === "manual" || p.command_line !== null || !!known.get(p.name)?.manual,
2184
- commandLine: p.command_line ?? (preserveEvents ? known.get(p.name)?.commandLine ?? null : null),
2185
- workingDirectory: p.working_directory ?? (preserveEvents ? known.get(p.name)?.workingDirectory ?? null : null),
2186
- environment: p.environment ?? (preserveEvents ? known.get(p.name)?.environment ?? {} : {})
2023
+ commandLine: p.command_line ?? known.get(p.name)?.commandLine ?? null,
2024
+ workingDirectory: p.working_directory ?? known.get(p.name)?.workingDirectory ?? null,
2025
+ environment: p.environment ?? known.get(p.name)?.environment ?? {}
2187
2026
  }));
2188
- const scenario = summary.scenario ? {
2027
+ const mergedParticipants = [
2028
+ ...participants,
2029
+ ...session.participants.filter((p) => !participants.some((current) => current.name === p.name))
2030
+ ];
2031
+ let scenario = summary.scenario ? {
2189
2032
  ...scenarioView(summary.scenario),
2190
- timelineUrl: next.scenario?.timelineUrl ?? summary.scenario.timeline_url
2191
- } : next.scenario;
2192
- let mergedScenario = preserveEvents && scenario && next.scenario ? {
2193
- ...scenario,
2194
- steps: mergeScenarioSteps(
2195
- next.scenario.steps,
2196
- scenario.steps,
2197
- (old, step) => summary.last_seq !== null && (stepPositions.get(old) ?? -1) > summary.last_seq ? old : mergeScenarioStep(old, step)
2198
- )
2199
- } : scenario;
2200
- if (mergedScenario && result?.scenario) {
2201
- mergedScenario = {
2202
- ...mergedScenario,
2203
- steps: mergeScenarioSteps(mergedScenario.steps, result.scenario.steps)
2033
+ timelineUrl: summary.scenario.timeline_url ?? session.scenario?.timelineUrl ?? null
2034
+ } : session.scenario;
2035
+ if (scenario && result?.scenario) {
2036
+ scenario = {
2037
+ ...scenario,
2038
+ name: result.scenario.name ?? scenario.name,
2039
+ stepCount: result.scenario.steps.length,
2040
+ steps: result.scenario.steps,
2041
+ stepsOmitted: 0,
2042
+ status: result.scenario.status,
2043
+ overAtMs: result.scenario.over_at_ms
2204
2044
  };
2205
2045
  }
2206
- if (mergedScenario && scenario && mergedScenario !== scenario) {
2207
- mergedScenario.stepsOmitted = Math.max(
2208
- 0,
2209
- scenario.stepsOmitted - (mergedScenario.steps.length - scenario.steps.length)
2210
- );
2211
- }
2212
- const mergedParticipants = preserveEvents ? [
2213
- ...participants,
2214
- ...next.participants.filter(
2215
- (p) => !participants.some((current) => current.name === p.name)
2216
- )
2217
- ] : participants;
2046
+ const problems = summary.problems.slice(0, MAX_PROBLEMS);
2047
+ const problemsOmitted = summary.problems_omitted + Math.max(0, summary.problems.length - problems.length);
2218
2048
  return {
2219
- ...next,
2220
- ...incomingRev === null ? {} : { projectionRev: incomingRev },
2221
- projectionSeq: Math.max(next.projectionSeq ?? -1, summary.last_seq ?? -1),
2222
- unreadable: force && !behind("finding", "result", "participant") ? summary.unreadable : union(next.unreadable, summary.unreadable),
2223
- phase: behind("phase", "result") ? next.phase ?? phase : phase,
2224
- phaseRank: behind("phase", "result") ? next.phaseRank : rank >= 0 ? rank : next.phaseRank,
2225
- elapsedMs: Math.max(next.elapsedMs, summary.last_t_ms ?? 0),
2226
- simMs: behind("time") ? next.simMs ?? summary.sim_ms : summary.sim_ms ?? next.simMs,
2227
- timeOmittedFields: behind("time") || summary.sim_ms === null ? next.timeOmittedFields : summary.time_omitted_fields,
2228
- time: behind("time") && next.time ? next.time : summary.time ? timeView(summary.time) : next.time,
2229
- lastCommand: behind("command") && next.lastCommand ? next.lastCommand : summary.last_command ? commandView(summary.last_command, summary.last_command.seq ?? -1) : next.lastCommand,
2230
- launcherState: newerState(next.launcherState, summary.launcher_state ?? null),
2231
- findings: preserveEvents ? mergeFindings(next.findings, summary.findings) : summary.findings,
2049
+ ...session,
2050
+ ...summary.stop_at_ms === void 0 ? {} : { stopAtMs: summary.stop_at_ms },
2051
+ runT0Ms,
2052
+ state: summary.state,
2053
+ launcher: launcherOf(summary),
2054
+ stopRequests: Math.max(session.stopRequests, stopRequestsOf(summary.stop)),
2055
+ logSources: withSources(session.logSources, Object.keys(summary.log)),
2056
+ problems,
2057
+ problemsOmitted,
2058
+ unreadable: summary.unreadable,
2059
+ phase: result ? "ended" : phase,
2060
+ phaseRank: result ? phaseIndex("ended") : rank >= 0 ? rank : session.phaseRank,
2061
+ elapsedMs,
2062
+ simMs: summary.sim_ms ?? session.simMs,
2063
+ timeOmittedFields: summary.sim_ms === null ? session.timeOmittedFields : summary.time_omitted_fields,
2064
+ time: summary.time ? timeView(summary.time) : session.time,
2065
+ lastCommand: summary.last_command ? commandView(summary.last_command, summary.last_command.seq ?? -1) : session.lastCommand,
2066
+ launcherState: newerState(session.launcherState, summary.launcher_state ?? null),
2067
+ findings: summary.findings.slice(0, MAX_FINDINGS),
2232
2068
  result,
2233
2069
  check,
2234
- scenario: mergedScenario,
2070
+ scenario,
2235
2071
  // Whether a participant is required or left out is in the check result (as is the order, that of the configuration
2236
2072
  // file). If there is a result, how it ended (stopped or not) comes from the result too
2237
- participants: behind("participant", "result", CONTROL_EVENT) && next.participants.length > 0 ? next.participants : withResult(check ? mergeCheck(mergedParticipants, check) : mergedParticipants, result)
2073
+ participants: withResult(
2074
+ check ? mergeCheck(mergedParticipants, check) : mergedParticipants,
2075
+ result
2076
+ )
2238
2077
  };
2239
2078
  }
2240
2079
  function newerState(current, incoming) {
@@ -2252,101 +2091,23 @@ function withSources(sources, names) {
2252
2091
  return next;
2253
2092
  }
2254
2093
  function addProblem(session, problem) {
2255
- const seq = problem.problem_seq;
2256
- if (seq !== void 0 && seq <= (session.problemEventSeq ?? 0)) return session;
2257
- const updated = seq === void 0 ? session : { ...session, problemEventSeq: seq };
2258
- if (seq !== void 0 && session.problems.some((item) => item.problem_seq === seq))
2259
- return updated;
2260
- if (updated.problems.length >= MAX_PROBLEMS) {
2261
- const alreadyCounted2 = seq !== void 0 && seq <= (session.problemSeq ?? 0);
2262
- return alreadyCounted2 ? updated : { ...updated, problemsOmitted: updated.problemsOmitted + 1 };
2263
- }
2264
- const alreadyCounted = seq !== void 0 && seq <= (session.problemSeq ?? 0);
2265
- const problems = [...updated.problems, problem];
2266
- if (problems.every((item) => item.problem_seq !== void 0))
2267
- problems.sort((a, b) => a.problem_seq - b.problem_seq);
2094
+ if (session.problems.length >= MAX_PROBLEMS) {
2095
+ return { ...session, problemsOmitted: session.problemsOmitted + 1 };
2096
+ }
2268
2097
  return {
2269
- ...updated,
2270
- problems,
2271
- problemsOmitted: alreadyCounted ? Math.max(0, updated.problemsOmitted - 1) : updated.problemsOmitted
2098
+ ...session,
2099
+ problems: [...session.problems, problem]
2272
2100
  };
2273
2101
  }
2274
2102
  function phaseIndex(phase) {
2275
2103
  return phase === null ? -1 : PHASES.indexOf(phase);
2276
2104
  }
2277
- function findingKey(finding) {
2278
- return JSON.stringify([
2279
- finding.severity,
2280
- finding.code,
2281
- finding.file,
2282
- finding.line,
2283
- finding.participant,
2284
- finding.network,
2285
- finding.message,
2286
- finding.detail
2287
- ]);
2288
- }
2289
- function findingIdentity(finding) {
2290
- return finding.event_seq === void 0 ? `body:${findingKey(finding)}` : `seq:${finding.event_seq}`;
2291
- }
2292
- function mergeFindings(current, incoming) {
2293
- const a = current.slice(0, MAX_FINDINGS);
2294
- const b = incoming.slice(0, MAX_FINDINGS);
2295
- if (a.every((finding) => finding.event_seq !== void 0) && b.every((finding) => finding.event_seq !== void 0)) {
2296
- const bySeq = /* @__PURE__ */ new Map();
2297
- for (const finding of [...b, ...a]) bySeq.set(finding.event_seq, finding);
2298
- return [...bySeq.values()].sort((left, right) => left.event_seq - right.event_seq).slice(0, MAX_FINDINGS);
2299
- }
2300
- const ak = a.map(findingKey);
2301
- const bk = b.map(findingKey);
2302
- const sizes = Array.from({ length: a.length + 1 }, () => new Uint16Array(b.length + 1));
2303
- for (let i2 = a.length - 1; i2 >= 0; --i2)
2304
- for (let j2 = b.length - 1; j2 >= 0; --j2)
2305
- sizes[i2][j2] = ak[i2] === bk[j2] ? 1 + sizes[i2 + 1][j2 + 1] : Math.max(sizes[i2 + 1][j2], sizes[i2][j2 + 1]);
2306
- const merged = [];
2307
- let i = 0, j = 0;
2308
- while ((i < a.length || j < b.length) && merged.length < MAX_FINDINGS) {
2309
- if (i < a.length && j < b.length && ak[i] === bk[j]) {
2310
- merged.push(a[i++]);
2311
- j++;
2312
- } else if (j === b.length || i < a.length && sizes[i + 1][j] >= sizes[i][j + 1])
2313
- merged.push(a[i++]);
2314
- else merged.push(b[j++]);
2315
- }
2316
- return merged;
2317
- }
2318
2105
  function applyEvents(session, events, countStale = false) {
2319
2106
  let next = session;
2320
2107
  const logs = [];
2321
2108
  let stale = 0;
2322
2109
  for (const event of events) {
2323
2110
  if (event.seq > next.lastSeq) {
2324
- const tracked = [
2325
- "time",
2326
- "phase",
2327
- "result",
2328
- "finding",
2329
- "participant",
2330
- "command",
2331
- CONTROL_EVENT
2332
- ].includes(event.event);
2333
- if (event.event === "scenario_step") stepPositions.set(event.step, event.seq);
2334
- next = {
2335
- ...next,
2336
- observedSeq: Math.max(next.observedSeq ?? -1, event.seq),
2337
- ...tracked ? { eventSeqs: { ...next.eventSeqs, [event.event]: event.seq } } : {}
2338
- };
2339
- const pending = next.pendingFindings;
2340
- if (event.event === "finding" && pending && event.seq <= pending.through) {
2341
- const numbered = pending.keys.indexOf(`seq:${event.seq}`);
2342
- const index = numbered === -1 ? pending.keys.indexOf(`body:${findingKey(event.finding)}`) : numbered;
2343
- if (index !== -1) {
2344
- const keys = [...pending.keys];
2345
- keys.splice(index, 1);
2346
- next = { ...next, lastSeq: event.seq, pendingFindings: { ...pending, keys } };
2347
- continue;
2348
- }
2349
- }
2350
2111
  next = applyOne(next, event, logs);
2351
2112
  if (event.unreadable)
2352
2113
  next = { ...next, unreadable: union(next.unreadable, event.unreadable) };
@@ -2366,37 +2127,6 @@ function applyEvents(session, events, countStale = false) {
2366
2127
  }
2367
2128
  return { ...next, logSources: sources };
2368
2129
  }
2369
- function recoverReplayLogs(session, recovered, notKept) {
2370
- if (!recovered.length) return session;
2371
- const sources = Object.fromEntries(
2372
- Object.entries(session.logSources).map(([name, source]) => [
2373
- name,
2374
- { lines: 0, dropped: source.dropped }
2375
- ])
2376
- );
2377
- const restored = /* @__PURE__ */ new Map();
2378
- for (const line of recovered) {
2379
- const source = sources[line.source] ??= { lines: 0, dropped: 0 };
2380
- if (line.gap) source.dropped += line.gap.count;
2381
- else {
2382
- const count2 = restored.get(line.source) ?? 0;
2383
- if (count2 < (notKept.get(line.source) ?? 0)) {
2384
- source.dropped--;
2385
- restored.set(line.source, count2 + 1);
2386
- }
2387
- }
2388
- }
2389
- const logs = session.logs.flatMap((line) => {
2390
- if (!line.gap?.notKept) return [line];
2391
- const available = restored.get(line.source) ?? 0;
2392
- const count2 = Math.max(0, line.gap.count - available);
2393
- restored.set(line.source, Math.max(0, available - line.gap.count));
2394
- return count2 > 0 ? [{ ...line, gap: { ...line.gap, count: count2 } }] : [];
2395
- });
2396
- logs.push(...recovered);
2397
- logs.sort((a, b) => a.seq - b.seq);
2398
- return appendLogs({ ...session, logs: [], logSources: sources }, logs);
2399
- }
2400
2130
  function appendLogs(session, added) {
2401
2131
  const sources = {};
2402
2132
  for (const [source, counts] of Object.entries(session.logSources))
@@ -2406,10 +2136,10 @@ function appendLogs(session, added) {
2406
2136
  if (!line.gap) counts.lines++;
2407
2137
  }
2408
2138
  const drop = /* @__PURE__ */ new Map();
2409
- const take = (source, count2) => {
2410
- sources[source].lines -= count2;
2411
- sources[source].dropped += count2;
2412
- drop.set(source, (drop.get(source) ?? 0) + count2);
2139
+ const take = (source, count) => {
2140
+ sources[source].lines -= count;
2141
+ sources[source].dropped += count;
2142
+ drop.set(source, (drop.get(source) ?? 0) + count);
2413
2143
  };
2414
2144
  let total = 0;
2415
2145
  for (const [source, counts] of Object.entries(sources)) {
@@ -2419,12 +2149,12 @@ function appendLogs(session, added) {
2419
2149
  }
2420
2150
  while (total > MAX_LOG_LINES) {
2421
2151
  const [largest, second] = Object.entries(sources).sort(([, a], [, b]) => b.lines - a.lines);
2422
- const count2 = Math.max(
2152
+ const count = Math.max(
2423
2153
  1,
2424
2154
  Math.min(total - MAX_LOG_LINES, largest[1].lines - (second?.[1].lines ?? 0))
2425
2155
  );
2426
- take(largest[0], count2);
2427
- total -= count2;
2156
+ take(largest[0], count);
2157
+ total -= count;
2428
2158
  }
2429
2159
  const all = [...session.logs, ...added];
2430
2160
  if (drop.size === 0) return { ...session, logs: all, logSources: sources };
@@ -2437,10 +2167,13 @@ function appendLogs(session, added) {
2437
2167
  return { ...session, logs: kept, logSources: sources };
2438
2168
  }
2439
2169
  function applyOne(session, event, logs) {
2170
+ const runT0Ms = event.event === "run_start" && event.t_ms !== null ? event.t_ms : session.runT0Ms;
2171
+ const elapsedMs = event.t_ms === null ? session.elapsedMs : Math.max(session.elapsedMs, Math.max(0, event.t_ms - runT0Ms));
2440
2172
  const next = {
2441
2173
  ...session,
2442
2174
  lastSeq: event.seq,
2443
- elapsedMs: Math.max(session.elapsedMs, event.t_ms ?? 0)
2175
+ runT0Ms,
2176
+ elapsedMs
2444
2177
  };
2445
2178
  switch (event.event) {
2446
2179
  case "phase": {
@@ -2477,150 +2210,378 @@ function applyOne(session, event, logs) {
2477
2210
  logs.push({ seq: event.seq, key: String(event.seq), source: event.source, line: event.line });
2478
2211
  return next;
2479
2212
  case "log_dropped":
2480
- for (const [source, count2] of Object.entries(event.sources)) {
2481
- if (count2 > 0) {
2213
+ for (const [source, count] of Object.entries(event.sources)) {
2214
+ if (count > 0) {
2482
2215
  logs.push({
2483
2216
  seq: event.seq,
2484
2217
  key: `${event.seq} ${source}`,
2485
2218
  source,
2486
2219
  line: "",
2487
- gap: { count: count2, atLeast: false, launcher: true }
2220
+ gap: { count, atLeast: false, launcher: true }
2221
+ });
2222
+ }
2223
+ }
2224
+ return next;
2225
+ case "finding":
2226
+ return next.findings.length >= MAX_FINDINGS ? next : {
2227
+ ...next,
2228
+ findings: [...next.findings, { ...event.finding }]
2229
+ };
2230
+ case "time":
2231
+ return { ...next, simMs: event.sim_ms, timeOmittedFields: [], time: timeView(event) };
2232
+ case "command":
2233
+ return { ...next, lastCommand: commandView(event, event.seq) };
2234
+ case "state":
2235
+ return { ...next, launcherState: newerState(next.launcherState, event) };
2236
+ case "result":
2237
+ return {
2238
+ ...next,
2239
+ result: event.result,
2240
+ phase: "ended",
2241
+ phaseRank: phaseIndex("ended"),
2242
+ check: next.check ?? event.result.check,
2243
+ participants: mergeResult(next.participants, event.result),
2244
+ scenario: next.scenario && event.result.scenario ? {
2245
+ ...next.scenario,
2246
+ name: event.result.scenario.name,
2247
+ stepCount: next.scenario.stepCount ?? event.result.scenario.steps.length,
2248
+ steps: event.result.scenario.steps,
2249
+ status: event.result.scenario.status,
2250
+ overAtMs: event.result.scenario.over_at_ms
2251
+ } : next.scenario
2252
+ };
2253
+ default:
2254
+ return next;
2255
+ }
2256
+ }
2257
+ function mergeCheck(current, check) {
2258
+ const byName = new Map(current.map((p) => [p.name, p]));
2259
+ const ordered = [];
2260
+ for (const p of check.participants) {
2261
+ if (p.name === null) continue;
2262
+ const known = byName.get(p.name);
2263
+ byName.delete(p.name);
2264
+ ordered.push({
2265
+ ...known ?? blankParticipant(p.name),
2266
+ required: p.required,
2267
+ state: known?.state ?? (p.enabled === false ? "disabled" : null),
2268
+ manual: p.manual || !!known?.manual
2269
+ });
2270
+ }
2271
+ return [...ordered, ...byName.values()];
2272
+ }
2273
+ function updateParticipant(current, event) {
2274
+ const known = current.find((p) => p.name === event.name);
2275
+ const updated = {
2276
+ ...known ?? blankParticipant(event.name),
2277
+ state: event.state,
2278
+ // Events arrive whole (only the summary leaves fields out)
2279
+ omittedFields: []
2280
+ };
2281
+ if (event.pid !== null) updated.pid = event.pid;
2282
+ if (event.state === "failed") updated.failure = event.reason ?? "";
2283
+ if (event.state === "stop_requested") updated.stopRequested = true;
2284
+ if (event.message) updated.message = event.message;
2285
+ if (event.state === "manual") updated.manual = true;
2286
+ if (typeof event.command_line === "string") updated.commandLine = event.command_line;
2287
+ if (typeof event.working_directory === "string")
2288
+ updated.workingDirectory = event.working_directory;
2289
+ if (event.state === "manual") updated.environment = event.environment ?? {};
2290
+ if (event.state === "ended" || event.state === "killed") {
2291
+ updated.exitCode = event.exit_code;
2292
+ updated.signal = event.signal;
2293
+ }
2294
+ return known ? current.map((p) => p === known ? updated : p) : [...current, updated];
2295
+ }
2296
+ function withResult(participants, result) {
2297
+ return result ? mergeResult(participants, result) : participants;
2298
+ }
2299
+ function mergeResult(current, result) {
2300
+ const merged = [...current];
2301
+ for (const p of result.participants) {
2302
+ const i = merged.findIndex((known) => known.name === p.name);
2303
+ const base = i >= 0 ? merged[i] : blankParticipant(p.name);
2304
+ const state = !p.enabled ? "disabled" : p.ended === "killed" ? "killed" : p.ended === "not_started" ? base.state ?? "not_started" : "ended";
2305
+ const view = {
2306
+ ...base,
2307
+ required: p.required,
2308
+ state,
2309
+ exitCode: p.exit_code,
2310
+ signal: p.signal,
2311
+ stopRequested: base.stopRequested || p.ended === "stopped",
2312
+ // Keep what the events told about the connection (number of variables and so on); without it, only the result's
2313
+ // state. The result is newer (it has the count of messages that arrived late). What the result lacks comes from
2314
+ // the events
2315
+ controlLink: p.control_link ?? base.controlLink,
2316
+ manual: base.manual || p.manual
2317
+ };
2318
+ if (i >= 0) merged[i] = view;
2319
+ else merged.push(view);
2320
+ }
2321
+ return merged;
2322
+ }
2323
+ function blankParticipant(name) {
2324
+ return {
2325
+ name,
2326
+ state: null,
2327
+ required: null,
2328
+ pid: null,
2329
+ exitCode: null,
2330
+ signal: null,
2331
+ failure: null,
2332
+ message: null,
2333
+ stopRequested: false,
2334
+ omittedFields: [],
2335
+ controlLink: null,
2336
+ manual: false,
2337
+ commandLine: null,
2338
+ workingDirectory: null,
2339
+ environment: {}
2340
+ };
2341
+ }
2342
+
2343
+ // ../client/src/run.ts
2344
+ function answerMissing(path, error) {
2345
+ if (!error.timedOut) return null;
2346
+ return path === "api/run" ? `${error.message}: the server may still start the run (it checks the file again when it has changed); whether it did shows in the session over the WebSocket` : `${error.message}: the server may have done it; the session over the WebSocket shows what happened`;
2347
+ }
2348
+ var RunControl = class {
2349
+ constructor(feed, transport, onError = rethrowLater, startTimeoutMs = () => 0) {
2350
+ this.feed = feed;
2351
+ this.transport = transport;
2352
+ this.startTimeoutMs = startTimeoutMs;
2353
+ this.startSending = new Writable(false, Object.is, onError);
2354
+ this.stopSending = new Writable(null, Object.is, onError);
2355
+ this.pendingRevision = new Writable(0, Object.is, onError);
2356
+ this.stopAskedWhileStarting = new Writable(false, Object.is, onError);
2357
+ this.failure = new Writable(null, Object.is, onError);
2358
+ this.starting = this.startSending.readonly();
2359
+ this.stopping = this.stopSending.readonly();
2360
+ this.currentStopping = derived(
2361
+ [this.pendingRevision, this.startSending, feed.session],
2362
+ () => {
2363
+ const key = this.startSending.get() ? this.startOperation : JSON.stringify(this.activeTarget());
2364
+ return [...this.pendingStops].filter((pending) => pending.key === key).at(-1)?.action ?? null;
2365
+ },
2366
+ Object.is,
2367
+ onError
2368
+ );
2369
+ this.stopWhileStarting = this.stopAskedWhileStarting.readonly();
2370
+ feed.session.subscribe(() => {
2371
+ this.startedTarget = null;
2372
+ });
2373
+ this.error = derived(
2374
+ [this.failure, feed.session],
2375
+ () => {
2376
+ const failure = this.failure.get();
2377
+ const session = feed.session.get();
2378
+ if (!failure) return null;
2379
+ const same = failure.session === (session?.id ?? null) && failure.running === isRunActive(session);
2380
+ return same ? failure.message : null;
2381
+ },
2382
+ Object.is,
2383
+ onError
2384
+ );
2385
+ }
2386
+ feed;
2387
+ transport;
2388
+ startTimeoutMs;
2389
+ startOperation = null;
2390
+ startedTarget = null;
2391
+ pendingStops = /* @__PURE__ */ new Set();
2392
+ pendingRevision;
2393
+ startSending;
2394
+ stopSending;
2395
+ stopAskedWhileStarting;
2396
+ failure;
2397
+ starting;
2398
+ stopping;
2399
+ currentStopping;
2400
+ stopWhileStarting;
2401
+ error;
2402
+ /** Starts a run. */
2403
+ start(request) {
2404
+ if (this.startSending.get()) return Promise.reject(new Error("a start is already pending"));
2405
+ let resolveStart;
2406
+ let rejectStart;
2407
+ const operation = new Promise((resolve, reject) => {
2408
+ resolveStart = resolve;
2409
+ rejectStart = reject;
2410
+ });
2411
+ this.startOperation = operation;
2412
+ this.startedTarget = null;
2413
+ this.stopAskedWhileStarting.set(false);
2414
+ this.startSending.set(true);
2415
+ this.send("api/run", request, this.startTimeoutMs() || void 0, (ack) => {
2416
+ if (ack && this.feed.currentTarget()?.run_id !== ack.run_id) {
2417
+ this.startedTarget = {
2418
+ target: { run_id: ack.run_id, instance: ack.instance },
2419
+ sessionBefore: this.feed.session.get()
2420
+ };
2421
+ }
2422
+ this.startSending.set(false);
2423
+ }).then(resolveStart, rejectStart);
2424
+ return operation;
2425
+ }
2426
+ activeTarget() {
2427
+ if (this.startedTarget && this.feed.session.get() === this.startedTarget.sessionBefore) {
2428
+ return this.startedTarget.target;
2429
+ }
2430
+ return this.feed.currentTarget();
2431
+ }
2432
+ /** Stops in order (waits for the participants to end). Asking again never turns it into a stop without waiting. */
2433
+ stop() {
2434
+ return this.requestStop(false);
2435
+ }
2436
+ /** Stops without waiting (kills the participants). */
2437
+ forceStop() {
2438
+ return this.requestStop(true);
2439
+ }
2440
+ captureStop() {
2441
+ const starting = this.startSending.get() ? this.startOperation : null;
2442
+ const target = starting ? null : this.activeTarget();
2443
+ return {
2444
+ key: starting ?? JSON.stringify(target),
2445
+ send: (force) => this.requestStop(force, starting, target)
2446
+ };
2447
+ }
2448
+ requestStop(force, starting = this.startSending.get() ? this.startOperation : null, target = starting ? null : this.activeTarget()) {
2449
+ const session = this.feed.session.get();
2450
+ const pending = {
2451
+ action: force ? "force" : "stop",
2452
+ starting: !!starting,
2453
+ key: starting ?? JSON.stringify(target)
2454
+ };
2455
+ this.pendingStops.add(pending);
2456
+ this.pendingRevision.update((n) => n + 1);
2457
+ this.stopSending.set(pending.action);
2458
+ const done = () => {
2459
+ this.pendingStops.delete(pending);
2460
+ this.pendingRevision.update((n) => n + 1);
2461
+ const remaining = [...this.pendingStops];
2462
+ this.stopAskedWhileStarting.set(remaining.some((p) => p.starting));
2463
+ this.stopSending.set(remaining.at(-1)?.action ?? null);
2464
+ };
2465
+ if (!starting) {
2466
+ if (!target) {
2467
+ const message = "no session and server instance are known: no stop was sent; reconnect and check the current run";
2468
+ this.failure.set({
2469
+ message,
2470
+ session: session?.id ?? null,
2471
+ running: isRunActive(session)
2472
+ });
2473
+ done();
2474
+ return Promise.reject(new Error(message));
2475
+ }
2476
+ return this.send("api/stop-session", { force, ...target }, void 0, done);
2477
+ }
2478
+ this.stopAskedWhileStarting.set(true);
2479
+ return starting.then(
2480
+ (ack) => {
2481
+ pending.key = JSON.stringify({ run_id: ack.run_id, instance: ack.instance });
2482
+ this.pendingRevision.update((n) => n + 1);
2483
+ return this.send(
2484
+ "api/stop-session",
2485
+ { force, run_id: ack.run_id, instance: ack.instance },
2486
+ void 0,
2487
+ () => void 0
2488
+ );
2489
+ },
2490
+ (error) => {
2491
+ const session2 = this.feed.session.get();
2492
+ this.failure.set({
2493
+ message: `the start was not confirmed; no stop was sent: ${errorMessage(error)}`,
2494
+ session: session2?.id ?? null,
2495
+ running: isRunActive(session2)
2496
+ });
2497
+ throw new Error(`the start was not confirmed; no stop was sent: ${errorMessage(error)}`);
2498
+ }
2499
+ ).finally(done);
2500
+ }
2501
+ /**
2502
+ * Sends an HTTP command and reads its `{instance, run_id}` acknowledgement. done is called after the answer
2503
+ * (failures too), before the Promise settles.
2504
+ */
2505
+ send(path, body, timeoutMs, done) {
2506
+ const incompatible = this.feed.incompatible.get();
2507
+ if (incompatible) {
2508
+ done();
2509
+ return Promise.reject(new Error(incompatible));
2510
+ }
2511
+ this.failure.set(null);
2512
+ return new Promise((resolve, reject) => {
2513
+ this.transport({ method: "POST", path, body, timeoutMs }, (outcome) => {
2514
+ if (!outcome.ok) {
2515
+ const failure = path === "api/stop-session" && outcome.error.status === 404 ? new HttpError(404, outcome.error.statusText, {
2516
+ code: "targeted-stop-unsupported",
2517
+ message: "the GUI server cannot stop a particular session: no stop was sent; use the GUI server of this release"
2518
+ }) : outcome.error;
2519
+ const session = this.feed.session.get();
2520
+ this.failure.set({
2521
+ message: answerMissing(path, failure) ?? errorMessage(failure),
2522
+ session: session?.id ?? null,
2523
+ running: isRunActive(session)
2524
+ });
2525
+ done();
2526
+ reject(failure);
2527
+ return;
2528
+ }
2529
+ let ack;
2530
+ try {
2531
+ if (path === "api/stop-session") {
2532
+ const target = body;
2533
+ const raw = typeof outcome.body === "object" && outcome.body !== null ? outcome.body : {};
2534
+ ack = readRunResponse({
2535
+ instance: raw["instance"] ?? target.instance,
2536
+ run_id: raw["run_id"]
2537
+ });
2538
+ if (ack.run_id !== target.run_id || ack.instance !== target.instance) {
2539
+ throw new Error("the stop answer did not identify the requested session");
2540
+ }
2541
+ } else {
2542
+ readSessionInstance(outcome.body);
2543
+ ack = readRunResponse(outcome.body);
2544
+ }
2545
+ } catch (error) {
2546
+ this.feed.report(
2547
+ error instanceof ProtocolError ? `unreadable answer: ${error.message}` : String(error)
2548
+ );
2549
+ const missingInstance = error instanceof ProtocolError && error.path === "response.instance";
2550
+ const message = missingInstance ? `${error.message}. The run may have started. Check the current run before retrying` : path === "api/stop-session" ? "the stop answer was unreadable: check the session before trying again" : "the start answer did not identify the run; no stop was sent";
2551
+ const session = this.feed.session.get();
2552
+ this.failure.set({
2553
+ message,
2554
+ session: session?.id ?? null,
2555
+ running: isRunActive(session)
2488
2556
  });
2557
+ done();
2558
+ reject(new Error(message));
2559
+ return;
2489
2560
  }
2490
- }
2491
- return next;
2492
- case "finding":
2493
- return next.findings.length >= MAX_FINDINGS ? next : {
2494
- ...next,
2495
- findings: next.findings.every((finding) => finding.event_seq !== void 0) ? mergeFindings(next.findings, [{ ...event.finding, event_seq: event.seq }]) : [...next.findings, { ...event.finding, event_seq: event.seq }]
2496
- };
2497
- case "time":
2498
- return { ...next, simMs: event.sim_ms, timeOmittedFields: [], time: timeView(event) };
2499
- case "command":
2500
- return { ...next, lastCommand: commandView(event, event.seq) };
2501
- case "state":
2502
- return { ...next, launcherState: newerState(next.launcherState, event) };
2503
- case "result":
2504
- return {
2505
- ...next,
2506
- result: event.result,
2507
- phase: "ended",
2508
- phaseRank: phaseIndex("ended"),
2509
- check: next.check ?? event.result.check,
2510
- participants: mergeResult(next.participants, event.result),
2511
- scenario: next.scenario && event.result.scenario ? {
2512
- ...next.scenario,
2513
- name: event.result.scenario.name,
2514
- stepCount: next.scenario.stepCount ?? event.result.scenario.steps.length,
2515
- steps: event.result.scenario.steps,
2516
- status: event.result.scenario.status,
2517
- overAtMs: event.result.scenario.over_at_ms
2518
- } : next.scenario
2519
- };
2520
- default:
2521
- return next;
2522
- }
2523
- }
2524
- function mergeCheck(current, check) {
2525
- const byName = new Map(current.map((p) => [p.name, p]));
2526
- const ordered = [];
2527
- for (const p of check.participants) {
2528
- if (p.name === null) continue;
2529
- const known = byName.get(p.name);
2530
- byName.delete(p.name);
2531
- ordered.push({
2532
- ...known ?? blankParticipant(p.name),
2533
- required: p.required,
2534
- state: known?.state ?? (p.enabled === false ? "disabled" : null),
2535
- manual: p.manual || !!known?.manual
2561
+ done(ack);
2562
+ resolve(ack);
2563
+ });
2536
2564
  });
2537
2565
  }
2538
- return [...ordered, ...byName.values()];
2539
- }
2540
- function updateParticipant(current, event) {
2541
- const known = current.find((p) => p.name === event.name);
2542
- const updated = {
2543
- ...known ?? blankParticipant(event.name),
2544
- state: event.state,
2545
- // Events arrive whole (only the summary leaves fields out)
2546
- omittedFields: []
2547
- };
2548
- if (event.pid !== null) updated.pid = event.pid;
2549
- if (event.state === "failed") updated.failure = event.reason ?? "";
2550
- if (event.state === "stop_requested") updated.stopRequested = true;
2551
- if (event.message) updated.message = event.message;
2552
- if (event.state === "manual") updated.manual = true;
2553
- if (typeof event.command_line === "string") updated.commandLine = event.command_line;
2554
- if (typeof event.working_directory === "string")
2555
- updated.workingDirectory = event.working_directory;
2556
- if (event.state === "manual") updated.environment = event.environment ?? {};
2557
- if (event.state === "ended" || event.state === "killed") {
2558
- updated.exitCode = event.exit_code;
2559
- updated.signal = event.signal;
2560
- }
2561
- return known ? current.map((p) => p === known ? updated : p) : [...current, updated];
2562
- }
2563
- function withResult(participants, result) {
2564
- return result ? mergeResult(participants, result) : participants;
2565
- }
2566
- function mergeResult(current, result) {
2567
- const merged = [...current];
2568
- for (const p of result.participants) {
2569
- const i = merged.findIndex((known) => known.name === p.name);
2570
- const base = i >= 0 ? merged[i] : blankParticipant(p.name);
2571
- const state = !p.enabled ? "disabled" : p.ended === "killed" ? "killed" : p.ended === "not_started" ? base.state ?? "not_started" : "ended";
2572
- const view = {
2573
- ...base,
2574
- required: p.required,
2575
- state,
2576
- exitCode: p.exit_code,
2577
- signal: p.signal,
2578
- stopRequested: base.stopRequested || p.ended === "stopped",
2579
- // Keep what the events told about the connection (number of variables and so on); without it, only the result's
2580
- // state. The result is newer (it has the count of messages that arrived late). What the result lacks comes from
2581
- // the events
2582
- controlLink: p.control_link ?? base.controlLink,
2583
- manual: base.manual || p.manual
2584
- };
2585
- if (i >= 0) merged[i] = view;
2586
- else merged.push(view);
2587
- }
2588
- return merged;
2589
- }
2590
- function blankParticipant(name) {
2591
- return {
2592
- name,
2593
- state: null,
2594
- required: null,
2595
- pid: null,
2596
- exitCode: null,
2597
- signal: null,
2598
- failure: null,
2599
- message: null,
2600
- stopRequested: false,
2601
- omittedFields: [],
2602
- controlLink: null,
2603
- manual: false,
2604
- commandLine: null,
2605
- workingDirectory: null,
2606
- environment: {}
2607
- };
2608
- }
2566
+ };
2609
2567
 
2610
2568
  // ../client/src/session.ts
2611
2569
  var MAX_NOTICES = 20;
2612
2570
  var STALE_EVENTS_NOTICE = "events came with a seq that is not after the last one, and were not shown (the launcher wrote them out of order, or the server sent them again)";
2613
2571
  function sameRunTarget(left, right) {
2614
- return left !== null && right !== null && left.session === right.session && left.instance === right.instance;
2572
+ return left !== null && right !== null && left.run_id === right.run_id && left.instance === right.instance;
2615
2573
  }
2616
2574
  var SessionFeed = class {
2617
- constructor(connection, onError = rethrowLater) {
2575
+ constructor(connection, onError = rethrowLater, onInstance) {
2618
2576
  this.connection = connection;
2619
2577
  this.onError = onError;
2578
+ this.onInstance = onInstance;
2620
2579
  this.current = new Writable(null, Object.is, onError);
2621
2580
  this.synced = new Writable(false, Object.is, onError);
2622
2581
  this.allowedValue = new Writable(null, Object.is, onError);
2623
2582
  this.allowed = this.allowedValue.readonly();
2583
+ this.runtimeValue = new Writable(null, Object.is, onError);
2584
+ this.runtime = this.runtimeValue.readonly();
2624
2585
  this.receivedAt = new Writable(0, Object.is, onError);
2625
2586
  this.noticeList = new Writable([], Object.is, onError);
2626
2587
  this.rejectedValue = new Writable(false, Object.is, onError);
@@ -2643,15 +2604,16 @@ var SessionFeed = class {
2643
2604
  }
2644
2605
  connection;
2645
2606
  onError;
2607
+ onInstance;
2646
2608
  rawListeners = /* @__PURE__ */ new Set();
2647
- snapshotVersion = () => 0;
2648
2609
  instanceId = null;
2649
- adoptionRevision = 0;
2650
- instanceListener = () => void 0;
2610
+ lastStreamSeq = -1;
2611
+ resyncing = false;
2651
2612
  stopTarget = null;
2652
2613
  current;
2653
2614
  synced;
2654
2615
  allowedValue;
2616
+ runtimeValue;
2655
2617
  receivedAt;
2656
2618
  noticeList;
2657
2619
  rejectedValue;
@@ -2659,10 +2621,10 @@ var SessionFeed = class {
2659
2621
  messageListeners = /* @__PURE__ */ new Set();
2660
2622
  noticeId = 0;
2661
2623
  stoppedFlag = false;
2662
- replayLogs = null;
2663
2624
  session;
2664
2625
  ready;
2665
2626
  allowed;
2627
+ runtime;
2666
2628
  lastEventAt;
2667
2629
  notices;
2668
2630
  rejected;
@@ -2672,13 +2634,19 @@ var SessionFeed = class {
2672
2634
  return this.stoppedFlag;
2673
2635
  }
2674
2636
  /**
2675
- * Fields to add to the authentication message: where in the session it holds the server should resend from. Called
2637
+ * Fields to add to the authentication message: where in the stream it holds the server should resend from. Called
2676
2638
  * on every connect (after the call, the copy is not in sync until hello and the resent events have arrived). Used
2677
2639
  * only inside the library.
2678
2640
  */
2679
2641
  resumeFields() {
2680
2642
  this.synced.set(false);
2681
- return {};
2643
+ const session = this.current.get();
2644
+ if (this.instanceId === null || session === null || this.lastStreamSeq < 0) return {};
2645
+ return {
2646
+ instance: this.instanceId,
2647
+ run_id: session.id,
2648
+ after_stream_seq: this.lastStreamSeq
2649
+ };
2682
2650
  }
2683
2651
  onMessages(listener) {
2684
2652
  this.messageListeners.add(listener);
@@ -2686,23 +2654,10 @@ var SessionFeed = class {
2686
2654
  this.messageListeners.delete(listener);
2687
2655
  };
2688
2656
  }
2689
- /**
2690
- * Applies the summary in an HTTP answer without waiting for the notification (the answers to start, stop and
2691
- * fetchSession(); used inside the library). While the WebSocket is connected, takes only the launcher and the stop
2692
- * request for the same run (the rest arrives in notifications). A summary of an earlier run never brings back an old
2693
- * run over a new one.
2694
- */
2695
2657
  onRawMessages(listener) {
2696
2658
  this.rawListeners.add(listener);
2697
2659
  return () => this.rawListeners.delete(listener);
2698
2660
  }
2699
- onSnapshotVersion(read2) {
2700
- this.snapshotVersion = read2;
2701
- }
2702
- /** Called before a new server's session can be published. */
2703
- onInstance(listener) {
2704
- this.instanceListener = listener;
2705
- }
2706
2661
  /** Instance associated with the current session, or null if its origin is not known. */
2707
2662
  currentInstance() {
2708
2663
  return this.instanceId;
@@ -2710,57 +2665,14 @@ var SessionFeed = class {
2710
2665
  currentTarget() {
2711
2666
  return this.stopTarget ? { ...this.stopTarget } : null;
2712
2667
  }
2713
- adopt(summary, instance, resyncFrom) {
2714
- const switching = this.instanceId !== null && instance !== this.instanceId;
2715
- if (switching && (resyncFrom !== this.instanceId || this.connection.state.get() === "open"))
2716
- return null;
2717
- const previous = switching ? null : this.current.get();
2718
- if (summary && previous && summary.id < previous.id) return null;
2719
- if (!summary && instance === this.instanceId)
2720
- return {
2721
- revision: this.adoptionRevision,
2722
- instance,
2723
- session: previous?.id ?? null
2724
- };
2725
- const revision = ++this.adoptionRevision;
2726
- const next = !summary ? null : previous?.id === summary.id ? applySummary(previous, summary, false, this.connection.state.get() === "open") : sessionFromSummary(summary);
2727
- const changedInstance = instance !== this.instanceId;
2728
- this.instanceId = instance;
2729
- const adoption = { revision, instance, session: next?.id ?? null };
2730
- this.stopTarget = next ? { session: next.id, instance } : null;
2731
- const notifySession = this.current.setDeferred(next);
2732
- const notifyAllowed = switching ? this.allowedValue.setDeferred(null) : () => void 0;
2733
- if (changedInstance) this.instanceListener(instance, () => this.isCurrent(revision));
2734
- notifySession();
2735
- notifyAllowed();
2736
- if (!this.sameRun(adoption)) return null;
2737
- this.adoptAllowed(summary?.allowed ?? null);
2738
- return this.sameRun(adoption) ? adoption : null;
2739
- }
2740
- sameRun(adoption) {
2741
- return this.instanceId === adoption.instance && (this.current.get()?.id ?? null) === adoption.session;
2742
- }
2743
- isCurrent(revision) {
2744
- return revision === this.adoptionRevision;
2745
- }
2746
- /**
2747
- * Takes what the server accepts (an HTTP answer or a notification): the one with the larger `rev` wins (rev 0 is a
2748
- * server that does not number it: the newest arrival wins). Used inside the library.
2749
- */
2750
- adoptAllowed(allowed) {
2751
- if (!allowed) return;
2752
- const current = this.allowedValue.get();
2753
- if (!current || allowed.rev === 0 || allowed.rev >= current.rev) this.allowedValue.set(allowed);
2754
- }
2755
- report(message, count2 = 1) {
2756
- this.notify(message, count2);
2668
+ report(message, count = 1) {
2669
+ this.notify(message, count);
2757
2670
  }
2758
2671
  dismissNotice(id) {
2759
2672
  this.noticeList.update((list) => list.filter((notice) => notice.id !== id));
2760
2673
  }
2761
2674
  /** Reads and applies a batch from the connection. */
2762
2675
  receive(raw) {
2763
- const snapshotVersion = this.snapshotVersion();
2764
2676
  const epoch = this.connection.batchEpoch();
2765
2677
  let originInstance = this.instanceId;
2766
2678
  const currentOrigin = () => this.connection.batchEpoch() === epoch && this.instanceId === originInstance;
@@ -2798,8 +2710,6 @@ var SessionFeed = class {
2798
2710
  break;
2799
2711
  }
2800
2712
  }
2801
- let filtered = this.filterOlderRuns(batch, accepted);
2802
- if (filtered.staleHello && stop === null) stop = "lost";
2803
2713
  if (stop === "unauthorized" || stop === "incompatible") {
2804
2714
  this.stoppedFlag = true;
2805
2715
  this.connection.close();
@@ -2810,8 +2720,7 @@ var SessionFeed = class {
2810
2720
  }
2811
2721
  if (stop === "lost") this.connection.restart();
2812
2722
  if (!currentOrigin()) return;
2813
- filtered = this.filterOlderRuns(filtered.batch, filtered.raw);
2814
- this.apply(filtered.batch, filtered.raw, snapshotVersion, currentOrigin, (instance) => {
2723
+ this.apply(batch, accepted, currentOrigin, (instance) => {
2815
2724
  originInstance = instance;
2816
2725
  });
2817
2726
  if (!currentOrigin()) return;
@@ -2819,52 +2728,23 @@ var SessionFeed = class {
2819
2728
  if (stop === "unauthorized") this.rejectedValue.set(true);
2820
2729
  if (incompatible !== null) this.incompatibleValue.set(incompatible);
2821
2730
  }
2822
- /** Keep messages at or after the run already observed over HTTP, within each server instance. */
2823
- filterOlderRuns(batch, raw) {
2824
- let instance = this.instanceId;
2825
- let floor = this.current.get()?.id ?? null;
2826
- let staleHello = false;
2827
- const selected = [];
2828
- const selectedRaw = [];
2829
- batch.forEach((message, index) => {
2830
- if (message.type === "hello") {
2831
- const id = message.session?.id ?? null;
2832
- if (instance === message.instance && floor !== null && (id === null || id < floor)) {
2833
- staleHello = true;
2834
- return;
2835
- }
2836
- if (instance !== message.instance) {
2837
- instance = message.instance;
2838
- floor = id;
2839
- } else if (id !== null) floor = id;
2840
- } else {
2841
- const id = message.type === "session" ? message.session.id : "session" in message && typeof message.session === "number" ? message.session : null;
2842
- if (id !== null && floor !== null && id < floor) return;
2843
- if (message.type === "session" && (floor === null || message.session.id > floor))
2844
- floor = message.session.id;
2845
- }
2846
- selected.push(message);
2847
- selectedRaw.push(raw[index]);
2848
- });
2849
- return { batch: selected, raw: selectedRaw, staleHello };
2850
- }
2851
- apply(batch, raw, snapshotVersion, currentOrigin, commitOrigin) {
2731
+ apply(batch, raw, currentOrigin, commitOrigin) {
2852
2732
  if (batch.length === 0) return;
2853
- const revision = ++this.adoptionRevision;
2854
2733
  const before = this.current.get();
2855
- const originalInstance = this.instanceId;
2856
- let instance = originalInstance;
2734
+ let instance = this.instanceId;
2857
2735
  let session = before;
2858
- let replayLogs = this.replayLogs?.instance === instance && this.replayLogs?.session === session?.id ? this.replayLogs : null;
2859
- const unseenLogs = () => replayLogs?.logs.filter((line) => replayLogs?.unseen.has(line.seq)) ?? [];
2736
+ let streamSeq = this.lastStreamSeq;
2737
+ let resyncing = this.resyncing;
2860
2738
  let events = [];
2861
2739
  const notices = [];
2740
+ const selectedBatch = [];
2741
+ const selectedRaw = [];
2862
2742
  let applied = false;
2863
2743
  let synced = this.synced.get();
2864
2744
  let allowedNow = this.allowedValue.get();
2865
- const takeAllowed = (incoming, replace = false) => {
2866
- if (!incoming) return;
2867
- if (replace || !allowedNow || incoming.rev === 0 || incoming.rev >= allowedNow.rev) {
2745
+ let runtimeNow = this.runtimeValue.get();
2746
+ const takeAllowed = (incoming) => {
2747
+ if (incoming) {
2868
2748
  allowedNow = incoming;
2869
2749
  }
2870
2750
  };
@@ -2876,132 +2756,185 @@ var SessionFeed = class {
2876
2756
  }
2877
2757
  events = [];
2878
2758
  };
2879
- for (const message of batch) {
2759
+ for (let i = 0; i < batch.length; i++) {
2760
+ const message = batch[i];
2761
+ const rawMessage = raw[i];
2762
+ if (message.type !== "hello" && message.type !== "resync" && message.type !== "values" && typeof message.stream_seq === "number") {
2763
+ if (!replaying && message.stream_seq <= streamSeq) {
2764
+ continue;
2765
+ }
2766
+ streamSeq = Math.max(streamSeq, message.stream_seq);
2767
+ }
2880
2768
  if (message.type !== "event") flush();
2881
2769
  switch (message.type) {
2882
2770
  case "hello": {
2883
2771
  synced = false;
2884
2772
  replaying = true;
2885
2773
  const { session: summary, replay } = message;
2886
- const staleSnapshot = !!summary && instance === message.instance && session?.id === summary.id && session.snapshotRev != null && (summary.snapshot_rev == null || summary.snapshot_rev < session.snapshotRev);
2887
- takeAllowed(message.allowed ?? summary?.allowed ?? null, !staleSnapshot);
2888
- const sameRun2 = summary && instance === message.instance && session?.id === summary.id;
2889
- const resumed = sameRun2 && replay?.from_seq != null;
2774
+ const sameInstance = instance !== null && instance === message.instance;
2775
+ const sameRun = !!summary && sameInstance && session?.id === summary.id;
2776
+ const deltaResume = sameRun && !resyncing && replay?.after_stream_seq != null;
2777
+ resyncing = false;
2778
+ if (typeof message.stream_seq === "number") {
2779
+ streamSeq = message.stream_seq;
2780
+ } else if (!sameInstance) {
2781
+ streamSeq = summary ? summary.last_seq ?? 0 : -1;
2782
+ } else if (summary) {
2783
+ streamSeq = deltaResume ? Math.max(streamSeq, summary.last_seq ?? 0) : summary.last_seq ?? 0;
2784
+ } else {
2785
+ streamSeq = -1;
2786
+ }
2787
+ takeAllowed(message.allowed ?? summary?.allowed ?? null);
2788
+ if (message.runtime !== void 0) {
2789
+ runtimeNow = message.runtime;
2790
+ } else if (!sameInstance) {
2791
+ runtimeNow = null;
2792
+ }
2890
2793
  instance = message.instance;
2891
- if (!sameRun2) replayLogs = null;
2892
2794
  if (!summary) {
2893
2795
  session = null;
2894
- } else if (sameRun2 && session) {
2895
- const kept = applySummary(session, summary, true, true);
2896
- if (!resumed && instance) {
2897
- const logs = replayLogs ? recoverReplayLogs(kept, unseenLogs(), replayLogs.notKept).logs : kept.logs;
2898
- replayLogs = {
2899
- instance,
2900
- session: summary.id,
2901
- logs: logs.filter((line) => !line.gap || line.gap.launcher),
2902
- unseen: new Set(logs.map((line) => line.seq)),
2903
- notKept: /* @__PURE__ */ new Map()
2904
- };
2905
- }
2906
- session = resumed ? kept : { ...kept, lastSeq: -1, logs: [], logSources: {}, droppedMarks: 0 };
2796
+ } else if (deltaResume && session) {
2797
+ session = applySummary(session, summary);
2907
2798
  } else {
2908
2799
  session = sessionFromSummary(summary);
2909
2800
  }
2801
+ selectedBatch.push(message);
2802
+ selectedRaw.push(rawMessage);
2910
2803
  break;
2911
2804
  }
2912
2805
  case "dropped": {
2913
- if (session && message.session === session.id) {
2806
+ if (session && message.run_id === session.id) {
2914
2807
  session = addDropped(session, message);
2915
- if (message.reason === "not-kept" && replayLogs) {
2916
- for (const [source, count2] of Object.entries(message.log))
2917
- replayLogs.notKept.set(source, (replayLogs.notKept.get(source) ?? 0) + count2);
2918
- }
2808
+ } else if (session && message.run_id !== null) {
2809
+ continue;
2919
2810
  }
2811
+ selectedBatch.push(message);
2812
+ selectedRaw.push(rawMessage);
2920
2813
  break;
2921
2814
  }
2922
- case "synced":
2923
- if (session && replayLogs && replayLogs.instance === instance && replayLogs.session === session.id)
2924
- session = recoverReplayLogs(session, unseenLogs(), replayLogs.notKept);
2925
- replayLogs = null;
2926
- synced = true;
2927
- replaying = false;
2815
+ case "synced": {
2816
+ if (message.run_id === null ? session === null : session?.id === message.run_id) {
2817
+ synced = true;
2818
+ replaying = false;
2819
+ } else {
2820
+ continue;
2821
+ }
2822
+ selectedBatch.push(message);
2823
+ selectedRaw.push(rawMessage);
2928
2824
  break;
2825
+ }
2929
2826
  case "allowed":
2827
+ if (message.run_id !== null && (!session || message.run_id !== session.id)) {
2828
+ continue;
2829
+ }
2930
2830
  takeAllowed(message.allowed);
2831
+ selectedBatch.push(message);
2832
+ selectedRaw.push(rawMessage);
2833
+ break;
2834
+ case "runtime":
2835
+ runtimeNow = message.runtime;
2836
+ selectedBatch.push(message);
2837
+ selectedRaw.push(rawMessage);
2931
2838
  break;
2932
2839
  case "session":
2933
- if (session?.id !== message.session.id) replayLogs = null;
2934
2840
  takeAllowed(message.session.allowed);
2935
- session = session?.id === message.session.id ? applySummary(
2936
- session,
2937
- message.session,
2938
- true,
2939
- message.session.last_seq !== null && (session.observedSeq ?? session.lastSeq) >= message.session.last_seq
2940
- ) : sessionFromSummary(message.session);
2841
+ session = session?.id === message.session.id ? applySummary(session, message.session) : sessionFromSummary(message.session);
2842
+ if (typeof message.stream_seq !== "number" && message.session.last_seq !== null) {
2843
+ streamSeq = Math.max(streamSeq, message.session.last_seq);
2844
+ }
2845
+ selectedBatch.push(message);
2846
+ selectedRaw.push(rawMessage);
2941
2847
  break;
2942
2848
  case "event":
2943
- if (session?.id === message.session) {
2944
- if (message.event.event === "log" || message.event.event === "log_dropped")
2945
- replayLogs?.unseen.delete(message.event.seq);
2849
+ if (session?.id === message.run_id) {
2946
2850
  events.push(message.event);
2851
+ if (typeof message.stream_seq !== "number") {
2852
+ streamSeq = Math.max(streamSeq, message.event.seq);
2853
+ }
2854
+ selectedBatch.push(message);
2855
+ selectedRaw.push(rawMessage);
2947
2856
  }
2948
2857
  break;
2949
2858
  case "error":
2950
2859
  if (message.code === "unauthorized") {
2951
- } else if (session && message.session === session.id) {
2952
- const { code, message: text3, skipped, problem_seq } = message;
2860
+ } else if (session && message.run_id === session.id) {
2861
+ const { code, message: text3, skipped } = message;
2953
2862
  session = addProblem(session, {
2954
2863
  code,
2955
2864
  message: text3,
2956
- ...skipped === void 0 ? {} : { skipped },
2957
- ...problem_seq === void 0 ? {} : { problem_seq }
2865
+ ...skipped === void 0 ? {} : { skipped }
2958
2866
  });
2959
- } else {
2867
+ } else if (message.run_id === null) {
2960
2868
  notices.push(message.message);
2869
+ } else {
2870
+ continue;
2961
2871
  }
2872
+ selectedBatch.push(message);
2873
+ selectedRaw.push(rawMessage);
2962
2874
  break;
2963
2875
  case "resync":
2964
2876
  synced = false;
2965
2877
  replaying = true;
2878
+ resyncing = true;
2879
+ selectedBatch.push(message);
2880
+ selectedRaw.push(rawMessage);
2881
+ break;
2882
+ default:
2883
+ if (session !== null && "run_id" in message && message.run_id !== session.id) {
2884
+ continue;
2885
+ }
2886
+ selectedBatch.push(message);
2887
+ selectedRaw.push(rawMessage);
2966
2888
  break;
2967
2889
  }
2968
2890
  }
2969
2891
  flush();
2970
2892
  const stale = (session?.staleEvents ?? 0) - (before?.id === session?.id ? before?.staleEvents ?? 0 : 0);
2971
- if (!currentOrigin() || !this.isCurrent(revision)) return;
2893
+ if (!currentOrigin()) return;
2894
+ const beforeInstance = this.instanceId;
2972
2895
  this.instanceId = instance;
2896
+ this.lastStreamSeq = streamSeq;
2897
+ this.resyncing = resyncing;
2973
2898
  commitOrigin(instance);
2974
- this.replayLogs = replayLogs && replayLogs.session === session?.id && replayLogs.instance === instance ? replayLogs : null;
2975
- this.stopTarget = session && instance ? { session: session.id, instance } : null;
2899
+ this.stopTarget = session && instance ? { run_id: session.id, instance } : null;
2976
2900
  const sessionId = session?.id ?? null;
2977
- const sameRun = () => currentOrigin() && this.instanceId === instance && (this.current.get()?.id ?? null) === sessionId;
2901
+ const sameStream = () => currentOrigin() && this.instanceId === instance && (this.current.get()?.id ?? null) === sessionId;
2978
2902
  const notifySession = this.current.setDeferred(session);
2979
2903
  const notifyAllowed = this.allowedValue.setDeferred(allowedNow);
2904
+ const notifyRuntime = this.runtimeValue.setDeferred(runtimeNow);
2980
2905
  const notifySynced = this.synced.setDeferred(synced);
2981
- if (instance && instance !== originalInstance) this.instanceListener(instance, sameRun);
2906
+ if (instance !== null && instance !== beforeInstance) {
2907
+ this.onInstance?.(instance);
2908
+ if (!sameStream()) return;
2909
+ }
2982
2910
  notifySession();
2983
2911
  notifyAllowed();
2912
+ notifyRuntime();
2984
2913
  notifySynced();
2985
- if (!sameRun()) return;
2914
+ if (!sameStream()) return;
2986
2915
  for (const notice of notices) {
2987
2916
  this.notify(notice);
2988
- if (!sameRun()) return;
2917
+ if (!sameStream()) return;
2989
2918
  }
2990
2919
  if (applied) this.receivedAt.set(Date.now());
2991
- if (!sameRun()) return;
2920
+ if (!sameStream()) return;
2992
2921
  if (stale > 0) this.notify(STALE_EVENTS_NOTICE, stale);
2993
- if (!sameRun()) return;
2994
- callEach(this.rawListeners, [raw, sameRun, snapshotVersion], this.onError, sameRun);
2995
- if (!sameRun()) return;
2996
- callEach(this.messageListeners, [batch], this.onError, sameRun);
2922
+ if (!sameStream()) return;
2923
+ if (selectedRaw.length > 0) {
2924
+ callEach(this.rawListeners, [selectedRaw, sameStream], this.onError, sameStream);
2925
+ }
2926
+ if (!sameStream()) return;
2927
+ if (selectedBatch.length > 0) {
2928
+ callEach(this.messageListeners, [selectedBatch], this.onError, sameStream);
2929
+ }
2997
2930
  }
2998
- notify(message, count2 = 1) {
2931
+ notify(message, count = 1) {
2999
2932
  this.noticeList.update((list) => {
3000
2933
  const same = list.find((notice) => notice.message === message);
3001
2934
  if (same) {
3002
- return [...list.filter((n) => n !== same), { ...same, count: same.count + count2 }];
2935
+ return [...list.filter((n) => n !== same), { ...same, count: same.count + count }];
3003
2936
  }
3004
- return [...list, { id: ++this.noticeId, message, count: count2 }].slice(-MAX_NOTICES);
2937
+ return [...list, { id: ++this.noticeId, message, count }].slice(-MAX_NOTICES);
3005
2938
  });
3006
2939
  }
3007
2940
  };
@@ -3064,7 +2997,7 @@ var TimeControl = class {
3064
2997
  send(command) {
3065
2998
  const session = this.session.get();
3066
2999
  const target = this.currentTarget();
3067
- if (!session || target?.session !== session.id) return { sent: false, reason: "no-session" };
3000
+ if (!session || target?.run_id !== session.id) return { sent: false, reason: "no-session" };
3068
3001
  if (this.state.get().sending !== null) return { sent: false, reason: "waiting" };
3069
3002
  this.failureValue.set(null);
3070
3003
  const pending = {
@@ -3090,7 +3023,7 @@ var TimeControl = class {
3090
3023
  kind: "server",
3091
3024
  message: errorMessage(outcome.error),
3092
3025
  command: pending.command,
3093
- session: target.session
3026
+ session: target.run_id
3094
3027
  }
3095
3028
  });
3096
3029
  }
@@ -3113,7 +3046,7 @@ var TimeControl = class {
3113
3046
  kind: "no-answer",
3114
3047
  message: `the launcher did not answer the command (${pending.command}) within ${this.answerTimeoutMs / 1e3} s; it may not read its input. You can send it again.`,
3115
3048
  command: pending.command,
3116
- session: pending.target.session
3049
+ session: pending.target.run_id
3117
3050
  }
3118
3051
  });
3119
3052
  }
@@ -3134,7 +3067,7 @@ var TimeControl = class {
3134
3067
  const target = this.currentTarget();
3135
3068
  let sending = null;
3136
3069
  if (pending && sameRunTarget(pending.target, target)) {
3137
- const answered = !session || !session.launcher.running || (session.lastCommand?.seq ?? -1) > pending.afterSeq;
3070
+ const answered = !session || !isRunActive(session) || (session.lastCommand?.seq ?? -1) > pending.afterSeq;
3138
3071
  sending = this.awaitingHttp.get() === pending || !answered ? pending.command : null;
3139
3072
  }
3140
3073
  const failure = this.failureValue.get();
@@ -3243,69 +3176,56 @@ var keyOf = (peer, name) => `${peer}\0${name}`;
3243
3176
  var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
3244
3177
  var text = (value, fallback = "") => typeof value === "string" ? value : fallback;
3245
3178
  var numberOrNull = (value) => typeof value === "number" && Number.isFinite(value) ? value : null;
3246
- var count = (value) => typeof value === "number" && value >= 0 ? value : 0;
3247
- var positionOrNull = (value) => Number.isSafeInteger(value) && value >= 0 ? value : null;
3248
3179
  function readVariables2(value, session) {
3249
- if (!isObject(value)) return { ...NO_VARIABLES, session };
3180
+ const u = new Unreadable("variables");
3181
+ const summary = lenient(
3182
+ (v) => readVariablesReport(v, "variables", u),
3183
+ null,
3184
+ u
3185
+ )(value, "variables");
3186
+ if (!summary) return { ...NO_VARIABLES, session };
3250
3187
  const peers = [];
3251
3188
  const availability = /* @__PURE__ */ new Map();
3252
- for (const p of Array.isArray(value["peers"]) ? value["peers"] : []) {
3253
- if (!isObject(p) || typeof p["name"] !== "string") continue;
3189
+ for (const p of summary.peers) {
3254
3190
  const variables = [];
3255
3191
  const states = /* @__PURE__ */ new Map();
3256
- for (const v of Array.isArray(p["variables"]) ? p["variables"] : []) {
3257
- if (!isObject(v) || typeof v["name"] !== "string") continue;
3258
- const items2 = Array.isArray(v["enum"]) ? v["enum"].flatMap(
3259
- (i) => isObject(i) && typeof i["name"] === "string" && typeof i["value"] === "number" ? [{ name: i["name"], value: i["value"] }] : []
3260
- ) : null;
3261
- variables.push({
3262
- name: v["name"],
3263
- type: text(v["type"]),
3264
- role: text(v["role"], "output"),
3265
- writable: v["writable"] === true,
3266
- unit: text(v["unit"]),
3267
- min: numberOrNull(v["min"]),
3268
- max: numberOrNull(v["max"]),
3269
- step: numberOrNull(v["step"]),
3270
- description: text(v["description"]),
3271
- enum: items2
3272
- });
3273
- states.set(v["name"], readAvailability(v["availability"]));
3192
+ for (const { availability: state, ...info } of p.variables) {
3193
+ variables.push(info);
3194
+ states.set(info.name, state);
3274
3195
  }
3275
- availability.set(p["name"], states);
3276
- peers.push({ name: p["name"], connected: p["connected"] === true, variables });
3196
+ availability.set(p.name, states);
3197
+ peers.push({ name: p.name, connected: p.connected, variables });
3277
3198
  }
3278
3199
  return {
3279
3200
  session,
3280
- status: text(value["state"], "unknown"),
3281
- reason: typeof value["reason"] === "string" ? value["reason"] : null,
3201
+ status: summary.state,
3202
+ reason: summary.reason,
3282
3203
  peers,
3283
3204
  availability,
3284
- peersOmitted: count(value["peers_omitted"]),
3285
- variablesOmitted: count(value["variables_omitted"])
3205
+ peersOmitted: summary.peers_omitted,
3206
+ variablesOmitted: summary.variables_omitted
3286
3207
  };
3287
3208
  }
3288
3209
  function readOperation(value, session) {
3289
- if (!isObject(value) || !Number.isSafeInteger(value["seq"]) || typeof value["state"] !== "string") {
3290
- return null;
3291
- }
3210
+ const u = new Unreadable("operation");
3211
+ const report = lenient((v, p) => readOperationReport(v, p, u), null, u)(value, "operation");
3212
+ if (!report) return null;
3292
3213
  const peers = {};
3293
- for (const [name, p] of Object.entries(isObject(value["peers"]) ? value["peers"] : {})) {
3294
- if (!isObject(p)) continue;
3214
+ for (const [name, p] of Object.entries(report.peers)) {
3295
3215
  peers[name] = {
3296
- state: text(p["state"], "unknown"),
3297
- appliedAtMs: numberOrNull(p["applied_at_ms"]),
3298
- late: p["late"] === true,
3299
- reason: typeof p["reason"] === "string" ? p["reason"] : null,
3300
- appliedWrites: positionOrNull(p["applied_writes"]),
3301
- failedWrite: positionOrNull(p["failed_write"])
3216
+ state: p.state,
3217
+ appliedAtMs: p.applied_at_ms,
3218
+ late: p.late,
3219
+ reason: p.reason,
3220
+ appliedWrites: p.applied_writes,
3221
+ failedWrite: p.failed_write
3302
3222
  };
3303
3223
  }
3304
3224
  return {
3305
3225
  session,
3306
- seq: value["seq"],
3307
- state: value["state"],
3308
- done: value["done"] === true,
3226
+ seq: report.seq,
3227
+ state: report.state,
3228
+ done: report.done,
3309
3229
  peers
3310
3230
  };
3311
3231
  }
@@ -3403,6 +3323,7 @@ function lost(seq, summary) {
3403
3323
  summary.openOmitted ? `the server does not keep track of the write (operation ${seq}) any more (it holds too many open operations): its result may not come; look at the values before writing again` : `the result of the write (operation ${seq}) was lost while the connection was down (it was settled meanwhile, and the server does not list it any more): look at the values before writing again`
3404
3324
  );
3405
3325
  }
3326
+ var runIdOf = (value) => typeof value === "string" && value.length > 0 ? value : null;
3406
3327
  var VariablesFeed = class {
3407
3328
  constructor(link, http, onError = rethrowLater, limits = () => ({})) {
3408
3329
  this.link = link;
@@ -3415,18 +3336,13 @@ var VariablesFeed = class {
3415
3336
  this.state = this.stateValue.readonly();
3416
3337
  this.operations = this.operationsValue.readonly();
3417
3338
  this.watchProblem = this.problemValue.readonly();
3418
- link.onBatch(
3419
- (batch, current, snapshotCurrent) => this.receive(batch, current, snapshotCurrent)
3420
- );
3339
+ link.onBatch((batch, current) => this.receive(batch, current));
3421
3340
  }
3422
3341
  link;
3423
3342
  http;
3424
3343
  onError;
3425
3344
  limits;
3426
3345
  instanceId = null;
3427
- snapshotVersionValue = 0;
3428
- snapshotIdentity = null;
3429
- serverRevision = null;
3430
3346
  stateValue;
3431
3347
  operationsValue;
3432
3348
  handles = /* @__PURE__ */ new Set();
@@ -3475,9 +3391,13 @@ var VariablesFeed = class {
3475
3391
  }
3476
3392
  }
3477
3393
  // --- Notifications --------------------------------------------------------------------------
3478
- receive(batch, current = () => true, initialSnapshotVersion = this.snapshotVersionValue) {
3479
- let snapshotVersion = initialSnapshotVersion;
3480
- const snapshotCurrent = (session, rev) => this.isSnapshotCurrent(snapshotVersion, this.instanceId, session, rev);
3394
+ onInstance(instance) {
3395
+ if (this.instanceId === instance) return;
3396
+ const hadInstance = this.instanceId !== null;
3397
+ this.instanceId = instance;
3398
+ if (hadInstance) this.enter(null, true);
3399
+ }
3400
+ receive(batch, current = () => true) {
3481
3401
  const touched = /* @__PURE__ */ new Set();
3482
3402
  let touchedAll = false;
3483
3403
  let operations = null;
@@ -3490,26 +3410,53 @@ var VariablesFeed = class {
3490
3410
  for (const message of batch) {
3491
3411
  if (!current()) return;
3492
3412
  if (!isObject(message)) continue;
3493
- const messageSession = message["session"];
3494
- const existingSession = this.stateValue.get().session;
3495
- if (typeof messageSession === "number" && existingSession !== null && messageSession < existingSession)
3496
- continue;
3497
3413
  switch (message["type"]) {
3498
3414
  case "hello": {
3499
3415
  flush();
3500
3416
  if (!current()) return;
3501
3417
  const summary = message["session"];
3502
- this.adoptInstance(message["instance"]);
3418
+ const nextInstance = runIdOf(message["instance"]);
3419
+ const instanceChanged = this.instanceId !== null && nextInstance !== null && this.instanceId !== nextInstance;
3420
+ if (nextInstance !== null) this.instanceId = nextInstance;
3421
+ if (instanceChanged) this.enter(null, true);
3503
3422
  if (!current()) return;
3504
- if (isObject(summary) && Number.isSafeInteger(summary["id"])) {
3505
- const id = summary["id"];
3506
- const details = summary["variables"];
3507
- const rev = isObject(details) ? positionOrNull(details["rev"]) : null;
3508
- const applied = this.adoptSummary(summary, current, () => snapshotCurrent(id, rev));
3509
- if (applied !== null && this.snapshotVersionValue === applied)
3510
- snapshotVersion = applied;
3423
+ const id = isObject(summary) ? runIdOf(summary["id"]) : null;
3424
+ if (isObject(summary) && id !== null) {
3425
+ const instance = this.instanceId;
3426
+ if (id !== this.stateValue.get().session) {
3427
+ this.enter(id);
3428
+ if (!current()) return;
3429
+ }
3430
+ const sameIdentity = () => current() && this.instanceId === instance && this.stateValue.get().session === id;
3431
+ const variables = summary["variables"];
3432
+ if (sameIdentity() && variables !== void 0) {
3433
+ let notifyOperations = () => void 0;
3434
+ const listed = [];
3435
+ if (isObject(variables) && Array.isArray(variables["operations"])) {
3436
+ let currentOps = this.operationsValue.get();
3437
+ for (const entry of variables["operations"]) {
3438
+ const operation = readOperation(entry, id);
3439
+ if (operation) {
3440
+ listed.push(operation);
3441
+ currentOps = this.withOperation(currentOps, operation);
3442
+ }
3443
+ }
3444
+ notifyOperations = this.prepareOperations(currentOps, listed, sameIdentity);
3445
+ }
3446
+ const next = readVariables2(variables, id);
3447
+ this.stateValue.set(next);
3448
+ notifyOperations();
3449
+ if (sameIdentity() && this.stateValue.get() === next && isObject(variables) && Array.isArray(variables["operations"])) {
3450
+ const fromSeq = variables["operations_from_seq"];
3451
+ const openOmitted = variables["operations_open_omitted"];
3452
+ this.forgetLost(id, {
3453
+ operations: listed,
3454
+ fromSeq: Number.isSafeInteger(fromSeq) ? fromSeq : null,
3455
+ openOmitted: typeof openOmitted === "number" && openOmitted > 0
3456
+ });
3457
+ }
3458
+ }
3511
3459
  } else {
3512
- if (this.stateValue.get().session !== null) break;
3513
3460
  this.enter(null);
3514
3461
  if (!current()) return;
3515
3462
  this.stateValue.set({ ...NO_VARIABLES, status: "off" });
@@ -3519,14 +3466,10 @@ var VariablesFeed = class {
3519
3466
  }
3520
3467
  case "session": {
3521
3468
  const summary = message["session"];
3522
- const id = isObject(summary) ? summary["id"] : null;
3523
- const existing = this.stateValue.get().session;
3524
- if (typeof id === "number" && existing !== null && id < existing) break;
3525
- if (Number.isSafeInteger(id) && id !== this.stateValue.get().session) {
3469
+ const id = isObject(summary) ? runIdOf(summary["id"]) : null;
3470
+ if (id !== null && id !== this.stateValue.get().session) {
3526
3471
  flush();
3527
3472
  if (!current()) return;
3528
- const afterFlush = this.stateValue.get().session;
3529
- if (afterFlush !== null && id < afterFlush) break;
3530
3473
  this.enter(id);
3531
3474
  if (!current()) return;
3532
3475
  if (this.stateValue.get().session !== id) break;
@@ -3535,42 +3478,31 @@ var VariablesFeed = class {
3535
3478
  break;
3536
3479
  }
3537
3480
  case "variables": {
3538
- const id = message["session"];
3539
- if (!Number.isSafeInteger(id)) break;
3481
+ const id = runIdOf(message["run_id"]);
3482
+ if (id === null) break;
3540
3483
  const details = message["variables"];
3541
- const rev = isObject(details) ? positionOrNull(details["rev"]) : null;
3542
3484
  const existing = this.stateValue.get().session;
3543
- if (existing !== null && id < existing) break;
3544
3485
  if (id !== existing) {
3545
3486
  flush();
3546
3487
  if (!current()) return;
3547
- const afterFlush = this.stateValue.get().session;
3548
- if (afterFlush !== null && id < afterFlush) break;
3549
- if (afterFlush !== id) {
3488
+ if (this.stateValue.get().session !== id) {
3550
3489
  this.enter(id);
3551
3490
  if (!current()) return;
3552
3491
  if (this.stateValue.get().session !== id) break;
3553
3492
  touchedAll = true;
3554
3493
  }
3555
3494
  }
3556
- if (snapshotCurrent(id, rev)) {
3557
- const version2 = this.applySnapshot(
3558
- readVariables2(details, id),
3559
- id,
3560
- rev
3561
- );
3562
- if (this.snapshotVersionValue === version2) snapshotVersion = version2;
3563
- }
3495
+ this.stateValue.set(readVariables2(details, id));
3564
3496
  break;
3565
3497
  }
3566
3498
  case "values": {
3567
- if (message["session"] !== this.stateValue.get().session) break;
3499
+ if (runIdOf(message["run_id"]) !== this.stateValue.get().session) break;
3568
3500
  this.takeValues(message, touched);
3569
3501
  break;
3570
3502
  }
3571
3503
  case "operation": {
3572
- const id = message["session"];
3573
- if (id !== this.stateValue.get().session) break;
3504
+ const id = runIdOf(message["run_id"]);
3505
+ if (id === null || id !== this.stateValue.get().session) break;
3574
3506
  const operation = readOperation(message, id);
3575
3507
  if (operation) {
3576
3508
  operations = this.withOperation(operations ?? this.operationsValue.get(), operation);
@@ -3580,12 +3512,8 @@ var VariablesFeed = class {
3580
3512
  }
3581
3513
  case "availability": {
3582
3514
  const id = this.stateValue.get().session;
3583
- if (message["session"] !== id || id === null) break;
3584
- const rev = positionOrNull(message["rev"]);
3585
- if (!snapshotCurrent(id, rev)) break;
3586
- const version2 = this.markSnapshot(id, rev);
3515
+ if (runIdOf(message["run_id"]) !== id || id === null) break;
3587
3516
  if (this.takeAvailability(message["peers"])) touchedAll = true;
3588
- if (this.snapshotVersionValue === version2) snapshotVersion = version2;
3589
3517
  break;
3590
3518
  }
3591
3519
  case "error": {
@@ -3620,94 +3548,8 @@ var VariablesFeed = class {
3620
3548
  this.stateValue.set({ ...state, availability: next });
3621
3549
  return true;
3622
3550
  }
3623
- snapshotVersion() {
3624
- return this.snapshotVersionValue;
3625
- }
3626
- /** Compare server capture order when available; legacy peers use the local best-effort watermark. */
3627
- isSnapshotCurrent(version2, instance, session, rev) {
3628
- if (session === null) return true;
3629
- const source = this.serverRevision;
3630
- if (source && source.instance === instance && source.session === session) {
3631
- return rev !== null && rev >= source.rev;
3632
- }
3633
- if (rev !== null) return true;
3634
- const identity = this.snapshotIdentity;
3635
- return !identity || identity.instance !== instance || identity.session !== session || this.snapshotVersionValue <= version2;
3636
- }
3637
- markSnapshot(session, rev) {
3638
- const version2 = ++this.snapshotVersionValue;
3639
- this.snapshotIdentity = { instance: this.instanceId, session };
3640
- if (rev !== null) this.serverRevision = { instance: this.instanceId, session, rev };
3641
- return version2;
3642
- }
3643
- applySnapshot(state, session, rev) {
3644
- const version2 = this.markSnapshot(session, rev);
3645
- this.stateValue.set(state);
3646
- return version2;
3647
- }
3648
- /** A reused numeric session on another server is a different run. */
3649
- adoptInstance(value) {
3650
- if (typeof value !== "string" || !value) return;
3651
- const changed = this.instanceId !== null && this.instanceId !== value;
3652
- this.instanceId = value;
3653
- if (changed) this.enter(null, true);
3654
- }
3655
- /** Applies a summary: an older snapshot can still carry a terminal write result. */
3656
- adoptSummary(summary, current = () => true, snapshotCurrent = current) {
3657
- if (!isObject(summary) || !Number.isSafeInteger(summary["id"]) || !current()) return null;
3658
- const id = summary["id"];
3659
- const instance = this.instanceId;
3660
- const existing = this.stateValue.get().session;
3661
- if (existing !== null && id < existing) return null;
3662
- const variables = summary["variables"];
3663
- let applyState = snapshotCurrent();
3664
- if (id !== existing) {
3665
- const initial = this.enter(id);
3666
- if (!current()) return null;
3667
- if (this.stateValue.get() !== initial) applyState = applyState && snapshotCurrent();
3668
- }
3669
- const sameIdentity = () => current() && this.instanceId === instance && this.stateValue.get().session === id;
3670
- if (!sameIdentity() || variables === void 0) return null;
3671
- applyState = applyState && snapshotCurrent();
3672
- let notifyOperations = () => void 0;
3673
- const listed = [];
3674
- if (isObject(variables) && Array.isArray(variables["operations"])) {
3675
- let operations = this.operationsValue.get();
3676
- for (const entry of variables["operations"]) {
3677
- const operation = readOperation(entry, id);
3678
- if (operation && (applyState || operation.done)) {
3679
- listed.push(operation);
3680
- operations = this.withOperation(operations, operation);
3681
- }
3682
- }
3683
- notifyOperations = this.prepareOperations(operations, listed, sameIdentity);
3684
- }
3685
- let next = null;
3686
- let appliedVersion = null;
3687
- if (applyState && snapshotCurrent() && sameIdentity()) {
3688
- next = readVariables2(variables, id);
3689
- appliedVersion = this.applySnapshot(
3690
- next,
3691
- id,
3692
- isObject(variables) ? positionOrNull(variables["rev"]) : null
3693
- );
3694
- }
3695
- notifyOperations();
3696
- if (!sameIdentity() || appliedVersion === null || this.snapshotVersionValue !== appliedVersion || !next || this.stateValue.get() !== next)
3697
- return appliedVersion;
3698
- if (isObject(variables) && Array.isArray(variables["operations"])) {
3699
- const fromSeq = variables["operations_from_seq"];
3700
- const openOmitted = variables["operations_open_omitted"];
3701
- this.forgetLost(id, {
3702
- operations: listed,
3703
- fromSeq: Number.isSafeInteger(fromSeq) ? fromSeq : null,
3704
- openOmitted: typeof openOmitted === "number" && openOmitted > 0
3705
- });
3706
- }
3707
- return appliedVersion;
3708
- }
3709
3551
  /**
3710
- * With the summary after a reconnect (or from api/session), settles as "no answer came" (lost) the writes waiting for
3552
+ * With the summary after a reconnect, settles as "no answer came" (lost) the writes waiting for
3711
3553
  * a result that will no longer arrive. For writes whose number is not known yet (before the HTTP answer), the summary
3712
3554
  * is kept and checked the same way once the number is known.
3713
3555
  */
@@ -3878,7 +3720,8 @@ var VariablesFeed = class {
3878
3720
  new WriteError("refused", "there is no run to write to", "not-running")
3879
3721
  );
3880
3722
  }
3881
- const body = { session, writes };
3723
+ const body = { run_id: session, writes };
3724
+ if (options.instance !== void 0) body["instance"] = options.instance;
3882
3725
  if (options.atMs !== void 0) body["at_ms"] = options.atMs;
3883
3726
  if (options.late !== void 0) body["late"] = options.late;
3884
3727
  return new Promise((resolve, reject) => {
@@ -3903,8 +3746,8 @@ var VariablesFeed = class {
3903
3746
  }
3904
3747
  const answer = outcome.body;
3905
3748
  const seq = isObject(answer) ? answer["operation"] : null;
3906
- const answered = isObject(answer) ? answer["session_id"] : null;
3907
- if (!Number.isSafeInteger(seq) || !Number.isSafeInteger(answered)) {
3749
+ const answered = isObject(answer) ? runIdOf(answer["run_id"]) : null;
3750
+ if (!Number.isSafeInteger(seq) || answered === null) {
3908
3751
  this.settle(
3909
3752
  pending,
3910
3753
  new WriteError(
@@ -4499,14 +4342,13 @@ function buildClient(options) {
4499
4342
  {
4500
4343
  type: "auth",
4501
4344
  token: token() ?? "",
4502
- ...feed?.resumeFields(),
4503
- session_without_check: true
4345
+ ...feed?.resumeFields()
4504
4346
  }
4505
4347
  ],
4506
4348
  afterGreeting: () => variablesFeed?.resume() ?? [],
4507
4349
  onError
4508
4350
  });
4509
- feed = new SessionFeed(connection, onError);
4351
+ feed = new SessionFeed(connection, onError, (instance) => variablesFeed?.onInstance(instance));
4510
4352
  const session = feed;
4511
4353
  variablesFeed = new VariablesFeed(
4512
4354
  {
@@ -4518,8 +4360,6 @@ function buildClient(options) {
4518
4360
  () => limits.get()
4519
4361
  );
4520
4362
  const variables = variablesFeed;
4521
- session.onSnapshotVersion(() => variables.snapshotVersion());
4522
- session.onInstance((instance) => variables.adoptInstance(instance));
4523
4363
  const run = new RunControl(session, http, onError, () => longRequestMs(limits.get()));
4524
4364
  const time = new TimeControl(
4525
4365
  session.session,
@@ -4565,12 +4405,13 @@ function buildClient(options) {
4565
4405
  currentInstance: () => session.currentInstance(),
4566
4406
  ready: session.ready,
4567
4407
  allowed: session.allowed,
4408
+ runtime: session.runtime,
4568
4409
  lastEventAt: session.lastEventAt,
4569
4410
  notices: session.notices,
4570
4411
  rejected: session.rejected,
4571
4412
  incompatible: session.incompatible,
4572
4413
  onMessages: (listener) => session.onMessages(listener),
4573
- report: (message, count2) => session.report(message, count2),
4414
+ report: (message, count) => session.report(message, count),
4574
4415
  dismissNotice: (id) => session.dismissNotice(id)
4575
4416
  },
4576
4417
  run: {
@@ -4653,45 +4494,15 @@ function buildClient(options) {
4653
4494
  },
4654
4495
  readConnections
4655
4496
  ),
4656
- fetchSession: () => {
4657
- const resyncFrom = session.currentInstance();
4658
- const snapshotVersion = variables.snapshotVersion();
4659
- return new Promise(
4660
- (resolve, reject) => http({ method: "GET", path: "api/session" }, (outcome) => {
4661
- if (!outcome.ok) {
4662
- reject(outcome.error);
4663
- return;
4664
- }
4665
- try {
4666
- const summary = readSessionResponse(outcome.body);
4667
- const instance = readSessionInstance(outcome.body);
4668
- const adoption = session.adopt(summary, instance, resyncFrom);
4669
- if (adoption !== null) {
4670
- const rawSession = outcome.body?.session;
4671
- const rev = rawSession?.variables?.rev;
4672
- const current = () => variables.isSnapshotCurrent(
4673
- snapshotVersion,
4674
- adoption.instance,
4675
- adoption.session,
4676
- Number.isSafeInteger(rev) && rev >= 0 ? rev : null
4677
- );
4678
- if (session.sameRun(adoption)) session.adoptAllowed(readSessionAllowed(outcome.body));
4679
- const sameRun = () => session.sameRun(adoption);
4680
- if (sameRun()) variables.adoptInstance(instance);
4681
- if (sameRun())
4682
- variables.adoptSummary(
4683
- outcome.body?.session,
4684
- sameRun,
4685
- current
4686
- );
4687
- }
4688
- resolve(summary);
4689
- } catch (error) {
4690
- reject(error);
4691
- }
4692
- })
4693
- );
4694
- }
4497
+ prepare: (body) => call(
4498
+ {
4499
+ method: "POST",
4500
+ path: "api/prepare",
4501
+ body,
4502
+ timeoutMs: longRequestMs(limits.get())
4503
+ },
4504
+ readPrepareResponse
4505
+ )
4695
4506
  };
4696
4507
  clientErrorSinks.set(client, onError);
4697
4508
  return { client, http, onError, runControl: run };
@@ -4763,7 +4574,7 @@ function linkOf(s) {
4763
4574
  }
4764
4575
  var NOT_PACED = "not-paced";
4765
4576
  function startOnItsWay(s) {
4766
- return s.busy.has("start") || s.allowed?.start.reason === "starting";
4577
+ return s.busy.has("start") || s.awaitingRunSession === true || s.allowed?.start.reason === "starting";
4767
4578
  }
4768
4579
  function runOf(s) {
4769
4580
  const session = s.session;
@@ -4772,7 +4583,7 @@ function runOf(s) {
4772
4583
  const outcome = runOutcome(session);
4773
4584
  if (outcome === "crashed") return starting ? "starting" : "crashed";
4774
4585
  if (outcome === "ended" || outcome === "finishing") return starting ? "starting" : "ended";
4775
- if (outcome === "stopping" || outcome === "forcing") return "stopping";
4586
+ if (outcome === "stopping" || outcome === "forcing" || s.stopConfirmed) return "stopping";
4776
4587
  const state = session.launcherState;
4777
4588
  const phase = state?.phase || session.phase;
4778
4589
  const paused = state?.paused ?? null;
@@ -4837,8 +4648,7 @@ function standsAt(session) {
4837
4648
  }
4838
4649
  function onItsWay(session) {
4839
4650
  const last = session?.lastCommand;
4840
- if (!session || !session.launcher.running || !last || !last.accepted || last.atMs === null)
4841
- return false;
4651
+ if (!isRunActive(session) || !last || !last.accepted || last.atMs === null) return false;
4842
4652
  if (last.name !== "step" && last.name !== "run_until") return false;
4843
4653
  const stands = standsAt(session);
4844
4654
  return !(stands !== null && stands >= last.atMs);
@@ -4847,7 +4657,7 @@ function clockOf(s) {
4847
4657
  const session = s.session;
4848
4658
  const state = session?.launcherState ?? null;
4849
4659
  const time = session?.time ?? null;
4850
- const live = !!session && session.launcher.running;
4660
+ const live = isRunActive(session);
4851
4661
  const pacing = state?.pacing;
4852
4662
  return {
4853
4663
  sim_ms: simMsOf(session ?? null),
@@ -4905,13 +4715,18 @@ function composeControls(s, run) {
4905
4715
  const link = linkOf(s);
4906
4716
  const down = linkReason(link, s);
4907
4717
  const session = s.session;
4908
- const live = !!session && session.launcher.running && run !== "ended" && run !== "crashed";
4718
+ const live = isRunActive(session) && run !== "ended" && run !== "crashed";
4909
4719
  const state = session?.launcherState ?? null;
4910
- const stopsAsked = session?.stopRequests ?? 0;
4720
+ const stopsAsked = Math.max(session?.stopRequests ?? 0, s.stopConfirmed ? 1 : 0);
4911
4721
  let start;
4912
4722
  if (link === "rejected" || link === "incompatible") start = control(false, down);
4913
4723
  else if (s.busy.has("start")) start = control(false, busyReason("start"));
4914
4724
  else if (down) start = control(false, down);
4725
+ else if (s.awaitingRunSession)
4726
+ start = control(
4727
+ false,
4728
+ reason("already-running", "a run is going: stop it before you start another")
4729
+ );
4915
4730
  else if (s.allowed) start = fromServer(s.allowed.start, "the server does not start a run now");
4916
4731
  else
4917
4732
  start = live ? control(
@@ -5069,16 +4884,25 @@ var FrontActions = class {
5069
4884
  this.closing.catch(() => void 0);
5070
4885
  this.busyValue = new Writable(/* @__PURE__ */ new Set(), Object.is, src.onError);
5071
4886
  this.failureValue = new Writable(null, Object.is, src.onError);
4887
+ this.startedRunIdValue = new Writable(null, Object.is, src.onError);
4888
+ this.stopConfirmedForValue = new Writable(null, Object.is, src.onError);
5072
4889
  this.busy = this.busyValue.readonly();
5073
4890
  this.failure = this.failureValue.readonly();
4891
+ this.startedRunId = this.startedRunIdValue.readonly();
4892
+ this.stopConfirmedFor = this.stopConfirmedForValue.readonly();
5074
4893
  this.stops.push(
5075
4894
  src.low.session.onMessages((batch) => this.onMessages(batch)),
5076
- src.low.session.session.subscribe(() => this.evaluate())
4895
+ src.low.session.session.subscribe(() => {
4896
+ this.startedRunIdValue.set(null);
4897
+ this.evaluate();
4898
+ })
5077
4899
  );
5078
4900
  }
5079
4901
  src;
5080
4902
  busyValue;
5081
4903
  failureValue;
4904
+ startedRunIdValue;
4905
+ stopConfirmedForValue;
5082
4906
  waiting = /* @__PURE__ */ new Map();
5083
4907
  inFlight = /* @__PURE__ */ new Map();
5084
4908
  /** The checks not answered yet, in the order they are sent: the first is on its way, the others wait. */
@@ -5092,14 +4916,36 @@ var FrontActions = class {
5092
4916
  disposed = false;
5093
4917
  busy;
5094
4918
  failure;
4919
+ startedRunId;
4920
+ stopConfirmedFor;
5095
4921
  // --- run ---------------------------------------------------------------------------------------
5096
4922
  start(intent = {}, options = {}) {
5097
4923
  const request = this.requestOf(intent, options);
5098
4924
  if (request instanceof ActionError) return this.fail(request);
5099
4925
  const own = this.refusalOfStart();
5100
4926
  if (own) return this.fail(own);
4927
+ this.stopConfirmedForValue.set(null);
5101
4928
  const start = this.src.low.run.start(request);
5102
- return this.guarded("start", () => start.then(() => void 0));
4929
+ return this.guarded(
4930
+ "start",
4931
+ () => start.then((started) => {
4932
+ if (started) {
4933
+ if (this.src.low.session.session.get()?.id !== started.run_id) {
4934
+ this.startedRunIdValue.set(started.run_id);
4935
+ }
4936
+ options.onStarted?.(started);
4937
+ }
4938
+ })
4939
+ );
4940
+ }
4941
+ isAwaitingRunSession() {
4942
+ const id = this.startedRunIdValue.get();
4943
+ return id !== null && this.src.low.session.session.get()?.id !== id;
4944
+ }
4945
+ isStopConfirmed() {
4946
+ const id = this.stopConfirmedForValue.get();
4947
+ const session = this.src.low.session.session.get();
4948
+ return id !== null && session !== null && isRunActive(session) && session.id === id;
5103
4949
  }
5104
4950
  /**
5105
4951
  * Checks what `intent` would start (`api/check`). Its failure is the caller's: it is not kept for `status.problem`.
@@ -5243,15 +5089,17 @@ var FrontActions = class {
5243
5089
  return this.once("stop", false);
5244
5090
  }
5245
5091
  forceStop(target) {
5246
- const current = this.src.low.session.currentTarget();
5247
- if (target && (current?.session !== target.session || current.instance !== target.instance))
5248
- return this.fail(
5249
- new ActionError("session-changed", "the confirmed run has changed", "refused")
5250
- );
5251
5092
  if (this.src.low.run.starting.get())
5252
5093
  return this.fail(
5253
5094
  new ActionError("starting", "wait until the new run can be identified", "refused")
5254
5095
  );
5096
+ const current = this.src.low.session.currentTarget();
5097
+ const startedId = this.startedRunIdValue.get();
5098
+ const effectiveRunId = startedId ?? current?.run_id ?? null;
5099
+ if (target && (effectiveRunId !== target.run_id || current?.instance !== target.instance))
5100
+ return this.fail(
5101
+ new ActionError("session-changed", "the confirmed run has changed", "refused")
5102
+ );
5255
5103
  return this.once("force_stop", true);
5256
5104
  }
5257
5105
  /** Pending stop only affects controls of the run it was sent for. */
@@ -5285,7 +5133,8 @@ var FrontActions = class {
5285
5133
  if (this.busyValue.get().has(name)) this.busyValue.set(new Set(this.busyValue.get()));
5286
5134
  else this.setBusy(name, true);
5287
5135
  operation.then(
5288
- () => {
5136
+ (ack) => {
5137
+ this.stopConfirmedForValue.set(ack.run_id);
5289
5138
  if (this.inFlight.get(name) === entry) {
5290
5139
  this.inFlight.delete(name);
5291
5140
  this.setBusy(name, false);
@@ -5440,7 +5289,7 @@ var FrontActions = class {
5440
5289
  if (event.event === "time") sim = event.sim_ms;
5441
5290
  if (event.event !== "command") continue;
5442
5291
  const mine = event.id === null ? void 0 : this.waiting.get(event.id);
5443
- if (mine && mine.session === message.session) this.answered(mine, event, sim);
5292
+ if (mine && mine.run_id === message.run_id) this.answered(mine, event, sim);
5444
5293
  else if (event.accepted && event.command !== null && MOVES.has(event.command)) {
5445
5294
  this.interruptMoving(
5446
5295
  null,
@@ -5499,7 +5348,7 @@ var FrontActions = class {
5499
5348
  const session = this.src.low.session.session.get();
5500
5349
  const instance = this.src.low.session.currentInstance();
5501
5350
  for (const w of [...this.waiting.values()]) {
5502
- if (!session || session.id !== w.session || instance !== w.instance || !session.launcher.running || session.result) {
5351
+ if (!session || !isRunActive(session) || session.id !== w.run_id || instance !== w.instance || session.result) {
5503
5352
  this.settle(
5504
5353
  w,
5505
5354
  new ActionError(
@@ -5592,9 +5441,9 @@ function outsideRows(low, onError) {
5592
5441
  for (const message of batch) {
5593
5442
  if (message.type !== "event" || message.event.event !== "outside") continue;
5594
5443
  const { network, to_outside, from_outside } = message.event;
5595
- const networks = new Map(next?.session === message.session ? next.networks : []);
5444
+ const networks = new Map(next?.run_id === message.run_id ? next.networks : []);
5596
5445
  networks.set(network, { to: to_outside, from: from_outside });
5597
- next = { session: message.session, networks };
5446
+ next = { run_id: message.run_id, networks };
5598
5447
  }
5599
5448
  if (next !== counts.get()) counts.set(next);
5600
5449
  });
@@ -5602,11 +5451,11 @@ function outsideRows(low, onError) {
5602
5451
  [low.session.session, counts],
5603
5452
  () => {
5604
5453
  const session = low.session.session.get();
5605
- if (!session?.launcher.running) return [];
5454
+ if (!session || !isRunActive(session)) return [];
5606
5455
  const known = counts.get();
5607
- const of = known?.session === session.id ? known.networks : /* @__PURE__ */ new Map();
5456
+ const of = known?.run_id === session.id ? known.networks : /* @__PURE__ */ new Map();
5608
5457
  return (session.launcherState?.outside ?? []).map((row) => {
5609
- const count2 = of.get(row.network);
5458
+ const count = of.get(row.network);
5610
5459
  return {
5611
5460
  network: row.network,
5612
5461
  target: row.target,
@@ -5616,8 +5465,8 @@ function outsideRows(low, onError) {
5616
5465
  condition: row.condition,
5617
5466
  reasons: row.reasons,
5618
5467
  nothing_received: row.nothing_received,
5619
- to_outside: count2?.to ?? null,
5620
- from_outside: count2?.from ?? null
5468
+ to_outside: count?.to ?? null,
5469
+ from_outside: count?.from ?? null
5621
5470
  };
5622
5471
  });
5623
5472
  },
@@ -5725,7 +5574,7 @@ function makeVariable(low, ref, refuse, launcher) {
5725
5574
  const track = new Writable({ writing: false, problem: null }, sameData);
5726
5575
  const view = new Writable(null, sameData);
5727
5576
  let binding = null;
5728
- let count2 = 0;
5577
+ let count = 0;
5729
5578
  let stops = [];
5730
5579
  const refresh = () => {
5731
5580
  if (binding) view.set(viewOf(binding.state.get(), track.get(), launcher.get()));
@@ -5747,7 +5596,7 @@ function makeVariable(low, ref, refuse, launcher) {
5747
5596
  return view.get();
5748
5597
  },
5749
5598
  subscribe: (listener) => {
5750
- if (count2++ === 0) {
5599
+ if (count++ === 0) {
5751
5600
  binding = low.variables.bind(ref);
5752
5601
  stops = [
5753
5602
  binding.state.subscribe(refresh),
@@ -5762,7 +5611,7 @@ function makeVariable(low, ref, refuse, launcher) {
5762
5611
  if (done) return;
5763
5612
  done = true;
5764
5613
  off();
5765
- if (--count2 === 0) {
5614
+ if (--count === 0) {
5766
5615
  for (const stop of stops) stop();
5767
5616
  stops = [];
5768
5617
  binding?.close();
@@ -5816,7 +5665,9 @@ function makeFront(options, onClose) {
5816
5665
  session: low.session.session.get(),
5817
5666
  allowed: low.session.allowed.get(),
5818
5667
  limits: low.limits.get(),
5819
- busy: actions.busyForCurrent()
5668
+ busy: actions.busyForCurrent(),
5669
+ awaitingRunSession: actions.isAwaitingRunSession(),
5670
+ stopConfirmed: actions.isStopConfirmed()
5820
5671
  });
5821
5672
  const sources = [
5822
5673
  low.connection.state,
@@ -5848,7 +5699,7 @@ function makeFront(options, onClose) {
5848
5699
  stamp
5849
5700
  });
5850
5701
  const controlsValue = derived(
5851
- [...sources, actions.busy],
5702
+ [...sources, actions.busy, actions.startedRunId, actions.stopConfirmedFor],
5852
5703
  () => {
5853
5704
  const s = snapshot();
5854
5705
  return controlsOf(s, runOf(s));
@@ -5857,7 +5708,7 @@ function makeFront(options, onClose) {
5857
5708
  onError
5858
5709
  );
5859
5710
  const writeControl = derived(
5860
- [...sources, actions.busy],
5711
+ [...sources, actions.busy, actions.startedRunId, actions.stopConfirmedFor],
5861
5712
  () => {
5862
5713
  const s = snapshot();
5863
5714
  return writeOf(s, runOf(s));
@@ -5866,7 +5717,7 @@ function makeFront(options, onClose) {
5866
5717
  onError
5867
5718
  );
5868
5719
  const status = derived(
5869
- [...sources, actions.busy, actions.failure],
5720
+ [...sources, actions.busy, actions.startedRunId, actions.stopConfirmedFor, actions.failure],
5870
5721
  () => {
5871
5722
  const s = snapshot();
5872
5723
  const base = statusOf(s, initialFile());
@@ -5930,7 +5781,32 @@ function makeFront(options, onClose) {
5930
5781
  clock,
5931
5782
  controls,
5932
5783
  scenario,
5784
+ runtime: low.session.runtime,
5933
5785
  outside: outside.value,
5786
+ prepare: (prepareOptions = {}) => {
5787
+ const file = prepareOptions.file ?? initialFile();
5788
+ if (file === null) {
5789
+ return Promise.reject(noFileError());
5790
+ }
5791
+ return low.prepare({
5792
+ file,
5793
+ ...prepareOptions.variant !== void 0 ? { variant: prepareOptions.variant } : {},
5794
+ ...prepareOptions.disable !== void 0 ? { disable: prepareOptions.disable } : {},
5795
+ ...prepareOptions.enable !== void 0 ? { enable: prepareOptions.enable } : {},
5796
+ ...prepareOptions.manual !== void 0 ? { manual: prepareOptions.manual } : {}
5797
+ }).then(
5798
+ (res) => res.runtime ?? low.session.runtime.get(),
5799
+ (error) => {
5800
+ throw actionError(error);
5801
+ }
5802
+ );
5803
+ },
5804
+ configs: () => low.configs().catch((error) => {
5805
+ throw actionError(error);
5806
+ }),
5807
+ recording: () => low.recording().catch((error) => {
5808
+ throw actionError(error);
5809
+ }),
5934
5810
  connections: ({ network }, listOptions = {}) => {
5935
5811
  const file = listOptions.file ?? initialFile();
5936
5812
  if (file === null) {
@@ -6132,7 +6008,7 @@ function createWaveforms(client, options = {}) {
6132
6008
  const refresh = () => {
6133
6009
  if (active !== feed || closed) return;
6134
6010
  historyTarget = client.session.currentTarget();
6135
- const current = historyTarget && historyTarget.session === client.variables.state.get().session;
6011
+ const current = historyTarget && historyTarget.run_id === client.variables.state.get().session;
6136
6012
  series.set(
6137
6013
  next.map((ref) => ({ ref: { ...ref }, points: current && feed ? feed.history(ref) : [] }))
6138
6014
  );
@@ -6146,7 +6022,7 @@ function createWaveforms(client, options = {}) {
6146
6022
  subscribe: (listener) => series.subscribe(listener),
6147
6023
  get() {
6148
6024
  const target = client.session.currentTarget();
6149
- if (target?.instance !== historyTarget?.instance || target?.session !== historyTarget?.session)
6025
+ if (target?.instance !== historyTarget?.instance || target?.run_id !== historyTarget?.run_id)
6150
6026
  return series.get().map(({ ref }) => ({ ref, points: [] }));
6151
6027
  return series.get();
6152
6028
  }
@@ -6193,7 +6069,7 @@ function createVariableEditor(front, ref) {
6193
6069
  view,
6194
6070
  shown: bound.pending ?? view.value,
6195
6071
  waiting,
6196
- canWrite: !closed && client.session.ready.get() && current !== null && current.session === client.variables.state.get().session && view.can_write && bound.block === null && !waiting
6072
+ canWrite: !closed && client.session.ready.get() && current !== null && current.run_id === client.variables.state.get().session && view.can_write && bound.block === null && !waiting
6197
6073
  };
6198
6074
  };
6199
6075
  const state = new Writable(read2(), Object.is, clientErrorSink(client));
@@ -6209,7 +6085,7 @@ function createVariableEditor(front, ref) {
6209
6085
  const bound = binding.state.get();
6210
6086
  const shown = read2(bound);
6211
6087
  if (closed) return;
6212
- if (current?.instance !== target?.instance || current?.session !== target?.session || !shown.view.can_write) {
6088
+ if (current?.instance !== target?.instance || current?.run_id !== target?.run_id || !shown.view.can_write) {
6213
6089
  reset();
6214
6090
  } else if (awaiting !== null && shown.view.value === awaiting) {
6215
6091
  reset();
@@ -6298,6 +6174,10 @@ export {
6298
6174
  fetchTransport,
6299
6175
  hasRange,
6300
6176
  isHolding,
6177
+ isLauncherAlive,
6178
+ isLauncherFinishing,
6179
+ isRunActive,
6180
+ isSessionRunning,
6301
6181
  isWriteError,
6302
6182
  launcherAnswer,
6303
6183
  phaseIndex,
@@ -6307,12 +6187,16 @@ export {
6307
6187
  readConfigText,
6308
6188
  readConnections,
6309
6189
  readDashboardResponse,
6190
+ readPrepareResponse,
6310
6191
  readRecording,
6192
+ readRunResponse,
6193
+ readRuntimeStatus,
6311
6194
  readSavedConfig,
6312
6195
  readScenarioList,
6313
6196
  readServerMessage,
6314
6197
  readSessionAllowed,
6315
6198
  readSessionResponse,
6199
+ readSessionRuntime,
6316
6200
  readTimeResponse,
6317
6201
  readVariablesSummary,
6318
6202
  readWriteResponse,