@lobu/runtime-device 24.9.0 → 24.10.0

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 (62) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +18 -16
  3. package/npm-shrinkwrap.json +78 -61
  4. package/package.json +1 -1
  5. package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +3 -0
  6. package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +4 -4
  7. package/vendor/cli/dist/commands/_lib/apply/client.d.ts +21 -17
  8. package/vendor/cli/dist/commands/_lib/apply/client.js +32 -34
  9. package/vendor/cli/dist/commands/dev.js +2 -0
  10. package/vendor/cli/dist/connectors/postgres.ts +39 -24
  11. package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +41 -10
  12. package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +12 -2
  13. package/vendor/cli/dist/connectors/whatsapp_web.ts +18 -2
  14. package/vendor/cli/dist/internal/context.d.ts +5 -0
  15. package/vendor/cli/dist/internal/context.js +23 -9
  16. package/vendor/cli/dist/runtime-components.json +4 -4
  17. package/vendor/cli/package.json +1 -1
  18. package/vendor/connector-sdk/dist/connector-types.d.ts +6 -0
  19. package/vendor/connector-sdk/dist/index.d.ts +1 -0
  20. package/vendor/connector-sdk/dist/index.js +1 -0
  21. package/vendor/connector-sdk/dist/ip-reachability.d.ts +1 -1
  22. package/vendor/connector-sdk/dist/ip-reachability.js +1 -1
  23. package/vendor/connector-sdk/dist/logger.d.ts +1 -1
  24. package/vendor/connector-sdk/dist/logger.js +1 -1
  25. package/vendor/connector-sdk/dist/reaction-client-types.d.ts +3 -1
  26. package/vendor/connector-sdk/dist/retry.d.ts +1 -1
  27. package/vendor/connector-sdk/dist/retry.js +1 -1
  28. package/vendor/connector-sdk/dist/source-withheld-error.d.ts +16 -0
  29. package/vendor/connector-sdk/dist/source-withheld-error.js +19 -0
  30. package/vendor/connector-sdk/package.json +1 -1
  31. package/vendor/connector-worker/dist/daemon/index.d.ts +1 -0
  32. package/vendor/connector-worker/dist/daemon/index.js +1 -0
  33. package/vendor/connector-worker/dist/daemon/terminal-delivery.d.ts +12 -2
  34. package/vendor/connector-worker/dist/daemon/terminal-delivery.js +19 -12
  35. package/vendor/connector-worker/dist/executor/interface.d.ts +10 -0
  36. package/vendor/connector-worker/dist/executor/interface.js +6 -0
  37. package/vendor/connector-worker/dist/executor/isolate.d.ts +1 -0
  38. package/vendor/connector-worker/dist/executor/isolate.js +85 -24
  39. package/vendor/connector-worker/dist/isolate/prelude.js +5 -0
  40. package/vendor/connector-worker/package.json +1 -1
  41. package/vendor/core/dist/classify-error.d.ts +1 -1
  42. package/vendor/core/dist/classify-error.js +2 -2
  43. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +28 -3
  44. package/vendor/core/dist/contracts/tools/manage-automations.js +27 -8
  45. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +8 -0
  46. package/vendor/core/dist/contracts/tools/manage-entity.js +11 -3
  47. package/vendor/core/dist/contracts/tools/save-memory.d.ts +11 -1
  48. package/vendor/core/dist/contracts/tools/save-memory.js +25 -3
  49. package/vendor/core/dist/contracts/tools/search-memory.js +1 -1
  50. package/vendor/core/dist/credentials.d.ts +12 -0
  51. package/vendor/core/dist/credentials.js +1 -0
  52. package/vendor/core/dist/errors.js +2 -2
  53. package/vendor/core/dist/worker/auth.d.ts +5 -0
  54. package/vendor/core/dist/worker/auth.js +15 -4
  55. package/vendor/core/package.json +1 -1
  56. package/vendor/postgres/cf/src/connection.js +7 -2
  57. package/vendor/postgres/cjs/src/connection.js +7 -2
  58. package/vendor/postgres/src/connection.js +7 -2
  59. package/vendor/views/dist/native.d.ts +33 -1
  60. package/vendor/views/dist/native.js +3 -0
  61. package/vendor/views/package.json +1 -1
  62. /package/vendor/postgres/{.bun-tag-c81dacd34e959a7a → .bun-tag-652f2580b8090d71} +0 -0
@@ -58,6 +58,7 @@ export type { FileDelta, FileSystemSource, Snapshot } from './file-source.js';
58
58
  export { connect } from './net.js';
59
59
  export type { ConnectFn, Socket, SocketAddress, SocketOptions, } from './net.js';
60
60
  export { assertFeedReadWindow, validateFeedReadWindow } from './feed-read-window.js';
61
+ export { SourceWithheldError } from './source-withheld-error.js';
61
62
  export { isSecretOutputKey, redactOutput } from './redact.js';
62
63
  export { scrubDiagnosticValue } from '@lobu/core/diagnostic-scrubber';
