@capybara-hq/kernel 0.1.0-rc.34 → 0.1.0-rc.36

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 (51) hide show
  1. package/dist/admin/outbox-dead.service.d.ts +2 -0
  2. package/dist/admin/outbox-dead.service.js +34 -0
  3. package/dist/agents/agents.module.js +3 -0
  4. package/dist/agents/readiness.controller.d.ts +8 -11
  5. package/dist/agents/readiness.controller.js +11 -17
  6. package/dist/agents/readiness.service.d.ts +30 -0
  7. package/dist/agents/readiness.service.js +61 -0
  8. package/dist/catalog/marketplaces.service.d.ts +1 -1
  9. package/dist/conversations/conversations.service.d.ts +3 -3
  10. package/dist/conversations/conversations.service.js +58 -29
  11. package/dist/db/kernel-schema.d.ts +8 -0
  12. package/dist/infra/database/transaction-host.d.ts +1 -0
  13. package/dist/infra/database/transaction-host.js +13 -2
  14. package/dist/infra/outbox/registry.d.ts +17 -0
  15. package/dist/infra/outbox/registry.js +11 -0
  16. package/dist/local-devices/local-device-gateway.d.ts +1 -1
  17. package/dist/local-devices/local-device-gateway.js +1 -1
  18. package/dist/local-devices/local-device-provider.d.ts +2 -2
  19. package/dist/local-devices/local-device-provider.js +7 -5
  20. package/dist/orgs/offboarding.d.ts +2 -0
  21. package/dist/orgs/offboarding.js +4 -0
  22. package/dist/orgs/orgs.service.d.ts +3 -1
  23. package/dist/orgs/orgs.service.js +23 -10
  24. package/dist/platform/ops/agents.ops.d.ts +3 -3
  25. package/dist/platform/ops/agents.ops.js +7 -10
  26. package/dist/runtime/checkpointer.js +3 -0
  27. package/dist/runtime/context/compaction.js +5 -5
  28. package/dist/runtime/conversation-lock.d.ts +4 -11
  29. package/dist/runtime/conversation-lock.js +14 -18
  30. package/dist/runtime/maintenance.d.ts +3 -1
  31. package/dist/runtime/maintenance.js +17 -10
  32. package/dist/runtime/project/knowledge.service.js +2 -2
  33. package/dist/runtime/run-deletion.d.ts +23 -0
  34. package/dist/runtime/run-deletion.js +130 -0
  35. package/dist/runtime/run-execution.d.ts +23 -0
  36. package/dist/runtime/run-execution.js +105 -0
  37. package/dist/runtime/run-finish.js +17 -4
  38. package/dist/runtime/run-jobs.js +11 -0
  39. package/dist/runtime/run-orphan-check.job.d.ts +12 -12
  40. package/dist/runtime/run-orphan-check.job.js +94 -26
  41. package/dist/runtime/run-queue.js +14 -0
  42. package/dist/runtime/run-worker.d.ts +9 -5
  43. package/dist/runtime/run-worker.js +90 -44
  44. package/dist/runtime/runtime.module.js +6 -0
  45. package/dist/runtime/stream.js +8 -2
  46. package/dist/runtime/subagents/tree-jobs.d.ts +4 -3
  47. package/dist/runtime/subagents/tree-jobs.js +4 -4
  48. package/dist/tools/pipeline.js +7 -1
  49. package/package.json +3 -3
  50. package/src/migrations/0135_run_execution_claim.sql +2 -0
  51. package/src/migrations/0136_run_recovery_cursor.sql +6 -0
@@ -287,10 +287,11 @@ class Connection {
287
287
  });
288
288
  this.close("abort");
289
289
  });
290
+ return this.chain;
290
291
  }
291
292
  /** 读 lastSeq 之后的全部事件并发送(按 seq 去重:只发大于已发送值的)。 */
