@octopi-agent/engine 0.90.11 → 0.97.15

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.
Files changed (169) hide show
  1. package/dist/config-admin/agent-presets.d.ts +70 -0
  2. package/dist/config-admin/agent-presets.js +243 -0
  3. package/dist/config-admin/discover.d.ts +30 -0
  4. package/dist/config-admin/discover.js +48 -0
  5. package/dist/config-admin/env.d.ts +22 -0
  6. package/dist/config-admin/env.js +41 -0
  7. package/dist/config-admin/index.d.ts +20 -0
  8. package/dist/config-admin/index.js +15 -0
  9. package/dist/config-admin/model-presets.d.ts +75 -0
  10. package/dist/config-admin/model-presets.js +249 -0
  11. package/dist/config-admin/name-guard.d.ts +14 -0
  12. package/dist/config-admin/name-guard.js +24 -0
  13. package/dist/config-admin/patch.d.ts +56 -0
  14. package/dist/config-admin/patch.js +201 -0
  15. package/dist/config-admin/port.d.ts +68 -0
  16. package/dist/config-admin/port.js +21 -0
  17. package/dist/config-admin/redact.d.ts +39 -0
  18. package/dist/config-admin/redact.js +42 -0
  19. package/dist/config-schema/agent.d.ts +43 -1
  20. package/dist/config-schema/context.d.ts +6 -1
  21. package/dist/config-schema/context.js +8 -0
  22. package/dist/config-schema/engine.d.ts +106 -4
  23. package/dist/config-schema/governance.d.ts +43 -1
  24. package/dist/config-schema/governance.js +157 -0
  25. package/dist/config-schema/models.d.ts +5 -2
  26. package/dist/config-schema/models.js +4 -1
  27. package/dist/config-schema/observability.d.ts +9 -0
  28. package/dist/config-schema/observability.js +29 -0
  29. package/dist/config-schema/run.d.ts +3 -0
  30. package/dist/config-schema/run.js +14 -0
  31. package/dist/config.d.ts +29 -4
  32. package/dist/config.js +15 -4
  33. package/dist/harness/activation/dispatcher.d.ts +8 -2
  34. package/dist/harness/activation/dispatcher.js +33 -5
  35. package/dist/harness/activation/inbox.d.ts +87 -0
  36. package/dist/harness/activation/inbox.js +169 -0
  37. package/dist/harness/activation/runtime.d.ts +9 -8
  38. package/dist/harness/activation/runtime.js +100 -8
  39. package/dist/harness/activation/types.d.ts +19 -0
  40. package/dist/harness/activation/types.js +2 -0
  41. package/dist/harness/agent/builder.d.ts +15 -1
  42. package/dist/harness/agent/builder.js +31 -10
  43. package/dist/harness/agent/config-bridge.d.ts +5 -0
  44. package/dist/harness/agent/config-bridge.js +3 -0
  45. package/dist/harness/agent/config-integrity.d.ts +72 -0
  46. package/dist/harness/agent/config-integrity.js +146 -0
  47. package/dist/harness/agent/wire-agent-builder.js +2 -1
  48. package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +3 -1
  49. package/dist/harness/collaboration/delegation/child-run.js +21 -5
  50. package/dist/harness/collaboration/delegation/notifier.js +4 -3
  51. package/dist/harness/collaboration/delegation/service.js +2 -3
  52. package/dist/harness/collaboration/delegation/wiring.js +6 -5
  53. package/dist/harness/collaboration/orchestration/reflector/llm-reflector.d.ts +1 -1
  54. package/dist/harness/collaboration/orchestration/reflector/llm-reflector.js +1 -1
  55. package/dist/harness/context/capabilities/compact/engine.d.ts +30 -0
  56. package/dist/harness/context/capabilities/compact/engine.js +198 -46
  57. package/dist/harness/context/capabilities/compact/handover.d.ts +78 -0
  58. package/dist/harness/context/capabilities/compact/handover.js +107 -0
  59. package/dist/harness/context/capabilities/compact/index.d.ts +3 -1
  60. package/dist/harness/context/capabilities/compact/index.js +2 -1
  61. package/dist/harness/context/capabilities/compact/types.d.ts +30 -1
  62. package/dist/harness/context/capabilities/summary/executor.js +2 -1
  63. package/dist/harness/context/capabilities/summary/policies.js +8 -5
  64. package/dist/harness/context/constitution/default-agents.md +11 -10
  65. package/dist/harness/context/default-context-engine.d.ts +34 -4
  66. package/dist/harness/context/default-context-engine.js +194 -49
  67. package/dist/harness/context/hybrid-compressor.js +6 -0
  68. package/dist/harness/context/llm-summarizer.d.ts +2 -8
  69. package/dist/harness/context/llm-summarizer.js +69 -91
  70. package/dist/harness/context/message-selector.js +4 -3
  71. package/dist/harness/context/summarize.d.ts +2 -0
  72. package/dist/harness/context/summarize.js +7 -2
  73. package/dist/harness/context/truncate-compressor.js +7 -0
  74. package/dist/harness/context/turn-envelope.d.ts +3 -2
  75. package/dist/harness/context/turn-envelope.js +3 -2
  76. package/dist/harness/context/types.d.ts +33 -1
  77. package/dist/harness/extension/execution-environment/dangerous-commands.d.ts +28 -0
  78. package/dist/harness/extension/execution-environment/dangerous-commands.js +129 -0
  79. package/dist/harness/extension/execution-environment/effect-policy.d.ts +127 -8
  80. package/dist/harness/extension/execution-environment/effect-policy.js +244 -19
  81. package/dist/harness/extension/execution-environment/index.d.ts +4 -2
  82. package/dist/harness/extension/execution-environment/index.js +2 -1
  83. package/dist/harness/extension/execution-environment/kill-switch.d.ts +34 -0
  84. package/dist/harness/extension/execution-environment/kill-switch.js +46 -0
  85. package/dist/harness/extension/execution-environment/ops-audit.d.ts +200 -0
  86. package/dist/harness/extension/execution-environment/ops-audit.js +338 -0
  87. package/dist/harness/extension/execution-environment/privileged-exec.d.ts +158 -0
  88. package/dist/harness/extension/execution-environment/privileged-exec.js +418 -0
  89. package/dist/harness/extension/execution-environment/process-info.d.ts +180 -0
  90. package/dist/harness/extension/execution-environment/process-info.js +466 -0
  91. package/dist/harness/extension/execution-environment/process-isolation.d.ts +7 -0
  92. package/dist/harness/extension/execution-environment/process-isolation.js +9 -0
  93. package/dist/harness/extension/execution-environment/sandbox.d.ts +109 -0
  94. package/dist/harness/extension/execution-environment/sandbox.js +228 -21
  95. package/dist/harness/extension/execution-environment/tool-capabilities.d.ts +1 -1
  96. package/dist/harness/extension/execution-environment/tool-capabilities.js +6 -0
  97. package/dist/harness/extension/execution-environment/types.d.ts +19 -0
  98. package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +5 -0
  99. package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +33 -0
  100. package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +4 -5
  101. package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +5 -15
  102. package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +3 -0
  103. package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +53 -2
  104. package/dist/harness/extension/plugin-ecosystem/tools/index.d.ts +2 -0
  105. package/dist/harness/extension/plugin-ecosystem/tools/index.js +2 -0
  106. package/dist/harness/extension/plugin-ecosystem/tools/privileged-tool.d.ts +43 -0
  107. package/dist/harness/extension/plugin-ecosystem/tools/privileged-tool.js +350 -0
  108. package/dist/harness/extension/plugin-ecosystem/tools/process-tools.d.ts +30 -0
  109. package/dist/harness/extension/plugin-ecosystem/tools/process-tools.js +137 -0
  110. package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +54 -4
  111. package/dist/harness/governance/human-in-the-loop/decision-cache.js +42 -16
  112. package/dist/harness/governance/security/temp-path.d.ts +9 -0
  113. package/dist/harness/governance/security/temp-path.js +13 -2
  114. package/dist/harness/governance/session-acl/seed-roles.js +14 -0
  115. package/dist/harness/index.d.ts +2 -0
  116. package/dist/harness/index.js +2 -0
  117. package/dist/harness/knowledge/fts.js +1 -2
  118. package/dist/harness/knowledge/index-store.js +59 -9
  119. package/dist/harness/memory/sqlite/keyword-search.d.ts +1 -0
  120. package/dist/harness/memory/sqlite/keyword-search.js +4 -3
  121. package/dist/harness/observability/observer/hub.js +8 -0
  122. package/dist/harness/observability/observer/run-snapshot.js +1 -0
  123. package/dist/harness/observability/observer/types.d.ts +4 -0
  124. package/dist/harness/run/agent/agent.d.ts +7 -0
  125. package/dist/harness/run/agent/agent.js +23 -1
  126. package/dist/harness/run/reliability/fallback-provider.d.ts +117 -5
  127. package/dist/harness/run/reliability/fallback-provider.js +262 -22
  128. package/dist/harness/run/reliability/harness-events.d.ts +24 -1
  129. package/dist/harness/run/reliability/model-error-policy.d.ts +32 -0
  130. package/dist/harness/run/reliability/model-error-policy.js +42 -0
  131. package/dist/harness/run/reliability/provider-wrapper.js +29 -2
  132. package/dist/harness/run/reliability/refusal-guard.d.ts +20 -0
  133. package/dist/harness/run/reliability/refusal-guard.js +102 -0
  134. package/dist/harness/run/reliability/run-agent.js +231 -33
  135. package/dist/harness/run/run-guard/default-run-guard.js +1 -1
  136. package/dist/harness/run/run-scope.d.ts +31 -0
  137. package/dist/harness/run/runner.d.ts +116 -2
  138. package/dist/harness/run/runner.js +547 -41
  139. package/dist/harness/session/attachments/llm-intent.js +2 -1
  140. package/dist/harness/session/tasks/render.d.ts +4 -1
  141. package/dist/harness/session/tasks/render.js +10 -7
  142. package/dist/harness/shared/events/agent-event-map.d.ts +66 -0
  143. package/dist/harness/shared/events/agent-event-map.js +5 -0
  144. package/dist/index.d.ts +3 -3
  145. package/dist/index.js +2 -2
  146. package/dist/integration/agent-runtime/channel-message-source.js +19 -1
  147. package/dist/integration/index.d.ts +2 -0
  148. package/dist/integration/index.js +1 -0
  149. package/dist/integration/observability/loop-watchdog.d.ts +56 -0
  150. package/dist/integration/observability/loop-watchdog.js +177 -0
  151. package/dist/integration/observability/metrics.d.ts +3 -0
  152. package/dist/integration/observability/metrics.js +18 -7
  153. package/dist/integration/providers/anthropic.d.ts +23 -0
  154. package/dist/integration/providers/anthropic.js +97 -12
  155. package/dist/integration/providers/fetch-timeout.d.ts +42 -0
  156. package/dist/integration/providers/fetch-timeout.js +51 -0
  157. package/dist/integration/providers/openai.d.ts +10 -0
  158. package/dist/integration/providers/openai.js +58 -11
  159. package/dist/integration/providers/provider-diagnostics.d.ts +80 -0
  160. package/dist/integration/providers/provider-diagnostics.js +89 -0
  161. package/dist/integration/providers/timeout-coherence.d.ts +52 -0
  162. package/dist/integration/providers/timeout-coherence.js +68 -0
  163. package/dist/integration/providers/wire-dump.d.ts +62 -0
  164. package/dist/integration/providers/wire-dump.js +111 -2
  165. package/dist/integration/storage/jsonl.js +4 -1
  166. package/dist/subsystems/cognition-steward/conceptualize/handler.js +1 -1
  167. package/dist/subsystems/memory-steward/backfill/handler.js +1 -1
  168. package/dist/subsystems/wisdom-steward/formation/handler.js +1 -1
  169. package/package.json +3 -2
