@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,72 +1,282 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import {
|
|
2
3
|
CODEX_PROVIDER_ID,
|
|
3
4
|
CODEX_IMAGE_MODEL,
|
|
4
5
|
generateCodexSubscriptionImage,
|
|
5
6
|
type CodexRequestContext,
|
|
6
7
|
} from "@opengeni/codex";
|
|
7
|
-
import
|
|
8
|
+
import {
|
|
9
|
+
acquireSubscriptionCoreCodexOperationLease,
|
|
10
|
+
buildSubscriptionCoreCodexConnectionTokenResolver,
|
|
11
|
+
releaseSubscriptionCoreCodexOperationLease,
|
|
12
|
+
renewSubscriptionCoreCodexOperationLease,
|
|
13
|
+
SubscriptionCoreCodexOperationUnavailableError,
|
|
14
|
+
SubscriptionCoreCodexSourceDisconnectedError,
|
|
15
|
+
reserveSubscriptionCoreCodexOperationRequest,
|
|
16
|
+
settleSubscriptionCoreCodexOperationRequest,
|
|
17
|
+
type Database,
|
|
18
|
+
type SubscriptionCoreCodexOperationLeaseRef,
|
|
19
|
+
type SubscriptionCoreCodexOperationScope,
|
|
20
|
+
type SubscriptionCoreTurnIdentity,
|
|
21
|
+
} from "@opengeni/db";
|
|
22
|
+
import type { Settings } from "@opengeni/config";
|
|
8
23
|
import type { ObjectStorage } from "@opengeni/storage";
|
|
9
24
|
import type { GeneratedImageReceipt } from "./generated-images";
|
|
10
25
|
import { CodexCredentialLeaseLostError } from "./agent-turn/credential-leases";
|
|
26
|
+
import { findCodexCreditPolicyError } from "./agent-turn/codex-credit-policy";
|
|
11
27
|
import {
|
|
12
28
|
executeImageGenerationOperation,
|
|
29
|
+
imageGenerationOperationIdentity,
|
|
13
30
|
imageProviderBindingHash,
|
|
31
|
+
type ImageGenerationOperationPorts,
|
|
14
32
|
} from "./image-generation-operation";
|
|
15
33
|
import type { ResolvedImageGenerationReference } from "./image-generation-references";
|
|
16
34
|
|
|
17
35
|
/** Execute the same standalone subscription image path used by Codex clients. */
|
|
18
|
-
export async function executeCodexImageGeneration(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
export async function executeCodexImageGeneration(
|
|
37
|
+
input: {
|
|
38
|
+
db: Database;
|
|
39
|
+
objectStorage: ObjectStorage | null;
|
|
40
|
+
accountId: string;
|
|
41
|
+
workspaceId: string;
|
|
42
|
+
sessionId: string;
|
|
43
|
+
turnId: string;
|
|
44
|
+
attemptId: string;
|
|
45
|
+
toolCallId: string;
|
|
46
|
+
prompt: string;
|
|
47
|
+
references?: readonly ResolvedImageGenerationReference[];
|
|
48
|
+
credentialId: string;
|
|
49
|
+
codexContext: Pick<
|
|
50
|
+
CodexRequestContext,
|
|
51
|
+
| "clientVersion"
|
|
52
|
+
| "getToken"
|
|
53
|
+
| "refresh"
|
|
54
|
+
| "beforeProviderDispatch"
|
|
55
|
+
| "onProviderRequestSettled"
|
|
56
|
+
>;
|
|
57
|
+
abortSignal?: AbortSignal;
|
|
58
|
+
/** Core turns only: the per-operation lease held around the provider call. */
|
|
59
|
+
operationLease?: { acquire(): Promise<void>; release(): Promise<void> };
|
|
60
|
+
/** Test seam for the provider request; production uses the Codex image client. */
|
|
61
|
+
generateImage?: typeof generateCodexSubscriptionImage;
|
|
62
|
+
},
|
|
63
|
+
ports?: ImageGenerationOperationPorts,
|
|
64
|
+
): Promise<GeneratedImageReceipt> {
|
|
36
65
|
const providerBindingHash = imageProviderBindingHash(CODEX_PROVIDER_ID, input.credentialId);
|
|
37
66
|
let providerDispatchAdmitted = false;
|
|
38
67
|
const codexContext: Pick<
|
|
39
68
|
CodexRequestContext,
|
|
40
|
-
"clientVersion" | "getToken" | "refresh" | "beforeProviderDispatch"
|
|
69
|
+
"clientVersion" | "getToken" | "refresh" | "beforeProviderDispatch" | "onProviderRequestSettled"
|
|
41
70
|
> = {
|
|
42
71
|
...input.codexContext,
|
|
43
|
-
beforeProviderDispatch: async () => {
|
|
44
|
-
await input.codexContext.beforeProviderDispatch?.();
|
|
72
|
+
beforeProviderDispatch: async (request) => {
|
|
73
|
+
await input.codexContext.beforeProviderDispatch?.(request);
|
|
45
74
|
providerDispatchAdmitted = true;
|
|
46
75
|
},
|
|
76
|
+
onProviderRequestSettled: async (request) => {
|
|
77
|
+
await input.codexContext.onProviderRequestSettled?.(request);
|
|
78
|
+
if (request.outcome === "refused") providerDispatchAdmitted = false;
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
return await executeImageGenerationOperation(
|
|
82
|
+
{
|
|
83
|
+
...input,
|
|
84
|
+
providerId: CODEX_PROVIDER_ID,
|
|
85
|
+
providerBindingHash,
|
|
86
|
+
modelId: CODEX_IMAGE_MODEL,
|
|
87
|
+
...(input.references ? { referenceDigests: input.references } : {}),
|
|
88
|
+
isProviderDispatchRejected: (error) =>
|
|
89
|
+
!providerDispatchAdmitted &&
|
|
90
|
+
(error instanceof CodexCredentialLeaseLostError ||
|
|
91
|
+
findCodexCreditPolicyError(error) !== null),
|
|
92
|
+
generate: async () => {
|
|
93
|
+
// A lease that cannot be taken is a verified pre-dispatch rejection:
|
|
94
|
+
// the ledger returns to `prepared` and nothing reached the provider.
|
|
95
|
+
await input.operationLease?.acquire();
|
|
96
|
+
let generated: Awaited<ReturnType<typeof generateCodexSubscriptionImage>>;
|
|
97
|
+
try {
|
|
98
|
+
generated = await (input.generateImage ?? generateCodexSubscriptionImage)({
|
|
99
|
+
prompt: input.prompt,
|
|
100
|
+
...(input.references ? { references: input.references } : {}),
|
|
101
|
+
turnId: input.turnId,
|
|
102
|
+
context: codexContext,
|
|
103
|
+
...(input.abortSignal ? { abortSignal: input.abortSignal } : {}),
|
|
104
|
+
});
|
|
105
|
+
} finally {
|
|
106
|
+
await input.operationLease?.release().catch(() => undefined);
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
toolCallId: input.toolCallId,
|
|
110
|
+
providerItemId: null,
|
|
111
|
+
bytes: generated.bytes,
|
|
112
|
+
declaredMediaType: generated.declaredMediaType,
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
...(ports ? [ports] : []),
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* A Codex image operation of a turn placed by the shared subscription core
|
|
122
|
+
* (M3 PR 2c, EP-T17). It runs on the turn's own leased chat connection under
|
|
123
|
+
* the turn's accepted authority, but holds its own operation lease (kind
|
|
124
|
+
* `image`, keyed by the ledger's turn/tool-call operation id) and reads and
|
|
125
|
+
* refreshes the credential through the operation seam. The chat-turn lease
|
|
126
|
+
* and the session binding are never read or written, so concurrent image
|
|
127
|
+
* calls never contend with the chat turn or each other.
|
|
128
|
+
*/
|
|
129
|
+
export async function executeCoreCodexImageGeneration(
|
|
130
|
+
input: Omit<
|
|
131
|
+
Parameters<typeof executeCodexImageGeneration>[0],
|
|
132
|
+
"credentialId" | "codexContext" | "operationLease"
|
|
133
|
+
> & {
|
|
134
|
+
settings: Settings;
|
|
135
|
+
core: { identity: SubscriptionCoreTurnIdentity; connectionId: string };
|
|
136
|
+
executionGeneration: number;
|
|
137
|
+
clientVersion: string;
|
|
138
|
+
/**
|
|
139
|
+
* The turn's chat-lease dispatch fence (`leases.codex.assertCurrentForDispatch`):
|
|
140
|
+
* an image operation runs only while its turn's live attempt still holds
|
|
141
|
+
* the chat lease, checked before the operation lease is taken and before
|
|
142
|
+
* the provider call.
|
|
143
|
+
*/
|
|
144
|
+
assertChatLease: () => Promise<void>;
|
|
145
|
+
/** Uses the same live account spending policy as the owning chat turn. */
|
|
146
|
+
assertCreditAdmission: () => Promise<void>;
|
|
147
|
+
deps?: {
|
|
148
|
+
acquire?: typeof acquireSubscriptionCoreCodexOperationLease;
|
|
149
|
+
renew?: typeof renewSubscriptionCoreCodexOperationLease;
|
|
150
|
+
release?: typeof releaseSubscriptionCoreCodexOperationLease;
|
|
151
|
+
resolver?: typeof buildSubscriptionCoreCodexConnectionTokenResolver;
|
|
152
|
+
reserve?: typeof reserveSubscriptionCoreCodexOperationRequest;
|
|
153
|
+
settle?: typeof settleSubscriptionCoreCodexOperationRequest;
|
|
154
|
+
ports?: ImageGenerationOperationPorts;
|
|
155
|
+
generateImage?: typeof generateCodexSubscriptionImage;
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
): Promise<GeneratedImageReceipt> {
|
|
159
|
+
const acquire = input.deps?.acquire ?? acquireSubscriptionCoreCodexOperationLease;
|
|
160
|
+
const renew = input.deps?.renew ?? renewSubscriptionCoreCodexOperationLease;
|
|
161
|
+
const release = input.deps?.release ?? releaseSubscriptionCoreCodexOperationLease;
|
|
162
|
+
const buildResolver = input.deps?.resolver ?? buildSubscriptionCoreCodexConnectionTokenResolver;
|
|
163
|
+
const reserve = input.deps?.reserve ?? reserveSubscriptionCoreCodexOperationRequest;
|
|
164
|
+
const settle = input.deps?.settle ?? settleSubscriptionCoreCodexOperationRequest;
|
|
165
|
+
const scope: SubscriptionCoreCodexOperationScope = {
|
|
166
|
+
kind: "turn",
|
|
167
|
+
identity: input.core.identity,
|
|
47
168
|
};
|
|
48
|
-
|
|
49
|
-
|
|
169
|
+
const { operationId } = imageGenerationOperationIdentity({
|
|
170
|
+
workspaceId: input.workspaceId,
|
|
171
|
+
sessionId: input.sessionId,
|
|
172
|
+
turnId: input.turnId,
|
|
173
|
+
toolCallId: input.toolCallId,
|
|
50
174
|
providerId: CODEX_PROVIDER_ID,
|
|
51
|
-
providerBindingHash,
|
|
175
|
+
providerBindingHash: imageProviderBindingHash(CODEX_PROVIDER_ID, input.core.connectionId),
|
|
52
176
|
modelId: CODEX_IMAGE_MODEL,
|
|
177
|
+
prompt: input.prompt,
|
|
53
178
|
...(input.references ? { referenceDigests: input.references } : {}),
|
|
54
|
-
isProviderDispatchRejected: (error) =>
|
|
55
|
-
!providerDispatchAdmitted && error instanceof CodexCredentialLeaseLostError,
|
|
56
|
-
generate: async () => {
|
|
57
|
-
const generated = await generateCodexSubscriptionImage({
|
|
58
|
-
prompt: input.prompt,
|
|
59
|
-
...(input.references ? { references: input.references } : {}),
|
|
60
|
-
turnId: input.turnId,
|
|
61
|
-
context: codexContext,
|
|
62
|
-
...(input.abortSignal ? { abortSignal: input.abortSignal } : {}),
|
|
63
|
-
});
|
|
64
|
-
return {
|
|
65
|
-
toolCallId: input.toolCallId,
|
|
66
|
-
providerItemId: null,
|
|
67
|
-
bytes: generated.bytes,
|
|
68
|
-
declaredMediaType: generated.declaredMediaType,
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
179
|
});
|
|
180
|
+
const ref: SubscriptionCoreCodexOperationLeaseRef = {
|
|
181
|
+
operationId,
|
|
182
|
+
attemptId: input.attemptId,
|
|
183
|
+
operationKind: "image",
|
|
184
|
+
connectionId: input.core.connectionId,
|
|
185
|
+
// Bounded (the column allows 256 characters): tool-call ids are provider-supplied.
|
|
186
|
+
holderId: `image:${createHash("sha256").update(`${input.attemptId}\0${input.toolCallId}`).digest("hex")}`,
|
|
187
|
+
generation: input.executionGeneration,
|
|
188
|
+
};
|
|
189
|
+
const resolver = buildResolver(input.db, input.settings, scope, input.core.connectionId, ref);
|
|
190
|
+
// Nothing has reached the provider yet: any failure here, including a
|
|
191
|
+
// transient database error, is a verified pre-dispatch rejection.
|
|
192
|
+
const preDispatch = async (step: () => Promise<void>): Promise<void> => {
|
|
193
|
+
try {
|
|
194
|
+
await step();
|
|
195
|
+
} catch (error) {
|
|
196
|
+
if (error instanceof CodexCredentialLeaseLostError || findCodexCreditPolicyError(error))
|
|
197
|
+
throw error;
|
|
198
|
+
throw new CodexCredentialLeaseLostError("not_found");
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
const unavailable = (error: unknown): never => {
|
|
202
|
+
// The operation lost its lease, scope or enabled cutover before dispatch.
|
|
203
|
+
if (
|
|
204
|
+
error instanceof SubscriptionCoreCodexOperationUnavailableError ||
|
|
205
|
+
error instanceof SubscriptionCoreCodexSourceDisconnectedError
|
|
206
|
+
) {
|
|
207
|
+
throw new CodexCredentialLeaseLostError("not_found");
|
|
208
|
+
}
|
|
209
|
+
throw error;
|
|
210
|
+
};
|
|
211
|
+
const {
|
|
212
|
+
deps: _deps,
|
|
213
|
+
settings: _settings,
|
|
214
|
+
core: _core,
|
|
215
|
+
assertChatLease: _assertChatLease,
|
|
216
|
+
assertCreditAdmission: _assertCreditAdmission,
|
|
217
|
+
...operationInput
|
|
218
|
+
} = input;
|
|
219
|
+
let pendingRequest: { operationId: string; responseReceived: boolean } | null = null;
|
|
220
|
+
let uncertain = false;
|
|
221
|
+
const receipt = await executeCodexImageGeneration(
|
|
222
|
+
{
|
|
223
|
+
...operationInput,
|
|
224
|
+
credentialId: input.core.connectionId,
|
|
225
|
+
...(input.deps?.generateImage ? { generateImage: input.deps.generateImage } : {}),
|
|
226
|
+
codexContext: {
|
|
227
|
+
clientVersion: input.clientVersion,
|
|
228
|
+
getToken: () => resolver.getToken().catch(unavailable),
|
|
229
|
+
refresh: () => resolver.refresh().catch(unavailable),
|
|
230
|
+
beforeProviderDispatch: async (request) => {
|
|
231
|
+
await preDispatch(async () => {
|
|
232
|
+
if (!request || pendingRequest || uncertain)
|
|
233
|
+
throw new Error("Image request predecessor is unsettled");
|
|
234
|
+
await input.assertCreditAdmission();
|
|
235
|
+
await input.assertChatLease();
|
|
236
|
+
if (!(await renew(input.db, scope, ref))) {
|
|
237
|
+
throw new CodexCredentialLeaseLostError("not_found");
|
|
238
|
+
}
|
|
239
|
+
const reserved = await reserve(input.db, scope, ref, input.core.connectionId, request);
|
|
240
|
+
pendingRequest = { ...reserved, responseReceived: false };
|
|
241
|
+
});
|
|
242
|
+
},
|
|
243
|
+
onProviderRequestSettled: async ({ outcome }) => {
|
|
244
|
+
if (!pendingRequest) throw new Error("Image request settlement has no reservation");
|
|
245
|
+
if (outcome === "response_received") {
|
|
246
|
+
pendingRequest.responseReceived = true;
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (outcome === "unknown") uncertain = true;
|
|
250
|
+
await settle(input.db, scope, { operationId: pendingRequest.operationId, outcome });
|
|
251
|
+
pendingRequest = null;
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
operationLease: {
|
|
255
|
+
acquire: async () => {
|
|
256
|
+
await preDispatch(async () => {
|
|
257
|
+
await input.assertChatLease();
|
|
258
|
+
const lease = await acquire(input.db, scope, ref);
|
|
259
|
+
if (lease.kind !== "acquired") throw new CodexCredentialLeaseLostError("not_found");
|
|
260
|
+
});
|
|
261
|
+
},
|
|
262
|
+
release: async () => {
|
|
263
|
+
await release(input.db, scope, ref);
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
input.deps?.ports,
|
|
268
|
+
);
|
|
269
|
+
// The image operation has retained the bytes and committed its artifact
|
|
270
|
+
// receipt. A transport success alone never licensed this native settlement.
|
|
271
|
+
const completedRequest = pendingRequest as {
|
|
272
|
+
operationId: string;
|
|
273
|
+
responseReceived: boolean;
|
|
274
|
+
} | null;
|
|
275
|
+
if (completedRequest?.responseReceived) {
|
|
276
|
+
await settle(input.db, scope, {
|
|
277
|
+
operationId: completedRequest.operationId,
|
|
278
|
+
outcome: "response_received",
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
return receipt;
|
|
72
282
|
}
|
package/src/activities/common.ts
CHANGED
|
@@ -29,7 +29,18 @@ export function scheduledUserMessagePayload(
|
|
|
29
29
|
tools: ToolRef[],
|
|
30
30
|
taskId: string,
|
|
31
31
|
runId: string,
|
|
32
|
+
degradedAccounts: readonly { serverId: string }[] = [],
|
|
32
33
|
): Extract<SessionSystemUpdatePayload, { type: "scheduled_occurrence" }> {
|
|
34
|
+
// Connectors this occurrence runs without because every account a person
|
|
35
|
+
// pinned for them is unusable. A connector that kept a working pin still has
|
|
36
|
+
// its tools and is not named.
|
|
37
|
+
const unavailableConnectors = [
|
|
38
|
+
...new Set(
|
|
39
|
+
degradedAccounts
|
|
40
|
+
.map((account) => account.serverId)
|
|
41
|
+
.filter((serverId) => !tools.some((tool) => tool.kind === "mcp" && tool.id === serverId)),
|
|
42
|
+
),
|
|
43
|
+
].sort();
|
|
33
44
|
return {
|
|
34
45
|
type: "scheduled_occurrence",
|
|
35
46
|
text: prompt,
|
|
@@ -37,6 +48,7 @@ export function scheduledUserMessagePayload(
|
|
|
37
48
|
scheduledTaskRunId: runId,
|
|
38
49
|
...(resources.length ? { resources } : {}),
|
|
39
50
|
...(tools.length ? { tools } : {}),
|
|
51
|
+
...(unavailableConnectors.length ? { unavailableConnectors } : {}),
|
|
40
52
|
};
|
|
41
53
|
}
|
|
42
54
|
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
import {
|
|
13
13
|
ChannelAPartialMutationError,
|
|
14
14
|
RoutingMutationOutcomeUnknownError,
|
|
15
|
+
isRoutingMutationOutputRejectedError,
|
|
15
16
|
SandboxChannelAService,
|
|
16
17
|
} from "@opengeni/runtime/sandbox";
|
|
17
18
|
|
|
@@ -159,7 +160,8 @@ export async function materializeConnectorAttachmentsInChannel(
|
|
|
159
160
|
} catch (error) {
|
|
160
161
|
if (
|
|
161
162
|
error instanceof ChannelAPartialMutationError ||
|
|
162
|
-
error instanceof RoutingMutationOutcomeUnknownError
|
|
163
|
+
error instanceof RoutingMutationOutcomeUnknownError ||
|
|
164
|
+
isRoutingMutationOutputRejectedError(error)
|
|
163
165
|
) {
|
|
164
166
|
throw error;
|
|
165
167
|
}
|
|
@@ -9,7 +9,14 @@ import {
|
|
|
9
9
|
import {
|
|
10
10
|
EmptyCompactionSummaryError,
|
|
11
11
|
REMOTE_COMPACTION_V2_IMPLEMENTATION,
|
|
12
|
-
|
|
12
|
+
compactionSummaryOutputTokens,
|
|
13
|
+
buildSummaryItem,
|
|
14
|
+
buildCompactionPromptInput,
|
|
15
|
+
fitCompactionPrefix,
|
|
16
|
+
ANTHROPIC_REQUEST_MAX_BYTES,
|
|
17
|
+
AnthropicSizeRecoveryExhaustedError,
|
|
18
|
+
type AnthropicRequestSize,
|
|
19
|
+
omitOpaqueArtifactsFromPortableCompactionHistory,
|
|
13
20
|
buildCompactionReplacementHistory,
|
|
14
21
|
buildRemoteV2ReplacementHistory,
|
|
15
22
|
compactionThresholdTokens,
|
|
@@ -58,7 +65,15 @@ export type MaybeCompactResult =
|
|
|
58
65
|
* Codex, call Codex `/codex/responses` with `compaction_trigger` and persist the
|
|
59
66
|
* opaque compaction item. Fail closed — never silently fall back to portable.
|
|
60
67
|
*/
|
|
61
|
-
export type CompactionSummarizer = (
|
|
68
|
+
export type CompactionSummarizer = ((
|
|
69
|
+
settings: Settings,
|
|
70
|
+
input: CompactionItem[],
|
|
71
|
+
) => Promise<string>) & {
|
|
72
|
+
/** Model-visible instructions and tool schemas outside the history estimate. */
|
|
73
|
+
estimatePrefixTokens?: () => number;
|
|
74
|
+
/** Exact provider wire size, with the same projection as the checkpoint call. */
|
|
75
|
+
measureInputBytes?: (settings: Settings, input: CompactionItem[]) => Promise<number>;
|
|
76
|
+
};
|
|
62
77
|
|
|
63
78
|
/** Returns the opaque Codex remote compaction v2 item. */
|
|
64
79
|
export type RemoteCompactionV2Requester = (
|
|
@@ -81,7 +96,7 @@ export async function maybeCompactContext(
|
|
|
81
96
|
// Injectable for tests; defaults to the real provider-aware model call.
|
|
82
97
|
summarize: CompactionSummarizer = (s, m) =>
|
|
83
98
|
summarizeForCompaction(s, m, {
|
|
84
|
-
maxOutputTokens:
|
|
99
|
+
maxOutputTokens: compactionSummaryOutputTokens(s.contextWindowTokens),
|
|
85
100
|
}),
|
|
86
101
|
// Operator-forced (the /compact command): bypass the budget trigger and
|
|
87
102
|
// compact now if there is anything to summarize. Structural guards still hold.
|
|
@@ -107,6 +122,8 @@ export async function maybeCompactContext(
|
|
|
107
122
|
materializeHistory?: (items: CompactionItem[]) => Promise<CompactionItem[]>;
|
|
108
123
|
/** Turn-scoped attachment/modality view; canonical persisted rows stay untouched. */
|
|
109
124
|
projectModelInput?: (items: CompactionItem[]) => Promise<CompactionItem[]>;
|
|
125
|
+
/** A typed pre-dispatch size rejection parks the newest complete work unit. */
|
|
126
|
+
requestSizeRecovery?: { maxBytes: number; size: AnthropicRequestSize };
|
|
110
127
|
} = {},
|
|
111
128
|
): Promise<MaybeCompactResult> {
|
|
112
129
|
if (options.codexCompactionMode === "remote_v2" && options.isCodexSubscriptionTurn !== true) {
|
|
@@ -205,9 +222,14 @@ export async function maybeCompactContext(
|
|
|
205
222
|
expectedAttemptId: scope.attemptId,
|
|
206
223
|
trigger,
|
|
207
224
|
estimatedTokensBefore,
|
|
225
|
+
...(options.requestSizeRecovery
|
|
226
|
+
? { requestSizeRecovery: options.requestSizeRecovery.size }
|
|
227
|
+
: {}),
|
|
208
228
|
...(useRemoteV2 ? { implementation: REMOTE_COMPACTION_V2_IMPLEMENTATION } : {}),
|
|
209
229
|
});
|
|
210
230
|
if (!started.recorded) {
|
|
231
|
+
if (started.reason === "request_size_recovery_exhausted")
|
|
232
|
+
throw new AnthropicSizeRecoveryExhaustedError();
|
|
211
233
|
throw new TurnAttemptFencedError(
|
|
212
234
|
`turn attempt was fenced while recording context compaction start: ${started.reason}`,
|
|
213
235
|
);
|
|
@@ -275,6 +297,44 @@ export async function settleFailedContextCompactionLandmark(
|
|
|
275
297
|
return settled;
|
|
276
298
|
}
|
|
277
299
|
|
|
300
|
+
/**
|
|
301
|
+
* After `compaction.started`, record that the checkpoint request was cut short
|
|
302
|
+
* by the attempt's own cancellation (graceful worker shutdown, or any other
|
|
303
|
+
* activity cancellation) rather than by a provider or summarizer failure.
|
|
304
|
+
*
|
|
305
|
+
* Unlike {@link settleFailedContextCompactionLandmark}, this never consumes an
|
|
306
|
+
* operator `/compact` request: the recovered attempt of the same turn
|
|
307
|
+
* re-evaluates, exactly as when a Pause has already fenced the attempt. A
|
|
308
|
+
* fence rejection is not an error here: the control that closed the attempt
|
|
309
|
+
* owns the outcome, so the caller's cancellation must keep propagating.
|
|
310
|
+
*/
|
|
311
|
+
export async function settleInterruptedContextCompactionLandmark(
|
|
312
|
+
db: Database,
|
|
313
|
+
scope: {
|
|
314
|
+
accountId: string;
|
|
315
|
+
workspaceId: string;
|
|
316
|
+
sessionId: string;
|
|
317
|
+
turnId: string;
|
|
318
|
+
executionGeneration: number;
|
|
319
|
+
attemptId: string;
|
|
320
|
+
},
|
|
321
|
+
options: {
|
|
322
|
+
publishLiveEvents?: (events: SessionEvent[]) => Promise<void>;
|
|
323
|
+
} = {},
|
|
324
|
+
): Promise<{ recorded: boolean; events: SessionEvent[] }> {
|
|
325
|
+
const skipped = await recordSkippedContextCompaction(db, {
|
|
326
|
+
...scope,
|
|
327
|
+
expectedExecutionGeneration: scope.executionGeneration,
|
|
328
|
+
expectedAttemptId: scope.attemptId,
|
|
329
|
+
reason: "interrupted",
|
|
330
|
+
requirePendingRequest: false,
|
|
331
|
+
clearRequestedCompaction: false,
|
|
332
|
+
});
|
|
333
|
+
if (!skipped.recorded) return { recorded: false, events: [] };
|
|
334
|
+
await options.publishLiveEvents?.(skipped.events);
|
|
335
|
+
return { recorded: true, events: skipped.events };
|
|
336
|
+
}
|
|
337
|
+
|
|
278
338
|
function prependCompactionEvents(
|
|
279
339
|
prefix: SessionEvent[],
|
|
280
340
|
outcome: MaybeCompactResult,
|
|
@@ -300,6 +360,7 @@ async function settleSkippedAfterStart(
|
|
|
300
360
|
reason:
|
|
301
361
|
| "no_history"
|
|
302
362
|
| "replacement_not_smaller"
|
|
363
|
+
| "replacement_exceeds_model_budget"
|
|
303
364
|
| "replacement_unchanged"
|
|
304
365
|
| "summarization_failed",
|
|
305
366
|
): Promise<Extract<MaybeCompactResult, { compacted: false }>> {
|
|
@@ -448,21 +509,82 @@ async function compactContextPortable(
|
|
|
448
509
|
options: {
|
|
449
510
|
clearRequestedCompaction?: boolean;
|
|
450
511
|
trigger?: "auto" | "operator" | "proactive" | "overflow";
|
|
512
|
+
requestSizeRecovery?: { maxBytes: number };
|
|
451
513
|
},
|
|
452
514
|
projectForWire: (items: CompactionItem[]) => Promise<CompactionItem[]>,
|
|
453
515
|
): Promise<MaybeCompactResult> {
|
|
454
516
|
const estimatedTokensBefore = estimateTokens(items);
|
|
455
|
-
const
|
|
517
|
+
const prefixTokens = Math.max(0, Math.ceil(summarize.estimatePrefixTokens?.() ?? 0));
|
|
518
|
+
const outputReserve = compactionSummaryOutputTokens(settings.contextWindowTokens);
|
|
519
|
+
const structuralBudget = Math.min(
|
|
520
|
+
contextInputBudgetTokens(settings) || settings.contextWindowTokens - outputReserve,
|
|
521
|
+
settings.contextWindowTokens - outputReserve,
|
|
522
|
+
);
|
|
523
|
+
let summarizedItems = canonicalItems;
|
|
524
|
+
let deferredItems: CompactionItem[] = [];
|
|
525
|
+
let summarized: Awaited<ReturnType<typeof summarizeWithCodexOverflowTrimming>>;
|
|
526
|
+
if (summarize.measureInputBytes) {
|
|
527
|
+
const budget = Math.max(0, structuralBudget - prefixTokens);
|
|
528
|
+
const maxBytes = Math.min(
|
|
529
|
+
ANTHROPIC_REQUEST_MAX_BYTES,
|
|
530
|
+
options.requestSizeRecovery?.maxBytes ?? ANTHROPIC_REQUEST_MAX_BYTES,
|
|
531
|
+
);
|
|
532
|
+
const prepare = async (prefix: CompactionItem[]) =>
|
|
533
|
+
buildCompactionPromptInput(
|
|
534
|
+
omitOpaqueArtifactsFromPortableCompactionHistory(await projectForWire(prefix)),
|
|
535
|
+
);
|
|
536
|
+
const cut = await fitCompactionPrefix(
|
|
537
|
+
canonicalItems,
|
|
538
|
+
async (prefix) => {
|
|
539
|
+
const projected = await prepare(prefix);
|
|
540
|
+
return (
|
|
541
|
+
estimateTokens(projected) <= budget &&
|
|
542
|
+
(await summarize.measureInputBytes!(settings, projected)) <= maxBytes
|
|
543
|
+
);
|
|
544
|
+
},
|
|
545
|
+
Boolean(options.requestSizeRecovery),
|
|
546
|
+
);
|
|
547
|
+
if (cut === null)
|
|
548
|
+
throw new EmptyCompactionSummaryError({
|
|
549
|
+
stage: "portable_byte_budget",
|
|
550
|
+
reason: "no_complete_prefix_fit",
|
|
551
|
+
});
|
|
552
|
+
summarizedItems = canonicalItems.slice(0, cut);
|
|
553
|
+
deferredItems = canonicalItems.slice(cut);
|
|
554
|
+
const projected = await prepare(summarizedItems);
|
|
555
|
+
summarized = {
|
|
556
|
+
summaryBody: await summarize(settings, projected),
|
|
557
|
+
preparation: {
|
|
558
|
+
input: projected,
|
|
559
|
+
estimatedInputTokens: estimateTokens(projected),
|
|
560
|
+
rewrittenToolOutputs: 0,
|
|
561
|
+
droppedHistoryItems: 0,
|
|
562
|
+
},
|
|
563
|
+
providerCalls: 1,
|
|
564
|
+
};
|
|
565
|
+
} else summarized = await summarizeWithCodexOverflowTrimming(summarize, settings, items);
|
|
456
566
|
const summaryBody = summarized.summaryBody;
|
|
457
567
|
const retainedTokens = await retentionTokenCounts(canonicalItems, projectForWire);
|
|
568
|
+
const summaryTokens = estimateTokens([buildSummaryItem(summaryBody)]);
|
|
458
569
|
const replacementHistory = buildCompactionReplacementHistory(
|
|
459
|
-
|
|
570
|
+
summarizedItems,
|
|
460
571
|
summaryBody,
|
|
461
572
|
(item) => retainedTokens.get(item) ?? estimateTokens([item]),
|
|
573
|
+
Math.min(outputReserve, Math.max(0, structuralBudget - prefixTokens - summaryTokens)),
|
|
462
574
|
);
|
|
463
|
-
const estimatedTokensAfter = estimateTokens(
|
|
464
|
-
|
|
465
|
-
|
|
575
|
+
const estimatedTokensAfter = estimateTokens(
|
|
576
|
+
await projectForWire([...replacementHistory, ...deferredItems]),
|
|
577
|
+
);
|
|
578
|
+
if (estimatedTokensAfter + prefixTokens > structuralBudget) {
|
|
579
|
+
return await settleSkippedAfterStart(db, scope, options, "replacement_exceeds_model_budget");
|
|
580
|
+
}
|
|
581
|
+
const replacementFingerprint = compactionReplacementFingerprint([
|
|
582
|
+
...replacementHistory,
|
|
583
|
+
...deferredItems,
|
|
584
|
+
]);
|
|
585
|
+
const previousReplacementFingerprint = deferredItems.length
|
|
586
|
+
? compactionReplacementFingerprint(canonicalItems)
|
|
587
|
+
: latestCompactionReplacementFingerprint(canonicalItems);
|
|
466
588
|
const summaryIndex =
|
|
467
589
|
replacementHistory.length -
|
|
468
590
|
(readReasoningConfiguration(replacementHistory.at(-1) ?? {}) ? 2 : 1);
|
|
@@ -486,8 +608,8 @@ async function compactContextPortable(
|
|
|
486
608
|
expectedExecutionGeneration: scope.executionGeneration,
|
|
487
609
|
expectedAttemptId: scope.attemptId,
|
|
488
610
|
replacementItems: replacementHistory.slice(0, summaryIndex),
|
|
489
|
-
...(replacementHistory.length > summaryIndex + 1
|
|
490
|
-
? { trailingItems: replacementHistory.slice(summaryIndex + 1) }
|
|
611
|
+
...(replacementHistory.length > summaryIndex + 1 || deferredItems.length > 0
|
|
612
|
+
? { trailingItems: [...replacementHistory.slice(summaryIndex + 1), ...deferredItems] }
|
|
491
613
|
: {}),
|
|
492
614
|
summaryItem: summaryItem as Record<string, unknown>,
|
|
493
615
|
...(options.clearRequestedCompaction ? { clearRequestedCompaction: true } : {}),
|
|
@@ -499,6 +621,9 @@ async function compactContextPortable(
|
|
|
499
621
|
compactionInputToolOutputsRewritten: summarized.preparation.rewrittenToolOutputs,
|
|
500
622
|
compactionInputHistoryItemsDropped: summarized.preparation.droppedHistoryItems,
|
|
501
623
|
compactionInputProviderCalls: summarized.providerCalls,
|
|
624
|
+
...(summarize.measureInputBytes
|
|
625
|
+
? { compactionDeferredHistoryItems: deferredItems.length }
|
|
626
|
+
: {}),
|
|
502
627
|
},
|
|
503
628
|
});
|
|
504
629
|
if (!applied.applied) {
|
|
@@ -520,7 +645,7 @@ async function compactContextPortable(
|
|
|
520
645
|
};
|
|
521
646
|
}
|
|
522
647
|
|
|
523
|
-
async function summarizeWithCodexOverflowTrimming(
|
|
648
|
+
export async function summarizeWithCodexOverflowTrimming(
|
|
524
649
|
summarize: CompactionSummarizer,
|
|
525
650
|
settings: Settings,
|
|
526
651
|
activeHistory: CompactionItem[],
|
|
@@ -531,17 +656,32 @@ async function summarizeWithCodexOverflowTrimming(
|
|
|
531
656
|
}> {
|
|
532
657
|
// Codex's estimator is intentionally coarse. Keep the explicit checkpoint
|
|
533
658
|
// request below both the effective input window and the raw window minus the
|
|
534
|
-
// requested summary
|
|
535
|
-
//
|
|
536
|
-
//
|
|
537
|
-
const summaryAwareBudget = Math.max(
|
|
659
|
+
// requested summary. Preserve the full portable history copy on the first
|
|
660
|
+
// call whenever it fits; only trim further after an actual provider overflow.
|
|
661
|
+
// Durable active history remains untouched until applyContextCompaction.
|
|
662
|
+
const summaryAwareBudget = Math.max(
|
|
663
|
+
0,
|
|
664
|
+
settings.contextWindowTokens - compactionSummaryOutputTokens(settings.contextWindowTokens),
|
|
665
|
+
);
|
|
538
666
|
const configuredInputBudget = contextInputBudgetTokens(settings);
|
|
539
667
|
const structuralBudget = Math.min(
|
|
540
668
|
configuredInputBudget > 0 ? configuredInputBudget : summaryAwareBudget,
|
|
541
669
|
summaryAwareBudget,
|
|
542
670
|
);
|
|
543
|
-
const
|
|
671
|
+
const prefixTokens = Math.max(0, Math.ceil(summarize.estimatePrefixTokens?.() ?? 0));
|
|
672
|
+
const initialBudget = Math.max(0, structuralBudget - prefixTokens);
|
|
544
673
|
let preparation = prepareCompactionPromptInput(activeHistory, initialBudget);
|
|
674
|
+
// A checkpoint prompt without source history cannot summarize that history.
|
|
675
|
+
// Do not let a plausible-sounding reply replace durable active context.
|
|
676
|
+
const requireHistory = () => {
|
|
677
|
+
if (activeHistory.length > 0 && preparation.input.length === 1) {
|
|
678
|
+
throw new EmptyCompactionSummaryError({
|
|
679
|
+
stage: "portable_input_budget",
|
|
680
|
+
reason: "no_history_fit",
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
requireHistory();
|
|
545
685
|
try {
|
|
546
686
|
return {
|
|
547
687
|
summaryBody: await summarize(settings, preparation.input),
|
|
@@ -551,15 +691,16 @@ async function summarizeWithCodexOverflowTrimming(
|
|
|
551
691
|
} catch (error) {
|
|
552
692
|
if (!isContextWindowExceeded(error)) throw error;
|
|
553
693
|
// The provider is more authoritative than the byte/4 estimate. Refit once
|
|
554
|
-
// to
|
|
694
|
+
// to 40% of both the available target and the actual prepared estimate;
|
|
555
695
|
// then fail terminally with prior history intact. Never issue one failing
|
|
556
|
-
// request per oldest item. The
|
|
557
|
-
// provider can count slightly more than twice the byte/4 estimate
|
|
558
|
-
//
|
|
696
|
+
// request per oldest item. The retry is bounded, not a guarantee: the
|
|
697
|
+
// provider can count slightly more than twice the byte/4 estimate. The
|
|
698
|
+
// prepared prefix has already been reserved from the available budget.
|
|
559
699
|
const retryBudget = Math.floor(
|
|
560
|
-
Math.min(initialBudget * 0.
|
|
700
|
+
Math.min(initialBudget * 0.4, preparation.estimatedInputTokens * 0.4),
|
|
561
701
|
);
|
|
562
702
|
preparation = prepareCompactionPromptInput(activeHistory, retryBudget);
|
|
703
|
+
requireHistory();
|
|
563
704
|
return {
|
|
564
705
|
summaryBody: await summarize(settings, preparation.input),
|
|
565
706
|
preparation,
|