@capybara-hq/kernel 0.1.0-rc.23 → 0.1.0-rc.24

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 (206) hide show
  1. package/bootstrap.json +25 -25
  2. package/dist/admin/admin.module.d.ts +2 -1
  3. package/dist/admin/admin.module.js +7 -3
  4. package/dist/admin/outbox-dead.controller.d.ts +23 -0
  5. package/dist/admin/outbox-dead.controller.js +62 -0
  6. package/dist/admin/outbox-dead.schemas.d.ts +8 -0
  7. package/dist/admin/outbox-dead.schemas.js +18 -0
  8. package/dist/admin/outbox-dead.service.d.ts +66 -0
  9. package/dist/admin/outbox-dead.service.js +179 -0
  10. package/dist/admin/overview.service.d.ts +40 -5
  11. package/dist/admin/overview.service.js +41 -7
  12. package/dist/agents/from-template.js +1 -1
  13. package/dist/background/finish.d.ts +5 -2
  14. package/dist/background/finish.js +14 -3
  15. package/dist/background/launch.d.ts +2 -1
  16. package/dist/background/launch.js +5 -2
  17. package/dist/background/store.d.ts +8 -0
  18. package/dist/background/store.js +24 -0
  19. package/dist/catalog/admin-catalog.controller.d.ts +21 -2
  20. package/dist/catalog/admin-catalog.controller.js +45 -6
  21. package/dist/catalog/admin-catalog.schemas.d.ts +5 -0
  22. package/dist/catalog/admin-catalog.schemas.js +8 -0
  23. package/dist/catalog/catalog.module.d.ts +2 -1
  24. package/dist/catalog/catalog.module.js +5 -1
  25. package/dist/catalog/marketplaces.service.d.ts +1 -1
  26. package/dist/catalog/platform-import-update.d.ts +50 -0
  27. package/dist/catalog/platform-import-update.js +116 -0
  28. package/dist/catalog/plugin-import.d.ts +36 -1
  29. package/dist/catalog/plugin-import.js +23 -1
  30. package/dist/catalog/plugin-upgrade.d.ts +18 -0
  31. package/dist/catalog/plugin-upgrade.js +19 -0
  32. package/dist/channels/channels.module.d.ts +5 -2
  33. package/dist/channels/channels.module.js +9 -2
  34. package/dist/channels/deliver-job.d.ts +25 -0
  35. package/dist/channels/deliver-job.js +25 -0
  36. package/dist/channels/inbound.d.ts +1 -1
  37. package/dist/channels/inbound.js +2 -15
  38. package/dist/channels/jobs.d.ts +28 -18
  39. package/dist/channels/jobs.js +63 -26
  40. package/dist/config/schema.d.ts +0 -3
  41. package/dist/config/schema.js +11 -20
  42. package/dist/conversations/agent-tree.d.ts +16 -0
  43. package/dist/conversations/agent-tree.js +36 -0
  44. package/dist/conversations/conversations.service.d.ts +44 -14
  45. package/dist/conversations/conversations.service.js +52 -38
  46. package/dist/conversations/event-log.d.ts +7 -10
  47. package/dist/conversations/event-log.js +24 -15
  48. package/dist/conversations/events.js +2 -1
  49. package/dist/conversations/queue.service.d.ts +8 -3
  50. package/dist/conversations/queue.service.js +37 -13
  51. package/dist/conversations/titles.d.ts +21 -8
  52. package/dist/conversations/titles.js +42 -15
  53. package/dist/db/kernel-schema.d.ts +26 -8
  54. package/dist/devices/devices.service.d.ts +12 -3
  55. package/dist/devices/devices.service.js +18 -3
  56. package/dist/errors.d.ts +11 -0
  57. package/dist/errors.js +11 -0
  58. package/dist/evals/run-replay.js +14 -8
  59. package/dist/extensions/extensions.module.js +3 -0
  60. package/dist/extensions/lifecycle.d.ts +6 -1
  61. package/dist/extensions/lifecycle.js +9 -2
  62. package/dist/extensions/usage-subscribers.d.ts +43 -0
  63. package/dist/extensions/usage-subscribers.js +108 -0
  64. package/dist/http/api.module.js +2 -0
  65. package/dist/index.d.ts +1 -0
  66. package/dist/index.js +1 -0
  67. package/dist/infra/cli/kernel-cli.module.js +5 -0
  68. package/dist/infra/events/kernel-events.d.ts +9 -35
  69. package/dist/infra/outbox/outbox-relay.module.d.ts +6 -0
  70. package/dist/infra/outbox/outbox-relay.module.js +18 -0
  71. package/dist/infra/outbox/outbox.dispatcher.d.ts +103 -0
  72. package/dist/infra/outbox/outbox.dispatcher.js +310 -0
  73. package/dist/infra/outbox/outbox.module.d.ts +24 -0
  74. package/dist/infra/outbox/outbox.module.js +50 -0
  75. package/dist/infra/outbox/outbox.relay.d.ts +31 -0
  76. package/dist/infra/outbox/outbox.relay.js +76 -0
  77. package/dist/infra/outbox/outbox.service.d.ts +51 -0
  78. package/dist/infra/outbox/outbox.service.js +131 -0
  79. package/dist/infra/outbox/registry.d.ts +120 -0
  80. package/dist/infra/outbox/registry.js +108 -0
  81. package/dist/infra/queue/queue-names.d.ts +8 -0
  82. package/dist/infra/queue/queue-names.js +16 -0
  83. package/dist/kernel.module.js +3 -0
  84. package/dist/local-devices/device-policy.service.d.ts +4 -0
  85. package/dist/local-devices/device-policy.service.js +61 -3
  86. package/dist/local-devices/machines.d.ts +13 -5
  87. package/dist/local-devices/machines.js +45 -7
  88. package/dist/local-devices/policy-summary.d.ts +44 -1
  89. package/dist/local-devices/policy-summary.js +69 -0
  90. package/dist/models/embeddings.d.ts +9 -9
  91. package/dist/models/embeddings.js +11 -18
  92. package/dist/models/models.module.js +3 -0
  93. package/dist/orgs/orgs.service.js +7 -0
  94. package/dist/overrides.d.ts +20 -3
  95. package/dist/overrides.js +10 -2
  96. package/dist/platform/exclusions.js +5 -0
  97. package/dist/platform/ops/admin.ops.js +18 -2
  98. package/dist/platform/ops/catalog-admin.ops.d.ts +3 -1
  99. package/dist/platform/ops/catalog-admin.ops.js +32 -4
  100. package/dist/platform/ops/outbox.ops.d.ts +21 -0
  101. package/dist/platform/ops/outbox.ops.js +125 -0
  102. package/dist/platform/ops/schedules.ops.js +40 -1
  103. package/dist/platform/platform-ops.module.d.ts +2 -1
  104. package/dist/platform/platform-ops.module.js +3 -0
  105. package/dist/platform/route-schemas.js +3 -0
  106. package/dist/roles/worker.module.js +9 -4
  107. package/dist/runtime/langgraph-loop.js +13 -5
  108. package/dist/runtime/limits.d.ts +15 -0
  109. package/dist/runtime/limits.js +25 -0
  110. package/dist/runtime/loop.d.ts +8 -3
  111. package/dist/runtime/loop.js +2 -1
  112. package/dist/runtime/maintenance.d.ts +4 -2
  113. package/dist/runtime/maintenance.js +17 -2
  114. package/dist/runtime/model-call.d.ts +14 -16
  115. package/dist/runtime/model-call.js +14 -24
  116. package/dist/runtime/queue-lost-jobs.d.ts +24 -0
  117. package/dist/runtime/queue-lost-jobs.js +51 -0
  118. package/dist/runtime/run-control.d.ts +42 -5
  119. package/dist/runtime/run-control.js +66 -12
  120. package/dist/runtime/run-finish.d.ts +39 -12
  121. package/dist/runtime/run-finish.js +97 -14
  122. package/dist/runtime/run-jobs.d.ts +95 -13
  123. package/dist/runtime/run-jobs.js +199 -28
  124. package/dist/runtime/run-orphan-check.job.d.ts +142 -0
  125. package/dist/runtime/run-orphan-check.job.js +339 -0
  126. package/dist/runtime/run-processors.d.ts +16 -9
  127. package/dist/runtime/run-processors.js +1 -1
  128. package/dist/runtime/run-queue.d.ts +64 -55
  129. package/dist/runtime/run-queue.js +147 -284
  130. package/dist/runtime/run-steps.d.ts +1 -2
  131. package/dist/runtime/run-steps.js +8 -11
  132. package/dist/runtime/run-worker.d.ts +6 -17
  133. package/dist/runtime/run-worker.js +32 -34
  134. package/dist/runtime/runtime.module.d.ts +2 -3
  135. package/dist/runtime/runtime.module.js +5 -6
  136. package/dist/runtime/step-log.d.ts +16 -4
  137. package/dist/runtime/step-log.js +26 -6
  138. package/dist/runtime/stream.controller.d.ts +2 -4
  139. package/dist/runtime/stream.controller.js +5 -11
  140. package/dist/runtime/subagents/child.js +1 -1
  141. package/dist/runtime/subagents/definition.d.ts +2 -1
  142. package/dist/runtime/subagents/definition.js +4 -2
  143. package/dist/runtime/subagents/deliveries.d.ts +6 -3
  144. package/dist/runtime/subagents/deliveries.js +16 -7
  145. package/dist/runtime/subagents/dispatch.d.ts +12 -12
  146. package/dist/runtime/subagents/dispatch.js +13 -38
  147. package/dist/runtime/subagents/messages.d.ts +5 -1
  148. package/dist/runtime/subagents/messages.js +11 -3
  149. package/dist/runtime/subagents/skill-fork.d.ts +3 -3
  150. package/dist/runtime/subagents/skill-fork.js +5 -5
  151. package/dist/runtime/subagents/subagents.service.js +1 -1
  152. package/dist/runtime/subagents/tree-jobs.d.ts +61 -0
  153. package/dist/runtime/subagents/tree-jobs.js +86 -0
  154. package/dist/runtime/usage-report-jobs.d.ts +23 -48
  155. package/dist/runtime/usage-report-jobs.js +67 -119
  156. package/dist/runtime/usage-report.d.ts +28 -77
  157. package/dist/runtime/usage-report.js +35 -213
  158. package/dist/runtime/waits.d.ts +48 -198
  159. package/dist/runtime/waits.js +103 -805
  160. package/dist/sandbox/sandbox.service.d.ts +17 -4
  161. package/dist/sandbox/sandbox.service.js +55 -14
  162. package/dist/schedules/calendar.d.ts +134 -0
  163. package/dist/schedules/calendar.js +410 -0
  164. package/dist/schedules/fire.d.ts +1 -3
  165. package/dist/schedules/fire.js +5 -10
  166. package/dist/schedules/run-tracker.d.ts +0 -5
  167. package/dist/schedules/run-tracker.js +0 -13
  168. package/dist/schedules/scan.job.js +15 -20
  169. package/dist/schedules/schedule-math.d.ts +42 -0
  170. package/dist/schedules/schedule-math.js +52 -0
  171. package/dist/schedules/scheduled-tasks.service.d.ts +16 -0
  172. package/dist/schedules/scheduled-tasks.service.js +53 -0
  173. package/dist/schedules/schedules.controller.d.ts +5 -1
  174. package/dist/schedules/schedules.controller.js +15 -1
  175. package/dist/schedules/schedules.schemas.d.ts +35 -0
  176. package/dist/schedules/schedules.schemas.js +27 -0
  177. package/dist/schedules/store.d.ts +5 -0
  178. package/dist/schedules/store.js +20 -0
  179. package/dist/tools/approvals.service.d.ts +26 -7
  180. package/dist/tools/approvals.service.js +88 -10
  181. package/dist/tools/builtin-names.d.ts +5 -3
  182. package/dist/tools/builtin-names.js +12 -4
  183. package/dist/tools/builtins/builtin-tools.d.ts +1 -2
  184. package/dist/tools/builtins/builtin-tools.js +21 -17
  185. package/dist/tools/builtins/sandbox/bash.js +9 -3
  186. package/dist/tools/builtins/sandbox/common.d.ts +18 -1
  187. package/dist/tools/builtins/sandbox/common.js +14 -1
  188. package/dist/tools/builtins/sandbox/index.d.ts +2 -1
  189. package/dist/tools/builtins/sandbox/index.js +4 -1
  190. package/dist/tools/builtins/sandbox/task-list.d.ts +12 -0
  191. package/dist/tools/builtins/sandbox/task-list.js +130 -0
  192. package/dist/tools/builtins/sandbox/task-output.d.ts +8 -1
  193. package/dist/tools/builtins/sandbox/task-output.js +21 -3
  194. package/dist/tools/builtins/web/extract.d.ts +2 -4
  195. package/dist/tools/builtins/web/extract.js +2 -5
  196. package/dist/tools/pipeline.d.ts +1 -1
  197. package/dist/tools/pipeline.js +1 -1
  198. package/dist/tools/questions.service.d.ts +15 -6
  199. package/dist/tools/questions.service.js +20 -8
  200. package/dist/tools/registry.d.ts +4 -2
  201. package/dist/tools/registry.js +4 -3
  202. package/dist/tools/tools.module.js +4 -3
  203. package/package.json +3 -3
  204. package/src/migrations/0118_device_policy_ops.sql +6 -0
  205. package/src/migrations/0119_outbox.sql +22 -0
  206. package/src/migrations/0120_drop_usage_report_sweep.sql +7 -0
