@opengeni/worker-bundle 1.0.1 → 2.0.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 (122) hide show
  1. package/dist/activities/agent-turn/codex.d.ts +1 -1
  2. package/dist/activities/agent-turn/compaction-prep.d.ts +1 -5
  3. package/dist/activities/agent-turn/errors.d.ts +31 -5
  4. package/dist/activities/agent-turn/finalization-monitor.d.ts +17 -0
  5. package/dist/activities/agent-turn/finalization.d.ts +1 -1
  6. package/dist/activities/agent-turn/governance-model.d.ts +0 -2
  7. package/dist/activities/agent-turn/quiescence.d.ts +1 -0
  8. package/dist/activities/agent-turn/recovery-warning.d.ts +8 -0
  9. package/dist/activities/agent-turn/run-credentials.d.ts +0 -1
  10. package/dist/activities/agent-turn/sandbox-establish.d.ts +1 -1
  11. package/dist/activities/agent-turn/sandbox-route.d.ts +0 -20
  12. package/dist/activities/agent-turn/sandbox-runtime.d.ts +1 -1
  13. package/dist/activities/agent-turn/skill-remove.d.ts +14 -0
  14. package/dist/activities/agent-turn/skill-search.d.ts +1 -1
  15. package/dist/activities/agent-turn/stream-attempt.d.ts +1 -0
  16. package/dist/activities/agent-turn/tool-environment.d.ts +0 -4
  17. package/dist/activities/agent-turn/turn-context.d.ts +2 -0
  18. package/dist/activities/agent-turn/turn-sandbox-access.d.ts +3 -0
  19. package/dist/activities/codex-capacity.d.ts +6 -1
  20. package/dist/activities/codex-rotation.d.ts +1 -1
  21. package/dist/activities/context-compaction.d.ts +7 -1
  22. package/dist/activities/mcp-account-routes.d.ts +22 -0
  23. package/dist/activities/mcp-credentials.d.ts +12 -13
  24. package/dist/activities/mcp-operation-authority.d.ts +0 -5
  25. package/dist/activities/rig-verification.d.ts +2 -3
  26. package/dist/activities/sandbox-images.d.ts +1 -1
  27. package/dist/activities/sandbox-lease.d.ts +4 -3
  28. package/dist/activities/session-state.d.ts +57 -2
  29. package/dist/activities/types.d.ts +12 -3
  30. package/dist/{activities-control-HMFGSKC5.js → activities-control-BOLIY3H4.js} +366 -187
  31. package/dist/activities-control-BOLIY3H4.js.map +1 -0
  32. package/dist/activities-control.d.ts +110 -2
  33. package/dist/{activities-turn-AP67JADS.js → activities-turn-2B3WMHBB.js} +767 -471
  34. package/dist/activities-turn-2B3WMHBB.js.map +1 -0
  35. package/dist/activities.d.ts +110 -2
  36. package/dist/artifact-materializer-entry.js +5 -2
  37. package/dist/artifact-materializer-entry.js.map +1 -1
  38. package/dist/artifact-outbox-entry.js +2 -2
  39. package/dist/artifact-outbox-entry.js.map +1 -1
  40. package/dist/{chunk-A4XQWVZK.js → chunk-I7HKKMUJ.js} +77 -1
  41. package/dist/chunk-I7HKKMUJ.js.map +1 -0
  42. package/dist/{chunk-CYITU5UH.js → chunk-TVEE2UUC.js} +275 -146
  43. package/dist/chunk-TVEE2UUC.js.map +1 -0
  44. package/dist/editable-artifact-materializer-service.d.ts +2 -2
  45. package/dist/editable-artifact-outbox-service.d.ts +2 -2
  46. package/dist/index.d.ts +55 -1
  47. package/dist/index.js +4 -3
  48. package/dist/index.js.map +1 -1
  49. package/dist/observability-metrics.d.ts +11 -3
  50. package/dist/retained-process-diagnostics.d.ts +4 -0
  51. package/dist/sandbox-resume.d.ts +2 -12
  52. package/dist/sandbox-routing.d.ts +5 -3
  53. package/dist/sandbox-snapshot-diagnostics.d.ts +20 -0
  54. package/dist/warm-capture-holder.d.ts +3 -0
  55. package/dist/workflow-bundle.js +51 -11
  56. package/package.json +15 -15
  57. package/src/activities/agent-turn/agent-build.ts +42 -5
  58. package/src/activities/agent-turn/claim.ts +12 -0
  59. package/src/activities/agent-turn/codex-capacity.ts +26 -4
  60. package/src/activities/agent-turn/codex.ts +6 -2
  61. package/src/activities/agent-turn/compaction-prep.ts +53 -72
  62. package/src/activities/agent-turn/errors.ts +98 -10
  63. package/src/activities/agent-turn/failure-settlement.ts +49 -28
  64. package/src/activities/agent-turn/finalization-monitor.ts +121 -0
  65. package/src/activities/agent-turn/finalization.ts +79 -21
  66. package/src/activities/agent-turn/governance-model.ts +15 -19
  67. package/src/activities/agent-turn/history.ts +24 -10
  68. package/src/activities/agent-turn/quiescence.ts +3 -0
  69. package/src/activities/agent-turn/recovery-warning.ts +18 -0
  70. package/src/activities/agent-turn/run-credentials.ts +3 -7
  71. package/src/activities/agent-turn/run.ts +68 -52
  72. package/src/activities/agent-turn/sandbox-establish.ts +10 -2
  73. package/src/activities/agent-turn/sandbox-route.ts +0 -20
  74. package/src/activities/agent-turn/sandbox-runtime.ts +40 -7
  75. package/src/activities/agent-turn/skill-remove.ts +46 -0
  76. package/src/activities/agent-turn/skill-save.ts +1 -1
  77. package/src/activities/agent-turn/skill-search.ts +1 -1
  78. package/src/activities/agent-turn/skill-selection.ts +2 -0
  79. package/src/activities/agent-turn/skill-tools.ts +10 -5
  80. package/src/activities/agent-turn/stream-attempt.ts +38 -15
  81. package/src/activities/agent-turn/tool-environment.ts +44 -29
  82. package/src/activities/agent-turn/turn-context.ts +3 -0
  83. package/src/activities/agent-turn/turn-sandbox-access.ts +7 -1
  84. package/src/activities/capabilities.ts +17 -2
  85. package/src/activities/codex-capacity.ts +38 -9
  86. package/src/activities/codex-rotation.ts +18 -5
  87. package/src/activities/context-compaction.ts +26 -4
  88. package/src/activities/goals.ts +1 -0
  89. package/src/activities/google-drive-publication.ts +1 -3
  90. package/src/activities/mcp-account-routes.ts +139 -0
  91. package/src/activities/mcp-credentials.ts +83 -194
  92. package/src/activities/mcp-operation-authority.ts +16 -41
  93. package/src/activities/parent-wake.ts +8 -0
  94. package/src/activities/rig-verification.ts +38 -37
  95. package/src/activities/run-input.ts +25 -16
  96. package/src/activities/sandbox-images.ts +0 -1
  97. package/src/activities/sandbox-lease.ts +177 -44
  98. package/src/activities/scheduled-tasks.ts +118 -93
  99. package/src/activities/session-state.ts +83 -3
  100. package/src/activities/types.ts +18 -2
  101. package/src/activities/workflow-wake.ts +2 -17
  102. package/src/editable-artifact-materializer-service.ts +7 -3
  103. package/src/editable-artifact-outbox-service.ts +4 -4
  104. package/src/github-rest-mcp.ts +0 -1
  105. package/src/index.ts +2 -1
  106. package/src/observability-metrics.ts +105 -2
  107. package/src/personal-github-git-credentials.ts +0 -1
  108. package/src/pr-review-credentials.ts +0 -2
  109. package/src/retained-process-diagnostics.ts +50 -0
  110. package/src/sandbox-resume.ts +58 -73
  111. package/src/sandbox-routing.ts +44 -19
  112. package/src/sandbox-snapshot-diagnostics.ts +112 -0
  113. package/src/warm-capture-holder.ts +15 -0
  114. package/src/workflows/session.ts +64 -2
  115. package/dist/activities/agent-turn/knowledge-sources.d.ts +0 -20
  116. package/dist/activities/packs.d.ts +0 -55
  117. package/dist/activities-control-HMFGSKC5.js.map +0 -1
  118. package/dist/activities-turn-AP67JADS.js.map +0 -1
  119. package/dist/chunk-A4XQWVZK.js.map +0 -1
  120. package/dist/chunk-CYITU5UH.js.map +0 -1
  121. package/src/activities/agent-turn/knowledge-sources.ts +0 -86
  122. package/src/activities/packs.ts +0 -166
