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

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 (140) hide show
  1. package/dist/admin/admin.module.js +2 -0
  2. package/dist/admin/health.service.d.ts +2 -2
  3. package/dist/admin/health.service.js +6 -2
  4. package/dist/agents/agents.module.js +3 -0
  5. package/dist/agents/agents.service.d.ts +6 -1
  6. package/dist/agents/agents.service.js +11 -2
  7. package/dist/catalog/catalog-import.module.js +0 -4
  8. package/dist/catalog/catalog-scope.service.d.ts +63 -26
  9. package/dist/catalog/catalog-scope.service.js +146 -71
  10. package/dist/catalog/catalog.module.js +4 -3
  11. package/dist/catalog/catalog.service.d.ts +11 -4
  12. package/dist/catalog/catalog.service.js +21 -5
  13. package/dist/catalog/cli.d.ts +4 -3
  14. package/dist/catalog/cli.js +8 -13
  15. package/dist/catalog/job-ids.d.ts +8 -20
  16. package/dist/catalog/job-ids.js +11 -16
  17. package/dist/catalog/marketplaces.service.d.ts +1 -1
  18. package/dist/catalog/org-plugin-uploads.d.ts +11 -4
  19. package/dist/catalog/org-plugin-uploads.js +21 -6
  20. package/dist/catalog/owned-items.d.ts +6 -13
  21. package/dist/catalog/owned-items.js +11 -29
  22. package/dist/catalog/owned-plugin-cleanup.d.ts +8 -17
  23. package/dist/catalog/owned-plugin-cleanup.js +12 -66
  24. package/dist/catalog/platform-components.d.ts +56 -34
  25. package/dist/catalog/platform-components.js +68 -78
  26. package/dist/catalog/plugin-import.d.ts +28 -25
  27. package/dist/catalog/plugin-import.js +90 -76
  28. package/dist/catalog/plugin-upgrade.d.ts +4 -4
  29. package/dist/catalog/plugin-upgrade.js +7 -19
  30. package/dist/catalog/scope-jobs.d.ts +59 -0
  31. package/dist/catalog/scope-jobs.js +65 -0
  32. package/dist/catalog/scope-sync-workers.d.ts +22 -0
  33. package/dist/catalog/scope-sync-workers.js +58 -2
  34. package/dist/catalog/scope-sync.d.ts +40 -65
  35. package/dist/catalog/scope-sync.js +114 -122
  36. package/dist/channels/inbound.js +2 -2
  37. package/dist/channels/threads.d.ts +4 -3
  38. package/dist/channels/threads.js +4 -3
  39. package/dist/conversations/conversations.controller.js +4 -2
  40. package/dist/conversations/conversations.service.d.ts +17 -5
  41. package/dist/conversations/conversations.service.js +17 -5
  42. package/dist/conversations/events.d.ts +21 -0
  43. package/dist/conversations/events.js +24 -1
  44. package/dist/conversations/source.d.ts +10 -0
  45. package/dist/conversations/source.js +17 -0
  46. package/dist/conversations/tree.d.ts +10 -0
  47. package/dist/conversations/tree.js +35 -0
  48. package/dist/db/kernel-schema.d.ts +9 -14
  49. package/dist/devices/devices.service.d.ts +11 -8
  50. package/dist/devices/devices.service.js +16 -23
  51. package/dist/evals/run-replay.d.ts +13 -2
  52. package/dist/evals/run-replay.js +28 -1
  53. package/dist/evals/snapshot.d.ts +7 -1
  54. package/dist/evals/snapshot.js +2 -1
  55. package/dist/extensions/hooks.d.ts +22 -3
  56. package/dist/extensions/hooks.js +15 -1
  57. package/dist/extensions/lifecycle-hooks.d.ts +99 -0
  58. package/dist/extensions/lifecycle-hooks.js +273 -0
  59. package/dist/extensions/org-config.d.ts +13 -1
  60. package/dist/extensions/org-config.js +19 -2
  61. package/dist/extensions/permission-view.d.ts +9 -5
  62. package/dist/extensions/permission-view.js +9 -4
  63. package/dist/extensions/point-defaults.d.ts +28 -1
  64. package/dist/extensions/point-defaults.js +44 -13
  65. package/dist/inbox/inbox.service.d.ts +6 -20
  66. package/dist/inbox/inbox.service.js +0 -3
  67. package/dist/inbox/org-notices.d.ts +1 -1
  68. package/dist/inbox/platform-inbox.service.d.ts +3 -32
  69. package/dist/inbox/platform-inbox.service.js +5 -54
  70. package/dist/infra/outbox/registry.d.ts +124 -0
  71. package/dist/infra/outbox/registry.js +126 -0
  72. package/dist/infra/queue/queue-names.d.ts +1 -1
  73. package/dist/infra/queue/queue-names.js +1 -0
  74. package/dist/orgs/directory-sync.js +1 -1
  75. package/dist/orgs/members.service.js +1 -1
  76. package/dist/orgs/offboarding.d.ts +50 -57
  77. package/dist/orgs/offboarding.js +117 -162
  78. package/dist/orgs/orgs.module.js +3 -0
  79. package/dist/orgs/orgs.service.d.ts +11 -5
  80. package/dist/orgs/orgs.service.js +15 -6
  81. package/dist/overrides.d.ts +3 -0
  82. package/dist/overrides.js +2 -0
  83. package/dist/platform/ops/inbox.ops.js +4 -20
  84. package/dist/platform/ops/platform.ops.d.ts +1 -0
  85. package/dist/platform/ops/platform.ops.js +6 -3
  86. package/dist/roles/worker-role.d.ts +10 -5
  87. package/dist/roles/worker-role.js +19 -9
  88. package/dist/roles/worker.module.js +2 -4
  89. package/dist/runtime/context/build.d.ts +3 -0
  90. package/dist/runtime/context/build.js +15 -0
  91. package/dist/runtime/context/plugin-context.d.ts +20 -0
  92. package/dist/runtime/context/plugin-context.js +30 -0
  93. package/dist/runtime/langgraph-loop.js +4 -0
  94. package/dist/runtime/loop.d.ts +8 -0
  95. package/dist/runtime/maintenance.d.ts +5 -3
  96. package/dist/runtime/maintenance.js +36 -11
  97. package/dist/runtime/model-call.d.ts +6 -1
  98. package/dist/runtime/model-call.js +1 -0
  99. package/dist/runtime/plugin-context.service.d.ts +69 -0
  100. package/dist/runtime/plugin-context.service.js +208 -0
  101. package/dist/runtime/run-control.d.ts +6 -1
  102. package/dist/runtime/run-control.js +13 -0
  103. package/dist/runtime/run-queue.d.ts +13 -0
  104. package/dist/runtime/run-queue.js +63 -0
  105. package/dist/runtime/run-worker.d.ts +22 -1
  106. package/dist/runtime/run-worker.js +107 -10
  107. package/dist/runtime/runtime.module.js +2 -0
  108. package/dist/runtime/subagents/dispatch.js +1 -0
  109. package/dist/runtime/subagents/skill-fork.js +3 -0
  110. package/dist/sandbox/jobs.d.ts +20 -10
  111. package/dist/sandbox/jobs.js +23 -17
  112. package/dist/schedules/fire.d.ts +25 -4
  113. package/dist/schedules/fire.js +87 -13
  114. package/dist/schedules/job-ids.d.ts +66 -17
  115. package/dist/schedules/job-ids.js +81 -13
  116. package/dist/schedules/run-tracker.js +2 -1
  117. package/dist/schedules/scan.job.d.ts +13 -32
  118. package/dist/schedules/scan.job.js +35 -144
  119. package/dist/schedules/scheduled-tasks.service.d.ts +6 -6
  120. package/dist/schedules/scheduled-tasks.service.js +17 -14
  121. package/dist/schedules/schedules.module.js +0 -4
  122. package/dist/skills/changes.controller.d.ts +1 -1
  123. package/dist/skills/changes.controller.js +1 -1
  124. package/dist/tools/approvals.service.d.ts +15 -4
  125. package/dist/tools/approvals.service.js +26 -10
  126. package/dist/tools/pipeline.d.ts +11 -2
  127. package/dist/tools/pipeline.js +5 -0
  128. package/dist/tools/questions.service.d.ts +15 -4
  129. package/dist/tools/questions.service.js +21 -19
  130. package/dist/tools/registry.d.ts +8 -1
  131. package/dist/tools/registry.js +9 -0
  132. package/package.json +3 -3
  133. package/src/migrations/0121_drop_platform_migration_runs.sql +12 -0
  134. package/src/migrations/0122_drop_scheduled_task_runs_rechecked_at.sql +5 -0
  135. package/src/migrations/0123_pgvector.sql +27 -0
  136. package/src/migrations/0124_conversation_source.sql +36 -0
  137. package/dist/catalog/platform-migration.d.ts +0 -115
  138. package/dist/catalog/platform-migration.js +0 -583
  139. package/dist/infra/queue/add-job-once.d.ts +0 -14
  140. package/dist/infra/queue/add-job-once.js +0 -16