@@ -44,7 +44,8 @@ export function createLlmIntentResolver(provider, opts) {
44
44
  { role: 'system', content: INTENT_SYSTEM },
45
45
  { role: 'user', content: lines.join('\n') },
46
46
  ],
47
- temperature: opts?.temperature ?? 0,
47
+ // 未显式配置即不发送:由模型配置(ModelInfo.temperature)或服务端默认决定
48
+ temperature: opts?.temperature,
48
49
  maxTokens: opts?.maxTokens ?? 300,
49
50
  });
50
51
  const raw = (response.content ?? '').trim();
@@ -7,9 +7,12 @@ import type { SessionTask } from './types.js';
7
7
  * 仅包含未闭合 goal;step 只出现 rollup,不罗列全部描述。
8
8
  *
9
9
  * @param tasks - 会话全部任务(含 step)
10
+ * @param opts - includeGuidance=false 时省略末尾「说明」段(交接式摘要等非对话消费者用)
10
11
  * @returns 注入字符串;无活跃 goal 时返回空串
11
12
  */
12
- export declare function renderSessionTasksInjection(tasks: SessionTask[]): string;
13
+ export declare function renderSessionTasksInjection(tasks: SessionTask[], opts?: {
14
+ includeGuidance?: boolean;
15
+ }): string;
13
16
  /**
14
17
  * 从会话任务提取检索主题线索(Memory/Cognition 层 query 用)。
15
18
  *
@@ -23,9 +23,10 @@ function stepProgressLine(goalId, all) {
23
23
  * 仅包含未闭合 goal;step 只出现 rollup,不罗列全部描述。
24
24
  *
25
25
  * @param tasks - 会话全部任务(含 step)
26
+ * @param opts - includeGuidance=false 时省略末尾「说明」段(交接式摘要等非对话消费者用)
26
27
  * @returns 注入字符串;无活跃 goal 时返回空串
27
28
  */
