dsh-remote-go 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.js +1344 -2095
- package/dist/src/admission.js +3 -28
- package/dist/src/api.js +37 -99
- package/dist/src/atomic-json.js +32 -66
- package/dist/src/bootstrap.js +17 -27
- package/dist/src/connect/attach.js +3 -25
- package/dist/src/connect/bootstrap.js +2 -8
- package/dist/src/connect/failures.js +3 -18
- package/dist/src/connect/guards.js +13 -8
- package/dist/src/connect/launch.js +11 -21
- package/dist/src/connect/links.js +11 -27
- package/dist/src/connect/ownership.js +33 -114
- package/dist/src/connect/pipeline.js +61 -158
- package/dist/src/connect/reattach.js +20 -44
- package/dist/src/connect/registry.js +0 -1
- package/dist/src/connect/repair.js +8 -37
- package/dist/src/connect/restart.js +36 -97
- package/dist/src/connect/stop.js +16 -50
- package/dist/src/connect/transport.js +10 -18
- package/dist/src/connect/verify.js +3 -12
- package/dist/src/connect/watchdog.js +6 -38
- package/dist/src/connect-log.js +16 -41
- package/dist/src/connect-progress.js +13 -45
- package/dist/src/constants.js +2 -40
- package/dist/src/context.js +10 -31
- package/dist/src/diagnostics.js +56 -25
- package/dist/src/download-jobs.js +11 -20
- package/dist/src/errors.js +175 -190
- package/dist/src/events.js +20 -84
- package/dist/src/host-lifecycle.js +39 -175
- package/dist/src/host-registry.js +27 -78
- package/dist/src/host-runtime.js +0 -9
- package/dist/src/host-view.js +6 -29
- package/dist/src/index.js +15 -35
- package/dist/src/kernel-adapter.js +34 -80
- package/dist/src/key-files.js +10 -23
- package/dist/src/known-hosts.js +13 -34
- package/dist/src/layout.js +3 -20
- package/dist/src/local-download.js +94 -163
- package/dist/src/local-ssh.js +12 -19
- package/dist/src/local-version.js +35 -49
- package/dist/src/node/download.js +1 -4
- package/dist/src/node-runtime.js +19 -38
- package/dist/src/probe.js +6 -7
- package/dist/src/prompts.js +56 -128
- package/dist/src/proxy/cookies.js +26 -60
- package/dist/src/proxy/headers.js +30 -125
- package/dist/src/proxy/http.js +33 -41
- package/dist/src/proxy/index.js +20 -34
- package/dist/src/proxy/limits.js +4 -6
- package/dist/src/proxy/routes.js +10 -17
- package/dist/src/proxy/upgrade.js +27 -42
- package/dist/src/redact.js +14 -33
- package/dist/src/remote-files.js +9 -21
- package/dist/src/remote-path.js +21 -62
- package/dist/src/remote-proc.js +35 -103
- package/dist/src/remote-web/registry.js +10 -50
- package/dist/src/remote-web/resolve.js +23 -104
- package/dist/src/remote-web/start.js +27 -64
- package/dist/src/remote-web/stop.js +6 -25
- package/dist/src/request-trust.js +15 -32
- package/dist/src/runtime/dispatch.js +33 -143
- package/dist/src/runtime/effects.js +7 -17
- package/dist/src/runtime/events.js +1 -1
- package/dist/src/runtime/fsm.js +11 -61
- package/dist/src/runtime/rules.js +113 -198
- package/dist/src/secrets.js +15 -38
- package/dist/src/service.js +22 -128
- package/dist/src/settings.js +41 -42
- package/dist/src/ssh-config.js +22 -41
- package/dist/src/ssh-failures.js +23 -74
- package/dist/src/ssh-sftp.js +47 -86
- package/dist/src/ssh.js +95 -177
- package/dist/src/store.js +31 -48
- package/dist/src/tool-shared.js +17 -52
- package/dist/src/tools-exec-policy.js +33 -79
- package/dist/src/tools-exec.js +87 -151
- package/dist/src/tools-report.js +100 -167
- package/dist/src/tools.js +59 -133
- package/dist/src/tunnel.js +9 -27
- package/dist/src/util.js +19 -56
- package/dist/src/version.js +6 -12
- package/dist/src/watchdog-bus.js +0 -8
- package/dist/src/watchdog.js +7 -47
- package/package.json +1 -1
|
@@ -2,28 +2,22 @@ import { REMOTE_START_TIMEOUT_MS, SSH_READY_TIMEOUT_MS } from '../constants.js';
|
|
|
2
2
|
import { beginConnectLog } from '../connect-log.js';
|
|
3
3
|
import { errors } from '../errors.js';
|
|
4
4
|
import { disposeSsh, scheduleReconnect } from '../host-lifecycle.js';
|
|
5
|
-
import { findKnownHostEntries, parseKnownHosts } from '../known-hosts.js';
|
|
6
5
|
import { layoutForRuntime } from '../layout.js';
|
|
7
6
|
import { applyManagedNodeFacts, managedNodeVersionFromEngine } from '../node-runtime.js';
|
|
8
7
|
import { requestHostKey } from '../prompts.js';
|
|
8
|
+
import { registryNamesInstance } from '../remote-web/registry.js';
|
|
9
9
|
import { dispatch, scopeFactsFor } from '../runtime/dispatch.js';
|
|
10
10
|
import { createRuntimeEffects } from '../runtime/effects.js';
|
|
11
|
-
import {
|
|
11
|
+
import { messageOf, nowIso } from '../util.js';
|
|
12
12
|
import { normalizeVersion, versionsEqual } from '../version.js';
|
|
13
13
|
import { markConnected } from './attach.js';
|
|
14
14
|
import { normalizeConnectFailure } from './failures.js';
|
|
15
15
|
import { LinkCancelled, assertStillWanted, assertTransportOpen, linkTaken } from './guards.js';
|
|
16
|
-
import { resolveForeignConflict } from './launch.js';
|
|
16
|
+
import { PATCHED_CARRIER_NOTE, resolveForeignConflict } from './launch.js';
|
|
17
17
|
import { rememberBound, rememberLaunched } from './ownership.js';
|
|
18
|
-
import { captureFingerprint, openTunnelFor, resolveTargetForRuntime, settlePasswordStorage } from './transport.js';
|
|
18
|
+
import { captureFingerprint, knownFingerprintsFor, openTunnelFor, resolveTargetForRuntime, settlePasswordStorage, } from './transport.js';
|
|
19
19
|
import { verifyRemoteUi } from './verify.js';
|
|
20
|
-
/**
|
|
21
|
-
* Start the pipeline in the background and make sure its promise never rejects: a listener
|
|
22
|
-
* or a step outside the pipeline's own error handling must not become an unhandled
|
|
23
|
-
* rejection that Node reports as a process-level failure (L).
|
|
24
|
-
* @param ctx - service context.
|
|
25
|
-
* @param runtime - host runtime.
|
|
26
|
-
*/
|
|
20
|
+
/** Start the pipeline in the background and keep its promise off the rejection path, so a listener or a step outside its error handling cannot become an unhandled rejection. */
|
|
27
21
|
export function startConnectPromise(ctx, runtime) {
|
|
28
22
|
const run = connectPipeline(ctx, runtime).catch((error) => {
|
|
29
23
|
ctx.progress.log(runtime, 'debug', 'connect pipeline stopped outside its error path:', messageOf(error));
|
|
@@ -34,14 +28,7 @@ export function startConnectPromise(ctx, runtime) {
|
|
|
34
28
|
runtime.connectPromise = null;
|
|
35
29
|
});
|
|
36
30
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Re-enter the pipeline after a dropped link. Lives here rather than in the
|
|
39
|
-
* lifecycle module so `scheduleReconnect` stays a pure timer with a callback.
|
|
40
|
-
*
|
|
41
|
-
* The retry is a `connect.requested` with `retry: true`: it must publish `connecting` and clear
|
|
42
|
-
* the previous failure, but it must **not** reset the retry budget the user's connect set (R5/H2),
|
|
43
|
-
* so the event carries the one difference.
|
|
44
|
-
*/
|
|
31
|
+
/** Re-enter the pipeline after a dropped link, as a `connect.requested` with `retry: true`: it publishes `connecting` and clears the previous failure but must not reset the retry budget the user's connect set. */
|
|
45
32
|
async function reconnectNow(ctx, runtime) {
|
|
46
33
|
if (ctx.state.disposed || runtime.desired !== 'connected')
|
|
47
34
|
return;
|
|
@@ -53,32 +40,18 @@ async function reconnectNow(ctx, runtime) {
|
|
|
53
40
|
run: () => startConnectPromise(ctx, runtime),
|
|
54
41
|
});
|
|
55
42
|
}
|
|
56
|
-
/** A timer callback that starts a retry: report a throw instead of leaving it unhandled
|
|
43
|
+
/** A timer callback that starts a retry: report a throw instead of leaving it unhandled. */
|
|
57
44
|
function retryNow(ctx, runtime) {
|
|
58
45
|
void reconnectNow(ctx, runtime).catch((error) => {
|
|
59
46
|
ctx.progress.log(runtime, 'warn', 'the automatic retry could not start:', messageOf(error));
|
|
60
47
|
});
|
|
61
48
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Watch one transport for its close. A close is one `transport.closed` event, and the rule
|
|
64
|
-
* decides (design-arch §2.4.2) whether it was a stale listener, the teardown's own close, a
|
|
65
|
-
* handshake that died (record the loss, settle the parked prompts, log) or a live link that
|
|
66
|
-
* dropped (publish `disconnected`, close the listener, ask the retry policy for a timer).
|
|
67
|
-
*
|
|
68
|
-
* Attached as soon as the transport exists — before `connect()` — because a drop while the
|
|
69
|
-
* handshake waits on a host-key prompt must resolve that prompt instead of parking the pipeline
|
|
70
|
-
* until its 120 s timeout (H3/M1). This replaces the two listeners this module used to keep
|
|
71
|
-
* (a silent handshake one and the live/in-flight one); their work is the event's effects now.
|
|
72
|
-
* @param ctx - the orchestration context (the effect owner is bound to it).
|
|
73
|
-
* @param runtime - host runtime.
|
|
74
|
-
* @param ssh - the transport that was just created.
|
|
75
|
-
*/
|
|
49
|
+
/** Watch one transport for its close; attached before `connect()` so a drop while a host-key prompt is parked resolves that prompt instead of stalling the pipeline. */
|
|
76
50
|
function watchTransport(ctx, runtime, ssh) {
|
|
77
51
|
if (!ssh || typeof ssh.on !== 'function')
|
|
78
52
|
return;
|
|
79
53
|
ssh.on('close', () => {
|
|
80
|
-
// A transport this runtime no longer dials (replaced, or disposed before a new attempt)
|
|
81
|
-
// is not a lost link: its close is the teardown itself.
|
|
54
|
+
// A transport this runtime no longer dials (replaced, or disposed before a new attempt) is not a lost link.
|
|
82
55
|
if (runtime.ssh !== ssh && runtime.jumpSsh !== ssh)
|
|
83
56
|
return;
|
|
84
57
|
if (runtime.closing || runtime.desired !== 'connected')
|
|
@@ -87,28 +60,14 @@ function watchTransport(ctx, runtime, ssh) {
|
|
|
87
60
|
void dispatch(createRuntimeEffects(ctx), runtime, event, scopeFactsFor(ctx, runtime, event), {
|
|
88
61
|
caller: 'callback',
|
|
89
62
|
}).then((result) => {
|
|
90
|
-
// The rule
|
|
91
|
-
// the budget and the settings switch stay in `scheduleReconnect`, the single place that
|
|
92
|
-
// actually creates the retry timer (never a second loop here, P2b hand-off).
|
|
63
|
+
// The rule only says "a retry makes sense"; `scheduleReconnect` owns the delay, the budget and the switch.
|
|
93
64
|
const wantsRetry = result.ok && result.effects.some((effect) => effect.type === 'arm' && effect.timer === 'reconnect');
|
|
94
65
|
if (wantsRetry)
|
|
95
66
|
scheduleReconnect(ctx, runtime, () => retryNow(ctx, runtime));
|
|
96
67
|
});
|
|
97
68
|
});
|
|
98
69
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Open the transport: direct, or through a jump host with a forwarded stream.
|
|
101
|
-
*
|
|
102
|
-
* The jump host and the target are separate security contexts. Each one gets its own
|
|
103
|
-
* options — its own policy, its own pin and its own `onHostKey` role — so a key confirmed
|
|
104
|
-
* for one can never be checked against, or written into, the other (B1).
|
|
105
|
-
*/
|
|
106
|
-
/**
|
|
107
|
-
* The dial. It reads only Config/Transport/Reporter/Store itself, but it hands `ctx` to
|
|
108
|
-
* `watchTransport`, whose close listener re-enters the pipeline after a drop — and that path needs
|
|
109
|
-
* the orchestration context. Narrowing the parameter therefore does not compile; the gate's
|
|
110
|
-
* `godCtxParams` entry records exactly that.
|
|
111
|
-
*/
|
|
70
|
+
/** The dial: direct, or through a jump host with a forwarded stream. The two are separate security contexts, each with its own policy, pin and `onHostKey` role, so a key confirmed for one can never be checked against, or written into, the other. It reads only Config/Transport/Reporter/Store itself but hands `ctx` to `watchTransport`, whose close listener re-enters the pipeline, so the parameter cannot be narrowed. */
|
|
112
71
|
async function openTransport(ctx, runtime, target) {
|
|
113
72
|
const settings = ctx.settings();
|
|
114
73
|
const auth = () => ({
|
|
@@ -118,10 +77,8 @@ async function openTransport(ctx, runtime, target) {
|
|
|
118
77
|
});
|
|
119
78
|
const buildOptions = (resolved, role, sock) => {
|
|
120
79
|
const isJump = role === 'jump';
|
|
121
|
-
// A per-host policy and pin describe the saved target. A jump host only obeys the
|
|
122
|
-
// global policy and, at most, a pin remembered for this session (it is not persisted).
|
|
123
|
-
const hostKeyPolicy = isJump ? settings.hostKeyPolicy : (runtime.entry.hostKeyPolicy ?? settings.hostKeyPolicy);
|
|
124
80
|
const resolvedPort = resolved.port ?? 22;
|
|
81
|
+
const hostKeyPolicy = isJump ? settings.hostKeyPolicy : (runtime.entry.hostKeyPolicy ?? settings.hostKeyPolicy);
|
|
125
82
|
const jumpPinMatches = isJump &&
|
|
126
83
|
runtime.jumpFingerprint?.host === resolved.host &&
|
|
127
84
|
(Number(runtime.jumpFingerprint?.port) || 22) === resolvedPort;
|
|
@@ -134,8 +91,6 @@ async function openTransport(ctx, runtime, target) {
|
|
|
134
91
|
host: resolved.host,
|
|
135
92
|
port: resolvedPort,
|
|
136
93
|
username: resolved.username ?? resolved.user ?? null,
|
|
137
|
-
// The key path expands against the *user* home (`~/.ssh/...`), never against
|
|
138
|
-
// DSH_HOME, so the SSH layer needs to know which one that is.
|
|
139
94
|
home: ctx.userHome(),
|
|
140
95
|
auth: auth(),
|
|
141
96
|
identityFiles: resolved.identityFiles ?? [],
|
|
@@ -156,13 +111,12 @@ async function openTransport(ctx, runtime, target) {
|
|
|
156
111
|
return;
|
|
157
112
|
}
|
|
158
113
|
ctx.progress.phase(runtime, 'ssh', 'ssh-connecting', { host: target.jumpHost.host, jump: true });
|
|
114
|
+
const jumpMaterial = await ctx.deps.loadSshMaterial({ home: ctx.userHome() });
|
|
159
115
|
const jumpTarget = {
|
|
160
116
|
...target.jumpHost,
|
|
161
117
|
username: target.jumpHost.user ?? target.username,
|
|
162
|
-
knownFingerprints:
|
|
118
|
+
knownFingerprints: knownFingerprintsFor(jumpMaterial, target.jumpHost.host, target.jumpHost.port ?? 22),
|
|
163
119
|
};
|
|
164
|
-
// An edited `jumpHost` is a different machine: a pin remembered for the previous jump host
|
|
165
|
-
// must not make the new one fail as `host-key-changed` (review blocker 3).
|
|
166
120
|
const rememberedJump = runtime.jumpFingerprint;
|
|
167
121
|
const rememberedJumpPort = (Number(rememberedJump?.port) || 22) === (jumpTarget.port ?? 22);
|
|
168
122
|
if (rememberedJump !== null && (!rememberedJumpPort || rememberedJump.host !== jumpTarget.host)) {
|
|
@@ -172,8 +126,6 @@ async function openTransport(ctx, runtime, target) {
|
|
|
172
126
|
runtime.jumpSsh = ctx.deps.sshFactory(buildOptions(jumpTarget, 'jump'));
|
|
173
127
|
watchTransport(ctx, runtime, runtime.jumpSsh);
|
|
174
128
|
await runtime.jumpSsh.connect();
|
|
175
|
-
// The jump host's key is settled (its own context above); from here the fingerprint the host
|
|
176
|
-
// card describes is the target's, which `captureFingerprint` fills once it answers.
|
|
177
129
|
runtime.fingerprint = null;
|
|
178
130
|
ctx.progress.phase(runtime, 'ssh', 'ssh-connecting', { host: target.host, via: target.jumpHost.host });
|
|
179
131
|
const stream = await runtime.jumpSsh.forwardOut(target.host, target.port ?? 22);
|
|
@@ -184,26 +136,26 @@ async function openTransport(ctx, runtime, target) {
|
|
|
184
136
|
async function connectPipeline(ctx, runtime) {
|
|
185
137
|
const log = (level, ...args) => ctx.progress.log(runtime, level, ...args);
|
|
186
138
|
const phase = (name, code, params) => ctx.progress.phase(runtime, name, code, params);
|
|
187
|
-
//
|
|
188
|
-
|
|
139
|
+
// Guards after every await: the link must still be wanted and the transport open, so a late write cannot revive it.
|
|
140
|
+
const gate = () => {
|
|
141
|
+
assertStillWanted(ctx, runtime);
|
|
142
|
+
assertTransportOpen(runtime);
|
|
143
|
+
};
|
|
144
|
+
// Every attempt entered through `connect.requested`, which owns `closing`, `transportLost`, the disarms and the card.
|
|
189
145
|
runtime.alongsidePids = [];
|
|
190
|
-
// Kill rights belong to this connection: a fresh connect starts with no launched pids.
|
|
191
146
|
runtime.launched = new Map();
|
|
192
147
|
runtime.bound = null;
|
|
193
148
|
runtime.tunnelRepairFailures = 0;
|
|
194
149
|
runtime.nextTunnelRepairAt = 0;
|
|
195
150
|
let remoteStarted = false;
|
|
196
151
|
let layout = null;
|
|
197
|
-
// Whether the SSH transport ever came up during this attempt: a link that was up and then
|
|
198
|
-
// dropped is a connection event and is retried like one (H3).
|
|
199
152
|
let transportUp = false;
|
|
200
153
|
try {
|
|
201
154
|
const target = await resolveTargetForRuntime(ctx, runtime);
|
|
202
155
|
assertStillWanted(ctx, runtime);
|
|
156
|
+
const { host: targetHost, port: targetPort, username } = target;
|
|
203
157
|
const viaJump = target.jumpHost ? ` via ${target.jumpHost.host}` : '';
|
|
204
|
-
log('debug', `target resolved: ${
|
|
205
|
-
// A password-auth host may have one remembered: load it before the transport
|
|
206
|
-
// is opened, so reconnect and background retries work without a prompt.
|
|
158
|
+
log('debug', `target resolved: ${username ?? '(default)'}@${targetHost}:${targetPort}${viaJump}`);
|
|
207
159
|
if (runtime.entry.auth?.type === 'password' && !runtime.password && ctx.secrets) {
|
|
208
160
|
const remembered = await ctx.secrets.get(runtime.id);
|
|
209
161
|
if (remembered) {
|
|
@@ -213,38 +165,28 @@ async function connectPipeline(ctx, runtime) {
|
|
|
213
165
|
assertStillWanted(ctx, runtime);
|
|
214
166
|
}
|
|
215
167
|
phase('ssh', 'ssh-connecting', { host: runtime.entry.name });
|
|
216
|
-
// An idle host keeps its SSH session for a fast resume; this attempt replaces it, so
|
|
217
|
-
// old one is released here instead of being overwritten (and leaked) by openTransport.
|
|
168
|
+
// An idle host keeps its SSH session for a fast resume; this attempt replaces it, so release it, do not leak it.
|
|
218
169
|
if (runtime.ssh !== null || runtime.jumpSsh !== null) {
|
|
219
170
|
log('debug', 'releasing the transport kept by the idle policy before dialling again');
|
|
220
171
|
await disposeSsh(runtime);
|
|
221
172
|
assertStillWanted(ctx, runtime);
|
|
222
173
|
}
|
|
223
174
|
await openTransport(ctx, runtime, target);
|
|
224
|
-
|
|
225
|
-
// connection too, so the close handler is attached before the remaining steps (H3).
|
|
226
|
-
assertStillWanted(ctx, runtime);
|
|
227
|
-
assertTransportOpen(runtime);
|
|
175
|
+
gate();
|
|
228
176
|
transportUp = true;
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
//
|
|
177
|
+
const fingerprint = runtime.fingerprint?.sha256 ?? 'unknown';
|
|
178
|
+
log('info', `SSH connected to ${targetHost}:${targetPort} as ${username ?? '(default)'} (fingerprint ${fingerprint})`);
|
|
179
|
+
// SSH accepted the credential: prove the password now, before a later bootstrap failure makes the user retype it.
|
|
232
180
|
await settlePasswordStorage(ctx, runtime, log);
|
|
233
181
|
assertStillWanted(ctx, runtime);
|
|
234
182
|
phase('probe', 'probing');
|
|
235
183
|
let facts = await ctx.deps.probe(runtime.ssh);
|
|
236
|
-
|
|
237
|
-
assertTransportOpen(runtime);
|
|
184
|
+
gate();
|
|
238
185
|
const freeGb = Math.round(Number(facts.diskFreeKb ?? 0) / 1_048_576);
|
|
239
186
|
log('debug', `probe: ${facts.os}/${facts.arch} · ${String(facts.osName ?? 'unknown OS')} · node ${facts.nodeVersion ?? 'not found'} · ${freeGb} GB free`);
|
|
240
|
-
// The runtime always runs on a plugin-owned Node (`~/.dsh/remote-go/node`),
|
|
241
|
-
// whether or not the remote already has one: a shared system/nvm Node is
|
|
242
|
-
// exactly what makes "works for my other project" break the remote DSH.
|
|
243
|
-
// There is no system fallback on purpose, so this failure is the connection's.
|
|
244
187
|
const profile = ctx.settings().bootstrap.profile;
|
|
245
188
|
const managedVersion = managedNodeVersionFromEngine(ctx.engineNodeRange());
|
|
246
|
-
// A probe that did not report $HOME cannot address the remote layout: `
|
|
247
|
-
// throws instead of building a literal-tilde path (H1).
|
|
189
|
+
// A probe that did not report $HOME cannot address the remote layout: `layoutForRuntime` throws.
|
|
248
190
|
const nodeLayout = layoutForRuntime({ facts });
|
|
249
191
|
log('info', `managed Node: expecting v${managedVersion} in ${nodeLayout.nodeDir}`);
|
|
250
192
|
const managed = await ctx.deps.ensureNode(runtime.ssh, {
|
|
@@ -253,12 +195,11 @@ async function connectPipeline(ctx, runtime) {
|
|
|
253
195
|
version: managedVersion,
|
|
254
196
|
onProgress: (event) => ctx.progress.nodeProgress(runtime, event),
|
|
255
197
|
});
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
// The probe above reported every field, so the merged object is a full `RemoteFacts`; the
|
|
259
|
-
// helper's own return type stays `Partial` because it also accepts a partial input.
|
|
198
|
+
gate();
|
|
199
|
+
// The probe reported every field, so the merged object is a full `RemoteFacts`.
|
|
260
200
|
facts = applyManagedNodeFacts(facts, managed);
|
|
261
|
-
|
|
201
|
+
const { version: nodeVersion, installed, nodeBinDir } = managed;
|
|
202
|
+
log('info', `managed Node ${nodeVersion}${installed ? ' installed' : ' reused'} at ${nodeBinDir}`);
|
|
262
203
|
runtime.facts = facts;
|
|
263
204
|
const targetVersion = ctx.localVersion();
|
|
264
205
|
if (!targetVersion) {
|
|
@@ -271,29 +212,25 @@ async function connectPipeline(ctx, runtime) {
|
|
|
271
212
|
log('info', `runtime plan ${plan.level}: ${plan.reason.en}`);
|
|
272
213
|
phase('start', 'starting-remote', { level: plan.level });
|
|
273
214
|
layout = layoutForRuntime(runtime);
|
|
215
|
+
// Adopt an instance left by a previous local process before the npx preflight: adoption must not need the registry.
|
|
274
216
|
let webInfo = null;
|
|
275
|
-
// Adopt an instance left running by a previous local process (keep-alive).
|
|
276
|
-
// Checked before the npx preflight: an adoptable instance should not require
|
|
277
|
-
// registry access just to reconnect.
|
|
278
217
|
try {
|
|
279
218
|
const adopted = await ctx.deps.adopt(runtime.ssh, layout, { profile });
|
|
280
219
|
const adoptedVersion = adopted?.version ? normalizeVersion(adopted.version) : null;
|
|
220
|
+
const mismatch = `running remote web version ${adoptedVersion} != ${targetVersion}`;
|
|
281
221
|
if (adopted && (!adoptedVersion || versionsEqual(adoptedVersion, targetVersion))) {
|
|
282
222
|
webInfo = { ...adopted, logPath: layout.logFile, startedAt: nowIso(), rawLine: '' };
|
|
283
223
|
log('info', `adopted running remote web pid=${adopted.pid} port=${adopted.port}`);
|
|
284
|
-
// Only a
|
|
285
|
-
// re-attached record is hosted, not owned (B1). It is still the instance this
|
|
286
|
-
// connection is bound to, so the explicit "Stop remote DSH" may stop it by identity.
|
|
224
|
+
// Only a launch record proves the process is ours to stop; a re-attached one is merely hosted.
|
|
287
225
|
if (adopted.origin !== 'reattach')
|
|
288
226
|
await rememberLaunched(ctx, runtime, adopted.pid, layout, profile);
|
|
289
227
|
else
|
|
290
228
|
await rememberBound(ctx, runtime, adopted.pid, layout, profile, 'reattach');
|
|
291
229
|
}
|
|
292
230
|
else if (adopted && adopted.origin !== 'reattach') {
|
|
293
|
-
log('info',
|
|
294
|
-
// The old process owns the same `~/.dsh` profile; leaving it running next
|
|
295
|
-
// to the new one would share session files with a stale version.
|
|
231
|
+
log('info', `${mismatch}; stopping it and starting a matching instance`);
|
|
296
232
|
try {
|
|
233
|
+
// The old process owns the same `~/.dsh` profile: leaving it next to the new one would share session files.
|
|
297
234
|
await ctx.deps.stopWeb(runtime.ssh, layout, { pid: adopted.pid });
|
|
298
235
|
}
|
|
299
236
|
catch (error) {
|
|
@@ -301,7 +238,7 @@ async function connectPipeline(ctx, runtime) {
|
|
|
301
238
|
}
|
|
302
239
|
}
|
|
303
240
|
else if (adopted) {
|
|
304
|
-
log('warn',
|
|
241
|
+
log('warn', `${mismatch}, but it was only re-attached; leaving it running`);
|
|
305
242
|
}
|
|
306
243
|
else {
|
|
307
244
|
log('debug', 'adopt: no running remote web to reuse');
|
|
@@ -310,20 +247,16 @@ async function connectPipeline(ctx, runtime) {
|
|
|
310
247
|
catch (error) {
|
|
311
248
|
log('debug', 'adopt check failed:', messageOf(error));
|
|
312
249
|
}
|
|
313
|
-
|
|
314
|
-
assertTransportOpen(runtime);
|
|
250
|
+
gate();
|
|
315
251
|
if (!webInfo) {
|
|
316
|
-
//
|
|
317
|
-
// HTTP, ...) still names a process on this ~/.dsh profile. Starting a second
|
|
318
|
-
// one would let two clients write the same session files. A record written by a
|
|
319
|
-
// re-attach names a process this plugin did not launch, so it is never stopped here.
|
|
252
|
+
// A row we refused to adopt still names a process on this ~/.dsh profile: two clients must not write the same session files.
|
|
320
253
|
const leftover = await ctx.deps.readRegistry(runtime.ssh, layout);
|
|
321
254
|
assertStillWanted(ctx, runtime);
|
|
322
255
|
const leftoverPid = Number(leftover?.pid ?? 0);
|
|
323
256
|
if (leftover?.origin === 'reattach') {
|
|
324
257
|
log('info', `leaving a re-attached remote web instance alone (pid ${leftoverPid || 'unknown'})`);
|
|
325
258
|
}
|
|
326
|
-
else if (leftover
|
|
259
|
+
else if (registryNamesInstance(leftover, layout, profile, leftoverPid)) {
|
|
327
260
|
try {
|
|
328
261
|
await ctx.deps.stopWeb(runtime.ssh, layout, { pid: leftoverPid });
|
|
329
262
|
log('info', `stopped a non-adoptable remote web instance pid=${leftoverPid}`);
|
|
@@ -333,18 +266,15 @@ async function connectPipeline(ctx, runtime) {
|
|
|
333
266
|
}
|
|
334
267
|
}
|
|
335
268
|
await resolveForeignConflict(ctx, runtime, layout, profile);
|
|
336
|
-
|
|
337
|
-
assertTransportOpen(runtime);
|
|
269
|
+
gate();
|
|
338
270
|
phase('bootstrap', 'bootstrapping', { level: plan.level });
|
|
339
|
-
// Resolve the exact package in the foreground first: a cold npx download
|
|
340
|
-
//
|
|
341
|
-
// log behind. This also warms the cache for the real start below.
|
|
271
|
+
// Resolve the exact package in the foreground first: a cold npx download belongs in the connect error, not in a
|
|
272
|
+
// detached process that only leaves a log behind.
|
|
342
273
|
log('info', `npx preflight: resolving @deepseek-ai/dsh@${plan.start.targetVersion}`);
|
|
343
274
|
const onStdout = ctx.progress.bootstrapReporter(runtime, plan.start.targetVersion);
|
|
344
275
|
const onStderr = ctx.progress.bootstrapReporter(runtime, plan.start.targetVersion);
|
|
345
276
|
await ctx.deps.preflight(runtime.ssh, plan, { onStdout, onStderr });
|
|
346
|
-
|
|
347
|
-
assertTransportOpen(runtime);
|
|
277
|
+
gate();
|
|
348
278
|
log('info', `npx preflight ready: @deepseek-ai/dsh@${plan.start.targetVersion}`);
|
|
349
279
|
phase('start', 'starting-remote', { level: plan.level });
|
|
350
280
|
webInfo = await ctx.deps.startWeb(runtime.ssh, {
|
|
@@ -356,14 +286,10 @@ async function connectPipeline(ctx, runtime) {
|
|
|
356
286
|
});
|
|
357
287
|
log('info', `remote DSH started: pid ${webInfo.pid ?? '?'}, port ${webInfo.port}`);
|
|
358
288
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
log('info', 'the remote profile disables api-remotes (browser Remote-Event carrier); re-enabled it for this launch');
|
|
363
|
-
}
|
|
289
|
+
gate();
|
|
290
|
+
if (webInfo.browserCarrier === 'patched')
|
|
291
|
+
log('info', PATCHED_CARRIER_NOTE);
|
|
364
292
|
remoteStarted = true;
|
|
365
|
-
// Only the instance launched by this connection's start script may be stopped later;
|
|
366
|
-
// an adopted one was already recorded above only when its record proves a launch.
|
|
367
293
|
if (webInfo.adopted !== true)
|
|
368
294
|
await rememberLaunched(ctx, runtime, webInfo.pid, layout, profile);
|
|
369
295
|
assertStillWanted(ctx, runtime);
|
|
@@ -387,27 +313,19 @@ async function connectPipeline(ctx, runtime) {
|
|
|
387
313
|
assertStillWanted(ctx, runtime);
|
|
388
314
|
phase('verifying', 'verifying');
|
|
389
315
|
await verifyRemoteUi(ctx, runtime, webInfo.port, webInfo.token, tunnel.localPort);
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
// The remote UI is reachable both ways: the desktop half hands the loopback origin to a
|
|
393
|
-
// Chromium guest, and the browser half frames it through the same-origin proxy (which strips
|
|
394
|
-
// any X-Frame-Options). Either way this exchange proves the launch token works.
|
|
316
|
+
gate();
|
|
317
|
+
// The remote UI is reachable both ways (desktop guest and same-origin proxy): the exchange proves the launch token.
|
|
395
318
|
runtime.remote.uiReady = true;
|
|
396
319
|
await ctx.store.patchHost(runtime.id, { lastOpenedAt: nowIso() });
|
|
397
|
-
|
|
398
|
-
//
|
|
399
|
-
assertStillWanted(ctx, runtime);
|
|
400
|
-
assertTransportOpen(runtime);
|
|
320
|
+
gate();
|
|
321
|
+
// The store write is an await: a disconnect may land meanwhile, and a late write must not resurrect the link.
|
|
401
322
|
runtime.entry = ctx.store.getHost(runtime.id) ?? runtime.entry;
|
|
402
323
|
if (ctx.settings().saveTokens) {
|
|
403
324
|
await ctx.store.saveToken(runtime.id, webInfo.token);
|
|
404
325
|
assertStillWanted(ctx, runtime);
|
|
405
326
|
}
|
|
406
|
-
|
|
407
|
-
//
|
|
408
|
-
assertStillWanted(ctx, runtime);
|
|
409
|
-
assertTransportOpen(runtime);
|
|
410
|
-
// `connect.succeeded` publishes `activeHostId` (the `publish-active-host` patch).
|
|
327
|
+
gate();
|
|
328
|
+
// Last gate before publishing: never report a host the user just removed or a tunnel this pipeline no longer owns.
|
|
411
329
|
await markConnected(ctx, runtime);
|
|
412
330
|
const localPort = runtime.tunnel?.localPort ?? runtime.remote.localPort ?? '?';
|
|
413
331
|
log('info', `connected: remote ${runtime.remote.version} on 127.0.0.1:${localPort}`);
|
|
@@ -415,27 +333,19 @@ async function connectPipeline(ctx, runtime) {
|
|
|
415
333
|
catch (error) {
|
|
416
334
|
// Phase is cleared with the status; capture it first so the log says where it stopped.
|
|
417
335
|
const failedPhase = runtime.phase;
|
|
418
|
-
// The
|
|
419
|
-
// is what the retry policy exists for, even while the remote was still being set up (H3).
|
|
336
|
+
// The link was up earlier in this attempt and is gone now: it dropped, which is what the retry policy is for.
|
|
420
337
|
const droppedTransport = runtime.transportLost === true || (transportUp === true && runtime.ssh?.connected !== true);
|
|
338
|
+
// The transition owns the state, the teardown and the failure lines; the caller keeps only its own
|
|
339
|
+
// publication point.
|
|
421
340
|
const cancelled = error instanceof LinkCancelled || linkTaken(ctx, runtime);
|
|
422
|
-
// The user's "no" is read
|
|
423
|
-
// for the next attempt (today's catch reset it right after the decision), and the decision
|
|
424
|
-
// itself still has to see it. This is the H2 "a refused prompt is final" rule.
|
|
341
|
+
// The user's "no" is read before the failure transition clears the flag: a refused prompt is final.
|
|
425
342
|
const saidNo = runtime.connectCancelled === true;
|
|
426
|
-
// The transition owns the state, the teardown and the failure lines; the caller only keeps
|
|
427
|
-
// its own publication point (the retry decision below emits exactly like the old code) and
|
|
428
|
-
// the one informational line the cancel branch used to write.
|
|
429
343
|
const event = cancelled
|
|
430
344
|
? { type: 'connect.cancelled' }
|
|
431
345
|
: { type: 'connect.failed', view: normalizeConnectFailure(runtime, error), phase: failedPhase };
|
|
432
346
|
await dispatch(createRuntimeEffects(ctx), runtime, event, scopeFactsFor(ctx, runtime, event), {
|
|
433
347
|
caller: 'script',
|
|
434
348
|
emit: false,
|
|
435
|
-
// "A remote was started in this attempt" is this pipeline's own flag (it becomes true
|
|
436
|
-
// before the remote block is written, and survives a failure inside the registry write);
|
|
437
|
-
// the scope can only see the block. Pass the caller's verdict so a cancellation after the
|
|
438
|
-
// remote started still honours the `stop` keep-alive policy.
|
|
439
349
|
teardown: {
|
|
440
350
|
stopRemote: remoteStarted && runtime.entry.keepAlive === 'stop',
|
|
441
351
|
keepRemote: remoteStarted && runtime.entry.keepAlive !== 'stop',
|
|
@@ -443,9 +353,7 @@ async function connectPipeline(ctx, runtime) {
|
|
|
443
353
|
});
|
|
444
354
|
if (cancelled)
|
|
445
355
|
log('info', 'connect cancelled by disconnect');
|
|
446
|
-
// One place decides whether a failed attempt is retried, and the budget lives in
|
|
447
|
-
// `scheduleReconnect` (H2). A user's "no" (host-key/conflict prompt) is final, and a
|
|
448
|
-
// first manual connect that never reached the remote is reported instead of looping.
|
|
356
|
+
// One place decides whether a failed attempt is retried, and the budget lives in `scheduleReconnect`.
|
|
449
357
|
if (!cancelled) {
|
|
450
358
|
const retryable = runtime.error?.retryable !== false && !saidNo;
|
|
451
359
|
const repairAttempt = (Number(runtime.reconnectAttempts) || 0) > 0;
|
|
@@ -458,12 +366,7 @@ async function connectPipeline(ctx, runtime) {
|
|
|
458
366
|
runtime.connectPromise = null;
|
|
459
367
|
}
|
|
460
368
|
}
|
|
461
|
-
/**
|
|
462
|
-
* Arm the next automatic attempt after a failed connect/reconnect; `scheduleReconnect`
|
|
463
|
-
* owns the settings gate and the attempt budget, so a spent budget is reported once.
|
|
464
|
-
* @param {object} ctx - service context.
|
|
465
|
-
* @param {object} runtime - host runtime.
|
|
466
|
-
*/
|
|
369
|
+
/** Arm the next automatic attempt; `scheduleReconnect` owns the settings gate and the budget, so a spent budget is reported once. */
|
|
467
370
|
function scheduleConnectRetry(ctx, runtime) {
|
|
468
371
|
if (ctx.state.disposed === true || runtime.desired !== 'connected')
|
|
469
372
|
return;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The re-attach to a remote web that restarted on its own (plugin-market update, supervisor,
|
|
3
|
-
* remote reboot): re-read the real pid/port, refresh `run/web.json`, rebuild the tunnel, take the
|
|
4
|
-
* new launch token and verify. The SSH session and the host entry are untouched.
|
|
5
|
-
*/
|
|
1
|
+
/** The re-attach to a remote web that restarted on its own (plugin-market update, supervisor, remote reboot): re-read the real pid/port, refresh `run/web.json`, rebuild the tunnel, take the new launch token and verify. The SSH session and the host entry are untouched. */
|
|
6
2
|
import { REMOTE_REATTACH_ATTEMPTS, REMOTE_REATTACH_INTERVAL_MS } from '../constants.js';
|
|
7
3
|
import { errors, toErrorView } from '../errors.js';
|
|
8
4
|
import { closeTunnel, endLinkWork, isLinkWorkCurrent } from '../host-lifecycle.js';
|
|
@@ -14,30 +10,19 @@ import { nowIso, sleep } from '../util.js';
|
|
|
14
10
|
import { normalizeVersion, versionsEqual } from '../version.js';
|
|
15
11
|
import { markConnected, recordRestart } from './attach.js';
|
|
16
12
|
import { SSH_CLOSED_DETAIL } from './failures.js';
|
|
17
|
-
import { LinkCancelled } from './guards.js';
|
|
13
|
+
import { LinkCancelled, linkActionState } from './guards.js';
|
|
18
14
|
import { rememberBound } from './ownership.js';
|
|
19
15
|
import { openTunnelFor } from './transport.js';
|
|
20
16
|
import { verifyRemoteUi } from './verify.js';
|
|
21
|
-
/**
|
|
22
|
-
* Re-attach to a remote web that restarted on its own (plugin-market update, supervisor,
|
|
23
|
-
* remote reboot): re-read the real pid/port, refresh `run/web.json`, rebuild the tunnel,
|
|
24
|
-
* take the new launch token and verify. The SSH session and the host entry are untouched.
|
|
25
|
-
*
|
|
26
|
-
* @param ctx - service context.
|
|
27
|
-
* @param runtime - host runtime the watchdog decided is unreachable.
|
|
28
|
-
* @param info - why the re-attach was requested.
|
|
29
|
-
* @returns whether the re-attach started.
|
|
30
|
-
*/
|
|
31
17
|
export async function reattachHost(ctx, runtime, info = {}) {
|
|
32
|
-
if (runtime
|
|
18
|
+
if (linkActionState(runtime) !== 'connected')
|
|
33
19
|
return { accepted: false, reason: 'not-connected' };
|
|
34
|
-
}
|
|
35
20
|
if (runtime.connectPromise || runtime.linkBusy !== null)
|
|
36
21
|
return { accepted: false, reason: 'busy' };
|
|
37
|
-
// One transition owns `activity`/`epoch`, the `connecting` card and the action start (`run`);
|
|
38
|
-
// the token is the old `beginLinkWork` one so the late-write filter keeps its semantics.
|
|
39
22
|
const token = (Number(runtime.linkToken) || 0) + 1;
|
|
40
23
|
const reason = typeof info?.reason === 'string' && info.reason !== '' ? info.reason : 'remote-unreachable';
|
|
24
|
+
// One transition owns `activity`/`epoch`, the `connecting` card and the action start (`run`); the token
|
|
25
|
+
// is the old `beginLinkWork` one so the late-write filter keeps its semantics.
|
|
41
26
|
const event = { type: 'reattach.requested', token, reason };
|
|
42
27
|
await dispatch(createRuntimeEffects(ctx), runtime, event, scopeFactsFor(ctx, runtime, event), {
|
|
43
28
|
caller: 'script',
|
|
@@ -55,11 +40,6 @@ export async function reattachHost(ctx, runtime, info = {}) {
|
|
|
55
40
|
});
|
|
56
41
|
return { accepted: true };
|
|
57
42
|
}
|
|
58
|
-
/**
|
|
59
|
-
* The action body: the re-attach re-reads the remote state, rewrites the run registry, rebuilds the
|
|
60
|
-
* tunnel and verifies the UI, so it spans all six slices exactly like its entry point — the same
|
|
61
|
-
* `ConnectCtx`, not a copied intersection (the gate's `godCtxParams` entries name it).
|
|
62
|
-
*/
|
|
63
43
|
async function runReattach(ctx, runtime, info, token) {
|
|
64
44
|
const log = (level, ...args) => ctx.progress.log(runtime, level, ...args);
|
|
65
45
|
const phase = (name, code, params) => ctx.progress.phase(runtime, name, code, params);
|
|
@@ -69,27 +49,24 @@ async function runReattach(ctx, runtime, info, token) {
|
|
|
69
49
|
const reason = typeof info?.reason === 'string' && info.reason !== '' ? info.reason : 'remote-unreachable';
|
|
70
50
|
let tunnelCreated = false;
|
|
71
51
|
try {
|
|
72
|
-
// `reattach.requested` already disarmed the timers and published the `restarting-remote` card.
|
|
73
52
|
log('info', `remote restart suspected: ${reason}; re-reading the remote state`);
|
|
74
|
-
// A restart takes a moment to print its new readiness line: retry before giving up.
|
|
75
53
|
const attempts = Math.max(1, Number(ctx.timers.reattachAttempts) || REMOTE_REATTACH_ATTEMPTS);
|
|
76
54
|
const intervalMs = Math.max(0, Number(ctx.timers.reattachIntervalMs ?? REMOTE_REATTACH_INTERVAL_MS) || 0);
|
|
77
55
|
let resolved = null;
|
|
56
|
+
// A restart takes a moment to print its new readiness line: retry before giving up.
|
|
78
57
|
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
79
58
|
if (!isLinkWorkCurrent(runtime, token))
|
|
80
59
|
return;
|
|
81
60
|
resolved = await ctx.deps.resolveRemote(runtime.ssh, layout, { profile });
|
|
82
61
|
if (resolved?.ok === true)
|
|
83
62
|
break;
|
|
84
|
-
|
|
63
|
+
const why = resolved?.reason ?? 'unreadable';
|
|
64
|
+
log('debug', `re-attach: remote state not ready yet (${why}), attempt ${attempt}/${attempts}`);
|
|
85
65
|
if (attempt < attempts && intervalMs > 0)
|
|
86
66
|
await sleep(intervalMs);
|
|
87
67
|
}
|
|
88
68
|
if (!isLinkWorkCurrent(runtime, token))
|
|
89
69
|
return;
|
|
90
|
-
// `resolved?.ok !== true` is the same test as `!resolved || resolved.ok !== true`, and it is
|
|
91
|
-
// the form the compiler can narrow: with `strictNullChecks` off the disjunction's `!resolved`
|
|
92
|
-
// arm widens the branch back to the whole union.
|
|
93
70
|
if (resolved?.ok !== true) {
|
|
94
71
|
const detail = resolved?.reason === 'no-token'
|
|
95
72
|
? {
|
|
@@ -104,8 +81,8 @@ async function runReattach(ctx, runtime, info, token) {
|
|
|
104
81
|
technical: `reason=${resolved?.reason ?? 'unknown'} fromPort=${fromPort ?? 'unknown'}`,
|
|
105
82
|
});
|
|
106
83
|
}
|
|
107
|
-
// A takeover needs the new launch token: a real DSH rejects `/?token=` and a cookie-less
|
|
108
|
-
//
|
|
84
|
+
// A takeover needs the new launch token: a real DSH rejects `/?token=` and a cookie-less request,
|
|
85
|
+
// so an empty token can never be treated as success.
|
|
109
86
|
if (typeof resolved.token !== 'string' || resolved.token === '') {
|
|
110
87
|
throw errors.remoteUnreachable({
|
|
111
88
|
zh: '远端 DSH 重启后没有留下可用的 launch token,无法自动重新挂载;请点「重启」或「重连」。',
|
|
@@ -114,16 +91,15 @@ async function runReattach(ctx, runtime, info, token) {
|
|
|
114
91
|
}
|
|
115
92
|
const targetVersion = ctx.localVersion();
|
|
116
93
|
const remoteVersion = typeof resolved.version === 'string' && resolved.version !== '' ? normalizeVersion(resolved.version) : null;
|
|
94
|
+
// A different DSH under the same ~/.dsh would show a UI that does not match this machine; the
|
|
95
|
+
// user's remedy is the explicit restart, which launches the pinned version.
|
|
117
96
|
if (remoteVersion && targetVersion && !versionsEqual(remoteVersion, targetVersion)) {
|
|
118
|
-
// A different DSH under the same ~/.dsh would show a UI that does not match this machine;
|
|
119
|
-
// the user's remedy is the explicit restart, which launches the pinned version.
|
|
120
97
|
throw errors.versionMismatch(targetVersion, remoteVersion);
|
|
121
98
|
}
|
|
122
|
-
if (remoteVersion === null)
|
|
99
|
+
if (remoteVersion === null)
|
|
123
100
|
log('warn', 're-attach: the running DSH version could not be proven; keeping it unknown, not assuming the local one');
|
|
124
|
-
|
|
125
|
-
//
|
|
126
|
-
// spawns the DSH). Keep the kill right only for the pid we are now attached to.
|
|
101
|
+
// The pid that listens may differ from the wrapper this connection launched (npx spawns the DSH):
|
|
102
|
+
// keep the kill right only for the pid we are now attached to.
|
|
127
103
|
if (runtime.launched instanceof Map) {
|
|
128
104
|
for (const pid of [...runtime.launched.keys()]) {
|
|
129
105
|
if (pid !== resolved.pid)
|
|
@@ -173,8 +149,8 @@ async function runReattach(ctx, runtime, info, token) {
|
|
|
173
149
|
await ctx.store.saveToken(runtime.id, resolved.token);
|
|
174
150
|
if (!isLinkWorkCurrent(runtime, token))
|
|
175
151
|
return;
|
|
176
|
-
// The re-attached instance is now the one this connection is bound to
|
|
177
|
-
// `launched` (a restart must not kill it), but the explicit stop
|
|
152
|
+
// The re-attached instance is now the one this connection is bound to: it stays out of
|
|
153
|
+
// `launched` (a restart must not kill it), but the explicit stop may end exactly it.
|
|
178
154
|
await rememberBound(ctx, runtime, resolved.pid, layout, profile, 'reattach');
|
|
179
155
|
if (!isLinkWorkCurrent(runtime, token))
|
|
180
156
|
return;
|
|
@@ -197,8 +173,8 @@ async function runReattach(ctx, runtime, info, token) {
|
|
|
197
173
|
const view = error instanceof LinkCancelled
|
|
198
174
|
? toErrorView(errors.network(SSH_CLOSED_DETAIL, { technical: 'reason=ssh-closed during re-attach' }))
|
|
199
175
|
: toErrorView(error);
|
|
200
|
-
// The transition owns the error state, the listener release, the heartbeat disarm, the
|
|
201
|
-
//
|
|
176
|
+
// The transition owns the error state, the listener release, the heartbeat disarm, the failure lines
|
|
177
|
+
// (which read the phase they are about to clear) and the publication.
|
|
202
178
|
const failure = { type: 'reattach.failed', view };
|
|
203
179
|
await dispatch(createRuntimeEffects(ctx), runtime, failure, scopeFactsFor(ctx, runtime, failure), {
|
|
204
180
|
caller: 'script',
|
|
@@ -207,7 +183,7 @@ async function runReattach(ctx, runtime, info, token) {
|
|
|
207
183
|
ctx.emitState();
|
|
208
184
|
}
|
|
209
185
|
finally {
|
|
210
|
-
// A listener this action created must never outlive the action (see runRestart).
|
|
186
|
+
// A listener this action created must never outlive the action (see `runRestart`).
|
|
211
187
|
if (tunnelCreated && !isLinkWorkCurrent(runtime, token))
|
|
212
188
|
await closeTunnel(runtime);
|
|
213
189
|
endLinkWork(runtime, token);
|
|
@@ -4,7 +4,6 @@ export async function readRegistryQuietly(ctx, runtime, layout) {
|
|
|
4
4
|
return await ctx.deps.readRegistry(runtime.ssh, layout);
|
|
5
5
|
}
|
|
6
6
|
catch (error) {
|
|
7
|
-
// swallow-ok: registry absence only means the restart cannot attribute the running pid
|
|
8
7
|
ctx.progress.log(runtime, 'debug', 'restart: registry read failed:', messageOf(error));
|
|
9
8
|
return null;
|
|
10
9
|
}
|