@parall/daemon 1.69.0 → 1.71.0
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/bundle/manifest.json +13 -13
- package/bundle/parall-browser-pod.js +137 -47
- package/bundle/parall-channel-exec.js +59 -34
- package/bundle/parall-claude-agent.js +160 -33
- package/bundle/parall-codex-agent.js +160 -33
- package/bundle/parall-daemon.js +285 -120
- package/dist/clip-runtime/clip-provider.d.ts +4 -0
- package/dist/clip-runtime/clip-provider.d.ts.map +1 -1
- package/dist/clip-runtime/clip-provider.js +16 -43
- package/dist/clip-runtime/connect-envelope.d.ts +22 -0
- package/dist/clip-runtime/connect-envelope.d.ts.map +1 -0
- package/dist/clip-runtime/connect-envelope.js +42 -0
- package/dist/clip-runtime/hub-client.d.ts.map +1 -1
- package/dist/clip-runtime/hub-client.js +1 -34
- package/dist/config.d.ts +11 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -0
- package/dist/daemon-main.d.ts.map +1 -1
- package/dist/daemon-main.js +11 -0
- package/dist/supervisor.d.ts +11 -0
- package/dist/supervisor.d.ts.map +1 -1
- package/dist/supervisor.js +59 -63
- package/dist/updater.d.ts +9 -0
- package/dist/updater.d.ts.map +1 -1
- package/dist/updater.js +18 -4
- package/package.json +6 -6
|
@@ -39,6 +39,9 @@ export interface ClipProviderOptions {
|
|
|
39
39
|
* re-trigger machine.hello. Optional.
|
|
40
40
|
*/
|
|
41
41
|
onPersistentFailure?: () => void;
|
|
42
|
+
/** Retry delay after the hub rejects registration. BYOC sets it (a rejected mck_ can
|
|
43
|
+
* recover); hosted pods leave it unset and stop (their lease was superseded). */
|
|
44
|
+
rejectedRetryDelayMs?: (attempt: number) => number;
|
|
42
45
|
/**
|
|
43
46
|
* Hosted-browser live-viewer handler. Set ONLY for a hosted browser pod
|
|
44
47
|
* (browser-pod.ts): clip-service relays viewer commands down the
|
|
@@ -68,6 +71,7 @@ export declare class ClipProvider {
|
|
|
68
71
|
private stopped;
|
|
69
72
|
private connected;
|
|
70
73
|
private reconnectAttempt;
|
|
74
|
+
private rejectedAttempt;
|
|
71
75
|
private reconnectTimer;
|
|
72
76
|
private heartbeatTimer;
|
|
73
77
|
private statusUnsubscribe;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clip-provider.d.ts","sourceRoot":"","sources":["../../src/clip-runtime/clip-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;
|
|
1
|
+
{"version":3,"file":"clip-provider.d.ts","sourceRoot":"","sources":["../../src/clip-runtime/clip-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAOH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAgJ/D,MAAM,WAAW,mBAAmB;IAClC,sDAAsD;IACtD,UAAU,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,YAAY,EAAE,MAAM,CAAC;IACrB,yDAAyD;IACzD,WAAW,EAAE,kBAAkB,CAAC;IAChC,mBAAmB;IACnB,GAAG,EAAE;QAAE,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IACpF;;;;;;OAMG;IACH,mBAAmB,CAAC,EAAE,MAAM,IAAI,CAAC;IACjC;sFACkF;IAClF,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;IACnD;;;;;;;;OAQG;IACH,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE;QACtB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAA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AAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,cAAc;IAgBtB;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,eAAe;IAsBvB;;;;;OAKG;IACH,UAAU,IAAI,IAAI;IAKlB,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,sBAAsB;IA2B9B,OAAO,CAAC,wBAAwB;IAWhC,OAAO,CAAC,gBAAgB;IAexB,OAAO,CAAC,gBAAgB;YA0BV,mBAAmB;IAsEjC;;;;;;OAMG;YACW,mBAAmB;IA4CjC,2EAA2E;YAC7D,eAAe;YAYf,YAAY;YAaZ,mBAAmB;IAiBjC,OAAO,CAAC,sBAAsB;IAQ9B,OAAO,CAAC,wBAAwB;IAuBhC,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,cAAc;CAUvB"}
|
|
@@ -15,21 +15,10 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import * as http2 from 'node:http2';
|
|
17
17
|
import { isBrowserDependencyName } from './browser-dependency.js';
|
|
18
|
+
import { ENVELOPE_FLAG_TRAILER, EnvelopeDecoder, encodeEnvelope } from './connect-envelope.js';
|
|
18
19
|
import { ClipCommandError } from './process.js';
|
|
19
20
|
import { isViewerReadinessCommand, parseViewerDispatchDeadlineUnixMs, viewerReadinessDeadlineError, } from './viewer-command-deadline.js';
|
|
20
21
|
import { viewerCommandFailure } from './viewer-command-error.js';
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
|
-
// Connect envelope helpers
|
|
23
|
-
// ---------------------------------------------------------------------------
|
|
24
|
-
const ENVELOPE_FLAG_DATA = 0x00;
|
|
25
|
-
const ENVELOPE_FLAG_TRAILER = 0x02;
|
|
26
|
-
function encodeEnvelope(msg) {
|
|
27
|
-
const json = Buffer.from(JSON.stringify(msg), 'utf-8');
|
|
28
|
-
const header = Buffer.alloc(5);
|
|
29
|
-
header[0] = ENVELOPE_FLAG_DATA;
|
|
30
|
-
header.writeUInt32BE(json.length, 1);
|
|
31
|
-
return Buffer.concat([header, json]);
|
|
32
|
-
}
|
|
33
22
|
/**
|
|
34
23
|
* Canonical key for a clip-registration set — used by flushReregister to skip a
|
|
35
24
|
* re-register that would not change the hub's view. Sorted by alias so set
|
|
@@ -41,33 +30,6 @@ function registrationKey(clips) {
|
|
|
41
30
|
const sorted = [...clips].sort((a, b) => (a.alias ?? '').localeCompare(b.alias ?? ''));
|
|
42
31
|
return JSON.stringify(sorted);
|
|
43
32
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Incremental envelope decoder. Feed chunks via push(), receive decoded
|
|
46
|
-
* messages from flush(). Handles partial reads across chunk boundaries.
|
|
47
|
-
*/
|
|
48
|
-
class EnvelopeDecoder {
|
|
49
|
-
buf = Buffer.alloc(0);
|
|
50
|
-
push(chunk) {
|
|
51
|
-
this.buf = this.buf.length === 0 ? Buffer.from(chunk) : Buffer.concat([this.buf, chunk]);
|
|
52
|
-
}
|
|
53
|
-
/** Drain all complete envelopes from the internal buffer. */
|
|
54
|
-
static MAX_FRAME_LENGTH = 16 * 1024 * 1024; // 16 MiB
|
|
55
|
-
*flush() {
|
|
56
|
-
while (this.buf.length >= 5) {
|
|
57
|
-
const flags = this.buf[0];
|
|
58
|
-
const length = this.buf.readUInt32BE(1);
|
|
59
|
-
if (length > EnvelopeDecoder.MAX_FRAME_LENGTH) {
|
|
60
|
-
this.buf = Buffer.alloc(0);
|
|
61
|
-
throw new Error(`envelope frame too large: ${length} bytes`);
|
|
62
|
-
}
|
|
63
|
-
if (this.buf.length < 5 + length)
|
|
64
|
-
break; // incomplete frame
|
|
65
|
-
const payload = this.buf.subarray(5, 5 + length);
|
|
66
|
-
this.buf = Buffer.from(this.buf.subarray(5 + length));
|
|
67
|
-
yield { flags, payload };
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
33
|
export class ClipProvider {
|
|
72
34
|
opts;
|
|
73
35
|
session = null;
|
|
@@ -75,6 +37,7 @@ export class ClipProvider {
|
|
|
75
37
|
stopped = false;
|
|
76
38
|
connected = false;
|
|
77
39
|
reconnectAttempt = 0;
|
|
40
|
+
rejectedAttempt = 0;
|
|
78
41
|
reconnectTimer = null;
|
|
79
42
|
heartbeatTimer = null;
|
|
80
43
|
statusUnsubscribe = null;
|
|
@@ -202,10 +165,11 @@ export class ClipProvider {
|
|
|
202
165
|
this.clearHeartbeatTimer();
|
|
203
166
|
this.scheduleReconnect();
|
|
204
167
|
}
|
|
205
|
-
scheduleReconnect() {
|
|
168
|
+
scheduleReconnect(delayMs) {
|
|
206
169
|
if (this.stopped || this.reconnectTimer)
|
|
207
170
|
return;
|
|
208
|
-
const delay =
|
|
171
|
+
const delay = delayMs ??
|
|
172
|
+
Math.min(ClipProvider.RECONNECT_BASE_MS * Math.pow(2, this.reconnectAttempt), ClipProvider.RECONNECT_MAX_MS);
|
|
209
173
|
this.reconnectAttempt++;
|
|
210
174
|
this.opts.log.info(`[clip-provider] reconnecting in ${delay}ms (attempt ${this.reconnectAttempt})`);
|
|
211
175
|
if (this.reconnectAttempt % ClipProvider.PERSISTENT_FAILURE_ATTEMPT === 0) {
|
|
@@ -384,6 +348,7 @@ export class ClipProvider {
|
|
|
384
348
|
this.opts.log.info(`[clip-provider] registered with hub (org=${this.opts.orgId})`);
|
|
385
349
|
this.connected = true;
|
|
386
350
|
this.reconnectAttempt = 0;
|
|
351
|
+
this.rejectedAttempt = 0;
|
|
387
352
|
this.startHeartbeat();
|
|
388
353
|
// A manifest change that landed during the connect handshake (after the
|
|
389
354
|
// initial register was sent) is flushed now that the stream is writable.
|
|
@@ -391,8 +356,16 @@ export class ClipProvider {
|
|
|
391
356
|
}
|
|
392
357
|
else {
|
|
393
358
|
this.opts.log.error(`[clip-provider] registration rejected: ${reg.message}`);
|
|
394
|
-
|
|
395
|
-
|
|
359
|
+
this.connected = false;
|
|
360
|
+
const retryDelay = this.opts.rejectedRetryDelayMs?.(this.rejectedAttempt++);
|
|
361
|
+
if (retryDelay === undefined) {
|
|
362
|
+
this.stopped = true;
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
// The pending timer also makes the rejected stream's late close a no-op.
|
|
366
|
+
this.clearHeartbeatTimer();
|
|
367
|
+
this.scheduleReconnect(retryDelay);
|
|
368
|
+
}
|
|
396
369
|
this.closeStream();
|
|
397
370
|
this.closeSession();
|
|
398
371
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connect protocol envelope framing (JSON mode), shared by the ProviderStream
|
|
3
|
+
* (clip-provider.ts) and the execution-side hub client (hub-client.ts):
|
|
4
|
+
* [flags:1][length:4 big-endian][JSON payload]
|
|
5
|
+
* flags=0x00 data, flags=0x02 end-of-stream (trailers)
|
|
6
|
+
*/
|
|
7
|
+
export declare const ENVELOPE_FLAG_TRAILER = 2;
|
|
8
|
+
export declare function encodeEnvelope(msg: unknown): Buffer;
|
|
9
|
+
/**
|
|
10
|
+
* Incremental envelope decoder. Feed chunks via push(), receive decoded
|
|
11
|
+
* messages from flush(). Handles partial reads across chunk boundaries.
|
|
12
|
+
*/
|
|
13
|
+
export declare class EnvelopeDecoder {
|
|
14
|
+
private buf;
|
|
15
|
+
push(chunk: Buffer): void;
|
|
16
|
+
/** Drain all complete envelopes from the internal buffer. */
|
|
17
|
+
flush(): Generator<{
|
|
18
|
+
flags: number;
|
|
19
|
+
payload: Buffer;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=connect-envelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect-envelope.d.ts","sourceRoot":"","sources":["../../src/clip-runtime/connect-envelope.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,eAAO,MAAM,qBAAqB,IAAO,CAAC;AAG1C,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAMnD;AAED;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,GAAG,CAAmB;IAE9B,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIzB,6DAA6D;IAC5D,KAAK,IAAI,SAAS,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAcxD"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connect protocol envelope framing (JSON mode), shared by the ProviderStream
|
|
3
|
+
* (clip-provider.ts) and the execution-side hub client (hub-client.ts):
|
|
4
|
+
* [flags:1][length:4 big-endian][JSON payload]
|
|
5
|
+
* flags=0x00 data, flags=0x02 end-of-stream (trailers)
|
|
6
|
+
*/
|
|
7
|
+
const ENVELOPE_FLAG_DATA = 0x00;
|
|
8
|
+
export const ENVELOPE_FLAG_TRAILER = 0x02;
|
|
9
|
+
const MAX_FRAME_LENGTH = 16 * 1024 * 1024; // 16 MiB
|
|
10
|
+
export function encodeEnvelope(msg) {
|
|
11
|
+
const json = Buffer.from(JSON.stringify(msg), 'utf-8');
|
|
12
|
+
const header = Buffer.alloc(5);
|
|
13
|
+
header[0] = ENVELOPE_FLAG_DATA;
|
|
14
|
+
header.writeUInt32BE(json.length, 1);
|
|
15
|
+
return Buffer.concat([header, json]);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Incremental envelope decoder. Feed chunks via push(), receive decoded
|
|
19
|
+
* messages from flush(). Handles partial reads across chunk boundaries.
|
|
20
|
+
*/
|
|
21
|
+
export class EnvelopeDecoder {
|
|
22
|
+
buf = Buffer.alloc(0);
|
|
23
|
+
push(chunk) {
|
|
24
|
+
this.buf = this.buf.length === 0 ? Buffer.from(chunk) : Buffer.concat([this.buf, chunk]);
|
|
25
|
+
}
|
|
26
|
+
/** Drain all complete envelopes from the internal buffer. */
|
|
27
|
+
*flush() {
|
|
28
|
+
while (this.buf.length >= 5) {
|
|
29
|
+
const flags = this.buf[0];
|
|
30
|
+
const length = this.buf.readUInt32BE(1);
|
|
31
|
+
if (length > MAX_FRAME_LENGTH) {
|
|
32
|
+
this.buf = Buffer.alloc(0);
|
|
33
|
+
throw new Error(`envelope frame too large: ${length} bytes`);
|
|
34
|
+
}
|
|
35
|
+
if (this.buf.length < 5 + length)
|
|
36
|
+
break; // incomplete frame
|
|
37
|
+
const payload = this.buf.subarray(5, 5 + length);
|
|
38
|
+
this.buf = Buffer.from(this.buf.subarray(5 + length));
|
|
39
|
+
yield { flags, payload };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hub-client.d.ts","sourceRoot":"","sources":["../../src/clip-runtime/hub-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;
|
|
1
|
+
{"version":3,"file":"hub-client.d.ts","sourceRoot":"","sources":["../../src/clip-runtime/hub-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAWH,gEAAgE;AAChE,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAaD;;;;;GAKG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;gBACX,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;CAK3C;AAED,MAAM,WAAW,gBAAgB;IAC/B,4DAA4D;IAC5D,UAAU,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,OAAO,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;GAIG;AACH,qBAAa,SAAS;IACR,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,gBAAgB;IAEnD;;;;OAIG;IACG,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAOvE;;;;OAIG;IACG,MAAM,CACV,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC;IAgCnB;;;;OAIG;IACH,OAAO,CAAC,KAAK;IAgEb;;;OAGG;IACH,OAAO,CAAC,YAAY;CAiGrB"}
|
|
@@ -20,41 +20,8 @@
|
|
|
20
20
|
* flags=0x00 data, flags=0x02 end-of-stream (trailers)
|
|
21
21
|
*/
|
|
22
22
|
import * as http2 from 'node:http2';
|
|
23
|
-
|
|
24
|
-
// Connect envelope helpers (mirror clip-provider.ts; JSON mode)
|
|
25
|
-
// ---------------------------------------------------------------------------
|
|
26
|
-
const ENVELOPE_FLAG_DATA = 0x00;
|
|
27
|
-
const ENVELOPE_FLAG_TRAILER = 0x02;
|
|
28
|
-
const MAX_FRAME_LENGTH = 16 * 1024 * 1024; // 16 MiB
|
|
23
|
+
import { ENVELOPE_FLAG_TRAILER, EnvelopeDecoder, encodeEnvelope } from './connect-envelope.js';
|
|
29
24
|
const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
|
|
30
|
-
function encodeEnvelope(msg) {
|
|
31
|
-
const json = Buffer.from(JSON.stringify(msg), 'utf-8');
|
|
32
|
-
const header = Buffer.alloc(5);
|
|
33
|
-
header[0] = ENVELOPE_FLAG_DATA;
|
|
34
|
-
header.writeUInt32BE(json.length, 1);
|
|
35
|
-
return Buffer.concat([header, json]);
|
|
36
|
-
}
|
|
37
|
-
class EnvelopeDecoder {
|
|
38
|
-
buf = Buffer.alloc(0);
|
|
39
|
-
push(chunk) {
|
|
40
|
-
this.buf = this.buf.length === 0 ? Buffer.from(chunk) : Buffer.concat([this.buf, chunk]);
|
|
41
|
-
}
|
|
42
|
-
*flush() {
|
|
43
|
-
while (this.buf.length >= 5) {
|
|
44
|
-
const flags = this.buf[0];
|
|
45
|
-
const length = this.buf.readUInt32BE(1);
|
|
46
|
-
if (length > MAX_FRAME_LENGTH) {
|
|
47
|
-
this.buf = Buffer.alloc(0);
|
|
48
|
-
throw new Error(`envelope frame too large: ${length} bytes`);
|
|
49
|
-
}
|
|
50
|
-
if (this.buf.length < 5 + length)
|
|
51
|
-
break; // incomplete frame
|
|
52
|
-
const payload = this.buf.subarray(5, 5 + length);
|
|
53
|
-
this.buf = Buffer.from(this.buf.subarray(5 + length));
|
|
54
|
-
yield { flags, payload };
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
25
|
/**
|
|
59
26
|
* Error surfaced by a hub Invoke that the hub flagged as a clip
|
|
60
27
|
* application-level rejection (errorIsCommand=true). The execution-side IPC
|
package/dist/config.d.ts
CHANGED
|
@@ -40,6 +40,17 @@ export type ClaudeDaemonConfig = {
|
|
|
40
40
|
*/
|
|
41
41
|
bootstrapBackoffMs: number;
|
|
42
42
|
bootstrapBackoffMaxMs: number;
|
|
43
|
+
/**
|
|
44
|
+
* Retry schedule once the server rejects this machine's key (401): boot
|
|
45
|
+
* identity probe, machine WS, and clip ProviderStream all back off
|
|
46
|
+
* exponentially from `credentialRetryBackoffMs` up to
|
|
47
|
+
* `credentialRetryBackoffMaxMs`. Slow, because the same key keeps failing
|
|
48
|
+
* until someone re-registers; never terminal, because a rejected key can
|
|
49
|
+
* become valid again (owner re-enabled, server-side policy change, a DB
|
|
50
|
+
* error the server reported as 401).
|
|
51
|
+
*/
|
|
52
|
+
credentialRetryBackoffMs: number;
|
|
53
|
+
credentialRetryBackoffMaxMs: number;
|
|
43
54
|
/**
|
|
44
55
|
* Outer supervisor keepalive: if `supervisor.run()` rejects with an
|
|
45
56
|
* unexpected error, wait this long and reinstantiate. Same exp-backoff
|
package/dist/config.d.ts.map
CH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|
restartBackoffMaxMs: parseMs(env.PRLL_DAEMON_RESTART_BACKOFF_MAX_MS, 5 * 60_000),
|
|
85
85
|
bootstrapBackoffMs: parseMsAllowZero(env.PRLL_DAEMON_BOOTSTRAP_BACKOFF_MS, 2_000),
|
|
86
86
|
bootstrapBackoffMaxMs: parseMs(env.PRLL_DAEMON_BOOTSTRAP_BACKOFF_MAX_MS, 60_000),
|
|
87
|
+
credentialRetryBackoffMs: parseMs(env.PRLL_DAEMON_CREDENTIAL_RETRY_BACKOFF_MS, 60_000),
|
|
88
|
+
credentialRetryBackoffMaxMs: parseMs(env.PRLL_DAEMON_CREDENTIAL_RETRY_BACKOFF_MAX_MS, 15 * 60_000),
|
|
87
89
|
supervisorRestartBackoffMs: parseMsAllowZero(env.PRLL_DAEMON_SUPERVISOR_RESTART_BACKOFF_MS, 5_000),
|
|
88
90
|
supervisorRestartBackoffMaxMs: parseMs(env.PRLL_DAEMON_SUPERVISOR_RESTART_BACKOFF_MAX_MS, 5 * 60_000),
|
|
89
91
|
updateCdnUrl: env.PRLL_DAEMON_UPDATE_CDN_URL?.trim() ||
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"daemon-main.d.ts","sourceRoot":"","sources":["../src/daemon-main.ts"],"names":[],"mappings":";AA+BA,MAAM,MAAM,oBAAoB,GAAG;IACjC,sBAAsB,EAAE,OAAO,CAAC;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,OAAO,CAAC;CAC1B,CAAC;
|
|
1
|
+
{"version":3,"file":"daemon-main.d.ts","sourceRoot":"","sources":["../src/daemon-main.ts"],"names":[],"mappings":";AA+BA,MAAM,MAAM,oBAAoB,GAAG;IACjC,sBAAsB,EAAE,OAAO,CAAC;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,OAAO,CAAC;CAC1B,CAAC;AA4NF,wBAAsB,cAAc,CAClC,SAAS,EAAE,oBAAoB,EAC/B,IAAI,WAAwB,GAC3B,OAAO,CAAC,IAAI,CAAC,CASf"}
|
package/dist/daemon-main.js
CHANGED
|
@@ -163,6 +163,7 @@ async function main(bootstrap) {
|
|
|
163
163
|
});
|
|
164
164
|
config.wsUrl = resolveWsUrl(config.apiUrl, config.wsUrl, config.swimlaneName);
|
|
165
165
|
// --- Self-update: boot check + periodic timer ---
|
|
166
|
+
let restartForUpdate = false;
|
|
166
167
|
if (updater) {
|
|
167
168
|
const applied = await updater.checkAndApply().catch((err) => {
|
|
168
169
|
log.warn(`boot update check failed: ${String(err)}`);
|
|
@@ -174,11 +175,21 @@ async function main(bootstrap) {
|
|
|
174
175
|
await telemetry.shutdown();
|
|
175
176
|
process.exit(UPDATE_EXIT_CODE);
|
|
176
177
|
}
|
|
178
|
+
// Updates installed after boot (periodic check, WS push) restart through
|
|
179
|
+
// here: abort stops the supervisor cleanly, then we exit 42 below.
|
|
180
|
+
updater.setRestartHandler(() => {
|
|
181
|
+
restartForUpdate = true;
|
|
182
|
+
abortController.abort();
|
|
183
|
+
});
|
|
177
184
|
updater.startPeriodicCheck(config.updateIntervalMs);
|
|
178
185
|
}
|
|
179
186
|
await runForever(config, client, log, abortController.signal, updater, healthGate, daemonTelemetry);
|
|
180
187
|
daemonTelemetry.stop();
|
|
181
188
|
await telemetry.shutdown();
|
|
189
|
+
if (restartForUpdate) {
|
|
190
|
+
log.info('daemon update applied — exiting for service manager restart');
|
|
191
|
+
process.exit(UPDATE_EXIT_CODE);
|
|
192
|
+
}
|
|
182
193
|
}
|
|
183
194
|
export async function runDaemonEntry(bootstrap, args = process.argv.slice(2)) {
|
|
184
195
|
try {
|
package/dist/supervisor.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ export declare class DaemonSupervisor {
|
|
|
38
38
|
private readonly pendingConfigRefresh;
|
|
39
39
|
private readonly restartingStates;
|
|
40
40
|
private ws;
|
|
41
|
+
private wsAuthRetryTimer;
|
|
42
|
+
private wsAuthRetryAttempt;
|
|
41
43
|
private running;
|
|
42
44
|
private machineId;
|
|
43
45
|
/**
|
|
@@ -84,6 +86,15 @@ export declare class DaemonSupervisor {
|
|
|
84
86
|
run(signal: AbortSignal): Promise<void>;
|
|
85
87
|
/** Disconnect WS, cancel timers, SIGTERM all children, await exit. */
|
|
86
88
|
stop(): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* The SDK stops after its small auth budget; re-arm it on the slow credential
|
|
91
|
+
* schedule (connect() from auth-invalid grants a fresh budget). Running
|
|
92
|
+
* children keep their own agk_ and are left alone; machine.hello on
|
|
93
|
+
* reconnect replays whatever was missed.
|
|
94
|
+
*/
|
|
95
|
+
private handleMachineWsAuthInvalid;
|
|
96
|
+
/** Slow schedule shared by every machine-key rejection retry (boot, WS, ProviderStream). */
|
|
97
|
+
private credentialRetryDelay;
|
|
87
98
|
private bootstrapWithRetry;
|
|
88
99
|
private fullReconcile;
|
|
89
100
|
private wipeBeforeRevive;
|
package/dist/supervisor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../src/supervisor.ts"],"names":[],"mappings":"AAmBA,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAiBL,KAAK,YAAY,
|
|
1
|
+
{"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../src/supervisor.ts"],"names":[],"mappings":"AAmBA,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAiBL,KAAK,YAAY,EAGlB,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,KAAK,eAAe,EAAyC,MAAM,uBAAuB,CAAC;AAUpG,OAAO,EAKL,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,KAAK,4BAA4B,EAElC,MAAM,4BAA4B,CAAC;AAepC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,uBAAuB,E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Ac;CAwB7B"}
|
package/dist/supervisor.js
CHANGED
|
@@ -28,15 +28,16 @@ const RUNTIME_PACKAGES = {
|
|
|
28
28
|
openclaw: '@parall/openclaw-agent',
|
|
29
29
|
};
|
|
30
30
|
const WORKSPACE_SETUP_RETRY_DELAY_MS = 5_000;
|
|
31
|
-
/** Idle interval that keeps a machine-key-rejected (parked) daemon on the event loop. */
|
|
32
|
-
const PARK_KEEPALIVE_MS = 60_000;
|
|
33
31
|
/**
|
|
34
32
|
* Recovery guidance logged whenever the server rejects this machine's key.
|
|
35
|
-
* Machine keys do not expire
|
|
36
|
-
*
|
|
37
|
-
*
|
|
33
|
+
* Machine keys do not expire. A rejection can clear on its own (owner
|
|
34
|
+
* re-enabled, server-side change), so the daemon keeps retrying on the slow
|
|
35
|
+
* credential schedule; a key that was revoked, rotated away, or whose Machine
|
|
36
|
+
* was deleted or owner left the org never recovers without a new registration.
|
|
38
37
|
*/
|
|
39
|
-
const MACHINE_KEY_RECOVERY = '
|
|
38
|
+
const MACHINE_KEY_RECOVERY = 'The daemon keeps retrying and reconnects by itself if the key becomes valid again. ' +
|
|
39
|
+
'If it keeps failing, the key was revoked or rotated, this machine was deleted, or its ' +
|
|
40
|
+
'owner left the org: re-register this machine to get a new key — Desktop app: "Disable daemon", then ' +
|
|
40
41
|
'"Enable daemon" (this registers a new machine and tries to delete the old one; ' +
|
|
41
42
|
're-attach its agents); CLI or server: ' +
|
|
42
43
|
'create a machine under Compute in Parall and run `parall-daemon init` with its key — ' +
|
|
@@ -116,6 +117,9 @@ export class DaemonSupervisor {
|
|
|
116
117
|
// registration check already keeps the stale state from ever spawning.
|
|
117
118
|
restartingStates = new Set();
|
|
118
119
|
ws = null;
|
|
120
|
+
// Slow re-arm of the machine WS after the server rejected this machine's key.
|
|
121
|
+
wsAuthRetryTimer = null;
|
|
122
|
+
wsAuthRetryAttempt = 0;
|
|
119
123
|
running = false;
|
|
120
124
|
machineId = null;
|
|
121
125
|
/**
|
|
@@ -319,20 +323,9 @@ export class DaemonSupervisor {
|
|
|
319
323
|
});
|
|
320
324
|
this.ws.on('machine.update', (data) => {
|
|
321
325
|
this.log.info(`WS: daemon update available — version=${data.new_version} mandatory=${data.mandatory}`);
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
.then(async (applied) => {
|
|
326
|
-
if (applied) {
|
|
327
|
-
this.log.info('daemon update applied — stopping supervisor before restart');
|
|
328
|
-
await this.stop();
|
|
329
|
-
process.exit(42);
|
|
330
|
-
}
|
|
331
|
-
})
|
|
332
|
-
.catch((err) => {
|
|
333
|
-
this.log.warn(`daemon update failed: ${String(err)}`);
|
|
334
|
-
});
|
|
335
|
-
}
|
|
326
|
+
// An applied update restarts through the updater's restart handler
|
|
327
|
+
// (daemon-main), the same path the periodic check takes.
|
|
328
|
+
void this.updater?.triggerUpdate(data.new_version, data.mandatory);
|
|
336
329
|
});
|
|
337
330
|
this.ws.on('machine.agent.attached', (data) => {
|
|
338
331
|
this.log.info(`WS: agent ${data.agent_id} attached`);
|
|
@@ -391,17 +384,10 @@ export class DaemonSupervisor {
|
|
|
391
384
|
if (state === 'reconnecting') {
|
|
392
385
|
this.daemonTelemetry?.recordWsReconnect({ cause: detail?.cause, closeCode: detail?.code });
|
|
393
386
|
}
|
|
387
|
+
if (state === 'connected')
|
|
388
|
+
this.wsAuthRetryAttempt = 0;
|
|
394
389
|
});
|
|
395
|
-
this.ws.onAuthInvalid((event) =>
|
|
396
|
-
// No automated recovery exists for the machine key: it is issued once
|
|
397
|
-
// at machine registration (config file / env) and there is no refresh
|
|
398
|
-
// flow the daemon can drive itself. Loud and actionable is the best
|
|
399
|
-
// this process can do — the operator must re-register.
|
|
400
|
-
this.log.error(`machine WS auth-invalid: the server rejected this machine's key ` +
|
|
401
|
-
`(status ${event.status}${event.code ? `, code ${event.code}` : ''}) — ` +
|
|
402
|
-
`${event.message}. Control-plane events (attach/detach, config updates, ` +
|
|
403
|
-
`update signals) are OFFLINE and reconnects are stopped. ${MACHINE_KEY_RECOVERY}`);
|
|
404
|
-
});
|
|
390
|
+
this.ws.onAuthInvalid((event) => this.handleMachineWsAuthInvalid(event));
|
|
405
391
|
await this.ws.connect();
|
|
406
392
|
await new Promise((resolve) => {
|
|
407
393
|
this.stopResolve = resolve;
|
|
@@ -420,6 +406,10 @@ export class DaemonSupervisor {
|
|
|
420
406
|
// failures come only from process-level unclean exits (the daemon-running
|
|
421
407
|
// marker in index.ts).
|
|
422
408
|
this.healthGate?.onSupervisorEnded();
|
|
409
|
+
if (this.wsAuthRetryTimer) {
|
|
410
|
+
clearTimeout(this.wsAuthRetryTimer);
|
|
411
|
+
this.wsAuthRetryTimer = null;
|
|
412
|
+
}
|
|
423
413
|
if (this.ws) {
|
|
424
414
|
this.ws.disconnect();
|
|
425
415
|
this.ws = null;
|
|
@@ -474,9 +464,35 @@ export class DaemonSupervisor {
|
|
|
474
464
|
this.stopResolve = null;
|
|
475
465
|
}
|
|
476
466
|
}
|
|
467
|
+
/**
|
|
468
|
+
* The SDK stops after its small auth budget; re-arm it on the slow credential
|
|
469
|
+
* schedule (connect() from auth-invalid grants a fresh budget). Running
|
|
470
|
+
* children keep their own agk_ and are left alone; machine.hello on
|
|
471
|
+
* reconnect replays whatever was missed.
|
|
472
|
+
*/
|
|
473
|
+
handleMachineWsAuthInvalid(event) {
|
|
474
|
+
if (!this.running)
|
|
475
|
+
return; // a ticket in flight across stop() can 401 late; no timer then
|
|
476
|
+
const delay = this.credentialRetryDelay(this.wsAuthRetryAttempt++);
|
|
477
|
+
this.log.error(`machine WS auth-invalid: the server rejected this machine's key ` +
|
|
478
|
+
`(status ${event.status}${event.code ? `, code ${event.code}` : ''}) — ` +
|
|
479
|
+
`${event.message}. Control-plane events (attach/detach, config updates, ` +
|
|
480
|
+
`update signals) are OFFLINE; retrying in ${Math.round(delay / 1000)}s. ` +
|
|
481
|
+
MACHINE_KEY_RECOVERY);
|
|
482
|
+
this.wsAuthRetryTimer = setTimeout(() => {
|
|
483
|
+
this.wsAuthRetryTimer = null;
|
|
484
|
+
if (this.running)
|
|
485
|
+
void this.ws?.connect();
|
|
486
|
+
}, delay);
|
|
487
|
+
}
|
|
477
488
|
// ---- Bootstrap (resilient identity probe) ----
|
|
489
|
+
/** Slow schedule shared by every machine-key rejection retry (boot, WS, ProviderStream). */
|
|
490
|
+
credentialRetryDelay(attempt) {
|
|
491
|
+
return Math.min(this.config.credentialRetryBackoffMs * 2 ** attempt, this.config.credentialRetryBackoffMaxMs);
|
|
492
|
+
}
|
|
478
493
|
async bootstrapWithRetry(signal) {
|
|
479
494
|
let attempt = 0;
|
|
495
|
+
let credentialAttempt = 0;
|
|
480
496
|
while (this.running && !signal.aborted) {
|
|
481
497
|
try {
|
|
482
498
|
const machine = await this.client.getMachineSelf();
|
|
@@ -490,42 +506,21 @@ export class DaemonSupervisor {
|
|
|
490
506
|
return true;
|
|
491
507
|
}
|
|
492
508
|
catch (err) {
|
|
493
|
-
// A
|
|
494
|
-
//
|
|
495
|
-
//
|
|
496
|
-
//
|
|
509
|
+
// A rejected machine key (401) is not a network blip, but it is not
|
|
510
|
+
// final either: an owner re-enabled, a server-side change, or a DB
|
|
511
|
+
// error the server reported as 401 make the same key valid again.
|
|
512
|
+
// Retry on the slow credential schedule and stay resident — exiting
|
|
513
|
+
// lets launchd/systemd relaunch us every few seconds with the same key
|
|
514
|
+
// (seen on staging: 13 rejections a minute). The sleep's timer is the
|
|
515
|
+
// live handle that keeps the process up; a bare pending Promise is not.
|
|
497
516
|
if (err instanceof ApiError && err.status === 401) {
|
|
517
|
+
const delay = this.credentialRetryDelay(credentialAttempt++);
|
|
498
518
|
this.log.error(`machine key rejected by the server ` +
|
|
499
519
|
`(status 401${err.code ? `, code ${err.code}` : ''}): ${err.message}. ` +
|
|
500
|
-
`
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
// loop that recreates the hammering this branch exists to stop. The
|
|
505
|
-
// parked process must therefore hold an ACTIVE handle: a pending
|
|
506
|
-
// Promise with only an abort listener keeps nothing on the event
|
|
507
|
-
// loop, Node exits 0 the moment nothing else is running, and the
|
|
508
|
-
// service manager relaunches it (observed on staging: one boot every
|
|
509
|
-
// ThrottleInterval, 13 rejections a minute). An idle interval is that
|
|
510
|
-
// handle; it does no work and is cleared when the operator sends
|
|
511
|
-
// SIGTERM/SIGINT after re-registering the machine.
|
|
512
|
-
const parked = setInterval(() => { }, PARK_KEEPALIVE_MS);
|
|
513
|
-
try {
|
|
514
|
-
await new Promise((resolve) => {
|
|
515
|
-
// The abort may have landed while getMachineSelf() was still in
|
|
516
|
-
// flight and the 401 raced it here — an addEventListener on an
|
|
517
|
-
// already-aborted signal never fires and would hang shutdown.
|
|
518
|
-
if (signal.aborted) {
|
|
519
|
-
resolve();
|
|
520
|
-
return;
|
|
521
|
-
}
|
|
522
|
-
signal.addEventListener('abort', () => resolve(), { once: true });
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
finally {
|
|
526
|
-
clearInterval(parked);
|
|
527
|
-
}
|
|
528
|
-
return false;
|
|
520
|
+
`Retrying in ${Math.round(delay / 1000)}s. ${MACHINE_KEY_RECOVERY}`);
|
|
521
|
+
if (!(await sleepCancellable(delay, signal)))
|
|
522
|
+
return false;
|
|
523
|
+
continue;
|
|
529
524
|
}
|
|
530
525
|
if (this.config.bootstrapBackoffMs === 0) {
|
|
531
526
|
this.log.error(`getMachineSelf failed: ${String(err)} (fail-fast mode)`);
|
|
@@ -1418,6 +1413,7 @@ export class DaemonSupervisor {
|
|
|
1418
1413
|
// (our ws-gateway WS never bounced to re-trigger machine.hello). Refetch
|
|
1419
1414
|
// machine config; applyClipProviderState rebuilds us if the URL moved.
|
|
1420
1415
|
onPersistentFailure: () => void this.refreshMachineConfig(),
|
|
1416
|
+
rejectedRetryDelayMs: (attempt) => this.credentialRetryDelay(attempt),
|
|
1421
1417
|
});
|
|
1422
1418
|
this.clipProvider
|
|
1423
1419
|
.connect()
|
package/dist/updater.d.ts
CHANGED
|
@@ -19,10 +19,18 @@ export declare class DaemonUpdater {
|
|
|
19
19
|
private updating;
|
|
20
20
|
private periodicTimer;
|
|
21
21
|
private reportOutcome;
|
|
22
|
+
private restartHandler;
|
|
22
23
|
constructor(bundleDir: string, cdnBaseUrl: string, log: GatewayLogger, signingEnabled: boolean);
|
|
23
24
|
/** Receive every update outcome (applied / failed / skipped / rolled_back / confirmed) as it happens. */
|
|
24
25
|
setOutcomeReporter(fn: (outcome: UpdateOutcome, reason?: UpdateReason) => void): void;
|
|
25
26
|
private report;
|
|
27
|
+
/**
|
|
28
|
+
* Restart the daemon onto an update installed after boot (periodic check or
|
|
29
|
+
* WS push). Installed-but-not-running is not an update: the old process
|
|
30
|
+
* would keep its bugs, and a later push for the same version is skipped
|
|
31
|
+
* because the disk is already current.
|
|
32
|
+
*/
|
|
33
|
+
setRestartHandler(fn: () => void): void;
|
|
26
34
|
/**
|
|
27
35
|
* Start periodic update checks. Call once after supervisor bootstrap.
|
|
28
36
|
*/
|
|
@@ -37,6 +45,7 @@ export declare class DaemonUpdater {
|
|
|
37
45
|
* Handle WS-triggered update. Adds jitter for non-mandatory updates.
|
|
38
46
|
*/
|
|
39
47
|
triggerUpdate(targetVersion: string, mandatory: boolean): Promise<boolean>;
|
|
48
|
+
private applyAndRestart;
|
|
40
49
|
/**
|
|
41
50
|
* Check if we need to roll back from a failed update.
|
|
42
51
|
* Call on every daemon startup, before bootstrap. `uncleanPrevExit` is true
|
package/dist/updater.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updater.d.ts","sourceRoot":"","sources":["../src/updater.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAEL,KAAK,aAAa,EAGnB,MAAM,uBAAuB,CAAC;AAgB/B,MAAM,WAAW,WAAW;IAC1B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