relay-companion 0.1.644 → 0.1.645
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.
|
@@ -16,7 +16,16 @@ function createDaemonProgress({ packageRoot, version, homeDir = os.homedir(), pi
|
|
|
16
16
|
return {
|
|
17
17
|
advance(phase = "running") { state = { ...state, phase, at: now(), sequence: state.sequence + 1 }; save(); },
|
|
18
18
|
component(name, status) { if (state.components[name] !== status) { state.components[name] = status; save(); } },
|
|
19
|
-
|
|
19
|
+
// The last failure of each part, as a closed code (see diagnostics.cjs
|
|
20
|
+
// classifyFailure) and the job it happened in. Kept after the part
|
|
21
|
+
// recovers, so the fleet can see what last went wrong and when.
|
|
22
|
+
componentError(name, { stage, code, at }) {
|
|
23
|
+
const previous = state.componentErrors?.[name];
|
|
24
|
+
if (previous && previous.stage === stage && previous.code === code && at - previous.at < 60_000) return;
|
|
25
|
+
state = { ...state, componentErrors: { ...(state.componentErrors || {}), [name]: { stage, code, at } } };
|
|
26
|
+
save();
|
|
27
|
+
},
|
|
28
|
+
snapshot() { return { ...state, components: { ...state.components }, componentErrors: { ...(state.componentErrors || {}) } }; },
|
|
20
29
|
async waiting(operation, phase = "offline") {
|
|
21
30
|
// Explicit local control progress while authentication/network is pending.
|
|
22
31
|
// It reports a wait, never successful delivery or signed-in operation.
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
"recovery",
|
|
5
5
|
"launcher",
|
|
6
6
|
"collector",
|
|
7
|
-
"unknown"
|
|
7
|
+
"unknown",
|
|
8
|
+
"daemon"
|
|
8
9
|
],
|
|
9
10
|
"stages": [
|
|
10
11
|
"discovery",
|
|
@@ -17,7 +18,15 @@
|
|
|
17
18
|
"local-fallback",
|
|
18
19
|
"services",
|
|
19
20
|
"health",
|
|
20
|
-
"unknown"
|
|
21
|
+
"unknown",
|
|
22
|
+
"inbox-background",
|
|
23
|
+
"attachments",
|
|
24
|
+
"task-wakes",
|
|
25
|
+
"agent-sessions",
|
|
26
|
+
"topics",
|
|
27
|
+
"tasks",
|
|
28
|
+
"process-query",
|
|
29
|
+
"report"
|
|
21
30
|
],
|
|
22
31
|
"outcomes": [
|
|
23
32
|
"started",
|
|
@@ -87,7 +96,13 @@
|
|
|
87
96
|
"runtime-node-missing",
|
|
88
97
|
"runtime-npm-missing",
|
|
89
98
|
"interrupted-by-sleep",
|
|
90
|
-
"check-timed-out"
|
|
99
|
+
"check-timed-out",
|
|
100
|
+
"file-corrupt",
|
|
101
|
+
"server-error",
|
|
102
|
+
"server-refused",
|
|
103
|
+
"component-stalled",
|
|
104
|
+
"worker-out-of-memory",
|
|
105
|
+
"collection-cancelled"
|
|
91
106
|
],
|
|
92
107
|
"runtimeStates": [
|
|
93
108
|
"active",
|
|
@@ -27,6 +27,18 @@ function errorCode(error) {
|
|
|
27
27
|
];
|
|
28
28
|
return patterns.find(([pattern]) => pattern.test(text))?.[1] || "unclassified";
|
|
29
29
|
}
|
|
30
|
+
// What kind of failure a background part hit, in the same closed vocabulary:
|
|
31
|
+
// never the message itself, which can hold paths or content. A server's error
|
|
32
|
+
// page or refusal, a local file that is corrupt, and a lock that could not be
|
|
33
|
+
// taken are told apart from the generic codes errorCode already knows.
|
|
34
|
+
function classifyFailure(error) {
|
|
35
|
+
const status = Number(error?.status || error?.statusCode || 0);
|
|
36
|
+
if (error?.code === "non_json_response" || status >= 500) return "server-error";
|
|
37
|
+
if (status >= 400) return "server-refused";
|
|
38
|
+
if (error?.name === "SyntaxError" || error instanceof SyntaxError) return "file-corrupt";
|
|
39
|
+
if (/lock unavailable|lock-unavailable/i.test(String(error?.message || ""))) return "transaction-lock-unavailable";
|
|
40
|
+
return errorCode(error) || "unclassified";
|
|
41
|
+
}
|
|
30
42
|
function configIdentity(homeDir) {
|
|
31
43
|
const config = read(path.join(homeDir, ".relay", "config.json"));
|
|
32
44
|
// A new account must never upload its predecessor's diagnostic history.
|
|
@@ -155,4 +167,4 @@ function snapshot({ homeDir = os.homedir(), now = Date.now, env = process.env }
|
|
|
155
167
|
discoveryError: errorCode(recovery?.discoveryError),
|
|
156
168
|
};
|
|
157
169
|
}
|
|
158
|
-
module.exports = { record, snapshot, events, configIdentity, read, errorCode, version, contract, MAX_EVENTS, MAX_AGE_MS };
|
|
170
|
+
module.exports = { record, snapshot, events, configIdentity, read, errorCode, classifyFailure, version, contract, MAX_EVENTS, MAX_AGE_MS };
|
|
@@ -55,7 +55,11 @@ function macPillLaunch({ homeDir, current, run }) {
|
|
|
55
55
|
const code = String(error?.code || error?.message || "unknown").split(/[:\s]/)[0].slice(0, 40);
|
|
56
56
|
// A check that timed out learned nothing about the registration.
|
|
57
57
|
if (code === "check-timed-out") return null;
|
|
58
|
-
|
|
58
|
+
// Which check failed (plutil-exit-1, wrong-label, ...), and whether macOS
|
|
59
|
+
// has the service loaded anyway: an invalid file that launchd still runs
|
|
60
|
+
// differs from one that will not start Relay after the next log-in.
|
|
61
|
+
const detail = /^[a-z0-9-]{1,30}$/.test(String(error?.detail || "")) ? `/${error.detail}` : "";
|
|
62
|
+
return { ok: false, reason: `registration-invalid: ${code}${detail}`.slice(0, 80), loaded: launchdLoaded(mac, run) };
|
|
59
63
|
}
|
|
60
64
|
if (record.releaseExecutable) {
|
|
61
65
|
const identity = require("./mac-background-identity.cjs");
|
|
@@ -69,6 +73,14 @@ function macPillLaunch({ homeDir, current, run }) {
|
|
|
69
73
|
return { ok: true, reason: null };
|
|
70
74
|
}
|
|
71
75
|
|
|
76
|
+
// true or false when launchd answered; null when it could not be asked.
|
|
77
|
+
function launchdLoaded(mac, run) {
|
|
78
|
+
try {
|
|
79
|
+
const state = mac.registration(PILL_LABEL, { run });
|
|
80
|
+
return state.present ? true : state.known ? false : null;
|
|
81
|
+
} catch { return null; }
|
|
82
|
+
}
|
|
83
|
+
|
|
72
84
|
function macPillLastExit(run) {
|
|
73
85
|
const userId = typeof process.getuid === "function" ? process.getuid() : 0;
|
|
74
86
|
const result = run("/bin/launchctl", ["print", `gui/${userId}/${PILL_LABEL}`]);
|
|
@@ -138,7 +150,15 @@ function collectInstallationHealth({ homeDir = os.homedir(), platform = process.
|
|
|
138
150
|
const componentNames = ["inbox-background", "agent-sessions", "topics", "tasks"];
|
|
139
151
|
const unhealthyComponents = progressMatches ? componentNames.filter(name => ["failed", "stalled"].includes(progress.components?.[name])) : [];
|
|
140
152
|
const pill = pillLiveness({ homeDir, platform, env, live, current, run, now });
|
|
141
|
-
|
|
153
|
+
// Each part's last failure from the daemon's health file: which job and what
|
|
154
|
+
// kind (closed codes, never messages), newest first, from the last day.
|
|
155
|
+
const LABEL = /^[a-z0-9_-]{1,40}$/;
|
|
156
|
+
const errors = progressMatches ? Object.entries(progress.componentErrors || {})
|
|
157
|
+
.filter(([name, item]) => LABEL.test(name) && LABEL.test(item?.stage || "") && LABEL.test(item?.code || "")
|
|
158
|
+
&& Number.isFinite(item.at) && item.at <= now && now - item.at < 24 * 60 * 60_000)
|
|
159
|
+
.sort((a, b) => b[1].at - a[1].at).slice(0, 4)
|
|
160
|
+
.map(([name, item]) => ({ component: name, stage: item.stage, code: item.code, at: new Date(item.at).toISOString() })) : [];
|
|
161
|
+
let serviceHealth = { state: "healthy", reason: "ready", components: unhealthyComponents, ...(errors.length ? { errors } : {}) };
|
|
142
162
|
if (!activeVersion) serviceHealth = { ...serviceHealth, state: "unverified", reason: "runtime-not-active" };
|
|
143
163
|
else if (!live?.daemon) serviceHealth = { ...serviceHealth, state: "failed", reason: "daemon-missing" };
|
|
144
164
|
else if (!daemonResponsive) serviceHealth = { ...serviceHealth, state: "failed", reason: "daemon-not-responsive" };
|
|
@@ -25,10 +25,19 @@ function readRegistration(label, { homeDir = os.homedir(), run = defaultRun, fsI
|
|
|
25
25
|
// plutil killed by the timeout says nothing about the file: a sleeping Mac's
|
|
26
26
|
// brief wake ends mid-check (2026-11-20).
|
|
27
27
|
if (decoded?.error?.code === "ETIMEDOUT" || (decoded?.signal && decoded?.status === null)) throw Error(`check-timed-out: ${label}`);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
// `detail` says which check failed, in words that never hold a path or the
|
|
29
|
+
// file's contents, so the fleet can tell an unreadable file from one that
|
|
30
|
+
// names the wrong service (installation-health.cjs reports it).
|
|
31
|
+
const invalid = detail => Object.assign(Error(`invalid-service-plist: ${label}`), { detail });
|
|
32
|
+
if (!commandOk(decoded)) {
|
|
33
|
+
throw invalid(decoded?.error ? `plutil-${String(decoded.error.code || "error").toLowerCase().slice(0, 20)}` : `plutil-exit-${Number.isInteger(decoded?.status) ? decoded.status : "unknown"}`);
|
|
34
|
+
}
|
|
35
|
+
let plist;
|
|
36
|
+
try { plist = JSON.parse(decoded.stdout); } catch { throw invalid("plutil-output-unreadable"); }
|
|
37
|
+
const args = plist?.ProgramArguments;
|
|
38
|
+
if (plist?.Label !== label) throw invalid("wrong-label");
|
|
39
|
+
if (!Array.isArray(args) || !args.every(x => typeof x === "string")) throw invalid("no-program-arguments");
|
|
40
|
+
if (plist.Program) throw invalid("program-key");
|
|
32
41
|
if (label === LABELS[0] && require("./node-contract.cjs").isElectronExecutable(args[0])) throw Error(`invalid-service-interpreter: ${label}`);
|
|
33
42
|
const suffix = label === LABELS[0] ? /[\\/]bin[\\/]relay\.js$/ : /[\\/]overlay[\\/]main\.cjs$/;
|
|
34
43
|
const script = args.find(x => /[\\/]node_modules[\\/]relay-companion[\\/]/.test(x) && suffix.test(x));
|
package/package.json
CHANGED