@@ -1,18 +1,21 @@
1
1
  import type { Logger } from "@capybara-hq/plugin-sdk";
2
2
  import type { Queue } from "bullmq";
3
3
  import { EventLog } from "../conversations/event-log.js";
4
- import type { ConversationKind } from "../db/kernel-schema.js";
5
4
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
6
5
  import { KernelDb } from "../infra/database/kernel-db.js";
7
6
  import { TransactionHost } from "../infra/database/transaction-host.js";
8
- import { KernelEvents } from "../infra/events/kernel-events.js";
9
- import { ToolPipeline } from "../tools/pipeline.js";
10
7
  import type { RunAbortDetail } from "./abort.js";
11
8
  import { KyselyCheckpointSaver } from "./checkpointer.js";
12
9
  import { ConversationLock } from "./conversation-lock.js";
13
10
  import { RunFinish } from "./run-finish.js";
14
- import { type RunJobData, RunJobs } from "./run-jobs.js";
15
- export { ACTIVE_RUN_STATUSES, RUN_QUEUE_NAME, type RunJobData, runJobId, runQueueNameFor, SUBAGENT_RUN_QUEUE_NAME, } from "./run-jobs.js";
11
+ import { RunJobs } from "./run-jobs.js";
12
+ export { ACTIVE_RUN_STATUSES, ENSURE_RUN_BACKSTOP_MS, ENSURE_RUN_JOB, type EnsureRunJobData, ensureRunJobId, RUN_QUEUE_NAME, type RunJobData, runJobId, runQueueNameFor, SUBAGENT_RUN_QUEUE_NAME, } from "./run-jobs.js";
13
+ /**
14
+ * Test seam (`KernelOverride`): returns true to make {@link RunQueue.ensureRun} throw before it
15
+ * does anything (Redis unreachable, or a direct call after a commit that never happened). The
16
+ * kernel never provides it.
17
+ */
18
+ export declare const ENSURE_RUN_FAILS: unique symbol;
16
19
  /**
17
20
  * 运行队列(生产方):`ensureRun` 在会话有未消费的用户消息、且没有进行中的运行时插入 `runs` 行并投递任务。
18
21
  * 「是否已有运行」以 PG 为准(会话行锁内检查 `runs` 中的 queued / running),并参考会话锁的持有者;
@@ -24,32 +27,25 @@ export declare class RunQueue {
24
27
  private readonly lock;
25
28
  private readonly jobs;
26
29
  private readonly finisher;
27
- /** 运行以孤儿结束(标记失败 / 直接中止)后删除它的 checkpoint thread(thread_id = runId)。 */
30
+ /** An orphan aborted directly loses its checkpoint thread (thread_id = runId). */
28
31
  private readonly checkpoints;
