tmux-ide 2.9.23 → 2.9.25

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.
Files changed (83) hide show
  1. package/bin/cli.js +1636 -385
  2. package/package.json +4 -2
  3. package/packages/contracts/src/pane-stream.ts +53 -0
  4. package/packages/daemon/dist/command-center/discovery.js +24 -5
  5. package/packages/daemon/dist/command-center/server.js +81 -75
  6. package/packages/daemon/dist/command-center/tmux-servers.js +11 -0
  7. package/packages/daemon/dist/doctor.js +46 -10
  8. package/packages/daemon/dist/lib/canonical-daemon-bootstrap.js +20 -2
  9. package/packages/daemon/dist/lib/daemon-crash-snapshot.js +118 -0
  10. package/packages/daemon/dist/lib/daemon-embed.js +22 -8
  11. package/packages/daemon/dist/lib/headless-daemon.js +63 -6
  12. package/packages/daemon/dist/lib/home-agent-observer.js +50 -0
  13. package/packages/daemon/dist/lib/invocation-directory.js +20 -0
  14. package/packages/daemon/dist/lib/machine-agents.js +18 -1
  15. package/packages/daemon/dist/lib/orphaned-control-clients.js +162 -0
  16. package/packages/daemon/dist/lib/runtime-namespace.js +22 -6
  17. package/packages/daemon/dist/lib/tmux-client-execution.js +12 -3
  18. package/packages/daemon/dist/lib/tmux-external-interaction-observer.js +32 -9
  19. package/packages/daemon/dist/lib/tmux-server-owner.js +26 -4
  20. package/packages/daemon/dist/lib/update-check.js +18 -0
  21. package/packages/daemon/dist/lib/update-daemon-outcome.js +31 -0
  22. package/packages/daemon/dist/lib/update.js +39 -14
  23. package/packages/daemon/dist/lib/workspace-promotion.js +24 -3
  24. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
  25. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
  26. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
  27. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
  28. package/packages/daemon/dist/terminal/attachments/native-runtime.js +17 -2
  29. package/packages/daemon/dist/terminal/graphics/kitty-graphics.js +16 -4
  30. package/packages/daemon/dist/terminal/mirror/mirror-service.js +26 -0
  31. package/packages/daemon/dist/terminal/mirror/session-channel.js +27 -2
  32. package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +749 -208
  33. package/packages/daemon/dist/terminal/session-runtime/registry.js +24 -2
  34. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +77 -2
  35. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +24 -2
  36. package/packages/daemon/dist/terminal/session-runtime/transport-binding.js +38 -0
  37. package/packages/daemon/dist/tui/chrome/snapshot.js +36 -1
  38. package/packages/daemon/dist/tui/chrome/statusline.js +8 -5
  39. package/packages/daemon/dist/tui/chrome/updater.js +2 -0
  40. package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-navigation.js +57 -4
  41. package/packages/daemon/dist/tui/mirror/runtime/application-home-agents-owner.js +18 -7
  42. package/packages/daemon/dist/tui/mirror/runtime/application-machine-agent-navigation.js +17 -0
  43. package/packages/daemon/dist/tui/mirror/runtime/application-machine-navigation.js +4 -2
  44. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-interaction-controller.js +55 -14
  45. package/packages/daemon/src/command-center/discovery.ts +24 -4
  46. package/packages/daemon/src/command-center/server.ts +67 -67
  47. package/packages/daemon/src/command-center/tmux-servers.ts +11 -0
  48. package/packages/daemon/src/doctor.ts +50 -9
  49. package/packages/daemon/src/lib/canonical-daemon-bootstrap.ts +31 -5
  50. package/packages/daemon/src/lib/daemon-crash-snapshot.ts +175 -0
  51. package/packages/daemon/src/lib/daemon-embed.ts +74 -7
  52. package/packages/daemon/src/lib/headless-daemon.ts +88 -7
  53. package/packages/daemon/src/lib/home-agent-observer.ts +53 -0
  54. package/packages/daemon/src/lib/invocation-directory.ts +21 -0
  55. package/packages/daemon/src/lib/machine-agents.ts +25 -1
  56. package/packages/daemon/src/lib/orphaned-control-clients.ts +215 -0
  57. package/packages/daemon/src/lib/runtime-namespace.ts +25 -7
  58. package/packages/daemon/src/lib/tmux-client-execution.ts +14 -5
  59. package/packages/daemon/src/lib/tmux-external-interaction-observer.ts +32 -8
  60. package/packages/daemon/src/lib/tmux-server-owner.ts +28 -3
  61. package/packages/daemon/src/lib/update-check.ts +34 -0
  62. package/packages/daemon/src/lib/update-daemon-outcome.ts +42 -0
  63. package/packages/daemon/src/lib/update.ts +58 -16
  64. package/packages/daemon/src/lib/workspace-promotion.ts +26 -3
  65. package/packages/daemon/src/terminal/attachments/native-runtime.ts +21 -2
  66. package/packages/daemon/src/terminal/graphics/kitty-graphics.ts +22 -6
  67. package/packages/daemon/src/terminal/mirror/mirror-service.ts +27 -0
  68. package/packages/daemon/src/terminal/mirror/session-channel.ts +32 -2
  69. package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +819 -223
  70. package/packages/daemon/src/terminal/session-runtime/registry.ts +35 -2
  71. package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +74 -2
  72. package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +21 -1
  73. package/packages/daemon/src/terminal/session-runtime/transport-binding.ts +42 -2
  74. package/packages/daemon/src/tui/chrome/snapshot.ts +47 -1
  75. package/packages/daemon/src/tui/chrome/statusline.ts +7 -4
  76. package/packages/daemon/src/tui/chrome/updater.ts +3 -0
  77. package/packages/daemon/src/tui/mirror/runtime/application-home-agent-navigation.ts +69 -4
  78. package/packages/daemon/src/tui/mirror/runtime/application-home-agents-owner.ts +30 -13
  79. package/packages/daemon/src/tui/mirror/runtime/application-machine-agent-navigation.ts +38 -1
  80. package/packages/daemon/src/tui/mirror/runtime/application-machine-navigation.ts +7 -2
  81. package/packages/daemon/src/tui/mirror/runtime/application-root-v2.tsx +4 -4
  82. package/packages/daemon/src/tui/mirror/runtime/application-terminal-interaction-controller.ts +71 -17
  83. package/packages/daemon-client/src/pane-stream-client.ts +47 -5
@@ -24,6 +24,8 @@ import {
24
24
  PANE_STREAM_INPUT_BYTES_CAPABILITY_VERSION,
25
25
  PANE_STREAM_BROWSER_ICON_CAPABILITY_VERSION,
26
26
  PANE_STREAM_READER_CAPABILITY_VERSION,
27
+ PANE_STREAM_READER_TOPOLOGY_BUNDLE_CAPABILITY_VERSION,
28
+ PANE_STREAM_TOPOLOGY_IN_PLACE_CAPABILITY_VERSION,
27
29
  type PaneStreamInputLifetime,
28
30
  } from "@tmux-ide/contracts";
29
31
  import { inflateSync } from "node:zlib";
@@ -102,7 +104,10 @@ import {
102
104
  } from "../attachments/admission-util.ts";
103
105
  import type { DirectTerminalSocket } from "../attachments/direct-websocket.ts";
104
106
  import type { SessionRuntimeObservability } from "../session-runtime/runtime-observability.ts";
105
- import { SessionRuntimeControllerLeaseError } from "../session-runtime/registry.ts";
107
+ import {
108
+ SessionRuntimeControllerLeaseError,
109
+ SessionRuntimeInputLifetimeEndedError,
110
+ } from "../session-runtime/registry.ts";
106
111
  import { terminalDeliveryObservationOrdinal } from "../session-runtime/terminal-delivery-observation-identity.ts";
