@opengeni/worker-bundle 2.0.1 → 2.0.2-canary.38686408778001
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/activities/agent-run-admission.d.ts +1 -12
- package/dist/activities/agent-turn/admission.d.ts +88 -10
- package/dist/activities/agent-turn/agent-build.d.ts +14 -3
- package/dist/activities/agent-turn/claim.d.ts +4 -1
- package/dist/activities/agent-turn/claude-core.d.ts +195 -0
- package/dist/activities/agent-turn/code-search.d.ts +60 -0
- package/dist/activities/agent-turn/codex-capacity.d.ts +3 -0
- package/dist/activities/agent-turn/codex-core-capacity.d.ts +37 -0
- package/dist/activities/agent-turn/codex-core-claim.d.ts +40 -0
- package/dist/activities/agent-turn/codex-core-errors.d.ts +102 -0
- package/dist/activities/agent-turn/codex-core-failover.d.ts +15 -0
- package/dist/activities/agent-turn/codex-core-requests.d.ts +28 -0
- package/dist/activities/agent-turn/codex-core-settlement.d.ts +77 -0
- package/dist/activities/agent-turn/codex-credit-policy.d.ts +30 -0
- package/dist/activities/agent-turn/codex-plan-entitlement.d.ts +105 -0
- package/dist/activities/agent-turn/codex-usage-policy.d.ts +2 -0
- package/dist/activities/agent-turn/codex.d.ts +2 -19
- package/dist/activities/agent-turn/compaction-interruption.d.ts +32 -0
- package/dist/activities/agent-turn/compaction-prep.d.ts +30 -1
- package/dist/activities/agent-turn/credential-leases.d.ts +64 -37
- package/dist/activities/agent-turn/credential-restriction.d.ts +3 -0
- package/dist/activities/agent-turn/errors.d.ts +172 -28
- package/dist/activities/agent-turn/failure-settlement.d.ts +10 -43
- package/dist/activities/agent-turn/final-reply.d.ts +18 -0
- package/dist/activities/agent-turn/finalization-monitor.d.ts +7 -2
- package/dist/activities/agent-turn/finalization.d.ts +2 -0
- package/dist/activities/agent-turn/github-repository-bindings.d.ts +2 -0
- package/dist/activities/agent-turn/governance-model.d.ts +13 -1
- package/dist/activities/agent-turn/history-sink.d.ts +3 -1
- package/dist/activities/agent-turn/history.d.ts +2 -0
- package/dist/activities/agent-turn/input-wait-reply.d.ts +76 -0
- package/dist/activities/agent-turn/meaningful-output.d.ts +9 -0
- package/dist/activities/agent-turn/media-artifacts.d.ts +5 -3
- package/dist/activities/agent-turn/model-call-admission.d.ts +15 -0
- package/dist/activities/agent-turn/model-usage.d.ts +56 -14
- package/dist/activities/agent-turn/model-wire-dispatch.d.ts +15 -0
- package/dist/activities/agent-turn/optional-repositories.d.ts +59 -0
- package/dist/activities/agent-turn/prompt-tool-availability.d.ts +17 -0
- package/dist/activities/agent-turn/provider-dispatch-barrier.d.ts +12 -1
- package/dist/activities/agent-turn/provider-recovery-copy.d.ts +24 -0
- package/dist/activities/agent-turn/provider-recovery-metrics.d.ts +18 -0
- package/dist/activities/agent-turn/provider-recovery-policy.d.ts +6 -0
- package/dist/activities/agent-turn/quiescence.d.ts +6 -7
- package/dist/activities/agent-turn/recovery-warning.d.ts +6 -5
- package/dist/activities/agent-turn/refresh-credentials.d.ts +6 -0
- package/dist/activities/agent-turn/run-credentials.d.ts +9 -5
- package/dist/activities/agent-turn/run.d.ts +27 -2
- package/dist/activities/agent-turn/sandbox-establish.d.ts +1 -0
- package/dist/activities/agent-turn/sandbox-provision.d.ts +25 -1
- package/dist/activities/agent-turn/sandbox-route.d.ts +3 -0
- package/dist/activities/agent-turn/sandbox-runtime.d.ts +1 -1
- package/dist/activities/agent-turn/secret-resolver.d.ts +64 -0
- package/dist/activities/agent-turn/session-title.d.ts +60 -3
- package/dist/activities/agent-turn/session-usage-custody.d.ts +66 -0
- package/dist/activities/agent-turn/skill-checkout.d.ts +25 -6
- package/dist/activities/agent-turn/skill-read.d.ts +70 -2
- package/dist/activities/agent-turn/skill-search.d.ts +2 -0
- package/dist/activities/agent-turn/skill-tools.d.ts +41 -4
- package/dist/activities/agent-turn/skill-transfer.d.ts +18 -6
- package/dist/activities/agent-turn/stream-attempt.d.ts +6 -3
- package/dist/activities/agent-turn/subscription-capacity-arming.d.ts +41 -0
- package/dist/activities/agent-turn/subscription-core-capacity.d.ts +86 -0
- package/dist/activities/agent-turn/subscription-core-failover.d.ts +69 -0
- package/dist/activities/agent-turn/subscription-core-placed.d.ts +14 -0
- package/dist/activities/agent-turn/subscription-core-requests.d.ts +109 -0
- package/dist/activities/agent-turn/subscription-core-settlement.d.ts +112 -0
- package/dist/activities/agent-turn/subscription-lease.d.ts +44 -0
- package/dist/activities/agent-turn/subscription-serving-capacity.d.ts +6 -0
- package/dist/activities/agent-turn/subscription-serving-catalog.d.ts +13 -0
- package/dist/activities/agent-turn/subscription-serving-claim.d.ts +30 -0
- package/dist/activities/agent-turn/subscription-serving-providers.d.ts +2 -0
- package/dist/activities/agent-turn/tool-environment.d.ts +30 -6
- package/dist/activities/agent-turn/tool-policy.d.ts +55 -3
- package/dist/activities/agent-turn/turn-context.d.ts +104 -5
- package/dist/activities/agent-turn/web-search.d.ts +57 -0
- package/dist/activities/agent-turn/xai-core.d.ts +96 -0
- package/dist/activities/automations.d.ts +3 -1
- package/dist/activities/browser-deadline-checkpoint.d.ts +34 -0
- package/dist/activities/capabilities.d.ts +8 -20
- package/dist/activities/codemode-dispatcher.d.ts +20 -3
- package/dist/activities/codex-capacity.d.ts +1 -56
- package/dist/activities/codex-image-generation.d.ts +49 -3
- package/dist/activities/common.d.ts +3 -1
- package/dist/activities/context-compaction.d.ts +41 -2
- package/dist/activities/environment.d.ts +1 -19
- package/dist/activities/gmail-files.d.ts +50 -0
- package/dist/activities/goals.d.ts +1 -9
- package/dist/activities/incident-telemetry-authority.d.ts +5 -2
- package/dist/activities/incident-telemetry-preflight.d.ts +10 -3
- package/dist/activities/knowledge-indexing.d.ts +19 -0
- package/dist/activities/mcp-account-routes.d.ts +2 -21
- package/dist/activities/model-call-fact-reconciler.d.ts +34 -0
- package/dist/activities/open-suffix-resume.d.ts +15 -0
- package/dist/activities/parent-wake.d.ts +17 -12
- package/dist/activities/programmatic-approvals.d.ts +10 -0
- package/dist/activities/requester-unavailable-receipt.d.ts +8 -0
- package/dist/activities/retained-screenshots.d.ts +7 -2
- package/dist/activities/run-credential-renewal.d.ts +1 -0
- package/dist/activities/run-credentials.d.ts +16 -4
- package/dist/activities/run-input.d.ts +17 -0
- package/dist/activities/sandbox-lease.d.ts +132 -12
- package/dist/activities/scheduled-tasks.d.ts +4 -35
- package/dist/activities/session-archive.d.ts +58 -0
- package/dist/activities/session-state.d.ts +15 -3
- package/dist/activities/session-storage.d.ts +44 -0
- package/dist/activities/subscription-core-claude-waits.d.ts +2 -0
- package/dist/activities/subscription-core-codex-quota.d.ts +25 -0
- package/dist/activities/subscription-core-codex-waits.d.ts +153 -0
- package/dist/activities/subscription-core-image-operation.d.ts +29 -0
- package/dist/activities/subscription-core-usage-recheck.d.ts +49 -0
- package/dist/activities/subscription-core-wait-bindings.d.ts +3 -0
- package/dist/activities/subscription-core-xai-quota.d.ts +30 -0
- package/dist/activities/subscription-core-xai-waits.d.ts +2 -0
- package/dist/activities/types.d.ts +68 -5
- package/dist/activities/video-generation-admission.d.ts +2 -8
- package/dist/activities/video-generation-credential.d.ts +15 -12
- package/dist/activities/video-generation-subscription-core.d.ts +70 -0
- package/dist/activities/workspace-capture.d.ts +2 -0
- package/dist/activities/workspace-credential-provider.d.ts +47 -0
- package/dist/activities/xai-auth.d.ts +6 -18
- package/dist/activities/xai-image-generation.d.ts +22 -6
- package/dist/{activities-control-QA6OLRQY.js → activities-control-NTXZHYET.js} +1552 -2876
- package/dist/activities-control-NTXZHYET.js.map +1 -0
- package/dist/activities-control.d.ts +64 -4
- package/dist/{activities-turn-YVVKCGAK.js → activities-turn-RKRI5GY4.js} +9238 -4392
- package/dist/activities-turn-RKRI5GY4.js.map +1 -0
- package/dist/activities.d.ts +64 -4
- package/dist/artifact-materializer-entry.js +104 -35
- package/dist/artifact-materializer-entry.js.map +1 -1
- package/dist/artifact-outbox-entry.js +132 -61
- package/dist/artifact-outbox-entry.js.map +1 -1
- package/dist/browser-deadline-checkpoint-contract.d.ts +2 -0
- package/dist/{chunk-GDCLDKSH.js → chunk-24GP3BX5.js} +79 -72
- package/dist/chunk-24GP3BX5.js.map +1 -0
- package/dist/{chunk-RAMNYSAW.js → chunk-4ER3YXOT.js} +22 -4
- package/dist/chunk-4ER3YXOT.js.map +1 -0
- package/dist/{chunk-I7HKKMUJ.js → chunk-5NNS4327.js} +734 -58
- package/dist/chunk-5NNS4327.js.map +1 -0
- package/dist/{chunk-M3NVMF2V.js → chunk-7BIHFUGB.js} +2293 -3956
- package/dist/chunk-7BIHFUGB.js.map +1 -0
- package/dist/chunk-MVESOYFC.js +3746 -0
- package/dist/chunk-MVESOYFC.js.map +1 -0
- package/dist/chunk-NQDVJ6RI.js +2823 -0
- package/dist/chunk-NQDVJ6RI.js.map +1 -0
- package/dist/chunk-O7UPBWXK.js +79 -0
- package/dist/chunk-O7UPBWXK.js.map +1 -0
- package/dist/chunk-W2QSM5HR.js +414 -0
- package/dist/chunk-W2QSM5HR.js.map +1 -0
- package/dist/chunk-ZN3XJR33.js +227 -0
- package/dist/chunk-ZN3XJR33.js.map +1 -0
- package/dist/editable-artifact-outbox-dispatcher.d.ts +12 -1
- package/dist/editable-artifact-outbox-service.d.ts +3 -1
- package/dist/host-export-pump.d.ts +3 -1
- package/dist/host-export.d.ts +2 -2
- package/dist/host-export.js +1 -1
- package/dist/http.d.ts +1 -1
- package/dist/index.d.ts +49 -48
- package/dist/index.js +835 -256
- package/dist/index.js.map +1 -1
- package/dist/internal-maintenance.d.ts +63 -0
- package/dist/maintenance-cadence.d.ts +43 -0
- package/dist/observability-metrics.d.ts +293 -24
- package/dist/onepassword-vault-provider.d.ts +7 -0
- package/dist/parent-wake-PCLH7A3Y.js +24 -0
- package/dist/parent-wake-PCLH7A3Y.js.map +1 -0
- package/dist/personal-github-git-credentials.d.ts +1 -1
- package/dist/readiness-checks.d.ts +39 -0
- package/dist/retained-process-retry.d.ts +7 -0
- package/dist/sandbox-lease-BJYU72N3.js +84 -0
- package/dist/sandbox-lease-BJYU72N3.js.map +1 -0
- package/dist/sandbox-reaper-contract.d.ts +25 -0
- package/dist/sandbox-resume.d.ts +72 -4
- package/dist/sandbox-routing.d.ts +4 -2
- package/dist/session-event-fanout.d.ts +6 -0
- package/dist/site-auth-maintenance-WK3MR2PV.js +12 -0
- package/dist/site-auth-maintenance-WK3MR2PV.js.map +1 -0
- package/dist/telemetry-scheduler.d.ts +14 -0
- package/dist/temporal-runtime-logger.d.ts +22 -0
- package/dist/turn-task-queue-reader.d.ts +18 -0
- package/dist/turn-worker-activity-telemetry.d.ts +47 -0
- package/dist/worker-service-lifecycle.d.ts +12 -0
- package/dist/workflow-bundle.js +468 -71
- package/dist/workflows/activities.d.ts +1 -1
- package/dist/workflows/browser-deadline-checkpoint.d.ts +10 -0
- package/dist/workflows/sandbox-reaper.d.ts +10 -1
- package/dist/workflows/scheduled-tasks.d.ts +4 -0
- package/dist/workflows/session-storage.d.ts +2 -0
- package/dist/workflows/session.d.ts +36 -0
- package/dist/workflows/site-auth-maintenance.d.ts +2 -1
- package/dist/workflows/workflow-wake.d.ts +14 -3
- package/dist/workflows.d.ts +3 -1
- package/package.json +26 -20
- package/src/activities/agent-run-admission.ts +1 -82
- package/src/activities/agent-turn/admission.ts +175 -24
- package/src/activities/agent-turn/agent-build.ts +226 -145
- package/src/activities/agent-turn/claim.ts +363 -64
- package/src/activities/agent-turn/claude-core.ts +587 -0
- package/src/activities/agent-turn/code-search.ts +275 -0
- package/src/activities/agent-turn/codex-capacity.ts +30 -757
- package/src/activities/agent-turn/codex-core-capacity.ts +190 -0
- package/src/activities/agent-turn/codex-core-claim.ts +83 -0
- package/src/activities/agent-turn/codex-core-errors.ts +308 -0
- package/src/activities/agent-turn/codex-core-failover.ts +73 -0
- package/src/activities/agent-turn/codex-core-requests.ts +86 -0
- package/src/activities/agent-turn/codex-core-settlement.ts +263 -0
- package/src/activities/agent-turn/codex-credit-policy.ts +247 -0
- package/src/activities/agent-turn/codex-plan-entitlement.ts +254 -0
- package/src/activities/agent-turn/codex-usage-policy.ts +2 -0
- package/src/activities/agent-turn/codex.ts +8 -76
- package/src/activities/agent-turn/compaction-interruption.ts +56 -0
- package/src/activities/agent-turn/compaction-prep.ts +249 -36
- package/src/activities/agent-turn/credential-leases.ts +269 -214
- package/src/activities/agent-turn/credential-restriction.ts +14 -0
- package/src/activities/agent-turn/errors.ts +1134 -82
- package/src/activities/agent-turn/failure-settlement.ts +879 -886
- package/src/activities/agent-turn/final-reply.ts +46 -0
- package/src/activities/agent-turn/finalization-monitor.ts +17 -5
- package/src/activities/agent-turn/finalization.ts +107 -88
- package/src/activities/agent-turn/github-repository-bindings.ts +3 -1
- package/src/activities/agent-turn/governance-model.ts +90 -22
- package/src/activities/agent-turn/history-sink.ts +26 -4
- package/src/activities/agent-turn/history.ts +25 -5
- package/src/activities/agent-turn/input-wait-reply.ts +139 -0
- package/src/activities/agent-turn/knowledge-source-tools.ts +2 -0
- package/src/activities/agent-turn/meaningful-output.ts +44 -0
- package/src/activities/agent-turn/media-artifacts.ts +3 -1
- package/src/activities/agent-turn/model-call-admission.ts +94 -0
- package/src/activities/agent-turn/model-usage.ts +299 -233
- package/src/activities/agent-turn/model-wire-dispatch.ts +27 -0
- package/src/activities/agent-turn/optional-repositories.ts +224 -0
- package/src/activities/agent-turn/prompt-tool-availability.ts +27 -0
- package/src/activities/agent-turn/provider-dispatch-barrier.ts +22 -0
- package/src/activities/agent-turn/provider-recovery-copy.ts +76 -0
- package/src/activities/agent-turn/provider-recovery-metrics.ts +64 -0
- package/src/activities/agent-turn/provider-recovery-policy.ts +25 -0
- package/src/activities/agent-turn/quiescence.ts +7 -7
- package/src/activities/agent-turn/recovery-warning.ts +6 -8
- package/src/activities/agent-turn/refresh-credentials.ts +44 -0
- package/src/activities/agent-turn/run-credentials.ts +124 -76
- package/src/activities/agent-turn/run.ts +501 -112
- package/src/activities/agent-turn/sandbox-establish.ts +152 -75
- package/src/activities/agent-turn/sandbox-provision.ts +54 -1
- package/src/activities/agent-turn/sandbox-route.ts +4 -1
- package/src/activities/agent-turn/sandbox-runtime.ts +319 -11
- package/src/activities/agent-turn/secret-resolver.ts +155 -0
- package/src/activities/agent-turn/session-title.ts +177 -12
- package/src/activities/agent-turn/session-usage-custody.ts +170 -0
- package/src/activities/agent-turn/skill-checkout.ts +111 -24
- package/src/activities/agent-turn/skill-install.ts +1 -1
- package/src/activities/agent-turn/skill-read.ts +374 -28
- package/src/activities/agent-turn/skill-save.ts +35 -7
- package/src/activities/agent-turn/skill-search.ts +9 -0
- package/src/activities/agent-turn/skill-selection.ts +4 -0
- package/src/activities/agent-turn/skill-tools.ts +208 -21
- package/src/activities/agent-turn/skill-transfer.ts +68 -23
- package/src/activities/agent-turn/stream-attempt.ts +599 -110
- package/src/activities/agent-turn/subscription-capacity-arming.ts +81 -0
- package/src/activities/agent-turn/subscription-core-capacity.ts +439 -0
- package/src/activities/agent-turn/subscription-core-failover.ts +229 -0
- package/src/activities/agent-turn/subscription-core-placed.ts +37 -0
- package/src/activities/agent-turn/subscription-core-requests.ts +271 -0
- package/src/activities/agent-turn/subscription-core-settlement.ts +234 -0
- package/src/activities/agent-turn/subscription-lease.ts +140 -0
- package/src/activities/agent-turn/subscription-serving-capacity.ts +195 -0
- package/src/activities/agent-turn/subscription-serving-catalog.ts +71 -0
- package/src/activities/agent-turn/subscription-serving-claim.ts +178 -0
- package/src/activities/agent-turn/subscription-serving-providers.ts +15 -0
- package/src/activities/agent-turn/tool-environment.ts +384 -292
- package/src/activities/agent-turn/tool-policy.ts +104 -4
- package/src/activities/agent-turn/tool-result-spill.ts +1 -0
- package/src/activities/agent-turn/turn-context.ts +124 -8
- package/src/activities/agent-turn/web-search.ts +431 -0
- package/src/activities/agent-turn/xai-core.ts +301 -0
- package/src/activities/automations.ts +81 -6
- package/src/activities/browser-deadline-checkpoint.ts +297 -0
- package/src/activities/capabilities.ts +53 -213
- package/src/activities/codemode-dispatcher.ts +236 -14
- package/src/activities/codex-capacity.ts +27 -380
- package/src/activities/codex-image-generation.ts +252 -42
- package/src/activities/common.ts +12 -0
- package/src/activities/connector-attachments.ts +3 -1
- package/src/activities/context-compaction.ts +162 -21
- package/src/activities/environment.ts +18 -106
- package/src/activities/gmail-files.ts +108 -0
- package/src/activities/goals.ts +120 -204
- package/src/activities/image-generation-operation.ts +1 -1
- package/src/activities/incident-telemetry-authority.ts +80 -50
- package/src/activities/incident-telemetry-preflight.ts +27 -15
- package/src/activities/knowledge-indexing.ts +287 -17
- package/src/activities/knowledge-source-sync.ts +10 -0
- package/src/activities/mcp-account-routes.ts +2 -124
- package/src/activities/model-call-fact-reconciler.ts +112 -0
- package/src/activities/open-suffix-resume.ts +122 -88
- package/src/activities/parent-wake.ts +89 -21
- package/src/activities/programmatic-approvals.ts +26 -0
- package/src/activities/requester-unavailable-receipt.ts +14 -0
- package/src/activities/retained-screenshots.ts +135 -24
- package/src/activities/run-credential-renewal.ts +13 -1
- package/src/activities/run-credentials.ts +61 -19
- package/src/activities/run-input.ts +116 -9
- package/src/activities/sandbox-lease.ts +1615 -73
- package/src/activities/scheduled-tasks.ts +758 -141
- package/src/activities/session-archive.ts +382 -0
- package/src/activities/session-state.ts +219 -10
- package/src/activities/session-storage.ts +124 -0
- package/src/activities/site-auth-maintenance.ts +5 -2
- package/src/activities/subscription-core-claude-waits.ts +49 -0
- package/src/activities/subscription-core-codex-quota.ts +46 -0
- package/src/activities/subscription-core-codex-waits.ts +488 -0
- package/src/activities/subscription-core-image-operation.ts +126 -0
- package/src/activities/subscription-core-usage-recheck.ts +146 -0
- package/src/activities/subscription-core-wait-bindings.ts +12 -0
- package/src/activities/subscription-core-xai-quota.ts +85 -0
- package/src/activities/subscription-core-xai-waits.ts +48 -0
- package/src/activities/types.ts +85 -9
- package/src/activities/video-generation-admission.ts +1 -36
- package/src/activities/video-generation-credential.ts +38 -56
- package/src/activities/video-generation-reconciliation.ts +150 -131
- package/src/activities/video-generation-subscription-core.ts +180 -0
- package/src/activities/workspace-capture.ts +13 -2
- package/src/activities/workspace-credential-provider.ts +302 -0
- package/src/activities/xai-auth.ts +34 -112
- package/src/activities/xai-image-generation.ts +84 -36
- package/src/activities-control.ts +8 -0
- package/src/activities-turn.ts +5 -0
- package/src/activities.ts +17 -0
- package/src/activity-services.ts +29 -4
- package/src/browser-deadline-checkpoint-contract.ts +5 -0
- package/src/editable-artifact-hint-broker.ts +3 -0
- package/src/editable-artifact-materializer-service.ts +79 -38
- package/src/editable-artifact-materializer-subprocess.ts +47 -2
- package/src/editable-artifact-outbox-dispatcher.ts +107 -46
- package/src/editable-artifact-outbox-service.ts +55 -25
- package/src/github-rest-mcp.ts +1 -1
- package/src/host-export-pump.ts +26 -4
- package/src/host-export.ts +4 -1
- package/src/http.ts +4 -2
- package/src/index.ts +222 -282
- package/src/internal-maintenance.ts +347 -0
- package/src/maintenance-cadence.ts +156 -0
- package/src/observability-metrics.ts +1173 -73
- package/src/onepassword-vault-provider.ts +11 -0
- package/src/personal-github-git-credentials.ts +3 -1
- package/src/pr-review-credentials.ts +1 -1
- package/src/readiness-checks.ts +113 -0
- package/src/retained-process-retry.ts +36 -0
- package/src/sandbox-reaper-contract.ts +33 -0
- package/src/sandbox-resume.ts +444 -73
- package/src/sandbox-routing.ts +230 -75
- package/src/session-event-fanout.ts +23 -0
- package/src/telemetry-scheduler.ts +53 -0
- package/src/temporal-runtime-logger.ts +44 -0
- package/src/turn-task-queue-reader.ts +110 -0
- package/src/turn-worker-activity-telemetry.ts +209 -0
- package/src/worker-service-lifecycle.ts +54 -1
- package/src/workflows/activities.ts +16 -1
- package/src/workflows/browser-deadline-checkpoint.ts +55 -0
- package/src/workflows/file-upload-reaper.ts +2 -0
- package/src/workflows/sandbox-reaper.ts +88 -0
- package/src/workflows/scheduled-tasks.ts +26 -13
- package/src/workflows/session-storage.ts +19 -0
- package/src/workflows/session.ts +238 -33
- package/src/workflows/site-auth-maintenance.ts +2 -1
- package/src/workflows/workflow-wake.ts +26 -4
- package/src/workflows.ts +7 -0
- package/dist/activities/agent-turn/xai-capacity.d.ts +0 -2
- package/dist/activities/codex-fleet-shadow.d.ts +0 -74
- package/dist/activities/codex-rotation.d.ts +0 -200
- package/dist/activities/xai-quota.d.ts +0 -3
- package/dist/activities-control-QA6OLRQY.js.map +0 -1
- package/dist/activities-turn-YVVKCGAK.js.map +0 -1
- package/dist/chunk-GDCLDKSH.js.map +0 -1
- package/dist/chunk-I7HKKMUJ.js.map +0 -1
- package/dist/chunk-M3NVMF2V.js.map +0 -1
- package/dist/chunk-RAMNYSAW.js.map +0 -1
- package/src/activities/agent-turn/xai-capacity.ts +0 -257
- package/src/activities/codex-fleet-shadow.ts +0 -306
- package/src/activities/codex-rotation.ts +0 -685
- package/src/activities/xai-quota.ts +0 -35
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Refusal settlement and finalization for a chat turn on the shared
|
|
3
|
+
* subscription core, for any provider whose errors classify into shared
|
|
4
|
+
* outcomes (SuperGrok track X1b; the Claude track binds the same steps).
|
|
5
|
+
* Every write is scoped to the exact accepted turn and its live lease, and
|
|
6
|
+
* the bookkeeping is best effort: it never changes how the turn settles by
|
|
7
|
+
* itself. Codex keeps its own M3 step (`codex-core-settlement.ts` and the
|
|
8
|
+
* Codex branch of `failure-settlement.ts`), whose refusal kinds predate the
|
|
9
|
+
* shared outcomes.
|
|
10
|
+
*/
|
|
11
|
+
import {
|
|
12
|
+
SubscriptionCoreError,
|
|
13
|
+
subscriptionCoreSettlement,
|
|
14
|
+
subscriptionCoreTurns,
|
|
15
|
+
type Database,
|
|
16
|
+
type SubscriptionCoreProvider,
|
|
17
|
+
type SubscriptionCoreTurnIdentity,
|
|
18
|
+
} from "@opengeni/db";
|
|
19
|
+
import { planSubscriptionCoreRefusal, type ProviderErrorOutcome } from "@opengeni/subscriptions";
|
|
20
|
+
import type { RunAgentTurnResult } from "../types";
|
|
21
|
+
import {
|
|
22
|
+
subscriptionCoreAccountRefusedFailure,
|
|
23
|
+
type SubscriptionCoreCodexTurnError,
|
|
24
|
+
} from "./codex-core-errors";
|
|
25
|
+
import type { CoreSubscriptionTurnLease } from "./credential-leases";
|
|
26
|
+
import type { TurnFailureDeps } from "./failure-settlement";
|
|
27
|
+
import {
|
|
28
|
+
failOverCoreSubscriptionTurn,
|
|
29
|
+
type CoreFailoverBinding,
|
|
30
|
+
} from "./subscription-core-failover";
|
|
31
|
+
import type { SubscriptionCoreTurn } from "./turn-context";
|
|
32
|
+
|
|
33
|
+
type LeaseFence = Pick<CoreSubscriptionTurnLease, "holderId" | "generation">;
|
|
34
|
+
|
|
35
|
+
function leaseRef(core: SubscriptionCoreTurn, lease: LeaseFence) {
|
|
36
|
+
if (!lease.holderId || lease.generation === null) return null;
|
|
37
|
+
return {
|
|
38
|
+
connectionId: core.connectionId,
|
|
39
|
+
holderId: lease.holderId,
|
|
40
|
+
generation: lease.generation,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The refresh generation the turn's latest request carried. */
|
|
45
|
+
export function coreRequestRefreshGeneration(core: SubscriptionCoreTurn): number {
|
|
46
|
+
return core.credentialVersion ?? core.placedRefreshGeneration;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Record a definitive refusal against the leased connection through the
|
|
51
|
+
* shared plan (`planSubscriptionCoreRefusal`): the (turn, connection)
|
|
52
|
+
* failure receipt, which counts toward the per-turn failover bound, then the
|
|
53
|
+
* health state that keeps placement away (a quota observation fenced on the
|
|
54
|
+
* refresh generation the refused bearer carried, a model cooldown, or a
|
|
55
|
+
* sign-in or forbidden quarantine). Whether the credential renews and was
|
|
56
|
+
* already refreshed before the refusal comes from the provider's binding.
|
|
57
|
+
* `receipt` reports whether the refusal was recorded.
|
|
58
|
+
*/
|
|
59
|
+
export async function recordCoreSubscriptionRefusal(input: {
|
|
60
|
+
db: Database;
|
|
61
|
+
provider: SubscriptionCoreProvider;
|
|
62
|
+
core: SubscriptionCoreTurn;
|
|
63
|
+
lease: LeaseFence;
|
|
64
|
+
outcome: ProviderErrorOutcome;
|
|
65
|
+
/** How the provider's transport treats the refused credential (`CoreRefusalBinding.credential`). */
|
|
66
|
+
credential: CoreRefusalCredential;
|
|
67
|
+
now?: Date;
|
|
68
|
+
}): Promise<{ receipt: boolean; health: boolean }> {
|
|
69
|
+
const ref = leaseRef(input.core, input.lease);
|
|
70
|
+
if (!ref) return { receipt: false, health: false };
|
|
71
|
+
const now = (input.now ?? new Date()).getTime();
|
|
72
|
+
const refreshGeneration = coreRequestRefreshGeneration(input.core);
|
|
73
|
+
const plan = planSubscriptionCoreRefusal(input.provider.adapter, input.outcome, {
|
|
74
|
+
now,
|
|
75
|
+
refreshGeneration,
|
|
76
|
+
renewable: input.credential.renewable,
|
|
77
|
+
refreshed: input.credential.refreshedBeforeRefusal,
|
|
78
|
+
});
|
|
79
|
+
if (plan.kind !== "settle") return { receipt: false, health: false };
|
|
80
|
+
return await subscriptionCoreSettlement(input.provider)
|
|
81
|
+
.applySubscriptionCoreRefusal(input.db, input.core.identity, ref, plan, {
|
|
82
|
+
refreshGeneration,
|
|
83
|
+
now,
|
|
84
|
+
})
|
|
85
|
+
.catch(() => ({ receipt: false, health: false }));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Finalization for a core turn before its lease is released: a completed
|
|
90
|
+
* model call moves the binding's cache-warmth clock. A refused or failed
|
|
91
|
+
* call leaves no warm cache.
|
|
92
|
+
*/
|
|
93
|
+
export async function touchCoreSubscriptionBinding(input: {
|
|
94
|
+
db: Database;
|
|
95
|
+
provider: SubscriptionCoreProvider;
|
|
96
|
+
core: SubscriptionCoreTurn;
|
|
97
|
+
lease: LeaseFence;
|
|
98
|
+
modelCallCompletedAt: Date | null;
|
|
99
|
+
}): Promise<void> {
|
|
100
|
+
const ref = leaseRef(input.core, input.lease);
|
|
101
|
+
if (!ref || !input.modelCallCompletedAt) return;
|
|
102
|
+
await subscriptionCoreTurns(input.provider)
|
|
103
|
+
.touchSubscriptionCoreBinding(input.db, input.core.identity, ref, input.modelCallCompletedAt)
|
|
104
|
+
.catch(() => false);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** One provider's refusal settlement inputs. */
|
|
108
|
+
/**
|
|
109
|
+
* How a provider's transport treats a refused credential: whether it renews,
|
|
110
|
+
* and whether an unauthorized request was already refreshed and retried once
|
|
111
|
+
* before the refusal reached settlement.
|
|
112
|
+
*/
|
|
113
|
+
export type CoreRefusalCredential = { renewable: boolean; refreshedBeforeRefusal: boolean };
|
|
114
|
+
|
|
115
|
+
export type CoreRefusalBinding = {
|
|
116
|
+
provider: SubscriptionCoreProvider;
|
|
117
|
+
displayName: string;
|
|
118
|
+
credential: CoreRefusalCredential;
|
|
119
|
+
/** The provider's classification of a failed model request (null: not a refusal). */
|
|
120
|
+
classify: (error: unknown) => ProviderErrorOutcome | null;
|
|
121
|
+
/**
|
|
122
|
+
* Joins the turn's in-flight observations of the leased connection (a
|
|
123
|
+
* provider that reports quota per response) before the refusal is recorded
|
|
124
|
+
* and the lease released, so placement sees them and none is dropped by
|
|
125
|
+
* the lease fence. Best effort.
|
|
126
|
+
*/
|
|
127
|
+
joinObservations?: (deps: TurnFailureDeps, core: SubscriptionCoreTurn) => Promise<void>;
|
|
128
|
+
lease: (deps: TurnFailureDeps) => CoreSubscriptionTurnLease;
|
|
129
|
+
isSourceDisconnected: (
|
|
130
|
+
db: Database,
|
|
131
|
+
identity: SubscriptionCoreTurnIdentity,
|
|
132
|
+
connectionId: string,
|
|
133
|
+
) => Promise<boolean>;
|
|
134
|
+
failover: CoreFailoverBinding;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
function causeHasCoreCode(error: unknown, code: string): boolean {
|
|
138
|
+
let current: unknown = error;
|
|
139
|
+
for (let depth = 0; depth < 8 && current instanceof Error; depth++) {
|
|
140
|
+
if (current instanceof SubscriptionCoreError && current.code === code) return true;
|
|
141
|
+
current = current.cause;
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Failure settlement of a core turn's definitive refusal: the provider's
|
|
148
|
+
* classification becomes a shared outcome, the refusal is recorded against
|
|
149
|
+
* the leased connection, and the same turn re-places within the per-turn
|
|
150
|
+
* bound (another account, or a durable wait). A graceful source disconnect
|
|
151
|
+
* re-places without a refusal. Returns the settled result, or the typed
|
|
152
|
+
* terminal failure when automatic re-placement was not possible (null: not
|
|
153
|
+
* an account refusal, so the generic failure path settles the turn). The
|
|
154
|
+
* caller runs this only when no request outcome is unknown and the lease
|
|
155
|
+
* was not lost.
|
|
156
|
+
*/
|
|
157
|
+
export async function settleCoreSubscriptionRefusal(
|
|
158
|
+
deps: TurnFailureDeps,
|
|
159
|
+
core: SubscriptionCoreTurn,
|
|
160
|
+
binding: CoreRefusalBinding,
|
|
161
|
+
): Promise<{ result: RunAgentTurnResult | null; failure: SubscriptionCoreCodexTurnError | null }> {
|
|
162
|
+
const { error, db, eventing, attempt } = deps;
|
|
163
|
+
const outcome = binding.classify(error);
|
|
164
|
+
const joinObservations = async () => {
|
|
165
|
+
await binding.joinObservations?.(deps, core).catch(() => undefined);
|
|
166
|
+
};
|
|
167
|
+
// Only a pre-dispatch lifecycle fence or a definite refusal can enter
|
|
168
|
+
// graceful recovery; a concurrent disconnect never upgrades an ambiguous
|
|
169
|
+
// failure into replay proof.
|
|
170
|
+
const disconnected =
|
|
171
|
+
causeHasCoreCode(error, "subscription_core_source_disconnected") ||
|
|
172
|
+
(!!outcome &&
|
|
173
|
+
(await binding
|
|
174
|
+
.isSourceDisconnected(db, core.identity, core.connectionId)
|
|
175
|
+
.catch(() => false)));
|
|
176
|
+
if (disconnected) {
|
|
177
|
+
await joinObservations();
|
|
178
|
+
const settled = await failOverCoreSubscriptionTurn(
|
|
179
|
+
deps,
|
|
180
|
+
core,
|
|
181
|
+
"source_disconnected",
|
|
182
|
+
binding.failover,
|
|
183
|
+
);
|
|
184
|
+
if (settled) return { result: settled, failure: null };
|
|
185
|
+
} else if (outcome) {
|
|
186
|
+
await joinObservations();
|
|
187
|
+
const recorded = await recordCoreSubscriptionRefusal({
|
|
188
|
+
db,
|
|
189
|
+
provider: binding.provider,
|
|
190
|
+
core,
|
|
191
|
+
lease: binding.lease(deps),
|
|
192
|
+
outcome,
|
|
193
|
+
credential: binding.credential,
|
|
194
|
+
});
|
|
195
|
+
if (recorded.receipt && eventing.publish && attempt.turnId && eventing.turnStartedPublished) {
|
|
196
|
+
const settled = await failOverCoreSubscriptionTurn(
|
|
197
|
+
deps,
|
|
198
|
+
core,
|
|
199
|
+
{ kind: outcome.kind, unbounded: false },
|
|
200
|
+
binding.failover,
|
|
201
|
+
);
|
|
202
|
+
if (settled) return { result: settled, failure: null };
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const refusal =
|
|
206
|
+
disconnected || causeHasCoreCode(error, "subscription_core_access_lost")
|
|
207
|
+
? "access_lost"
|
|
208
|
+
: outcome?.kind === "unauthorized"
|
|
209
|
+
? "sign_in"
|
|
210
|
+
: outcome?.kind === "forbidden"
|
|
211
|
+
? "forbidden"
|
|
212
|
+
: null;
|
|
213
|
+
return {
|
|
214
|
+
result: null,
|
|
215
|
+
failure: refusal ? subscriptionCoreAccountRefusedFailure(refusal, binding.displayName) : null,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Finalization of a core turn before its lease is released: a completed
|
|
221
|
+
* model call of the conversation lane moves the binding's cache clock (a
|
|
222
|
+
* session-title request has another prompt prefix and warms no conversation
|
|
223
|
+
* cache, as for Codex). No per-turn quota call runs on the core path: quota
|
|
224
|
+
* is observed on refusal and by the out-of-turn probe.
|
|
225
|
+
*/
|
|
226
|
+
export async function finalizeCoreSubscriptionTurn(input: {
|
|
227
|
+
db: Database;
|
|
228
|
+
provider: SubscriptionCoreProvider;
|
|
229
|
+
core: SubscriptionCoreTurn;
|
|
230
|
+
lease: LeaseFence;
|
|
231
|
+
}): Promise<void> {
|
|
232
|
+
const at = input.core.requests?.lastResponseReceivedAt() ?? null;
|
|
233
|
+
await touchCoreSubscriptionBinding({ ...input, modelCallCompletedAt: at });
|
|
234
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
export type LeaseRenewReason = "timer" | "runtime_event" | "model_usage";
|
|
2
|
+
export type LeaseLossReason = "deadline" | "not_found";
|
|
3
|
+
|
|
4
|
+
const HEARTBEAT_INTERVAL_MS = 60_000;
|
|
5
|
+
|
|
6
|
+
type LeaseIdentity = { turnId: string; holderId: string; generation: number };
|
|
7
|
+
export type SubscriptionLeaseDeps = {
|
|
8
|
+
ttlMs: number;
|
|
9
|
+
getTurnId: () => string | undefined;
|
|
10
|
+
heartbeat: (identity: LeaseIdentity) => Promise<Date | null>;
|
|
11
|
+
onLost: (reason: LeaseLossReason) => void;
|
|
12
|
+
onRenewed?: (reason: LeaseRenewReason) => void;
|
|
13
|
+
onError: (error: unknown, reason: LeaseRenewReason) => void;
|
|
14
|
+
lostError: (reason: LeaseLossReason) => Error;
|
|
15
|
+
now?: () => number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** Cross-provider lease lifecycle. Only on-time DB confirmation extends ownership. */
|
|
19
|
+
export class SubscriptionTurnLease {
|
|
20
|
+
held = false;
|
|
21
|
+
lost = false;
|
|
22
|
+
lossReason: LeaseLossReason | null = null;
|
|
23
|
+
holderId: string | null = null;
|
|
24
|
+
generation: number | null = null;
|
|
25
|
+
confirmedUntilMs: number | null = null;
|
|
26
|
+
private heartbeatInFlight = false;
|
|
27
|
+
private heartbeatTimer: ReturnType<typeof setInterval> | undefined;
|
|
28
|
+
private readonly now: () => number;
|
|
29
|
+
private readonly renewalIntervalMs: number;
|
|
30
|
+
|
|
31
|
+
constructor(private readonly leaseDeps: SubscriptionLeaseDeps) {
|
|
32
|
+
if (!Number.isFinite(leaseDeps.ttlMs) || leaseDeps.ttlMs <= 0)
|
|
33
|
+
throw new Error("Subscription lease TTL must be positive");
|
|
34
|
+
this.now = leaseDeps.now ?? (() => performance.now());
|
|
35
|
+
this.renewalIntervalMs = Math.min(HEARTBEAT_INTERVAL_MS, leaseDeps.ttlMs / 5);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private expired = (deadline: number | null): boolean =>
|
|
39
|
+
deadline === null || !Number.isFinite(deadline) || this.now() >= deadline;
|
|
40
|
+
|
|
41
|
+
markLost = (reason: LeaseLossReason): void => {
|
|
42
|
+
if (this.lost) return;
|
|
43
|
+
this.lost = true;
|
|
44
|
+
this.lossReason = reason;
|
|
45
|
+
this.leaseDeps.onLost(reason);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
assertUsable = (): void => {
|
|
49
|
+
if (this.lost) throw this.leaseDeps.lostError(this.lossReason ?? "not_found");
|
|
50
|
+
if (
|
|
51
|
+
!this.held ||
|
|
52
|
+
this.holderId === null ||
|
|
53
|
+
this.generation === null ||
|
|
54
|
+
this.expired(this.confirmedUntilMs)
|
|
55
|
+
) {
|
|
56
|
+
this.markLost("deadline");
|
|
57
|
+
throw this.leaseDeps.lostError("deadline");
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
renew = async (reason: LeaseRenewReason = "timer"): Promise<void> => {
|
|
62
|
+
const turnId = this.leaseDeps.getTurnId();
|
|
63
|
+
if (!turnId || !this.held || !this.holderId || this.generation === null || this.lost) return;
|
|
64
|
+
if (this.expired(this.confirmedUntilMs)) {
|
|
65
|
+
this.markLost("deadline");
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (this.heartbeatInFlight) return;
|
|
69
|
+
// Acquisition and successful renewal confirm ownership from request start.
|
|
70
|
+
// Reuse that proof between heartbeats; a failed renewal leaves it unchanged
|
|
71
|
+
// so the next checkpoint can retry immediately. Expiry is checked first.
|
|
72
|
+
const renewAt = this.confirmedUntilMs! - this.leaseDeps.ttlMs + this.renewalIntervalMs;
|
|
73
|
+
if (this.now() < renewAt) return;
|
|
74
|
+
this.heartbeatInFlight = true;
|
|
75
|
+
const priorDeadline = this.confirmedUntilMs;
|
|
76
|
+
const startedAt = this.now();
|
|
77
|
+
const identity = { turnId, holderId: this.holderId, generation: this.generation };
|
|
78
|
+
try {
|
|
79
|
+
const renewedUntil = await this.leaseDeps.heartbeat(identity);
|
|
80
|
+
// A late confirmation is not proof of uninterrupted ownership, even if
|
|
81
|
+
// Postgres extended the row. A changed holder must also discard its reply.
|
|
82
|
+
if (
|
|
83
|
+
!this.held ||
|
|
84
|
+
this.lost ||
|
|
85
|
+
this.leaseDeps.getTurnId() !== identity.turnId ||
|
|
86
|
+
this.holderId !== identity.holderId ||
|
|
87
|
+
this.generation !== identity.generation
|
|
88
|
+
)
|
|
89
|
+
return;
|
|
90
|
+
if (!renewedUntil) this.markLost("not_found");
|
|
91
|
+
else if (this.expired(priorDeadline) || this.expired(startedAt + this.leaseDeps.ttlMs))
|
|
92
|
+
this.markLost("deadline");
|
|
93
|
+
else {
|
|
94
|
+
this.confirmedUntilMs = startedAt + this.leaseDeps.ttlMs;
|
|
95
|
+
this.leaseDeps.onRenewed?.(reason);
|
|
96
|
+
}
|
|
97
|
+
} catch (error) {
|
|
98
|
+
if (
|
|
99
|
+
!this.held ||
|
|
100
|
+
this.lost ||
|
|
101
|
+
this.leaseDeps.getTurnId() !== identity.turnId ||
|
|
102
|
+
this.holderId !== identity.holderId ||
|
|
103
|
+
this.generation !== identity.generation
|
|
104
|
+
)
|
|
105
|
+
return;
|
|
106
|
+
if (this.expired(this.confirmedUntilMs)) this.markLost("deadline");
|
|
107
|
+
else this.leaseDeps.onError(error, reason);
|
|
108
|
+
} finally {
|
|
109
|
+
this.heartbeatInFlight = false;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
startHeartbeat = (): void => {
|
|
114
|
+
if (!this.leaseDeps.getTurnId() || this.heartbeatTimer) return;
|
|
115
|
+
this.heartbeatTimer = setInterval(() => void this.renew("timer"), HEARTBEAT_INTERVAL_MS);
|
|
116
|
+
this.heartbeatTimer.unref?.();
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
stopHeartbeat = (): void => {
|
|
120
|
+
if (!this.heartbeatTimer) return;
|
|
121
|
+
clearInterval(this.heartbeatTimer);
|
|
122
|
+
this.heartbeatTimer = undefined;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** One turn attempt's core lease holder for a provider (`<provider>-turn:<attempt>`). */
|
|
127
|
+
export function subscriptionTurnLeaseHolderId(
|
|
128
|
+
provider: string,
|
|
129
|
+
displayName: string,
|
|
130
|
+
input: { workflowId: string; attemptId: string },
|
|
131
|
+
turnId: string,
|
|
132
|
+
): string {
|
|
133
|
+
const parts = [input.workflowId, turnId, input.attemptId];
|
|
134
|
+
if (parts.some((part) => part.trim().length === 0)) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
`${displayName} credential lease holder requires a complete turn attempt identity`,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
return `${provider}-turn:${parts.map((part) => encodeURIComponent(part)).join(":")}`;
|
|
140
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import {
|
|
2
|
+
placeSubscriptionCoreTurnWithFailover,
|
|
3
|
+
subscriptionCoreProvider,
|
|
4
|
+
releaseSubscriptionTurnLease,
|
|
5
|
+
withSubscriptionCoreAcceptedTurn,
|
|
6
|
+
recordSubscriptionCoreServingPolicyForTurnAttempt,
|
|
7
|
+
recordSubscriptionCoreServingSelectionForTurnAttempt,
|
|
8
|
+
requestSessionTurnRecovery,
|
|
9
|
+
SubscriptionCoreServingFailoverLimitError,
|
|
10
|
+
SUBSCRIPTION_CORE_SERVING_FAILOVER_LIMIT,
|
|
11
|
+
} from "@opengeni/db";
|
|
12
|
+
import { publishDurableSessionEvents } from "@opengeni/events";
|
|
13
|
+
import { servingTurnProviders } from "./subscription-serving-providers";
|
|
14
|
+
import {
|
|
15
|
+
noServingModelMapping,
|
|
16
|
+
servingPolicyForSelection,
|
|
17
|
+
type ServingAttempt,
|
|
18
|
+
} from "./subscription-serving-claim";
|
|
19
|
+
import { selectCoreSubscriptionTurnCapacity } from "./subscription-core-capacity";
|
|
20
|
+
import { subscriptionTurnLeaseHolderId } from "./subscription-lease";
|
|
21
|
+
import {
|
|
22
|
+
subscriptionCoreUnsupportedFailure,
|
|
23
|
+
subscriptionCoreServingFailoverExhaustedFailure,
|
|
24
|
+
} from "./codex-core-errors";
|
|
25
|
+
import type { CapacityPhaseDeps, CapacityPhaseOutcome } from "./codex-capacity";
|
|
26
|
+
|
|
27
|
+
/** Between-attempt switch only: placement has committed before any provenance
|
|
28
|
+
* or recovery writer runs. No model/tool call has started at this phase.
|
|
29
|
+
*/
|
|
30
|
+
export async function selectServingTurnCapacity(
|
|
31
|
+
deps: CapacityPhaseDeps,
|
|
32
|
+
context: ServingAttempt,
|
|
33
|
+
): Promise<CapacityPhaseOutcome> {
|
|
34
|
+
const servingId = context.models.find(
|
|
35
|
+
(model) => model.id === deps.turnExecutionPolicy.productModelId,
|
|
36
|
+
)?.provider;
|
|
37
|
+
const provider = servingTurnProviders().find((candidate) => candidate.id === servingId);
|
|
38
|
+
if (!provider)
|
|
39
|
+
throw subscriptionCoreUnsupportedFailure("Serving provider runtime", "Model account");
|
|
40
|
+
const lease = provider.lease(deps);
|
|
41
|
+
lease.holderId ??= subscriptionTurnLeaseHolderId(
|
|
42
|
+
provider.id,
|
|
43
|
+
provider.displayName,
|
|
44
|
+
deps.input,
|
|
45
|
+
context.identity.turnId,
|
|
46
|
+
);
|
|
47
|
+
await provider.recoverHealth(deps, context.identity);
|
|
48
|
+
await provider.beforePlacement?.(deps, context.identity);
|
|
49
|
+
const placement = await placeSubscriptionCoreTurnWithFailover(
|
|
50
|
+
deps.db,
|
|
51
|
+
subscriptionCoreProvider(context.homeProviderId),
|
|
52
|
+
{
|
|
53
|
+
identity: context.identity,
|
|
54
|
+
attemptId: deps.input.attemptId,
|
|
55
|
+
executionGeneration: deps.attempt.executionGeneration,
|
|
56
|
+
holderId: lease.holderId,
|
|
57
|
+
leaseTtlMs: provider.leaseTtlMs,
|
|
58
|
+
models: context.models,
|
|
59
|
+
crossProviderFailoverEnabled: true,
|
|
60
|
+
productModelId: context.acceptedPolicy.productModelId,
|
|
61
|
+
reasoningLevel: context.acceptedPolicy.reasoningEffort,
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
if (placement.kind === "wait") {
|
|
65
|
+
if (placement.reason === "failover_no_model_mapping") throw noServingModelMapping();
|
|
66
|
+
// Wait against the accepted home provider, not the previous serving
|
|
67
|
+
// provider. Fresh candidate hints wake this exact frozen turn on capacity
|
|
68
|
+
// changes elsewhere; reconciliation never treats those hints as authority.
|
|
69
|
+
const home = servingTurnProviders().find(
|
|
70
|
+
(candidate) => candidate.id === context.homeProviderId,
|
|
71
|
+
);
|
|
72
|
+
if (!home?.park)
|
|
73
|
+
throw subscriptionCoreUnsupportedFailure("Cross-provider capacity waiting", "Model account");
|
|
74
|
+
return home.park(deps, {
|
|
75
|
+
...placement,
|
|
76
|
+
reason: placement.reason,
|
|
77
|
+
candidateProviders: placement.candidateProviders ?? [],
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (placement.kind === "run") {
|
|
81
|
+
const modelId = placement.modelId ?? context.acceptedPolicy.productModelId;
|
|
82
|
+
const targetPolicy = servingPolicyForSelection(
|
|
83
|
+
deps.settings,
|
|
84
|
+
context.acceptedPolicy,
|
|
85
|
+
modelId,
|
|
86
|
+
placement.reasoningLevel ?? context.acceptedPolicy.reasoningEffort,
|
|
87
|
+
);
|
|
88
|
+
if (!context.revision) {
|
|
89
|
+
// Claim had no available account. Before dispatch, establish the accepted
|
|
90
|
+
// baseline; the connection is advisory, not permission to dispatch.
|
|
91
|
+
const baseline = await recordSubscriptionCoreServingPolicyForTurnAttempt(deps.db, {
|
|
92
|
+
...context.identity,
|
|
93
|
+
attemptId: deps.input.attemptId,
|
|
94
|
+
executionGeneration: deps.attempt.executionGeneration,
|
|
95
|
+
crossProviderFailoverEnabled: true,
|
|
96
|
+
policy: deps.turnExecutionPolicy,
|
|
97
|
+
connectionId: placement.connectionId,
|
|
98
|
+
reason: "initial",
|
|
99
|
+
});
|
|
100
|
+
if (!baseline.accepted) throw new Error(`Serving baseline refused: ${baseline.reason}`);
|
|
101
|
+
context.revision = baseline.revision;
|
|
102
|
+
}
|
|
103
|
+
if (
|
|
104
|
+
targetPolicy.productModelId !== deps.turnExecutionPolicy.productModelId ||
|
|
105
|
+
targetPolicy.providerId !== deps.turnExecutionPolicy.providerId
|
|
106
|
+
) {
|
|
107
|
+
const released = await withSubscriptionCoreAcceptedTurn(deps.db, context.identity, (tx) =>
|
|
108
|
+
releaseSubscriptionTurnLease(tx, {
|
|
109
|
+
...context.identity,
|
|
110
|
+
provider: placement.provider ?? context.homeProviderId,
|
|
111
|
+
connectionId: placement.connectionId,
|
|
112
|
+
holderId: lease.holderId!,
|
|
113
|
+
generation: deps.attempt.executionGeneration,
|
|
114
|
+
}),
|
|
115
|
+
);
|
|
116
|
+
if (released.status !== "completed") throw new Error("Serving recovery lost accepted turn");
|
|
117
|
+
const recovery = await requestSessionTurnRecovery(deps.db, deps.input.workspaceId, {
|
|
118
|
+
sessionId: deps.input.sessionId,
|
|
119
|
+
turnId: context.identity.turnId,
|
|
120
|
+
triggerEventId: deps.turn.triggerEventId,
|
|
121
|
+
attemptId: deps.input.attemptId,
|
|
122
|
+
reason: "subscription_serving_model_changed",
|
|
123
|
+
subscriptionServingTarget: {
|
|
124
|
+
crossProviderFailoverEnabled: true,
|
|
125
|
+
executionGeneration: deps.attempt.executionGeneration,
|
|
126
|
+
policy: targetPolicy,
|
|
127
|
+
connectionId: placement.connectionId,
|
|
128
|
+
reason: placement.switch,
|
|
129
|
+
},
|
|
130
|
+
}).catch((error: unknown) => {
|
|
131
|
+
// The turn-locked writer is authoritative, including concurrent
|
|
132
|
+
// refusal receipts. Its transaction rolls back; no target is staged.
|
|
133
|
+
if (error instanceof SubscriptionCoreServingFailoverLimitError)
|
|
134
|
+
throw subscriptionCoreServingFailoverExhaustedFailure(
|
|
135
|
+
error.steps,
|
|
136
|
+
SUBSCRIPTION_CORE_SERVING_FAILOVER_LIMIT,
|
|
137
|
+
);
|
|
138
|
+
throw error;
|
|
139
|
+
});
|
|
140
|
+
if (recovery.action !== "recovering") {
|
|
141
|
+
deps.acknowledgeLostAttemptOwnership();
|
|
142
|
+
return { exit: deps.claimedResult({ status: "cancelled" }) };
|
|
143
|
+
}
|
|
144
|
+
deps.acknowledgeRecoveryQuiescence();
|
|
145
|
+
await publishDurableSessionEvents(
|
|
146
|
+
deps.bus,
|
|
147
|
+
deps.input.workspaceId,
|
|
148
|
+
deps.input.sessionId,
|
|
149
|
+
recovery.events,
|
|
150
|
+
);
|
|
151
|
+
deps.control.activityStatus = "recovering";
|
|
152
|
+
deps.control.turnMetricOutcome = "recovering";
|
|
153
|
+
return { exit: deps.claimedResult({ status: "recovering" }) };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Preserve provider-specific adoption, guarded credentials, heartbeat and
|
|
157
|
+
// selection alias. The placement result is already committed; do not place twice.
|
|
158
|
+
return selectCoreSubscriptionTurnCapacity(deps, {
|
|
159
|
+
...provider,
|
|
160
|
+
recoverHealth: async () => {},
|
|
161
|
+
beforePlacement: async () => {},
|
|
162
|
+
recordSelection: async (selectionDeps, selected, turnId) => {
|
|
163
|
+
const receipt = await recordSubscriptionCoreServingSelectionForTurnAttempt(deps.db, {
|
|
164
|
+
...context.identity,
|
|
165
|
+
turnId,
|
|
166
|
+
attemptId: deps.input.attemptId,
|
|
167
|
+
executionGeneration: deps.attempt.executionGeneration,
|
|
168
|
+
provider: provider.id,
|
|
169
|
+
connectionId: selected.connectionId,
|
|
170
|
+
modelId: deps.turnExecutionPolicy.productModelId,
|
|
171
|
+
reason: selected.switch,
|
|
172
|
+
});
|
|
173
|
+
await publishDurableSessionEvents(
|
|
174
|
+
deps.bus,
|
|
175
|
+
deps.input.workspaceId,
|
|
176
|
+
deps.input.sessionId,
|
|
177
|
+
receipt.events,
|
|
178
|
+
);
|
|
179
|
+
// Preserve the legacy alias for same-provider moves, not for a return
|
|
180
|
+
// from another provider to an old binding that happened to exist here.
|
|
181
|
+
await provider.recordSelection?.(
|
|
182
|
+
selectionDeps,
|
|
183
|
+
{
|
|
184
|
+
...selected,
|
|
185
|
+
previousConnectionId:
|
|
186
|
+
receipt.previousProvider !== null && receipt.previousProvider !== provider.id
|
|
187
|
+
? null
|
|
188
|
+
: selected.previousConnectionId,
|
|
189
|
+
},
|
|
190
|
+
turnId,
|
|
191
|
+
);
|
|
192
|
+
},
|
|
193
|
+
place: async () => placement,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
configuredModels,
|
|
3
|
+
withCodexCatalogProvider,
|
|
4
|
+
withXaiSubscriptionCatalogProvider,
|
|
5
|
+
type Settings,
|
|
6
|
+
} from "@opengeni/config";
|
|
7
|
+
import { resolveWorkspaceCatalogSettings } from "@opengeni/core";
|
|
8
|
+
import {
|
|
9
|
+
subscriptionCoreProvider,
|
|
10
|
+
type Database,
|
|
11
|
+
type SubscriptionCoreFailoverModel,
|
|
12
|
+
type SubscriptionCoreTurnIdentity,
|
|
13
|
+
} from "@opengeni/db";
|
|
14
|
+
import { subscriptionCoreModelPolicyProviderIds } from "@opengeni/subscriptions";
|
|
15
|
+
|
|
16
|
+
/** Shared by live placement and durable-wait evaluation, without importing
|
|
17
|
+
* provider runtime hooks into the control worker. Catalog entries are not
|
|
18
|
+
* authority: the core rechecks every candidate against accepted and live scope.
|
|
19
|
+
*/
|
|
20
|
+
export function servingCatalog(
|
|
21
|
+
settings: Settings,
|
|
22
|
+
providerIds: readonly string[],
|
|
23
|
+
): SubscriptionCoreFailoverModel[] {
|
|
24
|
+
return configuredModels(settings).flatMap((model) => {
|
|
25
|
+
if (model.billing.metering !== "external" || model.credentialSource.kind === "deployment")
|
|
26
|
+
return [];
|
|
27
|
+
const matches = providerIds.filter((id) =>
|
|
28
|
+
subscriptionCoreModelPolicyProviderIds(
|
|
29
|
+
subscriptionCoreProvider(id).adapter,
|
|
30
|
+
model.id,
|
|
31
|
+
).includes(model.providerId),
|
|
32
|
+
);
|
|
33
|
+
if (matches.length > 1) throw new Error("Ambiguous serving catalog provider");
|
|
34
|
+
const provider = matches[0];
|
|
35
|
+
return provider
|
|
36
|
+
? [
|
|
37
|
+
{
|
|
38
|
+
id: model.id,
|
|
39
|
+
provider,
|
|
40
|
+
upstreamModelId: model.upstreamModelId,
|
|
41
|
+
reasoningLevels: model.capabilities.reasoning.efforts.length
|
|
42
|
+
? [...model.capabilities.reasoning.efforts]
|
|
43
|
+
: ["none"],
|
|
44
|
+
},
|
|
45
|
+
]
|
|
46
|
+
: [];
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The control worker has raw deployment settings, not claim's credential
|
|
51
|
+
* overlays. Resolve the same current model definitions without loading keys
|
|
52
|
+
* or filtering exhausted accounts out of the catalog. Core placement owns
|
|
53
|
+
* authority/readiness, independently of catalog membership.
|
|
54
|
+
*/
|
|
55
|
+
export async function servingCatalogForBlockedTurn(
|
|
56
|
+
db: Database,
|
|
57
|
+
settings: Settings,
|
|
58
|
+
identity: SubscriptionCoreTurnIdentity,
|
|
59
|
+
productModelId: string,
|
|
60
|
+
providerIds: readonly string[],
|
|
61
|
+
): Promise<SubscriptionCoreFailoverModel[]> {
|
|
62
|
+
const resolved = await resolveWorkspaceCatalogSettings(db, settings, {
|
|
63
|
+
accountId: identity.accountId,
|
|
64
|
+
workspaceId: identity.workspaceId,
|
|
65
|
+
retainedProductModelId: productModelId,
|
|
66
|
+
});
|
|
67
|
+
let catalog = resolved.settings;
|
|
68
|
+
if (catalog.codexSubscriptionEnabled) catalog = withCodexCatalogProvider(catalog);
|
|
69
|
+
if (catalog.supergrokSubscriptionEnabled) catalog = withXaiSubscriptionCatalogProvider(catalog);
|
|
70
|
+
return servingCatalog(catalog, providerIds);
|
|
71
|
+
}
|