@vehicle-sil/gui-client 0.3.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)),
@@ -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),
@@ -1170,9 +1178,10 @@ var readRuntimeStatus = (value, path) => {
1170
1178
  var readPrepareResponse = (value) => {
1171
1179
  const path = "response";
1172
1180
  const f = object(value, path);
1181
+ const runtime = field(f, path, "runtime", optional(readRuntimeStatus, void 0));
1173
1182
  return {
1174
- instance: field(f, path, "instance", string),
1175
- runtime: field(f, path, "runtime", readRuntimeStatus)
1183
+ instance: field(f, path, "instance", nonEmptyString),
1184
+ ...runtime === void 0 ? {} : { runtime }
1176
1185
  };
1177
1186
  };
1178
1187
  var readSummaryLauncher = (value, path) => {
@@ -1217,8 +1226,8 @@ var readSessionSummary = (value, path) => {
1217
1226
  const timePath = `${path}.time`;
1218
1227
  const stopAt = field(f, path, "stop_at_ms", soft(nullable(integer), void 0, u));
1219
1228
  const summary = {
1220
- id: field(f, path, "id", integer),
1221
- ...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)) },
1222
1231
  state: field(f, path, "state", string),
1223
1232
  launcher: field(f, path, "launcher", readSummaryLauncher),
1224
1233
  stop: field(f, path, "stop", string),
@@ -1302,7 +1311,6 @@ var readSessionSummary = (value, path) => {
1302
1311
  log: field(f, path, "log", soft(partlyRecord(readLogCounts, u), {}, u)),
1303
1312
  problems: field(f, path, "problems", items(readServerProblem, u)),
1304
1313
  problems_omitted: field(f, path, "problems_omitted", soft(integer, 0, u)),
1305
- ...f["problem_seq"] === void 0 ? {} : { problem_seq: field(f, path, "problem_seq", soft(nullable(integer), null, u)) },
1306
1314
  scenario: field(
1307
1315
  f,
1308
1316
  path,
@@ -1331,7 +1339,6 @@ var readServerSaveItem = (value, path) => ({
1331
1339
  var readServerAllowed = (value, path) => {
1332
1340
  const f = object(value, path);
1333
1341
  return {
1334
- rev: field(f, path, "rev", optional(integer, 0)),
1335
1342
  start: field(f, path, "start", readServerAllowedItem),
1336
1343
  stop: field(f, path, "stop", readServerAllowedItem),
1337
1344
  force: field(f, path, "force", readServerAllowedItem),
@@ -1355,6 +1362,14 @@ var readSessionInstance = (value) => field(object(value, "response"), "response"
1355
1362
  throw new ProtocolError(path, "a server instance ID. Use the GUI server from this release");
1356
1363
  return instance;
1357
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
+ };
1358
1373
  var readSessionAllowed = (value) => field(
1359
1374
  object(value, "response"),
1360
1375
  "response",
@@ -1372,7 +1387,7 @@ var readTimeResponse = (value) => {
1372
1387
  const f = object(value, path);
1373
1388
  const command = field(f, path, "command", object);
1374
1389
  return {
1375
- session_id: field(f, path, "session_id", integer),
1390
+ run_id: field(f, path, "run_id", nonEmptyString),
1376
1391
  command: field(command, `${path}.command`, "command", string),
1377
1392
  id: field(command, `${path}.command`, "id", optional(nullable(integer), null))
1378
1393
  };
@@ -1456,7 +1471,6 @@ var readVariablesSummary = (value) => readVariablesReport(value, "variables");
1456
1471
  var readVariablesReport = (value, path, u) => {
1457
1472
  const f = object(value, path);
1458
1473
  return {
1459
- ...f["rev"] === void 0 ? {} : { rev: field(f, path, "rev", soft(nullable(nonNegativeInteger), null, u)) },
1460
1474
  state: field(f, path, "state", lenient(string, "unknown", u)),
1461
1475
  reason: field(f, path, "reason", soft(nullable(string), null, u)),
1462
1476
  peers: field(
@@ -1515,7 +1529,7 @@ var readVariables = readVariablesReport;
1515
1529
  var readWriteResponse = (value) => {
1516
1530
  const f = object(value, "response");
1517
1531
  return {
1518
- session_id: field(f, "response", "session_id", integer),
1532
+ run_id: field(f, "response", "run_id", nonEmptyString),
1519
1533
  operation: field(f, "response", "operation", integer)
1520
1534
  };
1521
1535
  };
@@ -1602,19 +1616,22 @@ var readDashboardResponse = (value) => {
1602
1616
  };
1603
1617
  var readReplay = (value, path) => {
1604
1618
  const f = object(value, path);
1605
- return { from_seq: field(f, path, "from_seq", nullable(integer)) };
1619
+ return { after_stream_seq: field(f, path, "after_stream_seq", nullable(integer)) };
1606
1620
  };
1607
1621
  var readServerMessage = (value) => {
1608
1622
  const path = "message";
1609
1623
  const f = object(value, path);
1610
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 };
1611
1627
  switch (type) {
1612
1628
  case "hello": {
1613
1629
  version(f, path, "vehicle_sil_gui", PROTOCOL_VERSION);
1614
1630
  const runtime = field(f, path, "runtime", optional(nullable(readRuntimeStatus), void 0));
1615
1631
  return {
1616
1632
  type,
1617
- instance: field(f, path, "instance", string),
1633
+ ...seqField,
1634
+ instance: field(f, path, "instance", nonEmptyString),
1618
1635
  session: field(f, path, "session", nullable(readSessionSummary)),
1619
1636
  allowed: field(f, path, "allowed", optional(nullable(readServerAllowed), null)),
1620
1637
  replay: field(f, path, "replay", nullable(readReplay)),
@@ -1622,29 +1639,32 @@ var readServerMessage = (value) => {
1622
1639
  };
1623
1640
  }
1624
1641
  case "runtime":
1625
- return { type, runtime: field(f, path, "runtime", readRuntimeStatus) };
1642
+ return { type, ...seqField, runtime: field(f, path, "runtime", readRuntimeStatus) };
1626
1643
  case "event": {
1627
1644
  const event = field(f, path, "event", (v, p) => readLauncherEvent(v, p, true));
1628
- return event && { type, session: field(f, path, "session", integer), event };
1645
+ return event && { type, ...seqField, run_id: field(f, path, "run_id", nonEmptyString), event };
1629
1646
  }
1630
1647
  case "synced":
1631
1648
  return {
1632
1649
  type,
1633
- session: field(f, path, "session", nullable(integer)),
1650
+ ...seqField,
1651
+ run_id: field(f, path, "run_id", nullable(nonEmptyString)),
1634
1652
  last_seq: field(f, path, "last_seq", nullable(integer))
1635
1653
  };
1636
1654
  case "session":
1637
- return { type, session: field(f, path, "session", readSessionSummary) };
1655
+ return { type, ...seqField, session: field(f, path, "session", readSessionSummary) };
1638
1656
  case "error":
1639
1657
  return {
1640
1658
  type,
1641
- session: field(f, path, "session", nullable(integer)),
1659
+ ...seqField,
1660
+ run_id: field(f, path, "run_id", nullable(nonEmptyString)),
1642
1661
  ...readServerProblem(value, path)
1643
1662
  };
1644
1663
  case "dropped":
1645
1664
  return {
1646
1665
  type,
1647
- session: field(f, path, "session", nullable(integer)),
1666
+ ...seqField,
1667
+ run_id: field(f, path, "run_id", nullable(nonEmptyString)),
1648
1668
  reason: field(f, path, "reason", string),
1649
1669
  log: field(f, path, "log", record(integer)),
1650
1670
  at_least: field(f, path, "at_least", array(string)),
@@ -1653,7 +1673,8 @@ var readServerMessage = (value) => {
1653
1673
  case "allowed":
1654
1674
  return {
1655
1675
  type,
1656
- session: field(f, path, "session", nullable(integer)),
1676
+ ...seqField,
1677
+ run_id: field(f, path, "run_id", nullable(nonEmptyString)),
1657
1678
  allowed: field(f, path, "allowed", readServerAllowed)
1658
1679
  };
1659
1680
  case "resync":
@@ -1661,14 +1682,17 @@ var readServerMessage = (value) => {
1661
1682
  case "variables":
1662
1683
  return {
1663
1684
  type,
1664
- session: field(f, path, "session", integer),
1685
+ ...seqField,
1686
+ run_id: field(f, path, "run_id", nonEmptyString),
1665
1687
  variables: field(f, path, "variables", readVariables)
1666
1688
  };
1667
- case "values":
1689
+ case "values": {
1690
+ const watchId = f["watch_id"] !== void 0 ? field(f, path, "watch_id", integer) : field(f, path, "id", integer);
1668
1691
  return {
1669
1692
  type,
1670
- id: field(f, path, "id", integer),
1671
- session: field(f, path, "session", integer),
1693
+ id: watchId,
1694
+ watch_id: watchId,
1695
+ run_id: field(f, path, "run_id", nonEmptyString),
1672
1696
  sim_ms: field(f, path, "sim_ms", nullable(number)),
1673
1697
  paused: field(f, path, "paused", boolean),
1674
1698
  peers: field(
@@ -1692,17 +1716,19 @@ var readServerMessage = (value) => {
1692
1716
  })
1693
1717
  )
1694
1718
  };
1719
+ }
1695
1720
  case "operation":
1696
1721
  return {
1697
1722
  type,
1698
- session: field(f, path, "session", integer),
1723
+ ...seqField,
1724
+ run_id: field(f, path, "run_id", nonEmptyString),
1699
1725
  ...readOperationReport(value, path)
1700
1726
  };
1701
1727
  case "availability":
1702
1728
  return {
1703
1729
  type,
1704
- session: field(f, path, "session", integer),
1705
- ...f["rev"] === void 0 ? {} : { rev: field(f, path, "rev", optional(nullable(integer), null)) },
1730
+ ...seqField,
1731
+ run_id: field(f, path, "run_id", nonEmptyString),
1706
1732
  peers: field(
1707
1733
  f,
1708
1734
  path,
@@ -1868,29 +1894,6 @@ function scenarioView(summary) {
1868
1894
  timelineUrl: summary.timeline_url
1869
1895
  };
1870
1896
  }
1871
- function fullStepText(incoming, current) {
1872
- if (incoming === null || current === null) return incoming;
1873
- const cut = /^(.*)\.\.\. \((\d+) more characters\)$/s.exec(incoming);
1874
- if (!cut) return incoming;
1875
- const prefix = cut[1];
1876
- return current.startsWith(prefix) && Array.from(current).length === Array.from(prefix).length + Number(cut[2]) ? current : incoming;
1877
- }
1878
- function mergeScenarioStep(current, incoming) {
1879
- return {
1880
- ...incoming,
1881
- text: fullStepText(incoming.text, current.text) ?? incoming.text,
1882
- message: fullStepText(incoming.message, current.message)
1883
- };
1884
- }
1885
- var stepPositions = /* @__PURE__ */ new WeakMap();
1886
- function mergeScenarioSteps(current, incoming, merge = (_old, next) => next) {
1887
- const steps = new Map(current.map((step) => [step.index, step]));
1888
- for (const step of incoming) {
1889
- const old = steps.get(step.index);
1890
- steps.set(step.index, old ? merge(old, step) : step);
1891
- }
1892
- return [...steps.values()].sort((a, b) => a.index - b.index);
1893
- }
1894
1897
  function withStep(steps, step) {
1895
1898
  const i = steps.findIndex((s) => s.index >= step.index);
1896
1899
  if (i < 0) return [...steps, step];
@@ -1925,8 +1928,8 @@ function runOutcome(session) {
1925
1928
  function sessionFromSummary(summary) {
1926
1929
  const blank = {
1927
1930
  id: summary.id,
1928
- ...summary.snapshot_rev == null ? {} : { snapshotRev: summary.snapshot_rev },
1929
1931
  lastSeq: -1,
1932
+ runT0Ms: summary.run_t0_ms ?? 0,
1930
1933
  file: summary.file,
1931
1934
  disable: summary.disable,
1932
1935
  manual: summary.manual,
@@ -1956,11 +1959,7 @@ function sessionFromSummary(summary) {
1956
1959
  droppedMarks: 0,
1957
1960
  scenario: null
1958
1961
  };
1959
- const adopted = applySummary(blank, summary, true);
1960
- return summary.last_seq == null ? adopted : {
1961
- ...adopted,
1962
- pendingFindings: { through: summary.last_seq, keys: summary.findings.map(findingIdentity) }
1963
- };
1962
+ return applySummary(blank, summary);
1964
1963
  }
1965
1964
  function addDropped(session, dropped) {
1966
1965
  const counts = Object.entries(dropped.log).filter(([, count]) => count > 0);
@@ -1998,55 +1997,14 @@ function launcherOf(summary) {
1998
1997
  silentSeconds: summary.launcher.silent_s
1999
1998
  };
2000
1999
  }
2001
- function applySummary(session, summary, force = false, controlOnly = false) {
2002
- const incomingRev = summary.snapshot_rev ?? null;
2003
- const currentRev = session.snapshotRev ?? null;
2004
- const staleControl = currentRev !== null && (incomingRev === null || incomingRev < currentRev);
2005
- const projectionRev = session.projectionRev ?? null;
2006
- const staleProjection = projectionRev !== null && (incomingRev === null || incomingRev < projectionRev);
2007
- if (staleControl && (staleProjection || !force && controlOnly)) return session;
2008
- const newer = force || (summary.last_seq ?? -1) > Math.max(session.lastSeq, session.observedSeq ?? -1, session.projectionSeq ?? -1);
2009
- const staleEndRegression = !force && session.state === "ended" && summary.state === "running";
2010
- const stillEnded = staleEndRegression || !force && !isRunActive(session) && summary.launcher.running && summary.state === "running";
2011
- const launcher = stillEnded ? session.launcher : launcherOf(summary);
2012
- const state = staleEndRegression ? session.state : summary.state;
2013
- const notLess = summary.problems.length + summary.problems_omitted >= session.problems.length + session.problemsOmitted;
2014
- const mergedProblems = [...summary.problems];
2015
- let omitted = summary.problems_omitted;
2016
- if (summary.problem_seq != null) {
2017
- const included = new Set(mergedProblems.map((problem) => problem.problem_seq));
2018
- for (const problem of session.problems) {
2019
- if (problem.problem_seq === void 0 || included.has(problem.problem_seq)) continue;
2020
- if (mergedProblems.length >= MAX_PROBLEMS) break;
2021
- mergedProblems.push(problem);
2022
- if (problem.problem_seq <= summary.problem_seq && omitted > 0) omitted--;
2023
- }
2024
- }
2025
- if (mergedProblems.every((problem) => problem.problem_seq !== void 0))
2026
- mergedProblems.sort((a, b) => a.problem_seq - b.problem_seq);
2027
- const next = staleControl ? session : {
2028
- ...session,
2029
- ...incomingRev === null ? {} : { snapshotRev: incomingRev },
2030
- ...summary.stop_at_ms === void 0 ? {} : { stopAtMs: summary.stop_at_ms },
2031
- ...summary.problem_seq == null ? {} : { problemSeq: Math.max(session.problemSeq ?? 0, summary.problem_seq) },
2032
- state,
2033
- launcher,
2034
- stopRequests: Math.max(session.stopRequests, stopRequestsOf(summary.stop)),
2035
- logSources: withSources(session.logSources, Object.keys(summary.log)),
2036
- ...summary.scenario?.timeline_url ? {
2037
- scenario: session.scenario ? { ...session.scenario, timelineUrl: summary.scenario.timeline_url } : scenarioView(summary.scenario)
2038
- } : {},
2039
- ...force || notLess ? { problems: mergedProblems, problemsOmitted: omitted } : {}
2040
- };
2041
- if (!newer || staleProjection || !force && controlOnly) {
2042
- return next;
2043
- }
2044
- 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;
2045
2005
  const rank = phaseIndex(phase);
2046
- const preserveEvents = force && controlOnly;
2047
- const behind = (...kinds) => summary.last_seq !== null && kinds.some((kind) => (session.eventSeqs?.[kind] ?? -1) > summary.last_seq);
2048
- const check = (preserveEvents ? next.check : null) ?? summary.check ?? next.check ?? summary.result?.check ?? null;
2049
- 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;
2050
2008
  const known = new Map(session.participants.map((p) => [p.name, p]));
2051
2009
  const participants = summary.participants.map((p) => ({
2052
2010
  name: p.name,
@@ -2056,66 +2014,66 @@ function applySummary(session, summary, force = false, controlOnly = false) {
2056
2014
  exitCode: p.exit_code,
2057
2015
  signal: p.signal,
2058
2016
  failure: p.reason,
2059
- message: p.message ?? (preserveEvents ? known.get(p.name)?.message ?? null : null),
2017
+ message: p.message ?? known.get(p.name)?.message ?? null,
2060
2018
  // A stop the launcher asked for is kept even in summaries of later states (ended and so on)
2061
2019
  stopRequested: p.stop_requested || p.state === "stop_requested" || !!known.get(p.name)?.stopRequested,
2062
2020
  omittedFields: p.omitted_fields,
2063
2021
  controlLink: p.control_link ?? known.get(p.name)?.controlLink ?? null,
2064
2022
  manual: p.state === "manual" || p.command_line !== null || !!known.get(p.name)?.manual,
2065
- commandLine: p.command_line ?? (preserveEvents ? known.get(p.name)?.commandLine ?? null : null),
2066
- workingDirectory: p.working_directory ?? (preserveEvents ? known.get(p.name)?.workingDirectory ?? null : null),
2067
- 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 ?? {}
2068
2026
  }));
2069
- 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 ? {
2070
2032
  ...scenarioView(summary.scenario),
2071
- timelineUrl: next.scenario?.timelineUrl ?? summary.scenario.timeline_url
2072
- } : next.scenario;
2073
- let mergedScenario = preserveEvents && scenario && next.scenario ? {
2074
- ...scenario,
2075
- steps: mergeScenarioSteps(
2076
- next.scenario.steps,
2077
- scenario.steps,
2078
- (old, step) => summary.last_seq !== null && (stepPositions.get(old) ?? -1) > summary.last_seq ? old : mergeScenarioStep(old, step)
2079
- )
2080
- } : scenario;
2081
- if (mergedScenario && result?.scenario) {
2082
- mergedScenario = {
2083
- ...mergedScenario,
2084
- 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
2085
2044
  };
2086
2045
  }
2087
- if (mergedScenario && scenario && mergedScenario !== scenario) {
2088
- mergedScenario.stepsOmitted = Math.max(
2089
- 0,
2090
- scenario.stepsOmitted - (mergedScenario.steps.length - scenario.steps.length)
2091
- );
2092
- }
2093
- const mergedParticipants = preserveEvents ? [
2094
- ...participants,
2095
- ...next.participants.filter(
2096
- (p) => !participants.some((current) => current.name === p.name)
2097
- )
2098
- ] : participants;
2046
+ const problems = summary.problems.slice(0, MAX_PROBLEMS);
2047
+ const problemsOmitted = summary.problems_omitted + Math.max(0, summary.problems.length - problems.length);
2099
2048
  return {
2100
- ...next,
2101
- ...incomingRev === null ? {} : { projectionRev: incomingRev },
2102
- projectionSeq: Math.max(next.projectionSeq ?? -1, summary.last_seq ?? -1),
2103
- unreadable: force && !behind("finding", "result", "participant") ? summary.unreadable : union(next.unreadable, summary.unreadable),
2104
- phase: behind("phase", "result") ? next.phase ?? phase : phase,
2105
- phaseRank: behind("phase", "result") ? next.phaseRank : rank >= 0 ? rank : next.phaseRank,
2106
- elapsedMs: Math.max(next.elapsedMs, summary.last_t_ms ?? 0),
2107
- simMs: behind("time") ? next.simMs ?? summary.sim_ms : summary.sim_ms ?? next.simMs,
2108
- timeOmittedFields: behind("time") || summary.sim_ms === null ? next.timeOmittedFields : summary.time_omitted_fields,
2109
- time: behind("time") && next.time ? next.time : summary.time ? timeView(summary.time) : next.time,
2110
- lastCommand: behind("command") && next.lastCommand ? next.lastCommand : summary.last_command ? commandView(summary.last_command, summary.last_command.seq ?? -1) : next.lastCommand,
2111
- launcherState: newerState(next.launcherState, summary.launcher_state ?? null),
2112
- 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),
2113
2068
  result,
2114
2069
  check,
2115
- scenario: mergedScenario,
2070
+ scenario,
2116
2071
  // Whether a participant is required or left out is in the check result (as is the order, that of the configuration
2117
2072
  // file). If there is a result, how it ended (stopped or not) comes from the result too
2118
- 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
+ )
2119
2077
  };
2120
2078
  }
2121
2079
  function newerState(current, incoming) {
@@ -2133,101 +2091,23 @@ function withSources(sources, names) {
2133
2091
  return next;
2134
2092
  }
2135
2093
  function addProblem(session, problem) {
2136
- const seq = problem.problem_seq;
2137
- if (seq !== void 0 && seq <= (session.problemEventSeq ?? 0)) return session;
2138
- const updated = seq === void 0 ? session : { ...session, problemEventSeq: seq };
2139
- if (seq !== void 0 && session.problems.some((item) => item.problem_seq === seq))
2140
- return updated;
2141
- if (updated.problems.length >= MAX_PROBLEMS) {
2142
- const alreadyCounted2 = seq !== void 0 && seq <= (session.problemSeq ?? 0);
2143
- return alreadyCounted2 ? updated : { ...updated, problemsOmitted: updated.problemsOmitted + 1 };
2144
- }
2145
- const alreadyCounted = seq !== void 0 && seq <= (session.problemSeq ?? 0);
2146
- const problems = [...updated.problems, problem];
2147
- if (problems.every((item) => item.problem_seq !== void 0))
2148
- 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
+ }
2149
2097
  return {
2150
- ...updated,
2151
- problems,
2152
- problemsOmitted: alreadyCounted ? Math.max(0, updated.problemsOmitted - 1) : updated.problemsOmitted
2098
+ ...session,
2099
+ problems: [...session.problems, problem]
2153
2100
  };
2154
2101
  }
2155
2102
  function phaseIndex(phase) {
2156
2103
  return phase === null ? -1 : PHASES.indexOf(phase);
2157
2104
  }
2158
- function findingKey(finding) {
2159
- return JSON.stringify([
2160
- finding.severity,
2161
- finding.code,
2162
- finding.file,
2163
- finding.line,
2164
- finding.participant,
2165
- finding.network,
2166
- finding.message,
2167
- finding.detail
2168
- ]);
2169
- }
2170
- function findingIdentity(finding) {
2171
- return finding.event_seq === void 0 ? `body:${findingKey(finding)}` : `seq:${finding.event_seq}`;
2172
- }
2173
- function mergeFindings(current, incoming) {
2174
- const a = current.slice(0, MAX_FINDINGS);
2175
- const b = incoming.slice(0, MAX_FINDINGS);
2176
- if (a.every((finding) => finding.event_seq !== void 0) && b.every((finding) => finding.event_seq !== void 0)) {
2177
- const bySeq = /* @__PURE__ */ new Map();
2178
- for (const finding of [...b, ...a]) bySeq.set(finding.event_seq, finding);
2179
- return [...bySeq.values()].sort((left, right) => left.event_seq - right.event_seq).slice(0, MAX_FINDINGS);
2180
- }
2181
- const ak = a.map(findingKey);
2182
- const bk = b.map(findingKey);
2183
- const sizes = Array.from({ length: a.length + 1 }, () => new Uint16Array(b.length + 1));
2184
- for (let i2 = a.length - 1; i2 >= 0; --i2)
2185
- for (let j2 = b.length - 1; j2 >= 0; --j2)
2186
- sizes[i2][j2] = ak[i2] === bk[j2] ? 1 + sizes[i2 + 1][j2 + 1] : Math.max(sizes[i2 + 1][j2], sizes[i2][j2 + 1]);
2187
- const merged = [];
2188
- let i = 0, j = 0;
2189
- while ((i < a.length || j < b.length) && merged.length < MAX_FINDINGS) {
2190
- if (i < a.length && j < b.length && ak[i] === bk[j]) {
2191
- merged.push(a[i++]);
2192
- j++;
2193
- } else if (j === b.length || i < a.length && sizes[i + 1][j] >= sizes[i][j + 1])
2194
- merged.push(a[i++]);
2195
- else merged.push(b[j++]);
2196
- }
2197
- return merged;
2198
- }
2199
2105
  function applyEvents(session, events, countStale = false) {
2200
2106
  let next = session;
2201
2107
  const logs = [];
2202
2108
  let stale = 0;
2203
2109
  for (const event of events) {
2204
2110
  if (event.seq > next.lastSeq) {
2205
- const tracked = [
2206
- "time",
2207
- "phase",
2208
- "result",
2209
- "finding",
2210
- "participant",
2211
- "command",
2212
- CONTROL_EVENT
2213
- ].includes(event.event);
2214
- if (event.event === "scenario_step") stepPositions.set(event.step, event.seq);
2215
- next = {
2216
- ...next,
2217
- observedSeq: Math.max(next.observedSeq ?? -1, event.seq),
2218
- ...tracked ? { eventSeqs: { ...next.eventSeqs, [event.event]: event.seq } } : {}
2219
- };
2220
- const pending = next.pendingFindings;
2221
- if (event.event === "finding" && pending && event.seq <= pending.through) {
2222
- const numbered = pending.keys.indexOf(`seq:${event.seq}`);
2223
- const index = numbered === -1 ? pending.keys.indexOf(`body:${findingKey(event.finding)}`) : numbered;
2224
- if (index !== -1) {
2225
- const keys = [...pending.keys];
2226
- keys.splice(index, 1);
2227
- next = { ...next, lastSeq: event.seq, pendingFindings: { ...pending, keys } };
2228
- continue;
2229
- }
2230
- }
2231
2111
  next = applyOne(next, event, logs);
2232
2112
  if (event.unreadable)
2233
2113
  next = { ...next, unreadable: union(next.unreadable, event.unreadable) };
@@ -2247,37 +2127,6 @@ function applyEvents(session, events, countStale = false) {
2247
2127
  }
2248
2128
  return { ...next, logSources: sources };
2249
2129
  }
2250
- function recoverReplayLogs(session, recovered, notKept) {
2251
- if (!recovered.length) return session;
2252
- const sources = Object.fromEntries(
2253
- Object.entries(session.logSources).map(([name, source]) => [
2254
- name,
2255
- { lines: 0, dropped: source.dropped }
2256
- ])
2257
- );
2258
- const restored = /* @__PURE__ */ new Map();
2259
- for (const line of recovered) {
2260
- const source = sources[line.source] ??= { lines: 0, dropped: 0 };
2261
- if (line.gap) source.dropped += line.gap.count;
2262
- else {
2263
- const count = restored.get(line.source) ?? 0;
2264
- if (count < (notKept.get(line.source) ?? 0)) {
2265
- source.dropped--;
2266
- restored.set(line.source, count + 1);
2267
- }
2268
- }
2269
- }
2270
- const logs = session.logs.flatMap((line) => {
2271
- if (!line.gap?.notKept) return [line];
2272
- const available = restored.get(line.source) ?? 0;
2273
- const count = Math.max(0, line.gap.count - available);
2274
- restored.set(line.source, Math.max(0, available - line.gap.count));
2275
- return count > 0 ? [{ ...line, gap: { ...line.gap, count } }] : [];
2276
- });
2277
- logs.push(...recovered);
2278
- logs.sort((a, b) => a.seq - b.seq);
2279
- return appendLogs({ ...session, logs: [], logSources: sources }, logs);
2280
- }
2281
2130
  function appendLogs(session, added) {
2282
2131
  const sources = {};
2283
2132
  for (const [source, counts] of Object.entries(session.logSources))
@@ -2318,10 +2167,13 @@ function appendLogs(session, added) {
2318
2167
  return { ...session, logs: kept, logSources: sources };
2319
2168
  }
2320
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));
2321
2172
  const next = {
2322
2173
  ...session,
2323
2174
  lastSeq: event.seq,
2324
- elapsedMs: Math.max(session.elapsedMs, event.t_ms ?? 0)
2175
+ runT0Ms,
2176
+ elapsedMs
2325
2177
  };
2326
2178
  switch (event.event) {
2327
2179
  case "phase": {
@@ -2373,7 +2225,7 @@ function applyOne(session, event, logs) {
2373
2225
  case "finding":
2374
2226
  return next.findings.length >= MAX_FINDINGS ? next : {
2375
2227
  ...next,
2376
- 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 }]
2228
+ findings: [...next.findings, { ...event.finding }]
2377
2229
  };
2378
2230
  case "time":
2379
2231
  return { ...next, simMs: event.sim_ms, timeOmittedFields: [], time: timeView(event) };
@@ -2508,13 +2360,16 @@ var RunControl = class {
2508
2360
  this.currentStopping = derived(
2509
2361
  [this.pendingRevision, this.startSending, feed.session],
2510
2362
  () => {
2511
- const key = this.startSending.get() ? this.startOperation : JSON.stringify(feed.currentTarget());
2363
+ const key = this.startSending.get() ? this.startOperation : JSON.stringify(this.activeTarget());
2512
2364
  return [...this.pendingStops].filter((pending) => pending.key === key).at(-1)?.action ?? null;
2513
2365
  },
2514
2366
  Object.is,
2515
2367
  onError
2516
2368
  );
2517
2369
  this.stopWhileStarting = this.stopAskedWhileStarting.readonly();
2370
+ feed.session.subscribe(() => {
2371
+ this.startedTarget = null;
2372
+ });
2518
2373
  this.error = derived(
2519
2374
  [this.failure, feed.session],
2520
2375
  () => {
@@ -2532,6 +2387,7 @@ var RunControl = class {
2532
2387
  transport;
2533
2388
  startTimeoutMs;
2534
2389
  startOperation = null;
2390
+ startedTarget = null;
2535
2391
  pendingStops = /* @__PURE__ */ new Set();
2536
2392
  pendingRevision;
2537
2393
  startSending;
@@ -2548,28 +2404,30 @@ var RunControl = class {
2548
2404
  if (this.startSending.get()) return Promise.reject(new Error("a start is already pending"));
2549
2405
  let resolveStart;
2550
2406
  let rejectStart;
2551
- const operation = new Promise(
2552
- (resolve, reject) => {
2553
- resolveStart = resolve;
2554
- rejectStart = reject;
2555
- }
2556
- );
2407
+ const operation = new Promise((resolve, reject) => {
2408
+ resolveStart = resolve;
2409
+ rejectStart = reject;
2410
+ });
2557
2411
  this.startOperation = operation;
2412
+ this.startedTarget = null;
2558
2413
  this.stopAskedWhileStarting.set(false);
2559
2414
  this.startSending.set(true);
2560
- let instance = null;
2561
- this.send(
2562
- "api/run",
2563
- request,
2564
- this.startTimeoutMs() || void 0,
2565
- () => {
2566
- this.startSending.set(false);
2567
- },
2568
- (seen) => {
2569
- instance = seen;
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
+ };
2570
2421
  }
2571
- ).then((summary) => resolveStart({ summary, instance }), rejectStart);
2572
- return operation.then(({ summary }) => summary);
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();
2573
2431
  }
2574
2432
  /** Stops in order (waits for the participants to end). Asking again never turns it into a stop without waiting. */
2575
2433
  stop() {
@@ -2581,13 +2439,13 @@ var RunControl = class {
2581
2439
  }
2582
2440
  captureStop() {
2583
2441
  const starting = this.startSending.get() ? this.startOperation : null;
2584
- const target = starting ? null : this.feed.currentTarget();
2442
+ const target = starting ? null : this.activeTarget();
2585
2443
  return {
2586
2444
  key: starting ?? JSON.stringify(target),
2587
2445
  send: (force) => this.requestStop(force, starting, target)
2588
2446
  };
2589
2447
  }
2590
- requestStop(force, starting = this.startSending.get() ? this.startOperation : null, target = starting ? null : this.feed.currentTarget()) {
2448
+ requestStop(force, starting = this.startSending.get() ? this.startOperation : null, target = starting ? null : this.activeTarget()) {
2591
2449
  const session = this.feed.session.get();
2592
2450
  const pending = {
2593
2451
  action: force ? "force" : "stop",
@@ -2619,22 +2477,12 @@ var RunControl = class {
2619
2477
  }
2620
2478
  this.stopAskedWhileStarting.set(true);
2621
2479
  return starting.then(
2622
- ({ summary, instance }) => {
2623
- if (!summary || !instance) {
2624
- const message = "the start answer did not identify the run; no stop was sent";
2625
- const session2 = this.feed.session.get();
2626
- this.failure.set({
2627
- message,
2628
- session: session2?.id ?? null,
2629
- running: isRunActive(session2)
2630
- });
2631
- throw new Error(message);
2632
- }
2633
- pending.key = JSON.stringify({ session: summary.id, instance });
2480
+ (ack) => {
2481
+ pending.key = JSON.stringify({ run_id: ack.run_id, instance: ack.instance });
2634
2482
  this.pendingRevision.update((n) => n + 1);
2635
2483
  return this.send(
2636
2484
  "api/stop-session",
2637
- { force, session: summary.id, instance },
2485
+ { force, run_id: ack.run_id, instance: ack.instance },
2638
2486
  void 0,
2639
2487
  () => void 0
2640
2488
  );
@@ -2651,10 +2499,10 @@ var RunControl = class {
2651
2499
  ).finally(done);
2652
2500
  }
2653
2501
  /**
2654
- * Sends and applies the summary in the answer. done is called after the answer (failures too), before the Promise
2655
- * settles.
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.
2656
2504
  */
2657
- send(path, body, timeoutMs, done, onInstance) {
2505
+ send(path, body, timeoutMs, done) {
2658
2506
  const incompatible = this.feed.incompatible.get();
2659
2507
  if (incompatible) {
2660
2508
  done();
@@ -2678,35 +2526,40 @@ var RunControl = class {
2678
2526
  reject(failure);
2679
2527
  return;
2680
2528
  }
2681
- let summary = null;
2529
+ let ack;
2682
2530
  try {
2683
- const instance = path === "api/stop-session" ? body.instance : readSessionInstance(outcome.body);
2684
- summary = readSessionResponse(outcome.body);
2685
- if (path === "api/stop-session" && (!summary || summary.id !== body.session)) {
2686
- throw new Error("the stop answer did not identify the requested session");
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);
2687
2544
  }
2688
- onInstance?.(instance);
2689
- this.feed.adopt(summary, instance);
2690
2545
  } catch (error) {
2691
2546
  this.feed.report(
2692
2547
  error instanceof ProtocolError ? `unreadable answer: ${error.message}` : String(error)
2693
2548
  );
2694
2549
  const missingInstance = error instanceof ProtocolError && error.path === "response.instance";
2695
- if (path === "api/stop-session" || missingInstance) {
2696
- 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";
2697
- const session = this.feed.session.get();
2698
- this.failure.set({
2699
- message,
2700
- session: session?.id ?? null,
2701
- running: isRunActive(session)
2702
- });
2703
- done();
2704
- reject(new Error(message));
2705
- return;
2706
- }
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)
2556
+ });
2557
+ done();
2558
+ reject(new Error(message));
2559
+ return;
2707
2560
  }
2708
- done();
2709
- resolve(summary);
2561
+ done(ack);
2562
+ resolve(ack);
2710
2563
  });
2711
2564
  });
2712
2565
  }
@@ -2716,12 +2569,13 @@ var RunControl = class {
2716
2569
  var MAX_NOTICES = 20;
2717
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)";
2718
2571
  function sameRunTarget(left, right) {
2719
- 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;
2720
2573
  }
2721
2574
  var SessionFeed = class {
2722
- constructor(connection, onError = rethrowLater) {
2575
+ constructor(connection, onError = rethrowLater, onInstance) {
2723
2576
  this.connection = connection;
2724
2577
  this.onError = onError;
2578
+ this.onInstance = onInstance;
2725
2579
  this.current = new Writable(null, Object.is, onError);
2726
2580
  this.synced = new Writable(false, Object.is, onError);
2727
2581
  this.allowedValue = new Writable(null, Object.is, onError);
@@ -2750,11 +2604,11 @@ var SessionFeed = class {
2750
2604
  }
2751
2605
  connection;
2752
2606
  onError;
2607
+ onInstance;
2753
2608
  rawListeners = /* @__PURE__ */ new Set();
2754
- snapshotVersion = () => 0;
2755
2609
  instanceId = null;
2756
- adoptionRevision = 0;
2757
- instanceListener = () => void 0;
2610
+ lastStreamSeq = -1;
2611
+ resyncing = false;
2758
2612
  stopTarget = null;
2759
2613
  current;
2760
2614
  synced;
@@ -2767,7 +2621,6 @@ var SessionFeed = class {
2767
2621
  messageListeners = /* @__PURE__ */ new Set();
2768
2622
  noticeId = 0;
2769
2623
  stoppedFlag = false;
2770
- replayLogs = null;
2771
2624
  session;
2772
2625
  ready;
2773
2626
  allowed;
@@ -2781,13 +2634,19 @@ var SessionFeed = class {
2781
2634
  return this.stoppedFlag;
2782
2635
  }
2783
2636
  /**
2784
- * 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
2785
2638
  * on every connect (after the call, the copy is not in sync until hello and the resent events have arrived). Used
2786
2639
  * only inside the library.
2787
2640
  */
2788
2641
  resumeFields() {
2789
2642
  this.synced.set(false);
2790
- 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
+ };
2791
2650
  }
2792
2651
  onMessages(listener) {
2793
2652
  this.messageListeners.add(listener);
@@ -2795,23 +2654,10 @@ var SessionFeed = class {
2795
2654
  this.messageListeners.delete(listener);
2796
2655
  };
2797
2656
  }
2798
- /**
2799
- * Applies the summary in an HTTP answer without waiting for the notification (the answers to start, stop and
2800
- * fetchSession(); used inside the library). While the WebSocket is connected, takes only the launcher and the stop
2801
- * request for the same run (the rest arrives in notifications). A summary of an earlier run never brings back an old
2802
- * run over a new one.
2803
- */
2804
2657
  onRawMessages(listener) {
2805
2658
  this.rawListeners.add(listener);
2806
2659
  return () => this.rawListeners.delete(listener);
2807
2660
  }
2808
- onSnapshotVersion(read2) {
2809
- this.snapshotVersion = read2;
2810
- }
2811
- /** Called before a new server's session can be published. */
2812
- onInstance(listener) {
2813
- this.instanceListener = listener;
2814
- }
2815
2661
  /** Instance associated with the current session, or null if its origin is not known. */
2816
2662
  currentInstance() {
2817
2663
  return this.instanceId;
@@ -2819,52 +2665,6 @@ var SessionFeed = class {
2819
2665
  currentTarget() {
2820
2666
  return this.stopTarget ? { ...this.stopTarget } : null;
2821
2667
  }
2822
- adopt(summary, instance, resyncFrom) {
2823
- const switching = this.instanceId !== null && instance !== this.instanceId;
2824
- if (switching && (resyncFrom !== this.instanceId || this.connection.state.get() === "open"))
2825
- return null;
2826
- const previous = switching ? null : this.current.get();
2827
- if (summary && previous && summary.id < previous.id) return null;
2828
- if (!summary && instance === this.instanceId)
2829
- return {
2830
- revision: this.adoptionRevision,
2831
- instance,
2832
- session: previous?.id ?? null
2833
- };
2834
- const revision = ++this.adoptionRevision;
2835
- const next = !summary ? null : previous?.id === summary.id ? applySummary(previous, summary, false, this.connection.state.get() === "open") : sessionFromSummary(summary);
2836
- const changedInstance = instance !== this.instanceId;
2837
- this.instanceId = instance;
2838
- const adoption = { revision, instance, session: next?.id ?? null };
2839
- this.stopTarget = next ? { session: next.id, instance } : null;
2840
- const notifySession = this.current.setDeferred(next);
2841
- const notifyAllowed = switching ? this.allowedValue.setDeferred(null) : () => void 0;
2842
- if (changedInstance) this.instanceListener(instance, () => this.isCurrent(revision));
2843
- notifySession();
2844
- notifyAllowed();
2845
- if (!this.sameRun(adoption)) return null;
2846
- this.adoptAllowed(summary?.allowed ?? null);
2847
- return this.sameRun(adoption) ? adoption : null;
2848
- }
2849
- sameRun(adoption) {
2850
- return this.instanceId === adoption.instance && (this.current.get()?.id ?? null) === adoption.session;
2851
- }
2852
- isCurrent(revision) {
2853
- return revision === this.adoptionRevision;
2854
- }
2855
- /**
2856
- * Takes what the server accepts (an HTTP answer or a notification): the one with the larger `rev` wins (rev 0 is a
2857
- * server that does not number it: the newest arrival wins). Used inside the library.
2858
- */
2859
- adoptAllowed(allowed) {
2860
- if (!allowed) return;
2861
- const current = this.allowedValue.get();
2862
- if (!current || allowed.rev === 0 || allowed.rev >= current.rev) this.allowedValue.set(allowed);
2863
- }
2864
- /** Updates the current persistent runtime status (from HTTP `prepare`/`session`). Used inside the library. */
2865
- adoptRuntime(runtime) {
2866
- this.runtimeValue.set(runtime);
2867
- }
2868
2668
  report(message, count = 1) {
2869
2669
  this.notify(message, count);
2870
2670
  }
@@ -2873,7 +2673,6 @@ var SessionFeed = class {
2873
2673
  }
2874
2674
  /** Reads and applies a batch from the connection. */
2875
2675
  receive(raw) {
2876
- const snapshotVersion = this.snapshotVersion();
2877
2676
  const epoch = this.connection.batchEpoch();
2878
2677
  let originInstance = this.instanceId;
2879
2678
  const currentOrigin = () => this.connection.batchEpoch() === epoch && this.instanceId === originInstance;
@@ -2911,8 +2710,6 @@ var SessionFeed = class {
2911
2710
  break;
2912
2711
  }
2913
2712
  }
2914
- let filtered = this.filterOlderRuns(batch, accepted);
2915
- if (filtered.staleHello && stop === null) stop = "lost";
2916
2713
  if (stop === "unauthorized" || stop === "incompatible") {
2917
2714
  this.stoppedFlag = true;
2918
2715
  this.connection.close();
@@ -2923,8 +2720,7 @@ var SessionFeed = class {
2923
2720
  }
2924
2721
  if (stop === "lost") this.connection.restart();
2925
2722
  if (!currentOrigin()) return;
2926
- filtered = this.filterOlderRuns(filtered.batch, filtered.raw);
2927
- this.apply(filtered.batch, filtered.raw, snapshotVersion, currentOrigin, (instance) => {
2723
+ this.apply(batch, accepted, currentOrigin, (instance) => {
2928
2724
  originInstance = instance;
2929
2725
  });
2930
2726
  if (!currentOrigin()) return;
@@ -2932,53 +2728,23 @@ var SessionFeed = class {
2932
2728
  if (stop === "unauthorized") this.rejectedValue.set(true);
2933
2729
  if (incompatible !== null) this.incompatibleValue.set(incompatible);
2934
2730
  }
2935
- /** Keep messages at or after the run already observed over HTTP, within each server instance. */
2936
- filterOlderRuns(batch, raw) {
2937
- let instance = this.instanceId;
2938
- let floor = this.current.get()?.id ?? null;
2939
- let staleHello = false;
2940
- const selected = [];
2941
- const selectedRaw = [];
2942
- batch.forEach((message, index) => {
2943
- if (message.type === "hello") {
2944
- const id = message.session?.id ?? null;
2945
- if (instance === message.instance && floor !== null && (id === null || id < floor)) {
2946
- staleHello = true;
2947
- return;
2948
- }
2949
- if (instance !== message.instance) {
2950
- instance = message.instance;
2951
- floor = id;
2952
- } else if (id !== null) floor = id;
2953
- } else {
2954
- const id = message.type === "session" ? message.session.id : "session" in message && typeof message.session === "number" ? message.session : null;
2955
- if (id !== null && floor !== null && id < floor) return;
2956
- if (message.type === "session" && (floor === null || message.session.id > floor))
2957
- floor = message.session.id;
2958
- }
2959
- selected.push(message);
2960
- selectedRaw.push(raw[index]);
2961
- });
2962
- return { batch: selected, raw: selectedRaw, staleHello };
2963
- }
2964
- apply(batch, raw, snapshotVersion, currentOrigin, commitOrigin) {
2731
+ apply(batch, raw, currentOrigin, commitOrigin) {
2965
2732
  if (batch.length === 0) return;
2966
- const revision = ++this.adoptionRevision;
2967
2733
  const before = this.current.get();
2968
- const originalInstance = this.instanceId;
2969
- let instance = originalInstance;
2734
+ let instance = this.instanceId;
2970
2735
  let session = before;
2971
- let replayLogs = this.replayLogs?.instance === instance && this.replayLogs?.session === session?.id ? this.replayLogs : null;
2972
- const unseenLogs = () => replayLogs?.logs.filter((line) => replayLogs?.unseen.has(line.seq)) ?? [];
2736
+ let streamSeq = this.lastStreamSeq;
2737
+ let resyncing = this.resyncing;
2973
2738
  let events = [];
2974
2739
  const notices = [];
2740
+ const selectedBatch = [];
2741
+ const selectedRaw = [];
2975
2742
  let applied = false;
2976
2743
  let synced = this.synced.get();
2977
2744
  let allowedNow = this.allowedValue.get();
2978
2745
  let runtimeNow = this.runtimeValue.get();
2979
- const takeAllowed = (incoming, replace = false) => {
2980
- if (!incoming) return;
2981
- if (replace || !allowedNow || incoming.rev === 0 || incoming.rev >= allowedNow.rev) {
2746
+ const takeAllowed = (incoming) => {
2747
+ if (incoming) {
2982
2748
  allowedNow = incoming;
2983
2749
  }
2984
2750
  };
@@ -2990,134 +2756,177 @@ var SessionFeed = class {
2990
2756
  }
2991
2757
  events = [];
2992
2758
  };
2993
- 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
+ }
2994
2768
  if (message.type !== "event") flush();
2995
2769
  switch (message.type) {
2996
2770
  case "hello": {
2997
2771
  synced = false;
2998
2772
  replaying = true;
2999
2773
  const { session: summary, replay } = message;
3000
- const staleSnapshot = !!summary && instance === message.instance && session?.id === summary.id && session.snapshotRev != null && (summary.snapshot_rev == null || summary.snapshot_rev < session.snapshotRev);
3001
- takeAllowed(message.allowed ?? summary?.allowed ?? null, !staleSnapshot);
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);
3002
2788
  if (message.runtime !== void 0) {
3003
2789
  runtimeNow = message.runtime;
3004
- } else if (message.instance !== instance) {
2790
+ } else if (!sameInstance) {
3005
2791
  runtimeNow = null;
3006
2792
  }
3007
- const sameRun2 = summary && instance === message.instance && session?.id === summary.id;
3008
- const resumed = sameRun2 && replay?.from_seq != null;
3009
2793
  instance = message.instance;
3010
- if (!sameRun2) replayLogs = null;
3011
2794
  if (!summary) {
3012
2795
  session = null;
3013
- } else if (sameRun2 && session) {
3014
- const kept = applySummary(session, summary, true, true);
3015
- if (!resumed && instance) {
3016
- const logs = replayLogs ? recoverReplayLogs(kept, unseenLogs(), replayLogs.notKept).logs : kept.logs;
3017
- replayLogs = {
3018
- instance,
3019
- session: summary.id,
3020
- logs: logs.filter((line) => !line.gap || line.gap.launcher),
3021
- unseen: new Set(logs.map((line) => line.seq)),
3022
- notKept: /* @__PURE__ */ new Map()
3023
- };
3024
- }
3025
- session = resumed ? kept : { ...kept, lastSeq: -1, logs: [], logSources: {}, droppedMarks: 0 };
2796
+ } else if (deltaResume && session) {
2797
+ session = applySummary(session, summary);
3026
2798
  } else {
3027
2799
  session = sessionFromSummary(summary);
3028
2800
  }
2801
+ selectedBatch.push(message);
2802
+ selectedRaw.push(rawMessage);
3029
2803
  break;
3030
2804
  }
3031
2805
  case "dropped": {
3032
- if (session && message.session === session.id) {
2806
+ if (session && message.run_id === session.id) {
3033
2807
  session = addDropped(session, message);
3034
- if (message.reason === "not-kept" && replayLogs) {
3035
- for (const [source, count] of Object.entries(message.log))
3036
- replayLogs.notKept.set(source, (replayLogs.notKept.get(source) ?? 0) + count);
3037
- }
2808
+ } else if (session && message.run_id !== null) {
2809
+ continue;
3038
2810
  }
2811
+ selectedBatch.push(message);
2812
+ selectedRaw.push(rawMessage);
3039
2813
  break;
3040
2814
  }
3041
- case "synced":
3042
- if (session && replayLogs && replayLogs.instance === instance && replayLogs.session === session.id)
3043
- session = recoverReplayLogs(session, unseenLogs(), replayLogs.notKept);
3044
- replayLogs = null;
3045
- synced = true;
3046
- 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);
3047
2824
  break;
2825
+ }
3048
2826
  case "allowed":
2827
+ if (message.run_id !== null && (!session || message.run_id !== session.id)) {
2828
+ continue;
2829
+ }
3049
2830
  takeAllowed(message.allowed);
2831
+ selectedBatch.push(message);
2832
+ selectedRaw.push(rawMessage);
3050
2833
  break;
3051
2834
  case "runtime":
3052
2835
  runtimeNow = message.runtime;
2836
+ selectedBatch.push(message);
2837
+ selectedRaw.push(rawMessage);
3053
2838
  break;
3054
2839
  case "session":
3055
- if (session?.id !== message.session.id) replayLogs = null;
3056
2840
  takeAllowed(message.session.allowed);
3057
- session = session?.id === message.session.id ? applySummary(
3058
- session,
3059
- message.session,
3060
- true,
3061
- message.session.last_seq !== null && (session.observedSeq ?? session.lastSeq) >= message.session.last_seq
3062
- ) : 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);
3063
2847
  break;
3064
2848
  case "event":
3065
- if (session?.id === message.session) {
3066
- if (message.event.event === "log" || message.event.event === "log_dropped")
3067
- replayLogs?.unseen.delete(message.event.seq);
2849
+ if (session?.id === message.run_id) {
3068
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);
3069
2856
  }
3070
2857
  break;
3071
2858
  case "error":
3072
2859
  if (message.code === "unauthorized") {
3073
- } else if (session && message.session === session.id) {
3074
- const { code, message: text3, skipped, problem_seq } = message;
2860
+ } else if (session && message.run_id === session.id) {
2861
+ const { code, message: text3, skipped } = message;
3075
2862
  session = addProblem(session, {
3076
2863
  code,
3077
2864
  message: text3,
3078
- ...skipped === void 0 ? {} : { skipped },
3079
- ...problem_seq === void 0 ? {} : { problem_seq }
2865
+ ...skipped === void 0 ? {} : { skipped }
3080
2866
  });
3081
- } else {
2867
+ } else if (message.run_id === null) {
3082
2868
  notices.push(message.message);
2869
+ } else {
2870
+ continue;
3083
2871
  }
2872
+ selectedBatch.push(message);
2873
+ selectedRaw.push(rawMessage);
3084
2874
  break;
3085
2875
  case "resync":
3086
2876
  synced = false;
3087
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);
3088
2888
  break;
3089
2889
  }
3090
2890
  }
3091
2891
  flush();
3092
2892
  const stale = (session?.staleEvents ?? 0) - (before?.id === session?.id ? before?.staleEvents ?? 0 : 0);
3093
- if (!currentOrigin() || !this.isCurrent(revision)) return;
2893
+ if (!currentOrigin()) return;
2894
+ const beforeInstance = this.instanceId;
3094
2895
  this.instanceId = instance;
2896
+ this.lastStreamSeq = streamSeq;
2897
+ this.resyncing = resyncing;
3095
2898
  commitOrigin(instance);
3096
- this.replayLogs = replayLogs && replayLogs.session === session?.id && replayLogs.instance === instance ? replayLogs : null;
3097
- this.stopTarget = session && instance ? { session: session.id, instance } : null;
2899
+ this.stopTarget = session && instance ? { run_id: session.id, instance } : null;
3098
2900
  const sessionId = session?.id ?? null;
3099
- 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;
3100
2902
  const notifySession = this.current.setDeferred(session);
3101
2903
  const notifyAllowed = this.allowedValue.setDeferred(allowedNow);
3102
2904
  const notifyRuntime = this.runtimeValue.setDeferred(runtimeNow);
3103
2905
  const notifySynced = this.synced.setDeferred(synced);
3104
- if (instance && instance !== originalInstance) this.instanceListener(instance, sameRun);
2906
+ if (instance !== null && instance !== beforeInstance) {
2907
+ this.onInstance?.(instance);
2908
+ if (!sameStream()) return;
2909
+ }
3105
2910
  notifySession();
3106
2911
  notifyAllowed();
3107
2912
  notifyRuntime();
3108
2913
  notifySynced();
3109
- if (!sameRun()) return;
2914
+ if (!sameStream()) return;
3110
2915
  for (const notice of notices) {
3111
2916
  this.notify(notice);
3112
- if (!sameRun()) return;
2917
+ if (!sameStream()) return;
3113
2918
  }
3114
2919
  if (applied) this.receivedAt.set(Date.now());
3115
- if (!sameRun()) return;
2920
+ if (!sameStream()) return;
3116
2921
  if (stale > 0) this.notify(STALE_EVENTS_NOTICE, stale);
3117
- if (!sameRun()) return;
3118
- callEach(this.rawListeners, [raw, sameRun, snapshotVersion], this.onError, sameRun);
3119
- if (!sameRun()) return;
3120
- 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
+ }
3121
2930
  }
3122
2931
  notify(message, count = 1) {
3123
2932
  this.noticeList.update((list) => {
@@ -3188,7 +2997,7 @@ var TimeControl = class {
3188
2997
  send(command) {
3189
2998
  const session = this.session.get();
3190
2999
  const target = this.currentTarget();
3191
- 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" };
3192
3001
  if (this.state.get().sending !== null) return { sent: false, reason: "waiting" };
3193
3002
  this.failureValue.set(null);
3194
3003
  const pending = {
@@ -3214,7 +3023,7 @@ var TimeControl = class {
3214
3023
  kind: "server",
3215
3024
  message: errorMessage(outcome.error),
3216
3025
  command: pending.command,
3217
- session: target.session
3026
+ session: target.run_id
3218
3027
  }
3219
3028
  });
3220
3029
  }
@@ -3237,7 +3046,7 @@ var TimeControl = class {
3237
3046
  kind: "no-answer",
3238
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.`,
3239
3048
  command: pending.command,
3240
- session: pending.target.session
3049
+ session: pending.target.run_id
3241
3050
  }
3242
3051
  });
3243
3052
  }
@@ -3367,7 +3176,6 @@ var keyOf = (peer, name) => `${peer}\0${name}`;
3367
3176
  var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
3368
3177
  var text = (value, fallback = "") => typeof value === "string" ? value : fallback;
3369
3178
  var numberOrNull = (value) => typeof value === "number" && Number.isFinite(value) ? value : null;
3370
- var positionOrNull = (value) => Number.isSafeInteger(value) && value >= 0 ? value : null;
3371
3179
  function readVariables2(value, session) {
3372
3180
  const u = new Unreadable("variables");
3373
3181
  const summary = lenient(
@@ -3515,6 +3323,7 @@ function lost(seq, summary) {
3515
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`
3516
3324
  );
3517
3325
  }
3326
+ var runIdOf = (value) => typeof value === "string" && value.length > 0 ? value : null;
3518
3327
  var VariablesFeed = class {
3519
3328
  constructor(link, http, onError = rethrowLater, limits = () => ({})) {
3520
3329
  this.link = link;
@@ -3527,18 +3336,13 @@ var VariablesFeed = class {
3527
3336
  this.state = this.stateValue.readonly();
3528
3337
  this.operations = this.operationsValue.readonly();
3529
3338
  this.watchProblem = this.problemValue.readonly();
3530
- link.onBatch(
3531
- (batch, current, snapshotCurrent) => this.receive(batch, current, snapshotCurrent)
3532
- );
3339
+ link.onBatch((batch, current) => this.receive(batch, current));
3533
3340
  }
3534
3341
  link;
3535
3342
  http;
3536
3343
  onError;
3537
3344
  limits;
3538
3345
  instanceId = null;
3539
- snapshotVersionValue = 0;
3540
- snapshotIdentity = null;
3541
- serverRevision = null;
3542
3346
  stateValue;
3543
3347
  operationsValue;
3544
3348
  handles = /* @__PURE__ */ new Set();
@@ -3587,9 +3391,13 @@ var VariablesFeed = class {
3587
3391
  }
3588
3392
  }
3589
3393
  // --- Notifications --------------------------------------------------------------------------
3590
- receive(batch, current = () => true, initialSnapshotVersion = this.snapshotVersionValue) {
3591
- let snapshotVersion = initialSnapshotVersion;
3592
- 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) {
3593
3401
  const touched = /* @__PURE__ */ new Set();
3594
3402
  let touchedAll = false;
3595
3403
  let operations = null;
@@ -3602,26 +3410,53 @@ var VariablesFeed = class {
3602
3410
  for (const message of batch) {
3603
3411
  if (!current()) return;
3604
3412
  if (!isObject(message)) continue;
3605
- const messageSession = message["session"];
3606
- const existingSession = this.stateValue.get().session;
3607
- if (typeof messageSession === "number" && existingSession !== null && messageSession < existingSession)
3608
- continue;
3609
3413
  switch (message["type"]) {
3610
3414
  case "hello": {
3611
3415
  flush();
3612
3416
  if (!current()) return;
3613
3417
  const summary = message["session"];
3614
- 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);
3615
3422
  if (!current()) return;
3616
- if (isObject(summary) && Number.isSafeInteger(summary["id"])) {
3617
- const id = summary["id"];
3618
- const details = summary["variables"];
3619
- const rev = isObject(details) ? positionOrNull(details["rev"]) : null;
3620
- const applied = this.adoptSummary(summary, current, () => snapshotCurrent(id, rev));
3621
- if (applied !== null && this.snapshotVersionValue === applied)
3622
- 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
+ }
3623
3459
  } else {
3624
- if (this.stateValue.get().session !== null) break;
3625
3460
  this.enter(null);
3626
3461
  if (!current()) return;
3627
3462
  this.stateValue.set({ ...NO_VARIABLES, status: "off" });
@@ -3631,14 +3466,10 @@ var VariablesFeed = class {
3631
3466
  }
3632
3467
  case "session": {
3633
3468
  const summary = message["session"];
3634
- const id = isObject(summary) ? summary["id"] : null;
3635
- const existing = this.stateValue.get().session;
3636
- if (typeof id === "number" && existing !== null && id < existing) break;
3637
- 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) {
3638
3471
  flush();
3639
3472
  if (!current()) return;
3640
- const afterFlush = this.stateValue.get().session;
3641
- if (afterFlush !== null && id < afterFlush) break;
3642
3473
  this.enter(id);
3643
3474
  if (!current()) return;
3644
3475
  if (this.stateValue.get().session !== id) break;
@@ -3647,42 +3478,31 @@ var VariablesFeed = class {
3647
3478
  break;
3648
3479
  }
3649
3480
  case "variables": {
3650
- const id = message["session"];
3651
- if (!Number.isSafeInteger(id)) break;
3481
+ const id = runIdOf(message["run_id"]);
3482
+ if (id === null) break;
3652
3483
  const details = message["variables"];
3653
- const rev = isObject(details) ? positionOrNull(details["rev"]) : null;
3654
3484
  const existing = this.stateValue.get().session;
3655
- if (existing !== null && id < existing) break;
3656
3485
  if (id !== existing) {
3657
3486
  flush();
3658
3487
  if (!current()) return;
3659
- const afterFlush = this.stateValue.get().session;
3660
- if (afterFlush !== null && id < afterFlush) break;
3661
- if (afterFlush !== id) {
3488
+ if (this.stateValue.get().session !== id) {
3662
3489
  this.enter(id);
3663
3490
  if (!current()) return;
3664
3491
  if (this.stateValue.get().session !== id) break;
3665
3492
  touchedAll = true;
3666
3493
  }
3667
3494
  }
3668
- if (snapshotCurrent(id, rev)) {
3669
- const version2 = this.applySnapshot(
3670
- readVariables2(details, id),
3671
- id,
3672
- rev
3673
- );
3674
- if (this.snapshotVersionValue === version2) snapshotVersion = version2;
3675
- }
3495
+ this.stateValue.set(readVariables2(details, id));
3676
3496
  break;
3677
3497
  }
3678
3498
  case "values": {
3679
- if (message["session"] !== this.stateValue.get().session) break;
3499
+ if (runIdOf(message["run_id"]) !== this.stateValue.get().session) break;
3680
3500
  this.takeValues(message, touched);
3681
3501
  break;
3682
3502
  }
3683
3503
  case "operation": {
3684
- const id = message["session"];
3685
- if (id !== this.stateValue.get().session) break;
3504
+ const id = runIdOf(message["run_id"]);
3505
+ if (id === null || id !== this.stateValue.get().session) break;
3686
3506
  const operation = readOperation(message, id);
3687
3507
  if (operation) {
3688
3508
  operations = this.withOperation(operations ?? this.operationsValue.get(), operation);
@@ -3692,12 +3512,8 @@ var VariablesFeed = class {
3692
3512
  }
3693
3513
  case "availability": {
3694
3514
  const id = this.stateValue.get().session;
3695
- if (message["session"] !== id || id === null) break;
3696
- const rev = positionOrNull(message["rev"]);
3697
- if (!snapshotCurrent(id, rev)) break;
3698
- const version2 = this.markSnapshot(id, rev);
3515
+ if (runIdOf(message["run_id"]) !== id || id === null) break;
3699
3516
  if (this.takeAvailability(message["peers"])) touchedAll = true;
3700
- if (this.snapshotVersionValue === version2) snapshotVersion = version2;
3701
3517
  break;
3702
3518
  }
3703
3519
  case "error": {
@@ -3732,94 +3548,8 @@ var VariablesFeed = class {
3732
3548
  this.stateValue.set({ ...state, availability: next });
3733
3549
  return true;
3734
3550
  }
3735
- snapshotVersion() {
3736
- return this.snapshotVersionValue;
3737
- }
3738
- /** Compare server capture order when available; legacy peers use the local best-effort watermark. */
3739
- isSnapshotCurrent(version2, instance, session, rev) {
3740
- if (session === null) return true;
3741
- const source = this.serverRevision;
3742
- if (source && source.instance === instance && source.session === session) {
3743
- return rev !== null && rev >= source.rev;
3744
- }
3745
- if (rev !== null) return true;
3746
- const identity = this.snapshotIdentity;
3747
- return !identity || identity.instance !== instance || identity.session !== session || this.snapshotVersionValue <= version2;
3748
- }
3749
- markSnapshot(session, rev) {
3750
- const version2 = ++this.snapshotVersionValue;
3751
- this.snapshotIdentity = { instance: this.instanceId, session };
3752
- if (rev !== null) this.serverRevision = { instance: this.instanceId, session, rev };
3753
- return version2;
3754
- }
3755
- applySnapshot(state, session, rev) {
3756
- const version2 = this.markSnapshot(session, rev);
3757
- this.stateValue.set(state);
3758
- return version2;
3759
- }
3760
- /** A reused numeric session on another server is a different run. */
3761
- adoptInstance(value) {
3762
- if (typeof value !== "string" || !value) return;
3763
- const changed = this.instanceId !== null && this.instanceId !== value;
3764
- this.instanceId = value;
3765
- if (changed) this.enter(null, true);
3766
- }
3767
- /** Applies a summary: an older snapshot can still carry a terminal write result. */
3768
- adoptSummary(summary, current = () => true, snapshotCurrent = current) {
3769
- if (!isObject(summary) || !Number.isSafeInteger(summary["id"]) || !current()) return null;
3770
- const id = summary["id"];
3771
- const instance = this.instanceId;
3772
- const existing = this.stateValue.get().session;
3773
- if (existing !== null && id < existing) return null;
3774
- const variables = summary["variables"];
3775
- let applyState = snapshotCurrent();
3776
- if (id !== existing) {
3777
- const initial = this.enter(id);
3778
- if (!current()) return null;
3779
- if (this.stateValue.get() !== initial) applyState = applyState && snapshotCurrent();
3780
- }
3781
- const sameIdentity = () => current() && this.instanceId === instance && this.stateValue.get().session === id;
3782
- if (!sameIdentity() || variables === void 0) return null;
3783
- applyState = applyState && snapshotCurrent();
3784
- let notifyOperations = () => void 0;
3785
- const listed = [];
3786
- if (isObject(variables) && Array.isArray(variables["operations"])) {
3787
- let operations = this.operationsValue.get();
3788
- for (const entry of variables["operations"]) {
3789
- const operation = readOperation(entry, id);
3790
- if (operation && (applyState || operation.done)) {
3791
- listed.push(operation);
3792
- operations = this.withOperation(operations, operation);
3793
- }
3794
- }
3795
- notifyOperations = this.prepareOperations(operations, listed, sameIdentity);
3796
- }
3797
- let next = null;
3798
- let appliedVersion = null;
3799
- if (applyState && snapshotCurrent() && sameIdentity()) {
3800
- next = readVariables2(variables, id);
3801
- appliedVersion = this.applySnapshot(
3802
- next,
3803
- id,
3804
- isObject(variables) ? positionOrNull(variables["rev"]) : null
3805
- );
3806
- }
3807
- notifyOperations();
3808
- if (!sameIdentity() || appliedVersion === null || this.snapshotVersionValue !== appliedVersion || !next || this.stateValue.get() !== next)
3809
- return appliedVersion;
3810
- if (isObject(variables) && Array.isArray(variables["operations"])) {
3811
- const fromSeq = variables["operations_from_seq"];
3812
- const openOmitted = variables["operations_open_omitted"];
3813
- this.forgetLost(id, {
3814
- operations: listed,
3815
- fromSeq: Number.isSafeInteger(fromSeq) ? fromSeq : null,
3816
- openOmitted: typeof openOmitted === "number" && openOmitted > 0
3817
- });
3818
- }
3819
- return appliedVersion;
3820
- }
3821
3551
  /**
3822
- * 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
3823
3553
  * a result that will no longer arrive. For writes whose number is not known yet (before the HTTP answer), the summary
3824
3554
  * is kept and checked the same way once the number is known.
3825
3555
  */
@@ -3990,7 +3720,7 @@ var VariablesFeed = class {
3990
3720
  new WriteError("refused", "there is no run to write to", "not-running")
3991
3721
  );
3992
3722
  }
3993
- const body = { session, writes };
3723
+ const body = { run_id: session, writes };
3994
3724
  if (options.instance !== void 0) body["instance"] = options.instance;
3995
3725
  if (options.atMs !== void 0) body["at_ms"] = options.atMs;
3996
3726
  if (options.late !== void 0) body["late"] = options.late;
@@ -4016,8 +3746,8 @@ var VariablesFeed = class {
4016
3746
  }
4017
3747
  const answer = outcome.body;
4018
3748
  const seq = isObject(answer) ? answer["operation"] : null;
4019
- const answered = isObject(answer) ? answer["session_id"] : null;
4020
- if (!Number.isSafeInteger(seq) || !Number.isSafeInteger(answered)) {
3749
+ const answered = isObject(answer) ? runIdOf(answer["run_id"]) : null;
3750
+ if (!Number.isSafeInteger(seq) || answered === null) {
4021
3751
  this.settle(
4022
3752
  pending,
4023
3753
  new WriteError(
@@ -4612,14 +4342,13 @@ function buildClient(options) {
4612
4342
  {
4613
4343
  type: "auth",
4614
4344
  token: token() ?? "",
4615
- ...feed?.resumeFields(),
4616
- session_without_check: true
4345
+ ...feed?.resumeFields()
4617
4346
  }
4618
4347
  ],
4619
4348
  afterGreeting: () => variablesFeed?.resume() ?? [],
4620
4349
  onError
4621
4350
  });
4622
- feed = new SessionFeed(connection, onError);
4351
+ feed = new SessionFeed(connection, onError, (instance) => variablesFeed?.onInstance(instance));
4623
4352
  const session = feed;
4624
4353
  variablesFeed = new VariablesFeed(
4625
4354
  {
@@ -4631,8 +4360,6 @@ function buildClient(options) {
4631
4360
  () => limits.get()
4632
4361
  );
4633
4362
  const variables = variablesFeed;
4634
- session.onSnapshotVersion(() => variables.snapshotVersion());
4635
- session.onInstance((instance) => variables.adoptInstance(instance));
4636
4363
  const run = new RunControl(session, http, onError, () => longRequestMs(limits.get()));
4637
4364
  const time = new TimeControl(
4638
4365
  session.session,
@@ -4774,50 +4501,8 @@ function buildClient(options) {
4774
4501
  body,
4775
4502
  timeoutMs: longRequestMs(limits.get())
4776
4503
  },
4777
- readPrepareResponse,
4778
- (res) => session.adoptRuntime(res.runtime)
4779
- ),
4780
- fetchSession: () => {
4781
- const resyncFrom = session.currentInstance();
4782
- const snapshotVersion = variables.snapshotVersion();
4783
- return new Promise(
4784
- (resolve, reject) => http({ method: "GET", path: "api/session" }, (outcome) => {
4785
- if (!outcome.ok) {
4786
- reject(outcome.error);
4787
- return;
4788
- }
4789
- try {
4790
- const summary = readSessionResponse(outcome.body);
4791
- const instance = readSessionInstance(outcome.body);
4792
- const runtime = readSessionRuntime(outcome.body);
4793
- const adoption = session.adopt(summary, instance, resyncFrom);
4794
- if (adoption !== null) {
4795
- if (runtime !== void 0) session.adoptRuntime(runtime);
4796
- const rawSession = outcome.body?.session;
4797
- const rev = rawSession?.variables?.rev;
4798
- const current = () => variables.isSnapshotCurrent(
4799
- snapshotVersion,
4800
- adoption.instance,
4801
- adoption.session,
4802
- Number.isSafeInteger(rev) && rev >= 0 ? rev : null
4803
- );
4804
- if (session.sameRun(adoption)) session.adoptAllowed(readSessionAllowed(outcome.body));
4805
- const sameRun = () => session.sameRun(adoption);
4806
- if (sameRun()) variables.adoptInstance(instance);
4807
- if (sameRun())
4808
- variables.adoptSummary(
4809
- outcome.body?.session,
4810
- sameRun,
4811
- current
4812
- );
4813
- }
4814
- resolve(summary);
4815
- } catch (error) {
4816
- reject(error);
4817
- }
4818
- })
4819
- );
4820
- }
4504
+ readPrepareResponse
4505
+ )
4821
4506
  };
4822
4507
  clientErrorSinks.set(client, onError);
4823
4508
  return { client, http, onError, runControl: run };
@@ -4889,7 +4574,7 @@ function linkOf(s) {
4889
4574
  }
4890
4575
  var NOT_PACED = "not-paced";
4891
4576
  function startOnItsWay(s) {
4892
- return s.busy.has("start") || s.allowed?.start.reason === "starting";
4577
+ return s.busy.has("start") || s.awaitingRunSession === true || s.allowed?.start.reason === "starting";
4893
4578
  }
4894
4579
  function runOf(s) {
4895
4580
  const session = s.session;
@@ -4898,7 +4583,7 @@ function runOf(s) {
4898
4583
  const outcome = runOutcome(session);
4899
4584
  if (outcome === "crashed") return starting ? "starting" : "crashed";
4900
4585
  if (outcome === "ended" || outcome === "finishing") return starting ? "starting" : "ended";
4901
- if (outcome === "stopping" || outcome === "forcing") return "stopping";
4586
+ if (outcome === "stopping" || outcome === "forcing" || s.stopConfirmed) return "stopping";
4902
4587
  const state = session.launcherState;
4903
4588
  const phase = state?.phase || session.phase;
4904
4589
  const paused = state?.paused ?? null;
@@ -5032,11 +4717,16 @@ function composeControls(s, run) {
5032
4717
  const session = s.session;
5033
4718
  const live = isRunActive(session) && run !== "ended" && run !== "crashed";
5034
4719
  const state = session?.launcherState ?? null;
5035
- const stopsAsked = session?.stopRequests ?? 0;
4720
+ const stopsAsked = Math.max(session?.stopRequests ?? 0, s.stopConfirmed ? 1 : 0);
5036
4721
  let start;
5037
4722
  if (link === "rejected" || link === "incompatible") start = control(false, down);
5038
4723
  else if (s.busy.has("start")) start = control(false, busyReason("start"));
5039
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
+ );
5040
4730
  else if (s.allowed) start = fromServer(s.allowed.start, "the server does not start a run now");
5041
4731
  else
5042
4732
  start = live ? control(
@@ -5194,16 +4884,25 @@ var FrontActions = class {
5194
4884
  this.closing.catch(() => void 0);
5195
4885
  this.busyValue = new Writable(/* @__PURE__ */ new Set(), Object.is, src.onError);
5196
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);
5197
4889
  this.busy = this.busyValue.readonly();
5198
4890
  this.failure = this.failureValue.readonly();
4891
+ this.startedRunId = this.startedRunIdValue.readonly();
4892
+ this.stopConfirmedFor = this.stopConfirmedForValue.readonly();
5199
4893
  this.stops.push(
5200
4894
  src.low.session.onMessages((batch) => this.onMessages(batch)),
5201
- src.low.session.session.subscribe(() => this.evaluate())
4895
+ src.low.session.session.subscribe(() => {
4896
+ this.startedRunIdValue.set(null);
4897
+ this.evaluate();
4898
+ })
5202
4899
  );
5203
4900
  }
5204
4901
  src;
5205
4902
  busyValue;
5206
4903
  failureValue;
4904
+ startedRunIdValue;
4905
+ stopConfirmedForValue;
5207
4906
  waiting = /* @__PURE__ */ new Map();
5208
4907
  inFlight = /* @__PURE__ */ new Map();
5209
4908
  /** The checks not answered yet, in the order they are sent: the first is on its way, the others wait. */
@@ -5217,20 +4916,37 @@ var FrontActions = class {
5217
4916
  disposed = false;
5218
4917
  busy;
5219
4918
  failure;
4919
+ startedRunId;
4920
+ stopConfirmedFor;
5220
4921
  // --- run ---------------------------------------------------------------------------------------
5221
4922
  start(intent = {}, options = {}) {
5222
4923
  const request = this.requestOf(intent, options);
5223
4924
  if (request instanceof ActionError) return this.fail(request);
5224
4925
  const own = this.refusalOfStart();
5225
4926
  if (own) return this.fail(own);
4927
+ this.stopConfirmedForValue.set(null);
5226
4928
  const start = this.src.low.run.start(request);
5227
4929
  return this.guarded(
5228
4930
  "start",
5229
4931
  () => start.then((started) => {
5230
- if (started) options.onStarted?.(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
+ }
5231
4938
  })
5232
4939
  );
5233
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;
4949
+ }
5234
4950
  /**
5235
4951
  * Checks what `intent` would start (`api/check`). Its failure is the caller's: it is not kept for `status.problem`.
5236
4952
  * One check at a time: a check is sent after the answer to the one before (the server runs them one at a time, and
@@ -5373,15 +5089,17 @@ var FrontActions = class {
5373
5089
  return this.once("stop", false);
5374
5090
  }
5375
5091
  forceStop(target) {
5376
- const current = this.src.low.session.currentTarget();
5377
- if (target && (current?.session !== target.session || current.instance !== target.instance))
5378
- return this.fail(
5379
- new ActionError("session-changed", "the confirmed run has changed", "refused")
5380
- );
5381
5092
  if (this.src.low.run.starting.get())
5382
5093
  return this.fail(
5383
5094
  new ActionError("starting", "wait until the new run can be identified", "refused")
5384
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
+ );
5385
5103
  return this.once("force_stop", true);
5386
5104
  }
5387
5105
  /** Pending stop only affects controls of the run it was sent for. */
@@ -5415,7 +5133,8 @@ var FrontActions = class {
5415
5133
  if (this.busyValue.get().has(name)) this.busyValue.set(new Set(this.busyValue.get()));
5416
5134
  else this.setBusy(name, true);
5417
5135
  operation.then(
5418
- () => {
5136
+ (ack) => {
5137
+ this.stopConfirmedForValue.set(ack.run_id);
5419
5138
  if (this.inFlight.get(name) === entry) {
5420
5139
  this.inFlight.delete(name);
5421
5140
  this.setBusy(name, false);
@@ -5570,7 +5289,7 @@ var FrontActions = class {
5570
5289
  if (event.event === "time") sim = event.sim_ms;
5571
5290
  if (event.event !== "command") continue;
5572
5291
  const mine = event.id === null ? void 0 : this.waiting.get(event.id);
5573
- 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);
5574
5293
  else if (event.accepted && event.command !== null && MOVES.has(event.command)) {
5575
5294
  this.interruptMoving(
5576
5295
  null,
@@ -5629,7 +5348,7 @@ var FrontActions = class {
5629
5348
  const session = this.src.low.session.session.get();
5630
5349
  const instance = this.src.low.session.currentInstance();
5631
5350
  for (const w of [...this.waiting.values()]) {
5632
- if (!session || !isRunActive(session) || session.id !== w.session || instance !== w.instance || session.result) {
5351
+ if (!session || !isRunActive(session) || session.id !== w.run_id || instance !== w.instance || session.result) {
5633
5352
  this.settle(
5634
5353
  w,
5635
5354
  new ActionError(
@@ -5722,9 +5441,9 @@ function outsideRows(low, onError) {
5722
5441
  for (const message of batch) {
5723
5442
  if (message.type !== "event" || message.event.event !== "outside") continue;
5724
5443
  const { network, to_outside, from_outside } = message.event;
5725
- const networks = new Map(next?.session === message.session ? next.networks : []);
5444
+ const networks = new Map(next?.run_id === message.run_id ? next.networks : []);
5726
5445
  networks.set(network, { to: to_outside, from: from_outside });
5727
- next = { session: message.session, networks };
5446
+ next = { run_id: message.run_id, networks };
5728
5447
  }
5729
5448
  if (next !== counts.get()) counts.set(next);
5730
5449
  });
@@ -5734,7 +5453,7 @@ function outsideRows(low, onError) {
5734
5453
  const session = low.session.session.get();
5735
5454
  if (!session || !isRunActive(session)) return [];
5736
5455
  const known = counts.get();
5737
- const of = known?.session === session.id ? known.networks : /* @__PURE__ */ new Map();
5456
+ const of = known?.run_id === session.id ? known.networks : /* @__PURE__ */ new Map();
5738
5457
  return (session.launcherState?.outside ?? []).map((row) => {
5739
5458
  const count = of.get(row.network);
5740
5459
  return {
@@ -5946,7 +5665,9 @@ function makeFront(options, onClose) {
5946
5665
  session: low.session.session.get(),
5947
5666
  allowed: low.session.allowed.get(),
5948
5667
  limits: low.limits.get(),
5949
- busy: actions.busyForCurrent()
5668
+ busy: actions.busyForCurrent(),
5669
+ awaitingRunSession: actions.isAwaitingRunSession(),
5670
+ stopConfirmed: actions.isStopConfirmed()
5950
5671
  });
5951
5672
  const sources = [
5952
5673
  low.connection.state,
@@ -5978,7 +5699,7 @@ function makeFront(options, onClose) {
5978
5699
  stamp
5979
5700
  });
5980
5701
  const controlsValue = derived(
5981
- [...sources, actions.busy],
5702
+ [...sources, actions.busy, actions.startedRunId, actions.stopConfirmedFor],
5982
5703
  () => {
5983
5704
  const s = snapshot();
5984
5705
  return controlsOf(s, runOf(s));
@@ -5987,7 +5708,7 @@ function makeFront(options, onClose) {
5987
5708
  onError
5988
5709
  );
5989
5710
  const writeControl = derived(
5990
- [...sources, actions.busy],
5711
+ [...sources, actions.busy, actions.startedRunId, actions.stopConfirmedFor],
5991
5712
  () => {
5992
5713
  const s = snapshot();
5993
5714
  return writeOf(s, runOf(s));
@@ -5996,7 +5717,7 @@ function makeFront(options, onClose) {
5996
5717
  onError
5997
5718
  );
5998
5719
  const status = derived(
5999
- [...sources, actions.busy, actions.failure],
5720
+ [...sources, actions.busy, actions.startedRunId, actions.stopConfirmedFor, actions.failure],
6000
5721
  () => {
6001
5722
  const s = snapshot();
6002
5723
  const base = statusOf(s, initialFile());
@@ -6074,7 +5795,7 @@ function makeFront(options, onClose) {
6074
5795
  ...prepareOptions.enable !== void 0 ? { enable: prepareOptions.enable } : {},
6075
5796
  ...prepareOptions.manual !== void 0 ? { manual: prepareOptions.manual } : {}
6076
5797
  }).then(
6077
- (res) => res.runtime,
5798
+ (res) => res.runtime ?? low.session.runtime.get(),
6078
5799
  (error) => {
6079
5800
  throw actionError(error);
6080
5801
  }
@@ -6287,7 +6008,7 @@ function createWaveforms(client, options = {}) {
6287
6008
  const refresh = () => {
6288
6009
  if (active !== feed || closed) return;
6289
6010
  historyTarget = client.session.currentTarget();
6290
- const current = historyTarget && historyTarget.session === client.variables.state.get().session;
6011
+ const current = historyTarget && historyTarget.run_id === client.variables.state.get().session;
6291
6012
  series.set(
6292
6013
  next.map((ref) => ({ ref: { ...ref }, points: current && feed ? feed.history(ref) : [] }))
6293
6014
  );
@@ -6301,7 +6022,7 @@ function createWaveforms(client, options = {}) {
6301
6022
  subscribe: (listener) => series.subscribe(listener),
6302
6023
  get() {
6303
6024
  const target = client.session.currentTarget();
6304
- if (target?.instance !== historyTarget?.instance || target?.session !== historyTarget?.session)
6025
+ if (target?.instance !== historyTarget?.instance || target?.run_id !== historyTarget?.run_id)
6305
6026
  return series.get().map(({ ref }) => ({ ref, points: [] }));
6306
6027
  return series.get();
6307
6028
  }
@@ -6348,7 +6069,7 @@ function createVariableEditor(front, ref) {
6348
6069
  view,
6349
6070
  shown: bound.pending ?? view.value,
6350
6071
  waiting,
6351
- 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
6352
6073
  };
6353
6074
  };
6354
6075
  const state = new Writable(read2(), Object.is, clientErrorSink(client));
@@ -6364,7 +6085,7 @@ function createVariableEditor(front, ref) {
6364
6085
  const bound = binding.state.get();
6365
6086
  const shown = read2(bound);
6366
6087
  if (closed) return;
6367
- 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) {
6368
6089
  reset();
6369
6090
  } else if (awaiting !== null && shown.view.value === awaiting) {
6370
6091
  reset();
@@ -6468,6 +6189,7 @@ export {
6468
6189
  readDashboardResponse,
6469
6190
  readPrepareResponse,
6470
6191
  readRecording,
6192
+ readRunResponse,
6471
6193
  readRuntimeStatus,
6472
6194
  readSavedConfig,
6473
6195
  readScenarioList,