@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.
- package/bootstrap.json +25 -25
- package/dist/admin/admin.module.d.ts +2 -1
- package/dist/admin/admin.module.js +7 -3
- package/dist/admin/outbox-dead.controller.d.ts +23 -0
- package/dist/admin/outbox-dead.controller.js +62 -0
- package/dist/admin/outbox-dead.schemas.d.ts +8 -0
- package/dist/admin/outbox-dead.schemas.js +18 -0
- package/dist/admin/outbox-dead.service.d.ts +66 -0
- package/dist/admin/outbox-dead.service.js +179 -0
- package/dist/admin/overview.service.d.ts +40 -5
- package/dist/admin/overview.service.js +41 -7
- package/dist/agents/from-template.js +1 -1
- package/dist/background/finish.d.ts +5 -2
- package/dist/background/finish.js +14 -3
- package/dist/background/launch.d.ts +2 -1
- package/dist/background/launch.js +5 -2
- package/dist/background/store.d.ts +8 -0
- package/dist/background/store.js +24 -0
- package/dist/catalog/admin-catalog.controller.d.ts +21 -2
- package/dist/catalog/admin-catalog.controller.js +45 -6
- package/dist/catalog/admin-catalog.schemas.d.ts +5 -0
- package/dist/catalog/admin-catalog.schemas.js +8 -0
- package/dist/catalog/catalog.module.d.ts +2 -1
- package/dist/catalog/catalog.module.js +5 -1
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/platform-import-update.d.ts +50 -0
- package/dist/catalog/platform-import-update.js +116 -0
- package/dist/catalog/plugin-import.d.ts +36 -1
- package/dist/catalog/plugin-import.js +23 -1
- package/dist/catalog/plugin-upgrade.d.ts +18 -0
- package/dist/catalog/plugin-upgrade.js +19 -0
- package/dist/channels/channels.module.d.ts +5 -2
- package/dist/channels/channels.module.js +9 -2
- package/dist/channels/deliver-job.d.ts +25 -0
- package/dist/channels/deliver-job.js +25 -0
- package/dist/channels/inbound.d.ts +1 -1
- package/dist/channels/inbound.js +2 -15
- package/dist/channels/jobs.d.ts +28 -18
- package/dist/channels/jobs.js +63 -26
- package/dist/config/schema.d.ts +0 -3
- package/dist/config/schema.js +11 -20
- package/dist/conversations/agent-tree.d.ts +16 -0
- package/dist/conversations/agent-tree.js +36 -0
- package/dist/conversations/conversations.service.d.ts +44 -14
- package/dist/conversations/conversations.service.js +52 -38
- package/dist/conversations/event-log.d.ts +7 -10
- package/dist/conversations/event-log.js +24 -15
- package/dist/conversations/events.js +2 -1
- package/dist/conversations/queue.service.d.ts +8 -3
- package/dist/conversations/queue.service.js +37 -13
- package/dist/conversations/titles.d.ts +21 -8
- package/dist/conversations/titles.js +42 -15
- package/dist/db/kernel-schema.d.ts +26 -8
- package/dist/devices/devices.service.d.ts +12 -3
- package/dist/devices/devices.service.js +18 -3
- package/dist/errors.d.ts +11 -0
- package/dist/errors.js +11 -0
- package/dist/evals/run-replay.js +14 -8
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/lifecycle.d.ts +6 -1
- package/dist/extensions/lifecycle.js +9 -2
- package/dist/extensions/usage-subscribers.d.ts +43 -0
- package/dist/extensions/usage-subscribers.js +108 -0
- package/dist/http/api.module.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/infra/cli/kernel-cli.module.js +5 -0
- package/dist/infra/events/kernel-events.d.ts +9 -35
- package/dist/infra/outbox/outbox-relay.module.d.ts +6 -0
- package/dist/infra/outbox/outbox-relay.module.js +18 -0
- package/dist/infra/outbox/outbox.dispatcher.d.ts +103 -0
- package/dist/infra/outbox/outbox.dispatcher.js +310 -0
- package/dist/infra/outbox/outbox.module.d.ts +24 -0
- package/dist/infra/outbox/outbox.module.js +50 -0
- package/dist/infra/outbox/outbox.relay.d.ts +31 -0
- package/dist/infra/outbox/outbox.relay.js +76 -0
- package/dist/infra/outbox/outbox.service.d.ts +51 -0
- package/dist/infra/outbox/outbox.service.js +131 -0
- package/dist/infra/outbox/registry.d.ts +120 -0
- package/dist/infra/outbox/registry.js +108 -0
- package/dist/infra/queue/queue-names.d.ts +8 -0
- package/dist/infra/queue/queue-names.js +16 -0
- package/dist/kernel.module.js +3 -0
- package/dist/local-devices/device-policy.service.d.ts +4 -0
- package/dist/local-devices/device-policy.service.js +61 -3
- package/dist/local-devices/machines.d.ts +13 -5
- package/dist/local-devices/machines.js +45 -7
- package/dist/local-devices/policy-summary.d.ts +44 -1
- package/dist/local-devices/policy-summary.js +69 -0
- package/dist/models/embeddings.d.ts +9 -9
- package/dist/models/embeddings.js +11 -18
- package/dist/models/models.module.js +3 -0
- package/dist/orgs/orgs.service.js +7 -0
- package/dist/overrides.d.ts +20 -3
- package/dist/overrides.js +10 -2
- package/dist/platform/exclusions.js +5 -0
- package/dist/platform/ops/admin.ops.js +18 -2
- package/dist/platform/ops/catalog-admin.ops.d.ts +3 -1
- package/dist/platform/ops/catalog-admin.ops.js +32 -4
- package/dist/platform/ops/outbox.ops.d.ts +21 -0
- package/dist/platform/ops/outbox.ops.js +125 -0
- package/dist/platform/ops/schedules.ops.js +40 -1
- package/dist/platform/platform-ops.module.d.ts +2 -1
- package/dist/platform/platform-ops.module.js +3 -0
- package/dist/platform/route-schemas.js +3 -0
- package/dist/roles/worker.module.js +9 -4
- package/dist/runtime/langgraph-loop.js +13 -5
- package/dist/runtime/limits.d.ts +15 -0
- package/dist/runtime/limits.js +25 -0
- package/dist/runtime/loop.d.ts +8 -3
- package/dist/runtime/loop.js +2 -1
- package/dist/runtime/maintenance.d.ts +4 -2
- package/dist/runtime/maintenance.js +17 -2
- package/dist/runtime/model-call.d.ts +14 -16
- package/dist/runtime/model-call.js +14 -24
- package/dist/runtime/queue-lost-jobs.d.ts +24 -0
- package/dist/runtime/queue-lost-jobs.js +51 -0
- package/dist/runtime/run-control.d.ts +42 -5
- package/dist/runtime/run-control.js +66 -12
- package/dist/runtime/run-finish.d.ts +39 -12
- package/dist/runtime/run-finish.js +97 -14
- package/dist/runtime/run-jobs.d.ts +95 -13
- package/dist/runtime/run-jobs.js +199 -28
- package/dist/runtime/run-orphan-check.job.d.ts +142 -0
- package/dist/runtime/run-orphan-check.job.js +339 -0
- package/dist/runtime/run-processors.d.ts +16 -9
- package/dist/runtime/run-processors.js +1 -1
- package/dist/runtime/run-queue.d.ts +64 -55
- package/dist/runtime/run-queue.js +147 -284
- package/dist/runtime/run-steps.d.ts +1 -2
- package/dist/runtime/run-steps.js +8 -11
- package/dist/runtime/run-worker.d.ts +6 -17
- package/dist/runtime/run-worker.js +32 -34
- package/dist/runtime/runtime.module.d.ts +2 -3
- package/dist/runtime/runtime.module.js +5 -6
- package/dist/runtime/step-log.d.ts +16 -4
- package/dist/runtime/step-log.js +26 -6
- package/dist/runtime/stream.controller.d.ts +2 -4
- package/dist/runtime/stream.controller.js +5 -11
- package/dist/runtime/subagents/child.js +1 -1
- package/dist/runtime/subagents/definition.d.ts +2 -1
- package/dist/runtime/subagents/definition.js +4 -2
- package/dist/runtime/subagents/deliveries.d.ts +6 -3
- package/dist/runtime/subagents/deliveries.js +16 -7
- package/dist/runtime/subagents/dispatch.d.ts +12 -12
- package/dist/runtime/subagents/dispatch.js +13 -38
- package/dist/runtime/subagents/messages.d.ts +5 -1
- package/dist/runtime/subagents/messages.js +11 -3
- package/dist/runtime/subagents/skill-fork.d.ts +3 -3
- package/dist/runtime/subagents/skill-fork.js +5 -5
- package/dist/runtime/subagents/subagents.service.js +1 -1
- package/dist/runtime/subagents/tree-jobs.d.ts +61 -0
- package/dist/runtime/subagents/tree-jobs.js +86 -0
- package/dist/runtime/usage-report-jobs.d.ts +23 -48
- package/dist/runtime/usage-report-jobs.js +67 -119
- package/dist/runtime/usage-report.d.ts +28 -77
- package/dist/runtime/usage-report.js +35 -213
- package/dist/runtime/waits.d.ts +48 -198
- package/dist/runtime/waits.js +103 -805
- package/dist/sandbox/sandbox.service.d.ts +17 -4
- package/dist/sandbox/sandbox.service.js +55 -14
- package/dist/schedules/calendar.d.ts +134 -0
- package/dist/schedules/calendar.js +410 -0
- package/dist/schedules/fire.d.ts +1 -3
- package/dist/schedules/fire.js +5 -10
- package/dist/schedules/run-tracker.d.ts +0 -5
- package/dist/schedules/run-tracker.js +0 -13
- package/dist/schedules/scan.job.js +15 -20
- package/dist/schedules/schedule-math.d.ts +42 -0
- package/dist/schedules/schedule-math.js +52 -0
- package/dist/schedules/scheduled-tasks.service.d.ts +16 -0
- package/dist/schedules/scheduled-tasks.service.js +53 -0
- package/dist/schedules/schedules.controller.d.ts +5 -1
- package/dist/schedules/schedules.controller.js +15 -1
- package/dist/schedules/schedules.schemas.d.ts +35 -0
- package/dist/schedules/schedules.schemas.js +27 -0
- package/dist/schedules/store.d.ts +5 -0
- package/dist/schedules/store.js +20 -0
- package/dist/tools/approvals.service.d.ts +26 -7
- package/dist/tools/approvals.service.js +88 -10
- package/dist/tools/builtin-names.d.ts +5 -3
- package/dist/tools/builtin-names.js +12 -4
- package/dist/tools/builtins/builtin-tools.d.ts +1 -2
- package/dist/tools/builtins/builtin-tools.js +21 -17
- package/dist/tools/builtins/sandbox/bash.js +9 -3
- package/dist/tools/builtins/sandbox/common.d.ts +18 -1
- package/dist/tools/builtins/sandbox/common.js +14 -1
- package/dist/tools/builtins/sandbox/index.d.ts +2 -1
- package/dist/tools/builtins/sandbox/index.js +4 -1
- package/dist/tools/builtins/sandbox/task-list.d.ts +12 -0
- package/dist/tools/builtins/sandbox/task-list.js +130 -0
- package/dist/tools/builtins/sandbox/task-output.d.ts +8 -1
- package/dist/tools/builtins/sandbox/task-output.js +21 -3
- package/dist/tools/builtins/web/extract.d.ts +2 -4
- package/dist/tools/builtins/web/extract.js +2 -5
- package/dist/tools/pipeline.d.ts +1 -1
- package/dist/tools/pipeline.js +1 -1
- package/dist/tools/questions.service.d.ts +15 -6
- package/dist/tools/questions.service.js +20 -8
- package/dist/tools/registry.d.ts +4 -2
- package/dist/tools/registry.js +4 -3
- package/dist/tools/tools.module.js +4 -3
- package/package.json +3 -3
- package/src/migrations/0118_device_policy_ops.sql +6 -0
- package/src/migrations/0119_outbox.sql +22 -0
- 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 {
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
|
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
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
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
|
|
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
|
|
105
|
-
*
|
|
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
|
-
*
|
|
117
|
-
*
|
|
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
|
-
|
|
140
|
+
oweEnsureRun(conversationId: string, seq: number | string, orgId: string): Promise<boolean>;
|
|
120
141
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
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
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* `
|
|
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
|
}
|