29
- /** The run's open `Agent` call results, in the orphan repair's transaction (sub-agents spec §12). */
30
- private readonly pipeline;
31
- private readonly events;
32
32
  private readonly log;
33
33
  readonly txHost: TransactionHost;
34
34
  private readonly config;
35
35
  /** The producer side of the delayed `bg-wake` job (`MaintenanceProcessor` consumes it). */
36
36
  private readonly maintenance;
37
+ private readonly ensureFails;
37
38
  constructor(kdb: KernelDb, eventLog: EventLog, lock: Pick<ConversationLock, "holder">, jobs: RunJobs, finisher: Pick<RunFinish, "finishIn">,
38
- /** 运行以孤儿结束(标记失败 / 直接中止)后删除它的 checkpoint thread(thread_id = runId)。 */
39
- checkpoints: Pick<KyselyCheckpointSaver, "deleteThread">,
40
- /** The run's open `Agent` call results, in the orphan repair's transaction (sub-agents spec §12). */
41
- pipeline: Pick<ToolPipeline, "stopOpenAgentCalls">, events: KernelEvents, log: Pick<Logger, "error" | "warn">, txHost: TransactionHost, config: KernelConfigService,
39
+ /** An orphan aborted directly loses its checkpoint thread (thread_id = runId). */
40
+ checkpoints: Pick<KyselyCheckpointSaver, "deleteThread">, log: Pick<Logger, "error" | "warn">, txHost: TransactionHost, config: KernelConfigService,
42
41
  /** The producer side of the delayed `bg-wake` job (`MaintenanceProcessor` consumes it). */
43
- maintenance: Pick<Queue, "add">);
42
+ maintenance: Pick<Queue, "add">, ensureFails?: () => boolean);
44
43
  private get db();
