tmux-ide 2.9.22 → 2.9.23
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/bin/cli.js +3434 -7568
- package/package.json +3 -3
- package/packages/contracts/src/index.ts +1 -0
- package/packages/contracts/src/websocket-heartbeat.ts +41 -0
- package/packages/daemon/dist/command-center/automation.js +1 -1
- package/packages/daemon/dist/command-center/daemon-fleet-facts-observer.js +37 -5
- package/packages/daemon/dist/command-center/discovery.js +28 -2
- package/packages/daemon/dist/command-center/server.js +8 -2
- package/packages/daemon/dist/command-center/tmux-servers.js +1 -1
- package/packages/daemon/dist/doctor.js +41 -0
- package/packages/daemon/dist/lib/bounded-tmux-read.js +34 -12
- package/packages/daemon/dist/lib/daemon-embed.js +111 -55
- package/packages/daemon/dist/lib/daemon-stop-progress.js +58 -0
- package/packages/daemon/dist/lib/embedded-daemon-lifecycle.js +11 -0
- package/packages/daemon/dist/lib/embedded-tmux-server-owners.js +88 -12
- package/packages/daemon/dist/lib/headless-daemon.js +177 -10
- package/packages/daemon/dist/lib/log.js +18 -1
- package/packages/daemon/dist/lib/tmux-external-interaction-observer.js +140 -19
- package/packages/daemon/dist/lib/tmux-native-browser.js +4 -2
- package/packages/daemon/dist/lib/tmux-pane-reader.js +4 -2
- package/packages/daemon/dist/lib/tmux-server-agent-admission.js +6 -1
- package/packages/daemon/dist/lib/tmux-server-owner-teardown.js +33 -0
- package/packages/daemon/dist/lib/tmux-server-owner.js +29 -37
- package/packages/daemon/dist/lib/tmux-server-owners.js +310 -20
- package/packages/daemon/dist/lib/tmux-server-registration.js +128 -9
- package/packages/daemon/dist/lib/unix-socket-authority.js +58 -3
- package/packages/daemon/dist/lib/workspace-pane-creation.js +10 -1
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
- package/packages/daemon/dist/plugins/cli.js +1 -2
- package/packages/daemon/dist/server/pane-stream-upgrade.js +5 -1
- package/packages/daemon/dist/server/websocket-heartbeat.js +103 -0
- package/packages/daemon/dist/terminal/attachments/native-runtime.js +32 -14
- package/packages/daemon/dist/terminal/mirror/layout-content-rows.js +11 -0
- package/packages/daemon/dist/terminal/mirror/mirror-service.js +61 -3
- package/packages/daemon/dist/terminal/mirror/session-channel.js +9 -11
- package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +111 -22
- package/packages/daemon/dist/terminal/pane-stream/runtime.js +3 -2
- package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +23 -0
- package/packages/daemon/dist/terminal/protocol/stock-split-resize.js +4 -1
- package/packages/daemon/dist/terminal/session-runtime/registry.js +17 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +81 -3
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +60 -3
- package/packages/daemon/src/command-center/automation.ts +1 -1
- package/packages/daemon/src/command-center/daemon-fleet-facts-observer.ts +49 -8
- package/packages/daemon/src/command-center/discovery.ts +35 -2
- package/packages/daemon/src/command-center/server.ts +22 -8
- package/packages/daemon/src/command-center/tmux-servers.ts +1 -1
- package/packages/daemon/src/doctor.ts +46 -0
- package/packages/daemon/src/lib/bounded-tmux-read.ts +29 -9
- package/packages/daemon/src/lib/daemon-embed.ts +159 -64
- package/packages/daemon/src/lib/daemon-stop-progress.ts +78 -0
- package/packages/daemon/src/lib/embedded-daemon-lifecycle.ts +12 -0
- package/packages/daemon/src/lib/embedded-tmux-server-owners.ts +115 -11
- package/packages/daemon/src/lib/headless-daemon.ts +205 -12
- package/packages/daemon/src/lib/log.ts +18 -1
- package/packages/daemon/src/lib/tmux-external-interaction-observer.ts +163 -25
- package/packages/daemon/src/lib/tmux-native-browser.ts +4 -3
- package/packages/daemon/src/lib/tmux-pane-reader.ts +4 -3
- package/packages/daemon/src/lib/tmux-server-agent-admission.ts +6 -1
- package/packages/daemon/src/lib/tmux-server-owner-teardown.ts +54 -0
- package/packages/daemon/src/lib/tmux-server-owner.ts +32 -35
- package/packages/daemon/src/lib/tmux-server-owners.ts +427 -22
- package/packages/daemon/src/lib/tmux-server-registration.ts +155 -7
- package/packages/daemon/src/lib/unix-socket-authority.ts +72 -3
- package/packages/daemon/src/lib/workspace-pane-creation.ts +11 -1
- package/packages/daemon/src/plugins/cli.ts +1 -2
- package/packages/daemon/src/server/pane-stream-upgrade.ts +6 -0
- package/packages/daemon/src/server/websocket-heartbeat.ts +135 -0
- package/packages/daemon/src/terminal/attachments/native-runtime.ts +58 -14
- package/packages/daemon/src/terminal/mirror/layout-content-rows.ts +11 -0
- package/packages/daemon/src/terminal/mirror/mirror-service.ts +61 -2
- package/packages/daemon/src/terminal/mirror/session-channel.ts +9 -13
- package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +125 -21
- package/packages/daemon/src/terminal/pane-stream/runtime.ts +4 -2
- package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +31 -0
- package/packages/daemon/src/terminal/protocol/stock-split-resize.ts +6 -1
- package/packages/daemon/src/terminal/session-runtime/registry.ts +23 -0
- package/packages/daemon/src/terminal/session-runtime/runtime-observability.ts +2 -0
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +100 -3
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +60 -3
- package/packages/daemon-client/src/direct-application-shell-transport.ts +21 -3
- package/packages/daemon-client/src/workspace-event-supervisor.ts +63 -2
|
@@ -37,6 +37,12 @@ import {
|
|
|
37
37
|
} from "./tmux-server-generation-runner.ts";
|
|
38
38
|
import { createNativeTmuxServerCatalog } from "./tmux-server-owner.ts";
|
|
39
39
|
import { createEmbeddedTmuxServerOwners } from "./embedded-tmux-server-owners.ts";
|
|
40
|
+
import type { TmuxServerOwnerRetirement } from "./tmux-server-owners.ts";
|
|
41
|
+
import {
|
|
42
|
+
PANE_STREAM_DAEMON_RESTARTING_CLOSE,
|
|
43
|
+
paneStreamCloseForRetirement,
|
|
44
|
+
type PaneStreamShutdownClose,
|
|
45
|
+
} from "../terminal/pane-stream/pane-stream-websocket.ts";
|
|
40
46
|
import {
|
|
41
47
|
captureTmuxServerProofAsync,
|
|
42
48
|
captureTmuxServerProof,
|
|
@@ -94,6 +100,7 @@ import { handlePtyWebSocket, shutdownPtyBridges } from "../server/ws-route.ts";
|
|
|
94
100
|
import {
|
|
95
101
|
broadcastInteractionReceipt,
|
|
96
102
|
broadcastResourceChanged,
|
|
103
|
+
broadcastTerminalsChanged,
|
|
97
104
|
handleWsEventsConnection,
|
|
98
105
|
setFleetFactsObserverDiagnostics,
|
|
99
106
|
setFleetFactsTmuxRunner,
|
|
@@ -120,7 +127,7 @@ import {
|
|
|
120
127
|
WorkspacePaneCreationAuthority,
|
|
121
128
|
} from "./workspace-pane-creation.ts";
|
|
122
129
|
import {
|
|
123
|
-
|
|
130
|
+
readLiveSessionSummaries,
|
|
124
131
|
readAdoptedFleet,
|
|
125
132
|
type FleetSessionFacts,
|
|
126
133
|
} from "../command-center/discovery.ts";
|
|
@@ -154,6 +161,7 @@ import {
|
|
|
154
161
|
attachPaneStreamWebSocket,
|
|
155
162
|
type PaneStreamWebSocketBoundary,
|
|
156
163
|
} from "../server/pane-stream-upgrade.ts";
|
|
164
|
+
import { daemonWebSocketHeartbeat } from "../server/websocket-heartbeat.ts";
|
|
157
165
|
import {
|
|
158
166
|
createPaneStreamRuntime,
|
|
159
167
|
type PaneStreamRuntime,
|
|
@@ -168,7 +176,9 @@ import {
|
|
|
168
176
|
import { setActivationBackend, type ProjectActivationOptions } from "./active-projects.ts";
|
|
169
177
|
import { readOrMintEnvironmentId } from "./environment-identity.ts";
|
|
170
178
|
import { captureDaemonProvenance } from "./daemon-provenance.ts";
|
|
171
|
-
import { registerLogSecret, setLogIdentity } from "./log.ts";
|
|
179
|
+
import { logger, registerLogSecret, setLogIdentity } from "./log.ts";
|
|
180
|
+
import { createStopProgress, type DaemonStopProgress } from "./daemon-stop-progress.ts";
|
|
181
|
+
export type { DaemonStopProgress } from "./daemon-stop-progress.ts";
|
|
172
182
|
import { createDaemonPluginSupervisor, pluginsEnabled } from "../plugins/daemon-plugins.ts";
|
|
173
183
|
import type { PluginSupervisor } from "../plugins/supervisor.ts";
|
|
174
184
|
import {
|
|
@@ -276,7 +286,15 @@ export interface EmbeddedDaemonHandle {
|
|
|
276
286
|
projectName: string,
|
|
277
287
|
options?: ProjectActivationOptions,
|
|
278
288
|
): Promise<{ stop: () => Promise<void> }>;
|
|
279
|
-
|
|
289
|
+
/** `restarting`: a new generation follows in this process; streams are told to reconnect. */
|
|
290
|
+
stop(opts?: { gracefulMs?: number; restarting?: boolean }): Promise<void>;
|
|
291
|
+
/** Where a stop is right now; lets a deadline say what was still open (#839). */
|
|
292
|
+
stopDiagnostics?(): DaemonStopProgress;
|
|
293
|
+
/**
|
|
294
|
+
* Last resort for a stop that will not finish: synchronously withdraw
|
|
295
|
+
* daemon.json and the startup claim so the forced exit leaves no stale owner.
|
|
296
|
+
*/
|
|
297
|
+
abandon?(): void;
|
|
280
298
|
}
|
|
281
299
|
|
|
282
300
|
function tmux(...args: string[]): string {
|
|
@@ -459,6 +477,8 @@ function attachWebSockets(
|
|
|
459
477
|
closeServers: () => Promise<void>;
|
|
460
478
|
} {
|
|
461
479
|
const eventsWss = new WebSocketServer({ noServer: true });
|
|
480
|
+
const heartbeat = daemonWebSocketHeartbeat();
|
|
481
|
+
eventsWss.on("headers", (headers) => heartbeat.advertise(headers));
|
|
462
482
|
const ptyWss = new WebSocketServer({ noServer: true });
|
|
463
483
|
const clients = new Set<WebSocket>();
|
|
464
484
|
|
|
@@ -485,6 +505,7 @@ function attachWebSockets(
|
|
|
485
505
|
if (pathname === "/ws/events") {
|
|
486
506
|
eventsWss.handleUpgrade(req, socket, head, (ws) => {
|
|
487
507
|
track(ws);
|
|
508
|
+
heartbeat.watch(ws, "ws-events");
|
|
488
509
|
const requestUrl = new URL(req.url ?? "/ws/events", "http://daemon.local");
|
|
489
510
|
handleWsEventsConnection(ws, opts.daemonIdentity, {
|
|
490
511
|
mode: requestUrl.searchParams.get("mode") === "semantic" ? "semantic" : "legacy",
|
|
@@ -874,11 +895,13 @@ async function startHttpServer({
|
|
|
874
895
|
getTerminalAttachmentRuntime: () => NativeTerminalAttachmentRuntime;
|
|
875
896
|
peekTerminalAttachmentRuntime: () => NativeTerminalAttachmentRuntime | null;
|
|
876
897
|
paneStreamRuntime: PaneStreamRuntime;
|
|
877
|
-
catalogLiveSessions: () =>
|
|
878
|
-
readonly
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
898
|
+
catalogLiveSessions: () =>
|
|
899
|
+
| readonly {
|
|
900
|
+
readonly liveSessionId: `live-session.${string}`;
|
|
901
|
+
readonly sessionName: string;
|
|
902
|
+
readonly paneCount: number;
|
|
903
|
+
}[]
|
|
904
|
+
| null;
|
|
882
905
|
catalogFleet: () =>
|
|
883
906
|
| ReturnType<typeof readAdoptedFleet>
|
|
884
907
|
| Promise<ReturnType<typeof readAdoptedFleet>>;
|
|
@@ -1440,6 +1463,8 @@ async function startEmbeddedDaemonGeneration(
|
|
|
1440
1463
|
};
|
|
1441
1464
|
let terminalAttachmentRuntime: NativeTerminalAttachmentRuntime | null = null;
|
|
1442
1465
|
let paneStreamRuntime: PaneStreamRuntime | null = null;
|
|
1466
|
+
// Declared before the owners so their teardown steps can report into it.
|
|
1467
|
+
const stopProgress = createStopProgress();
|
|
1443
1468
|
let localImages: LocalImageOwner | undefined;
|
|
1444
1469
|
let serverOwners: Awaited<ReturnType<typeof createEmbeddedTmuxServerOwners>> | null = null;
|
|
1445
1470
|
let defaultEditorContextRetired = false;
|
|
@@ -1555,6 +1580,9 @@ async function startEmbeddedDaemonGeneration(
|
|
|
1555
1580
|
{ processId: `daemon:${process.pid}`, daemonInstanceId: instanceId },
|
|
1556
1581
|
)
|
|
1557
1582
|
: null;
|
|
1583
|
+
let windowOwnershipDiagnostic:
|
|
1584
|
+
| ((phase: string, details?: Record<string, unknown>) => void)
|
|
1585
|
+
| undefined;
|
|
1558
1586
|
const runtimeObservability = runtimeTracePath
|
|
1559
1587
|
? createSessionRuntimeObservability({
|
|
1560
1588
|
// The JSONL stream is the qualifying record. Keep only a small
|
|
@@ -1587,11 +1615,20 @@ async function startEmbeddedDaemonGeneration(
|
|
|
1587
1615
|
};
|
|
1588
1616
|
externalInteractionObserver.setDiagnostics(diagnostics);
|
|
1589
1617
|
setFleetFactsObserverDiagnostics(diagnostics);
|
|
1618
|
+
windowOwnershipDiagnostic = (phase, details = {}) =>
|
|
1619
|
+
publishObserverDiagnostic({
|
|
1620
|
+
operation: "window-ownership",
|
|
1621
|
+
phase,
|
|
1622
|
+
atMicros: Math.floor(performance.now() * 1_000),
|
|
1623
|
+
...details,
|
|
1624
|
+
});
|
|
1590
1625
|
}
|
|
1591
1626
|
const nativeSurfaces =
|
|
1592
1627
|
process.platform === "darwin" ? new NativeSurfaceProviderRegistry(instanceId) : undefined;
|
|
1593
1628
|
sessionRuntimeRegistry = new SessionRuntimeRegistry({
|
|
1594
1629
|
generation: instanceId,
|
|
1630
|
+
// An idle client that met the 503 re-reads when the inventory is trusted again.
|
|
1631
|
+
onInventoryRecovered: (session) => broadcastTerminalsChanged(session),
|
|
1595
1632
|
...(runtimeObservability ? { observability: runtimeObservability } : {}),
|
|
1596
1633
|
semanticMutations: {
|
|
1597
1634
|
captureInteractionContext: (intent) => {
|
|
@@ -1625,6 +1662,10 @@ async function startEmbeddedDaemonGeneration(
|
|
|
1625
1662
|
publishResourceChange: (change) => broadcastResourceChanged(change, instanceId),
|
|
1626
1663
|
},
|
|
1627
1664
|
mirror: {
|
|
1665
|
+
// #764 diagnostics (draft only): the window-ownership guard.
|
|
1666
|
+
...(windowOwnershipDiagnostic
|
|
1667
|
+
? { onWindowOwnershipDiagnostic: windowOwnershipDiagnostic }
|
|
1668
|
+
: {}),
|
|
1628
1669
|
onNativeClientPresence: (session, present) =>
|
|
1629
1670
|
nativeSurfaces?.demand.presence(session, present),
|
|
1630
1671
|
splitLayoutEpoch: () => observationSelector?.nativeServerEpoch ?? null,
|
|
@@ -1858,6 +1899,16 @@ async function startEmbeddedDaemonGeneration(
|
|
|
1858
1899
|
});
|
|
1859
1900
|
await externalInteractionObserver.start();
|
|
1860
1901
|
serverOwners = await createEmbeddedTmuxServerOwners({
|
|
1902
|
+
trackTeardown: stopProgress.track,
|
|
1903
|
+
// The background sweep, not a client's request, now notices a server
|
|
1904
|
+
// that came back or was replaced; subscribed clients must hear of it.
|
|
1905
|
+
onServersChanged: () => {
|
|
1906
|
+
broadcastResourceChanged({ workspaceName: null, resource: "fleet-catalog" }, instanceId);
|
|
1907
|
+
broadcastResourceChanged(
|
|
1908
|
+
{ workspaceName: null, resource: "workspace-catalog" },
|
|
1909
|
+
instanceId,
|
|
1910
|
+
);
|
|
1911
|
+
},
|
|
1861
1912
|
localImages,
|
|
1862
1913
|
environmentId,
|
|
1863
1914
|
onDefaultScope: async (scope) => {
|
|
@@ -2085,33 +2136,38 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2085
2136
|
sessionRuntimeRegistry,
|
|
2086
2137
|
terminalInventoryRuntime,
|
|
2087
2138
|
paneStreamRuntime,
|
|
2088
|
-
dispose: async () => {
|
|
2139
|
+
dispose: async (retirement?: TmuxServerOwnerRetirement) => {
|
|
2089
2140
|
defaultEditorContextRetired = true;
|
|
2090
2141
|
defaultDiagnosticsLifetime.abort();
|
|
2091
2142
|
sessionMonitor?.stop();
|
|
2092
2143
|
paneSourceCredentials.dispose();
|
|
2144
|
+
// Named steps: a hung stop then reports which of these never settled (#839).
|
|
2145
|
+
const step = <T>(name: string, work: () => T | Promise<T>): Promise<T> =>
|
|
2146
|
+
stopProgress.track(`default-owner:${name}`, work);
|
|
2093
2147
|
const transportResults = await Promise.allSettled([
|
|
2094
|
-
|
|
2095
|
-
|
|
2148
|
+
step("terminal-attachments", () => terminalAttachmentRuntime?.dispose()),
|
|
2149
|
+
step("pane-streams", () =>
|
|
2150
|
+
paneStreamRuntime!.dispose(paneStreamCloseForRetirement(retirement)),
|
|
2151
|
+
),
|
|
2096
2152
|
]);
|
|
2097
2153
|
const authorityResults = await Promise.allSettled([
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2154
|
+
step("terminal-inventory", () => terminalInventoryRuntime!.dispose()),
|
|
2155
|
+
step("pane-creation", () => workspacePaneCreation.dispose()),
|
|
2156
|
+
step("workspace-open", () => workspaceOpen.dispose()),
|
|
2157
|
+
step("workspace-open-handoff", () => workspaceOpenHandoff?.dispose()),
|
|
2158
|
+
step("session-backends", () =>
|
|
2103
2159
|
Promise.all([
|
|
2104
2160
|
workspacePromotion.dispose(),
|
|
2105
2161
|
defaultSessionOpener.dispose(),
|
|
2106
2162
|
defaultSessionCreator.dispose(),
|
|
2107
2163
|
]).then(() => {}),
|
|
2108
2164
|
),
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2165
|
+
step("app-window-mutation", () => appWindowMutation.dispose()),
|
|
2166
|
+
step("multiplexer", () => workspaceMultiplexer.dispose()),
|
|
2167
|
+
step("interaction-observation", () => disposeInteractionObservation()),
|
|
2112
2168
|
]);
|
|
2113
2169
|
try {
|
|
2114
|
-
await sessionRuntimeRegistry!.dispose();
|
|
2170
|
+
await step("session-runtimes", () => sessionRuntimeRegistry!.dispose());
|
|
2115
2171
|
} finally {
|
|
2116
2172
|
interactionReceipts.dispose();
|
|
2117
2173
|
interactionEvidence?.dispose();
|
|
@@ -2161,7 +2217,7 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2161
2217
|
getTerminalAttachmentRuntime,
|
|
2162
2218
|
peekTerminalAttachmentRuntime,
|
|
2163
2219
|
paneStreamRuntime,
|
|
2164
|
-
catalogLiveSessions: () =>
|
|
2220
|
+
catalogLiveSessions: () => readLiveSessionSummaries(catalogTmuxRunner),
|
|
2165
2221
|
catalogFleet: async () => {
|
|
2166
2222
|
const endpoint = (sessionName: string, pane: FleetSessionFacts["panes"][number]) =>
|
|
2167
2223
|
pane.semanticPaneId
|
|
@@ -2249,9 +2305,11 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2249
2305
|
terminalAttachmentBoundary,
|
|
2250
2306
|
paneStreamBoundary,
|
|
2251
2307
|
} = startedServer;
|
|
2252
|
-
const retirePaneStreamTransport = async (
|
|
2308
|
+
const retirePaneStreamTransport = async (
|
|
2309
|
+
close?: PaneStreamShutdownClose,
|
|
2310
|
+
): Promise<readonly unknown[]> => {
|
|
2253
2311
|
const transportResults = await Promise.allSettled([
|
|
2254
|
-
Promise.resolve().then(() => paneStreamRuntime!.dispose()),
|
|
2312
|
+
Promise.resolve().then(() => paneStreamRuntime!.dispose(close)),
|
|
2255
2313
|
Promise.resolve().then(() => paneStreamBoundary.close()),
|
|
2256
2314
|
]);
|
|
2257
2315
|
const runtimeResults = await Promise.allSettled([
|
|
@@ -2375,6 +2433,14 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2375
2433
|
|
|
2376
2434
|
let stopped = false;
|
|
2377
2435
|
let stopping: Promise<void> | null = null;
|
|
2436
|
+
// Idempotent: the normal stop and a deadline-forced exit may both reach it.
|
|
2437
|
+
const releaseCanonicalPublication = (): void => {
|
|
2438
|
+
try {
|
|
2439
|
+
clearCanonicalDaemonInfoIfOwned(instanceId, claim);
|
|
2440
|
+
} finally {
|
|
2441
|
+
releaseCanonicalDaemonClaim(claim);
|
|
2442
|
+
}
|
|
2443
|
+
};
|
|
2378
2444
|
let stopSelf: (() => void) | null = null;
|
|
2379
2445
|
const activeProjectStops = new Map<string, { stop: () => void }>();
|
|
2380
2446
|
|
|
@@ -2518,50 +2584,68 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2518
2584
|
wsUrl,
|
|
2519
2585
|
localBypassToken,
|
|
2520
2586
|
compatibilityTerminalAttachmentRuntimeConstructed: () => terminalAttachmentRuntime !== null,
|
|
2521
|
-
|
|
2587
|
+
stopDiagnostics: () => stopProgress.snapshot(),
|
|
2588
|
+
abandon: () => releaseCanonicalPublication(),
|
|
2589
|
+
stop: async ({ gracefulMs = DEFAULT_GRACEFUL_MS, restarting = false } = {}) => {
|
|
2522
2590
|
if (stopping) return stopping;
|
|
2523
2591
|
if (stopped) return;
|
|
2524
2592
|
stopping = (async () => {
|
|
2525
2593
|
const failures: unknown[] = [];
|
|
2526
|
-
const capture = async (
|
|
2594
|
+
const capture = async (
|
|
2595
|
+
stage: string,
|
|
2596
|
+
operation: () => void | Promise<void>,
|
|
2597
|
+
): Promise<void> => {
|
|
2527
2598
|
try {
|
|
2528
|
-
await operation
|
|
2599
|
+
await stopProgress.run(stage, operation);
|
|
2529
2600
|
} catch (error) {
|
|
2530
2601
|
failures.push(error);
|
|
2531
2602
|
}
|
|
2532
2603
|
};
|
|
2533
2604
|
try {
|
|
2534
2605
|
stopped = true;
|
|
2535
|
-
|
|
2536
|
-
await capture(() =>
|
|
2537
|
-
await capture(() =>
|
|
2606
|
+
stopProgress.begin();
|
|
2607
|
+
await capture("plugins", () => pluginSupervisor?.stop());
|
|
2608
|
+
await capture("activation-backend", () => setActivationBackend(null));
|
|
2609
|
+
await capture("session-monitor", () => sessionMonitor?.stop());
|
|
2538
2610
|
paneSourceCredentials.dispose();
|
|
2539
|
-
|
|
2611
|
+
// A generation restarting in place tells its streams to reconnect
|
|
2612
|
+
// now; only a real shutdown says "daemon-shutdown" (#840).
|
|
2613
|
+
await capture("tmux-server-owners", () =>
|
|
2614
|
+
serverOwners?.dispose(restarting ? "generation-restart" : "shutdown"),
|
|
2615
|
+
);
|
|
2540
2616
|
|
|
2541
2617
|
// Retire direct-ticket admission, live PTYs, and the direct upgrade
|
|
2542
2618
|
// listener before touching the legacy WS or HTTP surfaces.
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
await capture(() =>
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2619
|
+
await capture("terminal-attachments", async () => {
|
|
2620
|
+
failures.push(
|
|
2621
|
+
...(await retireTerminalAttachmentTransport(
|
|
2622
|
+
terminalAttachmentRuntime,
|
|
2623
|
+
terminalAttachmentBoundary,
|
|
2624
|
+
)),
|
|
2625
|
+
);
|
|
2626
|
+
});
|
|
2627
|
+
await capture("pane-streams", async () => {
|
|
2628
|
+
failures.push(
|
|
2629
|
+
...(await retirePaneStreamTransport(
|
|
2630
|
+
restarting ? PANE_STREAM_DAEMON_RESTARTING_CLOSE : undefined,
|
|
2631
|
+
)),
|
|
2632
|
+
);
|
|
2633
|
+
});
|
|
2634
|
+
await capture("local-images", () => localImages?.dispose());
|
|
2635
|
+
await capture("terminal-inventory", () => terminalInventoryRuntime.dispose());
|
|
2636
|
+
await capture("pane-creation", () => workspacePaneCreation.dispose());
|
|
2637
|
+
await capture("workspace-open", () => workspaceOpen.dispose());
|
|
2638
|
+
await capture("workspace-open-handoff", () => workspaceOpenHandoff?.dispose());
|
|
2639
|
+
await capture("session-backends", () =>
|
|
2556
2640
|
Promise.all([
|
|
2557
2641
|
workspacePromotion.dispose(),
|
|
2558
2642
|
defaultSessionOpener.dispose(),
|
|
2559
2643
|
defaultSessionCreator.dispose(),
|
|
2560
2644
|
]).then(() => {}),
|
|
2561
2645
|
);
|
|
2562
|
-
await capture(() => appWindowMutation.dispose());
|
|
2563
|
-
await capture(() => workspaceMultiplexer.dispose());
|
|
2564
|
-
await capture(() => disposeInteractionObservation());
|
|
2646
|
+
await capture("app-window-mutation", () => appWindowMutation.dispose());
|
|
2647
|
+
await capture("workspace-multiplexer", () => workspaceMultiplexer.dispose());
|
|
2648
|
+
await capture("interaction-observation", () => disposeInteractionObservation());
|
|
2565
2649
|
|
|
2566
2650
|
let closePromise: Promise<void>;
|
|
2567
2651
|
try {
|
|
@@ -2570,26 +2654,28 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2570
2654
|
failures.push(error);
|
|
2571
2655
|
closePromise = Promise.resolve();
|
|
2572
2656
|
}
|
|
2573
|
-
await capture(() => closeClients());
|
|
2657
|
+
await capture("http-clients", () => closeClients());
|
|
2574
2658
|
for (const stop of activeProjectStops.values()) {
|
|
2575
|
-
await capture(() => stop.stop());
|
|
2659
|
+
await capture("active-projects", () => stop.stop());
|
|
2576
2660
|
}
|
|
2577
2661
|
activeProjectStops.clear();
|
|
2578
|
-
await capture(() => shutdownPtyBridges());
|
|
2579
|
-
await capture(() =>
|
|
2662
|
+
await capture("pty-bridges", () => shutdownPtyBridges());
|
|
2663
|
+
await capture("http-close-grace", () =>
|
|
2664
|
+
Promise.race([closePromise, delay(gracefulMs)]),
|
|
2665
|
+
);
|
|
2580
2666
|
for (const socket of sockets) {
|
|
2581
|
-
await capture(() => {
|
|
2667
|
+
await capture("http-sockets", () => {
|
|
2582
2668
|
socket.destroy();
|
|
2583
2669
|
});
|
|
2584
2670
|
}
|
|
2585
|
-
await capture(() => Promise.race([closePromise, delay(100)]));
|
|
2586
|
-
await capture(() => closeWsServers());
|
|
2587
|
-
await capture(() => shutdownWsEventObservation());
|
|
2588
|
-
await capture(() => setFleetFactsTmuxRunner(null));
|
|
2589
|
-
await capture(() => closeRuntimeTraceStream());
|
|
2590
|
-
await capture(() => setRemoteAccessRestartBackend(null));
|
|
2591
|
-
await capture(() => setDaemonShutdownBackend(null));
|
|
2592
|
-
await capture(() => setDaemonRestartBackend(null));
|
|
2671
|
+
await capture("http-close-final", () => Promise.race([closePromise, delay(100)]));
|
|
2672
|
+
await capture("ws-servers", () => closeWsServers());
|
|
2673
|
+
await capture("ws-event-observation", () => shutdownWsEventObservation());
|
|
2674
|
+
await capture("fleet-facts-runner", () => setFleetFactsTmuxRunner(null));
|
|
2675
|
+
await capture("runtime-trace", () => closeRuntimeTraceStream());
|
|
2676
|
+
await capture("remote-access-backend", () => setRemoteAccessRestartBackend(null));
|
|
2677
|
+
await capture("shutdown-backend", () => setDaemonShutdownBackend(null));
|
|
2678
|
+
await capture("restart-backend", () => setDaemonRestartBackend(null));
|
|
2593
2679
|
|
|
2594
2680
|
if (failures.length > 0) {
|
|
2595
2681
|
const cause =
|
|
@@ -2599,11 +2685,20 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2599
2685
|
throw new DaemonShutdownError("Daemon shutdown failed", { cause: cause as Error });
|
|
2600
2686
|
}
|
|
2601
2687
|
} finally {
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2688
|
+
const progress = stopProgress.finish();
|
|
2689
|
+
// A quick clean stop is routine (debug); a restart, a slow stop or a
|
|
2690
|
+
// failing one is what the next investigation needs (info).
|
|
2691
|
+
const notable = restarting || failures.length > 0 || progress.elapsedMs >= 1_000;
|
|
2692
|
+
logger[notable ? "info" : "debug"]("daemon-lifecycle", "generation stopped", {
|
|
2693
|
+
generationInstanceId: instanceId,
|
|
2694
|
+
port,
|
|
2695
|
+
stopMs: progress.elapsedMs,
|
|
2696
|
+
failures: failures.length,
|
|
2697
|
+
slowestStages: [...progress.completed]
|
|
2698
|
+
.sort((left, right) => right.ms - left.ms)
|
|
2699
|
+
.slice(0, 5),
|
|
2700
|
+
});
|
|
2701
|
+
releaseCanonicalPublication();
|
|
2607
2702
|
}
|
|
2608
2703
|
})();
|
|
2609
2704
|
return stopping;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export interface DaemonStopProgress {
|
|
2
|
+
readonly started: boolean;
|
|
3
|
+
readonly finished: boolean;
|
|
4
|
+
readonly elapsedMs: number;
|
|
5
|
+
/** The teardown stage in flight, or null when none is. */
|
|
6
|
+
readonly stage: string | null;
|
|
7
|
+
readonly stageMs: number;
|
|
8
|
+
readonly completed: readonly { readonly stage: string; readonly ms: number }[];
|
|
9
|
+
/** Steps inside the stage that have started and not settled, with their age. */
|
|
10
|
+
readonly openSteps: readonly { readonly step: string; readonly ms: number }[];
|
|
11
|
+
/** Steps settled so far; with `completed` it shows whether a slow stop still moves. */
|
|
12
|
+
readonly stepsSettled: number;
|
|
13
|
+
}
|
|
14
|
+
/** Wraps one named step of a teardown; steps may run in parallel. */
|
|
15
|
+
export type TrackTeardownStep = <T>(step: string, work: () => T | Promise<T>) => Promise<T>;
|
|
16
|
+
|
|
17
|
+
/** Records which teardown stage a stop is in and how long each one took. */
|
|
18
|
+
export function createStopProgress(now: () => number = () => performance.now()): {
|
|
19
|
+
begin(): void;
|
|
20
|
+
run(stage: string, operation: () => void | Promise<void>): Promise<void>;
|
|
21
|
+
track: TrackTeardownStep;
|
|
22
|
+
finish(): DaemonStopProgress;
|
|
23
|
+
snapshot(): DaemonStopProgress;
|
|
24
|
+
} {
|
|
25
|
+
const open = new Map<symbol, { step: string; startedAt: number }>();
|
|
26
|
+
let stepsSettled = 0;
|
|
27
|
+
let startedAt: number | null = null;
|
|
28
|
+
let finishedAt: number | null = null;
|
|
29
|
+
let stage: string | null = null;
|
|
30
|
+
let stageStartedAt = 0;
|
|
31
|
+
const completed: { stage: string; ms: number }[] = [];
|
|
32
|
+
const snapshot = (): DaemonStopProgress => {
|
|
33
|
+
const at = finishedAt ?? now();
|
|
34
|
+
return {
|
|
35
|
+
started: startedAt !== null,
|
|
36
|
+
finished: finishedAt !== null,
|
|
37
|
+
elapsedMs: startedAt === null ? 0 : Math.round(at - startedAt),
|
|
38
|
+
stage,
|
|
39
|
+
stageMs: stage === null ? 0 : Math.round(at - stageStartedAt),
|
|
40
|
+
completed: completed.map((entry) => ({ ...entry })),
|
|
41
|
+
openSteps: [...open.values()].map((entry) => ({
|
|
42
|
+
step: entry.step,
|
|
43
|
+
ms: Math.round(at - entry.startedAt),
|
|
44
|
+
})),
|
|
45
|
+
stepsSettled,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
begin() {
|
|
50
|
+
startedAt ??= now();
|
|
51
|
+
},
|
|
52
|
+
async run(name, operation) {
|
|
53
|
+
stage = name;
|
|
54
|
+
stageStartedAt = now();
|
|
55
|
+
try {
|
|
56
|
+
await operation();
|
|
57
|
+
} finally {
|
|
58
|
+
completed.push({ stage: name, ms: Math.round(now() - stageStartedAt) });
|
|
59
|
+
stage = null;
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
async track(step, work) {
|
|
63
|
+
const key = Symbol(step);
|
|
64
|
+
open.set(key, { step, startedAt: now() });
|
|
65
|
+
try {
|
|
66
|
+
return await work();
|
|
67
|
+
} finally {
|
|
68
|
+
open.delete(key);
|
|
69
|
+
stepsSettled += 1;
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
finish() {
|
|
73
|
+
finishedAt ??= now();
|
|
74
|
+
return snapshot();
|
|
75
|
+
},
|
|
76
|
+
snapshot,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -86,6 +86,18 @@ export async function startOwnedEmbeddedDaemon(
|
|
|
86
86
|
tmuxAuthorityReplaced: () => current.tmuxAuthorityReplaced?.() ?? Promise.resolve(false),
|
|
87
87
|
compatibilityTerminalAttachmentRuntimeConstructed: () =>
|
|
88
88
|
current.compatibilityTerminalAttachmentRuntimeConstructed(),
|
|
89
|
+
stopDiagnostics: () =>
|
|
90
|
+
current.stopDiagnostics?.() ?? {
|
|
91
|
+
started: false,
|
|
92
|
+
finished: false,
|
|
93
|
+
elapsedMs: 0,
|
|
94
|
+
stage: null,
|
|
95
|
+
stageMs: 0,
|
|
96
|
+
completed: [],
|
|
97
|
+
openSteps: [],
|
|
98
|
+
stepsSettled: 0,
|
|
99
|
+
},
|
|
100
|
+
abandon: () => current.abandon?.(),
|
|
89
101
|
activateProject: (name, activationOptions) => {
|
|
90
102
|
if (closed || !available) return Promise.reject(new Error("Embedded daemon is retiring"));
|
|
91
103
|
return current.activateProject(name, activationOptions);
|