@@ -54,6 +54,35 @@ export const OUTBOX_JOBS = {
54
54
  removeOnFail: true,
55
55
  },
56
56
  },
57
+ // `orgs/offboarding.ts` RUN_STOP_JOB: owed by the offboard transaction for each of the departed
58
+ // member's active runs in the org, under `runStopJobId` (spec §8.1)
59
+ "run-stop": {
60
+ queue: "cap-kernel-maintenance",
61
+ idempotent: "stopping a finished run is a no-op",
62
+ processedIn: "packages/kernel/src/runtime/maintenance.ts",
63
+ // retried while PG or Redis is briefly unavailable; removed once done; a job that failed every
64
+ // attempt is kept a week (no sweep stops the run after it: the failure must stay visible)
65
+ opts: {
66
+ attempts: 5,
67
+ backoff: { type: "exponential", delay: 5_000 },
68
+ removeOnComplete: true,
69
+ removeOnFail: { age: 7 * 86_400, count: 1_000 },
70
+ },
71
+ },
72
+ // `sandbox/jobs.ts` SANDBOX_DESTROY_FOR_JOB: owed by the transaction that soft-deletes a device
73
+ // (its deletion, offboarding), under `deviceDestroyJobId` (spec §8.1)
74
+ "sandbox-destroy-for": {
75
+ queue: "cap-kernel-maintenance",
76
+ idempotent: "destroying a destroyed device is a no-op",
77
+ processedIn: "packages/kernel/src/runtime/maintenance.ts",
78
+ // the options the direct enqueue had: retried while the provider is down
79
+ opts: {
80
+ attempts: 5,
81
+ backoff: { type: "exponential", delay: 30_000 },
82
+ removeOnComplete: true,
83
+ removeOnFail: 100,
84
+ },
85
+ },
57
86
  // `runtime/subagents/tree-jobs.ts` DELIVER_TO_PARENT_JOB: owed by a sub-agent run's terminal