292
- async catchUp() {
293
- for (;;) {
293
+ async catchUp(maxPages = Number.POSITIVE_INFINITY) {
294
+ for (let page = 0; page < maxPages; page++) {
294
295
  const evs = await this.d.eventLog.readAfter(this.p.conversationId, this.lastSeq, PAGE);
295
296
  for (const e of evs) {
296
297
  if (this.closed)
@@ -357,6 +358,11 @@ class Connection {
357
358
  const denied = await authorize(this.d, this.p);
358
359
  if (denied !== null)
359
360
  this.fail(denied);
361
+ else {
362
+ // Pub/sub is a hint: a lost final notification must not leave an open stream stale.
363
+ // One page per authorized recheck bounds PG work; the shared chain deduplicates hints.
364
+ await this.enqueue(() => this.catchUp(1));
365
+ }
360
366
  }
361
367
  catch (err) {
362
368
  this.d.log.warn("conversation stream access re-check failed; closing", {
@@ -1,4 +1,5 @@
1
1
  import type { OutboxService } from "../../infra/outbox/outbox.service.js";
2
+ import type { RunDeletion } from "../run-deletion.js";
2
3
  import type { Waits } from "../waits.js";
3
4
  /**
4
5
  * The stops a transaction owes a sub-agent tree (transactional outbox spec §6 "Sub-agents"), on
@@ -6,8 +7,8 @@ import type { Waits } from "../waits.js";
6
7
  * - `{ runId }`: what a run's terminal transaction owes its children: its active fork invocation
7
8
  * child stops (`Waits.stopChildren`, sub-agents spec §12), and a sub-agent run a person stopped
8
9
  * stops its descendants (`Waits.stopDescendantsOfStopped`, agent map spec §6);
9
- * - `{ conversationId, byAccountId }`: a deleted root's whole tree below it stops
10
- * (`Waits.stopTree` without the root, agent map spec §10).
10
+ * - `{ conversationId, byAccountId }`: a deleted root's whole tree including the root stops
11
+ * (`Waits.stopTree` including the root, agent map spec §10).
11
12
  *
12
13
  * The caller still stops them right after its commit; the job is the backstop for a process that
13
14
  * died in between, {@link TREE_JOB_BACKSTOP_MS} later.
@@ -53,7 +54,7 @@ export declare function oweDeliverToParent(outbox: Pick<OutboxService, "add">, c
53
54
  * The `stop-tree` job (`MaintenanceProcessor`): every stop reads the active runs and stops only
54
55
  * those, so a run the direct call already stopped is not stopped again.
55
56
  */
56
- export declare function processStopTree(waits: Pick<Waits, "stopChildren" | "stopDescendantsOfStopped" | "stopTree">, data: StopTreeJobData): Promise<void>;
57
+ export declare function processStopTree(waits: Pick<Waits, "stopChildren" | "stopDescendantsOfStopped" | "stopTree">, data: StopTreeJobData, deletion: Pick<RunDeletion, "stopTree">): Promise<void>;
57
58
  /**
58
59
  * The `deliver-to-parent` job (`MaintenanceProcessor`): `Waits.childFinished` writes the delivery
59
60
  * once by the child run (idempotency keys under the parent conversation's row lock).
@@ -5,8 +5,8 @@ import { MAINTENANCE_QUEUE_NAME } from "../maintenance-queue.js";
5
5
  * - `{ runId }`: what a run's terminal transaction owes its children: its active fork invocation
6
6
  * child stops (`Waits.stopChildren`, sub-agents spec §12), and a sub-agent run a person stopped
7
7
  * stops its descendants (`Waits.stopDescendantsOfStopped`, agent map spec §6);
8
- * - `{ conversationId, byAccountId }`: a deleted root's whole tree below it stops
9
- * (`Waits.stopTree` without the root, agent map spec §10).
8
+ * - `{ conversationId, byAccountId }`: a deleted root's whole tree including the root stops
9
+ * (`Waits.stopTree` including the root, agent map spec §10).
10
10
  *
11
11
  * The caller still stops them right after its commit; the job is the backstop for a process that
12
12
  * died in between, {@link TREE_JOB_BACKSTOP_MS} later.
@@ -69,13 +69,13 @@ export function oweDeliverToParent(outbox, childRunId, orgId) {
69
69
  * The `stop-tree` job (`MaintenanceProcessor`): every stop reads the active runs and stops only
70
70
  * those, so a run the direct call already stopped is not stopped again.
71
71
  */
72
- export async function processStopTree(waits, data) {
72
+ export async function processStopTree(waits, data, deletion) {
73
73
  if ("runId" in data) {
74
74
  await waits.stopChildren(data.runId, null);
75
75
  await waits.stopDescendantsOfStopped(data.runId);
76
76
  return;
77
77
  }
78
- await waits.stopTree(data.conversationId, data.byAccountId, { includeSelf: false });
78
+ await deletion.stopTree(data.conversationId, data.byAccountId);
79
79
  }
80
80
  /**
81
81
  * The `deliver-to-parent` job (`MaintenanceProcessor`): `Waits.childFinished` writes the delivery
@@ -1430,7 +1430,11 @@ let ToolPipeline = class ToolPipeline {
1430
1430
  }
1431
1431
  config = { config: effective.config };
1432
1432
  }
1433
- const r = await this.bounded(ctx.signal, (signal) => handler(input, { ...base, ...config, signal }), undefined, timeoutMs);
1433
+ const r = await this.bounded(ctx.signal, async (signal) => {
1434
+ await this.txHost.run(async () => { });
1435
+ signal.throwIfAborted();
1436
+ return handler(input, { ...base, ...config, signal });
1437
+ }, undefined, timeoutMs);
1434
1438
  if (r === "timeout") {
1435
1439
  return { kind: "error", message: timeoutText(tool.key, timeoutMs) };
1436
1440
  }
@@ -1575,6 +1579,8 @@ let ToolPipeline = class ToolPipeline {
1575
1579
  },
1576
1580
  });
1577
1581
  const session = await opened;
1582
+ await this.txHost.run(async () => { });
1583
+ signal.throwIfAborted();
1578
1584
  return source.resources
1579
1585
  ? runResourceTool(session, source.name, input)
1580
1586
  : // 交回已复核的定义(connector_tools.spec,含 connectorData):连接器按它路由,远端变化须先经漂移复核
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.34",
3
+ "version": "0.1.0-rc.36",
4
4
  "description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -65,7 +65,7 @@
65
65
  "yaml": "^2.9.1",
66
66
  "yauzl": "3.4.0",
67
67
  "zod": "^4.6.7",
68
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.24"
68
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.25"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",
@@ -74,7 +74,7 @@
74
74
  "@types/ws": "^8.18.2",
75
75
  "@types/yauzl": "3.4.0",
76
76
  "ws": "^8.22.0",
77
- "@capybara-hq/testing": "0.1.0-rc.19"
77
+ "@capybara-hq/testing": "0.1.0-rc.20"
78
78
  },
79
79
  "scripts": {
80
80
  "build": "tsc -b"
@@ -0,0 +1,2 @@
1
+ -- A new acquisition of the same run revokes all older worker transactions.
2
+ ALTER TABLE runs ADD COLUMN IF NOT EXISTS execution_id text;
@@ -0,0 +1,6 @@
1
+ -- A shared rotating cursor bounds each recovery pass without starving later active runs.
2
+ CREATE TABLE IF NOT EXISTS run_recovery_cursors (
3
+ name text PRIMARY KEY,
4
+ since timestamptz,
5
+ run_id text
6
+ );