@opengeni/worker-bundle 2.0.1 → 2.0.2-canary.38789554071001
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 +185 -26
- 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 +4 -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 +31 -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-5IIVRXLA.js} +1569 -2883
- package/dist/activities-control-5IIVRXLA.js.map +1 -0
- package/dist/activities-control.d.ts +64 -4
- package/dist/{activities-turn-YVVKCGAK.js → activities-turn-FLYJOM54.js} +9300 -4403
- package/dist/activities-turn-FLYJOM54.js.map +1 -0
- package/dist/activities.d.ts +64 -4
- package/dist/artifact-materializer-entry.js +107 -36
- 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-MVESOYFC.js +3746 -0
- package/dist/chunk-MVESOYFC.js.map +1 -0
- package/dist/{chunk-M3NVMF2V.js → chunk-N57B3PJ5.js} +2307 -3951
- package/dist/chunk-N57B3PJ5.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 +1152 -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 +42 -12
- 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 +114 -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 +634 -111
- 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 +182 -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 +124 -9
- package/src/activities/sandbox-lease.ts +1615 -73
- package/src/activities/scheduled-tasks.ts +780 -147
- 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 +85 -39
- 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,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex chat-turn placement on the shared subscription core (M3 PR 1,
|
|
3
|
+
* inventory EP-T01..T05): the provider-neutral placement
|
|
4
|
+
* (`subscription-core-capacity.ts`) bound to Codex, under the names M3
|
|
5
|
+
* shipped. Reached only when the organization's Codex cutover row is
|
|
6
|
+
* enabled; missing or disabled cutover state fails closed.
|
|
7
|
+
*/
|
|
8
|
+
import {
|
|
9
|
+
assertModelConnectionAllowsTurn,
|
|
10
|
+
CODEX_CREDENTIAL_LEASE_TTL_MS,
|
|
11
|
+
CodexCredentialLeaseAttemptFencedError,
|
|
12
|
+
SubscriptionCoreCodexLeaseLostError,
|
|
13
|
+
SubscriptionCoreCodexSourceDisconnectedError,
|
|
14
|
+
isSubscriptionCoreCodexSourceDisconnected,
|
|
15
|
+
buildSubscriptionCoreCodexTokenResolver,
|
|
16
|
+
placeSubscriptionCoreCodexTurn,
|
|
17
|
+
recordSubscriptionCoreCodexSelectionForTurnAttempt,
|
|
18
|
+
type CodexCredentialTokenSnapshot,
|
|
19
|
+
type Database,
|
|
20
|
+
type SubscriptionCoreCodexPlacement,
|
|
21
|
+
} from "@opengeni/db";
|
|
22
|
+
import type { Settings } from "@opengeni/config";
|
|
23
|
+
import { refreshCoreCodexModelEntitlements } from "@opengeni/core";
|
|
24
|
+
import { publishDurableSessionEvents } from "@opengeni/events";
|
|
25
|
+
import {
|
|
26
|
+
CODEX_CORE_WAIT_BINDING,
|
|
27
|
+
recoverCoreCodexHealthAndWake,
|
|
28
|
+
wakeSubscriptionCoreCodexWaitersAndDeliver,
|
|
29
|
+
type CoreCodexWakeServices,
|
|
30
|
+
} from "../subscription-core-codex-waits";
|
|
31
|
+
import type { CapacityPhaseDeps, CapacityPhaseOutcome } from "./codex-capacity";
|
|
32
|
+
import type { CodexTurnLease } from "./credential-leases";
|
|
33
|
+
import {
|
|
34
|
+
assertCoreSourceConnected,
|
|
35
|
+
coreLeaseRef,
|
|
36
|
+
guardCoreTokenResolver,
|
|
37
|
+
parkCoreSubscriptionTurn,
|
|
38
|
+
selectCoreSubscriptionTurnCapacity,
|
|
39
|
+
type CoreTurnPlacementProvider,
|
|
40
|
+
} from "./subscription-core-capacity";
|
|
41
|
+
import type { CodexSubscriptionCoreTurn, ProviderTurnState } from "./turn-context";
|
|
42
|
+
|
|
43
|
+
export function isCoreCodexSourceDisconnectedError(error: unknown): boolean {
|
|
44
|
+
let current = error;
|
|
45
|
+
for (let depth = 0; depth < 8 && current instanceof Error; depth++) {
|
|
46
|
+
if (current instanceof SubscriptionCoreCodexSourceDisconnectedError) return true;
|
|
47
|
+
current = current.cause;
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Codex's chat placement on the shared core. */
|
|
53
|
+
export const CODEX_CORE_TURN_PROVIDER: CoreTurnPlacementProvider = {
|
|
54
|
+
id: "codex",
|
|
55
|
+
displayName: "Codex",
|
|
56
|
+
startupPhaseProvider: "codex-subscription",
|
|
57
|
+
leaseTtlMs: CODEX_CREDENTIAL_LEASE_TTL_MS,
|
|
58
|
+
lease: (deps) => deps.leases.codex,
|
|
59
|
+
place: (db, request) => placeSubscriptionCoreCodexTurn(db, request),
|
|
60
|
+
// A recovery wakes the account's other waiters too.
|
|
61
|
+
recoverHealth: async ({ db, signalCodexCapacityWorkflow }, identity) => {
|
|
62
|
+
await recoverCoreCodexHealthAndWake({ db, signalCodexCapacityWorkflow }, identity);
|
|
63
|
+
},
|
|
64
|
+
beforePlacement: (deps, identity) =>
|
|
65
|
+
refreshCoreCodexModelEntitlements(deps.db, deps.settings, {
|
|
66
|
+
accountId: deps.input.accountId,
|
|
67
|
+
workspaceId: deps.input.workspaceId,
|
|
68
|
+
subjectId: identity.initiatingHumanSubjectId,
|
|
69
|
+
}),
|
|
70
|
+
adopt: ({ providerTurn, turnExecutionPolicy }, core, placement) => {
|
|
71
|
+
providerTurn.codexSubscriptionCore = core;
|
|
72
|
+
providerTurn.effectiveCodexCredentialId = placement.connectionId;
|
|
73
|
+
providerTurn.codexProductModelId = turnExecutionPolicy.productModelId;
|
|
74
|
+
providerTurn.codexPolicySnapshot = null;
|
|
75
|
+
// In-turn re-placement after a refusal arrives with the core failover
|
|
76
|
+
// bound (PR 2); this turn never walks to a second account.
|
|
77
|
+
providerTurn.codexCredentialFailoverLimit = 1;
|
|
78
|
+
},
|
|
79
|
+
recordSelection: async (deps, placement, turnId) => {
|
|
80
|
+
const { input, db, bus, observability, attempt, codexWorkspaceKey } = deps;
|
|
81
|
+
const receipt = await recordSubscriptionCoreCodexSelectionForTurnAttempt(db, {
|
|
82
|
+
workspaceId: input.workspaceId,
|
|
83
|
+
sessionId: input.sessionId,
|
|
84
|
+
turnId,
|
|
85
|
+
attemptId: input.attemptId,
|
|
86
|
+
executionGeneration: attempt.executionGeneration,
|
|
87
|
+
credentialId: placement.connectionId,
|
|
88
|
+
previousCredentialId: placement.previousConnectionId,
|
|
89
|
+
strategy: placement.rotationMode,
|
|
90
|
+
reusedLease: placement.reusedLease,
|
|
91
|
+
pinnedCredentialId: placement.explicit ? placement.connectionId : null,
|
|
92
|
+
eligibleCount: placement.eligibleCount,
|
|
93
|
+
connectedCount: placement.connectedCount,
|
|
94
|
+
});
|
|
95
|
+
await publishDurableSessionEvents(bus, input.workspaceId, input.sessionId, receipt.events);
|
|
96
|
+
observability.incrementCounter({
|
|
97
|
+
name: "opengeni_codex_credential_selections_total",
|
|
98
|
+
help: "Codex credential selections by strategy and reason.",
|
|
99
|
+
labels: {
|
|
100
|
+
workspace_key: codexWorkspaceKey,
|
|
101
|
+
strategy: `core_${placement.rotationMode}`,
|
|
102
|
+
reason: receipt.diagnostics.reason,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
park: (deps, wait) => parkCoreCodexTurn(deps, wait),
|
|
107
|
+
isSourceDisconnected: (db, identity, connectionId) =>
|
|
108
|
+
isSubscriptionCoreCodexSourceDisconnected(db, identity, connectionId),
|
|
109
|
+
sourceDisconnectedError: () => new SubscriptionCoreCodexSourceDisconnectedError(),
|
|
110
|
+
isAttemptFenced: (error) => error instanceof CodexCredentialLeaseAttemptFencedError,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/** Lifecycle disappearance is not an auth refusal or an ordinary account pause. */
|
|
114
|
+
export async function assertCoreCodexSourceConnected(
|
|
115
|
+
db: Database,
|
|
116
|
+
core: CodexSubscriptionCoreTurn,
|
|
117
|
+
): Promise<void> {
|
|
118
|
+
await assertCoreSourceConnected(db, CODEX_CORE_TURN_PROVIDER, core);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The turn's model-connection check. A shared-core placement already
|
|
123
|
+
* enforced the connection's model allowlist, entitlement exclusions and the
|
|
124
|
+
* workspace model policy in the same transaction as its lease; the legacy
|
|
125
|
+
* check reads legacy rows and must never see a core connection id.
|
|
126
|
+
*/
|
|
127
|
+
export async function assertTurnModelConnection(
|
|
128
|
+
db: Database,
|
|
129
|
+
providerTurn: Pick<ProviderTurnState, "codexSubscriptionCore"> &
|
|
130
|
+
Partial<Pick<ProviderTurnState, "xaiSubscriptionCore" | "claudeSubscriptionCore">>,
|
|
131
|
+
input: Parameters<typeof assertModelConnectionAllowsTurn>[1],
|
|
132
|
+
): Promise<void> {
|
|
133
|
+
if (
|
|
134
|
+
providerTurn.codexSubscriptionCore ||
|
|
135
|
+
providerTurn.xaiSubscriptionCore ||
|
|
136
|
+
providerTurn.claudeSubscriptionCore
|
|
137
|
+
)
|
|
138
|
+
return;
|
|
139
|
+
await assertModelConnectionAllowsTurn(db, input);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* The bearer resolver for a core-placed turn (EP-T03): the same snapshot
|
|
144
|
+
* shape as the legacy resolver, but every read and refresh goes through the
|
|
145
|
+
* exact accepted turn and this attempt's live core lease. A lost lease marks
|
|
146
|
+
* the local holder lost, so dispatch stops with the ordinary lease-loss error.
|
|
147
|
+
*/
|
|
148
|
+
export function buildCoreCodexRequestTokenResolver(
|
|
149
|
+
db: Database,
|
|
150
|
+
settings: Settings,
|
|
151
|
+
core: CodexSubscriptionCoreTurn,
|
|
152
|
+
lease: CodexTurnLease,
|
|
153
|
+
wake?: Pick<CoreCodexWakeServices, "signalCodexCapacityWorkflow">,
|
|
154
|
+
): {
|
|
155
|
+
getToken: () => Promise<CodexCredentialTokenSnapshot>;
|
|
156
|
+
refresh: () => Promise<CodexCredentialTokenSnapshot>;
|
|
157
|
+
} {
|
|
158
|
+
const ref = coreLeaseRef(lease, core, "Codex");
|
|
159
|
+
const resolver = buildSubscriptionCoreCodexTokenResolver(db, settings, core.identity, ref, {
|
|
160
|
+
// A rotated id_token reporting a new plan cleared the connection's
|
|
161
|
+
// model cooldowns in the same commit; waiters may now place (EP-T10).
|
|
162
|
+
onPlanChanged: () =>
|
|
163
|
+
void wakeSubscriptionCoreCodexWaitersAndDeliver(
|
|
164
|
+
{ db, signalCodexCapacityWorkflow: wake?.signalCodexCapacityWorkflow },
|
|
165
|
+
{ accountId: core.identity.accountId, reason: "plan_changed" },
|
|
166
|
+
),
|
|
167
|
+
});
|
|
168
|
+
return guardCoreTokenResolver(
|
|
169
|
+
db,
|
|
170
|
+
CODEX_CORE_TURN_PROVIDER,
|
|
171
|
+
core,
|
|
172
|
+
lease,
|
|
173
|
+
resolver,
|
|
174
|
+
(error) => error instanceof SubscriptionCoreCodexLeaseLostError,
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export async function selectCoreCodexTurnCapacity(
|
|
179
|
+
deps: CapacityPhaseDeps,
|
|
180
|
+
): Promise<CapacityPhaseOutcome> {
|
|
181
|
+
return await selectCoreSubscriptionTurnCapacity(deps, CODEX_CORE_TURN_PROVIDER);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Park on the durable core waiter (the shared park, Codex's waiter entry points). */
|
|
185
|
+
async function parkCoreCodexTurn(
|
|
186
|
+
deps: CapacityPhaseDeps,
|
|
187
|
+
wait: Extract<SubscriptionCoreCodexPlacement, { kind: "wait" }>,
|
|
188
|
+
): Promise<CapacityPhaseOutcome> {
|
|
189
|
+
return await parkCoreSubscriptionTurn(deps, wait, CODEX_CORE_WAIT_BINDING, "Codex");
|
|
190
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claim-time Codex cutover handling (M3 PR 1). An organization whose Codex
|
|
3
|
+
* cutover row exists (enabled or disabled) must not have its turns read the
|
|
4
|
+
* legacy Codex tables at claim: not the active-credential flag for its Codex
|
|
5
|
+
* turns, and not the legacy Codex Apps designation for any turn.
|
|
6
|
+
*/
|
|
7
|
+
import { readSubscriptionProviderCutoverState, withRlsContext, type Database } from "@opengeni/db";
|
|
8
|
+
|
|
9
|
+
export type ClaimCodexCutoverState = "not_configured" | "disabled" | "enabled";
|
|
10
|
+
|
|
11
|
+
/** Same bound as the legacy active-credential read it stands in for. */
|
|
12
|
+
export const CLAIM_CODEX_CUTOVER_READ_ATTEMPTS = 3;
|
|
13
|
+
export const CLAIM_CODEX_CUTOVER_READ_RETRY_MS = 50;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Read the account's Codex cutover row. Only a thrown (transient) read is
|
|
17
|
+
* retried; a returned state is authoritative. Persistent failure surfaces
|
|
18
|
+
* the error rather than guessing a state.
|
|
19
|
+
*/
|
|
20
|
+
export async function readClaimCodexCutoverState(
|
|
21
|
+
db: Database,
|
|
22
|
+
input: { accountId: string; workspaceId: string },
|
|
23
|
+
options: { attempts?: number; retryMs?: number } = {},
|
|
24
|
+
): Promise<ClaimCodexCutoverState> {
|
|
25
|
+
const attempts = options.attempts ?? CLAIM_CODEX_CUTOVER_READ_ATTEMPTS;
|
|
26
|
+
const retryMs = options.retryMs ?? CLAIM_CODEX_CUTOVER_READ_RETRY_MS;
|
|
27
|
+
let lastError: unknown;
|
|
28
|
+
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
29
|
+
try {
|
|
30
|
+
return await withRlsContext(
|
|
31
|
+
db,
|
|
32
|
+
{ accountId: input.accountId, workspaceId: input.workspaceId },
|
|
33
|
+
(scoped) =>
|
|
34
|
+
readSubscriptionProviderCutoverState(scoped, {
|
|
35
|
+
accountId: input.accountId,
|
|
36
|
+
provider: "codex",
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
lastError = error;
|
|
41
|
+
if (attempt < attempts - 1) {
|
|
42
|
+
await new Promise((resolve) => setTimeout(resolve, retryMs * (attempt + 1)));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The stored shared-core lease-busy chain, ignoring anything malformed. */
|
|
50
|
+
export function readSubscriptionLeaseBusyChain(
|
|
51
|
+
metadata: Record<string, unknown> | null | undefined,
|
|
52
|
+
): { startedAt: number; executionGeneration: number } | undefined {
|
|
53
|
+
const value = metadata?.subscriptionLeaseBusy;
|
|
54
|
+
if (!value || typeof value !== "object") return undefined;
|
|
55
|
+
const record = value as Record<string, unknown>;
|
|
56
|
+
const startedAt =
|
|
57
|
+
typeof record.startedAt === "string" ? Date.parse(record.startedAt) : Number.NaN;
|
|
58
|
+
const generation = record.executionGeneration;
|
|
59
|
+
return Number.isFinite(startedAt) &&
|
|
60
|
+
typeof generation === "number" &&
|
|
61
|
+
Number.isSafeInteger(generation) &&
|
|
62
|
+
generation > 0
|
|
63
|
+
? { startedAt, executionGeneration: generation }
|
|
64
|
+
: undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Only an enabled cutover resolves the core Codex Apps designation; a
|
|
69
|
+
* disabled row resolves none (maintenance, fail closed).
|
|
70
|
+
*/
|
|
71
|
+
export function claimMayResolveCoreCodexApps(input: {
|
|
72
|
+
codexConnectedAppsEnabled: boolean;
|
|
73
|
+
cutover: ClaimCodexCutoverState;
|
|
74
|
+
}): boolean {
|
|
75
|
+
return input.codexConnectedAppsEnabled && input.cutover === "enabled";
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Only an enabled cutover installs Codex; the core decides availability at placement.
|
|
80
|
+
*/
|
|
81
|
+
export function claimCodexActiveFromCutover(cutover: ClaimCodexCutoverState): boolean {
|
|
82
|
+
return cutover === "enabled";
|
|
83
|
+
}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { CODEX_CREDENTIAL_LEASE_TTL_MS } from "@opengeni/db";
|
|
2
|
+
import {
|
|
3
|
+
subscriptionCapacityWaitReasonText,
|
|
4
|
+
subscriptionCapacityWaitNeedsAction,
|
|
5
|
+
type WaitReason,
|
|
6
|
+
} from "@opengeni/subscriptions";
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Failures of a chat turn on the shared subscription core, for any provider.
|
|
10
|
+
* The codes are provider-neutral; the copy names the provider, and every
|
|
11
|
+
* builder defaults to Codex, so Codex callers and texts are unchanged (M3
|
|
12
|
+
* shipped these as Codex failures). Other providers pass their display name.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** The provider name in failure copy when a caller passes none (M3's Codex texts). */
|
|
16
|
+
const DEFAULT_DISPLAY_NAME = "Codex";
|
|
17
|
+
|
|
18
|
+
/** Typed, user-readable failure for a turn on the shared subscription core. */
|
|
19
|
+
export type SubscriptionCoreCodexFailurePayload = {
|
|
20
|
+
error: string;
|
|
21
|
+
code:
|
|
22
|
+
| "subscription_capacity_unavailable"
|
|
23
|
+
| "subscription_lease_busy"
|
|
24
|
+
| "subscription_core_unsupported"
|
|
25
|
+
| "subscription_core_cutover_disabled"
|
|
26
|
+
| "subscription_account_refused"
|
|
27
|
+
| "subscription_failover_exhausted";
|
|
28
|
+
retryable: boolean;
|
|
29
|
+
detail?: string;
|
|
30
|
+
/** Placement wait reason when `code` is `subscription_capacity_unavailable`. */
|
|
31
|
+
waitReason?: WaitReason;
|
|
32
|
+
/** Refusal class when `code` is `subscription_account_refused`. */
|
|
33
|
+
refusal?: SubscriptionCoreAccountRefusal;
|
|
34
|
+
/** ISO time the earliest known capacity returns, when placement knows it. */
|
|
35
|
+
resetsAt?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Refusals this turn took, and the per-turn refusal bound, when `code` is
|
|
38
|
+
* `subscription_failover_exhausted` (refusals, not switches: the turn
|
|
39
|
+
* switched accounts `maxRefusals - 1` times before the last refusal).
|
|
40
|
+
*/
|
|
41
|
+
refusals?: number;
|
|
42
|
+
maxRefusals?: number;
|
|
43
|
+
/** Combined model/provider changes and refusals, not a refusal count. */
|
|
44
|
+
failoverSteps?: number;
|
|
45
|
+
maxFailoverSteps?: number;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** The provider-neutral name of the core turn failure payload. */
|
|
49
|
+
export type SubscriptionCoreFailurePayload = SubscriptionCoreCodexFailurePayload;
|
|
50
|
+
|
|
51
|
+
/** A typed core turn failure (the class keeps its M3 name; it serves every provider). */
|
|
52
|
+
export class SubscriptionCoreCodexTurnError extends Error {
|
|
53
|
+
readonly code: SubscriptionCoreCodexFailurePayload["code"];
|
|
54
|
+
/**
|
|
55
|
+
* The provider name its copy used. In-process only, never part of the
|
|
56
|
+
* payload, so a follow-up failure for the same turn (an exhausted lease-busy
|
|
57
|
+
* chain) names the same provider without the settlement naming providers.
|
|
58
|
+
*/
|
|
59
|
+
readonly displayName: string;
|
|
60
|
+
constructor(
|
|
61
|
+
readonly payload: SubscriptionCoreCodexFailurePayload,
|
|
62
|
+
displayName: string = DEFAULT_DISPLAY_NAME,
|
|
63
|
+
) {
|
|
64
|
+
super(payload.error);
|
|
65
|
+
this.name = "SubscriptionCoreCodexTurnError";
|
|
66
|
+
this.code = payload.code;
|
|
67
|
+
this.displayName = displayName;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const WAIT_COPY = (name: string): Record<WaitReason, string> => ({
|
|
72
|
+
pinned_account_disabled: `The ${name} account pinned to this chat is turned off. Turn it back on, choose another account, or switch the chat to automatic. Waiting alone will not fix this.`,
|
|
73
|
+
pinned_account_unavailable: `The ${name} account chosen for this session is unavailable right now. Send a new message once it is available again, or switch the session back to automatic.`,
|
|
74
|
+
pinned_account_ineligible: `The ${name} account chosen for this session can no longer serve this work. Choose another account or switch the session back to automatic.`,
|
|
75
|
+
no_eligible_capacity: `No ${name} subscription has capacity for this turn right now. Send a new message once an account is available again.`,
|
|
76
|
+
model_not_allowed: `This model is not allowed for the ${name} subscriptions available here.`,
|
|
77
|
+
compaction_provider_locked:
|
|
78
|
+
"This session is tied to a provider that has no capacity right now. Send a new message once an account is available again.",
|
|
79
|
+
accepted_authority_unavailable:
|
|
80
|
+
"This work was accepted before the account move and its account access could not be carried. Send it again.",
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The `codex.capacity.waiting` payload for a turn parked on a core waiter
|
|
85
|
+
* (M3 PR 2a): the legacy event shape with the core wait reason and the
|
|
86
|
+
* earliest known reset.
|
|
87
|
+
*/
|
|
88
|
+
export function subscriptionCoreCapacityWaitPayload(
|
|
89
|
+
reason: WaitReason,
|
|
90
|
+
earliestResetAt: Date | null,
|
|
91
|
+
displayName: string = DEFAULT_DISPLAY_NAME,
|
|
92
|
+
): Record<string, unknown> {
|
|
93
|
+
return {
|
|
94
|
+
error: subscriptionCapacityWaitReasonText(reason, displayName),
|
|
95
|
+
code: "subscription_capacity_unavailable",
|
|
96
|
+
waitReason: reason,
|
|
97
|
+
...(subscriptionCapacityWaitNeedsAction(reason) ? { actionRequired: true } : {}),
|
|
98
|
+
...(earliestResetAt ? { resetsAt: earliestResetAt.toISOString() } : {}),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** The per-turn failover bound was reached; the session stays usable. */
|
|
103
|
+
export function subscriptionCoreFailoverExhaustedFailure(
|
|
104
|
+
refusals: number,
|
|
105
|
+
maxRefusals: number,
|
|
106
|
+
displayName: string = DEFAULT_DISPLAY_NAME,
|
|
107
|
+
): SubscriptionCoreCodexTurnError {
|
|
108
|
+
return new SubscriptionCoreCodexTurnError(
|
|
109
|
+
{
|
|
110
|
+
error: `${displayName} accounts refused this turn too many times in a row. Send a new message after checking the accounts' health or capacity.`,
|
|
111
|
+
code: "subscription_failover_exhausted",
|
|
112
|
+
retryable: false,
|
|
113
|
+
refusals,
|
|
114
|
+
maxRefusals,
|
|
115
|
+
},
|
|
116
|
+
displayName,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function subscriptionCoreServingFailoverExhaustedFailure(
|
|
121
|
+
steps: number,
|
|
122
|
+
limit: number,
|
|
123
|
+
): SubscriptionCoreCodexTurnError {
|
|
124
|
+
return new SubscriptionCoreCodexTurnError(
|
|
125
|
+
{
|
|
126
|
+
error:
|
|
127
|
+
"Model accounts reached this turn's failover limit. Send a new message after checking the accounts' health or capacity.",
|
|
128
|
+
code: "subscription_failover_exhausted",
|
|
129
|
+
retryable: false,
|
|
130
|
+
failoverSteps: steps,
|
|
131
|
+
maxFailoverSteps: limit,
|
|
132
|
+
},
|
|
133
|
+
"Model account",
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The capacity wait the core decided, as a typed terminal failure. PR 2a
|
|
139
|
+
* parks waits on a durable core waiter instead; this remains for callers that
|
|
140
|
+
* cannot wait.
|
|
141
|
+
*/
|
|
142
|
+
export function subscriptionCoreCapacityFailure(
|
|
143
|
+
reason: WaitReason,
|
|
144
|
+
earliestResetAt: Date | null,
|
|
145
|
+
displayName: string = DEFAULT_DISPLAY_NAME,
|
|
146
|
+
): SubscriptionCoreCodexTurnError {
|
|
147
|
+
return new SubscriptionCoreCodexTurnError(
|
|
148
|
+
{
|
|
149
|
+
error: WAIT_COPY(displayName)[reason],
|
|
150
|
+
code: "subscription_capacity_unavailable",
|
|
151
|
+
retryable: false,
|
|
152
|
+
waitReason: reason,
|
|
153
|
+
...(earliestResetAt ? { resetsAt: earliestResetAt.toISOString() } : {}),
|
|
154
|
+
},
|
|
155
|
+
displayName,
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* An older attempt of this same turn still holds its lease until expiry, or
|
|
161
|
+
* (`binding_conflict`) the session's account changed while this placement
|
|
162
|
+
* was deciding. Both retry the same way; only the copy differs.
|
|
163
|
+
*/
|
|
164
|
+
export function subscriptionCoreLeaseBusyFailure(
|
|
165
|
+
leasedUntil: Date | null,
|
|
166
|
+
cause?: "binding_conflict",
|
|
167
|
+
displayName: string = DEFAULT_DISPLAY_NAME,
|
|
168
|
+
): SubscriptionCoreCodexTurnError {
|
|
169
|
+
return new SubscriptionCoreCodexTurnError(
|
|
170
|
+
{
|
|
171
|
+
error:
|
|
172
|
+
cause === "binding_conflict"
|
|
173
|
+
? `The session's ${displayName} account changed while this turn was starting. The turn will retry.`
|
|
174
|
+
: `A previous attempt of this turn still holds its ${displayName} account. The turn will retry once that hold ends.`,
|
|
175
|
+
code: "subscription_lease_busy",
|
|
176
|
+
retryable: true,
|
|
177
|
+
...(leasedUntil ? { resetsAt: leasedUntil.toISOString() } : {}),
|
|
178
|
+
},
|
|
179
|
+
displayName,
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Most extra delay added after the older lease's expiry, so retries spread out. */
|
|
184
|
+
export const SUBSCRIPTION_CORE_LEASE_BUSY_JITTER_MS = 5_000;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* When a redispatched attempt should retry after finding an older attempt's
|
|
188
|
+
* live lease: just after that lease expires (plus jitter), never later than
|
|
189
|
+
* one lease TTL, and never sooner than one second.
|
|
190
|
+
*/
|
|
191
|
+
export function subscriptionCoreLeaseBusyDelayMs(
|
|
192
|
+
resetsAt: string | undefined,
|
|
193
|
+
now: number,
|
|
194
|
+
jitterSample: number,
|
|
195
|
+
ttlMs: number = CODEX_CREDENTIAL_LEASE_TTL_MS,
|
|
196
|
+
): number {
|
|
197
|
+
const until = resetsAt ? Date.parse(resetsAt) : Number.NaN;
|
|
198
|
+
const remaining = Number.isFinite(until) ? Math.min(Math.max(until - now, 0), ttlMs) : ttlMs;
|
|
199
|
+
const jitter = Math.min(Math.max(jitterSample, 0), 1) * SUBSCRIPTION_CORE_LEASE_BUSY_JITTER_MS;
|
|
200
|
+
return Math.max(1_000, Math.ceil(remaining + jitter));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* How long one turn may keep finding an older attempt's live lease: about
|
|
205
|
+
* three lease TTLs of wall-clock time since the first such recovery. Lease
|
|
206
|
+
* renewal is not fenced on the turn's current attempt, so a superseded attempt
|
|
207
|
+
* that keeps heartbeating would otherwise hold the turn forever.
|
|
208
|
+
*/
|
|
209
|
+
export const SUBSCRIPTION_CORE_LEASE_BUSY_MAX_MS = 3 * CODEX_CREDENTIAL_LEASE_TTL_MS;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* The consecutive lease-busy chain after this attempt: it continues only when
|
|
213
|
+
* the immediately previous execution generation recorded it. A stored start
|
|
214
|
+
* in the future (clock skew or a bad write) is clamped to now so it can never
|
|
215
|
+
* disable the bound.
|
|
216
|
+
*/
|
|
217
|
+
export function subscriptionCoreLeaseBusyChain(
|
|
218
|
+
stored: { startedAt: number; executionGeneration: number } | undefined,
|
|
219
|
+
executionGeneration: number,
|
|
220
|
+
now: number,
|
|
221
|
+
): { startedAt: number; executionGeneration: number; exhausted: boolean } {
|
|
222
|
+
const startedAt =
|
|
223
|
+
stored && stored.executionGeneration === executionGeneration - 1
|
|
224
|
+
? Math.min(stored.startedAt, now)
|
|
225
|
+
: now;
|
|
226
|
+
return {
|
|
227
|
+
startedAt,
|
|
228
|
+
executionGeneration,
|
|
229
|
+
exhausted: now - startedAt >= SUBSCRIPTION_CORE_LEASE_BUSY_MAX_MS,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** The lease-busy chain lasted too long: stop with readable copy. */
|
|
234
|
+
export function subscriptionCoreLeaseBusyExhaustedFailure(
|
|
235
|
+
displayName: string = DEFAULT_DISPLAY_NAME,
|
|
236
|
+
): SubscriptionCoreCodexTurnError {
|
|
237
|
+
return new SubscriptionCoreCodexTurnError(
|
|
238
|
+
{
|
|
239
|
+
error: `A previous attempt of this turn kept holding its ${displayName} account, so the turn stopped. Send a new message to try again.`,
|
|
240
|
+
code: "subscription_lease_busy",
|
|
241
|
+
retryable: false,
|
|
242
|
+
},
|
|
243
|
+
displayName,
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export type SubscriptionCoreAccountRefusal =
|
|
248
|
+
| "sign_in"
|
|
249
|
+
| "forbidden"
|
|
250
|
+
| "entitlement"
|
|
251
|
+
| "access_lost";
|
|
252
|
+
|
|
253
|
+
const REFUSAL_COPY = (name: string): Record<SubscriptionCoreAccountRefusal, string> => ({
|
|
254
|
+
sign_in: `The ${name} account serving this session needs a new sign-in. Reconnect it or choose another account, then send a new message.`,
|
|
255
|
+
forbidden: `The ${name} account serving this session refused this request. Check the account's access or choose another account, then send a new message.`,
|
|
256
|
+
entitlement: `The ${name} account serving this session cannot use this model on its current plan. Choose another model or account, then send a new message.`,
|
|
257
|
+
access_lost: `This session lost access to the ${name} account it was running on. Send a new message to continue on an account it can use.`,
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* A definitive refusal from the leased account (revoked sign-in, 403, or a
|
|
262
|
+
* plan that does not include the model). Health and quarantine of the
|
|
263
|
+
* connection arrive with PR 2; until then the turn stops with readable copy
|
|
264
|
+
* and the session stays usable.
|
|
265
|
+
*/
|
|
266
|
+
export function subscriptionCoreAccountRefusedFailure(
|
|
267
|
+
refusal: SubscriptionCoreAccountRefusal,
|
|
268
|
+
displayName: string = DEFAULT_DISPLAY_NAME,
|
|
269
|
+
): SubscriptionCoreCodexTurnError {
|
|
270
|
+
return new SubscriptionCoreCodexTurnError(
|
|
271
|
+
{
|
|
272
|
+
error: REFUSAL_COPY(displayName)[refusal],
|
|
273
|
+
code: "subscription_account_refused",
|
|
274
|
+
retryable: false,
|
|
275
|
+
refusal,
|
|
276
|
+
},
|
|
277
|
+
displayName,
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** A Codex consumer that has not moved to the core yet (PR 2) must not read legacy tables. */
|
|
282
|
+
export function subscriptionCoreUnsupportedFailure(
|
|
283
|
+
consumer: string,
|
|
284
|
+
displayName: string = DEFAULT_DISPLAY_NAME,
|
|
285
|
+
): SubscriptionCoreCodexTurnError {
|
|
286
|
+
return new SubscriptionCoreCodexTurnError(
|
|
287
|
+
{
|
|
288
|
+
error: `${consumer} is not available for ${displayName} subscriptions on this deployment yet.`,
|
|
289
|
+
code: "subscription_core_unsupported",
|
|
290
|
+
retryable: false,
|
|
291
|
+
},
|
|
292
|
+
displayName,
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** The organization's cutover row for the provider exists but is switched off. */
|
|
297
|
+
export function subscriptionCoreCutoverDisabledFailure(
|
|
298
|
+
displayName: string = DEFAULT_DISPLAY_NAME,
|
|
299
|
+
): SubscriptionCoreCodexTurnError {
|
|
300
|
+
return new SubscriptionCoreCodexTurnError(
|
|
301
|
+
{
|
|
302
|
+
error: `${displayName} subscriptions are paused for this organization during maintenance.`,
|
|
303
|
+
code: "subscription_core_cutover_disabled",
|
|
304
|
+
retryable: false,
|
|
305
|
+
},
|
|
306
|
+
displayName,
|
|
307
|
+
);
|
|
308
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-turn re-placement after a definitive refusal on a Codex turn placed by
|
|
3
|
+
* the shared subscription core (M3 PR 2a, inventory EP-T06): the shared
|
|
4
|
+
* failover (`subscription-core-failover.ts`) bound to Codex, under the names
|
|
5
|
+
* and metrics M3 shipped.
|
|
6
|
+
*
|
|
7
|
+
* An explicit choice never fails over (D-24): its placement waits on the
|
|
8
|
+
* chosen account. The per-turn bound counts every refusal of the turn, by
|
|
9
|
+
* any account (SUB-FAIL-11).
|
|
10
|
+
*/
|
|
11
|
+
import { countSubscriptionCoreCodexTurnRefusals } from "@opengeni/db";
|
|
12
|
+
import type { RunAgentTurnResult } from "../types";
|
|
13
|
+
import type { CodexCredentialFailure } from "./errors";
|
|
14
|
+
import type { TurnFailureDeps } from "./failure-settlement";
|
|
15
|
+
import {
|
|
16
|
+
coreFailoverDisposition,
|
|
17
|
+
failOverCoreSubscriptionTurn,
|
|
18
|
+
SUBSCRIPTION_CORE_TURN_REFUSAL_LIMIT,
|
|
19
|
+
type CoreFailoverBinding,
|
|
20
|
+
} from "./subscription-core-failover";
|
|
21
|
+
import type { CodexSubscriptionCoreTurn } from "./turn-context";
|
|
22
|
+
|
|
23
|
+
/** The shared per-turn refusal bound, under its M3 name. */
|
|
24
|
+
export const SUBSCRIPTION_CORE_CODEX_TURN_REFUSAL_LIMIT = SUBSCRIPTION_CORE_TURN_REFUSAL_LIMIT;
|
|
25
|
+
|
|
26
|
+
/** Pure bound: fail over while under the limit, stop at it. */
|
|
27
|
+
export function coreCodexFailoverDisposition(
|
|
28
|
+
refusals: number | null,
|
|
29
|
+
limit: number = SUBSCRIPTION_CORE_CODEX_TURN_REFUSAL_LIMIT,
|
|
30
|
+
): "failover" | "exhausted" | "unrecorded" {
|
|
31
|
+
return coreFailoverDisposition(refusals, limit);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const CODEX_CORE_FAILOVER: CoreFailoverBinding = {
|
|
35
|
+
displayName: "Codex",
|
|
36
|
+
lease: (deps) => deps.leases.codex,
|
|
37
|
+
countRefusals: (db, identity) => countSubscriptionCoreCodexTurnRefusals(db, identity),
|
|
38
|
+
refusalLimit: SUBSCRIPTION_CORE_CODEX_TURN_REFUSAL_LIMIT,
|
|
39
|
+
recoveryReason: "codex_credential_failover",
|
|
40
|
+
recoveryProvider: "codex-subscription",
|
|
41
|
+
metrics: {
|
|
42
|
+
checkpoints: {
|
|
43
|
+
name: "opengeni_codex_failover_checkpoints_total",
|
|
44
|
+
help: "Durable Codex failover checkpoint attempts by outcome.",
|
|
45
|
+
},
|
|
46
|
+
settlements: {
|
|
47
|
+
name: "opengeni_codex_failover_settlements_total",
|
|
48
|
+
help: "Atomic Codex failover settlements by outcome.",
|
|
49
|
+
},
|
|
50
|
+
labels: (deps) => ({ workspace_key: deps.codexWorkspaceKey }),
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Re-place the same turn after graceful source disappearance, without a
|
|
56
|
+
* refusal/quarantine budget, or settle a recorded refusal within its bound.
|
|
57
|
+
* A usage-verification refusal (`origin`) does not count toward the bound.
|
|
58
|
+
* Returns null when automatic replay is unsafe.
|
|
59
|
+
*/
|
|
60
|
+
export async function failOverCoreCodexTurn(
|
|
61
|
+
deps: TurnFailureDeps,
|
|
62
|
+
core: CodexSubscriptionCoreTurn,
|
|
63
|
+
refusal: CodexCredentialFailure | "source_disconnected",
|
|
64
|
+
): Promise<RunAgentTurnResult | null> {
|
|
65
|
+
return await failOverCoreSubscriptionTurn(
|
|
66
|
+
deps,
|
|
67
|
+
core,
|
|
68
|
+
refusal === "source_disconnected"
|
|
69
|
+
? refusal
|
|
70
|
+
: { kind: refusal.kind, unbounded: refusal.origin !== undefined },
|
|
71
|
+
CODEX_CORE_FAILOVER,
|
|
72
|
+
);
|
|
73
|
+
}
|