45
- /**
46
- * The `beforeTerminal` of an orphan repair: writes the run's open `Agent` call results in the
47
- * repair's transaction; `fire()` runs their observe hooks after the commit (review m1).
48
- */
49
- private stopOpenCalls;
50
44
  /**
51
45
  * 有未消费的用户消息(最新 user_message 的 seq > `consumed_seq`)、会话锁无人持有、
52
- * 且没有 queued / running / waiting 的运行时:插入 `runs`(queued)并投递任务,返回 runId;否则返回 null。
46
+ * 且没有 queued / running / waiting 的运行时:插入 `runs`(queued),返回 runId;否则返回 null。
47
+ * The run's job is owed in the same transaction (transactional outbox spec §6): the outbox
48
+ * delivers it after the commit, so a queued run never lacks its job.
53
49
  *
54
50
  * The boundary (`trigger_seq`) is that newest message; with none unconsumed, the queue's head
55
51
  * once it is sent; with no head either, a wake-eligible finished background task or sub-agent
@@ -58,13 +54,11 @@ export declare class RunQueue {
58
54
  * event inside the wake window schedules the delayed `bg-wake` job instead. A sub-agent's
59
55
  * conversation is only woken this way ({@link childWakeIn}).
60
56
  *
61
- * 孤儿清理(R29,按需进行,没有定时器):已有的 queued / running 运行若 BullMQ 任务已不存在、
62
- * 会话锁也无人持有(queued 的还要超过宽限期),说明没有任何 worker 会再执行它——写
63
- * `run_failed { code: "run.orphaned" }` 把它标记为失败(consumed_seq 推进到它的触发消息),
64
- * 再按常规判断是否起新一轮,并删除它的 checkpoint thread。会话因此不会永远卡在「有运行」。
65
- * 除了写入消息后,打开 SSE、读事件、运行结束后也会调用它(幂等),孤儿因此在有人查看时就被清理。
57
+ * An active run (queued, running or waiting) is left alone: a run nobody runs any more is the
58
+ * `run-orphan-check`'s to repair (transactional outbox spec §6), never this call's, and reads
59
+ * never call it.
66
60
  *
67
- * agent 已软删除的会话不起新运行(孤儿清理照常进行)。
61
+ * A conversation whose agent is soft-deleted starts no run.
68
62
  */