@@ -4,7 +4,7 @@ import type { EventLogger } from "@opengeni/events";
4
4
  import type { Observability } from "@opengeni/observability";
5
5
  import type { CompanyBrainContributionReceipt } from "./model-context-contributions.js";
6
6
  import { type OpenSandboxKubernetesInventory } from "./opensandbox-kubernetes-inventory.js";
7
- import { type RuntimeMetricsHooks, type SelfhostedOpObservation, type SelfhostedOpObserver } from "@opengeni/runtime";
7
+ import { type RuntimeMetricsHooks, type SelfhostedOpObservation, type SelfhostedOpObserver, type ToolPreparationPhaseMeasurement } from "@opengeni/runtime";
8
8
  export type TurnOutcome = "completed" | "failed" | "cancelled" | "recovering";
9
9
  export type WorkerDeathRecoveryOutcome = "recovering" | "exhausted";
10
10
  export type CreditMicrosKind = "usage" | "grant" | "topup" | "refund";
@@ -220,7 +220,7 @@ export declare function recordModelRequestPhase(observability: Observability, in
220
220
  outcome?: "completed" | "failed" | "timed_out";
221
221
  durationSeconds: number;
222
222
  }): void;
223
- export type TurnStartupPhase = "claim_and_policy" | "turn_start_settlement" | "credential_selection" | "runtime_preparation" | "sandbox_establish" | "file_resolution" | "tool_context_preparation" | "tool_preparation" | "tool_server_construction" | "tool_required_connect" | "tool_optional_connect" | "tool_attempt_catalog_build" | "tool_attempt_catalog_persist" | "tool_workspace_gateway_catalog_build" | "post_tool_preparation" | "agent_construction" | "post_agent_preparation" | "file_materialization" | "history_preparation" | "history_system_update_load" | "history_current_attachment_resolution" | "history_durable_history_load" | "history_sandbox_envelope_load" | "history_canonical_projection" | "history_provider_projection" | "history_attachment_ref_projection" | "history_screenshot_materialization" | "history_model_attachment_projection" | "history_runtime_input_assembly" | "history_artifact_candidate_scan" | "history_generated_image_materialization" | "history_position_load" | "owned_sandbox_setup" | "provider_dispatch" | "model_request_preparation" | "model_sdk_serialization" | "model_prepare_sandbox_agent_preparation" | "model_prepare_sandbox_agent_manifest_inventory" | "model_prepare_sandbox_session_manifest_inventory" | "model_prepare_sandbox_manifest_apply" | "model_prepare_sandbox_entry_materialization" | "model_prepare_sandbox_running_check" | "model_prepare_sandbox_start" | "model_prepare_sandbox_client_create" | "model_prepare_sandbox_client_resume" | "model_prepare_sandbox_client_delete" | "model_prepare_sandbox_client_state_serialize" | "model_prepare_sandbox_client_reuse_check" | "model_prepare_sandbox_workspace_mutation_admission" | "model_prepare_sandbox_workspace_mutation_provider" | "model_prepare_sandbox_workspace_mutation_settlement" | "model_prepare_sandbox_first_routed_resolution_other" | "model_prepare_sandbox_first_routed_mutation_admission" | "model_prepare_sandbox_first_routed_provider_operation" | "model_prepare_sandbox_first_routed_mutation_settlement" | "model_prepare_sandbox_first_routed_other" | "model_prepare_sandbox_snapshot_wait" | "model_prepare_runner_before_first_sandbox_operation" | "model_prepare_sdk_after_first_sandbox_operation" | "model_prepare_runner_before_mcp_tools" | "model_prepare_mcp_tools_snapshot" | "model_prepare_mcp_tools_before_input_filter" | "model_prepare_mcp_tools_before_repository_skill_discovery" | "model_prepare_repository_skill_discovery" | "model_prepare_repository_skill_discovery_before_input_filter" | "model_prepare_input_filter_base" | "model_prepare_input_filter_genesis" | "model_prepare_input_filter_host" | "model_prepare_input_filter_tool_output" | "model_prepare_input_filter_modality" | "model_prepare_input_filter_context" | "model_prepare_responses_input_conversion" | "model_prepare_responses_request_build" | "model_credential_resolution" | "model_wire_normalization" | "model_request_audit" | "stream_bootstrap";
223
+ export type TurnStartupPhase = "claim_and_policy" | "turn_start_settlement" | "credential_selection" | "runtime_preparation" | "sandbox_establish" | "file_resolution" | "tool_context_preparation" | "tool_preparation" | "tool_server_construction" | "tool_required_connect" | "tool_optional_connect" | "tool_attempt_catalog_build" | "tool_attempt_catalog_persist" | "tool_workspace_gateway_catalog_build" | "post_tool_preparation" | "agent_construction" | "post_agent_preparation" | "file_materialization" | "history_preparation" | "history_system_update_load" | "history_current_attachment_resolution" | "history_durable_history_load" | "history_sandbox_envelope_load" | "history_canonical_projection" | "history_provider_projection" | "history_attachment_ref_projection" | "history_screenshot_materialization" | "history_model_attachment_projection" | "history_runtime_input_assembly" | "history_artifact_candidate_scan" | "history_generated_image_materialization" | "history_position_load" | "owned_sandbox_setup" | "runtime_stream_initialization" | "model_request_preparation" | "model_sdk_serialization" | "model_prepare_sandbox_agent_preparation" | "model_prepare_sandbox_agent_manifest_inventory" | "model_prepare_sandbox_session_manifest_inventory" | "model_prepare_sandbox_manifest_apply" | "model_prepare_sandbox_entry_materialization" | "model_prepare_sandbox_running_check" | "model_prepare_sandbox_start" | "model_prepare_sandbox_client_create" | "model_prepare_sandbox_client_resume" | "model_prepare_sandbox_client_delete" | "model_prepare_sandbox_client_state_serialize" | "model_prepare_sandbox_client_reuse_check" | "model_prepare_sandbox_workspace_mutation_admission" | "model_prepare_sandbox_workspace_mutation_provider" | "model_prepare_sandbox_workspace_mutation_settlement" | "model_prepare_sandbox_first_routed_resolution_other" | "model_prepare_sandbox_first_routed_mutation_admission" | "model_prepare_sandbox_first_routed_provider_operation" | "model_prepare_sandbox_first_routed_mutation_settlement" | "model_prepare_sandbox_first_routed_other" | "model_prepare_sandbox_snapshot_wait" | "model_prepare_runner_before_first_sandbox_operation" | "model_prepare_sdk_after_first_sandbox_operation" | "model_prepare_runner_before_mcp_tools" | "model_prepare_mcp_tools_snapshot" | "model_prepare_mcp_tools_before_input_filter" | "model_prepare_mcp_tools_before_repository_skill_discovery" | "model_prepare_repository_skill_discovery" | "model_prepare_repository_skill_discovery_before_input_filter" | "model_prepare_input_filter_base" | "model_prepare_input_filter_genesis" | "model_prepare_input_filter_host" | "model_prepare_input_filter_tool_output" | "model_prepare_input_filter_modality" | "model_prepare_input_filter_context" | "model_prepare_responses_input_conversion" | "model_prepare_responses_request_build" | "model_credential_resolution" | "model_wire_normalization" | "model_request_audit" | "stream_bootstrap";
224
224
  export type TurnStartupOutcome = "completed" | "failed";
