@parall/daemon 1.61.0 → 1.63.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 +11 -11
- package/bundle/parall-browser-pod.js +1690 -642
- package/bundle/parall-claude-agent.js +3617 -1937
- package/bundle/parall-codex-agent.js +3515 -1845
- package/bundle/parall-daemon.js +5099 -2284
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +75 -2
- package/dist/config.d.ts +4 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +10 -3
- package/dist/daemon-main.d.ts.map +1 -1
- package/dist/daemon-main.js +25 -5
- package/dist/daemon-telemetry.d.ts +83 -0
- package/dist/daemon-telemetry.d.ts.map +1 -0
- package/dist/daemon-telemetry.js +143 -0
- package/dist/diagnostics.d.ts +127 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +358 -0
- package/dist/launch-lifecycle.d.ts +49 -0
- package/dist/launch-lifecycle.d.ts.map +1 -0
- package/dist/launch-lifecycle.js +64 -0
- package/dist/launch-state.d.ts +72 -0
- package/dist/launch-state.d.ts.map +1 -0
- package/dist/launch-state.js +168 -0
- package/dist/runtime-bin-resolver.d.ts.map +1 -1
- package/dist/runtime-bin-resolver.js +2 -0
- package/dist/runtime-detector.d.ts.map +1 -1
- package/dist/runtime-detector.js +42 -5
- package/dist/runtime-report.d.ts +21 -0
- package/dist/runtime-report.d.ts.map +1 -0
- package/dist/runtime-report.js +41 -0
- package/dist/runtimes.d.ts.map +1 -1
- package/dist/runtimes.js +6 -1
- package/dist/supervisor.d.ts +32 -6
- package/dist/supervisor.d.ts.map +1 -1
- package/dist/supervisor.js +131 -17
- package/dist/updater.d.ts +19 -0
- package/dist/updater.d.ts.map +1 -1
- package/dist/updater.js +43 -15
- package/package.json +7 -6
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as os from 'node:os';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
import * as zlib from 'node:zlib';
|
|
6
|
+
import { maskKnownValues, redactSecrets, resolveServiceVersion } from '@parall/agent-core';
|
|
7
|
+
import { MACHINE_DIAGNOSTICS_NOTE_MAX_CHARS, } from '@parall/sdk';
|
|
8
|
+
import { agentHomeDirFor, agentWorkspaceDirFor, daemonConfigDir, resolveBundleDir, resolveRootStateDir, } from './config.js';
|
|
9
|
+
import { proxyEnvNames } from './daemon-telemetry.js';
|
|
10
|
+
import { isSelfUpdateManaged } from './daemon-update-mode.js';
|
|
11
|
+
import { DETECTABLE_RUNTIME_TYPES } from './runtime-bin-resolver.js';
|
|
12
|
+
import { detectRuntimes } from './runtime-detector.js';
|
|
13
|
+
import { buildMachineRuntimeReport } from './runtime-report.js';
|
|
14
|
+
import { loadLocalManifest, loadUpdateState } from './updater.js';
|
|
15
|
+
import { winServicePaths } from './win-service.js';
|
|
16
|
+
/**
|
|
17
|
+
* Diagnostics bundle (daemon-diagnostics-bundle-design.md): what a
|
|
18
|
+
* self-hosted machine's owner sends the platform to get a problem looked at.
|
|
19
|
+
* Assembled OUT of process from files on disk — the CLI (and the Desktop
|
|
20
|
+
* button, which runs the CLI) never talks to the running daemon.
|
|
21
|
+
*
|
|
22
|
+
* Everything in the bundle comes from the ALLOWLIST below; nothing is read
|
|
23
|
+
* from anywhere else. The one credential this process can see, config.json's
|
|
24
|
+
* `api_key`, is dropped from the config copy and used as an exact value for
|
|
25
|
+
* redacting the log tail. Credentials the daemon keeps in memory (per-agent
|
|
26
|
+
* agk_ launch keys, PRLL_PROVIDER_CONFIG) are not on disk and can only be
|
|
27
|
+
* caught by redactSecrets' prefix rules — the log tail is the bridges' raw
|
|
28
|
+
* stdout/stderr, so that rule set is the floor, not a guarantee.
|
|
29
|
+
*/
|
|
30
|
+
export const DIAGNOSTICS_SCHEMA_VERSION = 1;
|
|
31
|
+
/** Bytes of the log file's tail that travel; well under the server's 16 MB body cap. */
|
|
32
|
+
export const DIAGNOSTICS_LOG_TAIL_BYTES = 1 << 20;
|
|
33
|
+
/** Runtime probes spawn `--version` (and maybe a login shell); bound the whole step. */
|
|
34
|
+
export const DIAGNOSTICS_DETECT_BUDGET_MS = 20_000;
|
|
35
|
+
export const DIAGNOSTICS_NOTE_MAX_CHARS = MACHINE_DIAGNOSTICS_NOTE_MAX_CHARS;
|
|
36
|
+
/** Env keys whose VALUES are safe to include; every other PRLL_* key contributes its name only. */
|
|
37
|
+
const ENV_VALUE_ALLOWLIST = new Set([
|
|
38
|
+
'PRLL_DAEMON_CONFIG_DIR',
|
|
39
|
+
'PRLL_DAEMON_BUNDLE_DIR',
|
|
40
|
+
'PRLL_SERVER_ENV',
|
|
41
|
+
'PRLL_DAEMON_MANAGED',
|
|
42
|
+
'PRLL_DAEMON_UPDATE_CDN_URL',
|
|
43
|
+
'PRLL_DAEMON_UPDATE_CHANNEL',
|
|
44
|
+
'PRLL_DAEMON_UPDATE_INTERVAL_MS',
|
|
45
|
+
'PRLL_DAEMON_UPDATE_DISABLED',
|
|
46
|
+
'PRLL_DAEMON_UPDATE_CONFIRM_DELAY_MS',
|
|
47
|
+
'PRLL_DAEMON_HOME_ISOLATION',
|
|
48
|
+
'PRLL_CLIP_RUNTIME_ENABLED',
|
|
49
|
+
'PRLL_OTEL_SPOOL_DIR',
|
|
50
|
+
]);
|
|
51
|
+
const CONFIG_KEYS_ALLOWLIST = ['api_url', 'machine_id', 'org_id', 'update_cdn_url'];
|
|
52
|
+
/** Allowlisted values that are URLs: only scheme, host and path leave the machine. */
|
|
53
|
+
const URL_VALUED_KEYS = new Set(['api_url', 'update_cdn_url', 'PRLL_DAEMON_UPDATE_CDN_URL']);
|
|
54
|
+
/**
|
|
55
|
+
* A URL as it may appear in the bundle: userinfo, query and fragment are the
|
|
56
|
+
* places a credential usually rides along (`https://u:p@host/?token=…`), so
|
|
57
|
+
* they are dropped outright; what remains (and an unparseable value) still
|
|
58
|
+
* goes through `redactSecrets`, so a credential-shaped path segment is masked
|
|
59
|
+
* like it would be in the log. The daemon's own config is never rewritten.
|
|
60
|
+
*/
|
|
61
|
+
export function sanitizeUrlValue(value, knownSecrets) {
|
|
62
|
+
let kept = value;
|
|
63
|
+
try {
|
|
64
|
+
const u = new URL(value);
|
|
65
|
+
// Only http(s) with a host has the scheme/host/path shape the contract
|
|
66
|
+
// keeps; anything else (mailto:, data:, file:) is opaque content.
|
|
67
|
+
if ((u.protocol !== 'http:' && u.protocol !== 'https:') || !u.host)
|
|
68
|
+
return '***';
|
|
69
|
+
if (u.username || u.password || u.search || u.hash) {
|
|
70
|
+
kept = `${u.protocol}//${u.host}${u.pathname}`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// not a URL: fall through to the redaction rules alone
|
|
75
|
+
}
|
|
76
|
+
return redactSecrets(kept, knownSecrets);
|
|
77
|
+
}
|
|
78
|
+
/** Other allowlisted strings (ids, directory paths) keep their shape: known-value masking only. */
|
|
79
|
+
function allowlistedValue(key, value, knownSecrets) {
|
|
80
|
+
if (typeof value !== 'string')
|
|
81
|
+
return value;
|
|
82
|
+
return URL_VALUED_KEYS.has(key)
|
|
83
|
+
? sanitizeUrlValue(value, knownSecrets)
|
|
84
|
+
: maskKnownValues(value, knownSecrets);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The last `maxBytes` of a buffer as text. `total` is the size of the whole
|
|
88
|
+
* source (the buffer may already be its trailing window); when anything was
|
|
89
|
+
* cut, the text restarts at the next line so no partial line or split UTF-8
|
|
90
|
+
* sequence leads the tail. A window with no newline at all (one line longer
|
|
91
|
+
* than the window) is kept as the partial line: a huge bridge line is still
|
|
92
|
+
* evidence, and `truncated` says it was cut.
|
|
93
|
+
*/
|
|
94
|
+
export function tailBuffer(buf, maxBytes, total = buf.length) {
|
|
95
|
+
let window = buf.length > maxBytes ? buf.subarray(buf.length - maxBytes) : buf;
|
|
96
|
+
const truncated = total > window.length;
|
|
97
|
+
if (truncated) {
|
|
98
|
+
// A cut inside a multi-byte character would decode to U+FFFD (3 bytes
|
|
99
|
+
// each) and push the re-encoded size past maxBytes: skip continuation
|
|
100
|
+
// bytes so the window starts on a character boundary.
|
|
101
|
+
let start = 0;
|
|
102
|
+
while (start < window.length && (window[start] & 0xc0) === 0x80)
|
|
103
|
+
start++;
|
|
104
|
+
window = window.subarray(start);
|
|
105
|
+
}
|
|
106
|
+
let text = window.toString('utf-8');
|
|
107
|
+
if (truncated) {
|
|
108
|
+
const nl = text.indexOf('\n');
|
|
109
|
+
if (nl >= 0)
|
|
110
|
+
text = text.slice(nl + 1);
|
|
111
|
+
}
|
|
112
|
+
return { text, truncated };
|
|
113
|
+
}
|
|
114
|
+
/** Last maxBytes of a file, cut to a line boundary; empty when the file is absent. */
|
|
115
|
+
export function tailFile(file, maxBytes) {
|
|
116
|
+
let fd;
|
|
117
|
+
try {
|
|
118
|
+
fd = fs.openSync(file, 'r');
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return { text: '', truncated: false };
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
const size = fs.fstatSync(fd).size;
|
|
125
|
+
const start = Math.max(0, size - maxBytes);
|
|
126
|
+
const buf = Buffer.alloc(size - start);
|
|
127
|
+
fs.readSync(fd, buf, 0, buf.length, start);
|
|
128
|
+
return tailBuffer(buf, maxBytes, size);
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
fs.closeSync(fd);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** Where this platform's daemon log lives for the CLI; Desktop passes its env-suffixed path. */
|
|
135
|
+
export function resolveDaemonLogPath(env = process.env) {
|
|
136
|
+
const explicit = env.PRLL_DAEMON_LOG_PATH?.trim();
|
|
137
|
+
if (explicit)
|
|
138
|
+
return explicit;
|
|
139
|
+
if (process.platform === 'win32')
|
|
140
|
+
return winServicePaths(os.homedir()).logFile;
|
|
141
|
+
if (process.platform === 'darwin') {
|
|
142
|
+
return path.join(os.homedir(), 'Library', 'Logs', 'parall-daemon.log');
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
async function defaultLogSource(env) {
|
|
147
|
+
const file = resolveDaemonLogPath(env);
|
|
148
|
+
if (file)
|
|
149
|
+
return { source: file, ...tailFile(file, DIAGNOSTICS_LOG_TAIL_BYTES) };
|
|
150
|
+
// Linux service installs log to journald.
|
|
151
|
+
try {
|
|
152
|
+
return {
|
|
153
|
+
source: 'journalctl --user-unit parall-daemon',
|
|
154
|
+
...(await commandTail('journalctl', ['--user-unit', 'parall-daemon', '-n', '4000', '-o', 'cat', '--no-pager'], DIAGNOSTICS_LOG_TAIL_BYTES)),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
return { source: 'journalctl (failed)', text: String(err), truncated: false };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Run a command and keep only the trailing `maxBytes` of its stdout, however
|
|
163
|
+
* much it prints: the buffer is trimmed as chunks arrive, so a verbose journal
|
|
164
|
+
* never hits a fixed maxBuffer and loses the useful end. Rejects when the
|
|
165
|
+
* command cannot start or exits non-zero without printing anything.
|
|
166
|
+
*/
|
|
167
|
+
export function commandTail(cmd, args, maxBytes) {
|
|
168
|
+
return new Promise((resolve, reject) => {
|
|
169
|
+
const child = spawn(cmd, args, { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
170
|
+
let kept = Buffer.alloc(0);
|
|
171
|
+
let total = 0;
|
|
172
|
+
let stderr = '';
|
|
173
|
+
child.stdout.on('data', (chunk) => {
|
|
174
|
+
total += chunk.length;
|
|
175
|
+
kept = Buffer.concat([kept, chunk]);
|
|
176
|
+
// Keep a little more than the window so the line cut still has slack.
|
|
177
|
+
if (kept.length > maxBytes * 2)
|
|
178
|
+
kept = kept.subarray(kept.length - maxBytes);
|
|
179
|
+
});
|
|
180
|
+
child.stderr.on('data', (chunk) => {
|
|
181
|
+
if (stderr.length < 4096)
|
|
182
|
+
stderr += chunk.toString('utf-8');
|
|
183
|
+
});
|
|
184
|
+
child.on('error', reject);
|
|
185
|
+
child.on('close', (code) => {
|
|
186
|
+
if (code !== 0 && total === 0) {
|
|
187
|
+
reject(new Error(`${cmd} exited with code ${code}: ${stderr.trim()}`));
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
resolve(tailBuffer(kept, maxBytes, total));
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function readJson(file) {
|
|
195
|
+
try {
|
|
196
|
+
const parsed = JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
197
|
+
return parsed && typeof parsed === 'object' ? parsed : null;
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function listDir(dir) {
|
|
204
|
+
try {
|
|
205
|
+
return fs.readdirSync(dir).sort();
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return [];
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function spoolStats(spoolRoot) {
|
|
212
|
+
const out = [];
|
|
213
|
+
for (const dir of listDir(spoolRoot)) {
|
|
214
|
+
for (const signal of listDir(path.join(spoolRoot, dir))) {
|
|
215
|
+
const signalDir = path.join(spoolRoot, dir, signal);
|
|
216
|
+
let files = 0;
|
|
217
|
+
let bytes = 0;
|
|
218
|
+
let oldest = null;
|
|
219
|
+
for (const name of listDir(signalDir)) {
|
|
220
|
+
if (!name.endsWith('.pb'))
|
|
221
|
+
continue;
|
|
222
|
+
try {
|
|
223
|
+
bytes += fs.statSync(path.join(signalDir, name)).size;
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
files += 1;
|
|
229
|
+
const ts = Number(name.slice(0, 13));
|
|
230
|
+
if (Number.isFinite(ts) && (oldest === null || ts < oldest))
|
|
231
|
+
oldest = ts;
|
|
232
|
+
}
|
|
233
|
+
if (files > 0) {
|
|
234
|
+
out.push({
|
|
235
|
+
dir,
|
|
236
|
+
signal,
|
|
237
|
+
files,
|
|
238
|
+
bytes,
|
|
239
|
+
oldest_at: oldest === null ? null : new Date(oldest).toISOString(),
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
function agentDirStats(stateDir) {
|
|
247
|
+
const out = [];
|
|
248
|
+
for (const agentId of listDir(path.join(stateDir, 'agents'))) {
|
|
249
|
+
try {
|
|
250
|
+
// The per-agent layout resolvers reject names that are not agent ids
|
|
251
|
+
// (a stray .DS_Store); those are not agents and are skipped.
|
|
252
|
+
out.push({
|
|
253
|
+
agent_id: agentId,
|
|
254
|
+
workspace: fs.existsSync(agentWorkspaceDirFor(stateDir, agentId)),
|
|
255
|
+
home: fs.existsSync(agentHomeDirFor(stateDir, agentId)),
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
// not an agent directory
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return out;
|
|
263
|
+
}
|
|
264
|
+
function withBudget(promise, ms, fallback) {
|
|
265
|
+
return new Promise((resolve) => {
|
|
266
|
+
// Deliberately NOT unref'd: the timer is the only thing keeping the loop
|
|
267
|
+
// alive while a stuck probe never settles, and it is cleared the moment
|
|
268
|
+
// the probe answers.
|
|
269
|
+
const timer = setTimeout(() => resolve(fallback), ms);
|
|
270
|
+
promise.then((v) => {
|
|
271
|
+
clearTimeout(timer);
|
|
272
|
+
resolve(v);
|
|
273
|
+
}, () => {
|
|
274
|
+
clearTimeout(timer);
|
|
275
|
+
resolve(fallback);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
export async function collectDiagnostics(opts = {}) {
|
|
280
|
+
const env = opts.env ?? process.env;
|
|
281
|
+
const now = opts.now ?? (() => new Date());
|
|
282
|
+
const configDir = daemonConfigDir(env);
|
|
283
|
+
const bundleDir = resolveBundleDir(env);
|
|
284
|
+
const rawConfig = readJson(path.join(configDir, 'config.json')) ?? {};
|
|
285
|
+
const apiKey = typeof rawConfig.api_key === 'string' ? rawConfig.api_key : '';
|
|
286
|
+
const config = {};
|
|
287
|
+
for (const key of CONFIG_KEYS_ALLOWLIST) {
|
|
288
|
+
if (key in rawConfig)
|
|
289
|
+
config[key] = allowlistedValue(key, rawConfig[key], [apiKey]);
|
|
290
|
+
}
|
|
291
|
+
const stateDir = resolveRootStateDir(env);
|
|
292
|
+
const manifest = loadLocalManifest(bundleDir);
|
|
293
|
+
const manifestVersion = typeof manifest?.version === 'string' ? manifest.version : null;
|
|
294
|
+
const bundleVersions = listDir(path.join(bundleDir, 'versions'));
|
|
295
|
+
// The runtime probe and the log source are independent; overlap them.
|
|
296
|
+
const [detected, log] = await Promise.all([
|
|
297
|
+
withBudget(opts.detect ? opts.detect() : detectRuntimes(env, { info() { }, warn() { } }), opts.detectBudgetMs ?? DIAGNOSTICS_DETECT_BUDGET_MS, null),
|
|
298
|
+
opts.logSource ? opts.logSource() : defaultLogSource(env),
|
|
299
|
+
]);
|
|
300
|
+
const runtimeReport = detected === null
|
|
301
|
+
? { skipped: 'timeout' }
|
|
302
|
+
: buildMachineRuntimeReport({
|
|
303
|
+
daemonVersion: manifestVersion ?? undefined,
|
|
304
|
+
selfUpdateCapable: isSelfUpdateManaged(bundleDir, env),
|
|
305
|
+
detected,
|
|
306
|
+
runtimeTypes: DETECTABLE_RUNTIME_TYPES,
|
|
307
|
+
});
|
|
308
|
+
const present = Object.keys(env)
|
|
309
|
+
.filter((k) => k.startsWith('PRLL_'))
|
|
310
|
+
.sort();
|
|
311
|
+
const values = {};
|
|
312
|
+
for (const key of present) {
|
|
313
|
+
if (ENV_VALUE_ALLOWLIST.has(key) && env[key]) {
|
|
314
|
+
values[key] = allowlistedValue(key, env[key], [apiKey]);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
const redacted = redactSecrets(log.text, [apiKey]);
|
|
318
|
+
return {
|
|
319
|
+
schema_version: DIAGNOSTICS_SCHEMA_VERSION,
|
|
320
|
+
created_at: now().toISOString(),
|
|
321
|
+
manifest: {
|
|
322
|
+
daemon_version: resolveServiceVersion(opts.importMetaUrl ?? import.meta.url),
|
|
323
|
+
bundle_manifest_version: manifestVersion,
|
|
324
|
+
platform: process.platform,
|
|
325
|
+
arch: process.arch,
|
|
326
|
+
node_version: process.versions.node,
|
|
327
|
+
os_release: os.release(),
|
|
328
|
+
hostname_length: os.hostname().length,
|
|
329
|
+
config_dir: configDir,
|
|
330
|
+
bundle_dir: bundleDir,
|
|
331
|
+
state_dir: stateDir,
|
|
332
|
+
},
|
|
333
|
+
config,
|
|
334
|
+
update_state: loadUpdateState(bundleDir),
|
|
335
|
+
bundle_versions: bundleVersions,
|
|
336
|
+
runtime_report: runtimeReport,
|
|
337
|
+
spool: spoolStats(path.join(configDir, 'otel-spool')),
|
|
338
|
+
agents: agentDirStats(stateDir),
|
|
339
|
+
env: { present, values, proxy: proxyEnvNames(env) },
|
|
340
|
+
log: {
|
|
341
|
+
source: log.source,
|
|
342
|
+
truncated: log.truncated,
|
|
343
|
+
bytes: Buffer.byteLength(redacted, 'utf-8'),
|
|
344
|
+
text: redacted,
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
/** The wire form: gzip of the JSON document. */
|
|
349
|
+
export function serializeBundle(bundle) {
|
|
350
|
+
return zlib.gzipSync(Buffer.from(JSON.stringify(bundle), 'utf-8'), { level: 9 });
|
|
351
|
+
}
|
|
352
|
+
export async function uploadDiagnostics(client, bundle, note) {
|
|
353
|
+
const bytes = serializeBundle(bundle);
|
|
354
|
+
return client.uploadMachineDiagnostics(new Uint8Array(bytes), {
|
|
355
|
+
daemon_version: bundle.manifest.daemon_version,
|
|
356
|
+
...(note ? { note } : {}),
|
|
357
|
+
});
|
|
358
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How each launch failure shape is reported to the platform
|
|
3
|
+
* (agent-health-alerting-design.md §4.6).
|
|
4
|
+
*
|
|
5
|
+
* The daemon is the only place that can see WHY an agent process failed to
|
|
6
|
+
* come up, and the server's readiness derivation only treats a report as a
|
|
7
|
+
* failed launch when it is `failed`, or `backoff` deep enough to have
|
|
8
|
+
* crossed `model.LaunchFailedAttempts`. Getting that distinction wrong makes
|
|
9
|
+
* a real failure look like a plain "not connected", so the decision lives
|
|
10
|
+
* here as named cases rather than inline at each call site in the
|
|
11
|
+
* supervisor.
|
|
12
|
+
*/
|
|
13
|
+
import type { LaunchStateInput } from './launch-state.js';
|
|
14
|
+
/** Spawn is starting: clears any previous failure once it succeeds. */
|
|
15
|
+
export declare function launchingReport(attempts: number): LaunchStateInput;
|
|
16
|
+
/** The child has been alive long enough to count as up. */
|
|
17
|
+
export declare function runningReport(): LaunchStateInput;
|
|
18
|
+
/**
|
|
19
|
+
* The credential request failed on the INITIAL spawn. Nothing retries this
|
|
20
|
+
* path — the agent stays down until the next reconcile or attach event — so
|
|
21
|
+
* it is a failed launch, not a backoff (a backoff at attempt 0 would never
|
|
22
|
+
* become visible).
|
|
23
|
+
*/
|
|
24
|
+
export declare function mintFailedReport(err: unknown): LaunchStateInput;
|
|
25
|
+
/**
|
|
26
|
+
* The credential request failed while RESTARTING. This path does retry on
|
|
27
|
+
* the backoff curve, so it reports the same shape the crash loop does: a
|
|
28
|
+
* growing attempt count that becomes visible once it is deep enough, and an
|
|
29
|
+
* outright failure when no retry was scheduled.
|
|
30
|
+
*/
|
|
31
|
+
export declare function restartMintFailedReport(err: unknown, attempts: number, retrying: boolean): LaunchStateInput;
|
|
32
|
+
/** Workspace preparation threw before the process existed. */
|
|
33
|
+
export declare function workspaceFailedReport(err: unknown): LaunchStateInput;
|
|
34
|
+
/** Restart reached startChild without a credential — a bug, but a visible one. */
|
|
35
|
+
export declare function missingCredentialReport(attempts: number): LaunchStateInput;
|
|
36
|
+
/**
|
|
37
|
+
* The child exited. `err` set means the spawn itself failed (ENOENT and
|
|
38
|
+
* friends); otherwise the exit code and signal describe it. A backoff this
|
|
39
|
+
* deep counts as failed.
|
|
40
|
+
*/
|
|
41
|
+
export declare function childExitReport(opts: {
|
|
42
|
+
err?: Error;
|
|
43
|
+
attempts: number;
|
|
44
|
+
failedAttempts: number;
|
|
45
|
+
code: number | null;
|
|
46
|
+
signal: NodeJS.Signals | null;
|
|
47
|
+
outputTail?: string;
|
|
48
|
+
}): LaunchStateInput;
|
|
49
|
+
//# sourceMappingURL=launch-lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launch-lifecycle.d.ts","sourceRoot":"","sources":["../src/launch-lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,uEAAuE;AACvE,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAElE;AAED,2DAA2D;AAC3D,wBAAgB,aAAa,IAAI,gBAAgB,CAEhD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,gBAAgB,CAM/D;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,OAAO,EACZ,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,OAAO,GAChB,gBAAgB,CAMlB;AAED,8DAA8D;AAC9D,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,GAAG,gBAAgB,CAEpE;AAED,kFAAkF;AAClF,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAM1E;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE;IACpC,GAAG,CAAC,EAAE,KAAK,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,gBAAgB,CAYnB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** Spawn is starting: clears any previous failure once it succeeds. */
|
|
2
|
+
export function launchingReport(attempts) {
|
|
3
|
+
return { status: 'launching', attempts };
|
|
4
|
+
}
|
|
5
|
+
/** The child has been alive long enough to count as up. */
|
|
6
|
+
export function runningReport() {
|
|
7
|
+
return { status: 'running', attempts: 0 };
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The credential request failed on the INITIAL spawn. Nothing retries this
|
|
11
|
+
* path — the agent stays down until the next reconcile or attach event — so
|
|
12
|
+
* it is a failed launch, not a backoff (a backoff at attempt 0 would never
|
|
13
|
+
* become visible).
|
|
14
|
+
*/
|
|
15
|
+
export function mintFailedReport(err) {
|
|
16
|
+
return {
|
|
17
|
+
status: 'failed',
|
|
18
|
+
attempts: 0,
|
|
19
|
+
lastError: `launch credential request failed: ${String(err)}`,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The credential request failed while RESTARTING. This path does retry on
|
|
24
|
+
* the backoff curve, so it reports the same shape the crash loop does: a
|
|
25
|
+
* growing attempt count that becomes visible once it is deep enough, and an
|
|
26
|
+
* outright failure when no retry was scheduled.
|
|
27
|
+
*/
|
|
28
|
+
export function restartMintFailedReport(err, attempts, retrying) {
|
|
29
|
+
return {
|
|
30
|
+
status: retrying ? 'backoff' : 'failed',
|
|
31
|
+
attempts,
|
|
32
|
+
lastError: `launch credential request failed: ${String(err)}`,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** Workspace preparation threw before the process existed. */
|
|
36
|
+
export function workspaceFailedReport(err) {
|
|
37
|
+
return { status: 'failed', attempts: 0, lastError: `workspace setup failed: ${String(err)}` };
|
|
38
|
+
}
|
|
39
|
+
/** Restart reached startChild without a credential — a bug, but a visible one. */
|
|
40
|
+
export function missingCredentialReport(attempts) {
|
|
41
|
+
return {
|
|
42
|
+
status: 'failed',
|
|
43
|
+
attempts,
|
|
44
|
+
lastError: 'no launch credential available for the agent process',
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The child exited. `err` set means the spawn itself failed (ENOENT and
|
|
49
|
+
* friends); otherwise the exit code and signal describe it. A backoff this
|
|
50
|
+
* deep counts as failed.
|
|
51
|
+
*/
|
|
52
|
+
export function childExitReport(opts) {
|
|
53
|
+
const failed = opts.err !== undefined || opts.attempts >= opts.failedAttempts;
|
|
54
|
+
return {
|
|
55
|
+
status: failed ? 'failed' : 'backoff',
|
|
56
|
+
attempts: opts.attempts,
|
|
57
|
+
lastExitCode: opts.code,
|
|
58
|
+
lastSignal: opts.signal,
|
|
59
|
+
lastError: opts.err
|
|
60
|
+
? String(opts.err.message ?? opts.err)
|
|
61
|
+
: `exited with code ${opts.code ?? 'null'} signal ${opts.signal ?? 'null'}`,
|
|
62
|
+
...(opts.outputTail ? { outputTail: opts.outputTail } : {}),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { AgentLaunchReportStatus, AgentLaunchStateReport } from '@parall/sdk';
|
|
2
|
+
export declare const LAUNCH_REPLAY_INTERVAL_MS: number;
|
|
3
|
+
/** How much stderr tail travels with a backoff / failed report. */
|
|
4
|
+
export declare const LAUNCH_OUTPUT_TAIL_BYTES = 4096;
|
|
5
|
+
/**
|
|
6
|
+
* Backoff depth at which a still-restarting launch is reported as failed.
|
|
7
|
+
* Deliberately higher than the server's `model.LaunchFailedAttempts` (3),
|
|
8
|
+
* which already treats a backoff that deep as failed for readiness and
|
|
9
|
+
* alerting: the user is warned while the daemon is still retrying. Changing
|
|
10
|
+
* one without the other widens or collapses that early-warning window.
|
|
11
|
+
*/
|
|
12
|
+
export declare const LAUNCH_FAILED_ATTEMPTS = 5;
|
|
13
|
+
/**
|
|
14
|
+
* A ULID (26 chars, Crockford base32): 48-bit millisecond timestamp + 80
|
|
15
|
+
* random bits. The server compares two daemon instances by the timestamp
|
|
16
|
+
* component, so the time prefix is the contract — not just uniqueness.
|
|
17
|
+
*/
|
|
18
|
+
export declare function newDaemonInstanceId(now?: number, random?: () => number): string;
|
|
19
|
+
/** Decode the millisecond timestamp of a ULID minted by newDaemonInstanceId. */
|
|
20
|
+
export declare function daemonInstanceTimestamp(id: string): number;
|
|
21
|
+
/** Fixed-size tail buffer for a child's stderr — never blocks the child. */
|
|
22
|
+
export declare class OutputTail {
|
|
23
|
+
private readonly limit;
|
|
24
|
+
private chunks;
|
|
25
|
+
private size;
|
|
26
|
+
constructor(limit?: number);
|
|
27
|
+
push(chunk: Buffer | string): void;
|
|
28
|
+
text(): string;
|
|
29
|
+
reset(): void;
|
|
30
|
+
}
|
|
31
|
+
export interface LaunchStateInput {
|
|
32
|
+
status: AgentLaunchReportStatus;
|
|
33
|
+
attempts: number;
|
|
34
|
+
lastExitCode?: number | null;
|
|
35
|
+
lastSignal?: string | null;
|
|
36
|
+
lastError?: string | null;
|
|
37
|
+
outputTail?: string | null;
|
|
38
|
+
}
|
|
39
|
+
export interface LaunchStateClient {
|
|
40
|
+
reportAgentLaunchState(agentId: string, report: AgentLaunchStateReport): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export interface LaunchStateLogger {
|
|
43
|
+
warn(msg: string): void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Tracks the last reported state per agent, sends on change, replays on
|
|
47
|
+
* demand. Reports are best-effort: a failed send is logged and the next
|
|
48
|
+
* change (or replay) carries the current truth.
|
|
49
|
+
*/
|
|
50
|
+
export declare class LaunchStateReporter {
|
|
51
|
+
private readonly client;
|
|
52
|
+
private readonly log;
|
|
53
|
+
readonly instanceId: string;
|
|
54
|
+
private seq;
|
|
55
|
+
private readonly current;
|
|
56
|
+
private readonly redactValues;
|
|
57
|
+
constructor(client: LaunchStateClient, log: LaunchStateLogger, opts?: {
|
|
58
|
+
instanceId?: string;
|
|
59
|
+
redactValues?: string[];
|
|
60
|
+
});
|
|
61
|
+
/** Report a state; a no-op when nothing changed since the last report. */
|
|
62
|
+
update(agentId: string, next: LaunchStateInput): Promise<void>;
|
|
63
|
+
/** Forget an agent (detached / shut down) so replays stop mentioning it. */
|
|
64
|
+
forget(agentId: string): void;
|
|
65
|
+
/** Re-send every current state (boot, reconnect, periodic). */
|
|
66
|
+
replayAll(): Promise<void>;
|
|
67
|
+
/** Current in-memory view (tests, diagnostics). */
|
|
68
|
+
snapshot(agentId: string): LaunchStateInput | undefined;
|
|
69
|
+
private send;
|
|
70
|
+
private clean;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=launch-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launch-state.d.ts","sourceRoot":"","sources":["../src/launch-state.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAEnF,eAAO,MAAM,yBAAyB,QAAc,CAAC;AACrD,mEAAmE;AACnE,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAC7C;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAcxC;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,GAAE,MAAmB,EAAE,MAAM,CAAC,EAAE,MAAM,MAAM,GAAG,MAAM,CAM3F;AAED,gFAAgF;AAChF,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAI1D;AAED,4EAA4E;AAC5E,qBAAa,UAAU;IAIT,OAAO,CAAC,QAAQ,CAAC,KAAK;IAHlC,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,IAAI,CAAK;gBAEY,KAAK,GAAE,MAAiC;IAErE,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAiBlC,IAAI,IAAI,MAAM;IAId,KAAK,IAAI,IAAI;CAId;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,uBAAuB,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,iBAAiB;IAChC,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxF;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED;;;;GAIG;AACH,qBAAa,mBAAmB;IAO5B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAPtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;IAC/D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAW;gBAGrB,MAAM,EAAE,iBAAiB,EACzB,GAAG,EAAE,iBAAiB,EACvC,IAAI,GAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;KAAO;IAM7D,0EAA0E;IACpE,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOpE,4EAA4E;IAC5E,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAI7B,+DAA+D;IACzD,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAMhC,mDAAmD;IACnD,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;YAIzC,IAAI;IAoBlB,OAAO,CAAC,KAAK;CAMd"}
|