@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
package/dist/runtime/waits.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import type { Logger } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { type OnApplicationShutdown } from "@nestjs/common";
|
|
3
|
-
import { type Job
|
|
3
|
+
import { type Job } from "bullmq";
|
|
4
4
|
import { BackgroundTaskStopper } from "../background/stop.js";
|
|
5
5
|
import { EventLog } from "../conversations/event-log.js";
|
|
6
|
-
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
7
6
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
8
7
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
9
8
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
10
|
-
import {
|
|
11
|
-
import type { KernelLogger } from "../log.js";
|
|
9
|
+
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
12
10
|
import { ApprovalsService } from "../tools/approvals.service.js";
|
|
13
11
|
import { ToolPipeline } from "../tools/pipeline.js";
|
|
14
12
|
import { QuestionsService } from "../tools/questions.service.js";
|
|
@@ -17,6 +15,7 @@ import { KyselyCheckpointSaver } from "./checkpointer.js";
|
|
|
17
15
|
import { type WaitingFor } from "./loop.js";
|
|
18
16
|
import { MAINTENANCE_QUEUE_NAME } from "./maintenance-queue.js";
|
|
19
17
|
import { RunFinish } from "./run-finish.js";
|
|
18
|
+
import { RunResume, resumeJobId } from "./run-jobs.js";
|
|
20
19
|
import { RunQueue } from "./run-queue.js";
|
|
21
20
|
import { SubagentDeliveries } from "./subagents/deliveries.js";
|
|
22
21
|
/** 等待超时任务所在的内核维护队列(见 maintenance.ts)。 */
|
|
@@ -24,50 +23,8 @@ export { MAINTENANCE_QUEUE_NAME };
|
|
|
24
23
|
/** 等待超时任务的名字与 jobId(每个审批 / 输入请求一个,重复投递被 BullMQ 忽略)。 */
|
|
25
24
|
export declare const WAIT_TIMEOUT_JOB = "wait-timeout";
|
|
26
25
|
export declare const waitTimeoutJobId: (waitId: string) => string;
|
|
27
|
-
/**
|
|
28
|
-
export
|
|
29
|
-
/**
|
|
30
|
-
* 等待兜底扫描(Task 22):任务名、job scheduler id(不含 `:`)、周期、宽限期与每类每次最多处理的条数。
|
|
31
|
-
* 宽限期:waiting 超过它、等待却已全部处理的运行才视为「续跑丢失」,避免与正常续跑(暂停后的复查等)竞争。
|
|
32
|
-
*/
|
|
33
|
-
export declare const WAIT_SWEEP_JOB = "wait-sweep";
|
|
34
|
-
/** The maintenance scheduler the sweep ran on before it became a `@LockedCron` (retired). */
|
|
35
|
-
export { WAIT_SWEEP_SCHEDULER_ID } from "./job-ids.js";
|
|
36
|
-
export declare const WAIT_SWEEP_GRACE_MS = 60000;
|
|
37
|
-
export declare const WAIT_SWEEP_BATCH = 500;
|
|
38
|
-
/** 一次扫描(本副本)实际生效的修复数。 */
|
|
39
|
-
export interface WaitSweepResult {
|
|
40
|
-
/** 过期仍 pending、被本次扫描按超时处理的审批 / 输入请求。 */
|
|
41
|
-
expired: number;
|
|
42
|
-
/** 等待已全部处理、被本次扫描续跑的 waiting 运行。 */
|
|
43
|
-
resumed: number;
|
|
44
|
-
/** 运行已终态、被本次扫描取消的审批 / 输入请求。 */
|
|
45
|
-
cancelled: number;
|
|
46
|
-
/**
|
|
47
|
-
* Finished runs whose fork invocation had no report, repaired (`pairStoppedForks`; the next run
|
|
48
|
-
* would build on a fork lead without its report).
|
|
49
|
-
*/
|
|
50
|
-
repaired: number;
|
|
51
|
-
/** Queued sub-agent runs, and chat runs queued by a resume, whose job was lost, enqueued again. */
|
|
52
|
-
requeued: number;
|
|
53
|
-
/** Running sub-agent runs without job or lock, failed `run.orphaned` and reported to the parent. */
|
|
54
|
-
orphaned: number;
|
|
55
|
-
/**
|
|
56
|
-
* Active fork sub-agent runs of a finished parent run, and active sub-agent runs of a deleted
|
|
57
|
-
* conversation's tree, asked to stop.
|
|
58
|
-
*/
|
|
59
|
-
stopped: number;
|
|
60
|
-
/**
|
|
61
|
-
* Finished background sub-agent runs whose `finished` delivery was never written (the finisher
|
|
62
|
-
* died after the child's terminal commit), delivered (agent map spec §10).
|
|
63
|
-
*/
|
|
64
|
-
delivered: number;
|
|
65
|
-
/**
|
|
66
|
-
* Idle sub-agents with a parked message no run took (a `SendMessage` that reached a run after
|
|
67
|
-
* its last model call, whose replica died before the post-run `ensureRun`), started again.
|
|
68
|
-
*/
|
|
69
|
-
restarted: number;
|
|
70
|
-
}
|
|
26
|
+
/** A resumed run's job id (`run-<conversationId>-resume-<waitId>`; `RunResume` owes it). */
|
|
27
|
+
export { resumeJobId };
|
|
71
28
|
/** The data of a wait timeout job; `subagents` waits also carry their run and step. */
|
|
72
29
|
export interface WaitTimeoutData {
|
|
73
30
|
kind: WaitingFor["kind"];
|
|
@@ -76,18 +33,22 @@ export interface WaitTimeoutData {
|
|
|
76
33
|
step?: number;
|
|
77
34
|
}
|
|
78
35
|
/**
|
|
79
|
-
*
|
|
80
|
-
* `approvals` / `questions`
|
|
36
|
+
* Runs waiting for a person (spec 4.4 / Task 9): suspend, resume, timeout and stop. All state is in
|
|
37
|
+
* PG (`runs.status = 'waiting'`, the `approvals` / `questions` rows); delays and retries are BullMQ
|
|
38
|
+
* jobs (the maintenance queue's `wait-timeout`) owed through the outbox; no in-process state.
|
|
81
39
|
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
40
|
+
* One resume only: a resume locks the run row and moves it `waiting → queued` only when it waits on
|
|
41
|
+
* nothing else, owing the run job `run-<conversationId>-resume-<waitId>` in the same transaction
|
|
42
|
+
* (transactional outbox spec §6). A decision does it in its own transaction
|
|
43
|
+
* (`RunResume.resumeIn`); the timeout job, the suspend's re-check and a fork child's finish
|
|
44
|
+
* through {@link resume}. Whichever comes first, the run resumes once.
|
|
85
45
|
*/
|
|
86
46
|
export declare class Waits implements OnApplicationShutdown {
|
|
87
47
|
private readonly kdb;
|
|
88
48
|
private readonly eventLog;
|
|
89
49
|
private readonly approvals;
|
|
90
50
|
private readonly questions;
|
|
51
|
+
/** Stops a queued or running sub-agent no worker holds directly ({@link stopRun}). */
|
|
91
52
|
private readonly runQueue;
|
|
92
53
|
/**
|
|
93
54
|
* Writes, in the caller's transaction, the results of a stopped run's open `Agent` calls;
|
|
@@ -103,9 +64,10 @@ export declare class Waits implements OnApplicationShutdown {
|
|
|
103
64
|
* `waiting` is set. Children are stopped through `request`.
|
|
104
65
|
*/
|
|
105
66
|
private readonly abort;
|
|
106
|
-
/**
|
|
107
|
-
private readonly
|
|
108
|
-
|
|
67
|
+
/** Owes the wait timeout jobs (`MaintenanceProcessor` consumes them) with the suspend. */
|
|
68
|
+
private readonly outbox;
|
|
69
|
+
/** The resume of a waiting run, in the caller's transaction ({@link resume}). */
|
|
70
|
+
private readonly resumes;
|
|
109
71
|
private readonly log;
|
|
110
72
|
/** Stops a finished sub-agent run's background tasks ({@link childFinished}). */
|
|
111
73
|
private readonly background;
|
|
@@ -114,7 +76,9 @@ export declare class Waits implements OnApplicationShutdown {
|
|
|
114
76
|
readonly txHost: TransactionHost;
|
|
115
77
|
/** Drops the `run.orphaned` subscription (the events may outlive this instance). */
|
|
116
78
|
private readonly unsubscribe;
|
|
117
|
-
constructor(kdb: KernelDb, eventLog: EventLog, approvals: Pick<ApprovalsService, "expire" | "cancelPendingIn">, questions: Pick<QuestionsService, "expire" | "cancelPendingIn">,
|
|
79
|
+
constructor(kdb: KernelDb, eventLog: EventLog, approvals: Pick<ApprovalsService, "expire" | "cancelPendingIn">, questions: Pick<QuestionsService, "expire" | "cancelPendingIn">,
|
|
80
|
+
/** Stops a queued or running sub-agent no worker holds directly ({@link stopRun}). */
|
|
81
|
+
runQueue: Pick<RunQueue, "abortIfOrphaned">,
|
|
118
82
|
/**
|
|
119
83
|
* Writes, in the caller's transaction, the results of a stopped run's open `Agent` calls;
|
|
120
84
|
* `fire` runs their observe hooks after the commit.
|
|
@@ -128,8 +92,10 @@ export declare class Waits implements OnApplicationShutdown {
|
|
|
128
92
|
* `waiting` is set. Children are stopped through `request`.
|
|
129
93
|
*/
|
|
130
94
|
abort: Pick<RunAbort, "requested" | "request">,
|
|
131
|
-
/**
|
|
132
|
-
|
|
95
|
+
/** Owes the wait timeout jobs (`MaintenanceProcessor` consumes them) with the suspend. */
|
|
96
|
+
outbox: Pick<OutboxService, "add">,
|
|
97
|
+
/** The resume of a waiting run, in the caller's transaction ({@link resume}). */
|
|
98
|
+
resumes: Pick<RunResume, "resumeIn">, events: KernelEvents, log: Pick<Logger, "error" | "warn">,
|
|
133
99
|
/** Stops a finished sub-agent run's background tasks ({@link childFinished}). */
|
|
134
100
|
background: Pick<BackgroundTaskStopper, "stopSubagentTasks">,
|
|
135
101
|
/** Delivers a background child's finish to its parent ({@link childFinished}). */
|
|
@@ -139,21 +105,22 @@ export declare class Waits implements OnApplicationShutdown {
|
|
|
139
105
|
/** The context's handle (the transaction of a `@Transactional` method, else the pool). */
|
|
140
106
|
private get db();
|
|
141
107
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
108
|
+
* After the loop returned `suspended` (the worker released the conversation lock and the quota):
|
|
109
|
+
* in one transaction the conditional `running → waiting` (recording `waiting_since`) and the
|
|
110
|
+
* wait's timeout job (`runAt` = `expiresAt`); then a re-check whether the wait is already
|
|
111
|
+
* settled: a decision that came while the run was still `running` did not resume it, so the
|
|
112
|
+
* re-check does.
|
|
113
|
+
* A run no longer running (ended by another path) → nothing.
|
|
114
|
+
* A stop received while suspending (`abort`), or found in the stop marker after `waiting` is set
|
|
115
|
+
* → the wait is cancelled and the run ended as {@link abortWaiting} does (a stop arriving after
|
|
116
|
+
* `waiting` is set is handled by `POST .../abort`, which sees `waiting`; neither side misses it).
|
|
146
117
|
*/
|
|
147
|
-
|
|
118
|
+
suspend(runId: string, conversationId: string, waitingFor: WaitingFor, abort?: RunAbortBy): Promise<void>;
|
|
148
119
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* 之前(那时条件更新不成立),复查保证这种情况下仍会续跑。
|
|
152
|
-
* 运行已不是 running(例如已被其他路径结束)→ 什么都不做。
|
|
153
|
-
* 暂停时已收到用户中止(`abort`),或置 waiting 之后补查到中止标记 → 直接按 {@link abortWaiting} 取消等待并结束
|
|
154
|
-
* 运行(置 waiting 之后到达的中止由 `POST .../abort` 看到 waiting 直接处理,两边不会都漏掉)。
|
|
120
|
+
* {@link suspend}'s transaction: the conditional `running → waiting` and the wait's timeout job
|
|
121
|
+
* owed with it ({@link oweTimeout}). False when the run was no longer running (nothing written).
|
|
155
122
|
*/
|
|
156
|
-
|
|
123
|
+
private suspendIn;
|
|
157
124
|
/**
|
|
158
125
|
* A sub-agent's run waits for an approval or an input (sub-agents spec §9): appends
|
|
159
126
|
* `subagent_waiting` to the **root** conversation of its tree, whatever its depth (agent map spec
|
|
@@ -165,9 +132,9 @@ export declare class Waits implements OnApplicationShutdown {
|
|
|
165
132
|
*/
|
|
166
133
|
private surfaceInRoot;
|
|
167
134
|
/**
|
|
168
|
-
*
|
|
169
|
-
* `
|
|
170
|
-
*
|
|
135
|
+
* Resumes the run in its own transaction (`RunResume.resumeIn`: locks the run row and, when it
|
|
136
|
+
* is `waiting` on nothing else, sets it `queued` and owes its resume job); true when this call
|
|
137
|
+
* queued it. The wait timeout, the suspend's re-check and a fork child's finish use it; the decisions call `RunResume.resumeIn` in their own transactions.
|
|
171
138
|
*/
|
|
172
139
|
resume(runId: string, waitId: string): Promise<boolean>;
|
|
173
140
|
/**
|
|
@@ -191,103 +158,16 @@ export declare class Waits implements OnApplicationShutdown {
|
|
|
191
158
|
abortWaiting(conversationId: string, runId: string, byAccountId: string | null, detail?: RunAbortDetail): Promise<boolean>;
|
|
192
159
|
/** {@link abortWaiting}'s transaction; the open `Agent` calls it wrote go back through `st`. */
|
|
193
160
|
private abortWaitingIn;
|
|
194
|
-
/** 扫描 3:运行已终态(如暂停途中失败)仍 pending 的审批 / 输入请求 → 取消(写决定 / 回答事件)。 */
|
|
195
|
-
private sweepFinishedRuns;
|
|
196
|
-
/**
|
|
197
|
-
* 同一事务里锁会话行与运行行(与 {@link abortWaiting} 同序),运行仍是终态时取消其 pending 等待;
|
|
198
|
-
* 提交后发布事件。返回取消的条数(并发的另一副本拿到锁时已无 pending → 0)。
|
|
199
|
-
*/
|
|
200
|
-
private cancelWaitsOfFinished;
|
|
201
|
-
private cancelWaitsOfFinishedIn;
|
|
202
|
-
/** 扫描 1:`expires_at < now()` 仍 pending 的审批 / 输入请求 → 与超时任务同一路径(置 expired、写事件、续跑)。 */
|
|
203
|
-
private sweepOverdue;
|
|
204
|
-
/**
|
|
205
|
-
* Sub-agents waits past their `runs.wait_expires_at` (their timeout job was lost): expired the
|
|
206
|
-
* way the timeout job would ({@link expire}: the fork invocation's active child stops as
|
|
207
|
-
* `timed out`, the parent resumes once it is done). Only fork invocations wait (agent map spec
|
|
208
|
-
* §5.4); their step is the run's fork dispatch step. A run stays here until its children have
|
|
209
|
-
* stopped; a pass that neither stopped a child nor resumed the run is not counted.
|
|
210
|
-
*/
|
|
211
|
-
private sweepOverdueSubagents;
|
|
212
|
-
/**
|
|
213
|
-
* Sub-agent runs nobody will run (spec §7.5; `RunQueue.repairOrphan`, the same orphan test as
|
|
214
|
-
* `ensureRun`, which never runs for a child): `queued` past the grace period without a job → enqueued
|
|
215
|
-
* again (the dispatch committed, its enqueue was lost); `running` without job and lock → failed
|
|
216
|
-
* `run.orphaned` and reported to the parent, which then resumes. Also a chat run left `queued`
|
|
217
|
-
* by a resume whose enqueue was lost (final review m8): enqueued again under its resume job id
|
|
218
|
-
* (`ensureRun` would only repair it at the conversation's next message).
|
|
219
|
-
*/
|
|
220
|
-
private sweepSubagentOrphans;
|
|
221
|
-
/**
|
|
222
|
-
* Idle sub-agent conversations (no active run, not deleted) with a message newer than what they
|
|
223
|
-
* consumed, written past the grace period and within the last day: a `SendMessage` that reached a
|
|
224
|
-
* run after its last model call is started by that run's post-job `ensureRun`
|
|
225
|
-
* (`RunQueue.childWakeIn`), which a replica dying after the terminal commit skips. Re-derived with
|
|
226
|
-
* the same `ensureRun` (its rules decide: a paused root starts nothing). A sub-agent whose last
|
|
227
|
-
* run was stopped (`aborted`) can never start from a message, so it is left out here, and the
|
|
228
|
-
* newest conversations come first (active within the last day), so parked messages that cannot
|
|
229
|
-
* start never fill the batch. Returns how many runs started.
|
|
230
|
-
*/
|
|
231
|
-
private sweepParkedMessages;
|
|
232
|
-
/**
|
|
233
|
-
* Finished runs (past the grace period, within the last day) triggered by a fork invocation that
|
|
234
|
-
* has no report ({@link unreportedForkRuns}): a terminal path that skipped
|
|
235
|
-
* `stopOpenAgentCalls`, such as an old replica's abort, would otherwise leave a fork lead without
|
|
236
|
-
* its report. Each is repaired under the conversation row lock with the normal
|
|
237
|
-
* `stopOpenAgentCalls` (an ended child gives its result, an active one the stopped text;
|
|
238
|
-
* idempotency keys make it safe against the regular paths); an active fork child is then stopped
|
|
239
|
-
* by {@link sweepForkChildrenOfFinished}. An `Agent` call has its result from its dispatch (agent
|
|
240
|
-
* map spec §4.1).
|
|
241
|
-
*/
|
|
242
|
-
private sweepOpenAgentCalls;
|
|
243
|
-
/** One run's repair of {@link sweepOpenAgentCalls}; its observe hooks go back through `st`. */
|
|
244
|
-
private repairOpenAgentCallsIn;
|
|
245
|
-
/**
|
|
246
|
-
* Active fork sub-agent runs (phase D, `for_skill`) of a parent run that finished more than the
|
|
247
|
-
* grace period ago (§12: the run's terminal state stops its fork child and reports it stopped;
|
|
248
|
-
* this is the backstop) → stopped. Background `Agent` children of a finished run are the normal
|
|
249
|
-
* case and keep running (agent map spec §5.4).
|
|
250
|
-
*/
|
|
251
|
-
private sweepForkChildrenOfFinished;
|
|
252
|
-
/**
|
|
253
|
-
* Active sub-agent runs with a deleted ancestor (agent map spec §10: deleting the root stops the
|
|
254
|
-
* whole tree; the delete's own {@link stopTree} is the normal path, this the backstop for a crash
|
|
255
|
-
* between marking the root deleted and stopping its tree, or a dispatch that raced it) → stopped
|
|
256
|
-
* on the deleter's behalf (no account). No grace period: nothing in a deleted tree should run.
|
|
257
|
-
*/
|
|
258
|
-
private sweepTreesOfDeletedRoots;
|
|
259
|
-
/**
|
|
260
|
-
* Background sub-agent runs that finished more than the grace period ago (within the last day)
|
|
261
|
-
* whose parent has no `subagent_finished` for them (agent map spec §10: the finisher died after
|
|
262
|
-
* the child's terminal commit; the finish path writes `subagent_finished` and the delivery in one
|
|
263
|
-
* transaction) → {@link childFinished}, idempotent against a late finisher. Keyed on the child
|
|
264
|
-
* run, so a run nobody dispatched (a wake run, §5.3) is repaired too, and on
|
|
265
|
-
* `subagent_finished`, not on the delivery, so a child that finished before background
|
|
266
|
-
* dispatch (its result was the `Agent` call's, its `subagent_finished` written then) is never
|
|
267
|
-
* delivered a second time. Fork invocations' runs, a run without a terminal event in its log
|
|
268
|
-
* (nothing to deliver), a conversation never dispatched and a child whose parent conversation
|
|
269
|
-
* was deleted are skipped; only a written delivery counts.
|
|
270
|
-
*/
|
|
271
|
-
private sweepUndelivered;
|
|
272
|
-
/**
|
|
273
|
-
* 扫描 2:waiting 超过宽限期、却已没有 pending 等待的运行(决定提交后进程崩溃、续跑投递失败回滚等)→
|
|
274
|
-
* {@link resume}(条件更新 `waiting → queued` + 投递)。续跑任务的 jobId 用该运行最近一次等待的 id
|
|
275
|
-
* (与人工决定 / 超时任务一致,已投递过的同一续跑被 BullMQ 去重)。
|
|
276
|
-
*/
|
|
277
|
-
private sweepStuckRuns;
|
|
278
|
-
/**
|
|
279
|
-
* The id of the run's latest wait (by creation time): an approval, an input request or a fork
|
|
280
|
-
* invocation's dispatch, whose wait id is its child run id (the id the child's finisher resumes
|
|
281
|
-
* with, so a sweep resume and a late finisher resume share one job id).
|
|
282
|
-
*/
|
|
283
|
-
private lastWaitId;
|
|
284
161
|
/**
|
|
285
162
|
* A `wait-timeout` job (dispatched by `MaintenanceProcessor`): expires the wait,
|
|
286
163
|
* or delays the job again until the wait's expiry when it ran early.
|
|
287
164
|
*/
|
|
288
165
|
processTimeout(job: Job<WaitTimeoutData>, token: string | undefined): Promise<void>;
|
|
289
|
-
/**
|
|
290
|
-
|
|
166
|
+
/**
|
|
167
|
+
* Owes the wait's timeout job (`wait-timeout-<waitId>`, `runAt` = the wait's deadline) in the
|
|
168
|
+
* suspend's transaction (transactional outbox spec §6 "Resumes and timeouts").
|
|
169
|
+
*/
|
|
170
|
+
private oweTimeout;
|
|
291
171
|
/**
|
|
292
172
|
* Whether the wait is over: an approval or input request is no longer pending (decided, expired
|
|
293
173
|
* or cancelled); `subagents`: the run's fork invocation child is no longer active.
|
|
@@ -309,7 +189,8 @@ export declare class Waits implements OnApplicationShutdown {
|
|
|
309
189
|
* `subagent_finished` (idempotent; not model-visible) and tries
|
|
310
190
|
* {@link resume}`(parentRunId, childRunId)`, which succeeds once its parent run waits on nothing
|
|
311
191
|
* else. A run of a conversation never dispatched, or not terminal yet, is left alone. A crash in
|
|
312
|
-
* between is repaired by the
|
|
192
|
+
* between is repaired by the `deliver-to-parent` job its terminal transaction owed (the
|
|
193
|
+
* `run-orphan-check` calls this too). A fork child's
|
|
313
194
|
* running background tasks the terminal run started are then stopped (not those of a later run);
|
|
314
195
|
* a stopped background child's are all stopped, whichever of its runs started them; a background
|
|
315
196
|
* child that ended on its own keeps them, and their finish wakes it (agent map spec §5.3). True
|
|
@@ -377,34 +258,3 @@ export declare class Waits implements OnApplicationShutdown {
|
|
|
377
258
|
*/
|
|
378
259
|
private stopRun;
|
|
379
260
|
}
|
|
380
|
-
/**
|
|
381
|
-
* Phase D: finished chat runs (past the grace period, within the last day) triggered by a fork
|
|
382
|
-
* invocation that has no report (dispatched or not); the wait sweep writes it
|
|
383
|
-
* (`pairStoppedForks`).
|
|
384
|
-
*/
|
|
385
|
-
export declare function unreportedForkRuns(db: KernelSchemaDb): Promise<{
|
|
386
|
-
parent_run_id: string;
|
|
387
|
-
parent_conversation_id: string;
|
|
388
|
-
}[]>;
|
|
389
|
-
/**
|
|
390
|
-
* A decided approval / answered question resumes the waiting run on this replica (domain events,
|
|
391
|
-
* spec §3b; the wait sweep resumes a run whose resume was lost). Its IM delivery follows the same
|
|
392
|
-
* events (`ChannelJobs`).
|
|
393
|
-
*/
|
|
394
|
-
export declare class DecisionResumer implements OnApplicationShutdown {
|
|
395
|
-
private readonly unsubscribe;
|
|
396
|
-
constructor(waits: Pick<Waits, "resume">, events: Pick<KernelEvents, "on">);
|
|
397
|
-
/** Unsubscribes after the stop phases: events emitted while they drain are still handled. */
|
|
398
|
-
onApplicationShutdown(): void;
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* The wait sweep, every 10 minutes, once across replicas: {@link Waits.sweep}. Replaces
|
|
402
|
-
* the maintenance scheduler `wait-sweep-every-10m` (retired at worker start).
|
|
403
|
-
*/
|
|
404
|
-
export declare class WaitSweepJob {
|
|
405
|
-
private readonly waits;
|
|
406
|
-
readonly lockService: LockService;
|
|
407
|
-
readonly log: KernelLogger;
|
|
408
|
-
constructor(waits: Pick<Waits, "sweep">, lockService: LockService, log: KernelLogger);
|
|
409
|
-
run(): Promise<void>;
|
|
410
|
-
}
|