225
225
  export type TurnStartupMilestone = "queue" | "provider_dispatch" | "first_byte";
226
226
  export type TurnStartupCache = "hit" | "miss" | "disabled" | "none";
@@ -233,7 +233,8 @@ export type SandboxLogicalProvisionOutcome = "completed" | "expected_transition"
233
233
  export type SandboxProvisionAttemptOutcome = "completed" | "retrying" | "failed";
234
234
  export declare function turnStartupCountBucket(count: number | null): TurnStartupCountBucket;
235
235
  /**
236
- * Measure the critical path from a durable turn start to provider dispatch.
236
+ * Measure startup operations, including nested and parallel work. These are
237
+ * not additive critical-path intervals; use milestones for elapsed latency.
237
238
  * Every label is a closed or configuration-derived enum; high-cardinality turn,
238
239
  * session, credential, connection, file, and model identifiers are forbidden.
239
240
  */
@@ -245,6 +246,13 @@ export declare function recordTurnStartupPhase(observability: Observability, inp
245
246
  durationSeconds: number;
246
247
  count?: number | null;
247
248
  cache?: TurnStartupCache;
249
+ /** Trace-only lookup for the completed claim while its execution root is still open. */
250
+ executionCorrelationId?: string;
251
+ }): void;
252
+ /** Background MCP preparation must not inflate startup phase distributions. */
253
+ export declare function recordToolPreparationPhase(observability: Observability, input: ToolPreparationPhaseMeasurement & {
254
+ provider: string;
255
+ backend: string;
248
256
  }): void;
