@lark-codem/codem-cli 0.1.279-dev.100104369221.0.g78d9435 → 0.1.279-dev.100104396969.0.g5dfd2fe
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/process-tree.js +25 -19
- package/bin/tt-env.js +1 -1
- package/bin/worker-runtime.js +2 -2
- package/package.json +9 -10
- package/profile/config-lock.js +44 -7
- package/profile/credential-errors.js +2 -1
- package/profile/runtime-logs.js +10 -77
- package/profile/realtime-log-id.js +0 -9
package/bin/process-tree.js
CHANGED
|
@@ -140,6 +140,7 @@ export async function snapshotDescendantPids(
|
|
|
140
140
|
*
|
|
141
141
|
* `descendants` 由调用方在树还完整时用 snapshotDescendantPids 取样后传入;
|
|
142
142
|
* 不传就现取(只在父进程仍活着时才有意义)。
|
|
143
|
+
* 父进程已退出时传 pid: null 和已记录的 descendants,只清理后代,避免向复用的父 PID 发信号。
|
|
143
144
|
*
|
|
144
145
|
* 返回实际发出信号的 pid 数——调用方用它做日志,不做控制流:kill 失败绝大多数
|
|
145
146
|
* 是"进程已经没了",那正是我们要的结果。
|
|
@@ -154,7 +155,8 @@ export async function terminateProcessTree({
|
|
|
154
155
|
timeoutMs = null,
|
|
155
156
|
onError = null
|
|
156
157
|
} = {}) {
|
|
157
|
-
|
|
158
|
+
const hasRoot = Number.isInteger(pid) && pid > 0;
|
|
159
|
+
if (!hasRoot && !Array.isArray(descendants)) {
|
|
158
160
|
return { signaled: 0 };
|
|
159
161
|
}
|
|
160
162
|
|
|
@@ -165,19 +167,21 @@ export async function terminateProcessTree({
|
|
|
165
167
|
|
|
166
168
|
if (platform === "win32") {
|
|
167
169
|
// /T 覆盖此刻仍挂在 pid 下的活树,一次调用比逐个 taskkill 更少竞态。
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
170
|
+
if (hasRoot) {
|
|
171
|
+
try {
|
|
172
|
+
await execFileImpl(
|
|
173
|
+
"taskkill.exe",
|
|
174
|
+
["/F", "/T", "/PID", String(pid)],
|
|
175
|
+
applyHostedWindowsChildOptions(
|
|
176
|
+
Number.isFinite(timeoutMs) && timeoutMs > 0 ? { timeout: timeoutMs } : {},
|
|
177
|
+
{ platform }
|
|
178
|
+
)
|
|
179
|
+
);
|
|
180
|
+
signaled += 1;
|
|
181
|
+
} catch (error) {
|
|
182
|
+
// pid 已消失时 taskkill 返回非 0,属预期。
|
|
183
|
+
onError?.(error);
|
|
184
|
+
}
|
|
181
185
|
}
|
|
182
186
|
// 快照里那些已经和 pid 断了血缘的(父先死的孤儿),/T 够不着,逐个补刀。
|
|
183
187
|
for (const targetPid of targets) {
|
|
@@ -207,11 +211,13 @@ export async function terminateProcessTree({
|
|
|
207
211
|
// 已退出。
|
|
208
212
|
}
|
|
209
213
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
214
|
+
if (hasRoot) {
|
|
215
|
+
try {
|
|
216
|
+
killImpl(pid, signal);
|
|
217
|
+
signaled += 1;
|
|
218
|
+
} catch {
|
|
219
|
+
// 已退出。
|
|
220
|
+
}
|
|
215
221
|
}
|
|
216
222
|
return { signaled };
|
|
217
223
|
}
|
package/bin/tt-env.js
CHANGED
|
@@ -58,7 +58,7 @@ export function resolveTtEnvLane(env = process.env) {
|
|
|
58
58
|
return parseTtEnvLane(env?.[CODEM_X_TT_ENV]);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
function isOfficialCodemHost(hostname) {
|
|
62
62
|
const host = hostname.toLowerCase();
|
|
63
63
|
return host === PROD_ROUTER_HOST || host === BOE_ROUTER_HOST;
|
|
64
64
|
}
|
package/bin/worker-runtime.js
CHANGED
|
@@ -229,10 +229,10 @@ export async function selectWorkerRuntime({ env = process.env, root = env.CODEM_
|
|
|
229
229
|
const reasons = [];
|
|
230
230
|
const load = async family => {
|
|
231
231
|
try {
|
|
232
|
-
const runtime = await loadRuntime(root, family);
|
|
232
|
+
const runtime = await loadRuntime(root, family, { retained: Boolean(actual || frozen), restoring });
|
|
233
233
|
// A retained alpha pair can recover its own Session, but cannot serve a new
|
|
234
234
|
// latest-channel Session after a failed channel switch.
|
|
235
|
-
if ((!actual || upgrading) && !frozen && family === 'current' && currentChannel !== null) {
|
|
235
|
+
if ((!actual || upgrading) && !frozen && runtime.family === 'current' && currentChannel !== null) {
|
|
236
236
|
const channel = typeof currentChannel === 'function' ? await currentChannel() : currentChannel;
|
|
237
237
|
if (runtime.channel !== channel) throw new Error('worker runtime channel unavailable');
|
|
238
238
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-codem/codem-cli",
|
|
3
|
-
"version": "0.1.279-dev.
|
|
3
|
+
"version": "0.1.279-dev.100104396969.0.g5dfd2fe",
|
|
4
4
|
"codemServiceManagementProtocol": 3,
|
|
5
|
-
"codemWorkerRuntimeProtocol": 1,
|
|
6
5
|
"codemProfileProtocol": 1,
|
|
7
6
|
"type": "module",
|
|
8
7
|
"description": "CodeM local CLI for Feishu-driven coding sessions",
|
|
@@ -30,17 +29,17 @@
|
|
|
30
29
|
"access": "public"
|
|
31
30
|
},
|
|
32
31
|
"dependencies": {
|
|
33
|
-
"@lark-codem/codem-core": "0.8.96-dev.
|
|
32
|
+
"@lark-codem/codem-core": "0.8.96-dev.100104396969.0.g1b41401",
|
|
34
33
|
"zod": "3.25.76",
|
|
35
|
-
"@lark-codem/lark-cli": "0.1.
|
|
34
|
+
"@lark-codem/lark-cli": "0.1.5"
|
|
36
35
|
},
|
|
37
36
|
"optionalDependencies": {
|
|
38
|
-
"@lark-codem/codem-cli-darwin-arm64": "0.1.279-dev.
|
|
39
|
-
"@lark-codem/codem-cli-darwin-x64": "0.1.279-dev.
|
|
40
|
-
"@lark-codem/codem-cli-linux-arm64": "0.1.279-dev.
|
|
41
|
-
"@lark-codem/codem-cli-linux-x64": "0.1.279-dev.
|
|
42
|
-
"@lark-codem/codem-cli-win32-arm64": "0.1.279-dev.
|
|
43
|
-
"@lark-codem/codem-cli-win32-x64": "0.1.279-dev.
|
|
37
|
+
"@lark-codem/codem-cli-darwin-arm64": "0.1.279-dev.100104396969.0.g5dfd2fe",
|
|
38
|
+
"@lark-codem/codem-cli-darwin-x64": "0.1.279-dev.100104396969.0.g5dfd2fe",
|
|
39
|
+
"@lark-codem/codem-cli-linux-arm64": "0.1.279-dev.100104396969.0.g5dfd2fe",
|
|
40
|
+
"@lark-codem/codem-cli-linux-x64": "0.1.279-dev.100104396969.0.g5dfd2fe",
|
|
41
|
+
"@lark-codem/codem-cli-win32-arm64": "0.1.279-dev.100104396969.0.g5dfd2fe",
|
|
42
|
+
"@lark-codem/codem-cli-win32-x64": "0.1.279-dev.100104396969.0.g5dfd2fe"
|
|
44
43
|
},
|
|
45
44
|
"engines": {
|
|
46
45
|
"node": ">=18"
|
package/profile/config-lock.js
CHANGED
|
@@ -73,6 +73,7 @@ import { debugLog } from "./debug.js";
|
|
|
73
73
|
const DEFAULT_STALE_MS = 10_000;
|
|
74
74
|
const DEFAULT_TIMEOUT_MS = 15_000;
|
|
75
75
|
const DEFAULT_RETRY_MS = 75;
|
|
76
|
+
const RELEASE_EMPTY_READ_DELAYS_MS = [50, 100, 200, 400, 500, 500];
|
|
76
77
|
const REAPER_CHOOSING_PREFIX = "choosing-";
|
|
77
78
|
const REAPER_TICKET_PREFIX = "ticket-";
|
|
78
79
|
const REAPER_TICKET_WIDTH = 16;
|
|
@@ -160,6 +161,48 @@ async function readOwner(filePath) {
|
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
|
|
164
|
+
async function releaseOwnedLock(lockFile, token, sleep) {
|
|
165
|
+
let stage = "read";
|
|
166
|
+
let attempts = 0;
|
|
167
|
+
try {
|
|
168
|
+
// s3fs can return an empty body after the lock was written and closed.
|
|
169
|
+
let raw;
|
|
170
|
+
do {
|
|
171
|
+
attempts++;
|
|
172
|
+
raw = await fs.readFile(lockFile, "utf8");
|
|
173
|
+
if (raw.length !== 0) break;
|
|
174
|
+
if (attempts > RELEASE_EMPTY_READ_DELAYS_MS.length) {
|
|
175
|
+
debugLog("config-lock.release_failed", { lockFile, stage, attempts, outcome: "empty_read_exhausted" });
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
await sleep(RELEASE_EMPTY_READ_DELAYS_MS[attempts - 1]);
|
|
179
|
+
} while (true);
|
|
180
|
+
|
|
181
|
+
stage = "parse";
|
|
182
|
+
const owner = JSON.parse(raw);
|
|
183
|
+
if (typeof owner?.token !== "string") {
|
|
184
|
+
debugLog("config-lock.release_failed", { lockFile, stage, attempts, outcome: "invalid_record" });
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (owner.token !== token) {
|
|
188
|
+
debugLog("config-lock.release_failed", { lockFile, stage: "ownership", attempts, outcome: "owner_changed" });
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// A live holder is the only participant that can remove its lock under this protocol.
|
|
193
|
+
stage = "remove";
|
|
194
|
+
await fs.unlink(lockFile);
|
|
195
|
+
} catch (error) {
|
|
196
|
+
if (error?.code === "ENOENT") return;
|
|
197
|
+
debugLog("config-lock.release_failed", {
|
|
198
|
+
lockFile, stage, attempts, outcome: stage === "parse" ? "invalid_record" : "io_error",
|
|
199
|
+
errorCode: error?.code, errorClass: error?.name,
|
|
200
|
+
// JSON.parse errors can echo file contents. Keep only stack frames.
|
|
201
|
+
stack: error?.stack?.split("\n").filter((line) => line.startsWith(" at ")).join("\n")
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
163
206
|
// 机会性清扫残留 tmp(Bug 7384601509):tmp 的生命周期原本只挂在「获取进程走完所有
|
|
164
207
|
// 出口」上——等待窗口内被 SIGINT/SIGTERM/SIGKILL/崩溃/断电终止的进程,其 tmp 因文件名
|
|
165
208
|
// 内嵌 randomUUID 永不复用而永久残留。这里在每次获取时顺带回收同目录的 `<lock>.tmp-*`
|
|
@@ -298,13 +341,7 @@ export async function acquireConfigLock(targetPath, {
|
|
|
298
341
|
return;
|
|
299
342
|
}
|
|
300
343
|
released = true;
|
|
301
|
-
|
|
302
|
-
// 绝不移动或删除别人的锁。存活 holder 的锁只有自己会删(见头注不变量),
|
|
303
|
-
// 所以这里的 read→unlink 无竞态。
|
|
304
|
-
const owner = await readOwner(lockFile);
|
|
305
|
-
if (owner?.token === token) {
|
|
306
|
-
await fs.rm(lockFile, { force: true }).catch(() => {});
|
|
307
|
-
}
|
|
344
|
+
await releaseOwnedLock(lockFile, token, sleep);
|
|
308
345
|
};
|
|
309
346
|
}
|
|
310
347
|
} finally {
|
|
@@ -31,6 +31,7 @@ export class CredentialStorageError extends Error {
|
|
|
31
31
|
export function isRecoverableCredentialState(error) {
|
|
32
32
|
return error?.code === "credential_storage_rotation_pending"
|
|
33
33
|
|| error?.code === "credential_storage_rotation_unknown"
|
|
34
|
-
//
|
|
34
|
+
// A missing OAuth record permits reauthorization with the existing device,
|
|
35
|
+
// never use of its stale plaintext mirror or another credential kind.
|
|
35
36
|
|| (error?.code === "credential_storage_missing" && error.kind === "oauth");
|
|
36
37
|
}
|
package/profile/runtime-logs.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { realtimeLogID } from "./realtime-log-id.js";
|
|
2
1
|
import { workerRuntimeAttributes } from "./worker-runtime-observation.js";
|
|
3
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
3
|
import os from "node:os";
|
|
@@ -79,43 +78,26 @@ const OBSERVATION_METRICS = {
|
|
|
79
78
|
};
|
|
80
79
|
const EXTRA_FIELDS = ["observation_id", "runtime_client_instance_id", "command_id", "delivery_id", "probe_id", "sync_id", "transport_request_id", "attempt_id"];
|
|
81
80
|
const LIFECYCLE_EXTRA_FIELDS = [...EXTRA_FIELDS, "process_instance_id", "startup_id", "request_id", "event_id"];
|
|
82
|
-
const UPLINK_BATCH_METRICS = [
|
|
83
|
-
"message_count", "packet_bytes", "queue_wait_ms", "encode_ms", "ack_wait_ms",
|
|
84
|
-
"batch_sequence", "pending_count", "pending_bytes"
|
|
85
|
-
];
|
|
86
|
-
const UPLINK_DIAGNOSTIC_METRICS = new Map([
|
|
87
|
-
["uplink_queue_pressure", ["pending_count", "pending_bytes", "oldest_age_ms", "full_count", "batch_sequence", "ack_wait_ms"]],
|
|
88
|
-
["event_handoff_failed", UPLINK_BATCH_METRICS],
|
|
89
|
-
["uplink_batch_slow", UPLINK_BATCH_METRICS]
|
|
90
|
-
]);
|
|
91
81
|
const STRING_FIELDS = new Set([
|
|
92
|
-
|
|
93
|
-
"
|
|
82
|
+
...EXTRA_FIELDS, "command_type", "ack_status", "ack_outcome", "readback_scope", "timing_origin", "required_capability",
|
|
83
|
+
"request_id", "command_id", "session_id", "task_id", "dispatch_id", "event_id", "sync_id",
|
|
94
84
|
"process_instance_id", "run_id", "stage", "phase", "status", "outcome", "reason", "action",
|
|
95
85
|
"error_class", "error_code", "error_kind", "error_type", "code", "signal", "stop_reason",
|
|
96
86
|
"first_error", "retry_source", "cleanup_result",
|
|
97
87
|
"terminal_event", "event_type", "actor_type", "source", "trigger", "hook_id", "hook_event",
|
|
98
88
|
"target_version", "cli_version", "core_version", "version", "previous_state", "state",
|
|
99
89
|
"failure_kind", "failure_impact", "failure_type", "failure_subtype", "failure_code", "failure_status", "delay_source", "mode", "provider", "name", "termination", "interaction_id", "interaction_kind", "owner_state", "artifact_id", "resource_type", "delivery_mode", "host", "scheme", "tool_call_id", "tool_name", "background_task_id", "model", "artifact_kind", "codem_user_id", "device_id", "operation", "foreground_error_code",
|
|
100
|
-
"operation_id", "entrypoint", "workflow_launch_id"
|
|
101
|
-
"load_id", "refresh_id", "registry_snapshot_id", "capability_key", "capability_type",
|
|
102
|
-
"component_type", "publisher_type", "capability_source", "installation_mode",
|
|
103
|
-
"capability_version", "project_key", "business_scene", "invocation_id", "result",
|
|
104
|
-
"error_category", "runtime_scope", "refresh_trigger", "load_trigger", "stage_name",
|
|
105
|
-
"operation_name", "invocation_source", "binding_state", "load_result"
|
|
90
|
+
"operation_id", "entrypoint", "workflow_launch_id"
|
|
106
91
|
]);
|
|
107
92
|
const VALUE_FIELDS = new Set([
|
|
108
93
|
"session_retained", "lease_valid_until_ms", "requested_valid_until_ms", "lease_remaining_ms", "wall_remaining_ms",
|
|
109
|
-
"local_rpc_id", "batch_index", "rpc_error_code", "has_subscribers", "window_active",
|
|
110
94
|
...new Set(Object.values(OBSERVATION_METRICS).flat()),
|
|
111
95
|
"pid", "exit_code", "duration_ms", "elapsed_ms", "wait_ms", "run_ms", "total_ms", "took_ms",
|
|
112
96
|
"attempt", "attempts", "attempt_count", "retryable", "http_status", "errno", "active_task_count",
|
|
113
97
|
"pending_event_count", "pending_command_ack_count", "next_retry_ms", "consecutive_failures",
|
|
114
|
-
...Array.from(UPLINK_DIAGNOSTIC_METRICS.values()).flat(), "transport_open",
|
|
115
98
|
"outage_duration_ms", "startup_duration_ms", "failed_attempts", "active_runs", "completed",
|
|
116
99
|
"delivered", "result_delivered", "queued_behind_existing", "expected", "timed_out",
|
|
117
100
|
"force_exit_ms", "teardown_ceiling_ms", "recovered", "count", "ms_since_process_start", "owner_pid", "consumed", "delivery_attempt", "ack_deadline_ms", "command_to_bridge_ms", "size_bytes", "source_size_bytes", "processed_bytes", "before", "after", "omitted_detail_count", "opened", "selected", "foreground",
|
|
118
|
-
"expected_count", "loaded_count", "loaded_capability_count", "failed_count", "skipped_count", "ready_count", "downloaded_count", "turn_id", "turn_index",
|
|
119
101
|
...LIFECYCLE_METRICS
|
|
120
102
|
]);
|
|
121
103
|
|
|
@@ -133,7 +115,7 @@ function optional(read) {
|
|
|
133
115
|
}
|
|
134
116
|
|
|
135
117
|
function metricProjection(event, fields = {}) {
|
|
136
|
-
return { count: 1, ...Object.fromEntries((OBSERVATION_METRICS[event] ??
|
|
118
|
+
return { count: 1, ...Object.fromEntries((OBSERVATION_METRICS[event] ?? [])
|
|
137
119
|
.filter(key => typeof fields?.[key] === "number" && Number.isFinite(fields[key]) && fields[key] >= 0)
|
|
138
120
|
.map(key => [key, fields[key]])) };
|
|
139
121
|
}
|
|
@@ -142,18 +124,11 @@ function extraProjection(fields = {}) {
|
|
|
142
124
|
return Object.fromEntries(EXTRA_FIELDS.filter(key => token(fields?.[key])).map(key => [key, token(fields[key])]));
|
|
143
125
|
}
|
|
144
126
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
function projectFields(input, fingerprintErrors = true, component) {
|
|
127
|
+
function projectFields(input, fingerprintErrors = true) {
|
|
148
128
|
const result = {};
|
|
149
129
|
for (const [key, value] of Object.entries(input ?? {}).slice(0, 100)) {
|
|
150
130
|
const name = fieldName(key);
|
|
151
|
-
if (
|
|
152
|
-
result[name] = value;
|
|
153
|
-
} else if (component === "realtime" && REALTIME_IDS.has(name)) {
|
|
154
|
-
const id = realtimeLogID(value);
|
|
155
|
-
if (id !== undefined) result[name] = id;
|
|
156
|
-
} else if (STRING_FIELDS.has(name)) {
|
|
131
|
+
if (STRING_FIELDS.has(name)) {
|
|
157
132
|
const safe = token(value);
|
|
158
133
|
if (safe) result[name] = safe;
|
|
159
134
|
} else if (VALUE_FIELDS.has(name) && (typeof value === "boolean" || (typeof value === "number" && Number.isFinite(value)))) {
|
|
@@ -204,13 +179,7 @@ function lifecycleErrorCode(fields) {
|
|
|
204
179
|
return fields.outcome === "failed" || fields.outcome === "rejected" || fields.outcome === "conflicting" ? "unknown" : undefined;
|
|
205
180
|
}
|
|
206
181
|
|
|
207
|
-
const REALTIME_LOG_ONLY = new Set([
|
|
208
|
-
"app_server_rpc", "app_server_rpc_unmatched", "app_server_host_attached", "app_server_host_failed", "app_server_question", "hitl_answer",
|
|
209
|
-
"downlink_admission", "rpc_reply", "uplink_commit", "uplink_transport", "subscription_query", "runtime_lease"
|
|
210
|
-
]);
|
|
211
|
-
|
|
212
182
|
function keepLegacyMetric(event, fields, role, severity) {
|
|
213
|
-
if (REALTIME_LOG_ONLY.has(event)) return false;
|
|
214
183
|
if (/^startup\.(?:main|update_check|daemon_service_reconcile|login_gate|login_handoff_to_linco)$/u.test(event) && severity === "info") return false;
|
|
215
184
|
if (/(?:^|\.)drain_(?:started|completed)$/u.test(event) && severity === "info") return false;
|
|
216
185
|
if (role === "daemon" && event === "runtime_capability_probe" && severity === "info") return false;
|
|
@@ -347,35 +316,7 @@ export class RuntimeLogReporter {
|
|
|
347
316
|
|
|
348
317
|
get pendingCount() { return this.#live.queue.length + this.#replay.queue.length; }
|
|
349
318
|
get droppedCount() { return this.#dropped; }
|
|
350
|
-
|
|
351
|
-
#header() {
|
|
352
|
-
const identity = this.#identity;
|
|
353
|
-
return { aid: SLARDAR_PC_AID, device_id: identity.deviceId ?? this.#instanceId,
|
|
354
|
-
user_id: identity.userId ?? "0", parfait_version: SLARDAR_PC_REPORTER_VERSION,
|
|
355
|
-
channel: identity.channel ?? "unknown", os: this.#platform, os_version: this.#osVersion };
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
recordMetric(name, category, metrics) {
|
|
359
|
-
if (this.#closed) return false;
|
|
360
|
-
if (this.#live.queue.length >= CAPACITY) {
|
|
361
|
-
this.#dropped += 1;
|
|
362
|
-
return false;
|
|
363
|
-
}
|
|
364
|
-
const identity = this.#identity;
|
|
365
|
-
const record = {
|
|
366
|
-
app_version: this.#version, app_minor_version: "", build_id: "",
|
|
367
|
-
process_type: `codem-${this.#role}`, session_id: "", timestamp: Date.now(),
|
|
368
|
-
log_type: "flexible", event_name: name,
|
|
369
|
-
category: { reporter: "codem_js", runtime_role: this.#role,
|
|
370
|
-
...(identity.tenantId ? { tenant_id: identity.tenantId } : {}), ...category },
|
|
371
|
-
metrics
|
|
372
|
-
};
|
|
373
|
-
this.#live.queue.push({ header: this.#header(), record, metricName: null, attempts: 0 });
|
|
374
|
-
// Bursts need not wait for the periodic timer, and a slow collector still
|
|
375
|
-
// has only one bounded in-flight upload.
|
|
376
|
-
if (this.#live.queue.length >= BATCH_SIZE) void this.#flushLane(this.#live, REQUEST_TIMEOUT_MS);
|
|
377
|
-
return true;
|
|
378
|
-
}
|
|
319
|
+
get identityKey() { return JSON.stringify([this.#instanceId, this.#role, this.#identity.deviceId, this.#identity.userId, this.#identity.tenantId]); }
|
|
379
320
|
|
|
380
321
|
record(level, component, event, fields = {}) {
|
|
381
322
|
try {
|
|
@@ -386,17 +327,13 @@ export class RuntimeLogReporter {
|
|
|
386
327
|
|
|
387
328
|
#logEntry(level, component, event, fields) {
|
|
388
329
|
let safeFields;
|
|
389
|
-
try { safeFields = projectFields(fields
|
|
330
|
+
try { safeFields = projectFields(fields); } catch { safeFields = {}; }
|
|
390
331
|
if (OBSERVATION_EVENTS.has(event)) safeFields.observation_id = randomUUID();
|
|
391
332
|
const severity = ["info", "warn", "error", "fatal"].includes(level) ? level : "info";
|
|
392
333
|
// Keep arbitrary upstream error codes out of trusted-device metric dimensions.
|
|
393
334
|
const trustedDevice = TRUSTED_DEVICE_EVENTS.has(event);
|
|
394
335
|
const dimensions = trustedDevice ? {} : Object.fromEntries(["stage", "error_class", "error_code", "error_kind", "outcome"]
|
|
395
336
|
.filter(key => safeFields[key]).map(key => [key, safeFields[key]]));
|
|
396
|
-
if (UPLINK_DIAGNOSTIC_METRICS.has(event)) {
|
|
397
|
-
if (safeFields.lane) dimensions.lane = safeFields.lane;
|
|
398
|
-
if (safeFields.target_kind) dimensions.target_kind = safeFields.target_kind;
|
|
399
|
-
}
|
|
400
337
|
if (OBSERVATION_EVENTS.has(event)) {
|
|
401
338
|
for (const [key, values] of Object.entries(trustedDevice ? TRUSTED_DEVICE_DIMENSIONS : OBSERVATION_DIMENSIONS)) {
|
|
402
339
|
if (safeFields[key]) dimensions[key] = values.includes(safeFields[key]) ? safeFields[key] : "unknown";
|
|
@@ -656,10 +593,6 @@ export function flushRuntimeLogsInBackground() {
|
|
|
656
593
|
if (active) setImmediate(() => { void active?.flush().catch(() => {}); }).unref?.();
|
|
657
594
|
}
|
|
658
595
|
|
|
659
|
-
export function recordRuntimeMetric(name, category, metrics) {
|
|
660
|
-
try { return active?.recordMetric(name, category, metrics) ?? false; } catch { return false; }
|
|
661
|
-
}
|
|
662
|
-
|
|
663
596
|
export function persistRuntimeCrash(component, event, fields) {
|
|
664
597
|
try { active?.persistCrash(component, event, fields); } catch { /* best effort */ }
|
|
665
598
|
}
|
|
@@ -719,9 +652,9 @@ export function recordInteractiveProcessExit({ exitCode, signal }) {
|
|
|
719
652
|
export function recordSelectedRuntimeLog(component, event, fields = {}) {
|
|
720
653
|
try {
|
|
721
654
|
const selectedEvent = event.replace(/^linco\./u, "");
|
|
722
|
-
if (!/^(?:startup\.(?:main|update_check|daemon_service_reconcile|login_gate|login_handoff_to_linco)|oauth\.refresh\.(?:relogin_suspect|persist_failed|persisted)|managed_config\.(?:member_refresh_failed|sandbox_refresh_failed|sandbox_fetch_recovered|sandbox_fetch_exhausted|refreshed|resource_failed)|
|
|
655
|
+
if (!/^(?:startup\.(?:main|update_check|daemon_service_reconcile|login_gate|login_handoff_to_linco)|oauth\.refresh\.(?:relogin_suspect|persist_failed|persisted)|managed_config\.(?:member_refresh_failed|sandbox_refresh_failed|sandbox_fetch_recovered|sandbox_fetch_exhausted|refreshed|resource_failed)|(?:agent|command)\.(?:start|interactive_start|success|error|spawn_error|resolve_error|exit_drain_timeout|cancelled_before_spawn|artifact_oversize|artifact_missing|artifact_dropped|artifact_route_selected|artifact_image_upload|artifact_file_upload|artifact_local_register)|router\.credentials\.(?:ensured|refresh_failed)|config-lock\.release_failed|binary\.heal_chmod_failed|project\.(?:inject_error|state)|(?:permission_ask|user_question|plan)\.report_failed|process_tree\.(?:force_kill|force_kill_failed)|artifact\.(?:oversize|missing|dropped)|runtime_post\.daemon\.device_rebind_[a-z_]+)$/u.test(selectedEvent)) return;
|
|
723
656
|
const expected = optional(() => fields?.errorKind === "user_stop" || fields?.terminalError?.kind === "user_stop" || fields?.exitCode === 130 || fields?.signal === "SIGINT");
|
|
724
|
-
const level = expected ? "info" : (fields?.status === "failed" ||
|
|
657
|
+
const level = expected ? "info" : (fields?.status === "failed" || /(?:failed|error|exhausted|timeout)$/u.test(event)) ? "error" : /(?:suspect|dropped|missing|oversize)$/u.test(event) ? "warn" : "info";
|
|
725
658
|
recordRuntimeLog(level, component, event, fields);
|
|
726
659
|
} catch { /* best effort */ }
|
|
727
660
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// Base bounds the JSON encoding of RPC IDs at 1024 bytes. Printable route
|
|
2
|
-
// keys include Go QueryEscape's percent escapes and plus sign. Only record
|
|
3
|
-
// identifier characters; never truncate two different IDs to the same value.
|
|
4
|
-
export function realtimeLogID(value) {
|
|
5
|
-
if (Number.isSafeInteger(value)) return value;
|
|
6
|
-
if (typeof value === "string" && value.length <= 1022 &&
|
|
7
|
-
/^[\p{L}\p{N}_.:%~+-]+$/u.test(value) && Buffer.byteLength(value) <= 1022) return value;
|
|
8
|
-
return undefined;
|
|
9
|
-
}
|