69
63
  ensureRun(conversationId: string,
70
64
  /** From the `bg-wake` job: it fired `wakeRetry - 1` times before its window ended. */
@@ -73,6 +67,20 @@ export declare class RunQueue {
73
67
  }): Promise<string | null>;
74
68
  /** {@link ensureRun}'s transaction: what it decided goes back through `st`. */
75
69
  private ensureRunIn;
70
+ /**
71
+ * The job id of a new run for `seq` (in {@link ensureRunIn}'s transaction, read from PG only):
72
+ * the trigger's `runJobId` for its first run; a later run of the same trigger (a run that hit its
73
+ * deadline leaves the messages it did not absorb unconsumed, R34) gets `<runJobId>-<n>`,
74
+ * recorded in `runs.job_id`, so its job is never taken for the earlier run's (BullMQ ignores an
75
+ * add under the id of a job it still holds).
76
+ */
77
+ private jobIdFor;
78
+ /**
79
+ * Owes the new run's job in {@link ensureRunIn}'s transaction, before its run row is written.
80
+ * False (logged): the same job id is still owed, so the caller writes no run (a second run of
81
+ * one trigger; the conversation's unique active run makes this a should-not-happen).
82
+ */
83
+ private oweJob;
76
84
  /**
77
85
  * {@link ensureRunIn} for a sub-agent's conversation (agent map spec §5.3), under its row lock.
78
86
  * Its runs from a task, or from a message to an idle sub-agent, are started by the dispatch
@@ -84,8 +92,7 @@ export declare class RunQueue {
84
92
  * started again only by its parent. Both read the queue and the trigger account's access on the root
85
93
  * of its tree; a message needs no wake setting and has no wake window. The run counts against
86
94
  * the root's budget window and runs on the sub-agent queue under `runJobId(child, boundary
87
- * seq)`. An active run is left to the orphan repair after the commit (`repairRunId`), never
88
- * started past.
95
+ * seq)`. An active run is never started past (one nobody runs is the `run-orphan-check`'s).
89
96
  */
