@lark-codem/codem-cli 0.1.273 → 0.1.274-dev-local-session-handoff.202611162309.0.g72d20c0
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/LICENSE +6 -6
- package/bin/codem-service.js +132 -132
- package/bin/codem.js +250 -250
- package/bin/linco-paths.js +45 -45
- package/bin/platform-child-process.js +178 -178
- package/bin/tt-env.js +171 -171
- package/bin/worker-runtime-telemetry.js +75 -75
- package/bin/worker-runtime.js +294 -345
- package/package.json +8 -8
- package/profile/config-lock.js +512 -512
- package/profile/credential-errors.js +37 -37
- package/profile/credential-metadata.js +29 -29
- package/profile/debug.js +104 -104
- package/profile/device-identity.js +95 -95
- package/profile/diagnostic-id.js +47 -47
- package/profile/index.d.ts +61 -61
- package/profile/index.js +17 -17
- package/profile/profile-io.js +70 -70
- package/profile/profile-migration.js +1022 -1022
- package/profile/profile-snapshot.js +120 -120
- package/profile/profile-writers.js +296 -296
- package/profile/runtime-logs.js +662 -660
- package/profile/slardar-pc-transport.js +42 -42
- package/profile/worker-runtime-observation.js +10 -10
- package/bin/process-tree.js +0 -217
package/profile/runtime-logs.js
CHANGED
|
@@ -1,660 +1,662 @@
|
|
|
1
|
-
import { workerRuntimeAttributes } from "./worker-runtime-observation.js";
|
|
2
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
3
|
-
import os from "node:os";
|
|
4
|
-
import fs from "node:fs";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { diagnosticId } from "./diagnostic-id.js";
|
|
7
|
-
import { readDeviceId } from "./device-identity.js";
|
|
8
|
-
import { sendSlardarPcBatch, SLARDAR_PC_AID, SLARDAR_PC_REPORTER_VERSION } from "./slardar-pc-transport.js";
|
|
9
|
-
|
|
10
|
-
const CAPACITY = 256;
|
|
11
|
-
const BATCH_SIZE = 32;
|
|
12
|
-
const INTERVAL_MS = 10_000;
|
|
13
|
-
const REQUEST_TIMEOUT_MS = 3_000;
|
|
14
|
-
const MAX_BATCH_BYTES = 256 * 1024;
|
|
15
|
-
const LIFECYCLE_EVENT_NAME = "codem_bridge_lifecycle";
|
|
16
|
-
const LIFECYCLE_COMPONENTS = {
|
|
17
|
-
daemon_startup: "daemon", runtime_sync: "runtime-post", command_handoff: "bridge",
|
|
18
|
-
runner_operation: "bridge", delivery_settled: "runtime-post", runtime_state: "bridge",
|
|
19
|
-
event_discarded: "runtime-post", process_lifecycle: "linco"
|
|
20
|
-
};
|
|
21
|
-
const LIFECYCLE_METRICS = [
|
|
22
|
-
"duration_ms", "ack_settle_duration_ms", "startup_wait_ms", "operation_age_ms",
|
|
23
|
-
"outage_duration_ms", "consecutive_failures", "deferred_age_ms", "pending_command_ack_count",
|
|
24
|
-
"pending_ack_age_ms", "pending_event_count", "oldest_event_age_ms", "lifetime_ms"
|
|
25
|
-
];
|
|
26
|
-
const LIFECYCLE_DIMENSIONS = {
|
|
27
|
-
outcome: ["success", "failed", "rejected", "canceled", "unknown", "accepted", "duplicate", "conflicting", "observed", "recovered"],
|
|
28
|
-
operation: ["prepare", "spawn", "ready", "cancel", "shutdown"],
|
|
29
|
-
scope: ["startup", "runner", "sync", "command", "queue"],
|
|
30
|
-
kind: ["command_ack", "runtime_event", "control", "events", "relay", "offline"],
|
|
31
|
-
phase: ["startup_marker", "prelude", "healthcheck", "config_load", "update_check", "service_reconcile", "login_gate", "launch", "authentication", "singleton", "initialize", "start_client", "first_sync", "trusted_device",
|
|
32
|
-
"build_request", "request", "validate_response", "apply_response", "persist_state",
|
|
33
|
-
"admission", "handler", "resolve_binary", "build_env", "host_capabilities", "parse_capabilities",
|
|
34
|
-
"strict_resume", "verify_binding", "prepare", "spawn", "ready", "cancel", "teardown"],
|
|
35
|
-
reason: ["overflow", "oversized", "timeout", "cleanup_failed", "unsupported_command", "invalid_payload",
|
|
36
|
-
"shutting_down_handoff", "handoff_target_not_active", "handler_inflight", "duplicate_inflight",
|
|
37
|
-
"runtime_unavailable", "runtime_environment_failed", "capability_probe_failed", "runtime_binary_changed",
|
|
38
|
-
"strict_resume_unsupported", "turn_context_unsupported", "active_run_protocol_mismatch", "trusted_device_blocked",
|
|
39
|
-
"invalid_runtime_event", "event_rejected", "task_terminated:canceled", "task_terminated:failed", "task_terminated:succeeded"],
|
|
40
|
-
error_source: ["bridge", "base", "linco", "transport"],
|
|
41
|
-
stability: ["stable", "unstable", "unknown"],
|
|
42
|
-
action: ["exit", "restart"],
|
|
43
|
-
expected: ["true", "false", "unknown"],
|
|
44
|
-
critical: ["true", "false"]
|
|
45
|
-
};
|
|
46
|
-
const TRUSTED_DEVICE_EVENTS = new Set(["host_identity_collection", "host_identity_command", "host_session_attempt", "host_session_expired", "trusted_device_admission_blocked", "trusted_device_admission_recovered"]);
|
|
47
|
-
const TRUSTED_DEVICE_PHASES = ["auth", "identity", "provider", "host_key", "activation_state", "activation_apply", "activation_sign", "activation_complete", "credential_resolve", "session_apply", "session_sign", "session_complete", "trusted_device"];
|
|
48
|
-
const TRUSTED_DEVICE_DIMENSIONS = {
|
|
49
|
-
phase: TRUSTED_DEVICE_PHASES,
|
|
50
|
-
operation: ["create", "renew", "recovery", "platform_identity", "network_interfaces", "network_ports", "serial_number", "platform_uuid", "network_adapters"],
|
|
51
|
-
outcome: ["success", "partial", "failed", "ready", "not_registered", "no_auth", "reset", "blocked", "invalid", "verified", "not_required", "absent", "expired"],
|
|
52
|
-
failure_kind: ["none", "timeout", "exec_failed", "invalid_json", "empty_identity", "read_failed", "authorization", "unknown"]
|
|
53
|
-
};
|
|
54
|
-
const OBSERVATION_EVENTS = new Set(["command_delivery_observed", "command_admission", "runtime_capability_probe", "command_ack", "command_observation_closed", "diagnostic_reporter_health", ...TRUSTED_DEVICE_EVENTS]);
|
|
55
|
-
const OBSERVATION_DIMENSIONS = {
|
|
56
|
-
phase: ["resolve_binary", "build_env", "host_capabilities", "parse_capabilities", "strict_resume", "verify_binding", "prepare", "persist_state", "trusted_device", "request", "validate_response", "apply_response"],
|
|
57
|
-
reason: ["runtime_unavailable", "runtime_environment_failed", "capability_probe_failed", "runtime_binary_changed", "strict_resume_unsupported", "turn_context_unsupported", "active_run_protocol_mismatch", "trusted_device_blocked", "shutting_down_handoff", "handoff_target_not_active", "duplicate_inflight", "handler_inflight", "prepare_exception_unknown", "capacity", "stopped", "replaced", "scope_changed", "queue_removed", "local_rejected"],
|
|
58
|
-
command_type: ["agent.run", "agent.steer", "agent.stop", "task.assign", "task.stop", "artifact.relay.read", "artifact.convert_to_lark_resource", "artifact.download", "directory.list", "git.preview", "workflow.preview"],
|
|
59
|
-
actor_type: ["device", "sandbox"],
|
|
60
|
-
ack_status: ["accepted", "ignored_duplicate", "rejected"],
|
|
61
|
-
ack_outcome: ["accepted", "duplicate", "rejected", "conflicting"],
|
|
62
|
-
readback_scope: ["command", "delivery", "unmatched"],
|
|
63
|
-
timing_origin: ["observed", "restored_unknown"]
|
|
64
|
-
};
|
|
65
|
-
const OBSERVATION_METRICS = {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
"
|
|
96
|
-
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
result[name] =
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (token(error.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
dimensions.
|
|
168
|
-
dimensions.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
if (
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if (
|
|
186
|
-
if (
|
|
187
|
-
if (
|
|
188
|
-
return
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
#
|
|
216
|
-
#
|
|
217
|
-
#
|
|
218
|
-
#
|
|
219
|
-
#
|
|
220
|
-
#
|
|
221
|
-
#
|
|
222
|
-
#
|
|
223
|
-
#
|
|
224
|
-
#
|
|
225
|
-
#
|
|
226
|
-
#
|
|
227
|
-
#
|
|
228
|
-
#
|
|
229
|
-
#
|
|
230
|
-
#
|
|
231
|
-
#
|
|
232
|
-
#
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
this.#
|
|
238
|
-
this.#
|
|
239
|
-
this.#
|
|
240
|
-
this.#
|
|
241
|
-
this.#
|
|
242
|
-
this.#
|
|
243
|
-
this.#
|
|
244
|
-
this.#
|
|
245
|
-
this.#
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
//
|
|
251
|
-
//
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
this.#
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
this.#
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
const
|
|
286
|
-
if (
|
|
287
|
-
|
|
288
|
-
if (entry
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
this.#replay.queue.push({
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
get
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
const
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
const {
|
|
378
|
-
const
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
...
|
|
382
|
-
|
|
383
|
-
...(
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
...
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
this.#dropped += 1;
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
//
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
const
|
|
509
|
-
const
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
batch.
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
lane.
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
export function
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
active
|
|
571
|
-
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
:
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
...
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
const
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
1
|
+
import { workerRuntimeAttributes } from "./worker-runtime-observation.js";
|
|
2
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { diagnosticId } from "./diagnostic-id.js";
|
|
7
|
+
import { readDeviceId } from "./device-identity.js";
|
|
8
|
+
import { sendSlardarPcBatch, SLARDAR_PC_AID, SLARDAR_PC_REPORTER_VERSION } from "./slardar-pc-transport.js";
|
|
9
|
+
|
|
10
|
+
const CAPACITY = 256;
|
|
11
|
+
const BATCH_SIZE = 32;
|
|
12
|
+
const INTERVAL_MS = 10_000;
|
|
13
|
+
const REQUEST_TIMEOUT_MS = 3_000;
|
|
14
|
+
const MAX_BATCH_BYTES = 256 * 1024;
|
|
15
|
+
const LIFECYCLE_EVENT_NAME = "codem_bridge_lifecycle";
|
|
16
|
+
const LIFECYCLE_COMPONENTS = {
|
|
17
|
+
daemon_startup: "daemon", runtime_sync: "runtime-post", command_handoff: "bridge",
|
|
18
|
+
runner_operation: "bridge", delivery_settled: "runtime-post", runtime_state: "bridge",
|
|
19
|
+
event_discarded: "runtime-post", process_lifecycle: "linco"
|
|
20
|
+
};
|
|
21
|
+
const LIFECYCLE_METRICS = [
|
|
22
|
+
"duration_ms", "ack_settle_duration_ms", "startup_wait_ms", "operation_age_ms",
|
|
23
|
+
"outage_duration_ms", "consecutive_failures", "deferred_age_ms", "pending_command_ack_count",
|
|
24
|
+
"pending_ack_age_ms", "pending_event_count", "oldest_event_age_ms", "lifetime_ms"
|
|
25
|
+
];
|
|
26
|
+
const LIFECYCLE_DIMENSIONS = {
|
|
27
|
+
outcome: ["success", "failed", "rejected", "canceled", "unknown", "accepted", "duplicate", "conflicting", "observed", "recovered"],
|
|
28
|
+
operation: ["prepare", "spawn", "ready", "cancel", "shutdown"],
|
|
29
|
+
scope: ["startup", "runner", "sync", "command", "queue"],
|
|
30
|
+
kind: ["command_ack", "runtime_event", "control", "events", "relay", "offline"],
|
|
31
|
+
phase: ["startup_marker", "prelude", "healthcheck", "config_load", "update_check", "service_reconcile", "login_gate", "launch", "authentication", "singleton", "initialize", "start_client", "first_sync", "trusted_device",
|
|
32
|
+
"build_request", "request", "validate_response", "apply_response", "persist_state",
|
|
33
|
+
"admission", "handler", "resolve_binary", "build_env", "host_capabilities", "parse_capabilities",
|
|
34
|
+
"strict_resume", "verify_binding", "prepare", "spawn", "ready", "cancel", "teardown"],
|
|
35
|
+
reason: ["overflow", "oversized", "timeout", "cleanup_failed", "unsupported_command", "invalid_payload",
|
|
36
|
+
"shutting_down_handoff", "handoff_target_not_active", "handler_inflight", "duplicate_inflight",
|
|
37
|
+
"runtime_unavailable", "runtime_environment_failed", "capability_probe_failed", "runtime_binary_changed",
|
|
38
|
+
"strict_resume_unsupported", "turn_context_unsupported", "active_run_protocol_mismatch", "trusted_device_blocked",
|
|
39
|
+
"invalid_runtime_event", "event_rejected", "task_terminated:canceled", "task_terminated:failed", "task_terminated:succeeded"],
|
|
40
|
+
error_source: ["bridge", "base", "linco", "transport"],
|
|
41
|
+
stability: ["stable", "unstable", "unknown"],
|
|
42
|
+
action: ["exit", "restart"],
|
|
43
|
+
expected: ["true", "false", "unknown"],
|
|
44
|
+
critical: ["true", "false"]
|
|
45
|
+
};
|
|
46
|
+
const TRUSTED_DEVICE_EVENTS = new Set(["host_identity_collection", "host_identity_command", "host_session_attempt", "host_session_expired", "trusted_device_admission_blocked", "trusted_device_admission_recovered"]);
|
|
47
|
+
const TRUSTED_DEVICE_PHASES = ["auth", "identity", "provider", "host_key", "activation_state", "activation_apply", "activation_sign", "activation_complete", "credential_resolve", "session_apply", "session_sign", "session_complete", "trusted_device"];
|
|
48
|
+
const TRUSTED_DEVICE_DIMENSIONS = {
|
|
49
|
+
phase: TRUSTED_DEVICE_PHASES,
|
|
50
|
+
operation: ["create", "renew", "recovery", "platform_identity", "network_interfaces", "network_ports", "serial_number", "platform_uuid", "network_adapters"],
|
|
51
|
+
outcome: ["success", "partial", "failed", "ready", "not_registered", "no_auth", "reset", "blocked", "invalid", "verified", "not_required", "absent", "expired"],
|
|
52
|
+
failure_kind: ["none", "timeout", "exec_failed", "invalid_json", "empty_identity", "read_failed", "authorization", "unknown"]
|
|
53
|
+
};
|
|
54
|
+
const OBSERVATION_EVENTS = new Set(["command_delivery_observed", "command_admission", "runtime_capability_probe", "command_ack", "command_observation_closed", "diagnostic_reporter_health", ...TRUSTED_DEVICE_EVENTS]);
|
|
55
|
+
const OBSERVATION_DIMENSIONS = {
|
|
56
|
+
phase: ["resolve_binary", "build_env", "host_capabilities", "parse_capabilities", "strict_resume", "verify_binding", "prepare", "persist_state", "trusted_device", "request", "validate_response", "apply_response"],
|
|
57
|
+
reason: ["runtime_unavailable", "runtime_environment_failed", "capability_probe_failed", "runtime_binary_changed", "strict_resume_unsupported", "turn_context_unsupported", "active_run_protocol_mismatch", "trusted_device_blocked", "shutting_down_handoff", "handoff_target_not_active", "duplicate_inflight", "handler_inflight", "prepare_exception_unknown", "capacity", "stopped", "replaced", "scope_changed", "queue_removed", "local_rejected"],
|
|
58
|
+
command_type: ["agent.run", "agent.steer", "agent.stop", "task.assign", "task.stop", "artifact.relay.read", "artifact.convert_to_lark_resource", "artifact.download", "directory.list", "git.preview", "workflow.preview"],
|
|
59
|
+
actor_type: ["device", "sandbox"],
|
|
60
|
+
ack_status: ["accepted", "ignored_duplicate", "rejected"],
|
|
61
|
+
ack_outcome: ["accepted", "duplicate", "rejected", "conflicting"],
|
|
62
|
+
readback_scope: ["command", "delivery", "unmatched"],
|
|
63
|
+
timing_origin: ["observed", "restored_unknown"]
|
|
64
|
+
};
|
|
65
|
+
const OBSERVATION_METRICS = {
|
|
66
|
+
history_recall: ["duration_ms", "hit_count", "message_count", "output_tokens_upper_bound"],
|
|
67
|
+
host_identity_collection: ["duration_ms", "field_error_count"],
|
|
68
|
+
host_identity_command: ["duration_ms", "timeout_ms"],
|
|
69
|
+
host_session_attempt: ["elapsed_ms", "next_retry_ms", "consecutive_failures", "session_remaining_ms", ...TRUSTED_DEVICE_PHASES.map(phase => `${phase}_duration_ms`)],
|
|
70
|
+
host_session_expired: ["expired_for_ms", "consecutive_failures", "next_retry_ms"],
|
|
71
|
+
trusted_device_admission_blocked: ["elapsed_ms", "blocked_response_count"],
|
|
72
|
+
trusted_device_admission_recovered: ["elapsed_ms", "blocked_response_count"],
|
|
73
|
+
command_delivery_observed: ["attempt_delta", "suppressed_count"],
|
|
74
|
+
command_admission: ["attempt_delta", "suppressed_count", "deferred_age_ms", "deferred_duration_ms"],
|
|
75
|
+
runtime_capability_probe: ["probe_duration_ms"],
|
|
76
|
+
command_ack: ["attempt_delta", "suppressed_count", "ack_queue_wait_ms", "ack_settle_duration_ms", "pending_ack_age_ms", "pending_command_ack_count", "pending_ack_unknown_age_count"],
|
|
77
|
+
command_observation_closed: ["omitted_detail_count", "pending_command_ack_count", "deferred_count"],
|
|
78
|
+
diagnostic_reporter_health: ["dropped_delta", "upload_failure_delta", "pending_event_count"]
|
|
79
|
+
};
|
|
80
|
+
const EXTRA_FIELDS = ["observation_id", "runtime_client_instance_id", "command_id", "delivery_id", "probe_id", "sync_id", "transport_request_id", "attempt_id"];
|
|
81
|
+
const LIFECYCLE_EXTRA_FIELDS = [...EXTRA_FIELDS, "process_instance_id", "startup_id", "request_id", "event_id"];
|
|
82
|
+
const STRING_FIELDS = new Set([
|
|
83
|
+
...EXTRA_FIELDS, "command_type", "ack_status", "ack_outcome", "readback_scope", "timing_origin", "required_capability",
|
|
84
|
+
"request_id", "command_id", "session_id", "task_id", "dispatch_id", "event_id", "sync_id",
|
|
85
|
+
"process_instance_id", "run_id", "stage", "phase", "status", "outcome", "reason", "action",
|
|
86
|
+
"error_class", "error_code", "error_kind", "error_type", "code", "signal", "stop_reason",
|
|
87
|
+
"first_error", "retry_source", "cleanup_result",
|
|
88
|
+
"terminal_event", "event_type", "actor_type", "source", "trigger", "hook_id", "hook_event",
|
|
89
|
+
"target_version", "cli_version", "core_version", "version", "previous_state", "state",
|
|
90
|
+
"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",
|
|
91
|
+
"operation_id", "entrypoint"
|
|
92
|
+
]);
|
|
93
|
+
const VALUE_FIELDS = new Set([
|
|
94
|
+
"truncated",
|
|
95
|
+
"session_retained",
|
|
96
|
+
...new Set(Object.values(OBSERVATION_METRICS).flat()),
|
|
97
|
+
"pid", "exit_code", "duration_ms", "elapsed_ms", "wait_ms", "run_ms", "total_ms", "took_ms",
|
|
98
|
+
"attempt", "attempts", "attempt_count", "retryable", "http_status", "errno", "active_task_count",
|
|
99
|
+
"pending_event_count", "pending_command_ack_count", "next_retry_ms", "consecutive_failures",
|
|
100
|
+
"outage_duration_ms", "startup_duration_ms", "failed_attempts", "active_runs", "completed",
|
|
101
|
+
"delivered", "result_delivered", "queued_behind_existing", "expected", "timed_out",
|
|
102
|
+
"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",
|
|
103
|
+
...LIFECYCLE_METRICS
|
|
104
|
+
]);
|
|
105
|
+
|
|
106
|
+
function token(value) {
|
|
107
|
+
return typeof value === "string" && /^[a-z\d._:-]{1,128}$/iu.test(value.trim())
|
|
108
|
+
? value.trim() : undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function fieldName(key) {
|
|
112
|
+
return key.replace(/[A-Z]/gu, (letter) => `_${letter.toLowerCase()}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function optional(read) {
|
|
116
|
+
try { return read(); } catch { return undefined; }
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function metricProjection(event, fields = {}) {
|
|
120
|
+
return { count: 1, ...Object.fromEntries((OBSERVATION_METRICS[event] ?? [])
|
|
121
|
+
.filter(key => typeof fields?.[key] === "number" && Number.isFinite(fields[key]) && fields[key] >= 0)
|
|
122
|
+
.map(key => [key, fields[key]])) };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function extraProjection(fields = {}) {
|
|
126
|
+
return Object.fromEntries(EXTRA_FIELDS.filter(key => token(fields?.[key])).map(key => [key, token(fields[key])]));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function projectFields(input, fingerprintErrors = true) {
|
|
130
|
+
const result = {};
|
|
131
|
+
for (const [key, value] of Object.entries(input ?? {}).slice(0, 100)) {
|
|
132
|
+
const name = fieldName(key);
|
|
133
|
+
if (STRING_FIELDS.has(name)) {
|
|
134
|
+
const safe = token(value);
|
|
135
|
+
if (safe) result[name] = safe;
|
|
136
|
+
} else if (VALUE_FIELDS.has(name) && (typeof value === "boolean" || (typeof value === "number" && Number.isFinite(value)))) {
|
|
137
|
+
result[name] = value;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (!fingerprintErrors) return result;
|
|
141
|
+
const error = input?.error ?? input?.terminalError;
|
|
142
|
+
const fingerprint = input?.error_fingerprint ?? input?.errorFingerprint;
|
|
143
|
+
if (typeof fingerprint === "string" && /^[a-f0-9]{24}$/u.test(fingerprint)) result.error_fingerprint = fingerprint;
|
|
144
|
+
const terminal = input?.terminalError ?? error?.terminalError;
|
|
145
|
+
if (terminal && typeof terminal === "object") {
|
|
146
|
+
if (token(terminal.code)) result.error_code = token(terminal.code);
|
|
147
|
+
if (token(terminal.kind)) result.error_kind = token(terminal.kind);
|
|
148
|
+
}
|
|
149
|
+
if (error) {
|
|
150
|
+
if (typeof error === "object") {
|
|
151
|
+
if (token(error.name)) result.error_type = token(error.name);
|
|
152
|
+
if (token(error.code)) result.error_code = token(error.code);
|
|
153
|
+
if (token(error.kind)) result.error_kind = token(error.kind);
|
|
154
|
+
}
|
|
155
|
+
// Errors can contain prompts, paths and raw upstream response bodies.
|
|
156
|
+
// Retain classification + a fingerprint, never their arbitrary text.
|
|
157
|
+
const message = typeof error === "string" ? error : error.message;
|
|
158
|
+
if (typeof message === "string") result.error_fingerprint = createHash("sha256").update(message.slice(0, 4096)).digest("hex").slice(0, 24);
|
|
159
|
+
}
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Build the display summary from classified fields. Keep free-form text at
|
|
164
|
+
// its source so collecting telemetry never scans upstream or local messages.
|
|
165
|
+
function lifecycleErrorSummary(dimensions, fields) {
|
|
166
|
+
return [
|
|
167
|
+
dimensions.phase ?? dimensions.operation ?? dimensions.scope,
|
|
168
|
+
dimensions.error_source,
|
|
169
|
+
dimensions.error_code,
|
|
170
|
+
dimensions.reason !== dimensions.error_code ? dimensions.reason : undefined,
|
|
171
|
+
Number.isSafeInteger(fields.errno) && fields.errno !== 0 ? `errno=${fields.errno}` : undefined,
|
|
172
|
+
Number.isSafeInteger(fields.exit_code) ? `exit_code=${fields.exit_code}` : undefined
|
|
173
|
+
].filter(Boolean).join(" · ");
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function lifecycleErrorCode(fields) {
|
|
177
|
+
const code = token(fields.error_code ?? fields.error?.code ?? fields.error?.cause?.code)?.toLowerCase();
|
|
178
|
+
if (code && /^(?:e(?:connreset|connrefused|pipe|timedout|netunreach|hostunreach|notfound|ai_again|acces|perm|noent|exist|nospace|nospc|io)|runtime_post_[a-z_]{1,48}|http_[1-5]\d\d|(?:[a-z_]{1,35}_)?timeout|not_logged_in|unsupported_command|invalid_payload|invalid_response|relogin_required|rotation_pending|cleanup_failed|oversized|overflow|unexpected_exit|spawn_failed|ready_missing|prepare_failed|ack_rejected|ack_conflicting)$/u.test(code)) return code;
|
|
179
|
+
const status = Number(fields.http_status);
|
|
180
|
+
if (Number.isInteger(status) && status >= 100 && status <= 599) return `http_${status}`;
|
|
181
|
+
return fields.outcome === "failed" || fields.outcome === "rejected" || fields.outcome === "conflicting" ? "unknown" : undefined;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function keepLegacyMetric(event, fields, role, severity) {
|
|
185
|
+
if (/^startup\.(?:main|update_check|daemon_service_reconcile|login_gate|login_handoff_to_linco)$/u.test(event) && severity === "info") return false;
|
|
186
|
+
if (/(?:^|\.)drain_(?:started|completed)$/u.test(event) && severity === "info") return false;
|
|
187
|
+
if (role === "daemon" && event === "runtime_capability_probe" && severity === "info") return false;
|
|
188
|
+
if (role === "daemon" && ["sync_ready", "sync_failed", "sync_recovered", "shutdown_completed"].includes(event)) return false;
|
|
189
|
+
if (event === "command_ack" && ["settled", "pending"].includes(fields.stage)) return false;
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function runtimeLogIdentity(config) {
|
|
194
|
+
const oauth = optional(() => config?.auth?.oauth);
|
|
195
|
+
return {
|
|
196
|
+
deviceId: optional(() => token(readDeviceId(config))),
|
|
197
|
+
// open_id and lastLoginUser are different identities / historical owners.
|
|
198
|
+
userId: optional(() => token(oauth?.slardarUserId)),
|
|
199
|
+
tenantId: optional(() => token(oauth?.tenantId ?? oauth?.tenant_id)),
|
|
200
|
+
channel: optional(() => token(config?.channel)),
|
|
201
|
+
serverEnvironment: optional(() => typeof config?.serverUrl === "string" && /(?:^|[./-])boe(?:[./-]|$)/iu.test(config.serverUrl) ? "boe" : undefined)
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Prefer an operation's attribution over the identity of its eventual sender.
|
|
206
|
+
export function runtimeObservationTenant(value) {
|
|
207
|
+
return optional(() => {
|
|
208
|
+
const payload = value?.payload ?? value;
|
|
209
|
+
const context = payload?.telemetryContext ?? payload?.telemetry_context;
|
|
210
|
+
return token(context?.tenantId ?? context?.tenant_id ?? payload?.tenantId ?? payload?.tenant_id ?? value?.tenantId ?? value?.tenant_id);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export class RuntimeLogReporter {
|
|
215
|
+
#live = { queue: [], inflight: undefined, abort: undefined };
|
|
216
|
+
#replay = { queue: [], inflight: undefined, abort: undefined };
|
|
217
|
+
#identity = {};
|
|
218
|
+
#timer;
|
|
219
|
+
#closed = false;
|
|
220
|
+
#dropped = 0;
|
|
221
|
+
#uploadFailures = 0;
|
|
222
|
+
#reportedDrops = 0;
|
|
223
|
+
#reportedFailures = 0;
|
|
224
|
+
#lastHealthAt = Date.now();
|
|
225
|
+
#send;
|
|
226
|
+
#role;
|
|
227
|
+
#version;
|
|
228
|
+
#instanceId;
|
|
229
|
+
#diagnosticId;
|
|
230
|
+
#platform;
|
|
231
|
+
#osVersion;
|
|
232
|
+
#crashDirectory;
|
|
233
|
+
#restoring;
|
|
234
|
+
#savedDuringRestore = new Set();
|
|
235
|
+
|
|
236
|
+
constructor({ role = "cli", version = "unknown", send = sendSlardarPcBatch, instanceId = randomUUID(), diagnosticId: supportId = diagnosticId(), platform = process.platform, osVersion = os.release(), crashDirectory } = {}) {
|
|
237
|
+
this.#send = send;
|
|
238
|
+
this.#crashDirectory = crashDirectory;
|
|
239
|
+
this.#role = token(role) ?? "cli";
|
|
240
|
+
this.#version = token(version) ?? "unknown";
|
|
241
|
+
this.#instanceId = instanceId;
|
|
242
|
+
this.#diagnosticId = supportId;
|
|
243
|
+
this.#platform = platform === "win32" ? "Windows" : platform === "darwin" ? "Mac OS X" : platform;
|
|
244
|
+
this.#osVersion = osVersion;
|
|
245
|
+
this.#timer = setInterval(() => { void this.flush(); }, INTERVAL_MS);
|
|
246
|
+
this.#timer.unref?.();
|
|
247
|
+
this.#restoring = this.#restoreCrashes().finally(() => { this.#savedDuringRestore = undefined; });
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Crash files hold already-projected records and the identity at failure time.
|
|
251
|
+
// Never await network IO in uncaughtExceptionMonitor. Replay is at-least-once.
|
|
252
|
+
// deliverNow also queues the record for this process's next flush. A
|
|
253
|
+
// successful send deletes its file; otherwise the next process replays it.
|
|
254
|
+
persistCrash(component, event, fields = {}, { deliverNow = false } = {}) {
|
|
255
|
+
try {
|
|
256
|
+
if (this.#closed || (!this.#crashDirectory && !deliverNow)) return;
|
|
257
|
+
const entry = this.#logEntry("fatal", component, event, fields);
|
|
258
|
+
this.#saveCrash(entry);
|
|
259
|
+
if (deliverNow) this.#replay.queue.push(entry);
|
|
260
|
+
} catch { /* Crash diagnostics must preserve the original exit behavior. */ }
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
#saveCrash(entry) {
|
|
264
|
+
if (!this.#crashDirectory) return;
|
|
265
|
+
try {
|
|
266
|
+
fs.mkdirSync(this.#crashDirectory, { recursive: true, mode: 0o700 });
|
|
267
|
+
const names = fs.readdirSync(this.#crashDirectory).filter(name => /^js-[a-f0-9-]+\.json$/u.test(name));
|
|
268
|
+
if (names.length >= 32) return;
|
|
269
|
+
const name = `js-${randomUUID()}.json`;
|
|
270
|
+
const file = path.join(this.#crashDirectory, name);
|
|
271
|
+
fs.writeFileSync(file, JSON.stringify(entry), { flag: "wx", mode: 0o600 });
|
|
272
|
+
this.#savedDuringRestore?.add(name);
|
|
273
|
+
entry.crashFile = file;
|
|
274
|
+
} catch { /* Local storage can be full or unavailable. */ }
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
async #restoreCrashes() {
|
|
278
|
+
if (!this.#crashDirectory) return;
|
|
279
|
+
try {
|
|
280
|
+
for (const name of (await fs.promises.readdir(this.#crashDirectory)).filter(name => /^js-[a-f0-9-]+\.json$/u.test(name)).slice(0, 32)) {
|
|
281
|
+
if (this.#closed) return;
|
|
282
|
+
if (this.#savedDuringRestore?.has(name)) continue;
|
|
283
|
+
const file = path.join(this.#crashDirectory, name);
|
|
284
|
+
try {
|
|
285
|
+
const stat = await fs.promises.lstat(file);
|
|
286
|
+
if (!stat.isFile() || stat.size > 65536) continue;
|
|
287
|
+
const entry = JSON.parse(await fs.promises.readFile(file, "utf8"));
|
|
288
|
+
if (entry?.record?.category?.reporter !== "codem_js" || entry?.record?.log_type !== "log" || !entry.header) continue;
|
|
289
|
+
if (this.#closed) return;
|
|
290
|
+
if (entry.metricName === LIFECYCLE_EVENT_NAME) {
|
|
291
|
+
entry.record.category.replay = "1";
|
|
292
|
+
this.#replay.queue.push({ ...entry, attempts: 0, crashFile: file });
|
|
293
|
+
} else {
|
|
294
|
+
this.#replay.queue.push({ header: entry.header, record: entry.record, metricName: entry.metricName,
|
|
295
|
+
metrics: metricProjection(entry.record.category.event, entry.metrics), extra: extraProjection(entry.extra), attempts: 0, crashFile: file });
|
|
296
|
+
}
|
|
297
|
+
} catch { /* A partial crash write cannot prevent startup. */ }
|
|
298
|
+
}
|
|
299
|
+
} catch { /* First startup or unavailable storage. */ }
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
observeConfig(config) {
|
|
303
|
+
// A sandbox may read the launcher profile for credentials. That profile is
|
|
304
|
+
// not the tenant/device owning the sandbox's runtime diagnostics.
|
|
305
|
+
if (this.#role === "sandbox") return;
|
|
306
|
+
try { this.#identity = runtimeLogIdentity(config); } catch { this.#identity = {}; }
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
observeSandboxConfig(config) {
|
|
310
|
+
this.#role = "sandbox";
|
|
311
|
+
this.#identity = {
|
|
312
|
+
deviceId: optional(() => token(config?.deviceId)),
|
|
313
|
+
tenantId: optional(() => token(config?.tenantId ?? config?.tenantKey)),
|
|
314
|
+
serverEnvironment: runtimeLogIdentity(config).serverEnvironment
|
|
315
|
+
};
|
|
316
|
+
// ownerUserKey is not a Slardar UID. Keep user_id anonymous in this scope.
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
get pendingCount() { return this.#live.queue.length + this.#replay.queue.length; }
|
|
320
|
+
get droppedCount() { return this.#dropped; }
|
|
321
|
+
get identityKey() { return JSON.stringify([this.#instanceId, this.#role, this.#identity.deviceId, this.#identity.userId, this.#identity.tenantId]); }
|
|
322
|
+
|
|
323
|
+
record(level, component, event, fields = {}) {
|
|
324
|
+
try {
|
|
325
|
+
if (this.#closed) return false;
|
|
326
|
+
return this.#enqueue(this.#logEntry(level, component, event, fields));
|
|
327
|
+
} catch { return false; }
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
#logEntry(level, component, event, fields) {
|
|
331
|
+
let safeFields;
|
|
332
|
+
try { safeFields = projectFields(fields); } catch { safeFields = {}; }
|
|
333
|
+
if (OBSERVATION_EVENTS.has(event)) safeFields.observation_id = randomUUID();
|
|
334
|
+
const severity = ["info", "warn", "error", "fatal"].includes(level) ? level : "info";
|
|
335
|
+
// Keep arbitrary upstream error codes out of trusted-device metric dimensions.
|
|
336
|
+
const trustedDevice = TRUSTED_DEVICE_EVENTS.has(event);
|
|
337
|
+
const dimensions = trustedDevice ? {} : Object.fromEntries(["stage", "error_class", "error_code", "error_kind", "outcome"]
|
|
338
|
+
.filter(key => safeFields[key]).map(key => [key, safeFields[key]]));
|
|
339
|
+
if (OBSERVATION_EVENTS.has(event)) {
|
|
340
|
+
for (const [key, values] of Object.entries(trustedDevice ? TRUSTED_DEVICE_DIMENSIONS : OBSERVATION_DIMENSIONS)) {
|
|
341
|
+
if (safeFields[key]) dimensions[key] = values.includes(safeFields[key]) ? safeFields[key] : "unknown";
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return {
|
|
345
|
+
...this.#entry(severity, component, event, safeFields, this.#identity, dimensions, true),
|
|
346
|
+
metricName: keepLegacyMetric(event, safeFields, this.#role, severity) ? "codem_runtime_diagnostic" : null,
|
|
347
|
+
metrics: metricProjection(event, safeFields), extra: extraProjection(safeFields)
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
recordLifecycle(event, fields = {}, { persist = false } = {}) {
|
|
352
|
+
try {
|
|
353
|
+
if (this.#closed || !Object.hasOwn(LIFECYCLE_COMPONENTS, event)) return false;
|
|
354
|
+
const unstable = fields.stability === "unstable" || fields.outcome === "failed" || fields.outcome === "conflicting";
|
|
355
|
+
const hasDetail = fields.detail ?? (persist || unstable || fields.outcome === "rejected" || fields.outcome === "unknown");
|
|
356
|
+
const severity = persist ? "fatal" : unstable ? "error" : "info";
|
|
357
|
+
const dimensions = {
|
|
358
|
+
stability: unstable ? "unstable" : fields.outcome === "unknown" ? "unknown" : "stable",
|
|
359
|
+
has_detail: hasDetail ? "1" : "0", replay: "0"
|
|
360
|
+
};
|
|
361
|
+
for (const [key, values] of Object.entries(LIFECYCLE_DIMENSIONS)) {
|
|
362
|
+
if (fields[key] != null && values.includes(String(fields[key]))) dimensions[key] = String(fields[key]);
|
|
363
|
+
}
|
|
364
|
+
const errorCode = lifecycleErrorCode(fields);
|
|
365
|
+
if (errorCode) dimensions.error_code = errorCode;
|
|
366
|
+
if (fields.command_type) dimensions.command_type = OBSERVATION_DIMENSIONS.command_type.includes(fields.command_type) ? fields.command_type : "other";
|
|
367
|
+
const metrics = Object.fromEntries(LIFECYCLE_METRICS
|
|
368
|
+
.filter(key => typeof fields[key] === "number" && Number.isFinite(fields[key]) && fields[key] >= 0)
|
|
369
|
+
.map(key => [key, Math.round(fields[key])]));
|
|
370
|
+
if (event !== "runtime_state") {
|
|
371
|
+
metrics.count = event === "delivery_settled" && Number.isSafeInteger(fields.count) && fields.count > 0 ? fields.count : 1;
|
|
372
|
+
}
|
|
373
|
+
const identity = {
|
|
374
|
+
...this.#identity,
|
|
375
|
+
...(Object.hasOwn(fields, "tenantId") ? { tenantId: token(fields.tenantId) } : {})
|
|
376
|
+
};
|
|
377
|
+
const { replay: _replay, ...logDimensions } = dimensions;
|
|
378
|
+
const summary = hasDetail ? lifecycleErrorSummary(dimensions, fields) : "";
|
|
379
|
+
const { reason: _reason, error_code: _errorCode, ...projected } = projectFields(fields, false);
|
|
380
|
+
const safeFields = {
|
|
381
|
+
...projected, ...logDimensions, ...metrics,
|
|
382
|
+
process_instance_id: this.#instanceId,
|
|
383
|
+
...(event === "daemon_startup" ? { startup_id: this.#instanceId } : {}),
|
|
384
|
+
observation_id: randomUUID(),
|
|
385
|
+
...(summary ? { error_summary: summary } : {})
|
|
386
|
+
};
|
|
387
|
+
const extra = Object.fromEntries(LIFECYCLE_EXTRA_FIELDS
|
|
388
|
+
.filter(key => token(safeFields[key])).map(key => [key, safeFields[key]]));
|
|
389
|
+
if (summary) extra.error_summary = summary;
|
|
390
|
+
const entry = {
|
|
391
|
+
...this.#entry(severity, LIFECYCLE_COMPONENTS[event], event, safeFields, identity, dimensions, hasDetail),
|
|
392
|
+
metricName: LIFECYCLE_EVENT_NAME, metrics, extra
|
|
393
|
+
};
|
|
394
|
+
if (persist && hasDetail) this.#saveCrash(entry);
|
|
395
|
+
return this.#enqueue(entry);
|
|
396
|
+
} catch { return false; }
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
#entry(severity, component, event, safeFields, identity, dimensions, includeLog) {
|
|
400
|
+
const category = {
|
|
401
|
+
...workerRuntimeAttributes(),
|
|
402
|
+
client_kind: "cli", runtime_role: this.#role, reporter: "codem_js", log_schema: "1",
|
|
403
|
+
component: token(component) ?? "unknown", event: token(event) ?? "unknown", severity,
|
|
404
|
+
identity_source: identity.deviceId ? "codem" : "process",
|
|
405
|
+
diagnostic_id: this.#diagnosticId,
|
|
406
|
+
...(identity.tenantId ? { tenant_id: identity.tenantId } : {}),
|
|
407
|
+
...(identity.serverEnvironment ? { server_environment: identity.serverEnvironment } : {}),
|
|
408
|
+
...dimensions
|
|
409
|
+
};
|
|
410
|
+
const header = {
|
|
411
|
+
aid: SLARDAR_PC_AID,
|
|
412
|
+
device_id: identity.deviceId ?? this.#instanceId,
|
|
413
|
+
user_id: identity.userId ?? "0",
|
|
414
|
+
parfait_version: SLARDAR_PC_REPORTER_VERSION,
|
|
415
|
+
channel: identity.channel ?? "unknown",
|
|
416
|
+
os: this.#platform, os_version: this.#osVersion
|
|
417
|
+
};
|
|
418
|
+
const timestamp = Date.now();
|
|
419
|
+
const payload = includeLog ? {
|
|
420
|
+
schema_version: 1, timestamp, component: category.component, event: category.event, level: severity,
|
|
421
|
+
process_instance_id: this.#instanceId, diagnostic_id: this.#diagnosticId, pid: process.pid,
|
|
422
|
+
...(identity.tenantId ? { tenant_id: identity.tenantId } : {}),
|
|
423
|
+
fields: safeFields
|
|
424
|
+
} : undefined;
|
|
425
|
+
const record = {
|
|
426
|
+
app_version: this.#version, app_minor_version: "", build_id: "",
|
|
427
|
+
process_type: `codem-${this.#role}`, session_id: "", timestamp, category,
|
|
428
|
+
log_type: "log", log_level: severity === "fatal" ? "error" : severity,
|
|
429
|
+
...(payload ? { log_content: `CodeM diagnostic ${severity} ${category.component}/${category.event}\n${JSON.stringify(payload)}` } : {})
|
|
430
|
+
};
|
|
431
|
+
const criticalSettlement = event === "delivery_settled" && dimensions.critical === "true";
|
|
432
|
+
const priority = severity === "fatal" ? 3 :
|
|
433
|
+
["resumed", "settled"].includes(safeFields.stage) || (severity === "error" && !safeFields.suppressed_count) ? 2 :
|
|
434
|
+
severity === "info" && !criticalSettlement ? 0 : 1;
|
|
435
|
+
return { header, record, includeLog, priority, attempts: 0, crashFile: undefined };
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
#enqueue(entry) {
|
|
439
|
+
const queue = this.#live.queue;
|
|
440
|
+
if (queue.length >= CAPACITY) {
|
|
441
|
+
const minimum = Math.min(...queue.map(item => item.priority));
|
|
442
|
+
if (minimum > entry.priority) { this.#dropped += 1; return false; }
|
|
443
|
+
queue.splice(queue.findIndex(item => item.priority === minimum), 1);
|
|
444
|
+
this.#dropped += 1;
|
|
445
|
+
}
|
|
446
|
+
queue.push(entry);
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
async flush({ timeoutMs = REQUEST_TIMEOUT_MS } = {}) {
|
|
451
|
+
// Counters only in the failure path: never recursively log an upload error.
|
|
452
|
+
if (Date.now() - this.#lastHealthAt >= 60_000 && (this.#dropped !== this.#reportedDrops || this.#uploadFailures !== this.#reportedFailures)) {
|
|
453
|
+
this.#lastHealthAt = Date.now();
|
|
454
|
+
const dropped = this.#dropped;
|
|
455
|
+
const failures = this.#uploadFailures;
|
|
456
|
+
const queued = this.record("warn", "runtime-post", "diagnostic_reporter_health", {
|
|
457
|
+
dropped_delta: dropped - this.#reportedDrops,
|
|
458
|
+
upload_failure_delta: failures - this.#reportedFailures,
|
|
459
|
+
pending_event_count: this.pendingCount
|
|
460
|
+
});
|
|
461
|
+
// The health record can itself evict an entry or be refused by a full
|
|
462
|
+
// higher-priority queue. Neither loss has been included in this snapshot.
|
|
463
|
+
if (queued) {
|
|
464
|
+
this.#reportedDrops = dropped;
|
|
465
|
+
this.#reportedFailures = failures;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
const deadline = Date.now() + timeoutMs;
|
|
469
|
+
const live = this.#flushLane(this.#live, timeoutMs).then(() => {
|
|
470
|
+
// Cover records added after drain's last queue check but before its
|
|
471
|
+
// promise clears. Deferred retries still wait for the regular timer.
|
|
472
|
+
const remaining = deadline - Date.now();
|
|
473
|
+
if (remaining > 0 && this.#live.queue.some(entry => entry.attempts === 0)) {
|
|
474
|
+
return this.#flushLane(this.#live, remaining);
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
// Run both lanes concurrently: old replay cannot delay live sends. Waiting
|
|
478
|
+
// for both within one budget also gives short-lived invocations a chance
|
|
479
|
+
// to finish replay; a timeout leaves its original crash file for next time.
|
|
480
|
+
const replay = this.#restoring.then(() => this.#flushLane(this.#replay, REQUEST_TIMEOUT_MS));
|
|
481
|
+
let timer;
|
|
482
|
+
try {
|
|
483
|
+
await Promise.race([
|
|
484
|
+
Promise.all([live, replay]),
|
|
485
|
+
new Promise(resolve => { timer = setTimeout(resolve, timeoutMs); timer.unref?.(); })
|
|
486
|
+
]);
|
|
487
|
+
} finally { clearTimeout(timer); }
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
#flushLane(lane, timeoutMs) {
|
|
491
|
+
if (lane.inflight) return lane.inflight;
|
|
492
|
+
if (this.#closed || lane.queue.length === 0) return Promise.resolve();
|
|
493
|
+
lane.inflight = this.#drain(lane, timeoutMs).catch(() => {}).finally(() => { lane.inflight = undefined; });
|
|
494
|
+
return lane.inflight;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
async #drain(lane, timeoutMs) {
|
|
498
|
+
const retry = [];
|
|
499
|
+
const controller = new AbortController();
|
|
500
|
+
lane.abort = controller;
|
|
501
|
+
let expire;
|
|
502
|
+
const deadline = new Promise((_, reject) => {
|
|
503
|
+
expire = setTimeout(() => { controller.abort(); reject(new Error("Slardar upload timed out")); }, timeoutMs);
|
|
504
|
+
expire.unref?.();
|
|
505
|
+
});
|
|
506
|
+
try {
|
|
507
|
+
while (lane.queue.length && !this.#closed) {
|
|
508
|
+
const first = lane.queue[0];
|
|
509
|
+
const key = JSON.stringify(first.header);
|
|
510
|
+
const batch = [];
|
|
511
|
+
const data = [];
|
|
512
|
+
let bytes = 0;
|
|
513
|
+
while (batch.length < BATCH_SIZE && lane.queue.length && JSON.stringify(lane.queue[0].header) === key && Boolean(lane.queue[0].crashFile) === Boolean(first.crashFile)) {
|
|
514
|
+
const { record, metrics, extra, metricName = "codem_runtime_diagnostic", includeLog = true } = lane.queue[0];
|
|
515
|
+
const records = includeLog ? [record] : [];
|
|
516
|
+
if (metricName) records.push({
|
|
517
|
+
app_version: record.app_version, app_minor_version: "", build_id: "",
|
|
518
|
+
process_type: record.process_type, session_id: "", timestamp: record.timestamp,
|
|
519
|
+
log_type: "flexible", event_name: metricName, category: record.category,
|
|
520
|
+
metrics: metrics ?? { count: 1 }, ...(extra ? { extra } : {})
|
|
521
|
+
});
|
|
522
|
+
const entryBytes = Buffer.byteLength(JSON.stringify(records));
|
|
523
|
+
if (batch.length && bytes + entryBytes > MAX_BATCH_BYTES) break;
|
|
524
|
+
bytes += entryBytes;
|
|
525
|
+
batch.push(lane.queue.shift());
|
|
526
|
+
data.push(...records);
|
|
527
|
+
}
|
|
528
|
+
try {
|
|
529
|
+
await Promise.race([Promise.resolve().then(() => this.#send({ header: first.header, data }, { signal: controller.signal })), deadline]);
|
|
530
|
+
for (const entry of batch) {
|
|
531
|
+
if (entry.crashFile) await fs.promises.unlink(entry.crashFile).catch(() => {});
|
|
532
|
+
}
|
|
533
|
+
} catch {
|
|
534
|
+
this.#uploadFailures += 1;
|
|
535
|
+
// One later retry, on the regular interval. Bound both memory and work;
|
|
536
|
+
// an unavailable collector must not create a retry loop or block exit.
|
|
537
|
+
for (const entry of batch) {
|
|
538
|
+
if (!this.#closed && entry.attempts === 0 && retry.length + lane.queue.length < CAPACITY) {
|
|
539
|
+
entry.attempts += 1;
|
|
540
|
+
retry.push(entry);
|
|
541
|
+
} else this.#dropped += 1;
|
|
542
|
+
}
|
|
543
|
+
if (controller.signal.aborted) break;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
} finally {
|
|
547
|
+
if (!this.#closed) lane.queue.push(...retry.slice(0, Math.max(0, CAPACITY - lane.queue.length)));
|
|
548
|
+
clearTimeout(expire);
|
|
549
|
+
lane.abort = undefined;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
close() {
|
|
554
|
+
this.#closed = true;
|
|
555
|
+
clearInterval(this.#timer);
|
|
556
|
+
for (const lane of [this.#live, this.#replay]) {
|
|
557
|
+
lane.abort?.abort();
|
|
558
|
+
lane.queue.length = 0;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
let active;
|
|
564
|
+
|
|
565
|
+
export function runtimeLogsEnabled() { return Boolean(active); }
|
|
566
|
+
export function runtimeLogIdentityKey() { return active?.identityKey; }
|
|
567
|
+
|
|
568
|
+
export function startRuntimeLogs({ role, version, env = process.env, send } = {}) {
|
|
569
|
+
try {
|
|
570
|
+
if (active || /^(1|true|yes)$/iu.test(env.CODEM_TELEMETRY_DISABLED ?? "") || env.NODE_TEST_CONTEXT) return;
|
|
571
|
+
const root = env.CODEM_HOME || env.LINCO_HOME || path.join(os.homedir(), ".codem");
|
|
572
|
+
active = new RuntimeLogReporter({ role, version, send, crashDirectory: path.join(root, "runtime-crashes") });
|
|
573
|
+
} catch { /* Monitoring initialization never prevents a command from running. */ }
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
export function observeRuntimeLogConfig(config) {
|
|
577
|
+
try { active?.observeConfig(config); } catch { /* best effort */ }
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
export function observeRuntimeLogSandboxConfig(config) {
|
|
581
|
+
try { active?.observeSandboxConfig(config); } catch { /* best effort */ }
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
export function recordRuntimeLog(level, component, event, fields = {}) {
|
|
585
|
+
try { return active?.record(level, component, event, fields) ?? false; } catch { return false; }
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// An explicit result or state observation. This never waits for the collector;
|
|
589
|
+
// persist is reserved for rare terminal failures that can outlive this process.
|
|
590
|
+
export function recordBridgeLifecycle(event, fields, options = {}) {
|
|
591
|
+
try { return active?.recordLifecycle(event, fields, options) ?? false; } catch { return false; }
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
export function flushRuntimeLogsInBackground() {
|
|
595
|
+
if (active) setImmediate(() => { void active?.flush().catch(() => {}); }).unref?.();
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
export function persistRuntimeCrash(component, event, fields) {
|
|
599
|
+
try { active?.persistCrash(component, event, fields); } catch { /* best effort */ }
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// A failure that ends a short-lived process: persist first, then try to deliver
|
|
603
|
+
// within one upload budget, so an immediate exit cannot lose the count.
|
|
604
|
+
export function reportRuntimeFailure(component, event, fields = {}) {
|
|
605
|
+
try { active?.persistCrash(component, event, fields, { deliverNow: true }); } catch { /* best effort */ }
|
|
606
|
+
flushRuntimeLogsInBackground();
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
export async function flushRuntimeLogs(budgetMs = 200) {
|
|
610
|
+
if (!active) return;
|
|
611
|
+
let timeout;
|
|
612
|
+
try {
|
|
613
|
+
await Promise.race([
|
|
614
|
+
active.flush({ timeoutMs: budgetMs }),
|
|
615
|
+
new Promise((resolve) => { timeout = setTimeout(resolve, budgetMs); })
|
|
616
|
+
]);
|
|
617
|
+
} catch { /* best effort, including a broken uploader */ } finally { clearTimeout(timeout); }
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// Existing debug sites contain both useful operational events and user data.
|
|
621
|
+
// Observe the client's final payload; this does not assert server delivery.
|
|
622
|
+
export function recordPreparedArtifacts(component, artifacts, context = {}) {
|
|
623
|
+
try {
|
|
624
|
+
const limit = 32;
|
|
625
|
+
recordRuntimeLog("info", component, "artifact.delivery_prepared", { ...context, count: artifacts.length, omitted_detail_count: Math.max(0, artifacts.length - limit) });
|
|
626
|
+
for (const artifact of artifacts.slice(0, limit)) {
|
|
627
|
+
const file = artifact?.file;
|
|
628
|
+
const uri = artifact?.url?.uri ?? file?._downloadUrl ?? artifact?.image?.uri;
|
|
629
|
+
let urlFields = {};
|
|
630
|
+
try {
|
|
631
|
+
const parsed = new URL(uri);
|
|
632
|
+
urlFields = { host: parsed.hostname, scheme: parsed.protocol.replace(/:$/u, "") };
|
|
633
|
+
} catch { /* Local references have no remote URL. */ }
|
|
634
|
+
const route = file?._localArtifactRef ? "local_relay"
|
|
635
|
+
: file?._artifactId || artifact?._imgKey ? "uploaded"
|
|
636
|
+
: file?._data || artifact?.image?._data ? "inline"
|
|
637
|
+
: artifact?.kind === "url" || urlFields.host ? "url" : "reference";
|
|
638
|
+
recordRuntimeLog("info", component, "artifact.delivery_item", {
|
|
639
|
+
...context, artifact_kind: artifact?.kind, delivery_mode: route,
|
|
640
|
+
artifact_id: file?._artifactId ?? file?._localArtifactRef ?? artifact?._imgKey,
|
|
641
|
+
...urlFields
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
} catch { /* Diagnostics cannot interrupt delivery. */ }
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
export function recordInteractiveProcessExit({ exitCode, signal }) {
|
|
648
|
+
const abnormalSignal = signal && signal !== "SIGINT" && signal !== "SIGTERM";
|
|
649
|
+
const failed = abnormalSignal || (exitCode && exitCode !== 130);
|
|
650
|
+
recordRuntimeLog(failed ? "error" : "info", "cli", "process.exited", { exitCode, signal });
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
// Select events explicitly, then project fields again at the remote boundary.
|
|
654
|
+
export function recordSelectedRuntimeLog(component, event, fields = {}) {
|
|
655
|
+
try {
|
|
656
|
+
const selectedEvent = event.replace(/^linco\./u, "");
|
|
657
|
+
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)|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;
|
|
658
|
+
const expected = optional(() => fields?.errorKind === "user_stop" || fields?.terminalError?.kind === "user_stop" || fields?.exitCode === 130 || fields?.signal === "SIGINT");
|
|
659
|
+
const level = expected ? "info" : (fields?.status === "failed" || /(?:failed|error|exhausted|timeout)$/u.test(event)) ? "error" : /(?:suspect|dropped|missing|oversize)$/u.test(event) ? "warn" : "info";
|
|
660
|
+
recordRuntimeLog(level, component, event, fields);
|
|
661
|
+
} catch { /* best effort */ }
|
|
662
|
+
}
|