58
87
  // transaction, under `deliverToParentJobId` (spec §6)
59
88
  "deliver-to-parent": {
@@ -101,6 +130,103 @@ export const OUTBOX_JOBS = {
101
130
  removeOnFail: true,
102
131
  },
103
132
  },
133
+ // `catalog/scope-sync.ts` SCOPE_ITEM_JOB: owed by every transaction that changes an item's
134
+ // scope, disabled flag, list, owner or platform version, under `scopeItemJobId` (one per scope
135
+ // version), and by a sync deferred on a replica that had not loaded the extension yet, under
136
+ // `scopeRetryJobId` with `runAt` (spec §8.1)
137
+ "scope-item": {
138
+ queue: "cap-kernel-plugin-scope",
139
+ idempotent: "the sync converges each (item, org) from the scope, switches and installs it reads under the org's lock, and the installer re-checks under the org row lock, so a second run changes nothing",
140
+ processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts",
141
+ // one attempt (a pair's failure is recorded, not retried); removed once done, so the next
142
+ // add of the same id is not swallowed
143
+ opts: { attempts: 1, removeOnComplete: true, removeOnFail: true },
144
+ },
145
+ // `catalog/scope-jobs.ts` SCOPE_BACKSTOP_JOB: owed by a confirmation's commit (an import, a
146
+ // permissions confirm, an org upload's first version) with `runAt` 5 min on, under
147
+ // `scopeBackstopJobId`, so a crash before the post-deploy add still converges (ruling R24)
148
+ "scope-item-backstop": {
149
+ queue: "cap-kernel-plugin-scope",
150
+ idempotent: "the sync converges each (item, org) from what it reads, as a scope-item job does, so a run after the immediate job changes nothing",
151
+ processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts",
152
+ // retried while the item's extension is not enabled on the deployment yet (the job throws):
153
+ // 1, 2, 4, 8 min; removed once done
154
+ opts: {
155
+ attempts: 5,
156
+ backoff: { type: "exponential", delay: 60_000 },
157
+ removeOnComplete: true,
158
+ removeOnFail: true,
159
+ },
160
+ },
161
+ // `catalog/scope-sync.ts` SCOPE_ORG_JOB: owed by an org's creation, under `scopeOrgJobId`
162
+ "scope-org": {
163
+ queue: "cap-kernel-plugin-scope",
164
+ idempotent: "the sync converges each (item, org) of the org from what it reads, so a second run changes nothing",
165
+ processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts",
166
+ opts: { attempts: 1, removeOnComplete: true, removeOnFail: true },
167
+ },
168
+ // `catalog/job-ids.ts` OWNED_PLUGIN_CLEANUP_JOB: owed by the removal of an org-owned plugin
169
+ // (and by a confirmation that took out the extension of an item removed meanwhile), under
170
+ // `ownedPluginCleanupJobId` (spec §8.1)
171
+ "owned-plugin-cleanup": {
172
+ queue: "cap-kernel-maintenance",
173
+ idempotent: "the cleanup takes the extension out only while no live item uses it, and a missing install or a released claim changes nothing",
174
+ processedIn: "packages/kernel/src/runtime/maintenance.ts",
175
+ // a few retries while PG is briefly unavailable; removed once done
176
+ opts: {
177
+ attempts: 3,
178
+ backoff: { type: "exponential", delay: 5_000 },
179
+ removeOnComplete: true,
180
+ removeOnFail: true,
181
+ },
182
+ },
183
+ // `schedules/job-ids.ts` SCHED_FIRE_JOB: owed by the transaction that writes a pending task run
184
+ // (the scan's tick, a person's "run now"), under `schedFireJobId` (spec §8.1)
185
+ "sched-fire": {
186
+ queue: "cap-kernel-maintenance",
187
+ idempotent: "a fire acts only on a pending task run, under its row lock; a retried start reuses what the first one made",
188
+ processedIn: "packages/kernel/src/runtime/maintenance.ts",
189
+ // a few retries while PG is briefly unavailable; removed once done
190
+ opts: {
191
+ attempts: 3,
192
+ backoff: { type: "exponential", delay: 2_000 },
193
+ removeOnComplete: true,
194
+ removeOnFail: true,
195
+ },
196
+ },
197
+ // `schedules/job-ids.ts` SCHED_SETTLE_JOB: the claimed check, owed by the fire job's claim (the
198
+ // transaction that writes `fired_at`) with `runAt` 10 min on, under `schedSettleJobId` (a run
199
+ // still in flight owes the next check an hour on); the unfired check, owed with the task run
200
+ // (scan tick, "run now") under `schedSettleUnfiredJobId` (ruling R26)
201
+ "sched-settle": {
202
+ queue: "cap-kernel-maintenance",
203
+ idempotent: "a check acts only on a task run still pending (claimed for the claimed check, unclaimed for the unfired one), under the task and run row locks, so a run claimed, started, ended or skipped since is left as it is",
204
+ processedIn: "packages/kernel/src/runtime/maintenance.ts",
205
+ // retried while PG is briefly unavailable; removed once done
206
+ opts: {
207
+ attempts: 5,
208
+ backoff: { type: "exponential", delay: 5_000 },
209
+ removeOnComplete: true,
210
+ removeOnFail: true,
211
+ },
212
+ },
213
+ // `extensions/lifecycle-hooks.ts` LIFECYCLE_JOB: owed by the transaction that removes a member,
214
+ // deletes an agent or deletes an org, once per subscribing plugin, under `lifecycleJobId`
215
+ // (memory plugin spec §6.3)
216
+ lifecycle: {
217
+ queue: "cap-kernel-lifecycle",
218
+ idempotent: "lifecycle handlers must be idempotent (the SDK contract): they delete what the plugin holds for the removed member, agent or org, and deleting it again is a no-op",
219
+ processedIn: "packages/kernel/src/extensions/lifecycle-hooks.ts",
220
+ // retried while the plugin is not loaded on the replica that took the job (a rolling deploy)
221
+ // or its handler fails: 15 attempts from 2 s, doubling (about 18 h in all); removed once done;
222
+ // a job that failed every attempt is kept a week (the failure must stay visible)
223
+ opts: {
224
+ attempts: 15,
225
+ backoff: { type: "exponential", delay: 2_000 },
226
+ removeOnComplete: true,
227
+ removeOnFail: { age: 7 * 86_400, count: 1_000 },
228
+ },
229
+ },
104
230
  };