28
- export function renderSessionTasksInjection(tasks) {
29
+ export function renderSessionTasksInjection(tasks, opts) {
29
30
  const goals = tasks
30
31
  .filter((t) => !t.parentId && isActive(t.status))
31
32
  .sort((a, b) => a.createdAt - b.createdAt);
@@ -46,12 +47,14 @@ export function renderSessionTasksInjection(tasks) {
46
47
  lines.push(` 进展:${goal.progressNote}`);
47
48
  }
48
49
  }
49
- lines.push('');
50
- lines.push('说明:');
51
- lines.push('- 用户要求继续或话题回归时,可恢复对应任务或先说明进展。');
52
- lines.push('- 与当前消息无关时,优先处理当前消息,不要强行续做。');
53
- lines.push('- 完成或放弃时请调用 task_complete / task_drop,保持列表与对话一致。');
54
- lines.push('- 复杂任务可先 task_create 建目标,再用 task_plan 或 task_create(parent_id) 登记步骤。');
50
+ if (opts?.includeGuidance !== false) {
51
+ lines.push('');
52
+ lines.push('说明:');
53
+ lines.push('- 用户要求继续或话题回归时,可恢复对应任务或先说明进展。');
54
+ lines.push('- 与当前消息无关时,优先处理当前消息,不要强行续做。');
55
+ lines.push('- 完成或放弃时请调用 task_complete / task_drop,保持列表与对话一致。');
56
+ lines.push('- 复杂任务可先 task_create 建目标,再用 task_plan 或 task_create(parent_id) 登记步骤。');
57
+ }
55
58
  lines.push('</session_tasks>');
56
59
  return lines.join('\n');
57
60
  }
@@ -19,17 +19,32 @@ export interface AgentEventMap {
19
19
  error: string;
20
20
  reason?: string;
21
21
  };
22
+ /**
23
+ * 模型调用即将重试(重试窗口对用户可见)
24
+ *
25
+ * 此前重试不产生任何事件:一次 52 分钟停滞期间前端零反馈。
26
+ * `attempt` 从 1 起;`delayMs` 是**即将**等待的退避时长(通知先于等待发出)。
27
+ */
28
+ 'engine.model_retry': {
29
+ attempt: number;
30
+ maxAttempts: number;
31
+ reason: string;
32
+ delayMs: number;
33
+ error: string;
34
+ };
22
35
  'iteration.start': Record<string, never>;
23
36
  'llm.usage': {
24
37
  usage: import('@octopi-agent/core/types/turn.js').TokenUsage;
25
38
  };