249
257
  /**
250
258
  * Explain why a turn did or did not keep provider sandbox work off the
@@ -0,0 +1,4 @@
1
+ import { type SandboxRetainedProcess } from "@opengeni/db";
2
+ import type { Observability } from "@opengeni/observability";
3
+ /** Protected cause locations and schema facts; public logs receive only the diagnostic key. */
4
+ export declare function warnRetainedProcessProofFailure(observability: Pick<Observability, "recordFailureDiagnostic" | "warn">, error: unknown, process: Pick<SandboxRetainedProcess, "id" | "sessionId" | "ownerAttemptId" | "ownerTurnId" | "reconcileAttempts">): void;
@@ -2,7 +2,8 @@ import { type Settings } from "@opengeni/config";
2
2
  import { readLease, reinstateTurnLeaseHolder, SandboxLeaseSupersededError, type Database, type LeaseHolderKind } from "@opengeni/db";
3
3
  import { establishSandboxSessionFromEnvelope, type EstablishedSandboxSession, type RuntimeMetricsHooks } from "@opengeni/runtime";
4
4
  import { type ObjectStorage } from "@opengeni/storage";
5
- import type { Observability } from "@opengeni/observability";
5
+ import { type Observability } from "@opengeni/observability";
6
+ export { safeSnapshotError } from "./sandbox-snapshot-diagnostics.js";
6
7
  export type ResumeHolderKind = LeaseHolderKind;
