@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
|
@@ -1,51 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
connectionModelAllowed,
|
|
3
|
-
getSessionGoal,
|
|
4
|
-
acquireCodexCredentialLease,
|
|
5
|
-
CodexCredentialLeaseAttemptFencedError,
|
|
6
|
-
CodexCredentialFailoverExhaustedError,
|
|
7
|
-
CODEX_CREDENTIAL_LEASE_TTL_MS,
|
|
8
|
-
recordSessionCodexSelectionForTurnAttempt,
|
|
9
|
-
setSessionCodexPinInTransaction,
|
|
10
|
-
settleCodexCredentialFailover,
|
|
11
|
-
withSessionCodexCapacityMutation,
|
|
12
|
-
type CodexCredentialLeaseResult,
|
|
13
|
-
type CodexCredentialLeaseSessionState,
|
|
14
|
-
type CodexCredentialLeaseSelectionContext,
|
|
15
|
-
} from "@opengeni/db";
|
|
1
|
+
import { readSubscriptionProviderCutoverState, withRlsContext } from "@opengeni/db";
|
|
16
2
|
import { type Settings } from "@opengeni/config";
|
|
17
|
-
|
|
18
|
-
import { publishDurableSessionEvents } from "@opengeni/events";
|
|
19
|
-
import {
|
|
20
|
-
authoritativeCodexCapacityResetAt,
|
|
21
|
-
classifyCodexPin,
|
|
22
|
-
computeIdleDelayMs,
|
|
23
|
-
isCodexCredentialEligible,
|
|
24
|
-
selectCodexCredentialLeaseForTurn,
|
|
25
|
-
type CodexRotationStrategy,
|
|
26
|
-
type CodexTurnLeaseDecision,
|
|
27
|
-
} from "../codex-rotation";
|
|
28
|
-
import {
|
|
29
|
-
codexFleetShadowDecisionMetricLabelsV1,
|
|
30
|
-
codexFleetShadowErrorMetricLabelsV1,
|
|
31
|
-
publishCodexFleetShadowDecisionV1,
|
|
32
|
-
} from "../codex-fleet-shadow";
|
|
33
|
-
import {
|
|
34
|
-
armAndReconcileCodexCapacityWait,
|
|
35
|
-
signalCodexCapacityWakeTargets,
|
|
36
|
-
} from "../codex-capacity";
|
|
3
|
+
|
|
37
4
|
import type {
|
|
38
5
|
TurnActivityServices as ActivityServices,
|
|
39
6
|
RunAgentTurnInput,
|
|
40
7
|
RunAgentTurnResult,
|
|
41
8
|
} from "../types";
|
|
42
|
-
|
|
9
|
+
|
|
43
10
|
import { createTurnCredentialLeases } from "./credential-leases";
|
|
44
|
-
import {
|
|
45
|
-
import {
|
|
11
|
+
import { selectCoreCodexTurnCapacity } from "./codex-core-capacity";
|
|
12
|
+
import { subscriptionCoreCutoverDisabledFailure } from "./codex-core-errors";
|
|
46
13
|
|
|
47
|
-
import { refreshCappedCodexUsageRows } from "./codex";
|
|
48
|
-
import { codexUsageLimitFailurePayload, CODEX_USAGE_LIMIT_MAX_RESUME_MS } from "./errors";
|
|
49
14
|
import type { ClaimTurnOk } from "./claim";
|
|
50
15
|
import type {
|
|
51
16
|
AttemptIdentityState,
|
|
@@ -88,725 +53,33 @@ export type CapacityPhaseDeps = {
|
|
|
88
53
|
|
|
89
54
|
export type CapacityPhaseOutcome = { exit: RunAgentTurnResult } | { ok: true };
|
|
90
55
|
|
|
56
|
+
export type CodexCutoverState = "not_configured" | "disabled" | "enabled";
|
|
57
|
+
|
|
58
|
+
/** Missing or disabled cutover state is maintenance, never legacy routing. */
|
|
59
|
+
export function codexCutoverDisposition(state: CodexCutoverState): "core" | "fail_closed" {
|
|
60
|
+
return state === "enabled" ? "core" : "fail_closed";
|
|
61
|
+
}
|
|
62
|
+
|
|
91
63
|
export async function selectCodexTurnCapacity(
|
|
92
64
|
deps: CapacityPhaseDeps,
|
|
93
65
|
): Promise<CapacityPhaseOutcome> {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
db,
|
|
98
|
-
bus,
|
|
99
|
-
observability,
|
|
100
|
-
wakeSessionWorkflow,
|
|
101
|
-
signalCodexCapacityWorkflow,
|
|
102
|
-
dispatchId,
|
|
103
|
-
control,
|
|
104
|
-
attempt,
|
|
105
|
-
billingState,
|
|
106
|
-
eventing,
|
|
107
|
-
providerTurn,
|
|
108
|
-
leases,
|
|
109
|
-
claimedResult,
|
|
110
|
-
acknowledgeLostAttemptOwnership,
|
|
111
|
-
turn,
|
|
112
|
-
codexWorkspaceKey,
|
|
113
|
-
} = deps;
|
|
114
|
-
const turnId = attempt.turnId;
|
|
115
|
-
const holderId = leases.codex.holderId;
|
|
116
|
-
if (!turnId) {
|
|
117
|
-
throw new Error("Turn id was not initialized");
|
|
118
|
-
}
|
|
119
|
-
if (!holderId) {
|
|
120
|
-
throw new Error("Codex lease holder was not initialized");
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (billingState.isCodexTurn) {
|
|
124
|
-
const credentialSelectionStartedAt = performance.now();
|
|
125
|
-
let credentialSelectionOutcome: "completed" | "failed" = "completed";
|
|
126
|
-
try {
|
|
127
|
-
const selectForTurn = (
|
|
128
|
-
context: CodexCredentialLeaseSelectionContext,
|
|
129
|
-
lockedSessionCodexState: CodexCredentialLeaseSessionState,
|
|
130
|
-
) => {
|
|
131
|
-
const allowed = context.accounts.filter((account) =>
|
|
132
|
-
connectionModelAllowed(account.allowedModelIds, deps.turnExecutionPolicy.productModelId),
|
|
133
|
-
);
|
|
134
|
-
if (context.accounts.length > 0 && allowed.length === 0)
|
|
135
|
-
throw new Error("This model is disabled for the connected Codex subscriptions");
|
|
136
|
-
const sessionPin = lockedSessionCodexState.pinnedCredentialId;
|
|
137
|
-
if (
|
|
138
|
-
sessionPin &&
|
|
139
|
-
lockedSessionCodexState.pinSource !== "policy" &&
|
|
140
|
-
context.accounts.some((account) => account.id === sessionPin) &&
|
|
141
|
-
!allowed.some((account) => account.id === sessionPin)
|
|
142
|
-
)
|
|
143
|
-
throw new Error("This model is disabled for the pinned Codex subscription");
|
|
144
|
-
return selectCodexCredentialLeaseForTurn({
|
|
145
|
-
context: { ...context, accounts: allowed },
|
|
146
|
-
sessionId: input.sessionId,
|
|
147
|
-
sessionPinnedCredentialId: lockedSessionCodexState.pinnedCredentialId,
|
|
148
|
-
sessionPinSource: lockedSessionCodexState.pinSource,
|
|
149
|
-
sessionLastCredentialId: lockedSessionCodexState.lastCredentialId,
|
|
150
|
-
now: new Date(),
|
|
151
|
-
});
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
let leaseAcquisitionStartedAtMs = performance.now();
|
|
155
|
-
let leased: CodexCredentialLeaseResult<CodexTurnLeaseDecision> =
|
|
156
|
-
await acquireCodexCredentialLease(
|
|
157
|
-
db,
|
|
158
|
-
{
|
|
159
|
-
accountId: input.accountId,
|
|
160
|
-
workspaceId: input.workspaceId,
|
|
161
|
-
sessionId: input.sessionId,
|
|
162
|
-
turnId,
|
|
163
|
-
attemptId: input.attemptId,
|
|
164
|
-
executionGeneration: attempt.executionGeneration,
|
|
165
|
-
workflowId: input.workflowId,
|
|
166
|
-
workflowRunId: input.workflowRunId,
|
|
167
|
-
dispatchId,
|
|
168
|
-
expectedRedispatches: attempt.redispatchesAtDispatch,
|
|
169
|
-
holderId,
|
|
170
|
-
advanceActivePointer: true,
|
|
171
|
-
},
|
|
172
|
-
selectForTurn,
|
|
173
|
-
);
|
|
174
|
-
if (leased.decision.kind === "allCapped") {
|
|
175
|
-
// Bounded self-heal of stale usage cache, then ONE new atomic selection.
|
|
176
|
-
await refreshCappedCodexUsageRows(
|
|
177
|
-
db,
|
|
178
|
-
settings,
|
|
179
|
-
input.workspaceId,
|
|
180
|
-
leased.accounts,
|
|
181
|
-
{
|
|
182
|
-
signalCodexCapacityWorkflow,
|
|
183
|
-
wakeSessionWorkflow,
|
|
184
|
-
},
|
|
185
|
-
turn.id,
|
|
186
|
-
);
|
|
187
|
-
leaseAcquisitionStartedAtMs = performance.now();
|
|
188
|
-
leased = await acquireCodexCredentialLease(
|
|
189
|
-
db,
|
|
190
|
-
{
|
|
191
|
-
accountId: input.accountId,
|
|
192
|
-
workspaceId: input.workspaceId,
|
|
193
|
-
sessionId: input.sessionId,
|
|
194
|
-
turnId,
|
|
195
|
-
attemptId: input.attemptId,
|
|
196
|
-
executionGeneration: attempt.executionGeneration,
|
|
197
|
-
workflowId: input.workflowId,
|
|
198
|
-
workflowRunId: input.workflowRunId,
|
|
199
|
-
dispatchId,
|
|
200
|
-
expectedRedispatches: attempt.redispatchesAtDispatch,
|
|
201
|
-
holderId,
|
|
202
|
-
advanceActivePointer: true,
|
|
203
|
-
},
|
|
204
|
-
selectForTurn,
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
const lockedSessionCodexState = leased.sessionCodexState;
|
|
208
|
-
providerTurn.codexPolicySnapshot = leased.codexPolicySnapshot;
|
|
209
|
-
const sessionPin = lockedSessionCodexState.pinnedCredentialId;
|
|
210
|
-
const sessionPinSource = lockedSessionCodexState.pinSource;
|
|
211
|
-
const rotationDecision = leased.decision;
|
|
212
|
-
const selectedPinDisposition = classifyCodexPin({
|
|
213
|
-
pinnedCredentialId: sessionPin,
|
|
214
|
-
pinSource: sessionPinSource,
|
|
215
|
-
strategy: leased.rotationStrategy as CodexRotationStrategy,
|
|
216
|
-
rotationEnabled: leased.rotationEnabled,
|
|
217
|
-
});
|
|
218
|
-
// pin policy pin persistence follows the atomic credential allocator selection. The selector
|
|
219
|
-
// already ran exact-turn reuse before policy filtering and vetoed pointer
|
|
220
|
-
// movement for manual/policy homes; this write only records the NEXT turn's
|
|
221
|
-
// policy home (or clears a policy pin whose strategy is no longer active).
|
|
222
|
-
if (
|
|
223
|
-
!leased.codexPolicySnapshotReused &&
|
|
224
|
-
selectedPinDisposition === "sharded" &&
|
|
225
|
-
leased.credentialId !== null &&
|
|
226
|
-
(sessionPinSource !== "policy" || sessionPin !== leased.credentialId)
|
|
227
|
-
) {
|
|
228
|
-
const pinMutation = await withSessionCodexCapacityMutation(
|
|
229
|
-
db,
|
|
230
|
-
{
|
|
231
|
-
workspaceId: input.workspaceId,
|
|
232
|
-
reason: "codex_policy_pin_changed",
|
|
233
|
-
},
|
|
234
|
-
async (tx) => {
|
|
235
|
-
const changed = await setSessionCodexPinInTransaction(
|
|
236
|
-
tx,
|
|
237
|
-
input.workspaceId,
|
|
238
|
-
input.sessionId,
|
|
239
|
-
leased.credentialId,
|
|
240
|
-
"policy",
|
|
241
|
-
{
|
|
242
|
-
expected: {
|
|
243
|
-
pinnedCredentialId: sessionPin,
|
|
244
|
-
pinSource: sessionPinSource,
|
|
245
|
-
},
|
|
246
|
-
},
|
|
247
|
-
);
|
|
248
|
-
return { result: changed, changed };
|
|
249
|
-
},
|
|
250
|
-
);
|
|
251
|
-
await signalCodexCapacityWakeTargets(
|
|
252
|
-
{ signalCodexCapacityWorkflow, wakeSessionWorkflow },
|
|
253
|
-
pinMutation.wakeTargets,
|
|
254
|
-
);
|
|
255
|
-
} else if (selectedPinDisposition === "clearStale") {
|
|
256
|
-
const pinMutation = await withSessionCodexCapacityMutation(
|
|
257
|
-
db,
|
|
258
|
-
{
|
|
259
|
-
workspaceId: input.workspaceId,
|
|
260
|
-
reason: "codex_stale_policy_pin_cleared",
|
|
261
|
-
},
|
|
262
|
-
async (tx) => {
|
|
263
|
-
const changed = await setSessionCodexPinInTransaction(
|
|
264
|
-
tx,
|
|
265
|
-
input.workspaceId,
|
|
266
|
-
input.sessionId,
|
|
267
|
-
null,
|
|
268
|
-
"policy",
|
|
269
|
-
{
|
|
270
|
-
expected: {
|
|
271
|
-
pinnedCredentialId: sessionPin,
|
|
272
|
-
pinSource: sessionPinSource,
|
|
273
|
-
},
|
|
274
|
-
},
|
|
275
|
-
);
|
|
276
|
-
return { result: changed, changed };
|
|
277
|
-
},
|
|
278
|
-
);
|
|
279
|
-
await signalCodexCapacityWakeTargets(
|
|
280
|
-
{ signalCodexCapacityWorkflow, wakeSessionWorkflow },
|
|
281
|
-
pinMutation.wakeTargets,
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
providerTurn.effectiveCodexCredentialId = leased.credentialId;
|
|
285
|
-
providerTurn.codexCredentialFailoverLimit = leased.failoverLimit;
|
|
286
|
-
leases.codex.generation = leased.generation;
|
|
287
|
-
leases.codex.confirmedUntilMs =
|
|
288
|
-
leased.leasedUntil && leaseAcquisitionStartedAtMs !== null
|
|
289
|
-
? leaseAcquisitionStartedAtMs + CODEX_CREDENTIAL_LEASE_TTL_MS
|
|
290
|
-
: null;
|
|
291
|
-
leases.codex.held =
|
|
292
|
-
providerTurn.effectiveCodexCredentialId !== null &&
|
|
293
|
-
leased.holderId !== null &&
|
|
294
|
-
leased.generation !== null &&
|
|
295
|
-
leases.codex.confirmedUntilMs !== null;
|
|
296
|
-
if (leases.codex.held) leases.codex.startHeartbeat();
|
|
297
|
-
|
|
298
|
-
const eligibleCount = leased.accounts.filter((account) =>
|
|
299
|
-
isCodexCredentialEligible(account, new Date()),
|
|
300
|
-
).length;
|
|
301
|
-
const selectionReceipt = providerTurn.effectiveCodexCredentialId
|
|
302
|
-
? await recordSessionCodexSelectionForTurnAttempt(db, {
|
|
303
|
-
workspaceId: input.workspaceId,
|
|
304
|
-
sessionId: input.sessionId,
|
|
305
|
-
turnId,
|
|
306
|
-
attemptId: input.attemptId,
|
|
307
|
-
executionGeneration: attempt.executionGeneration,
|
|
308
|
-
credentialId: providerTurn.effectiveCodexCredentialId,
|
|
309
|
-
strategy: leased.rotationStrategy,
|
|
310
|
-
reusedLease: leased.reused,
|
|
311
|
-
pinnedCredentialId: sessionPin,
|
|
312
|
-
pinSource: sessionPinSource,
|
|
313
|
-
eligibleCount,
|
|
314
|
-
connectedCount: leased.accounts.length,
|
|
315
|
-
})
|
|
316
|
-
: null;
|
|
317
|
-
if (selectionReceipt)
|
|
318
|
-
await publishDurableSessionEvents(
|
|
319
|
-
bus,
|
|
320
|
-
input.workspaceId,
|
|
321
|
-
input.sessionId,
|
|
322
|
-
selectionReceipt.events,
|
|
323
|
-
);
|
|
324
|
-
const selectionDiagnostics = selectionReceipt?.diagnostics ?? null;
|
|
325
|
-
const actualOutcome = providerTurn.effectiveCodexCredentialId
|
|
326
|
-
? "selected"
|
|
327
|
-
: rotationDecision.kind === "allCapped" || rotationDecision.kind === "allocatorDisabled"
|
|
328
|
-
? "waiting"
|
|
329
|
-
: "none";
|
|
330
|
-
const actualReason = selectionDiagnostics
|
|
331
|
-
? selectionDiagnostics.reason
|
|
332
|
-
: rotationDecision.kind === "allCapped"
|
|
333
|
-
? "all_capped"
|
|
334
|
-
: rotationDecision.kind === "allocatorDisabled"
|
|
335
|
-
? "allocator_disabled"
|
|
336
|
-
: "none";
|
|
337
|
-
const fencedInFlight = leased.reused;
|
|
338
|
-
const shadowResult = await publishCodexFleetShadowDecisionV1({
|
|
339
|
-
enabled: settings.codexFleetPolicyShadowEnabled,
|
|
340
|
-
decision: {
|
|
341
|
-
accounts: leased.accounts,
|
|
342
|
-
actualCredentialId: providerTurn.effectiveCodexCredentialId,
|
|
343
|
-
actualOutcome,
|
|
344
|
-
actualReason,
|
|
345
|
-
affinityCredentialId: fencedInFlight
|
|
346
|
-
? providerTurn.effectiveCodexCredentialId
|
|
347
|
-
: (sessionPin ?? lockedSessionCodexState.lastCredentialId ?? null),
|
|
348
|
-
fencedInFlight,
|
|
349
|
-
nearExhaustionPct: settings.codexRotationNearExhaustionPct,
|
|
350
|
-
now: new Date(),
|
|
351
|
-
aliasSeed: randomUUID(),
|
|
352
|
-
},
|
|
353
|
-
publish: eventing.publish,
|
|
354
|
-
});
|
|
355
|
-
if (shadowResult.outcome === "published") {
|
|
356
|
-
const shadowPayload = shadowResult.payload;
|
|
357
|
-
observability.incrementCounter({
|
|
358
|
-
name: "opengeni_codex_fleet_shadow_decisions_total",
|
|
359
|
-
help: "Shadow decisions by bounded actual/shadow outcome and comparison.",
|
|
360
|
-
labels: codexFleetShadowDecisionMetricLabelsV1(shadowPayload),
|
|
361
|
-
});
|
|
362
|
-
observability.info("Codex adaptive fleet shadow decision", {
|
|
363
|
-
workspaceId: input.workspaceId,
|
|
364
|
-
policyVersion: shadowPayload.replay.policyVersion,
|
|
365
|
-
inputFingerprint: shadowPayload.replay.inputFingerprint,
|
|
366
|
-
decisionFingerprint: shadowPayload.replay.decisionFingerprint,
|
|
367
|
-
actualOutcome: shadowPayload.actual.outcome,
|
|
368
|
-
shadowOutcome: shadowPayload.replay.decision.outcome,
|
|
369
|
-
comparison: shadowPayload.comparison,
|
|
370
|
-
candidateCount: shadowPayload.replay.input.candidates.length,
|
|
371
|
-
truncatedCandidateCount: shadowPayload.replay.truncatedCandidateCount,
|
|
372
|
-
payloadBytes: shadowResult.payloadBytes,
|
|
373
|
-
});
|
|
374
|
-
} else if (shadowResult.outcome === "failed") {
|
|
375
|
-
// Shadow observability is explicitly non-authoritative. A malformed
|
|
376
|
-
// snapshot or event-write fault must never change the authoritative lease,
|
|
377
|
-
// capacity wait, failover, or the account serving this fenced turn.
|
|
378
|
-
observability.incrementCounter({
|
|
379
|
-
name: "opengeni_codex_fleet_shadow_errors_total",
|
|
380
|
-
help: "Shadow decision build/publication failures.",
|
|
381
|
-
labels: codexFleetShadowErrorMetricLabelsV1(shadowResult),
|
|
382
|
-
});
|
|
383
|
-
observability.warn("Codex adaptive fleet shadow decision failed open", {
|
|
384
|
-
stage: shadowResult.stage,
|
|
385
|
-
reason: shadowResult.reason,
|
|
386
|
-
errorClass: "CodexFleetShadowOperationError",
|
|
387
|
-
errorCode: "codex_fleet_shadow_failed",
|
|
388
|
-
origin: "worker",
|
|
389
|
-
payloadBytes: shadowResult.payloadBytes,
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
const poolDepth = eligibleCount === 0 ? "zero" : eligibleCount === 1 ? "one" : "many";
|
|
394
|
-
observability.incrementCounter({
|
|
395
|
-
name: "opengeni_codex_pool_observations_total",
|
|
396
|
-
help: "Observed eligible Codex pool depth buckets at turn selection.",
|
|
397
|
-
labels: { workspace_key: codexWorkspaceKey, depth: poolDepth },
|
|
398
|
-
});
|
|
399
|
-
if (eligibleCount <= 1) {
|
|
400
|
-
observability.incrementCounter({
|
|
401
|
-
name: "opengeni_codex_pool_low_total",
|
|
402
|
-
help: "Alert signal emitted when the eligible Codex pool is zero or one.",
|
|
403
|
-
labels: { workspace_key: codexWorkspaceKey, depth: poolDepth },
|
|
404
|
-
});
|
|
405
|
-
observability.warn("Codex eligible credential pool is low", {
|
|
406
|
-
workspaceId: input.workspaceId,
|
|
407
|
-
eligibleCount,
|
|
408
|
-
connectedCount: leased.accounts.length,
|
|
409
|
-
depth: poolDepth,
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if (
|
|
414
|
-
providerTurn.effectiveCodexCredentialId === null &&
|
|
415
|
-
leased.accounts.length > 0 &&
|
|
416
|
-
(rotationDecision.kind === "allocatorDisabled" ||
|
|
417
|
-
leased.accounts.every((account) => !account.allocatorEnabled)) &&
|
|
418
|
-
turnId
|
|
419
|
-
) {
|
|
420
|
-
if (turn.source === "compaction") {
|
|
421
|
-
if (
|
|
422
|
-
!(await eventing.settle!({
|
|
423
|
-
events: [
|
|
424
|
-
{
|
|
425
|
-
type: "turn.cancelled",
|
|
426
|
-
payload: {
|
|
427
|
-
maintenance: "context_compaction",
|
|
428
|
-
reason: "codex_allocator_disabled",
|
|
429
|
-
requestPreserved: true,
|
|
430
|
-
},
|
|
431
|
-
},
|
|
432
|
-
{
|
|
433
|
-
type: "session.status.changed",
|
|
434
|
-
payload: { status: "idle" },
|
|
435
|
-
},
|
|
436
|
-
],
|
|
437
|
-
turnStatus: "cancelled",
|
|
438
|
-
sessionStatus: "idle",
|
|
439
|
-
activeTurnId: null,
|
|
440
|
-
}))
|
|
441
|
-
) {
|
|
442
|
-
return { exit: claimedResult({ status: "cancelled" }) };
|
|
443
|
-
}
|
|
444
|
-
control.turnMetricOutcome = "cancelled";
|
|
445
|
-
control.activityStatus = "idle";
|
|
446
|
-
return { exit: claimedResult({ status: "idle", deferredUntilWake: true }) };
|
|
447
|
-
}
|
|
448
|
-
const goal = await getSessionGoal(db, input.workspaceId, input.sessionId);
|
|
449
|
-
const activeGoal = goal?.status === "active" ? goal : null;
|
|
450
|
-
const evaluated = await armAndReconcileCodexCapacityWait(
|
|
451
|
-
{ db, bus },
|
|
452
|
-
{
|
|
453
|
-
accountId: input.accountId,
|
|
454
|
-
workspaceId: input.workspaceId,
|
|
455
|
-
sessionId: input.sessionId,
|
|
456
|
-
turnId,
|
|
457
|
-
attemptId: input.attemptId,
|
|
458
|
-
workflowId: input.workflowId,
|
|
459
|
-
goalId: activeGoal?.id ?? null,
|
|
460
|
-
goalVersion: activeGoal?.version ?? null,
|
|
461
|
-
earliestResetAt: null,
|
|
462
|
-
resetKind: "mutation_only",
|
|
463
|
-
failurePayload: {
|
|
464
|
-
error:
|
|
465
|
-
rotationDecision.kind === "allocatorDisabled"
|
|
466
|
-
? "The policy-selected Codex subscription is disabled for new allocations."
|
|
467
|
-
: "All connected Codex subscriptions are disabled for new allocations.",
|
|
468
|
-
code: "codex_allocator_disabled",
|
|
469
|
-
detail:
|
|
470
|
-
rotationDecision.kind === "allocatorDisabled"
|
|
471
|
-
? "waiting for the selected credential to be re-enabled under the accepted source policy"
|
|
472
|
-
: "waiting for a credential in the accepted source pool to be re-enabled, reconnected, or added",
|
|
473
|
-
},
|
|
474
|
-
},
|
|
475
|
-
);
|
|
476
|
-
if (evaluated.action === "stopped") {
|
|
477
|
-
control.turnMetricOutcome = "failed";
|
|
478
|
-
control.activityStatus = evaluated.sessionStatus === "queued" ? "idle" : "failed";
|
|
479
|
-
return { exit: claimedResult({ status: control.activityStatus }) };
|
|
480
|
-
}
|
|
481
|
-
if (evaluated.action === "resumed") {
|
|
482
|
-
control.turnMetricOutcome = "recovering";
|
|
483
|
-
control.activityStatus = "recovering";
|
|
484
|
-
return { exit: claimedResult({ status: "recovering" }) };
|
|
485
|
-
}
|
|
486
|
-
if (evaluated.action === "waiting") {
|
|
487
|
-
control.turnMetricOutcome = "recovering";
|
|
488
|
-
control.activityStatus = "waiting_capacity";
|
|
489
|
-
return {
|
|
490
|
-
exit: claimedResult({
|
|
491
|
-
status: "waiting_capacity",
|
|
492
|
-
capacityWait: {
|
|
493
|
-
waiterId: evaluated.waiter.id,
|
|
494
|
-
generation: evaluated.waiter.generation,
|
|
495
|
-
nextCheckAt: evaluated.waiter.nextCheckAt.toISOString(),
|
|
496
|
-
wakeRevision: evaluated.waiter.wakeRevision,
|
|
497
|
-
},
|
|
498
|
-
}),
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
acknowledgeLostAttemptOwnership();
|
|
502
|
-
control.turnMetricOutcome = "cancelled";
|
|
503
|
-
control.activityStatus = "cancelled";
|
|
504
|
-
return { exit: claimedResult({ status: "cancelled" }) };
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
if (rotationDecision.kind === "none") {
|
|
508
|
-
if (
|
|
509
|
-
leased.poolAccountCount === 0 &&
|
|
510
|
-
!leased.codexPolicySnapshotReused &&
|
|
511
|
-
leased.codexPolicySnapshot?.source !== "disabled"
|
|
512
|
-
) {
|
|
513
|
-
// Preserve the established no-account behavior. The empty-string
|
|
514
|
-
// token resolver used by the later model path raises this same typed
|
|
515
|
-
// reconnect outcome, but capacity must not report success and defer
|
|
516
|
-
// the failure to an unguarded provider setup.
|
|
517
|
-
throw new CodexReloginRequired("No Codex subscription is connected for this workspace.");
|
|
518
|
-
}
|
|
519
|
-
const noneReason =
|
|
520
|
-
sessionPinSource === "manual" && sessionPin !== null
|
|
521
|
-
? {
|
|
522
|
-
code: "codex_manual_pin_unavailable",
|
|
523
|
-
error: "The pinned Codex subscription is unavailable for this turn.",
|
|
524
|
-
detail:
|
|
525
|
-
"waiting for the pinned account to reconnect or become allocatable under the accepted source policy",
|
|
526
|
-
}
|
|
527
|
-
: !leased.rotationEnabled && leased.activeCredentialId === null
|
|
528
|
-
? {
|
|
529
|
-
code: "codex_active_pointer_unavailable",
|
|
530
|
-
error: "The Codex active subscription pointer is unavailable for this turn.",
|
|
531
|
-
detail:
|
|
532
|
-
"waiting for the accepted active account to be restored or become allocatable",
|
|
533
|
-
}
|
|
534
|
-
: leased.poolAccountCount > leased.accounts.length
|
|
535
|
-
? {
|
|
536
|
-
code: "codex_policy_pool_unavailable",
|
|
537
|
-
error: "No Codex subscription matches the accepted account-selection policy.",
|
|
538
|
-
detail:
|
|
539
|
-
"waiting for a matching credential to reconnect or become allocatable under the accepted source policy",
|
|
540
|
-
}
|
|
541
|
-
: {
|
|
542
|
-
code: "codex_credential_unavailable",
|
|
543
|
-
error:
|
|
544
|
-
"No Codex subscription is currently available under the accepted policy.",
|
|
545
|
-
detail:
|
|
546
|
-
"waiting for a matching credential to reconnect or become allocatable under the accepted source policy",
|
|
547
|
-
};
|
|
548
|
-
if (turn.source === "compaction") {
|
|
549
|
-
if (
|
|
550
|
-
!(await eventing.settle!({
|
|
551
|
-
events: [
|
|
552
|
-
{
|
|
553
|
-
type: "turn.cancelled",
|
|
554
|
-
payload: {
|
|
555
|
-
maintenance: "context_compaction",
|
|
556
|
-
reason: noneReason.code,
|
|
557
|
-
requestPreserved: true,
|
|
558
|
-
},
|
|
559
|
-
},
|
|
560
|
-
{
|
|
561
|
-
type: "session.status.changed",
|
|
562
|
-
payload: { status: "idle" },
|
|
563
|
-
},
|
|
564
|
-
],
|
|
565
|
-
turnStatus: "cancelled",
|
|
566
|
-
sessionStatus: "idle",
|
|
567
|
-
activeTurnId: null,
|
|
568
|
-
}))
|
|
569
|
-
) {
|
|
570
|
-
return { exit: claimedResult({ status: "cancelled" }) };
|
|
571
|
-
}
|
|
572
|
-
control.turnMetricOutcome = "cancelled";
|
|
573
|
-
control.activityStatus = "idle";
|
|
574
|
-
return { exit: claimedResult({ status: "idle", deferredUntilWake: true }) };
|
|
575
|
-
}
|
|
576
|
-
const goal = await getSessionGoal(db, input.workspaceId, input.sessionId);
|
|
577
|
-
const activeGoal = goal?.status === "active" ? goal : null;
|
|
578
|
-
const evaluated = await armAndReconcileCodexCapacityWait(
|
|
579
|
-
{ db, bus },
|
|
580
|
-
{
|
|
581
|
-
accountId: input.accountId,
|
|
582
|
-
workspaceId: input.workspaceId,
|
|
583
|
-
sessionId: input.sessionId,
|
|
584
|
-
turnId,
|
|
585
|
-
attemptId: input.attemptId,
|
|
586
|
-
workflowId: input.workflowId,
|
|
587
|
-
goalId: activeGoal?.id ?? null,
|
|
588
|
-
goalVersion: activeGoal?.version ?? null,
|
|
589
|
-
earliestResetAt: null,
|
|
590
|
-
resetKind: "mutation_only",
|
|
591
|
-
failurePayload: {
|
|
592
|
-
error: noneReason.error,
|
|
593
|
-
code: noneReason.code,
|
|
594
|
-
detail: noneReason.detail,
|
|
595
|
-
},
|
|
596
|
-
},
|
|
597
|
-
);
|
|
598
|
-
if (evaluated.action === "stopped") {
|
|
599
|
-
control.turnMetricOutcome = "failed";
|
|
600
|
-
control.activityStatus = evaluated.sessionStatus === "queued" ? "idle" : "failed";
|
|
601
|
-
return { exit: claimedResult({ status: control.activityStatus }) };
|
|
602
|
-
}
|
|
603
|
-
if (evaluated.action === "resumed") {
|
|
604
|
-
control.turnMetricOutcome = "recovering";
|
|
605
|
-
control.activityStatus = "recovering";
|
|
606
|
-
return { exit: claimedResult({ status: "recovering" }) };
|
|
607
|
-
}
|
|
608
|
-
if (evaluated.action === "waiting") {
|
|
609
|
-
control.turnMetricOutcome = "recovering";
|
|
610
|
-
control.activityStatus = "waiting_capacity";
|
|
611
|
-
return {
|
|
612
|
-
exit: claimedResult({
|
|
613
|
-
status: "waiting_capacity",
|
|
614
|
-
capacityWait: {
|
|
615
|
-
waiterId: evaluated.waiter.id,
|
|
616
|
-
generation: evaluated.waiter.generation,
|
|
617
|
-
nextCheckAt: evaluated.waiter.nextCheckAt.toISOString(),
|
|
618
|
-
wakeRevision: evaluated.waiter.wakeRevision,
|
|
619
|
-
},
|
|
620
|
-
}),
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
acknowledgeLostAttemptOwnership();
|
|
624
|
-
control.turnMetricOutcome = "cancelled";
|
|
625
|
-
control.activityStatus = "cancelled";
|
|
626
|
-
return { exit: claimedResult({ status: "cancelled" }) };
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
if (rotationDecision.kind === "allCapped" && turnId) {
|
|
630
|
-
if (turn.source === "compaction") {
|
|
631
|
-
if (
|
|
632
|
-
!(await eventing.settle!({
|
|
633
|
-
events: [
|
|
634
|
-
{
|
|
635
|
-
type: "turn.cancelled",
|
|
636
|
-
payload: {
|
|
637
|
-
maintenance: "context_compaction",
|
|
638
|
-
reason: "codex_capacity_unavailable",
|
|
639
|
-
requestPreserved: true,
|
|
640
|
-
},
|
|
641
|
-
},
|
|
642
|
-
{
|
|
643
|
-
type: "session.status.changed",
|
|
644
|
-
payload: { status: "idle" },
|
|
645
|
-
},
|
|
646
|
-
],
|
|
647
|
-
turnStatus: "cancelled",
|
|
648
|
-
sessionStatus: "idle",
|
|
649
|
-
activeTurnId: null,
|
|
650
|
-
}))
|
|
651
|
-
) {
|
|
652
|
-
return { exit: claimedResult({ status: "cancelled" }) };
|
|
653
|
-
}
|
|
654
|
-
control.turnMetricOutcome = "cancelled";
|
|
655
|
-
control.activityStatus = "idle";
|
|
656
|
-
return { exit: claimedResult({ status: "idle", deferredUntilWake: true }) };
|
|
657
|
-
}
|
|
658
|
-
// Every eligible account is capped/cooling (and a usage refresh did NOT
|
|
659
|
-
// surface a reset): idle the turn AT THE BOUNDARY (no wasted model/sandbox
|
|
660
|
-
// build) until the EARLIEST reset across all accounts — the multi-account
|
|
661
|
-
// generalization of #143's single-account idle-until-reset. No saveRunState:
|
|
662
|
-
// no model ran, nothing to freeze.
|
|
663
|
-
const goal = await getSessionGoal(db, input.workspaceId, input.sessionId);
|
|
664
|
-
const goalActive = Boolean(goal && goal.status === "active");
|
|
665
|
-
// BOUNDED + POSITIVE: clamp to [MIN_IDLE_MS, max] so a null/elapsed/unknown
|
|
666
|
-
// reset can never yield a 0 (which session.ts would treat as "continue now",
|
|
667
|
-
// re-entering this path in a tight CPU/DB-hammering loop).
|
|
668
|
-
const resumeMs = computeIdleDelayMs(
|
|
669
|
-
rotationDecision.earliestResetAt,
|
|
670
|
-
new Date(),
|
|
671
|
-
CODEX_USAGE_LIMIT_MAX_RESUME_MS,
|
|
672
|
-
);
|
|
673
|
-
const allConnectedAccountsWereConsidered =
|
|
674
|
-
leased.rotationEnabled && selectedPinDisposition !== "manual";
|
|
675
|
-
const capacityDetail = allConnectedAccountsWereConsidered
|
|
676
|
-
? "all connected Codex subscriptions are rate-limited"
|
|
677
|
-
: selectedPinDisposition === "manual"
|
|
678
|
-
? "the pinned Codex subscription is rate-limited"
|
|
679
|
-
: "the active Codex subscription is rate-limited";
|
|
680
|
-
const failurePayload = codexUsageLimitFailurePayload(
|
|
681
|
-
{ resetsInSeconds: Math.ceil(resumeMs / 1000) },
|
|
682
|
-
capacityDetail,
|
|
683
|
-
{ allAccounts: allConnectedAccountsWereConsidered },
|
|
684
|
-
);
|
|
685
|
-
const authoritativeResetAt = authoritativeCodexCapacityResetAt(leased.accounts, new Date());
|
|
686
|
-
const evaluated = await armAndReconcileCodexCapacityWait(
|
|
687
|
-
{ db, bus },
|
|
688
|
-
{
|
|
689
|
-
accountId: input.accountId,
|
|
690
|
-
workspaceId: input.workspaceId,
|
|
691
|
-
sessionId: input.sessionId,
|
|
692
|
-
turnId,
|
|
693
|
-
attemptId: input.attemptId,
|
|
694
|
-
workflowId: input.workflowId,
|
|
695
|
-
goalId: goalActive && goal ? goal.id : null,
|
|
696
|
-
goalVersion: goalActive && goal ? goal.version : null,
|
|
697
|
-
earliestResetAt: authoritativeResetAt,
|
|
698
|
-
resetKind: authoritativeResetAt ? "authoritative" : "bounded_refresh",
|
|
699
|
-
failurePayload,
|
|
700
|
-
},
|
|
701
|
-
);
|
|
702
|
-
if (evaluated.action === "stopped") {
|
|
703
|
-
control.turnMetricOutcome = "failed";
|
|
704
|
-
control.activityStatus = evaluated.sessionStatus === "queued" ? "idle" : "failed";
|
|
705
|
-
return { exit: claimedResult({ status: control.activityStatus }) };
|
|
706
|
-
}
|
|
707
|
-
if (evaluated.action === "resumed") {
|
|
708
|
-
control.turnMetricOutcome = "recovering";
|
|
709
|
-
control.activityStatus = "recovering";
|
|
710
|
-
return { exit: claimedResult({ status: "recovering" }) };
|
|
711
|
-
}
|
|
712
|
-
if (evaluated.action === "waiting") {
|
|
713
|
-
control.turnMetricOutcome = "recovering";
|
|
714
|
-
control.activityStatus = "waiting_capacity";
|
|
715
|
-
return {
|
|
716
|
-
exit: claimedResult({
|
|
717
|
-
status: "waiting_capacity",
|
|
718
|
-
capacityWait: {
|
|
719
|
-
waiterId: evaluated.waiter.id,
|
|
720
|
-
generation: evaluated.waiter.generation,
|
|
721
|
-
nextCheckAt: evaluated.waiter.nextCheckAt.toISOString(),
|
|
722
|
-
wakeRevision: evaluated.waiter.wakeRevision,
|
|
723
|
-
},
|
|
724
|
-
}),
|
|
725
|
-
};
|
|
726
|
-
}
|
|
727
|
-
acknowledgeLostAttemptOwnership();
|
|
728
|
-
control.turnMetricOutcome = "cancelled";
|
|
729
|
-
control.activityStatus = "cancelled";
|
|
730
|
-
return { exit: claimedResult({ status: "cancelled" }) };
|
|
731
|
-
}
|
|
732
|
-
if (providerTurn.effectiveCodexCredentialId) {
|
|
733
|
-
const selectionReason = selectionDiagnostics!.reason;
|
|
734
|
-
observability.incrementCounter({
|
|
735
|
-
name: "opengeni_codex_credential_selections_total",
|
|
736
|
-
help: "Codex credential selections by strategy and reason.",
|
|
737
|
-
labels: {
|
|
738
|
-
workspace_key: codexWorkspaceKey,
|
|
739
|
-
strategy: leased.rotationStrategy,
|
|
740
|
-
reason: selectionReason,
|
|
741
|
-
},
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
} catch (error) {
|
|
745
|
-
credentialSelectionOutcome = "failed";
|
|
746
|
-
if (error instanceof CodexCredentialLeaseAttemptFencedError) {
|
|
747
|
-
acknowledgeLostAttemptOwnership();
|
|
748
|
-
control.activityStatus = "cancelled";
|
|
749
|
-
control.turnMetricOutcome = "cancelled";
|
|
750
|
-
return { exit: claimedResult({ status: "cancelled" }) };
|
|
751
|
-
}
|
|
752
|
-
if (error instanceof CodexCredentialFailoverExhaustedError) {
|
|
753
|
-
const settlement = await settleCodexCredentialFailover(db, {
|
|
754
|
-
accountId: input.accountId,
|
|
755
|
-
workspaceId: input.workspaceId,
|
|
756
|
-
sessionId: input.sessionId,
|
|
757
|
-
turnId,
|
|
758
|
-
attemptId: input.attemptId,
|
|
759
|
-
holderId: null,
|
|
760
|
-
generation: null,
|
|
761
|
-
expectedRedispatches: attempt.redispatchesAtDispatch,
|
|
762
|
-
maxFailovers: error.maxFailovers,
|
|
763
|
-
recoveryPayload: {
|
|
764
|
-
triggerEventId: attempt.triggerEventId!,
|
|
765
|
-
reason: "codex_credential_failover_exhausted",
|
|
766
|
-
},
|
|
767
|
-
failedPayload: {
|
|
768
|
-
error:
|
|
769
|
-
"Automatic Codex credential failover stopped after every bounded account attempt was consumed. Send a new message after checking account health or capacity.",
|
|
770
|
-
code: "codex_credential_failover_exhausted",
|
|
771
|
-
retryable: false,
|
|
772
|
-
recovery: "user_message",
|
|
773
|
-
failoverCount: error.failoverCount,
|
|
774
|
-
maxFailovers: error.maxFailovers,
|
|
775
|
-
},
|
|
776
|
-
});
|
|
777
|
-
if (settlement.action === "limit_exceeded") {
|
|
778
|
-
await publishDurableSessionEvents(
|
|
779
|
-
bus,
|
|
780
|
-
input.workspaceId,
|
|
781
|
-
input.sessionId,
|
|
782
|
-
settlement.events,
|
|
783
|
-
);
|
|
784
|
-
control.activityStatus = "idle";
|
|
785
|
-
control.turnMetricOutcome = "failed";
|
|
786
|
-
await deliverFailedChildTurnToParent(
|
|
787
|
-
{ db, bus, settings, observability, wakeSessionWorkflow },
|
|
788
|
-
input.workspaceId,
|
|
789
|
-
input.sessionId,
|
|
790
|
-
turnId,
|
|
791
|
-
);
|
|
792
|
-
return { exit: claimedResult({ status: "idle" }) };
|
|
793
|
-
}
|
|
794
|
-
acknowledgeLostAttemptOwnership();
|
|
795
|
-
control.activityStatus = "cancelled";
|
|
796
|
-
control.turnMetricOutcome = "cancelled";
|
|
797
|
-
return { exit: claimedResult({ status: "cancelled" }) };
|
|
798
|
-
}
|
|
799
|
-
throw error;
|
|
800
|
-
} finally {
|
|
801
|
-
recordTurnStartupPhase(observability, {
|
|
802
|
-
phase: "credential_selection",
|
|
803
|
-
provider: "codex-subscription",
|
|
804
|
-
backend: turn.sandboxBackend,
|
|
805
|
-
outcome: credentialSelectionOutcome,
|
|
806
|
-
durationSeconds: (performance.now() - credentialSelectionStartedAt) / 1_000,
|
|
807
|
-
});
|
|
808
|
-
}
|
|
809
|
-
}
|
|
66
|
+
// This phase is invoked for every turn. Only Codex-billed work may read or
|
|
67
|
+
// be blocked by Codex's one-way cutover state.
|
|
68
|
+
if (!deps.billingState.isCodexTurn) return { ok: true };
|
|
810
69
|
|
|
811
|
-
|
|
70
|
+
const cutover = await withRlsContext(
|
|
71
|
+
deps.db,
|
|
72
|
+
{ accountId: deps.input.accountId, workspaceId: deps.input.workspaceId },
|
|
73
|
+
(scoped) =>
|
|
74
|
+
readSubscriptionProviderCutoverState(scoped, {
|
|
75
|
+
accountId: deps.input.accountId,
|
|
76
|
+
provider: "codex",
|
|
77
|
+
}),
|
|
78
|
+
);
|
|
79
|
+
const disposition = codexCutoverDisposition(cutover);
|
|
80
|
+
// Once the one-way migration has created a provider row, an explicitly
|
|
81
|
+
// disabled cutover must never silently route work back through the legacy
|
|
82
|
+
// Codex tables; an enabled one places the turn on the shared core.
|
|
83
|
+
if (disposition === "fail_closed") throw subscriptionCoreCutoverDisabledFailure();
|
|
84
|
+
return await selectCoreCodexTurnCapacity(deps);
|
|
812
85
|
}
|