107
112
  import {
108
113
  PaneStreamLeaseError,
@@ -221,6 +226,9 @@ const BindingIdSchemaZ = z
221
226
  /** The mirror surface the endpoint consumes (MirrorService satisfies it). */
222
227
  export interface PaneStreamMirror {
223
228
  describeSession(session: string): Promise<MirrorSessionDescription>;
229
+ /** Registered-window ownership is being read again (a session came or went). */
230
+ windowOwnershipPending?(): boolean;
231
+ verifyWindowOwnership?(): Promise<void>;
224
232
  describeSessionAuthority?(
225
233
  session: string,
226
234
  expectedSemanticPaneIds?: readonly string[],
@@ -332,6 +340,10 @@ export interface PaneStreamAdmissionCoordinatorOptions {
332
340
  readonly flowBudgets?: PaneStreamFlowBudgets;
333
341
  /** Cadence of the send-buffer drain check while frames are in flight. */
334
342
  readonly drainTickMs?: number;
343
+ /** Waits between tries of a step of a stream's opening that failed (#585). */
344
+ readonly openRetryDelaysMs?: readonly number[];
345
+ /** How long input waits for registered-window ownership to be read again. */
346
+ readonly ownershipWaitMs?: number;
335
347
  /** Hard whole-socket ceiling; the ledger should stall panes far earlier. */
336
348
  readonly maxSocketBufferedBytes?: number;
337
349
  /** Input flood budget for one rolling admission window, never a lifetime quota. */
@@ -356,6 +368,15 @@ export interface SessionRuntimePaneStreamTransportBinding {
356
368
  readonly explicitAuthority?: boolean;
357
369
  readonly deliveryLaneId?: string;
358
370
  readonly deliveryRequestId?: string;
371
+ /**
372
+ * Amend the transport's exact pane grant when the session's pane set changes
373
+ * under a live stream (#723). Called by the daemon with panes from its own
374
+ * inventory; a binding without it cannot take a new pane in place.
375
+ */
376
+ amendPaneGrant?(change: {
377
+ readonly added: readonly string[];
378
+ readonly removed: readonly string[];
379
+ }): void;
359
380
  /** Optional only for the bounded v1 transport adapter. New clients require these methods. */
360
381
  authoritySnapshot?(): SessionRuntimeAuthoritySnapshot;
361
382
  activateLegacyAuthority?(geometry: boolean): SessionRuntimeAuthoritySnapshot;
@@ -477,6 +498,8 @@ export class PaneStreamAdmissionCoordinator {
477
498
  readonly #redemptionTimeoutMs: number;
478
499
  readonly #flowBudgets: PaneStreamFlowBudgets;
479
500
  readonly #drainTickMs: number;
501
+ readonly #openRetryDelaysMs: readonly number[];
502
+ readonly #ownershipWaitMs: number;
480
503
  readonly #maxSocketBufferedBytes: number;
481
504
  readonly #maxInputFrames: number;
482
505
  readonly #maxInputBytes: number;
@@ -517,6 +540,8 @@ export class PaneStreamAdmissionCoordinator {
517
540
  this.#flowBudgets = options.flowBudgets ?? DEFAULT_PANE_STREAM_FLOW_BUDGETS;
518
541
  this.#ledger = new PaneStreamWireLedger(this.#flowBudgets);
519
542
  this.#drainTickMs = boundedInteger(options.drainTickMs, 15, 1_000);
543
+ this.#openRetryDelaysMs = options.openRetryDelaysMs ?? PANE_STREAM_OPEN_RETRY_DELAYS_MS;
544
+ this.#ownershipWaitMs = options.ownershipWaitMs ?? PANE_STREAM_OWNERSHIP_WAIT_MS;
520
545
  this.#maxSocketBufferedBytes = boundedInteger(
521
546
  options.maxSocketBufferedBytes,
522
547
  32 << 20,
@@ -905,6 +930,8 @@ export class PaneStreamAdmissionCoordinator {
905
930
  leaseManager: this.#leaseManager,
906
931
  ledger: this.#ledger,
907
932
  drainTickMs: this.#drainTickMs,
933
+ openRetryDelaysMs: this.#openRetryDelaysMs,
934
+ ownershipWaitMs: this.#ownershipWaitMs,
908
935
  maxSocketBufferedBytes: this.#maxSocketBufferedBytes,
909
936
  maxInputFrames: this.#maxInputFrames,
910
937
  maxInputBytes: this.#maxInputBytes,
@@ -1127,6 +1154,8 @@ interface LiveConnectionOptions {
1127
1154
  readonly leaseManager: PaneStreamLeaseAuthority;
1128
1155
  readonly ledger: PaneStreamWireLedger;
1129
1156
  readonly drainTickMs: number;
1157
+ readonly openRetryDelaysMs: readonly number[];
1158
+ readonly ownershipWaitMs: number;
1130
1159
  readonly maxSocketBufferedBytes: number;
1131
1160
  readonly maxInputFrames: number;
1132
1161
  readonly maxInputBytes: number;
@@ -1146,8 +1175,38 @@ interface SeedBatch {
1146
1175
  guardArmed: boolean;
1147
1176
  }
1148
1177
 
1178
+ /**
1179
+ * How long an in-place topology change waits for the layout that matches the
1180
+ * session's inventory, when the inventory read was newer than the layout in
1181
+ * hand (a split and a close in quick succession). After it the stream closes
1182
+ * as it would without capability 119.
1183
+ */
1184
+ export const PANE_STREAM_TOPOLOGY_SETTLE_MS = 500;
1185
+
1186
+ /** One pane's delivery, opened and negotiated but not yet announced to the client. */
1187
+ interface OpenedPaneDelivery {
1188
+ readonly channel: PaneChannel;
1189
+ readonly delivery: SessionRuntimeTerminalDeliveryConnection;
1190
+ readonly pending: TerminalDeliveryServerMessage[];
1191
+ readonly markNegotiated: () => void;
1192
+ readonly markReady: () => void;
1193
+ }
1194
+
1195
+ /** About half a second in all: long enough for one slow tmux answer, short for a user. */
1196
+ export const PANE_STREAM_OPEN_RETRY_DELAYS_MS: readonly number[] = [150, 400];
1197
+ /** Input waits this long for ownership to be read again before the stream closes. */
1198
+ export const PANE_STREAM_OWNERSHIP_WAIT_MS = 2_000;
1199
+ /** At most this many input and geometry frames wait for it. */
1200
+ export const PANE_STREAM_OWNERSHIP_HELD_FRAMES = 256;
1201
+
1149
1202
  interface PaneChannel {
1150
1203
  readonly semanticPaneId: string;
1204
+ /**
1205
+ * The pane left the session under a capability-119 stream. A client frame
1206
+ * that was already on its way for this pane (an ack, input) is dropped, not
1207
+ * a protocol error: the client could not know yet.
1208
+ */
1209
+ retiredInPlace?: boolean;
1151
1210
  sub: MirrorSubscription | null;
1152
1211
  delivery: SessionRuntimeTerminalDeliveryConnection | null;
1153
1212
  deliveryAddress: {
@@ -1228,6 +1287,8 @@ export class PaneStreamLiveConnection {
1228
1287
  readonly #leaseManager: PaneStreamLeaseAuthority;
1229
1288
  readonly #ledger: PaneStreamWireLedger;
1230
1289
  readonly #drainTickMs: number;
1290
+ readonly #openRetryDelaysMs: readonly number[];
1291
+ readonly #ownershipWaitMs: number;
1231
1292
  readonly #maxSocketBufferedBytes: number;
1232
1293
  readonly #maxInputFrames: number;
1233
1294
  readonly #maxInputBytes: number;
@@ -1241,6 +1302,13 @@ export class PaneStreamLiveConnection {
1241
1302
  readonly #panes = new Map<string, PaneChannel>();
1242
1303
  readonly #semanticLayouts = new Map<string, MirrorLayoutEvent>();
1243
1304
  #semanticExpectedPaneIds: readonly string[] | null = null;
1305
+ /** Capability 119 (#723): a changed pane set is announced, not a reason to close. */
1306
+ readonly #topologyInPlace: boolean;
1307
+ /** The stream was issued for every pane of its session: new panes join it. */
1308
+ #leasesWholeSession = false;
1309
+ #topologyReconciling = false;
1310
+ #topologyPending: MirrorLayoutAuthoritySnapshot | null = null;
1311
+ #topologyWaiter: (() => void) | null = null;
1244
1312
  #semanticRuntimeSessionId: string | null = null;
1245
1313
  #semanticWindowLinks: WindowLinkTopology | null = null;
1246
1314
  #semanticTopologyEpoch = -1;
@@ -1364,6 +1432,8 @@ export class PaneStreamLiveConnection {
1364
1432
  this.#leaseManager = options.leaseManager;
1365
1433
  this.#ledger = options.ledger;
1366
1434
  this.#drainTickMs = options.drainTickMs;
1435
+ this.#openRetryDelaysMs = options.openRetryDelaysMs;
1436
+ this.#ownershipWaitMs = options.ownershipWaitMs ?? PANE_STREAM_OWNERSHIP_WAIT_MS;
1367
1437
  this.#maxSocketBufferedBytes = options.maxSocketBufferedBytes;
1368
1438
  this.#maxInputFrames = options.maxInputFrames;
1369
1439
  this.#maxInputBytes = options.maxInputBytes;
@@ -1378,26 +1448,13 @@ export class PaneStreamLiveConnection {
1378
1448
  : undefined;
1379
1449
  this.#diagnosticAfterFrameParse = options.diagnosticAfterFrameParse;
1380
1450
  this.#onRetire = options.onRetire;
1381
- for (const pane of options.descriptor.panes) {
1382
- this.#panes.set(pane, {
1383
- semanticPaneId: pane,
1384
- sub: null,
1385
- delivery: null,
1386
- deliveryAddress: null,
1387
- serverSeq: 0,
1388
- sentPaneFrames: 0,
1389
- consumedSeq: 0,
1390
- nextInputSeq: 1,
1391
- frozenByWire: false,
1392
- closed: false,
1393
- batch: null,
1394
- graphicsAnnounced: false,
1395
- graphicsQueue: [],
1396
- graphicsSending: false,
1397
- graphicsServed: new Map(),
1398
- graphicsState: null,
1399
- });
1400
- }
1451
+ this.#topologyInPlace =
1452
+ options.descriptor.terminalDelivery?.protocolVersions.some(
1453
+ (version) =>
1454
+ version === PANE_STREAM_TOPOLOGY_IN_PLACE_CAPABILITY_VERSION ||
1455
+ version === PANE_STREAM_READER_TOPOLOGY_BUNDLE_CAPABILITY_VERSION,
1456
+ ) === true;
1457
+ for (const pane of options.descriptor.panes) this.#panes.set(pane, newPaneChannel(pane));
1401
1458
  }
1402
1459
 
1403
1460
  get clientId(): string {
@@ -1427,6 +1484,7 @@ export class PaneStreamLiveConnection {
1427
1484
  )
1428
1485
  ? { inputBytes: true as const }
1429
1486
  : {}),
1487
+ ...(this.#topologyInPlace ? { topologyInPlace: true as const } : {}),
1430
1488
  protocolVersion: PANE_STREAM_PROTOCOL_VERSION,
1431
1489
  daemonInstanceId: this.#binding.daemonInstanceId,
1432
1490
  requestId: this.#binding.requestId,
@@ -1440,7 +1498,12 @@ export class PaneStreamLiveConnection {
1440
1498
  : {}),
1441
1499
  });
1442
1500
  this.#recordDiagnosticLifecycle("pane-stream-server-ready");
1443
- } catch {
1501
+ } catch (error) {
1502
+ // The one 1011 that still closed without a cause in the log.
1503
+ this.#closeCause = {
1504
+ cause: "ready-frame-failed",
1505
+ error: (error instanceof Error ? error.message : String(error)).slice(0, 300),
1506
+ };
1444
1507
  this.close(1011, "stream-unavailable-describe");
1445
1508
  return;
1446
1509
  }
@@ -1480,8 +1543,14 @@ export class PaneStreamLiveConnection {
1480
1543
  // Whether this connection held input when it went: the next stream of
1481
1544
  // the same client can only be granted input once that is released.
1482
1545
  ...(this.#heldInput === null ? {} : { heldInput: this.#heldInput }),
1546
+ // Keys not delivered because their pane lifetime had ended (#397).
1547
+ ...(this.#inputLifetimeEndedDropped > 0
1548
+ ? { droppedEndedLifetimeInputs: this.#inputLifetimeEndedDropped }
1549
+ : {}),
1483
1550
  });
1484
1551
  this.#closed = true;
1552
+ this.#ownershipHeld.length = 0;
1553
+ this.#ownershipWake?.();
1485
1554
  for (const demand of this.#surfaceDemands.values()) demand.close();
1486
1555
  this.#surfaceDemands.clear();
1487
1556
  this.#surfaceViewer?.close();
@@ -1548,7 +1617,9 @@ export class PaneStreamLiveConnection {
1548
1617
  // is absence; a describe FAILURE is not and fails the connection).
1549
1618
  let described: MirrorSessionDescription;
1550
1619
  try {
1551
- described = await this.#mirror.describeSession(this.#descriptor.sessionName);
1620
+ described = await this.#retryOpenStep("describe-session", () =>
1621
+ this.#mirror.describeSession(this.#descriptor.sessionName),
1622
+ );
1552
1623
  } catch (error) {
1553
1624
  this.#fail("describe-session-failed", error);
1554
1625
  return;
@@ -1603,6 +1674,37 @@ export class PaneStreamLiveConnection {
1603
1674
  this.#closeIfAllPanesGone();
1604
1675
  }
1605
1676
 
1677
+ /**
1678
+ * One step of a stream's opening, tried again after a failure (#585): on a
1679
+ * loaded host one slow tmux answer failed the step, the step closed the whole
1680
+ * stream with 1011, and nothing was tried twice. A refusal of authority is a
1681
+ * decision, not a failure, and is never repeated. Each repeat is logged.
1682
+ */
1683
+ async #retryOpenStep<T>(step: string, run: () => Promise<T>): Promise<T> {
1684
+ for (let attempt = 0; ; attempt += 1) {
1685
+ try {
1686
+ return await run();
1687
+ } catch (error) {
1688
+ const delayMs = this.#openRetryDelaysMs[attempt];
1689
+ if (
1690
+ delayMs === undefined ||
1691
+ this.#closed ||
1692
+ error instanceof SessionRuntimeControllerLeaseError
1693
+ )
1694
+ throw error;
1695
+ logger.info("pane-stream", "stream open step failed; trying again", {
1696
+ session: this.#descriptor.sessionName,
1697
+ clientId: this.#clientId,
1698
+ step,
1699
+ attempt: attempt + 1,
1700
+ error: (error instanceof Error ? error.message : String(error)).slice(0, 300),
1701
+ });
1702
+ await new Promise<void>((resolve) => setTimeout(resolve, delayMs));
1703
+ if (this.#closed) throw error;
1704
+ }
1705
+ }
1706
+ }
1707
+
1606
1708
  async #subscribeSemantic(known: ReadonlySet<string>): Promise<void> {
1607
1709
  const binding = this.#sessionRuntimeBinding;
1608
1710
  const offer = this.#descriptor.terminalDelivery;
@@ -1696,32 +1798,7 @@ export class PaneStreamLiveConnection {
1696
1798
  // removes N x attachment latency without allowing a fast pane to make the
1697
1799
  // session look ready while a sibling is still missing. allSettled is
1698
1800
  // deliberate: partial success is always closed before the socket retires.
1699
- const openings = channels.map(async (channel) => {
1700
- const pending: TerminalDeliveryServerMessage[] = [];
1701
- let ready = false;
1702
- let negotiated = false;
1703
- const delivery = await binding.openTerminalDelivery(
1704
- channel.semanticPaneId,
1705
- offer,
1706
- (message) => {
1707
- if (!ready && !(negotiated && message.type === "terminal.delivery.fault"))
1708
- pending.push(message);
1709
- else return this.#sendTerminalDelivery(channel.semanticPaneId, message);
1710
- },
1711
- this.#descriptor.workspaceName,
1712
- );
1713
- return {
1714
- channel,
1715
- delivery,
1716
- pending,
1717
- markNegotiated: () => {
1718
- negotiated = true;
1719
- },
1720
- markReady: () => {
1721
- ready = true;
1722
- },
1723
- };
1724
- });
1801
+ const openings = channels.map((channel) => this.#openPaneDelivery(binding, offer, channel));
1725
1802
  const settled = await Promise.allSettled(openings);
1726
1803
  const opened = settled.flatMap((result) =>
1727
1804
  result.status === "fulfilled" ? [result.value] : [],
@@ -1743,27 +1820,7 @@ export class PaneStreamLiveConnection {
1743
1820
  return;
1744
1821
  }
1745
1822
 
1746
- const deliveryIdentityChanged = opened.some(({ channel, delivery, pending }) => {
1747
- if (!delivery.negotiation.accepted) return true;
1748
- const negotiated = delivery.negotiation.negotiated;
1749
- if (negotiated.generation !== this.#binding.daemonInstanceId) return true;
1750
- let incarnation: string | null = null;
1751
- for (const message of pending) {
1752
- if (message.type !== "terminal.delivery" && message.type !== "terminal.projection")
1753
- continue;
1754
- if (
1755
- message.workspaceName !== this.#descriptor.workspaceName ||
1756
- message.semanticPaneId !== channel.semanticPaneId ||
1757
- message.generation !== negotiated.generation ||
1758
- message.deliveryNonce !== negotiated.deliveryNonce ||
1759
- (incarnation !== null && message.incarnation !== incarnation)
1760
- )
1761
- return true;
1762
- incarnation = message.incarnation;
1763
- }
1764
- return false;
1765
- });
1766
- if (deliveryIdentityChanged) {
1823
+ if (opened.some((entry) => this.#deliveryIdentityChanged(entry))) {
1767
1824
  await Promise.all(opened.map(({ delivery }) => delivery.close().catch(() => undefined)));
1768
1825
  this.#failTopologyChanged();
1769
1826
  return;
@@ -1794,6 +1851,7 @@ export class PaneStreamLiveConnection {
1794
1851
  }
1795
1852
  this.#recordDiagnosticLifecycle("pane-stream-layout-validated");
1796
1853
  this.#semanticExpectedPaneIds = expectedPaneIds;
1854
+ this.#leasesWholeSession = expectedPaneIds.every((pane) => this.#panes.has(pane));
1797
1855
  this.#semanticRuntimeSessionId = authority!.runtimeSessionId;
1798
1856
  this.#semanticWindowLinks = authority!.windowLinks;
1799
1857
  this.#semanticTopologyEpoch = authority!.topologyEpoch;
@@ -1822,6 +1880,70 @@ export class PaneStreamLiveConnection {
1822
1880
  Number(visibleAtDelivery.has(right.channel.semanticPaneId)) -
1823
1881
  Number(visibleAtDelivery.has(left.channel.semanticPaneId)),
1824
1882
  );
1883
+ await this.#publishOpenedDeliveries(opened);
1884
+ this.#closeIfAllPanesGone();
1885
+ }
1886
+
1887
+ /** Open one pane's delivery; its messages wait until the pane is announced. */
1888
+ async #openPaneDelivery(
1889
+ binding: SessionRuntimePaneStreamTransportBinding,
1890
+ offer: NonNullable<PaneStreamLeaseDescriptor["terminalDelivery"]>,
1891
+ channel: PaneChannel,
1892
+ ): Promise<OpenedPaneDelivery> {
1893
+ const pending: TerminalDeliveryServerMessage[] = [];
1894
+ let ready = false;
1895
+ let negotiated = false;
1896
+ // #585: a failed open is tried again (150 ms, 400 ms) before the stream
1897
+ // closes; this applies to a pane added in place too.
1898
+ const delivery = await this.#retryOpenStep("pane-delivery-open", () => {
1899
+ // A try that failed may have delivered something; start clean.
1900
+ pending.length = 0;
1901
+ return binding.openTerminalDelivery(
1902
+ channel.semanticPaneId,
1903
+ offer,
1904
+ (message) => {
1905
+ if (!ready && !(negotiated && message.type === "terminal.delivery.fault"))
1906
+ pending.push(message);
1907
+ else return this.#sendTerminalDelivery(channel.semanticPaneId, message);
1908
+ },
1909
+ this.#descriptor.workspaceName,
1910
+ );
1911
+ });
1912
+ return {
1913
+ channel,
1914
+ delivery,
1915
+ pending,
1916
+ markNegotiated: () => {
1917
+ negotiated = true;
1918
+ },
1919
+ markReady: () => {
1920
+ ready = true;
1921
+ },
1922
+ };
1923
+ }
1924
+
1925
+ #deliveryIdentityChanged({ channel, delivery, pending }: OpenedPaneDelivery): boolean {
1926
+ if (!delivery.negotiation.accepted) return true;
1927
+ const negotiated = delivery.negotiation.negotiated;
1928
+ if (negotiated.generation !== this.#binding.daemonInstanceId) return true;
1929
+ let incarnation: string | null = null;
1930
+ for (const message of pending) {
1931
+ if (message.type !== "terminal.delivery" && message.type !== "terminal.projection") continue;
1932
+ if (
1933
+ message.workspaceName !== this.#descriptor.workspaceName ||
1934
+ message.semanticPaneId !== channel.semanticPaneId ||
1935
+ message.generation !== negotiated.generation ||
1936
+ message.deliveryNonce !== negotiated.deliveryNonce ||
1937
+ (incarnation !== null && message.incarnation !== incarnation)
1938
+ )
1939
+ return true;
1940
+ incarnation = message.incarnation;
1941
+ }
1942
+ return false;
1943
+ }
1944
+
1945
+ /** Announce validated deliveries, then replay what each collected meanwhile. */
1946
+ async #publishOpenedDeliveries(opened: readonly OpenedPaneDelivery[]): Promise<void> {
1825
1947
  for (const { channel, delivery, markNegotiated } of opened) {
1826
1948
  if (this.#closed || channel.closed) {
1827
1949
  await delivery.close();
@@ -1868,10 +1990,46 @@ export class PaneStreamLiveConnection {
1868
1990
  markReady();
1869
1991
  this.#startGraphics(channel);
1870
1992
  }
1871
- this.#closeIfAllPanesGone();
1872
1993
  }
1873
1994
 
1995
+ /**
1996
+ * A tombstone ends a pane's delivery for good: the hub drops the pane and
1997
+ * sends nothing more. Without capability 119 the pane's removal closes the
1998
+ * stream anyway. With it, the removal arrives as a `topology` frame within
1999
+ * moments; if none comes, the pane is still in the session and would stay
2000
+ * blank for ever, so the stream closes as it would without the capability
2001
+ * and the client takes a new one.
2002
+ */
2003
+ #watchTombstone(pane: string): void {
2004
+ const channel = this.#panes.get(pane);
2005
+ if (!this.#topologyInPlace || !channel || channel.closed) return;
2006
+ const timer = setTimeout(() => {
2007
+ if (this.#closed || channel.retiredInPlace || this.#panes.get(pane) !== channel) return;
2008
+ // A change being applied may be the one that removes this pane (kill-pane
2009
+ // plus split: the new pane's delivery can take longer to open than the
2010
+ // settle time). Decide again once it is done, with a fresh settle time.
2011
+ if (this.#topologyReconciling) {
2012
+ this.#tombstonesAfterChange.add(channel);
2013
+ return;
2014
+ }
2015
+ this.#failTopologyChanged("a pane that stays lost its source");
2016
+ }, PANE_STREAM_TOPOLOGY_SETTLE_MS);
2017
+ timer.unref?.();
2018
+ }
2019
+
2020
+ /**
2021
+ * Tombstoned channels whose guard came due while a change was being applied.
2022
+ * The channel, not the pane id: a pane that left and came back within the
2023
+ * change has a fresh channel, which this tombstone is not about.
2024
+ */
2025
+ readonly #tombstonesAfterChange = new Set<PaneChannel>();
2026
+
1874
2027
  async #sendTerminalDelivery(pane: string, message: TerminalDeliveryServerMessage): Promise<void> {
2028
+ if (
2029
+ (message.type === "terminal.delivery" || message.type === "terminal.projection") &&
2030
+ message.frame === "tombstone"
2031
+ )
2032
+ this.#watchTombstone(pane);
1875
2033
  if (message.type === "terminal.projection") {
1876
2034
  const channel = this.#panes.get(pane);
1877
2035
  if (channel?.deliveryAddress) channel.deliveryAddress.incarnation = message.incarnation;
@@ -2025,7 +2183,8 @@ export class PaneStreamLiveConnection {
2025
2183
  (version) =>
2026
2184
  version === TERMINAL_GRAPHICS_ZLIB_CAPABILITY_VERSION ||
2027
2185
  version === PANE_STREAM_BROWSER_ICON_CAPABILITY_VERSION ||
2028
- version === PANE_STREAM_READER_CAPABILITY_VERSION,
2186
+ version === PANE_STREAM_READER_CAPABILITY_VERSION ||
2187
+ version === PANE_STREAM_READER_TOPOLOGY_BUNDLE_CAPABILITY_VERSION,
2029
2188
  ) === true;
2030
2189
  channel.graphicsZlib = zlib;
2031
2190
  channel.graphicsLocal =
@@ -2433,16 +2592,23 @@ export class PaneStreamLiveConnection {
2433
2592
 
2434
2593
  #onLayoutAuthority(snapshot: MirrorLayoutAuthoritySnapshot): void {
2435
2594
  if (this.#closed || !this.#semanticExpectedPaneIds || !this.#semanticRuntimeSessionId) return;
2436
- if (
2437
- snapshot.session !== this.#descriptor.sessionName ||
2438
- snapshot.runtimeSessionId !== this.#semanticRuntimeSessionId ||
2439
- snapshot.topologyEpoch <= this.#semanticTopologyEpoch ||
2440
- snapshot.layouts.length > PANE_STREAM_MAX_PANES
2441
- ) {
2595
+ if (this.#topologyReconciling) {
2596
+ // One change at a time, and only the newest state is worth announcing.
2597
+ this.#topologyPending = snapshot;
2598
+ this.#topologyWaiter?.();
2599
+ return;
2600
+ }
2601
+ if (!this.#layoutAuthorityAdmissible(snapshot)) {
2442
2602
  this.#failTopologyChanged();
2443
2603
  return;
2444
2604
  }
2445
2605
  const frames = this.#validateInitialLayout(snapshot.layouts, this.#semanticExpectedPaneIds);
2606
+ if (!frames && this.#topologyInPlace) {
2607
+ // The layout does not fit the pane set this stream knows. With
2608
+ // capability 119 that is a change to follow, not a reason to close.
2609
+ void this.#reconcileTopology(snapshot);
2610
+ return;
2611
+ }
2446
2612
  if (
2447
2613
  !frames ||
2448
2614
  !PaneStreamLayoutSnapshotFrameSchemaZ.safeParse({
@@ -2455,8 +2621,36 @@ export class PaneStreamLiveConnection {
2455
2621
  this.#failTopologyChanged();
2456
2622
  return;
2457
2623
  }
2624
+ if (!this.#windowLinksAdmissible(snapshot)) {
2625
+ this.#failTopologyChanged();
2626
+ return;
2627
+ }
2628
+ this.#semanticWindowLinks = snapshot.windowLinks;
2629
+ this.#semanticTopologyEpoch = snapshot.topologyEpoch;
2630
+ this.#semanticLayouts.clear();
2631
+ for (const event of snapshot.layouts)
2632
+ this.#semanticLayouts.set(event.semanticWindowId as string, event);
2633
+ this.#sendFrame(null, {
2634
+ type: "layout-snapshot",
2635
+ topologyEpoch: snapshot.topologyEpoch,
2636
+ layouts: frames,
2637
+ windowLinks: snapshot.windowLinks,
2638
+ });
2639
+ }
2640
+
2641
+ /** The same session and runtime, a newer epoch, a layout a stream can carry. */
2642
+ #layoutAuthorityAdmissible(snapshot: MirrorLayoutAuthoritySnapshot): boolean {
2643
+ return (
2644
+ snapshot.session === this.#descriptor.sessionName &&
2645
+ snapshot.runtimeSessionId === this.#semanticRuntimeSessionId &&
2646
+ snapshot.topologyEpoch > this.#semanticTopologyEpoch &&
2647
+ snapshot.layouts.length <= PANE_STREAM_MAX_PANES
2648
+ );
2649
+ }
2650
+
2651
+ #windowLinksAdmissible(snapshot: MirrorLayoutAuthoritySnapshot): boolean {
2458
2652
  const previousLinks = this.#semanticWindowLinks;
2459
- if (
2653
+ return !(
2460
2654
  !previousLinks ||
2461
2655
  snapshot.windowLinks.liveSessionId !== previousLinks.liveSessionId ||
2462
2656
  snapshot.windowLinks.linkRevision < previousLinks.linkRevision ||
@@ -2465,21 +2659,230 @@ export class PaneStreamLiveConnection {
2465
2659
  [...snapshot.windowLinks.links].sort((a, b) => a.linkId.localeCompare(b.linkId)),
2466
2660
  ) !==
2467
2661
  JSON.stringify([...previousLinks.links].sort((a, b) => a.linkId.localeCompare(b.linkId))))
2662
+ );
2663
+ }
2664
+
2665
+ /**
2666
+ * Capability 119 (#723). Follow a changed pane set without closing: one
2667
+ * change at a time, newest state only. Every doubt ends where a stream
2668
+ * without the capability ends, in `#failTopologyChanged()`.
2669
+ */
2670
+ async #reconcileTopology(first: MirrorLayoutAuthoritySnapshot): Promise<void> {
2671
+ this.#topologyReconciling = true;
2672
+ let snapshot = first;
2673
+ try {
2674
+ for (;;) {
2675
+ this.#topologyPending = null;
2676
+ const outcome = await this.#applyTopology(snapshot);
2677
+ if (this.#closed) return;
2678
+ if (outcome === "failed") return this.#failTopologyChanged(this.#topologyFailure);
2679
+ let next: MirrorLayoutAuthoritySnapshot | null = this.#topologyPending;
2680
+ if (outcome === "stale" && !next) {
2681
+ // The inventory was read after a further change: its layout follows.
2682
+ next = await this.#nextTopologySnapshot();
2683
+ if (this.#closed) return;
2684
+ if (!next) return this.#failTopologyChanged();
2685
+ }
2686
+ if (!next) return;
2687
+ if (!this.#layoutAuthorityAdmissible(next)) return this.#failTopologyChanged();
2688
+ snapshot = next;
2689
+ }
2690
+ } finally {
2691
+ this.#topologyReconciling = false;
2692
+ this.#topologyPending = null;
2693
+ const tombstoned = [...this.#tombstonesAfterChange];
2694
+ this.#tombstonesAfterChange.clear();
2695
+ for (const channel of tombstoned)
2696
+ if (this.#panes.get(channel.semanticPaneId) === channel)
2697
+ this.#watchTombstone(channel.semanticPaneId);
2698
+ }
2699
+ }
2700
+
2701
+ #nextTopologySnapshot(): Promise<MirrorLayoutAuthoritySnapshot | null> {
2702
+ if (this.#topologyPending) return Promise.resolve(this.#topologyPending);
2703
+ return new Promise((resolve) => {
2704
+ const finish = (): void => {
2705
+ clearTimeout(timer);
2706
+ this.#topologyWaiter = null;
2707
+ resolve(this.#topologyPending);
2708
+ };
2709
+ const timer = setTimeout(finish, PANE_STREAM_TOPOLOGY_SETTLE_MS);
2710
+ timer.unref?.();
2711
+ this.#topologyWaiter = finish;
2712
+ });
2713
+ }
2714
+
2715
+ /**
2716
+ * "applied": the client was told and the stream goes on. "stale": this
2717
+ * layout does not fit the session's inventory as read now; a newer layout
2718
+ * decides. "failed": close.
2719
+ */
2720
+ async #applyTopology(
2721
+ snapshot: MirrorLayoutAuthoritySnapshot,
2722
+ ): Promise<"applied" | "stale" | "failed"> {
2723
+ const binding = this.#sessionRuntimeBinding;
2724
+ const offer = this.#descriptor.terminalDelivery;
2725
+ if (
2726
+ !binding ||
2727
+ !offer ||
2728
+ !this.#semanticExpectedPaneIds ||
2729
+ !this.#windowLinksAdmissible(snapshot)
2730
+ )
2731
+ return this.#topologyFailed("not a semantic stream, or its window links changed");
2732
+ // A zoomed window lists one pane, so the layout alone cannot tell which
2733
+ // panes exist: the trusted inventory does.
2734
+ // The inventory is read by session NAME. Only an inventory that states
2735
+ // the runtime session this stream was issued for may extend the grant: a
2736
+ // session replaced under the same name is another session.
2737
+ let described: MirrorSessionDescription;
2738
+ let inventoryIsThisSession = false;
2739
+ try {
2740
+ if (this.#mirror.describeSessionAuthority) {
2741
+ const authority = await this.#mirror.describeSessionAuthority(this.#descriptor.sessionName);
2742
+ if (authority.runtimeSessionId !== this.#semanticRuntimeSessionId)
2743
+ return this.#topologyFailed("inventory is of another runtime session");
2744
+ described = authority.description;
2745
+ inventoryIsThisSession = true;
2746
+ } else {
2747
+ described = await this.#mirror.describeSession(this.#descriptor.sessionName);
2748
+ }
2749
+ } catch (error) {
2750
+ return this.#topologyFailed("session inventory unavailable", error);
2751
+ }
2752
+ if (this.#closed) return this.#topologyFailed("closed");
2753
+ const next = [...new Set(described.panes.map((pane) => pane.semanticPaneId))].sort();
2754
+ if (next.length === 0) return this.#topologyFailed("session has no panes");
2755
+ const frames = this.#validateInitialLayout(snapshot.layouts, next);
2756
+ if (!frames) return "stale";
2757
+ if (
2758
+ !PaneStreamLayoutSnapshotFrameSchemaZ.safeParse({
2759
+ type: "layout-snapshot",
2760
+ topologyEpoch: snapshot.topologyEpoch,
2761
+ layouts: frames,
2762
+ windowLinks: snapshot.windowLinks,
2763
+ }).success
2764
+ )
2765
+ return this.#topologyFailed("layout snapshot invalid");
2766
+ const live = [...this.#panes.values()].filter((channel) => !channel.closed);
2767
+ const removed = live.filter((channel) => !next.includes(channel.semanticPaneId));
2768
+ // A stream issued for the whole session follows it; one issued for some
2769
+ // panes keeps exactly those.
2770
+ const liveIds = new Set(live.map((channel) => channel.semanticPaneId));
2771
+ const added = this.#leasesWholeSession ? next.filter((pane) => !liveIds.has(pane)) : [];
2772
+ if (added.length > 0 && !inventoryIsThisSession)
2773
+ return this.#topologyFailed("inventory cannot prove the runtime session");
2774
+ const remaining = live.length - removed.length + added.length;
2775
+ if (remaining === 0 || remaining > PANE_STREAM_MAX_PANES)
2776
+ return this.#topologyFailed("pane count outside the stream limit");
2777
+
2778
+ // The transport's pane grant is exact. The daemon amends it from its own
2779
+ // inventory of this session before a new pane's delivery can open.
2780
+ if (added.length > 0) {
2781
+ try {
2782
+ if (!binding.amendPaneGrant)
2783
+ return this.#topologyFailed("transport cannot amend its grant");
2784
+ binding.amendPaneGrant({ added, removed: [] });
2785
+ } catch (error) {
2786
+ return this.#topologyFailed("pane grant refused", error);
2787
+ }
2788
+ }
2789
+ const channels = added.map(newPaneChannel);
2790
+ const settled = await Promise.allSettled(
2791
+ channels.map((channel) => this.#openPaneDelivery(binding, offer, channel)),
2792
+ );
2793
+ const opened = settled.flatMap((result) =>
2794
+ result.status === "fulfilled" ? [result.value] : [],
2795
+ );
2796
+ if (
2797
+ this.#closed ||
2798
+ opened.length !== channels.length ||
2799
+ opened.some((entry) => this.#deliveryIdentityChanged(entry))
2468
2800
  ) {
2469
- this.#failTopologyChanged();
2470
- return;
2801
+ await Promise.all(opened.map(({ delivery }) => delivery.close().catch(() => undefined)));
2802
+ if (added.length > 0) {
2803
+ try {
2804
+ binding.amendPaneGrant?.({ added: [], removed: added });
2805
+ } catch {
2806
+ // The stream closes; its binding and grant go with it.
2807
+ }
2808
+ }
2809
+ const rejected = settled.find((result) => result.status === "rejected");
2810
+ return this.#topologyFailed(
2811
+ this.#closed
2812
+ ? "closed while opening"
2813
+ : rejected
2814
+ ? "delivery open rejected"
2815
+ : opened.some((entry) => !entry.delivery.negotiation.accepted)
2816
+ ? "delivery negotiation refused"
2817
+ : "delivery identity changed",
2818
+ rejected?.status === "rejected" ? rejected.reason : undefined,
2819
+ );
2820
+ }
2821
+
2822
+ // Commit. From here on nothing can fail the change.
2823
+ if (removed.length > 0) {
2824
+ try {
2825
+ binding.amendPaneGrant?.({
2826
+ added: [],
2827
+ removed: removed.map((channel) => channel.semanticPaneId),
2828
+ });
2829
+ } catch {
2830
+ // A pane that is gone cannot be used through a grant that lingers.
2831
+ }
2471
2832
  }
2833
+ for (const channel of removed) this.#retirePaneInPlace(channel);
2834
+ for (const channel of channels) this.#panes.set(channel.semanticPaneId, channel);
2835
+ this.#semanticExpectedPaneIds = next;
2472
2836
  this.#semanticWindowLinks = snapshot.windowLinks;
2473
2837
  this.#semanticTopologyEpoch = snapshot.topologyEpoch;
2474
2838
  this.#semanticLayouts.clear();
2475
2839
  for (const event of snapshot.layouts)
2476
2840
  this.#semanticLayouts.set(event.semanticWindowId as string, event);
2841
+ this.#sendFrame(null, {
2842
+ type: "topology",
2843
+ topologyEpoch: snapshot.topologyEpoch,
2844
+ panes: [...this.#panes.values()]
2845
+ .filter((channel) => !channel.closed)
2846
+ .map((channel) => channel.semanticPaneId),
2847
+ removed: removed.map((channel) => channel.semanticPaneId),
2848
+ added,
2849
+ });
2477
2850
  this.#sendFrame(null, {
2478
2851
  type: "layout-snapshot",
2479
2852
  topologyEpoch: snapshot.topologyEpoch,
2480
2853
  layouts: frames,
2481
2854
  windowLinks: snapshot.windowLinks,
2482
2855
  });
2856
+ await this.#publishOpenedDeliveries(opened);
2857
+ return "applied";
2858
+ }
2859
+
2860
+ #topologyFailure = "";
2861
+ #topologyFailed(why: string, error?: unknown): "failed" {
2862
+ this.#topologyFailure = error === undefined ? why : `${why}: ${String(error).slice(0, 200)}`;
2863
+ return "failed";
2864
+ }
2865
+
2866
+ /** A pane that left the session: its delivery ends, the stream does not. */
2867
+ #retirePaneInPlace(channel: PaneChannel): void {
2868
+ const sub = channel.sub;
2869
+ const delivery = channel.delivery;
2870
+ channel.sub = null;
2871
+ channel.delivery = null;
2872
+ channel.closed = true;
2873
+ channel.retiredInPlace = true;
2874
+ // The channel stays only so late client frames for it are dropped; a long
2875
+ // stream under an agent that splits often must not keep each pane's buffers.
2876
+ channel.deliveryAddress = null;
2877
+ channel.batch = null;
2878
+ channel.graphicsQueue = [];
2879
+ channel.graphicsServed = new Map();
2880
+ channel.graphicsState = null;
2881
+ this.#surfaceDemands.get(channel.semanticPaneId)?.close();
2882
+ this.#surfaceDemands.delete(channel.semanticPaneId);
2883
+ if (sub) void sub.close().catch(() => undefined);
2884
+ if (delivery) void delivery.close().catch(() => undefined);
2885
+ this.#ledger.forgetPane(this.#clientId, channel.semanticPaneId);
2483
2886
  }
2484
2887
 
2485
2888
  #onLayout(event: MirrorLayoutEvent): void {
@@ -2507,7 +2910,15 @@ export class PaneStreamLiveConnection {
2507
2910
  }
2508
2911
 
2509
2912
  #offers(version: number): boolean {
2510
- return this.#descriptor.terminalDelivery?.protocolVersions.includes(version) === true;
2913
+ const offered = this.#descriptor.terminalDelivery?.protocolVersions;
2914
+ if (!offered) return false;
2915
+ // 120 stands for 118 and 119 together.
2916
+ return (
2917
+ offered.includes(version) ||
2918
+ ((version === PANE_STREAM_READER_CAPABILITY_VERSION ||
2919
+ version === PANE_STREAM_TOPOLOGY_IN_PLACE_CAPABILITY_VERSION) &&
2920
+ offered.includes(PANE_STREAM_READER_TOPOLOGY_BUNDLE_CAPABILITY_VERSION))
2921
+ );
2511
2922
  }
2512
2923
 
2513
2924
  #layoutFrame(event: MirrorLayoutEvent): PaneStreamServerFrame | null {
@@ -2583,8 +2994,10 @@ export class PaneStreamLiveConnection {
2583
2994
  return frames;
2584
2995
  }
2585
2996
 
2586
- #failTopologyChanged(): void {
2997
+ /** `inPlaceFailure`: why a capability-119 stream could not follow the change. */
2998
+ #failTopologyChanged(inPlaceFailure?: string): void {
2587
2999
  if (this.#closed) return;
3000
+ if (inPlaceFailure) this.#closeCause = { cause: `topology-in-place: ${inPlaceFailure}` };
2588
3001
  this.#sendFrame(null, {
2589
3002
  type: "error",
2590
3003
  protocolVersion: PANE_STREAM_PROTOCOL_VERSION,
@@ -2783,17 +3196,23 @@ export class PaneStreamLiveConnection {
2783
3196
  if (frame.type === "presence") {
2784
3197
  if (!this.#acceptAuthorityGeneration(frame.generation)) return;
2785
3198
  this.#usesExplicitAuthority = true;
2786
- if (!this.#sessionRuntimeBinding?.updatePresence) return this.#failProtocol("protocol-error");
2787
- const snapshot = this.#sessionRuntimeBinding.updatePresence(frame.state);
2788
- if (!this.#sessionRuntimeBinding.onAuthoritySnapshot) this.#sendAuthoritySnapshot(snapshot);
3199
+ const binding = this.#sessionRuntimeBinding;
3200
+ if (!binding?.updatePresence) return this.#failProtocol("protocol-error");
3201
+ this.#afterHeldFrames(() => {
3202
+ const snapshot = binding.updatePresence!(frame.state);
3203
+ if (!binding.onAuthoritySnapshot) this.#sendAuthoritySnapshot(snapshot);
3204
+ });
2789
3205
  return;
2790
3206
  }
2791
3207
  if (frame.type === "activity") {
2792
3208
  if (!this.#acceptAuthorityGeneration(frame.generation)) return;
2793
3209
  this.#usesExplicitAuthority = true;
2794
- if (!this.#sessionRuntimeBinding?.noteActivity) return this.#failProtocol("protocol-error");
2795
- const snapshot = this.#sessionRuntimeBinding.noteActivity(frame.activity);
2796
- if (!this.#sessionRuntimeBinding.onAuthoritySnapshot) this.#sendAuthoritySnapshot(snapshot);
3210
+ const binding = this.#sessionRuntimeBinding;
3211
+ if (!binding?.noteActivity) return this.#failProtocol("protocol-error");
3212
+ this.#afterHeldFrames(() => {
3213
+ const snapshot = binding.noteActivity!(frame.activity);
3214
+ if (!binding.onAuthoritySnapshot) this.#sendAuthoritySnapshot(snapshot);
3215
+ });
2797
3216
  return;
2798
3217
  }
2799
3218
  if (frame.type === "authority-request") {
@@ -2804,43 +3223,54 @@ export class PaneStreamLiveConnection {
2804
3223
  !this.#sessionRuntimeBinding.authoritySnapshot
2805
3224
  )
2806
3225
  return this.#failProtocol("protocol-error");
2807
- let lease: SessionRuntimeAuthorityLease | null = null;
2808
- try {
2809
- lease = this.#sessionRuntimeBinding.requestAuthority(frame.authority);
2810
- } catch (error) {
2811
- // Topology changes can temporarily prevent ownership. Reject this
2812
- // request without letting an expected conflict terminate the daemon.
2813
- if (
2814
- !(error instanceof SessionRuntimeControllerLeaseError) ||
2815
- error.code !== "controller-conflict"
2816
- )
2817
- return this.#failProtocol("input-rejected");
2818
- }
2819
- if (lease) this.#requestedAuthorities.add(frame.authority);
2820
- this.#sendFrame(null, {
2821
- type: "authority-receipt",
2822
- requestId: frame.requestId,
2823
- authority: frame.authority,
2824
- status: lease ? "granted" : "rejected",
2825
- lease,
2826
- snapshot: this.#sessionRuntimeBinding.authoritySnapshot(),
2827
- });
3226
+ const binding = this.#sessionRuntimeBinding;
3227
+ // While ownership is read again the request waits for it, in order with
3228
+ // input, instead of being rejected: a rejected request left a new stream
3229
+ // without input until the client gave up on it.
3230
+ const request = (): void => {
3231
+ let lease: SessionRuntimeAuthorityLease | null = null;
3232
+ try {
3233
+ lease = binding.requestAuthority!(frame.authority);
3234
+ } catch (error) {
3235
+ if (this.#holdForWindowOwnership(error, request)) return;
3236
+ // Topology changes can temporarily prevent ownership. Reject this
3237
+ // request without letting an expected conflict terminate the daemon.
3238
+ if (
3239
+ !(error instanceof SessionRuntimeControllerLeaseError) ||
3240
+ error.code !== "controller-conflict"
3241
+ )
3242
+ return this.#failProtocol("input-rejected");
3243
+ }
3244
+ if (lease) this.#requestedAuthorities.add(frame.authority);
3245
+ this.#sendFrame(null, {
3246
+ type: "authority-receipt",
3247
+ requestId: frame.requestId,
3248
+ authority: frame.authority,
3249
+ status: lease ? "granted" : "rejected",
3250
+ lease,
3251
+ snapshot: binding.authoritySnapshot!(),
3252
+ });
3253
+ };
3254
+ this.#afterWindowOwnership(request);
2828
3255
  return;
2829
3256
  }
2830
3257
  if (frame.type === "authority-release") {
2831
3258
  if (!this.#acceptAuthorityGeneration(frame.generation)) return;
2832
3259
  this.#usesExplicitAuthority = true;
2833
- this.#requestedAuthorities.delete(frame.authority);
2834
- if (!this.#sessionRuntimeBinding?.releaseAuthority)
2835
- return this.#failProtocol("protocol-error");
2836
- const snapshot = this.#sessionRuntimeBinding.releaseAuthority(frame.authority);
2837
- this.#sendFrame(null, {
2838
- type: "authority-receipt",
2839
- requestId: frame.requestId,
2840
- authority: frame.authority,
2841
- status: "released",
2842
- lease: null,
2843
- snapshot,
3260
+ const binding = this.#sessionRuntimeBinding;
3261
+ if (!binding?.releaseAuthority) return this.#failProtocol("protocol-error");
3262
+ // After any held request or input: a release must not overtake them.
3263
+ this.#afterHeldFrames(() => {
3264
+ this.#requestedAuthorities.delete(frame.authority);
3265
+ const snapshot = binding.releaseAuthority!(frame.authority);
3266
+ this.#sendFrame(null, {
3267
+ type: "authority-receipt",
3268
+ requestId: frame.requestId,
3269
+ authority: frame.authority,
3270
+ status: "released",
3271
+ lease: null,
3272
+ snapshot,
3273
+ });
2844
3274
  });
2845
3275
  return;
2846
3276
  }
@@ -2883,7 +3313,7 @@ export class PaneStreamLiveConnection {
2883
3313
  return;
2884
3314
  }
2885
3315
  if (frame.type === "semantic-intent") {
2886
- this.#acceptSemanticIntent(frame.operationId, frame.intent);
3316
+ this.#afterHeldFrames(() => this.#acceptSemanticIntent(frame.operationId, frame.intent));
2887
3317
  return;
2888
3318
  }
2889
3319
  if (frame.type === "terminal-surface-watch") {
@@ -3065,41 +3495,45 @@ export class PaneStreamLiveConnection {
3065
3495
  }
3066
3496
  if (!this.#prepareInputAuthority(true)) return;
3067
3497
  this.#nextViewportSeq += 1;
3068
- try {
3069
- if (frame.semanticWindowId === undefined)
3070
- this.#sessionRuntimeBinding!.fitViewport(frame.authorityLease, frame.cols, frame.rows);
3071
- else
3072
- this.#sessionRuntimeBinding!.fitViewport(
3073
- frame.authorityLease,
3074
- frame.cols,
3075
- frame.rows,
3076
- frame.semanticWindowId,
3077
- );
3078
- this.#sendFrame(null, {
3079
- type: "viewport-ack",
3080
- seq: frame.seq,
3081
- cols: frame.cols,
3082
- rows: frame.rows,
3083
- outcome: "ok",
3084
- authorityLease: frame.authorityLease,
3085
- });
3086
- } catch (error) {
3087
- if (
3088
- error instanceof SessionRuntimeControllerLeaseError &&
3089
- (error.code === "invalid-client-capability" || error.code === "stale-controller-lease")
3090
- ) {
3498
+ const fit = (): void => {
3499
+ try {
3500
+ if (frame.semanticWindowId === undefined)
3501
+ this.#sessionRuntimeBinding!.fitViewport(frame.authorityLease, frame.cols, frame.rows);
3502
+ else
3503
+ this.#sessionRuntimeBinding!.fitViewport(
3504
+ frame.authorityLease,
3505
+ frame.cols,
3506
+ frame.rows,
3507
+ frame.semanticWindowId,
3508
+ );
3091
3509
  this.#sendFrame(null, {
3092
3510
  type: "viewport-ack",
3093
3511
  seq: frame.seq,
3094
3512
  cols: frame.cols,
3095
3513
  rows: frame.rows,
3096
- outcome: "geometry-authority-conflict",
3514
+ outcome: "ok",
3097
3515
  authorityLease: frame.authorityLease,
3098
3516
  });
3099
- return;
3517
+ } catch (error) {
3518
+ if (
3519
+ error instanceof SessionRuntimeControllerLeaseError &&
3520
+ (error.code === "invalid-client-capability" || error.code === "stale-controller-lease")
3521
+ ) {
3522
+ this.#sendFrame(null, {
3523
+ type: "viewport-ack",
3524
+ seq: frame.seq,
3525
+ cols: frame.cols,
3526
+ rows: frame.rows,
3527
+ outcome: "geometry-authority-conflict",
3528
+ authorityLease: frame.authorityLease,
3529
+ });
3530
+ return;
3531
+ }
3532
+ if (this.#holdForWindowOwnership(error, fit)) return;
3533
+ this.#failProtocol("input-rejected");
3100
3534
  }
3101
- this.#failProtocol("input-rejected");
3102
- }
3535
+ };
3536
+ this.#afterWindowOwnership(fit);
3103
3537
  return;
3104
3538
  }
3105
3539
  this.#acceptInput(
@@ -3177,6 +3611,7 @@ export class PaneStreamLiveConnection {
3177
3611
  deliveryNonce: string;
3178
3612
  }): PaneChannel | null {
3179
3613
  const channel = this.#panes.get(address.semanticPaneId);
3614
+ if (channel?.retiredInPlace) return null;
3180
3615
  const expected = channel?.deliveryAddress;
3181
3616
  if (
3182
3617
  !channel?.delivery ||
@@ -3238,6 +3673,14 @@ export class PaneStreamLiveConnection {
3238
3673
  ].includes(rawCode)
3239
3674
  ? rawCode
3240
3675
  : "stream-unavailable";
3676
+ // A refused intent is answered to the client only; without this line a
3677
+ // click that did nothing leaves no trace in either log (#764).
3678
+ logger.info("pane-stream", "intent rejected", {
3679
+ session: this.#descriptor.sessionName,
3680
+ clientId: this.#clientId,
3681
+ verb: intent.verb,
3682
+ code,
3683
+ });
3241
3684
  this.#sendFrame(null, {
3242
3685
  type: "semantic-intent-ack",
3243
3686
  operationId,
@@ -3257,6 +3700,7 @@ export class PaneStreamLiveConnection {
3257
3700
 
3258
3701
  #acceptConsumed(pane: string, seq: number): void {
3259
3702
  const channel = this.#panes.get(pane);
3703
+ if (channel?.retiredInPlace) return;
3260
3704
  if (
3261
3705
  !this.#deliveryAcks ||
3262
3706
  !channel ||
@@ -3310,6 +3754,7 @@ export class PaneStreamLiveConnection {
3310
3754
  return;
3311
3755
  }
3312
3756
  const channel = this.#panes.get(pane);
3757
+ if (channel?.retiredInPlace) return;
3313
3758
  const semanticDelivery = this.#descriptor.terminalDelivery !== null;
3314
3759
  if (
3315
3760
  !channel ||
@@ -3397,93 +3842,223 @@ export class PaneStreamLiveConnection {
3397
3842
  this.#inputWindowFrames += 1;
3398
3843
  this.#inputWindowBytes += frameBytes;
3399
3844
  channel.nextInputSeq += 1;
3400
- try {
3401
- this.#sessionRuntimeBinding!.assertController(pane);
3402
- if (semanticDelivery)
3403
- this.#sessionRuntimeBinding!.sendInput(
3404
- pane,
3405
- { kind, data },
3406
- performanceTraceId,
3407
- causalProbe,
3408
- causalProbe
3409
- ? (result) => {
3410
- if (this.#closed) return;
3411
- if (result.status === "proved") {
3412
- this.#sendFrame(null, { type: "causal-cell-proof", proof: result.proof });
3413
- } else {
3414
- this.#sendFrame(null, {
3415
- type: "causal-cell-failure",
3416
- failure: {
3417
- version: 1,
3418
- capability: "causal-cell-v1",
3419
- traceId: result.traceId,
3420
- reason: result.reason,
3421
- ...(result.diagnostic ? { diagnostic: result.diagnostic } : {}),
3422
- },
3423
- });
3845
+ const deliver = (): void => {
3846
+ // Held for an ownership read (#394) while the pane left the stream in
3847
+ // place: dropped like any other late frame for it, not delivered.
3848
+ if (channel.retiredInPlace) return;
3849
+ try {
3850
+ this.#sessionRuntimeBinding!.assertController(pane);
3851
+ if (semanticDelivery)
3852
+ this.#sessionRuntimeBinding!.sendInput(
3853
+ pane,
3854
+ { kind, data },
3855
+ performanceTraceId,
3856
+ causalProbe,
3857
+ causalProbe
3858
+ ? (result) => {
3859
+ if (this.#closed) return;
3860
+ if (result.status === "proved") {
3861
+ this.#sendFrame(null, { type: "causal-cell-proof", proof: result.proof });
3862
+ } else {
3863
+ this.#sendFrame(null, {
3864
+ type: "causal-cell-failure",
3865
+ failure: {
3866
+ version: 1,
3867
+ capability: "causal-cell-v1",
3868
+ traceId: result.traceId,
3869
+ reason: result.reason,
3870
+ ...(result.diagnostic ? { diagnostic: result.diagnostic } : {}),
3871
+ },
3872
+ });
3873
+ }
3424
3874
  }
3425
- }
3426
- : undefined,
3427
- expectedLifetime,
3428
- );
3429
- else if (kind === "text") channel.sub!.sendText(data);
3430
- else if (kind === "key") channel.sub!.sendKey(data);
3431
- else throw new Error("Byte input requires semantic runtime");
3432
- let ackStartedAtMicros: number | null = null;
3433
- let ackStartedAtSharedMicros: number | null = null;
3434
- if (trace) {
3435
- try {
3436
- ackStartedAtMicros = this.#observability!.nowMicros();
3437
- } catch {
3438
- // Diagnostics cannot alter protocol truth.
3439
- }
3440
- if (this.#diagnosticSharedRawMicros) {
3875
+ : undefined,
3876
+ expectedLifetime,
3877
+ );
3878
+ else if (kind === "text") channel.sub!.sendText(data);
3879
+ else if (kind === "key") channel.sub!.sendKey(data);
3880
+ else throw new Error("Byte input requires semantic runtime");
3881
+ let ackStartedAtMicros: number | null = null;
3882
+ let ackStartedAtSharedMicros: number | null = null;
3883
+ if (trace) {
3441
3884
  try {
3442
- ackStartedAtSharedMicros = this.#sharedMicros();
3885
+ ackStartedAtMicros = this.#observability!.nowMicros();
3443
3886
  } catch {
3444
- // Preserve process-local ACK diagnostics.
3887
+ // Diagnostics cannot alter protocol truth.
3445
3888
  }
3446
- }
3447
- }
3448
- sendControl(this.#socket, { type: "input-ack", pane, seq });
3449
- if (trace && ackStartedAtMicros !== null) {
3450
- let ackEndedAtMicros: number | null = null;
3451
- try {
3452
- ackEndedAtMicros = this.#observability!.nowMicros();
3453
- } catch {
3454
- // Diagnostics cannot alter protocol truth.
3455
- }
3456
- let ackEndedAtSharedMicros: number | null = null;
3457
- if (ackStartedAtSharedMicros !== null) {
3458
- try {
3459
- ackEndedAtSharedMicros = this.#sharedMicros();
3460
- } catch {
3461
- // Preserve process-local ACK diagnostics.
3889
+ if (this.#diagnosticSharedRawMicros) {
3890
+ try {
3891
+ ackStartedAtSharedMicros = this.#sharedMicros();
3892
+ } catch {
3893
+ // Preserve process-local ACK diagnostics.
3894
+ }
3462
3895
  }
3463
3896
  }
3464
- if (ackEndedAtMicros !== null) {
3897
+ sendControl(this.#socket, { type: "input-ack", pane, seq });
3898
+ if (trace && ackStartedAtMicros !== null) {
3899
+ let ackEndedAtMicros: number | null = null;
3465
3900
  try {
3466
- this.#observability!.recordSpan(
3467
- "transport",
3468
- "pane-stream-input-ack-socket-send",
3469
- ackStartedAtMicros,
3470
- ackEndedAtMicros,
3471
- trace,
3472
- ackStartedAtSharedMicros === null || ackEndedAtSharedMicros === null
3473
- ? undefined
3474
- : {
3475
- startedAtMicros: ackStartedAtSharedMicros,
3476
- endedAtMicros: ackEndedAtSharedMicros,
3477
- },
3478
- );
3901
+ ackEndedAtMicros = this.#observability!.nowMicros();
3479
3902
  } catch {
3480
3903
  // Diagnostics cannot alter protocol truth.
3481
3904
  }
3905
+ let ackEndedAtSharedMicros: number | null = null;
3906
+ if (ackStartedAtSharedMicros !== null) {
3907
+ try {
3908
+ ackEndedAtSharedMicros = this.#sharedMicros();
3909
+ } catch {
3910
+ // Preserve process-local ACK diagnostics.
3911
+ }
3912
+ }
3913
+ if (ackEndedAtMicros !== null) {
3914
+ try {
3915
+ this.#observability!.recordSpan(
3916
+ "transport",
3917
+ "pane-stream-input-ack-socket-send",
3918
+ ackStartedAtMicros,
3919
+ ackEndedAtMicros,
3920
+ trace,
3921
+ ackStartedAtSharedMicros === null || ackEndedAtSharedMicros === null
3922
+ ? undefined
3923
+ : {
3924
+ startedAtMicros: ackStartedAtSharedMicros,
3925
+ endedAtMicros: ackEndedAtSharedMicros,
3926
+ },
3927
+ );
3928
+ } catch {
3929
+ // Diagnostics cannot alter protocol truth.
3930
+ }
3931
+ }
3482
3932
  }
3933
+ } catch (error) {
3934
+ if (this.#holdForWindowOwnership(error, deliver)) return;
3935
+ if (error instanceof SessionRuntimeInputLifetimeEndedError) {
3936
+ // Fenced to a lifetime that ended: not delivered, not acknowledged.
3937
+ // The pane's delivery tells the client its lifetime ended.
3938
+ this.#noteInputLifetimeEnded(pane, error);
3939
+ return;
3940
+ }
3941
+ this.#fail("control-frame-handler-failed", error);
3483
3942
  }
3484
- } catch (error) {
3485
- this.#fail("control-frame-handler-failed", error);
3943
+ };
3944
+ this.#afterWindowOwnership(deliver);
3945
+ }
3946
+
3947
+ /**
3948
+ * Input and geometry frames that arrive while registered-window ownership is
3949
+ * being read again (another session was created or killed) wait for that
3950
+ * read, in arrival order, instead of closing the stream. The mirror refuses
3951
+ * them meanwhile; before, the stream closed with 1011 and the client had to
3952
+ * reconnect. Bounded: a read that does not settle in time closes as before.
3953
+ */
3954
+ #ownershipHeld: (() => void)[] = [];
3955
+ #ownershipDraining = false;
3956
+ /** Ends the drain's wait when the stream closes. */
3957
+ #ownershipWake: (() => void) | null = null;
3958
+
3959
+ #afterWindowOwnership(run: () => void): void {
3960
+ if (this.#ownershipHeld.length === 0 && !this.#mirror.windowOwnershipPending?.()) {
3961
+ run();
3962
+ return;
3486
3963
  }
3964
+ this.#holdUntilWindowOwnership(run);
3965
+ }
3966
+
3967
+ /**
3968
+ * Frames whose effect depends on authority order (release, presence,
3969
+ * activity, intents) are not held for the read themselves, but must not
3970
+ * overtake frames that are.
3971
+ */
3972
+ #afterHeldFrames(run: () => void): void {
3973
+ if (this.#ownershipHeld.length === 0) {
3974
+ run();
3975
+ return;
3976
+ }
3977
+ this.#holdUntilWindowOwnership(run);
3978
+ }
3979
+
3980
+ /** A refusal while ownership is pending holds the frame; anything else is the caller's. */
3981
+ #holdForWindowOwnership(error: unknown, run: () => void): boolean {
3982
+ if (
3983
+ !(error instanceof SessionRuntimeControllerLeaseError) ||
3984
+ error.code !== "controller-conflict" ||
3985
+ !this.#mirror.windowOwnershipPending?.()
3986
+ )
3987
+ return false;
3988
+ this.#ownershipHeld.unshift(run);
3989
+ if (!this.#ownershipDraining) void this.#drainWindowOwnership();
3990
+ return true;
3991
+ }
3992
+
3993
+ #holdUntilWindowOwnership(run: () => void): void {
3994
+ if (this.#ownershipHeld.length >= PANE_STREAM_OWNERSHIP_HELD_FRAMES) {
3995
+ this.#ownershipHeld.length = 0;
3996
+ this.#fail("window-ownership-held-overflow");
3997
+ return;
3998
+ }
3999
+ this.#ownershipHeld.push(run);
4000
+ if (!this.#ownershipDraining) void this.#drainWindowOwnership();
4001
+ }
4002
+
4003
+ async #drainWindowOwnership(): Promise<void> {
4004
+ this.#ownershipDraining = true;
4005
+ try {
4006
+ await this.#drainWindowOwnershipOnce();
4007
+ } finally {
4008
+ this.#ownershipDraining = false;
4009
+ }
4010
+ }
4011
+
4012
+ async #drainWindowOwnershipOnce(): Promise<void> {
4013
+ const deadline = Date.now() + this.#ownershipWaitMs;
4014
+ while (!this.#closed && this.#ownershipHeld.length > 0) {
4015
+ if (this.#mirror.windowOwnershipPending?.()) {
4016
+ const left = deadline - Date.now();
4017
+ if (left <= 0) {
4018
+ this.#ownershipHeld.length = 0;
4019
+ this.#fail("window-ownership-unverified");
4020
+ return;
4021
+ }
4022
+ const timers: ReturnType<typeof setTimeout>[] = [];
4023
+ const wait = (ms: number) =>
4024
+ new Promise<void>((resolve) => {
4025
+ const timer = setTimeout(resolve, ms);
4026
+ timer.unref?.();
4027
+ timers.push(timer);
4028
+ });
4029
+ const read = this.#mirror.verifyWindowOwnership?.();
4030
+ await Promise.race([
4031
+ // Without a read to wait on, poll instead of spinning.
4032
+ read ? read.catch(() => wait(25)) : wait(25),
4033
+ wait(left),
4034
+ new Promise<void>((resolve) => {
4035
+ this.#ownershipWake = resolve;
4036
+ }),
4037
+ ]);
4038
+ this.#ownershipWake = null;
4039
+ for (const timer of timers) clearTimeout(timer);
4040
+ continue;
4041
+ }
4042
+ const run = this.#ownershipHeld.shift()!;
4043
+ const before = this.#ownershipHeld.length;
4044
+ run();
4045
+ // A refusal inside run() put it back at the front: wait again.
4046
+ if (this.#ownershipHeld.length > before) continue;
4047
+ }
4048
+ }
4049
+
4050
+ #inputLifetimeEndedLogged = new Set<string>();
4051
+ #inputLifetimeEndedDropped = 0;
4052
+ #noteInputLifetimeEnded(pane: string, error: Error): void {
4053
+ this.#inputLifetimeEndedDropped += 1;
4054
+ if (this.#inputLifetimeEndedLogged.has(pane)) return;
4055
+ this.#inputLifetimeEndedLogged.add(pane);
4056
+ logger.info("pane-stream", "input for an ended pane lifetime not delivered", {
4057
+ session: this.#descriptor.sessionName,
4058
+ clientId: this.#clientId,
4059
+ pane,
4060
+ error: error.message.slice(0, 200),
4061
+ });
3487
4062
  }
3488
4063
 
3489
4064
  #failProtocol(code: PaneStreamErrorFrameCode): void {
@@ -3512,6 +4087,27 @@ export class PaneStreamLiveConnection {
3512
4087
  readonly #onSocketClose = (): void => this.close(1000, "peer-closed");
3513
4088
  }
3514
4089
 
4090
+ function newPaneChannel(pane: string): PaneChannel {
4091
+ return {
4092
+ semanticPaneId: pane,
4093
+ sub: null,
4094
+ delivery: null,
4095
+ deliveryAddress: null,
4096
+ serverSeq: 0,
4097
+ sentPaneFrames: 0,
4098
+ consumedSeq: 0,
4099
+ nextInputSeq: 1,
4100
+ frozenByWire: false,
4101
+ closed: false,
4102
+ batch: null,
4103
+ graphicsAnnounced: false,
4104
+ graphicsQueue: [],
4105
+ graphicsSending: false,
4106
+ graphicsServed: new Map(),
4107
+ graphicsState: null,
4108
+ };
4109
+ }
4110
+
3515
4111
  function concatBytes(chunks: readonly Uint8Array[]): Uint8Array {
3516
4112
  if (chunks.length === 0) return new Uint8Array(0);
3517
4113
  if (chunks.length === 1) return chunks[0]!;