63
64
  //# sourceMappingURL=index.d.ts.map
@@ -46,6 +46,7 @@ export { extensionNetworkSync } from './extension-network.js';
46
46
  // =============================================================================
47
47
  export { connect } from './net.js';
48
48
  export { assertFeedReadWindow, validateFeedReadWindow } from './feed-read-window.js';
49
+ export { SourceWithheldError } from './source-withheld-error.js';
49
50
  // The worker's output redaction catalog, shared so a connector that returns
50
51
  // third-party text (logs, messages) can scrub it with the same patterns.
51
52
  export { isSecretOutputKey, redactOutput } from './redact.js';
@@ -21,7 +21,7 @@
21
21
  * Keeping the classifier here rather than in each consumer is deliberate:
22
22
  * `@lobu/connector-sdk` is the only package every consumer can import (the
23
23
  * server package is not reachable from a bundled connector, and `@lobu/core`
24
- * pulls OpenTelemetry, Sentry, and winston, which connectors intentionally
24
+ * pulls OpenTelemetry and winston, which connectors intentionally
25
25
  * avoid).
26
26
  *
27
27
  * The matcher collapses the spellings an attacker can use to dress up an
@@ -21,7 +21,7 @@
21
21
  * Keeping the classifier here rather than in each consumer is deliberate:
22
22
  * `@lobu/connector-sdk` is the only package every consumer can import (the
23
23
  * server package is not reachable from a bundled connector, and `@lobu/core`
24
- * pulls OpenTelemetry, Sentry, and winston, which connectors intentionally
24
+ * pulls OpenTelemetry and winston, which connectors intentionally
25
25
  * avoid).
26
26
  *
27
27
  * The matcher collapses the spellings an attacker can use to dress up an
@@ -2,7 +2,7 @@
2
2
  * SDK logger.
3
3
  *
4
4
  * Deliberately self-contained. The package root must stay loadable inside a
5
- * V8 isolate, and `@lobu/core`'s root entry pulls winston, Sentry and
5
+ * V8 isolate, and `@lobu/core`'s root entry pulls winston and
6
6
  * OpenTelemetry into every connector bundle — 6 MB of gateway internals whose
7
7
  * first `require('util')` throws where no Node runtime exists (guarded by
8
8
  * `packages/server/src/__tests__/integration/sandbox/connector-isolate-lane.test.ts`).
@@ -2,7 +2,7 @@
2
2
  * SDK logger.
3
3
  *
4
4
  * Deliberately self-contained. The package root must stay loadable inside a
5
- * V8 isolate, and `@lobu/core`'s root entry pulls winston, Sentry and
5
+ * V8 isolate, and `@lobu/core`'s root entry pulls winston and
6
6
  * OpenTelemetry into every connector bundle — 6 MB of gateway internals whose
7
7
  * first `require('util')` throws where no Node runtime exists (guarded by
8
8
  * `packages/server/src/__tests__/integration/sandbox/connector-isolate-lane.test.ts`).
@@ -17,7 +17,7 @@ import type { ConnectionListInput } from "@lobu/core/contracts/tools/manage-conn
17
17
  import type { EntityCreateInput, EntityCreateResult, EntityDeleteInput, EntityDeleteResult, EntityDiscoverDuplicatesInput, EntityDiscoverDuplicatesResult, EntityGetInput, EntityGetResult, EntityLinkInput, EntityLinkResult, EntityListInput, EntityListResult, EntityListLinksInput, EntityListLinksResult, EntityUnlinkInput, EntityUnlinkResult, EntityUpdateInput, EntityUpdateResult, EntityUpdateLinkInput, EntityUpdateLinkResult } from "@lobu/core/contracts/tools/manage-entity";
18
18
  import type { OperationExecuteInput, OperationListAvailableInput, OperationListRunsInput } from "@lobu/core/contracts/tools/manage-operations";
19
19
  import type { PublicGetContentArgs } from "@lobu/core/contracts/tools/read-knowledge";
20
- import type { SaveContentInput } from "@lobu/core/contracts/tools/save-memory";
20
+ import type { SaveContentInput, UnlinkedEntityName } from "@lobu/core/contracts/tools/save-memory";
21
21
  import type { PublicSearchArgs } from "@lobu/core/contracts/tools/search-memory";
22
22
  /**
23
23
  * A rich card for chat delivery, as a plain serializable object — a `chat`
@@ -58,6 +58,8 @@ export interface KnowledgeSaveResult {
58
58
  id: number;
59
59
  created: boolean;
60
60
  metadata: Record<string, unknown>;
61
+ /** `{ name }` entries from `entity_ids` that did not link. */
62
+ unlinked: UnlinkedEntityName[];
61
63
  }