90
97
  private childWakeIn;
91
98
  /**
@@ -101,10 +108,24 @@ export declare class RunQueue {
101
108
  * Re-derives the wakes a paused root held for its tree (agent map spec §5.3: a paused root queue
102
109
  * holds the wakes of the whole tree): after the root's queue is unpaused, {@link ensureRun} on
103
110
  * every sub-agent conversation below it that has an unconsumed wake event or message and no
104
- * active run (the root itself is the caller's own `ensureRun`). Errors are logged; the next
105
- * event, run end or page opening of that conversation re-derives its wake.
111
+ * active run (the root itself is the caller's own `ensureRun`). Errors are logged; the
112
+ * ensure-run backstop the releasing transaction owed ({@link oweHeldTreeIn}) wakes it later.
106
113
  */
107
114
  wakeHeldTree(rootId: string): Promise<void>;
115
+ /**
116
+ * Owes, in the caller's transaction (the one that unpauses the root's queue or sends its item
117
+ * now), the ensure-run backstop of every sub-agent {@link wakeHeldTree} would wake after the
118
+ * commit, under the sub-agent's newest seq (transactional outbox spec §6): a process that dies
119
+ * before that call leaves no held wake behind. A root whose queue is still paused (or that is
120
+ * deleted) releases nothing and owes nothing.
121
+ */
122
+ oweHeldTreeIn(rootId: string): Promise<void>;
123
+ /**
124
+ * The sub-agent conversations below `rootId` a paused root holds: not deleted, with an
125
+ * unconsumed wake event (a finished background task, a delivery) or message, and no active run;
126
+ * with their org and newest seq. Reads only (no row locks).
127
+ */
128
+ private heldTree;
108
129
  /**
109
130
  * Schedules the delayed `bg-wake` job at the end of the conversation's wake window (after the
110
131
  * commit): one job per conversation and window end, so finishes inside one window share it. It
@@ -113,41 +134,29 @@ export declare class RunQueue {
113
134
  */