105
231
  /** The registry's BullMQ options of a job name (none for a name it does not list). */
106
232
  export function outboxJobOptions(name) {
@@ -4,5 +4,5 @@
4
4
  * (admin/health.service.ts) lists the same names from the feature constants;
5
5
  * test/infra/queue-names.test.ts keeps the two equal.
6
6
  */
7
- export declare const KERNEL_QUEUES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-plugin-scope", "cap-kernel-titles", "cap-kernel-usage-report", "cap-kernel-evals"];
7
+ export declare const KERNEL_QUEUES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-plugin-scope", "cap-kernel-titles", "cap-kernel-usage-report", "cap-kernel-evals", "cap-kernel-lifecycle"];
8
8
  export type KernelQueueName = (typeof KERNEL_QUEUES)[number];
@@ -13,4 +13,5 @@ export const KERNEL_QUEUES = [
13
13
  "cap-kernel-titles",
14
14
  "cap-kernel-usage-report",
15
15
  "cap-kernel-evals",
16
+ "cap-kernel-lifecycle",
16
17
  ];
@@ -611,7 +611,7 @@ let DirectorySync = class DirectorySync {
611
611
  if (row?.source !== source)
612
612
  return undefined;
613
613
  const result = await this.offboarding.offboard(orgId, accountId, "directory");
614
- // the markers, events and run stops follow the root commit (none after a rollback)
614
+ // the revocation markers and events follow the root commit (hints; none after a rollback)
615
615
  afterCommit(() => this.offboarding.afterOffboard(result));
616
616
  return result;
617
617
  }
@@ -151,7 +151,7 @@ let MembersService = class MembersService {
151
151
  }
152
152
  const actor = { actorAccountId, ...(actorTokenId !== undefined && { actorTokenId }) };
153
153
  const res = await this.offboarding.offboard(orgId, targetId, "removed", actor);
154
- // the markers, events and run stops follow the root commit (none after a rollback)
154
+ // the revocation markers and events follow the root commit (hints; none after a rollback)
155
155
  afterCommit(() => this.offboarding.afterOffboard(res));
156
156
  await audit(this.db.db, {
157
157
  ...actor,
@@ -1,12 +1,11 @@
1
- import type { Redis } from "ioredis";
2
1
  import { EventLog } from "../conversations/event-log.js";
2
+ import { LifecycleHooks } from "../extensions/lifecycle-hooks.js";
3
3
  import { ExtensionRegistry } from "../extensions/registry.js";
4
4
  import { SessionService } from "../identity/sessions.js";
5
5
  import { KernelDb } from "../infra/database/kernel-db.js";
6
6
  import { TransactionHost } from "../infra/database/transaction-host.js";
7
- import { LockService } from "../infra/lock/lock.service.js";
7
+ import { OutboxService } from "../infra/outbox/outbox.service.js";
8
8
  import type { KernelLogger } from "../log.js";
9
- import { SandboxJobs } from "../sandbox/jobs.js";
10
9
  import { ApprovalsService } from "../tools/approvals.service.js";
11
10
  import { Credentials } from "../tools/credentials.js";
12
11
  import { QuestionsService } from "../tools/questions.service.js";
@@ -26,11 +25,11 @@ export interface OffboardResult {
26
25
  revokedSessionIds: string[];
27
26
  /** 写了 cancelled 事件的会话 → 最大 seq(提交后发布)。 */
28
27
  notify: Map<string, number>;
29
- /** 此人在该组织进行中的运行(queued / running / waiting),提交后中止。 */
28
+ /** The person's active runs in the org (queued / running / waiting): a `run-stop` job each is owed. */
30
29
  runs: InFlightRun[];
31
30
  /** 负责的 agent 转交给的所有者;没有转交时为 null。 */
32
31
  newOwnerId: string | null;
33
- /** The person's devices in the org, soft-deleted here; destroyed by a job after commit. */
32
+ /** The person's devices in the org, soft-deleted here; a destroy job each is owed. */
34
33
  devices: string[];
35
34
  /** Conversations whose queued messages were deleted (`changed: queue` after commit). */
36
35
  queueConversations: string[];
@@ -39,21 +38,28 @@ export interface OffboardResult {
39
38
  export interface OffboardingRunControl {
40
39
  abortWaiting(conversationId: string, runId: string, byAccountId: string | null): Promise<boolean>;
41
40
  abortIfOrphaned(conversationId: string, runId: string, byAccountId: string | null): Promise<boolean>;
41
+ abortQueued(conversationId: string, runId: string, byAccountId: string | null): Promise<boolean>;
42
42
  requestAbort(runId: string, byAccountId: string | null): Promise<void>;
43
43
  }
44
- /** The safety-net sweep: cron job name (no `:`), every 10 minutes, and the rows per page. */
45
- export declare const OFFBOARD_SWEEP_JOB = "offboard-sweep";
46
- export declare const OFFBOARD_SWEEP_BATCH = 500;
47
- /** 一次兜底扫描最多翻的页数(每页 {@link OFFBOARD_SWEEP_BATCH} 条),防止单次任务无限长。 */
48
- export declare const OFFBOARD_SWEEP_MAX_PAGES = 20;
49
- /** 已经广播中止的运行的标记保留时长(秒),长于扫描周期:期间扫描不再重复广播。 */
50
- export declare const OFFBOARD_ABORT_MARK_TTL_SECONDS = 1800;
51
- /** 「已请求中止」标记(Redis 键)。 */
52
- export declare const offboardAbortKey: (runId: string) => string;
44
+ /**
45
+ * The stop of a departed member's run (transactional outbox spec §8.1), owed by the offboard
46
+ * transaction on the maintenance queue under {@link runStopJobId}; `MaintenanceProcessor` runs
47
+ * {@link Offboarding.stopRun}.
48
+ */
49
+ export declare const RUN_STOP_JOB = "run-stop";
50
+ /** The `run-stop` job's data. */
51
+ export interface RunStopJobData {
52
+ conversationId: string;
53
+ runId: string;
54
+ }
55
+ /** The `run-stop` job id: a run is stopped once (no `:`). */
56
+ export declare const runStopJobId: (runId: string) => string;
53
57
  /**
54
58
  * 成员离职(spec 3.3):管理员移出、本人离开与通讯录同步共用这一条路径,全部写入在调用方的同一个事务内,
55
- * 要么都生效要么都不生效。Redis 吊销标记、事件发布与中止进行中的运行是提交后的尽力而为({@link afterOffboard}),
56
- * 漏掉的运行由兜底扫描({@link sweep}:发起人已不是该组织成员的进行中运行)中止。框架无关。
59
+ * 要么都生效要么都不生效。The stops of the person's runs and the destruction of their devices are owed
60
+ * in that transaction (outbox jobs, transactional outbox spec §8.1); the Redis revocation markers
61
+ * and the event publishes after the commit are hints ({@link afterOffboard}: `revoked_at` in PG is
62
+ * the authority).
57
63
  *
58
64
  * 已接受的窄窗口:离职提交时正在进行的 OAuth token 刷新(`Credentials` 刷新锁内)可能在提交之后把此人的
59
65
  * 个人凭据重新写回(upsert)。凭据只在此人以成员身份调用工具时使用,而其运行已被中止、成员关系已删除,
@@ -63,22 +69,25 @@ export declare class Offboarding {
63
69
  private readonly db;
64
70
  readonly txHost: TransactionHost;
65
71
  private readonly sessions;
66
- private readonly redis;
67
72
  private readonly registry;
68
73
  private readonly eventLog;
69
- /** The departed member's devices: one-off maintenance jobs, destroyed by a worker. */
70
- private readonly sandboxJobs;
71
- /** Stops the departed member's runs (`by: null`, a system action). */
74
+ /** Owes the run stops and device destroys in the offboard transaction. */
75
+ private readonly outbox;
76
+ /** Stops the departed member's runs (`by: null`, a system action) in the `run-stop` job. */
72
77
  private readonly runs;
73
78
  private readonly credentials;
74
79
  private readonly approvals;
75
80
  private readonly questions;
81
+ /** Owes `org.member_removed` to the subscribing plugins, in the offboard transaction. */
82
+ private readonly lifecycle;
76
83
  readonly log: KernelLogger;
77
- constructor(db: KernelDb, txHost: TransactionHost, sessions: Pick<SessionService, "markRevoked">, redis: Pick<Redis, "set" | "exists">, registry: Pick<ExtensionRegistry, "list">, eventLog: Pick<EventLog, "notify" | "publishChanged">,
78
- /** The departed member's devices: one-off maintenance jobs, destroyed by a worker. */
79
- sandboxJobs: Pick<SandboxJobs, "destroy">,
80
- /** Stops the departed member's runs (`by: null`, a system action). */
81
- runs: OffboardingRunControl, credentials: Pick<Credentials, "clearAccount">, approvals: Pick<ApprovalsService, "cancelPendingFor">, questions: Pick<QuestionsService, "cancelPendingFor">, log: KernelLogger);
84
+ constructor(db: KernelDb, txHost: TransactionHost, sessions: Pick<SessionService, "markRevoked">, registry: Pick<ExtensionRegistry, "list">, eventLog: Pick<EventLog, "notify" | "publishChanged">,
85
+ /** Owes the run stops and device destroys in the offboard transaction. */
86
+ outbox: Pick<OutboxService, "add">,
87
+ /** Stops the departed member's runs (`by: null`, a system action) in the `run-stop` job. */
88
+ runs: OffboardingRunControl, credentials: Pick<Credentials, "clearAccount">, approvals: Pick<ApprovalsService, "pendingConversationsFor" | "cancelPendingFor">, questions: Pick<QuestionsService, "pendingConversationsFor" | "cancelPendingFor">,
89
+ /** Owes `org.member_removed` to the subscribing plugins, in the offboard transaction. */
90
+ lifecycle: Pick<LifecycleHooks, "recordIn">, log: KernelLogger);
82
91
  /**
83
92
  * In the caller's transaction (`mandatory`: the caller holds the org row lock, order org row →
84
93
  * membership, and did the "last owner" checks):
@@ -87,7 +96,8 @@ export declare class Offboarding {
87
96
  * account (both are account-wide, so conservatively all); a person who leaves (`left`) keeps
88
97
  * them, and the session's current org is cleared (the membership check ends the access);
89
98
  * 3. 删除其在该组织所有连接器上的个人凭据;
90
- * 4. 取消其作为处理人的 pending 审批与提问(写 cancelled 事件),记下此人在该组织进行中的运行(提交后中止);
99
+ * 4. 取消其作为处理人的 pending 审批与提问(写 cancelled 事件); owes a `run-stop` job for each of the
100
+ * person's active runs in the org;
91
101
  * 5. 其负责的该组织 agent 转给组织所有者(最早加入的 owner)并置 `needs_reassignment = true`;
92
102
  * 6. 归档其在该组织各渠道连接上的 IM 话题行(重新加入后在 IM 里开始新的对话,不接着旧会话),
93
103
  * 删除其在该组织的「以后都允许」工具授权(`tool_grants`);
@@ -95,9 +105,10 @@ export declare class Offboarding {
95
105
  * 以及成员关系自身的 `directory:<插件>` 来源,不论此人当初是不是由通讯录加入(手动重新加入后再被移出也不会被同步加回);
96
106
  * 同步不再把此人加回,直到有人手动重新加入({@link MembersService.add} 删除排除);
97
107
  * 8. 审计 `org.member.offboarded`;
98
- * 9. Soft-deletes the person's devices in the org and clears their default row (the
99
- * instances and files are destroyed after the commit, best effort; the hourly sweep finishes
100
- * any left).
108
+ * 9. Soft-deletes the person's devices in the org and clears their default row, and owes the
109
+ * destruction of each (instance and files, `device-destroy-<deviceId>`);
110
+ * 10. Owes the `org.member_removed` lifecycle hook deliveries (outbox jobs, one per subscribing
111
+ * plugin).
101
112
  */
102
113
  offboard(orgId: string, accountId: string, reason: OffboardReason, actor?: {
103
114
  actorAccountId?: string;
@@ -107,36 +118,18 @@ export declare class Offboarding {
107
118
  private exclusionPlugins;
108
119
  /**
109
120
  * After the commit (callers register it with the infra `afterCommit` inside their transaction):
110
- * writes the session revocation markers, publishes the cancelled events, stops the person's
111
- * runs in the org and schedules destroying their devices. A failing step only logs a
112
- * warning.
121
+ * writes the session revocation markers and publishes the cancelled events and queue changes,
122
+ * all hints (the run stops and device destroys were owed in the transaction). A failing step
123
+ * only logs a warning.
113
124
  */
114
125
  afterOffboard(r: OffboardResult): Promise<void>;
115
126
  /**
116
- * 中止一个运行,顺序同会话中止接口:waiting → 直接取消等待并写终态;孤儿 → 直接写终态;
117
- * 否则经 Redis 广播中止(运行所在副本收到后结束;尚未开始的运行开始时补查中止标记)。失败只记 warn。
118
- * 不像会话中止那样随后起新一轮运行:离职者的待处理消息不再处理。
127
+ * The `run-stop` job (`MaintenanceProcessor`): stops a departed member's run the way the
128
+ * conversation's stop does (`POST .../abort`), by no account: a waiting run is aborted directly,
129
+ * a queued run is ended in PG (ruling R27: it never starts later, however long it was held), an
130
+ * orphan is finished directly, a running run is asked to stop through Redis (its replica ends it). A finished run is left alone. No
131
+ * new run follows, as after a person's stop: the departed member's queued messages were deleted.
132
+ * A failure throws (the job is retried).
119
133
  */
120
- private stopRun;
121
- /**
122
- * 兜底扫描(维护队列每 10 分钟):进行中、且发起人已不是该会话所属组织成员的运行 → 中止
123
- * (提交后的中止没做成时,如进程崩溃)。按 `(runs.created_at, runs.id)` 键集分页翻完(每页 500 条,
124
- * 至多 20 页):经广播中止、尚未真正结束的运行仍是进行中,若只取前 500 条,超过 500 条卡住的运行会
125
- * 一直占满这一页,后面的永远轮不到。已广播中止、仍带 `capk:offboard-abort:<runId>` 标记(30 分钟)的运行跳过,
126
- * 不每轮重复广播;标记过期仍未结束的再处理一次。返回本次处理(未跳过)的运行数。
127
- * 现任成员(含匿名访客这样的 guest 成员)发起的运行不受影响。
128
- */
129
- sweep(batch?: number): Promise<number>;
130
- private recentlyAborted;
131
- }
132
- /**
133
- * The offboarding safety-net sweep ({@link Offboarding.sweep}) every 10 minutes, once per tick
134
- * across replicas; a worker-role job (`WorkerModule`).
135
- */
136
- export declare class OffboardSweepJob {
137
- private readonly offboarding;
138
- readonly lockService: LockService;
139
- readonly log: KernelLogger;
140
- constructor(offboarding: Pick<Offboarding, "sweep">, lockService: LockService, log: KernelLogger);
141
- run(): Promise<void>;
134
+ stopRun(data: RunStopJobData): Promise<void>;
142
135
  }