62
64
  export interface NotificationsSendInput {
63
65
  /** Notification title (≤200 chars). */
@@ -9,7 +9,7 @@
9
9
  * 503.
10
10
  *
11
11
  * The backoff loop lives here rather than being imported from `@lobu/core`:
12
- * core's root entry drags winston, Sentry and OpenTelemetry into every
12
+ * core's root entry drags winston and OpenTelemetry into every
13
13
  * connector bundle, and the package root must stay loadable inside a V8
14
14
  * isolate. It keeps the semantics of core's `retryWithBackoff` for the one
15
15
  * configuration `withHttpRetry` uses: exponential, capped, full jitter.
@@ -9,7 +9,7 @@
9
9
  * 503.
10
10
  *
11
11
  * The backoff loop lives here rather than being imported from `@lobu/core`:
12
- * core's root entry drags winston, Sentry and OpenTelemetry into every
12
+ * core's root entry drags winston and OpenTelemetry into every
13
13
  * connector bundle, and the package root must stay loadable inside a V8
14
14
  * isolate. It keeps the semantics of core's `retryWithBackoff` for the one
15
15
  * configuration `withHttpRetry` uses: exponential, capped, full jitter.
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Thrown from a feed `read` when the source deliberately withholds the
3
+ * requested record (for example, a private person's communications). The read
4
+ * is reported as withheld rather than failed: the caller is told the reason,
5
+ * nothing is retried, and pagination continues past it.
6
+ *
7
+ * The platform keys on the error's own `code === 'withheld'`, never on this
8
+ * class, so a connector on an older SDK opts in with
9
+ * `Object.assign(new Error(reason), { code: 'withheld' })`. The message is the
10
+ * human reason shown to the user.
11
+ */
12
+ export declare class SourceWithheldError extends Error {
13
+ readonly code: "withheld";
14
+ constructor(reason: string);
15
+ }
16
+ //# sourceMappingURL=source-withheld-error.d.ts.map
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Thrown from a feed `read` when the source deliberately withholds the
3
+ * requested record (for example, a private person's communications). The read
4
+ * is reported as withheld rather than failed: the caller is told the reason,
5
+ * nothing is retried, and pagination continues past it.
6
+ *
7
+ * The platform keys on the error's own `code === 'withheld'`, never on this
8
+ * class, so a connector on an older SDK opts in with
9
+ * `Object.assign(new Error(reason), { code: 'withheld' })`. The message is the
10
+ * human reason shown to the user.
11
+ */
12
+ export class SourceWithheldError extends Error {
13
+ code = 'withheld';
14
+ constructor(reason) {
15
+ super(reason);
16
+ this.name = 'SourceWithheldError';
17
+ }
18
+ }
19
+ //# sourceMappingURL=source-withheld-error.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/connector-sdk",
3
- "version": "24.9.0",
3
+ "version": "24.10.0",
4
4
  "description": "Lobu memory SDK — build pluggable connectors for Lobu memory",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -13,4 +13,5 @@ export type { DaemonConfig } from './worker.js';
13
13
  export { startDaemon, WorkerDaemon } from './worker.js';
14
14
  export { resolveDaemonLaunchContext, resolveDaemonWorkerId, startDaemonCommand, type DaemonStartOptions, } from './start.js';
15
15
  export { executeClaimedAutomationRun, UnexecutableRunError } from './execute-run.js';
16
+ export { completeSyncOnce } from './terminal-delivery.js';
16
17
  //# sourceMappingURL=index.d.ts.map
@@ -10,4 +10,5 @@ export { executeRun } from './executor.js';
10
10
  export { startDaemon, WorkerDaemon } from './worker.js';
11
11
  export { resolveDaemonLaunchContext, resolveDaemonWorkerId, startDaemonCommand, } from './start.js';
12
12
  export { executeClaimedAutomationRun, UnexecutableRunError } from './execute-run.js';
13
+ export { completeSyncOnce } from './terminal-delivery.js';
13
14
  //# sourceMappingURL=index.js.map
@@ -1,10 +1,20 @@
1
1
  import type { CompleteAgentTurnRequest, CompleteAgentTurnResponse, ExecutorClient } from './client.js';
2
+ interface TerminalDeliveryPolicy {
3
+ deadlineMs: number;
4
+ attempts: number;
5
+ /** Pause before retry N (0-based), doubled each time; 0 retries at once. */
6
+ backoffMs: number;
7
+ retriable: (error: unknown) => boolean;
8
+ }
9
+ /** Compresses a sync/action delivery budget; tests pass this to keep backoff fast. */
10
+ type DeliveryTiming = Partial<Pick<TerminalDeliveryPolicy, 'deadlineMs' | 'backoffMs'>>;
2
11
  /**
3
12
  * A delivery failure's retry classification: HTTP 5xx/429 and transport errors
4
13
  * are retriable; an explicit decode failure or any other 4xx is not.
5
14
  */
6
15
  export declare function isRetriableDeliveryFailure(err: unknown): boolean;
7
- export declare function completeSyncOnce(client: ExecutorClient, payload: Parameters<ExecutorClient['complete']>[0]): Promise<void>;
8
- export declare function completeActionOnce(client: ExecutorClient, payload: Parameters<ExecutorClient['completeAction']>[0]): Promise<void>;
16
+ export declare function completeSyncOnce(client: ExecutorClient, payload: Parameters<ExecutorClient['complete']>[0], timing?: DeliveryTiming): Promise<void>;
17
+ export declare function completeActionOnce(client: ExecutorClient, payload: Parameters<ExecutorClient['completeAction']>[0], timing?: DeliveryTiming): Promise<void>;
9
18
  export declare function completeAgentTurnOnce(client: ExecutorClient, payload: CompleteAgentTurnRequest): Promise<CompleteAgentTurnResponse>;
19
+ export {};
10
20
  //# sourceMappingURL=terminal-delivery.d.ts.map
@@ -1,16 +1,23 @@
1
1
  /**
2
2
  * Bounded delivery of an immutable terminal outcome. Execution and failure
3
- * reporting share the retry loop; sync/action and agent-turn budgets differ.
4
- * WorkerDecodeError identifies an unreadable response, not an execution
5
- * failure, and is surfaced without retrying.
3
+ * reporting share the retry loop and its classification; sync/action and
4
+ * agent-turn budgets differ. WorkerDecodeError identifies an unreadable
5
+ * response, not an execution failure, and is surfaced without retrying.
6
6
  */
7
7
  import { WorkerDecodeError, WorkerHttpError } from './client.js';
8
- /** Syncs/actions: two attempts in 15s, anything but an undecodable answer retried. */
8
+ /**
9
+ * Syncs/actions ride out a gateway rollout: a dying replica answers 5xx or
10
+ * drops the connection, and an immediate retry would reach the same one. Six
11
+ * attempts back off 1s, 2s, 4s, 8s, 16s, all inside 90s -- the reaper writes
12
+ * a run off 120s after its last heartbeat, and the executor stops heartbeating
13
+ * up to 30s before delivery starts. A 4xx other than 429 is the gateway's
14
+ * answer and is not re-sent.
15
+ */
9
16
  const ACTION_DELIVERY = {
10
- deadlineMs: 15_000,
11
- attempts: 2,
12
- backoffMs: 0,
13
- retriable: (error) => !(error instanceof WorkerDecodeError),
17
+ deadlineMs: 90_000,
18
+ attempts: 6,
19
+ backoffMs: 1_000,
20
+ retriable: isRetriableDeliveryFailure,
14
21
  };
15
22
  /**
16
23
  * Agent turns retry transient delivery failures across a short gateway outage.
@@ -89,11 +96,11 @@ async function deliverTerminal(send, policy) {
89
96
  }
90
97
  throw lastError instanceof Error ? lastError : new Error(String(lastError));
91
98
  }
92
- export async function completeSyncOnce(client, payload) {
93
- await deliverTerminal(() => client.complete(payload), ACTION_DELIVERY);
99
+ export async function completeSyncOnce(client, payload, timing = {}) {
100
+ await deliverTerminal(() => client.complete(payload), { ...ACTION_DELIVERY, ...timing });
94
101
  }
95
- export async function completeActionOnce(client, payload) {
96
- await deliverTerminal(() => client.completeAction(payload), ACTION_DELIVERY);
102
+ export async function completeActionOnce(client, payload, timing = {}) {
103
+ await deliverTerminal(() => client.completeAction(payload), { ...ACTION_DELIVERY, ...timing });
97
104
  }
98
105
  export function completeAgentTurnOnce(client, payload) {
99
106
  return deliverTerminal(() => client.completeAgentTurn(payload), AGENT_TURN_DELIVERY);
@@ -238,12 +238,20 @@ export interface SyncExecutor {
238
238
  execute(compiledCode: string, job: ExecutorJob, hooks?: ExecutionHooks): Promise<ExecutorResult>;
239
239
  }
240
240
  export type ConnectorExitReason = 'ok' | 'error_message' | 'timeout' | 'oom' | 'crash';
241
+ /**
242
+ * A structured outcome the connector itself declared on the error it threw.
243
+ * `withheld`: the source deliberately withholds the record (SourceWithheldError).
244
+ */
245
+ export type ConnectorErrorCode = 'withheld';
241
246
  export interface ConnectorExecutionDiagnostics {
242
247
  exitCode: number | null;
243
248
  exitSignal: string | null;
244
249
  outputTail: string;
245
250
  exitReason: ConnectorExitReason;
246
251
  httpStatus?: number;
252
+ /** Validated PostgreSQL SQLSTATE; distinct from connector outcome codes. */
253
+ pgCode?: string;
254
+ code?: ConnectorErrorCode;
247
255
  }
248
256
  export declare class ConnectorExecutionError extends Error implements ConnectorExecutionDiagnostics {
249
257
  exitCode: number | null;
@@ -251,6 +259,8 @@ export declare class ConnectorExecutionError extends Error implements ConnectorE
251
259
  outputTail: string;
252
260
  exitReason: ConnectorExitReason;
253
261
  httpStatus?: number;
262
+ pgCode?: string;
263
+ code?: ConnectorErrorCode;
254
264
  constructor(message: string, diagnostics: ConnectorExecutionDiagnostics, options?: {
255
265
  cause?: unknown;
256
266
  });
@@ -4,6 +4,8 @@ export class ConnectorExecutionError extends Error {
4
4
  outputTail;
5
5
  exitReason;
6
6
  httpStatus;
7
+ pgCode;
8
+ code;
7
9
  constructor(message, diagnostics, options) {
8
10
  super(message, options);
9
11
  this.name = 'ConnectorExecutionError';
@@ -12,6 +14,10 @@ export class ConnectorExecutionError extends Error {
12
14
  this.outputTail = diagnostics.outputTail;
13
15
  this.exitReason = diagnostics.exitReason;
14
16
  this.httpStatus = diagnostics.httpStatus;
17
+ if (diagnostics.pgCode)
18
+ this.pgCode = diagnostics.pgCode;
19
+ if (diagnostics.code)
20
+ this.code = diagnostics.code;
15
21
  }
16
22
  }
17
23
  /** Per-stream ring buffer that preserves the most recent bytes. */
@@ -83,6 +83,7 @@ export declare class IsolateExecutor implements SyncExecutor {
83
83
  private assertHostAllowed;
84
84
  private requireIsolatedVm;
85
85
  execute(compiledCode: string, job: ExecutorJob, hooks?: ExecutionHooks): Promise<ExecutorResult>;
86
+ private executeInIsolate;
86
87
  /** Build the `ConnectorExecutionError` the daemon reports for a guest-thrown error. */
87
88
  private guestError;
88
89
  private hostFetch;
@@ -62,6 +62,8 @@ const MAX_REDIRECTS = 20;
62
62
  * reads; an honest connector drains or cancels every body it opens.
63
63
  */
64
64
  const MAX_OPEN_FETCHES = 1024;
65
+ /** Rejects a host hook that was still queued when the run ended; never a run's failure. */
66
+ const SKIPPED_HOOK = new Error('the run ended before this hook started');
65
67
  /** Thrown when a job demands the isolate lane on a host that cannot run one. */
66
68
  export class IsolateRuntimeUnavailableError extends Error {
67
69
  constructor(reason) {
@@ -477,13 +479,44 @@ export class IsolateExecutor {
477
479
  return ivm;
478
480
  }
479
481
  async execute(compiledCode, job, hooks) {
482
+ const tail = new RingBuffer(STREAM_TAIL_CAP_BYTES);
483
+ if (this.options.timeoutMs === 0)
484
+ return this.executeInIsolate(compiledCode, job, hooks, tail);
485
+ // The budget belongs to the whole run, including native context setup.
486
+ // Race setup too: merely subtracting its duration would still leave a
487
+ // caller waiting indefinitely before the guest's timer could start.
488
+ const timeoutAbort = new AbortController();
489
+ const signal = hooks?.signal
490
+ ? AbortSignal.any([hooks.signal, timeoutAbort.signal])
491
+ : timeoutAbort.signal;
492
+ let timer;
493
+ const timeout = new Promise((_resolve, reject) => {
494
+ timer = setTimeout(() => {
495
+ const outputTail = redactOutput(tail.toString());
496
+ reject(new ConnectorExecutionError(`Execution timed out after ${this.options.timeoutMs}ms${outputTail ? `\n[console]\n${outputTail}` : ''}`, { exitCode: null, exitSignal: null, outputTail, exitReason: 'timeout' }));
497
+ // An in-flight host is terminated immediately. If setup resolves
498
+ // later, executeInIsolate's cancellation latch disposes it before
499
+ // handing it any guest code.
500
+ timeoutAbort.abort();
501
+ }, this.options.timeoutMs);
502
+ });
503
+ try {
504
+ return await Promise.race([
505
+ this.executeInIsolate(compiledCode, job, { ...hooks, signal }, tail),
506
+ timeout,
507
+ ]);
508
+ }
509
+ finally {
510
+ clearTimeout(timer);
511
+ }
512
+ }
513
+ async executeInIsolate(compiledCode, job, hooks, tail) {
480
514
  if (job.httpAuth && !hooks?.onHttpFetch) {
481
515
  throw new Error('HTTP authentication requires a gateway fetch hook');
482
516
  }
483
517
  assertIsolateEligible(compiledCode);
484
518
  const exemptHosts = [...this.exactAllowedHosts, ...operatorHttpExemptHosts(job)];
485
519
  const ivm = await this.requireIsolatedVm();
486
- const tail = new RingBuffer(STREAM_TAIL_CAP_BYTES);
487
520
  let logBytesUsed = 0;
488
521
  let logTruncated = false;
489
522
  let hookFailure = null;
@@ -561,7 +594,11 @@ export class IsolateExecutor {
561
594
  }
562
595
  });
563
596
  };
597
+ // The first state that ended the run. A run can end after the guest
598
+ // returned, while its hooks drain; that run did not complete.
599
+ let endedWith = null;
564
600
  const terminate = (state) => {
601
+ endedWith ??= state;
565
602
  runAbort.abort();
566
603
  for (const timer of pendingSleeps)
567
604
  clearTimeout(timer);
@@ -592,12 +629,21 @@ export class IsolateExecutor {
592
629
  hooks?.signal?.addEventListener('abort', onCancel, { once: true });
593
630
  const queueHook = (task) => {
594
631
  const next = processingChain.then(async () => {
632
+ // A hook queued behind one that outlived the run must not start: the
633
+ // run already has its terminal state, so any side effect now would
634
+ // land for a run reported as failed.
635
+ if (runAbort.signal.aborted)
636
+ throw SKIPPED_HOOK;
595
637
  await task();
596
638
  });
597
639
  // Keep the chain alive after a failure so later calls still see the
598
640
  // terminal state instead of re-running against a torn-down host.
599
641
  processingChain = next.catch(() => undefined);
600
642
  next.catch((error) => {
643
+ // A skipped hook is a consequence of the run's end, not its cause:
644
+ // the original failure keeps its name, status and diagnostics.
645
+ if (error === SKIPPED_HOOK)
646
+ return;
601
647
  if (hookFailure === null)
602
648
  hookFailure = error;
603
649
  terminate({ name: 'HookFailure', message: error instanceof Error ? error.message : String(error) });
@@ -705,7 +751,7 @@ export class IsolateExecutor {
705
751
  return { data: chunk.value, done: false };
706
752
  };
707
753
  const mergedConfig = job.mode === 'authenticate' ? job.config : buildConnectorConfig(job);
708
- host = await IsolateHost.create({
754
+ const createHost = () => IsolateHost.create({
709
755
  ivm,
710
756
  memoryMb: this.options.memoryMb,
711
757
  messageBytes: this.options.messageBytes,
@@ -1031,12 +1077,13 @@ export class IsolateExecutor {
1031
1077
  },
1032
1078
  },
1033
1079
  });
1034
- const redactedTail = () => redactOutput(tail.toString());
1035
- const withTail = (prefix) => {
1036
- const t = redactedTail();
1037
- return t ? `${prefix}\n[console]\n${t}` : prefix;
1038
- };
1039
1080
  try {
1081
+ host = await createHost();
1082
+ const redactedTail = () => redactOutput(tail.toString());
1083
+ const withTail = (prefix) => {
1084
+ const t = redactedTail();
1085
+ return t ? `${prefix}\n[console]\n${t}` : prefix;
1086
+ };
1040
1087
  const source = `var __job_json = ${jsonLiteral(guestJob)};\nvar __config_json = ${jsonLiteral(mergedConfig)};\n${compiledCode}\n${GUEST_RUNNER}`;
1041
1088
  let raw;
1042
1089
  try {
@@ -1047,7 +1094,9 @@ export class IsolateExecutor {
1047
1094
  // reports through exactly the path a mid-run cancel takes.
1048
1095
  if (cancelled || hooks?.signal?.aborted)
1049
1096
  host.terminate(cancelState);
1050
- raw = await host.run(source, { timeoutMs: this.options.timeoutMs });
1097
+ // execute owns the single deadline from entry, including setup and
1098
+ // outstanding hooks; a second guest timer would restart the budget.
1099
+ raw = await host.run(source, { timeoutMs: 0 });
1051
1100
  }
1052
1101
  catch (error) {
1053
1102
  if (hookFailure !== null)
@@ -1055,19 +1104,6 @@ export class IsolateExecutor {
1055
1104
  if (guestFatal)
1056
1105
  throw this.guestError(guestFatal, redactedTail());
1057
1106
  if (error instanceof IsolateHostError) {
1058
- if (error.kind === 'timeout') {
1059
- // Not "Feed execution": this executor runs feeds, connector
1060
- // actions AND agent turns, and a chat user whose turn timed out
1061
- // was being told a feed had failed. The classifier maps both
1062
- // spellings (classify-error.ts) so a mid-rollout worker still
1063
- // classifies.
1064
- throw new ConnectorExecutionError(withTail(`Execution timed out after ${this.options.timeoutMs}ms`), {
1065
- exitCode: null,
1066
- exitSignal: null,
1067
- outputTail: redactedTail(),
1068
- exitReason: 'timeout',
1069
- });
1070
- }
1071
1107
  if (error.kind === 'memory') {
1072
1108
  throw new ConnectorExecutionError(withTail(`Isolate out of memory (limit ${this.options.memoryMb} MB)`), {
1073
1109
  exitCode: null,
@@ -1087,10 +1123,31 @@ export class IsolateExecutor {
1087
1123
  throw this.guestError(error instanceof Error ? { name: error.name, message: error.message, stack: error.stack } : { message: String(error) }, redactedTail());
1088
1124
  }
1089
1125
  // Wait for hooks the guest fired without awaiting (or whose promise the
1090
- // guest dropped) before reporting the result.
1091
- await processingChain;
1126
+ // guest dropped) before reporting the result. A hook fired just before
1127
+ // the guest returned can join the chain after this wait begins, so wait
1128
+ // until the chain stops growing.
1129
+ let drained;
1130
+ do {
1131
+ drained = processingChain;
1132
+ await drained;
1133
+ } while (drained !== processingChain);
1092
1134
  if (hookFailure !== null)
1093
1135
  throw hookFailure;
1136
+ // The guest returned, but the run ended (e.g. cancelled) while its hooks
1137
+ // drained, so some never ran or never reached the host: reporting
1138
+ // success would drop their side effects silently.
1139
+ // Assigned inside `terminate`, which TypeScript's narrowing cannot see.
1140
+ const ended = endedWith;
1141
+ if (ended) {
1142
+ if (guestFatal)
1143
+ throw this.guestError(guestFatal, redactedTail());
1144
+ throw new ConnectorExecutionError(withTail(ended.message), {
1145
+ exitCode: null,
1146
+ exitSignal: null,
1147
+ outputTail: redactedTail(),
1148
+ exitReason: 'crash',
1149
+ });
1150
+ }
1094
1151
  const outcome = parseGuestJson(raw, 'result');
1095
1152
  if (!outcome || typeof outcome !== 'object' || typeof outcome.ok !== 'boolean') {
1096
1153
  throw new Error('result: guest returned a malformed outcome envelope');
@@ -1112,7 +1169,7 @@ export class IsolateExecutor {
1112
1169
  closeAllSockets();
1113
1170
  vault.clear();
1114
1171
  void egress.destroy().catch(() => undefined);
1115
- host.dispose();
1172
+ host?.dispose();
1116
1173
  }
1117
1174
  }
1118
1175
  /** Build the `ConnectorExecutionError` the daemon reports for a guest-thrown error. */
@@ -1126,6 +1183,10 @@ export class IsolateExecutor {
1126
1183
  httpStatus: typeof description.httpStatus === 'number' && description.httpStatus >= 100 && description.httpStatus < 600
1127
1184
  ? description.httpStatus
1128
1185
  : undefined,
1186
+ code: description.code === 'withheld' ? description.code : undefined,
1187
+ pgCode: typeof description.pgCode === 'string' && /^[0-9A-Z]{5}$/.test(description.pgCode) && !description.pgCode.startsWith('E')
1188
+ ? description.pgCode
1189
+ : undefined,
1129
1190
  });
1130
1191
  error.name = description.name ? redactOutput(String(description.name)) : 'ConnectorExecutionError';
1131
1192
  if (description.stack)
@@ -303,6 +303,11 @@ var exports = module.exports;
303
303
  if (error instanceof Error) {
304
304
  var desc = { name: String(error.name || 'Error'), message: String(error.message), stack: typeof error.stack === 'string' ? error.stack : undefined };
305
305
  if (typeof error.status === 'number' && error.status >= 100 && error.status < 600) desc.httpStatus = error.status;
306
+ // A deliberately withheld source read (SourceWithheldError, or any error
307
+ // whose own code is 'withheld'). SQLSTATE travels separately so it cannot
308
+ // be mistaken for a connector outcome. Ambiguous E-prefixed errnos stay opaque.
309
+ if (Object.prototype.hasOwnProperty.call(error, 'code') && error.code === 'withheld') desc.code = 'withheld';
310
+ if (Object.prototype.hasOwnProperty.call(error, 'code') && typeof error.code === 'string' && /^[0-9A-Z]{5}$/.test(error.code) && error.code.charAt(0) !== 'E') desc.pgCode = error.code;
306
311
  return desc;
307
312
  }
308
313
  var text;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/connector-worker",
3
- "version": "24.9.0",
3
+ "version": "24.10.0",
4
4
  "description": "Self-hosted worker for Lobu memory — connectors and embedding generation",
5
5
  "type": "module",
6
6
  "bin": {
@@ -10,7 +10,7 @@
10
10
  * agent as `agent_error`.
11
11
  * - `response-renderer.ts` and `chat-response-bridge.ts` resolve the code to
12
12
  * a remediation CTA; with none, the user gets the provider's raw prose.
13
- * - An unclassified failure also misses the `PROVIDER_*` Sentry alerting.
13
+ * - An unclassified failure also misses the `PROVIDER_*` error alerting.
14
14
  *
15
15
  * Adding a failure mode = one pattern here + one entry in `AGENT_ERRORS`.
16
16
  *
@@ -11,7 +11,7 @@
11
11
  * agent as `agent_error`.
12
12
  * - `response-renderer.ts` and `chat-response-bridge.ts` resolve the code to
13
13
  * a remediation CTA; with none, the user gets the provider's raw prose.
14
- * - An unclassified failure also misses the `PROVIDER_*` Sentry alerting.
14
+ * - An unclassified failure also misses the `PROVIDER_*` error alerting.
15
15
  *
16
16
  * Adding a failure mode = one pattern here + one entry in `AGENT_ERRORS`.
17
17
  *
@@ -115,7 +115,7 @@ function classifyErrorMessage(message) {
115
115
  // (code no_credentials) when every credential tier misses. The live red-test
116
116
  // (LOBU-BACKEND-W) landed as `unclassified` because the auth-hint regex
117
117
  // doesn't cover this shape — and an unclassified event dodges the
118
- // PROVIDER_* Sentry alert.
118
+ // PROVIDER_* alert.
119
119
  if (/no\s+(provider\s+)?credentials\s+configured|no_credentials/i.test(message))
120
120
  return errors_js_1.AgentErrorCode.PROVIDER_AUTH;
121
121
  // The provider accepted the credential but refuses to USE it: Anthropic 403s
@@ -417,9 +417,17 @@ export declare const AutomationClaimNextWindowContextSchema: import("@sinclair/t
417
417
  }>>;
418
418
  }>;
419
419
  export type AutomationClaimNextWindowContext = Static<typeof AutomationClaimNextWindowContextSchema>;
420
- export declare const AutomationClaimNextWindowResultSchema: import("@sinclair/typebox").TObject<{
420
+ /**
421
+ * A claim either leases a window (`claimed`, with context to process and a
422
+ * window_token for completeWindow) or reports that the due window had no new
423
+ * or changed source content and was already booked as a no-op run
424
+ * (`completed`). A completed receipt needs no completeWindow: the schedule
425
+ * has advanced, so refresh activity for the next due window.
426
+ */
427
+ export declare const AutomationClaimNextWindowResultSchema: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
421
428
  action: import("@sinclair/typebox").TLiteral<"claim_next_window">;
422
429
  automation_id: import("@sinclair/typebox").TString;
430
+ status: import("@sinclair/typebox").TLiteral<"claimed">;
423
431
  run_id: import("@sinclair/typebox").TInteger;
424
432
  lease_expires_at: import("@sinclair/typebox").TString;
425
433
  context: import("@sinclair/typebox").TObject<{
@@ -460,7 +468,15 @@ export declare const AutomationClaimNextWindowResultSchema: import("@sinclair/ty
460
468
  }>>;
461
469
  }>>;
462
470
  }>;
463
- }>;
471
+ }>, import("@sinclair/typebox").TObject<{
472
+ action: import("@sinclair/typebox").TLiteral<"claim_next_window">;
473
+ automation_id: import("@sinclair/typebox").TString;
474
+ status: import("@sinclair/typebox").TLiteral<"completed">;
475
+ run_id: import("@sinclair/typebox").TInteger;
476
+ skipped_unchanged: import("@sinclair/typebox").TLiteral<true>;
477
+ window_start: import("@sinclair/typebox").TString;
478
+ window_end: import("@sinclair/typebox").TString;
479
+ }>]>;
464
480
  export type AutomationClaimNextWindowResult = Static<typeof AutomationClaimNextWindowResultSchema>;
465
481
  export declare const AutomationTriggerExecutionSchema: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
466
482
  lane: import("@sinclair/typebox").TLiteral<"managed_agent">;
@@ -596,9 +612,10 @@ export declare const ManageAutomationsResultSchema: import("@sinclair/typebox").
596
612
  window_start: import("@sinclair/typebox").TString;
597
613
  window_end: import("@sinclair/typebox").TString;
598
614
  content_linked: import("@sinclair/typebox").TInteger;
599
- }>, import("@sinclair/typebox").TObject<{
615
+ }>, import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
600
616
  action: import("@sinclair/typebox").TLiteral<"claim_next_window">;
601
617
  automation_id: import("@sinclair/typebox").TString;
618
+ status: import("@sinclair/typebox").TLiteral<"claimed">;
602
619
  run_id: import("@sinclair/typebox").TInteger;
603
620
  lease_expires_at: import("@sinclair/typebox").TString;
604
621
  context: import("@sinclair/typebox").TObject<{
@@ -640,6 +657,14 @@ export declare const ManageAutomationsResultSchema: import("@sinclair/typebox").
640
657
  }>>;
641
658
  }>;
642
659
  }>, import("@sinclair/typebox").TObject<{
660
+ action: import("@sinclair/typebox").TLiteral<"claim_next_window">;
661
+ automation_id: import("@sinclair/typebox").TString;
662
+ status: import("@sinclair/typebox").TLiteral<"completed">;
663
+ run_id: import("@sinclair/typebox").TInteger;
664
+ skipped_unchanged: import("@sinclair/typebox").TLiteral<true>;
665
+ window_start: import("@sinclair/typebox").TString;
666
+ window_end: import("@sinclair/typebox").TString;
667
+ }>]>, import("@sinclair/typebox").TObject<{
643
668
  action: import("@sinclair/typebox").TLiteral<"trigger">;
644
669
  automation_id: import("@sinclair/typebox").TString;
645
670
  run_id: import("@sinclair/typebox").TInteger;