114
135
  private scheduleWake;
115
136
  /**
116
- * Enqueues a run job under the caller's job id (resumes, dispatches, repairs), with the same
117
- * options as {@link ensureRun} (see {@link RunJobs.enqueue}).
137
+ * Owes the ensure-run backstop of `conversationId` in the caller's transaction
138
+ * ({@link oweEnsureRun}): `seq` is the event the transaction wrote, `orgId` the conversation's.
118
139
  */
119
- enqueue(data: RunJobData, jobId: string, kind?: ConversationKind): Promise<void>;
140
+ oweEnsureRun(conversationId: string, seq: number | string, orgId: string): Promise<boolean>;
120
141
  /**
121
- * 中止一个孤儿运行(`POST .../abort` 用):运行仍是 queued / running、会话锁无人持有、BullMQ 任务已不存在
122
- * (queued 的还要超过宽限期,判定同 {@link ensureRun} 的孤儿清理)时,没有任何 worker 会收到中止广播——
123
- * 直接写 `run_aborted`、status 置为 aborted、consumed_seq 至少推进到触发消息,返回 true。
124
- * 不是孤儿(有人在执行或即将执行)或运行已结束 → 返回 false,由调用方走广播中止。
142
+ * Stops an orphaned run directly (`POST .../abort`, a tree stop): a `running` run whose
143
+ * conversation lock is free and whose BullMQ job is gone hears no stop broadcast, so its
144
+ * `run_aborted` is written here (status aborted, `consumed_seq` at least to its trigger): true. Not
145
+ * an orphan (someone runs it; a queued run's job is owed, or lost and re-added by the
146
+ * `run-orphan-check`, whose worker then sees the stop marker) or already finished: false, and the
147
+ * caller broadcasts the stop.
125
148
  */
126
149
  abortIfOrphaned(conversationId: string, runId: string, byAccountId: string | null, detail?: RunAbortDetail): Promise<boolean>;
127
150
  private abortOrphanIn;
128
- /**
129
- * Repairs an orphaned run of a conversation nobody else repairs on demand (a sub-agent's: no
130
- * `ensureRun` ever runs for it; sub-agents spec §7.5), with the same orphan test as
131
- * {@link ensureRun}: the conversation lock is free, the run is still `queued` / `running`, its
132
- * job is gone, and a `queued` one is past the grace period.
133
- * - `queued` (the dispatch or resume committed, its enqueue was lost) → enqueued again under its
134
- * own job id (`runs.job_id`, else the trigger's), so concurrent repairs on several replicas
135
- * still leave one job: `"requeued"`;
136
- * - `running` (its worker died without a terminal state and BullMQ dropped the job) → marked
137
- * failed `run.orphaned`; the caller reports it to the parent: `"failed"`.
138
- * Not an orphan, or already finished → null.
139
- */
140
- repairOrphan(conversationId: string, runId: string): Promise<"requeued" | "failed" | null>;
141
- private repairOrphanIn;
142
151
  /** 会话当前未结束的运行(调用方已持有会话行锁)。 */
143
152
  private activeRun;
144
153
  /**
145
- * 未结束的运行是否已是孤儿(调用方已确认会话锁无人持有):waiting → 否(等人处理,本来就没有任务,
146
- * 由人工决定或超时任务续跑);queued 且仍在宽限期内 → 否(任务可能还没投递);BullMQ 任务(续跑任务按
147
- * `runs.job_id`)仍存在 → 否;否则是。
154
+ * Whether an active run is an orphan for {@link abortIfOrphaned} (the caller saw the conversation
155
+ * lock free): a `running` one whose BullMQ job (a resume's under `runs.job_id`) is gone. A
156
+ * `waiting` one never is (no job by design), nor a `queued` one (its job is owed in the
157
+ * transaction that queued it).
148
158
  */
149
159
  private isOrphan;
150
160
  /** 删除已结束运行的 checkpoint thread(失败只记日志)。 */
151
161
  private dropCheckpoints;
152
- private deleteQueued;
153
162
  }