7
8
  /**
8
9
  * The durable identity of a turn holding a shared sandbox lease.
@@ -22,9 +23,6 @@ export type SandboxResumeServices = {
22
23
  db: Database;
23
24
  settings: Settings;
24
25
  objectStorage?: ObjectStorage | null;
25
- /** Exact settings before a verified rig provider image overlaid the logical
26
- * pack/deployment image. Fresh-create NotFound fallback must preserve an
27
- * ID-only logical base instead of selecting the provider default. */
28
26
  logicalFallbackSettings?: Settings;
29
27
  sandboxMetrics?: RuntimeMetricsHooks;
30
28
  /** Structured logger for lifecycle decisions (holder release reasons). Falls
@@ -163,14 +161,6 @@ export declare class SandboxLeaseInstanceLostError extends SandboxLeaseSupersede
163
161
  export declare function waitForSandboxExecReadiness(established: EstablishedSandboxSession, timeoutMs?: number, identity?: {
164
162
  sandboxGroupId?: string | null;
165
163
  }): Promise<void>;
166
- export declare function safeSnapshotError(error: unknown): {
167
- errorClass: "SnapshotOperationError";
168
- errorCode: "snapshot_operation_failed";
169
- status?: number;
170
- origin: "sandbox-resume";
171
- causeName?: string;
172
- integrityCode?: string;
173
- };
174
164
  export declare function waitForWarmSnapshot(snapshot: Promise<unknown>, timeoutMs: number, signal?: AbortSignal): Promise<boolean>;
175
165
  export type SandboxDeadlineRotationCheckpointResult = {
176
166
  /** The exact established epoch still carries a requested rotation and a
@@ -2,7 +2,7 @@ import { type Settings } from "@opengeni/config";
2
2
  import { type Database, type EnrollmentRecord } from "@opengeni/db";
3
3
  import type { OpStreamOutputFrame } from "@opengeni/runtime/sandbox";
4
4
  import type { EventBus } from "@opengeni/events";
5
- import { type EstablishedSandboxSession, type RoutingSandboxFirstOperationObserver, type RoutingSandboxOperationObserver, type SelfhostedOpObserver, type SelfhostedConnectionBinding, type SelfhostedRelayConfig, type OpStreamJournal } from "@opengeni/runtime";
5
+ import { type EstablishedSandboxSession, type RoutingSandboxFirstOperationObserver, type RoutingSandboxOperationObserver, type RoutingSandboxCaptureWaitObserver, type SelfhostedOpObserver, type SelfhostedConnectionBinding, type SelfhostedRelayConfig, type OpStreamJournal } from "@opengeni/runtime";
6
6
  export type RoutingWiringServices = {
7
7
  db: Database;
8
8
  settings: Settings;
@@ -15,6 +15,7 @@ export type RoutingWiringServices = {
15
15
  onOp?: SelfhostedOpObserver;
16
16
  /** Every physical routed provider call, across cloud and selfhosted homes. */