26
39
  'turn.end': {
40
+ /** 本次调用的正文;error=true 时 = 中断前的部分流出(不是回答,不得当回复外发) */
27
41
  content?: string;
28
42
  userText?: string;
29
43
  hasToolCalls: boolean;
30
44
  phase: 'pre_tools' | 'final';
31
45
  truncated?: boolean;
32
46
  stopped?: boolean;
47
+ /** 本次 LLM 调用失败(只出现在重试中途;彻底失败走 agent_end reason='error') */
33
48
  error?: boolean;
34
49
  usage?: import('@octopi-agent/core/types/turn.js').TokenUsage;
35
50
  /** F3 LLM 计时摘要(loop turn_end 透传;Run 页签耗时区消费) */
@@ -52,6 +67,16 @@ export interface AgentEventMap {
52
67
  /** 行动简述 */
53
68
  purpose?: string;
54
69
  };
70
+ /**
71
+ * 工具执行中的部分输出(展示通道;不进对话历史、不参与 afterToolCall 定形)。
72
+ * 载荷已经过 SecurityGuard 出口扫描(与 tool.exec.end 同一判定),违规部分被扣发。
73
+ */
74
+ 'tool.exec.update': {
75
+ toolCallId: string;
76
+ toolName: string;
77
+ /** 部分输出内容(对齐 LoopToolResult.content 语义;发射端已截断) */
78
+ content?: unknown;
79
+ };
55
80
  /** ToolEffectPolicy §5.6 效应账本摘要(turn 级;Observer tool.effect) */
56
81
  'tool.effect.ledger': {
57
82
  entries: number;
@@ -170,6 +195,12 @@ export interface AgentEventMap {
170
195
  error: string;
171
196
  durationMs?: number;
172
197
  };
198
+ /** 摘要请求 cache-miss 旁路/穷尽可观测(F22):no_prefix=无同形前缀,window_guard=前缀放不下改文本化旁路,window_exhausted=最终失败 */
199
+ 'context.compact.summarize_fallback': {
200
+ reason?: 'proactive' | 'overflow';
201
+ fallback?: string;
202
+ cached?: boolean;
203
+ };
173
204
  /**
174
205
  * system prompt 七层装配完成(AssembleManifest 可观测快照)
175
206
  * UI 用此事件渲染 Context Runtime;不进入模型输入。
@@ -217,6 +248,36 @@ export interface AgentEventMap {
217
248
  };
218
249
  /** RunMetricsCollector 快照(reliability → Observer) */
219
250
  'run.guard.metrics': import('../../run/reliability/harness-events.js').RunGuardMetricsEvent['data'];
251
+ /** ops P0:jail 意图 × 实测后端(授权 vs 故障的事后判据,run 开始即记录) */
252
+ 'ops.jail.state': import('../../extension/execution-environment/effect-policy.js').OpsJailState;
253
+ /** ops P2:run 级降级申报(securityDegraded 快照) */
254
+ 'ops.policy.degraded': {
255
+ degradation: string[];
256
+ requestedVsEffective: {
257
+ requestedMode: string;
258
+ mode: string;
259
+ };
260
+ origin: {
261
+ sessionId: string;
262
+ agentId: string;
263
+ runId?: string | null;
264
+ };
265
+ };
266
+ /** ops P2:安全配置漂移 → 拒新 run(§8.4) */
267
+ 'ops.config.security_changed': {
268
+ changed: string[];
269
+ action: string;
270
+ /** 旧→新摘要(§7) */
271
+ previousFingerprint: string | null;
272
+ currentFingerprint: string | null;
273
+ /** 谁改的无法从文件判定(agent 写与宿主写同样是磁盘字节)→ 如实 unattributed */
274
+ source: 'unattributed';
275
+ hostAttested: boolean;
276
+ origin: {
277
+ sessionId: string;
278
+ agentId: string;
279
+ };
280
+ };
220
281
  'task.created': {
221
282
  taskId: string;
222
283
  taskType: string;
@@ -275,12 +336,14 @@ export declare const AgentEvents: {
275
336
  readonly ENGINE_START: "engine.start";
276
337
  readonly ENGINE_END: "engine.end";
277
338
  readonly ENGINE_ERROR: "engine.error";
339
+ readonly ENGINE_MODEL_RETRY: "engine.model_retry";
278
340
  readonly ITERATION_START: "iteration.start";
279
341
  readonly TURN_END: "turn.end";
280
342
  /** Runner 收口计时(F3 转正) */
281
343
  readonly RUN_TIMING: "run.timing";
282
344
  readonly TOOL_EXEC_START: "tool.exec.start";
283
345
  readonly TOOL_EXEC_END: "tool.exec.end";
346
+ readonly TOOL_EXEC_UPDATE: "tool.exec.update";
284
347
  readonly INJECTION_DETECTED: "injection.detected";
285
348
  readonly POLICY_VIOLATED: "policy.violated";
286
349
  readonly SENSITIVE_DATA_DETECTED: "sensitive_data.detected";
@@ -301,6 +364,9 @@ export declare const AgentEvents: {
301
364
  readonly RUN_SCOPE_MESSAGES: "run.scope.messages";
302
365
  readonly RUN_SCOPE_LLM: "run.scope.llm";
303
366
  readonly RUN_GUARD_METRICS: "run.guard.metrics";
367
+ readonly OPS_JAIL_STATE: "ops.jail.state";
368
+ readonly OPS_POLICY_DEGRADED: "ops.policy.degraded";
369
+ readonly OPS_CONFIG_SECURITY_CHANGED: "ops.config.security_changed";
304
370
  readonly TASK_CREATED: "task.created";
305
371
  readonly TASK_STARTED: "task.started";
306
372
  readonly TASK_COMPLETED: "task.completed";
@@ -18,12 +18,14 @@ export const AgentEvents = {
18
18
  ENGINE_START: 'engine.start',
19
19
  ENGINE_END: 'engine.end',
20
20
  ENGINE_ERROR: 'engine.error',
21
+ ENGINE_MODEL_RETRY: 'engine.model_retry',
21
22
  ITERATION_START: 'iteration.start',
22
23
  TURN_END: 'turn.end',
23
24
  /** Runner 收口计时(F3 转正) */
24
25
  RUN_TIMING: 'run.timing',
25
26
  TOOL_EXEC_START: 'tool.exec.start',
26
27
  TOOL_EXEC_END: 'tool.exec.end',
28
+ TOOL_EXEC_UPDATE: 'tool.exec.update',
27
29
  INJECTION_DETECTED: 'injection.detected',
28
30
  POLICY_VIOLATED: 'policy.violated',
29
31
  SENSITIVE_DATA_DETECTED: 'sensitive_data.detected',
@@ -44,6 +46,9 @@ export const AgentEvents = {
44
46
  RUN_SCOPE_MESSAGES: 'run.scope.messages',
45
47
  RUN_SCOPE_LLM: 'run.scope.llm',
46
48
  RUN_GUARD_METRICS: 'run.guard.metrics',
49
+ OPS_JAIL_STATE: 'ops.jail.state',
50
+ OPS_POLICY_DEGRADED: 'ops.policy.degraded',
51
+ OPS_CONFIG_SECURITY_CHANGED: 'ops.config.security_changed',
47
52
  TASK_CREATED: 'task.created',
48
53
  TASK_STARTED: 'task.started',
49
54
  TASK_COMPLETED: 'task.completed',
package/dist/index.d.ts CHANGED
@@ -26,7 +26,7 @@ export type { ContextEngine, ContextEngineInfo, AssembleParams, AssembleResult,
26
26
  export { setRunTelemetryFactory, getRunTelemetryFactory } from './harness/observability/run-telemetry.js';
27
27
  export type { RunTelemetry, RunTelemetryFactory } from './harness/observability/run-telemetry.js';
28
28
  export { createRunTelemetry } from './integration/observability/run-telemetry.js';
29
- export { AgentBuilder, createAgent, isSubsystemAllowed, discoverSubsystemSpecs } from './harness/agent/builder.js';
29
+ export { AgentBuilder, createAgent, DefaultErrorStrategy, isSubsystemAllowed, discoverSubsystemSpecs } from './harness/agent/builder.js';
30
30
  export type { AgentTraceOptions } from './harness/agent/builder.js';
31
31
  export type { AgentBuildOptions, AgentBuildResult, AgentBuildCoreResult } from './harness/agent/builder.js';
32
32
  export type { ChannelAdapter, ChannelMessage, ChannelReply } from './harness/extension/plugin-ecosystem/channel-types.js';
@@ -40,11 +40,11 @@ export { TurnFileUndoLog, commitSessionFileUndo, discardSessionFileUndo, resolve
40
40
  export { TurnMemoryJournal, JournaledMemoryStore, createMemoryRestorer, discardMemoryUndo, } from './harness/extension/execution-environment/memory-undo.js';
41
41
  export type { MemoryUndoEntry, MemoryEffectRestorer, DiscardMemoryEffectsResult, } from './harness/extension/execution-environment/memory-undo.js';
42
42
  export type { MemoryEffectJournal, MemoryEffectDomain } from '@octopi-agent/core/types/tools.js';
43
- export { resolveEffectiveEffectPolicy, requiresJail, isPathAllowed, isToolAllowedOnSurface, DEFAULT_EFFECT_RUN_MODE, readSessionEffectOverrides, normalizeTransactionRoots, mergeTransactionRoots, SESSION_EFFECT_OVERRIDES_KEY, } from './harness/extension/execution-environment/effect-policy.js';
43
+ export { resolveEffectiveEffectPolicy, requiresJail, buildOpsJailState, isPathAllowed, isToolAllowedOnSurface, DEFAULT_EFFECT_RUN_MODE, readSessionEffectOverrides, normalizeTransactionRoots, mergeTransactionRoots, SESSION_EFFECT_OVERRIDES_KEY, } from './harness/extension/execution-environment/effect-policy.js';
44
44
  export { ProcessSandbox, createProcessSandbox, assessL4ProcessMinimum, probeProcessIsolation, scrubEnv, killProcessTree, supervisedSpawnProfile, } from './harness/extension/execution-environment/index.js';
45
45
  export type { ProcessIsolationProfile, IsolationBackend, L4ProcessAssessment, } from './harness/extension/execution-environment/process-isolation.js';
46
46
  export { runWithToolLimits, resolveToolTimeoutMs, ToolTimeoutError, } from './harness/extension/execution-environment/resource-limits.js';
47
- export type { EffectIntent, ConfirmEffect, ConfirmEffectDecision, UntrustedAdmission, ToolSurface, SecurityDegradation, SessionEffectOverrides, } from './harness/extension/execution-environment/effect-policy.js';
47
+ export type { EffectIntent, ConfirmEffect, ConfirmEffectDecision, UntrustedAdmission, JailIntent, OnJailUnavailable, OpsJailState, ToolSurface, SecurityDegradation, SessionEffectOverrides, } from './harness/extension/execution-environment/effect-policy.js';
48
48
  export type { EffectRunMode, EffectPolicyConfig, EffectiveEffectPolicy, PathContainment, ShellEscapePolicy, } from './harness/extension/execution-environment/effect-policy.js';
49
49
  export { scanOrphanSessionUndo, } from './harness/extension/execution-environment/undo-log.js';
50
50
  export type { SessionUndoPaths, FileUndoEntry, DiscardFileEffectsResult, DiscardConflictReason, EditResendResult, NotReversedEffects, NotReversedReason, UndoLimitConfig, OrphanUndoDir, } from './harness/extension/execution-environment/undo-log.js';
package/dist/index.js CHANGED
@@ -21,13 +21,13 @@ import { createRunTelemetry } from './integration/observability/run-telemetry.js
21
21
  setRunTelemetryFactory(createRunTelemetry);
22
22
  export { setRunTelemetryFactory, getRunTelemetryFactory } from './harness/observability/run-telemetry.js';
23
23
  export { createRunTelemetry } from './integration/observability/run-telemetry.js';
24
- export { AgentBuilder, createAgent, isSubsystemAllowed, discoverSubsystemSpecs } from './harness/agent/builder.js';
24
+ export { AgentBuilder, createAgent, DefaultErrorStrategy, isSubsystemAllowed, discoverSubsystemSpecs } from './harness/agent/builder.js';
25
25
  export { Agent } from './harness/run/agent/index.js';
26
26
  export { SessionAwareRunner } from './harness/run/runner.js';
27
27
  export { DEFAULT_TOOL_ISOLATION, resolveToolIsolationCwd, } from './harness/extension/execution-environment/isolation.js';
28
28
  export { TurnFileUndoLog, commitSessionFileUndo, discardSessionFileUndo, resolveSessionUndoPaths, resolveSessionUndoOnClose, createUnconfiguredFileEffects, createUnconfiguredMemoryEffects, } from './harness/extension/execution-environment/undo-log.js';
29
29
  export { TurnMemoryJournal, JournaledMemoryStore, createMemoryRestorer, discardMemoryUndo, } from './harness/extension/execution-environment/memory-undo.js';
30
- export { resolveEffectiveEffectPolicy, requiresJail, isPathAllowed, isToolAllowedOnSurface, DEFAULT_EFFECT_RUN_MODE, readSessionEffectOverrides, normalizeTransactionRoots, mergeTransactionRoots, SESSION_EFFECT_OVERRIDES_KEY, } from './harness/extension/execution-environment/effect-policy.js';
30
+ export { resolveEffectiveEffectPolicy, requiresJail, buildOpsJailState, isPathAllowed, isToolAllowedOnSurface, DEFAULT_EFFECT_RUN_MODE, readSessionEffectOverrides, normalizeTransactionRoots, mergeTransactionRoots, SESSION_EFFECT_OVERRIDES_KEY, } from './harness/extension/execution-environment/effect-policy.js';
31
31
  export { ProcessSandbox, createProcessSandbox, assessL4ProcessMinimum, probeProcessIsolation, scrubEnv, killProcessTree, supervisedSpawnProfile, } from './harness/extension/execution-environment/index.js';
32
32
  export { runWithToolLimits, resolveToolTimeoutMs, ToolTimeoutError, } from './harness/extension/execution-environment/resource-limits.js';
33
33
  export { scanOrphanSessionUndo, } from './harness/extension/execution-environment/undo-log.js';
@@ -50,9 +50,27 @@ export async function dispatchChannelMessage(options) {
50
50
  const { runtime, msg, resolveAgentId, resolveSessionId, onEvent } = options;
51
51
  const agentId = resolveAgentId(msg);
52
52
  if (!agentId) {
53
+ // 回执契约 = 恒发一次(liveness);no_agent 的实际结果由上层 error/静默路径处理
54
+ msg.delivery = 'run';
55
+ msg.onDelivery?.('run');
53
56
  return { status: 'skipped', reason: 'no_agent' };
54
57
  }
55
58
  const sessionId = resolveSessionId(msg);
56
59
  const trigger = channelMessageToTrigger(msg, agentId, sessionId);
57
- return runtime.dispatch(trigger, onEvent ? { onEvent } : undefined);
60
+ // 单一入口:dispatch 内部 offer;活跃 Run 接收即回执(早于 Run 结束)。
61
+ // 拒绝/早退路径(runtime_stopped 等)也要回执一次(liveness),错误走 error 通道。
62
+ let delivered = false;
63
+ const result = await runtime.dispatch(trigger, {
64
+ ...(onEvent ? { onEvent } : {}),
65
+ onDelivery: (delivery) => {
66
+ delivered = true;
67
+ msg.delivery = delivery;
68
+ msg.onDelivery?.(delivery);
69
+ },
70
+ });
71
+ if (!delivered) {
72
+ msg.delivery = 'run';
73
+ msg.onDelivery?.('run');
74
+ }
75
+ return result;
58
76
  }
@@ -12,6 +12,8 @@ export type { SessionIndexBackend, SessionIndexSink, SessionIndexPrefilterQuery,
12
12
  export { NoopObserver } from './observability/noop-observer.js';
13
13
  export { LogObserver } from './observability/log-observer.js';
14
14
  export { createRunTelemetry } from './observability/run-telemetry.js';
15
+ export { startLoopWatchdog } from './observability/loop-watchdog.js';
16
+ export type { LoopWatchdog, LoopWatchdogOptions } from './observability/loop-watchdog.js';
15
17
  export { SdkMcpClient, createSdkMcpClient } from './mcp/index.js';
16
18
  export { createDuckDuckGoProvider, createTavilyProvider, createBraveProvider, createSerperProvider, createMimoProvider, createWebSearchProviderFromSlot, resolveWebSearchProviders, createWebSearchWithFallback, } from './web-search/index.js';
17
19
  export type { WebSearchConfig, WebSearchProviderSlotConfig, ResolvedWebSearchProviders, } from './web-search/index.js';
@@ -12,6 +12,7 @@ export { createSqliteSessionIndex, rebuildSessionIndexFromStore, ensureSessionIn
12
12
  export { NoopObserver } from './observability/noop-observer.js';
13
13
  export { LogObserver } from './observability/log-observer.js';
14
14
  export { createRunTelemetry } from './observability/run-telemetry.js';
15
+ export { startLoopWatchdog } from './observability/loop-watchdog.js';
15
16
  // ── MCP ──
16
17
  export { SdkMcpClient, createSdkMcpClient } from './mcp/index.js';
17
18
  // ── Web Search ──
@@ -0,0 +1,56 @@
1
+ /**
2
+ * 事件循环停滞看门狗(宿主自检器官)
3
+ *
4
+ * 背景(2026-10-28 事故):网关事件循环被同步阻塞整体冻结约 4.5 小时——两个 run 的
5
+ * turn 同时停摆、HTTP accept 停止、SIGTERM handler 无法运行,最终被 `serve restart`
6
+ * 的 SIGKILL 升级收尾。事后缺一份阻塞现场的栈采样,确切阻塞点永久失考。
7
+ *
8
+ * 机制:独立 worker 线程(不随主循环冻结)定期 ping 主线程;主线程 message handler
9
+ * 回 pong 以证明事件循环存活。主循环冻结 → pong 静默超阈值 → worker 判定停滞:
10
+ * 写 JSONL 报告 +(macOS)自动 `sample <pid>` 抓主线程栈。检测与取证全部发生在
11
+ * worker 侧,不依赖已被冻结的事件循环。
12
+ *
13
+ * 第二道闸:进程 RSS 越过 `footprintThresholdMb` 即同样落报告 + 采栈。停滞检测
14
+ * 只能证明「已经僵死」,内存失控则可能在冻死前给出一段可干预的窗口——2026-10-30
15
+ * 网关膨胀到 30.5G 的进程在采样完成后几分钟就被系统收走。
16
+ *
17
+ * 设计约束:
18
+ * - 观测 fail-open:看门狗自身的任何失败不得影响宿主(写盘/采样失败静默吞掉)。
19
+ * - worker unref:不阻止进程退出;宿主应显式 `stop()` 收尾。
20
+ * - 复发 runbook:报告文件给出停滞起点(lastPongAt),`.sample-*.txt` 给出阻塞栈;
21
+ * 若自动采样失败,在杀进程前手动执行 `sample <pid> 5 -f /tmp/octopi-hang.txt`。
22
+ *
23
+ * @module integration/observability/loop-watchdog
24
+ */
25
+ /** 看门狗配置 */
26
+ export interface LoopWatchdogOptions {
27
+ /** 显式关闭(缺省开启;关闭态返回 no-op 句柄) */
28
+ enabled?: boolean;
29
+ /** 心跳间隔(毫秒,缺省 5_000) */
30
+ intervalMs?: number;
31
+ /** 主循环静默多久判停滞(毫秒,缺省 30_000) */
32
+ stallThresholdMs?: number;
33
+ /** 报告落盘路径(JSONL,每行一个事件;缺省 `<OCTOPI_HOME>/logs/loop-watchdog.jsonl`) */
34
+ reportFile?: string;
35
+ /** 停滞时自动 `sample` 抓主线程栈(macOS 专属;缺省 true,测试关闭) */
36
+ captureSample?: boolean;
37
+ /**
38
+ * 进程 RSS 阈值(MB,缺省 4096;传 0 关闭)
39
+ *
40
+ * 越过阈值即写 `footprint` 事件并采栈——不必等事件循环冻死。用于在内存
41
+ * 失控的早期抓住现场(滞回:跌回阈值的 80% 以下才复位,避免阈值附近反复采样)。
42
+ */
43
+ footprintThresholdMb?: number;
44
+ }
45
+ /** 看门狗句柄 */
46
+ export interface LoopWatchdog {
47
+ /** 停止看门狗并回收 worker */
48
+ stop(): void;
49
+ }
50
+ /**
51
+ * 启动事件循环停滞看门狗
52
+ *
53
+ * @param options - 心跳间隔 / 停滞阈值 / 报告路径 / 是否自动栈采样
54
+ * @returns 看门狗句柄(`stop()` 回收 worker)
55
+ */
56
+ export declare function startLoopWatchdog(options?: LoopWatchdogOptions): LoopWatchdog;
@@ -0,0 +1,177 @@
1
+ /**
2
+ * 事件循环停滞看门狗(宿主自检器官)
3
+ *
4
+ * 背景(2026-10-28 事故):网关事件循环被同步阻塞整体冻结约 4.5 小时——两个 run 的
5
+ * turn 同时停摆、HTTP accept 停止、SIGTERM handler 无法运行,最终被 `serve restart`
6
+ * 的 SIGKILL 升级收尾。事后缺一份阻塞现场的栈采样,确切阻塞点永久失考。
7
+ *
8
+ * 机制:独立 worker 线程(不随主循环冻结)定期 ping 主线程;主线程 message handler
9
+ * 回 pong 以证明事件循环存活。主循环冻结 → pong 静默超阈值 → worker 判定停滞:
10
+ * 写 JSONL 报告 +(macOS)自动 `sample <pid>` 抓主线程栈。检测与取证全部发生在
11
+ * worker 侧,不依赖已被冻结的事件循环。
12
+ *
13
+ * 第二道闸:进程 RSS 越过 `footprintThresholdMb` 即同样落报告 + 采栈。停滞检测
14
+ * 只能证明「已经僵死」,内存失控则可能在冻死前给出一段可干预的窗口——2026-10-30
15
+ * 网关膨胀到 30.5G 的进程在采样完成后几分钟就被系统收走。
16
+ *
17
+ * 设计约束:
18
+ * - 观测 fail-open:看门狗自身的任何失败不得影响宿主(写盘/采样失败静默吞掉)。
19
+ * - worker unref:不阻止进程退出;宿主应显式 `stop()` 收尾。
20
+ * - 复发 runbook:报告文件给出停滞起点(lastPongAt),`.sample-*.txt` 给出阻塞栈;
21
+ * 若自动采样失败,在杀进程前手动执行 `sample <pid> 5 -f /tmp/octopi-hang.txt`。
22
+ *
23
+ * @module integration/observability/loop-watchdog
24
+ */
25
+ import { Worker } from 'node:worker_threads';
26
+ import { join } from 'node:path';
27
+ import { getOctopiHome } from '../../paths.js';
28
+ /**
29
+ * worker 侧脚本(eval 载入;此处为字符串以规避 dist/源码双态下的模块解析差异)
30
+ *
31
+ * 职责:心跳 ping、停滞判定、报告落盘、栈采样。不得引用 worker_threads 之外的
32
+ * 外部模块形态(eval worker 无 ESM import,只能 require)。
33
+ */
34
+ const WORKER_SRC = `
35
+ const { parentPort, workerData } = require('node:worker_threads');
36
+ const { appendFileSync, mkdirSync } = require('node:fs');
37
+ const { dirname } = require('node:path');
38
+ const { spawnSync } = require('node:child_process');
39
+
40
+ let lastPongAt = Date.now();
41
+ let stalledSince = undefined;
42
+ let footprintLatched = false;
43
+
44
+ const writeReport = (record) => {
45
+ try {
46
+ mkdirSync(dirname(workerData.reportFile), { recursive: true });
47
+ appendFileSync(workerData.reportFile, JSON.stringify(record) + '\\n');
48
+ } catch {
49
+ // 观测 fail-open:报告写盘失败不得影响 worker 自身的监测
50
+ }
51
+ };
52
+
53
+ const captureStack = (tag) => {
54
+ if (!workerData.captureSample || process.platform !== 'darwin') return;
55
+ const sampleFile = workerData.sampleFile.replace('{{ts}}', tag + '-' + Date.now());
56
+ try {
57
+ const r = spawnSync('sample', [String(process.pid), '3', '-f', sampleFile], {
58
+ timeout: 15000,
59
+ stdio: 'ignore',
60
+ });
61
+ // spawnSync 失败不抛(ENOENT 等走返回值):必须按返回值如实留痕,
62
+ // 否则「宣称采样成功」会把运维引向不存在的文件
63
+ if (r.error == null && r.status === 0) {
64
+ console.error('[LoopWatchdog] stack sample written: ' + sampleFile);
65
+ } else {
66
+ console.error('[LoopWatchdog] stack sample FAILED (' + (r.error ? r.error.message : 'exit ' + r.status) + '); run manually: sample ' + process.pid + ' 5 -f /tmp/octopi-hang.txt');
67
+ }
68
+ } catch (err) {
69
+ console.error('[LoopWatchdog] stack sample FAILED: ' + String(err) + '; run manually: sample ' + process.pid + ' 5 -f /tmp/octopi-hang.txt');
70
+ }
71
+ };
72
+
73
+ parentPort.on('message', (msg) => {
74
+ if (msg && msg.type === 'pong') {
75
+ lastPongAt = Date.now();
76
+ if (stalledSince !== undefined) {
77
+ writeReport({
78
+ event: 'recovered',
79
+ detectedAt: new Date().toISOString(),
80
+ stalledForMs: Date.now() - stalledSince,
81
+ });
82
+ console.error('[LoopWatchdog] event loop recovered after ' + (Date.now() - stalledSince) + 'ms stall');
83
+ stalledSince = undefined;
84
+ }
85
+ }
86
+ });
87
+
88
+ setInterval(() => {
89
+ parentPort.postMessage({ type: 'ping' });
90
+ const silentForMs = Date.now() - lastPongAt;
91
+ if (stalledSince === undefined && silentForMs >= workerData.stallThresholdMs) {
92
+ stalledSince = lastPongAt;
93
+ writeReport({
94
+ event: 'stall',
95
+ detectedAt: new Date().toISOString(),
96
+ silentForMs,
97
+ lastPongAt,
98
+ pid: process.pid,
99
+ });
100
+ console.error('[LoopWatchdog] event loop stalled: no heartbeat for ' + silentForMs + 'ms (pid ' + process.pid + ')');
101
+ captureStack('stall');
102
+ }
103
+
104
+ // 内存足迹阈值:在撑爆前留出干预窗口。
105
+ // 2026-10-30 事故里 footprint 涨到 30.5G 时主线程已被原生 h2 扩容循环吃满,
106
+ // 等到心跳消失再采样只是事后取证——进程几分钟后就被系统收走,无从止损。
107
+ // 滞回(跌回 80% 以下才复位)避免在阈值附近反复采样。
108
+ const thresholdMb = workerData.footprintThresholdMb;
109
+ if (thresholdMb > 0) {
110
+ const rssMb = Math.round(process.memoryUsage().rss / 1048576);
111
+ if (!footprintLatched && rssMb >= thresholdMb) {
112
+ footprintLatched = true;
113
+ writeReport({
114
+ event: 'footprint',
115
+ detectedAt: new Date().toISOString(),
116
+ rssMb,
117
+ thresholdMb,
118
+ pid: process.pid,
119
+ });
120
+ console.error('[LoopWatchdog] footprint ' + rssMb + 'MB >= threshold ' + thresholdMb + 'MB (pid ' + process.pid + ')');
121
+ captureStack('footprint');
122
+ } else if (footprintLatched && rssMb < thresholdMb * 0.8) {
123
+ footprintLatched = false;
124
+ writeReport({
125
+ event: 'footprint_recovered',
126
+ detectedAt: new Date().toISOString(),
127
+ rssMb,
128
+ thresholdMb,
129
+ });
130
+ console.error('[LoopWatchdog] footprint back under threshold: ' + rssMb + 'MB');
131
+ }
132
+ }
133
+ }, workerData.intervalMs);
134
+ `;
135
+ /**
136
+ * 启动事件循环停滞看门狗
137
+ *
138
+ * @param options - 心跳间隔 / 停滞阈值 / 报告路径 / 是否自动栈采样
139
+ * @returns 看门狗句柄(`stop()` 回收 worker)
140
+ */
141
+ export function startLoopWatchdog(options = {}) {
142
+ if (options.enabled === false) {
143
+ return { stop: () => { } };
144
+ }
145
+ const reportFile = options.reportFile ?? join(getOctopiHome(), 'logs', 'loop-watchdog.jsonl');
146
+ const worker = new Worker(WORKER_SRC, {
147
+ eval: true,
148
+ workerData: {
149
+ intervalMs: options.intervalMs ?? 5_000,
150
+ stallThresholdMs: options.stallThresholdMs ?? 30_000,
151
+ reportFile,
152
+ captureSample: options.captureSample ?? true,
153
+ sampleFile: `${reportFile}.sample-{{ts}}.txt`,
154
+ footprintThresholdMb: options.footprintThresholdMb ?? 4096,
155
+ },
156
+ });
157
+ // 心跳应答(主循环冻结时此 handler 不再被调度——正是停滞信号)
158
+ worker.on('message', (msg) => {
159
+ if (msg?.type === 'ping') {
160
+ worker.postMessage({ type: 'pong' });
161
+ }
162
+ });
163
+ worker.on('error', (err) => {
164
+ // 观测 fail-open:worker 自身崩溃不得影响宿主;但必须留痕——否则自检能力
165
+ // 整个进程生命周期无声缺席(eval worker 启动失败/平台差异)
166
+ console.warn(`[LoopWatchdog] worker error, stall detection disabled: ${String(err)}`);
167
+ });
168
+ // 不阻止进程退出
169
+ worker.unref();
170
+ return {
171
+ stop: () => {
172
+ worker.terminate().catch(() => {
173
+ // 关停竞态(worker 已退出)无害
174
+ });
175
+ },
176
+ };
177
+ }
@@ -50,6 +50,8 @@ export interface MetricsSnapshot {
50
50
  sessionsActive: number;
51
51
  /** 总 turn 数 */
52
52
  turnsTotal: number;
53
+ /** 以失败告终的 turn 数(turn.end 带 error;含重试中失败尝试,失败不再是指标盲区) */
54
+ failedTurns: number;
53
55
  /** 空回复数 */
54
56
  emptyResponses: number;
55
57
  /** 重试次数 */
@@ -84,6 +86,7 @@ export declare class MetricsAggregator {
84
86
  private _toolErrors;
85
87
  private _sessionsActive;
86
88
  private _turnsTotal;
89
+ private _failedTurns;
87
90
  private _emptyResponses;
88
91
  private _retriesTotal;
89
92
  private _snapshots;
@@ -63,6 +63,7 @@ export class MetricsAggregator {
63
63
  // Session 指标
64
64
  _sessionsActive = new Set();
65
65
  _turnsTotal = 0;
66
+ _failedTurns = 0;
66
67
  _emptyResponses = 0;
67
68
  _retriesTotal = 0;
68
69
  // 快照历史
@@ -123,14 +124,22 @@ export class MetricsAggregator {
123
124
  break;
124
125
  }
125
126
  // ── Turn ──
126
- case 'turn.start':
127
- this._turnsTotal++;
128
- break;
129
- case 'turn.end':
130
- if (!event.data?.content || event.data.content.length === 0) {
131
- this._emptyResponses++;
127
+ // 只计完整结束的 turn:重试中失败尝试的 turn_end(error) 不是用户语义上的轮次,
128
+ // 否则 turnsTotal 会把失败尝试计成 turn、与 llmCalls 倒挂;失败调用的空输出
129
+ // 也不是「空响应」。
130
+ case 'turn.end': {
131
+ const failed = Boolean(event.data?.error);
132
+ if (!failed) {
133
+ this._turnsTotal++;
134
+ if (!event.data?.content || event.data.content.length === 0) {
135
+ this._emptyResponses++;
136
+ }
137
+ }
138
+ else {
139
+ this._failedTurns++;
132
140
  }
133
141
  break;
142
+ }
134
143
  // ── 重试 ──
135
144
  case 'retry':
136
145
  this._retriesTotal++;
@@ -162,6 +171,7 @@ export class MetricsAggregator {
162
171
  toolErrors: Object.fromEntries(this._toolErrors),
163
172
  sessionsActive: this._sessionsActive.size,
164
173
  turnsTotal: this._turnsTotal,
174
+ failedTurns: this._failedTurns,
165
175
  emptyResponses: this._emptyResponses,
166
176
  retriesTotal: this._retriesTotal,
167
177
  estimatedCostUsd: Math.round(estimatedCostUsd * 10000) / 10000,
@@ -188,6 +198,7 @@ export class MetricsAggregator {
188
198
  this._toolErrors.clear();
189
199
  this._sessionsActive.clear();
190
200
  this._turnsTotal = 0;
201
+ this._failedTurns = 0;
191
202
  this._emptyResponses = 0;
192
203
  this._retriesTotal = 0;
193
204
  this._snapshots = [];
@@ -211,7 +222,7 @@ export function formatMetricsSnapshot(snap) {
211
222
  lines.push(`${'─'.repeat(50)}`);
212
223
  lines.push(`Uptime: ${(snap.uptimeMs / 1000).toFixed(0)}s`);
213
224
  lines.push(`Sessions: ${snap.sessionsActive} active`);
214
- lines.push(`Turns: ${snap.turnsTotal}`);
225
+ lines.push(`Turns: ${snap.turnsTotal} (${snap.failedTurns} failed)`);
215
226
  lines.push(`Empty replies: ${snap.emptyResponses}`);
216
227
  lines.push(`Retries: ${snap.retriesTotal}`);
217
228
  lines.push('');