17
17
  onSandboxOperation?: RoutingSandboxOperationObserver;
18
+ onSandboxCaptureWait?: RoutingSandboxCaptureWaitObserver;
18
19
  /** The op-stream durable-resume journal (the Temporal adaptation from
19
20
  * op-journal.ts): attach generation + settled-frontier persistence. Absent ⇒
20
21
  * the runtime defaults (generation "1", no persistence) — tests / non-turn
@@ -27,11 +28,12 @@ export type RoutingWiringServices = {
27
28
  instanceId: string;
28
29
  leaseEpoch: number;
29
30
  }) => Promise<void>;
30
- /** Called when a route repair replaces the worker's original home handle. */
31
+ /** Prepare and publish the worker's home handle. Rejection leaves the route
32
+ * unpublished; replacement preparation must settle before the first tool op. */
31
33
  onHomeSandboxRebound?: (input: {
32
34
  established: EstablishedSandboxSession;
33
35
  leaseEpoch: number;
34
- }) => void;
36
+ }) => void | Promise<void>;
35
37
  /** Cancel bounded capture waits with the owning turn activity. */
36
38
  waitSignal?: AbortSignal;
37
39
  };
@@ -0,0 +1,20 @@
1
+ import { type Observability } from "@opengeni/observability";
2
+ type SafeSnapshotError = {
3
+ errorClass: "SnapshotOperationError";
4
+ errorCode: "snapshot_operation_failed";
5
+ status?: number;
6
+ origin: "sandbox-resume" | "worker-lifecycle";
7
+ causeName?: string;
8
+ integrityCode?: string;
9
+ providerErrorName?: string;
10
+ providerGrpcCode?: number;
11
+ providerHttpStatus?: number;
12
+ providerRetryable?: boolean;
13
+ };
14
+ export declare function safeSnapshotError(error: unknown, origin?: SafeSnapshotError["origin"]): SafeSnapshotError;
15
+ export declare function warnDrainSnapshotFailure(observability: Pick<Observability, "warn">, message: string, error: unknown, lease: {
16
+ workspaceId?: string;
17
+ sandboxGroupId: string;
18
+ leaseEpoch: number;
19
+ }): void;
20
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { LeaseSnapshot } from "@opengeni/db";
2
+ /** Physical capture retention is not permission to heartbeat or execute a closed turn. */
3
+ export declare function retainsHolderForWarmCapture(lease: Pick<LeaseSnapshot, "liveness" | "leaseEpoch" | "archiveCapture"> | null, expectedEpoch: number, now?: number): boolean;