deepline 0.3.535 → 0.3.536
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/bundling-sources/sdk/src/client-core.ts +232 -147
- package/dist/bundling-sources/sdk/src/index.ts +4 -0
- package/dist/bundling-sources/sdk/src/plays/local-file-discovery.ts +27 -1
- package/dist/bundling-sources/sdk/src/plays/run-request.ts +16 -5
- package/dist/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/sdk/src/types.ts +2 -23
- package/dist/bundling-sources/shared_libs/integration-contracts/monitor-fleet-contract.ts +26 -14
- package/dist/bundling-sources/shared_libs/integration-contracts/monitor-input-contract.ts +33 -8
- package/dist/bundling-sources/shared_libs/monitors/fleets/count-drift-alert.ts +121 -0
- package/dist/bundling-sources/shared_libs/monitors/fleets/limits.ts +8 -0
- package/dist/bundling-sources/shared_libs/monitors/fleets/plan.ts +14 -82
- package/dist/bundling-sources/shared_libs/monitors/package.json +1 -0
- package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +4 -4
- package/dist/bundling-sources/shared_libs/play-data-plane/r2.ts +0 -26
- package/dist/bundling-sources/shared_libs/play-runtime/activity-observation.ts +36 -0
- package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +21 -31
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +88 -96
- package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +12 -10
- package/dist/bundling-sources/shared_libs/play-runtime/durable-summary-events.ts +3 -1
- package/dist/bundling-sources/shared_libs/play-runtime/governor/app-runtime-rate-state-backend.ts +71 -2
- package/dist/bundling-sources/shared_libs/play-runtime/governor/governor.ts +9 -0
- package/dist/bundling-sources/shared_libs/play-runtime/governor/rate-state-backend.ts +2 -0
- package/dist/bundling-sources/shared_libs/play-runtime/launch-identity.ts +1 -0
- package/dist/bundling-sources/shared_libs/play-runtime/map-memory-limits.ts +127 -9
- package/dist/bundling-sources/shared_libs/play-runtime/memory-ledger.ts +15 -2
- package/dist/bundling-sources/shared_libs/play-runtime/prebuilt-result-quality.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +6 -0
- package/dist/bundling-sources/shared_libs/play-runtime/provider-capacity/fixture-capacity-simulator.ts +1 -0
- package/dist/bundling-sources/shared_libs/play-runtime/provider-capacity/gradient2-concurrency-controller.ts +41 -0
- package/dist/bundling-sources/shared_libs/play-runtime/provider-capacity/provider-capacity-policy.ts +6 -0
- package/dist/bundling-sources/shared_libs/play-runtime/provider-capacity/provider-concurrency-policy.ts +9 -0
- package/dist/bundling-sources/shared_libs/play-runtime/resource-governor.ts +7 -0
- package/dist/bundling-sources/shared_libs/play-runtime/run-failure.ts +2 -2
- package/dist/bundling-sources/shared_libs/play-runtime/run-ledger.ts +5 -2
- package/dist/bundling-sources/shared_libs/play-runtime/runner-app/runtime-tool-hooks.ts +8 -3
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-operation-contract.ts +7 -0
- package/dist/bundling-sources/shared_libs/play-runtime/sandbox-compute-usage.ts +31 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +6 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +26 -1
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-scope.ts +11 -4
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +73 -18
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +169 -2
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +26 -4
- package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +84 -49
- package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +37 -32
- package/dist/bundling-sources/shared_libs/plays/launch/input-contract.ts +13 -1
- package/dist/bundling-sources/shared_libs/plays/local-file-discovery.ts +68 -1
- package/dist/bundling-sources/shared_libs/product-notifications/configuration-draft.ts +57 -1
- package/dist/bundling-sources/shared_libs/product-notifications/configuration.ts +22 -9
- package/dist/cli/auth-6XQKFOLG.js +43 -0
- package/dist/cli/{auth-ZCTMB5RA.mjs → auth-KCTCUO7P.mjs} +7 -7
- package/dist/cli/{billing-GVFKZQH3.js → billing-4VBGZ3CT.js} +273 -112
- package/dist/cli/{billing-OU2ZHL72.mjs → billing-OOJHKLNS.mjs} +185 -24
- package/dist/cli/{chunk-FGN75ZN6.js → chunk-2B4IOGFD.js} +390 -382
- package/dist/cli/{chunk-KOZBZPRM.js → chunk-2FCSUOYN.js} +55 -55
- package/dist/cli/{chunk-T2N3B7IQ.js → chunk-2GJZLIKW.js} +8 -8
- package/dist/cli/{chunk-AUEUAPVS.mjs → chunk-2YWJS76L.mjs} +1 -1
- package/dist/cli/{chunk-W5YJYU4G.mjs → chunk-3PCYV6ZJ.mjs} +2 -2
- package/dist/cli/{chunk-UUQ2OXMH.js → chunk-4E5JXZ3W.js} +18 -20
- package/dist/cli/{chunk-R4RG4FV5.mjs → chunk-4KWD3MX2.mjs} +13 -10
- package/dist/cli/{chunk-XSOTEVOB.js → chunk-6BBGUQJJ.js} +50 -141
- package/dist/cli/{chunk-PHLNYBAA.js → chunk-6VUGBQZQ.js} +5 -5
- package/dist/cli/{chunk-G2DLG32W.mjs → chunk-AB2GBOD4.mjs} +40 -27
- package/dist/cli/{chunk-JWWYLGUT.mjs → chunk-ANUKBZ6W.mjs} +475 -11
- package/dist/cli/{chunk-FZKPPB5P.mjs → chunk-BASLYGXK.mjs} +85 -77
- package/dist/cli/{chunk-SQWET4SL.js → chunk-BBTKAASQ.js} +2 -1
- package/dist/cli/{chunk-NRO3NTVO.js → chunk-CBV7AKWM.js} +5 -5
- package/dist/cli/{chunk-PI5R65OQ.js → chunk-CIDN5K23.js} +1 -1
- package/dist/cli/{chunk-QNHHZ63P.mjs → chunk-CQBIO6HW.mjs} +1 -1
- package/dist/cli/{chunk-2KHUFWTK.js → chunk-CQDQNZGH.js} +42 -37
- package/dist/cli/{chunk-D4MHCCIR.js → chunk-CWSLUNA6.js} +33 -33
- package/dist/cli/{chunk-E3CLOVG5.mjs → chunk-CXTW7SRW.mjs} +50 -141
- package/dist/cli/{chunk-H6SWS5CG.mjs → chunk-DA2I2M7D.mjs} +2 -2
- package/dist/cli/{chunk-WAIBM6KX.mjs → chunk-DQHUJMCL.mjs} +5 -5
- package/dist/cli/{chunk-DWPY6ZID.mjs → chunk-DUYAMLOC.mjs} +1 -1
- package/dist/cli/{chunk-K53NKWZO.mjs → chunk-E24UGPGG.mjs} +13 -15
- package/dist/cli/{chunk-STR5LXK4.mjs → chunk-FSIVF2SI.mjs} +1 -1
- package/dist/cli/{chunk-7R5DAANG.mjs → chunk-GF32SBST.mjs} +1 -1
- package/dist/cli/{chunk-7CWSAEYS.mjs → chunk-GHLDCLSC.mjs} +1 -1
- package/dist/cli/{chunk-ZUVE63Y7.js → chunk-GTVZKY3F.js} +2 -2
- package/dist/cli/{chunk-J75DANZY.mjs → chunk-HAJQGP5V.mjs} +2 -2
- package/dist/cli/{chunk-RFQWSH6I.js → chunk-HWDKRN7L.js} +3 -3
- package/dist/cli/{chunk-5YAJGRWB.js → chunk-IPVRMYWT.js} +7 -7
- package/dist/cli/{chunk-ZPGGW27Q.mjs → chunk-JL2OTMSG.mjs} +1 -0
- package/dist/cli/{chunk-K76AEBFY.mjs → chunk-JUHDJNSI.mjs} +4 -4
- package/dist/cli/{chunk-R2KKEHJN.mjs → chunk-KPQHUVYW.mjs} +5 -5
- package/dist/cli/{chunk-6LHX33VN.js → chunk-KWYGWO4Y.js} +9 -6
- package/dist/cli/{chunk-7PXP2FQK.js → chunk-LDGZFDUB.js} +2 -2
- package/dist/cli/{chunk-KWGXHPHL.js → chunk-LN6RXDTB.js} +523 -59
- package/dist/cli/{chunk-TCVCFZP6.mjs → chunk-LZXZQPA2.mjs} +4 -1
- package/dist/cli/{chunk-2D6SWQTK.js → chunk-MSP4DTSD.js} +13 -13
- package/dist/cli/{chunk-BNH4Y35W.mjs → chunk-OLH2PHMC.mjs} +2 -2
- package/dist/cli/{chunk-QYBAHYP4.mjs → chunk-OUDTOMZC.mjs} +7 -9
- package/dist/cli/{chunk-GESIFFQX.mjs → chunk-OVX3Q5Q3.mjs} +1 -1
- package/dist/cli/{chunk-6TYRRNXY.mjs → chunk-PNY3BWHP.mjs} +2 -2
- package/dist/cli/{chunk-DYIWDUY4.js → chunk-Q4MNUOS4.js} +316 -303
- package/dist/cli/{chunk-5EKNDNFQ.js → chunk-Q5CXV3E3.js} +2 -2
- package/dist/cli/{chunk-W6T23EUC.mjs → chunk-RVSSQPQO.mjs} +1 -1
- package/dist/cli/{chunk-WNNA4L6Z.js → chunk-SLPJ3LXI.js} +22 -22
- package/dist/cli/{chunk-K3IPGMGP.js → chunk-TX5TUHJN.js} +17 -19
- package/dist/cli/{chunk-IF75RD6U.js → chunk-U2LVWCTD.js} +18 -6
- package/dist/cli/{chunk-ZS2WHWWL.js → chunk-UNDLNT3V.js} +1 -1
- package/dist/cli/{chunk-4NLRWKZB.js → chunk-VBDZIMWD.js} +26 -26
- package/dist/cli/{chunk-DAPKLYST.js → chunk-W7AEIGZR.js} +41 -41
- package/dist/cli/{chunk-LVISZFYO.mjs → chunk-WC5M3JXE.mjs} +2 -2
- package/dist/cli/{chunk-C374C22Y.js → chunk-WOQO3GV4.js} +14 -11
- package/dist/cli/{chunk-243O3FH5.js → chunk-XBAH3TKU.js} +5 -5
- package/dist/cli/{chunk-DFJODFMC.mjs → chunk-XJD2GYUP.mjs} +5 -5
- package/dist/cli/{chunk-BF65LB7X.mjs → chunk-XVZRJJDS.mjs} +4 -4
- package/dist/cli/{chunk-OM732MGV.js → chunk-Y2NTPYGS.js} +17 -17
- package/dist/cli/{chunk-YFZLZNTH.mjs → chunk-YBMHOH6H.mjs} +4 -4
- package/dist/cli/{chunk-RKY4LBX3.mjs → chunk-YRLAUGQY.mjs} +3 -3
- package/dist/cli/{chunk-FKD3KL5Q.mjs → chunk-Z2XA6YU4.mjs} +10 -5
- package/dist/cli/{chunk-JQQG4QL4.mjs → chunk-Z7UIOGW4.mjs} +3 -3
- package/dist/cli/{chunk-HYBZWSSH.js → chunk-ZEV2Y56V.js} +44 -44
- package/dist/cli/{chunk-MI6ZP7XI.mjs → chunk-ZG7BOECV.mjs} +18 -6
- package/dist/cli/{chunk-HWPOXCCK.js → chunk-ZILSRDIN.js} +8 -8
- package/dist/cli/{chunk-CIDATNTY.js → chunk-ZISEH7OL.js} +16 -16
- package/dist/cli/{chunk-KA6ZERJL.js → chunk-ZZ4MF2GI.js} +6 -6
- package/dist/cli/command-docs.js +2 -2
- package/dist/cli/command-docs.mjs +1 -1
- package/dist/cli/{csv-CD55KEIO.js → csv-2V2DIFNG.js} +15 -15
- package/dist/cli/{csv-CLPVMIRF.mjs → csv-P3HLK4GO.mjs} +6 -6
- package/dist/cli/{db-MQKLDAEO.js → db-MREAQVW6.js} +36 -36
- package/dist/cli/{db-AU4SMWUN.mjs → db-ZYOY3QRQ.mjs} +9 -9
- package/dist/cli/describe-IKZFOADR.mjs +49 -0
- package/dist/cli/describe-WW3OQRLP.js +49 -0
- package/dist/cli/describe-core.d.mts +3 -3
- package/dist/cli/describe-core.d.ts +3 -3
- package/dist/cli/describe-core.js +5 -5
- package/dist/cli/describe-core.mjs +4 -4
- package/dist/cli/{executions-77GOLWRM.js → executions-H5IJ7QSQ.js} +11 -11
- package/dist/cli/{executions-TFIJPUX7.mjs → executions-KTSY5M34.mjs} +9 -9
- package/dist/cli/{feedback-OV5YAL3A.js → feedback-724QK3Z5.js} +16 -16
- package/dist/cli/{feedback-2WRSZ5WL.mjs → feedback-WWJRIXEU.mjs} +8 -8
- package/dist/cli/git-PHYRD56H.js +25 -0
- package/dist/cli/{git-VNS4ATLZ.mjs → git-R5VRG7X6.mjs} +7 -7
- package/dist/cli/index.js +151 -157
- package/dist/cli/index.mjs +51 -57
- package/dist/cli/{legacy-noops-HDOB5C6F.js → legacy-noops-C6GDEGPU.js} +11 -11
- package/dist/cli/{legacy-noops-C732QDCY.mjs → legacy-noops-PWZ5XLAO.mjs} +8 -8
- package/dist/cli/{monitors-5IUMHH3E.js → monitors-VAVQ4WCE.js} +125 -122
- package/dist/cli/{monitors-2LYEFXOU.mjs → monitors-WQSKMHAP.mjs} +19 -16
- package/dist/cli/{org-ADW2EVAC.js → org-CWWRWXZQ.js} +89 -89
- package/dist/cli/{org-G4YGZPHS.mjs → org-MAL4QPVF.mjs} +9 -9
- package/dist/cli/{play-7GQ56C2D.mjs → play-ILW6MSNG.mjs} +123 -76
- package/dist/cli/{play-EHSOSSHT.js → play-WJOWK5PQ.js} +641 -594
- package/dist/cli/{providers-WL3YTCSV.mjs → providers-4V2NMLZZ.mjs} +9 -9
- package/dist/cli/{providers-PWCF6OOO.js → providers-W662ANCH.js} +12 -12
- package/dist/cli/{quickstart-ZKI5MURA.js → quickstart-BW6EBUYX.js} +8 -8
- package/dist/cli/{quickstart-323XOPGI.mjs → quickstart-C22BR743.mjs} +6 -6
- package/dist/cli/{run-XZPWA6JS.js → run-KW7KW4FX.js} +50 -53
- package/dist/cli/{run-ZCNZU3K2.mjs → run-SPAU5IMW.mjs} +31 -34
- package/dist/cli/search-HLE54W5G.js +32 -0
- package/dist/cli/{search-CVLVSFMJ.mjs → search-XPC75HLM.mjs} +10 -11
- package/dist/cli/{search-output-6PY6RN2R.mjs → search-output-JKYJSEPM.mjs} +6 -6
- package/dist/cli/{search-output-7HRSSRBS.js → search-output-VJYE7USJ.js} +8 -8
- package/dist/cli/{secrets-6S2ZWDIM.mjs → secrets-OJG73GXQ.mjs} +9 -9
- package/dist/cli/{secrets-IYD5VKY4.js → secrets-YB57KGSB.js} +18 -18
- package/dist/cli/{sessions-GVEX5TUJ.mjs → sessions-7ZL37BW4.mjs} +8 -8
- package/dist/cli/sessions-VEBYZIEU.js +22 -0
- package/dist/cli/{settings-CANK4HJQ.js → settings-A7DD2ZYE.js} +88 -89
- package/dist/cli/{settings-BN5MJZ3C.mjs → settings-RKSQB7FA.mjs} +15 -16
- package/dist/cli/{setup-JNMSCCU4.mjs → setup-NXDUTITY.mjs} +11 -12
- package/dist/cli/{setup-YSGKGLSJ.js → setup-S3K5YU62.js} +51 -52
- package/dist/cli/skills-NVQ744CN.js +36 -0
- package/dist/cli/{skills-QCQN2UM2.mjs → skills-VMFAIDO6.mjs} +9 -10
- package/dist/cli/{tools-CDPOID7V.mjs → tools-52NTHBSJ.mjs} +20 -21
- package/dist/cli/tools-SBDUL3WB.js +56 -0
- package/dist/cli/update-HHVFZPCV.js +34 -0
- package/dist/cli/{update-D3ZERUQ3.mjs → update-SAKBEKMV.mjs} +11 -12
- package/dist/cli/{views-RDZRWQBQ.mjs → views-ACRV7MD6.mjs} +54 -10
- package/dist/cli/{views-4NV2KQKA.js → views-C3GJOBDG.js} +66 -22
- package/dist/cli/{workflow-2CG3TVCG.mjs → workflow-CS22E7TC.mjs} +10 -10
- package/dist/cli/{workflow-RABJCAZC.js → workflow-ZNWCZEGN.js} +20 -20
- package/dist/{client-DhSvMO3A.d.mts → client-BlLYQDNo.d.mts} +1 -1
- package/dist/{client-oGNJMQFd.d.ts → client-DSQlkIDO.d.ts} +1 -1
- package/dist/{client-core-CdWH6Sii.d.ts → client-core-CDwapXy5.d.ts} +159 -108
- package/dist/{client-core-CVG1Et-4.d.mts → client-core-rX7n2H8U.d.mts} +159 -108
- package/dist/{compiler-manifest-D2ZlBGxj.d.ts → compiler-manifest-BHNC4RL-.d.mts} +15 -22
- package/dist/{compiler-manifest-D2ZlBGxj.d.mts → compiler-manifest-BHNC4RL-.d.ts} +15 -22
- package/dist/{errors-B-gOQdj-.d.mts → errors-D7sPXrvB.d.mts} +1 -1
- package/dist/{errors-CB0KAmmV.d.ts → errors-lhtIWG5Z.d.ts} +1 -1
- package/dist/{index-c3nvUGCS.d.ts → index-CQTBHXHr.d.ts} +1 -1
- package/dist/{index-BbJADro4.d.mts → index-NaDZq2xf.d.mts} +1 -1
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +15 -15
- package/dist/index.mjs +11 -11
- package/dist/install-integrity.json +129 -132
- package/dist/monitor-fleet-contract.d.mts +17 -11
- package/dist/monitor-fleet-contract.d.ts +17 -11
- package/dist/monitor-fleet-contract.js +3 -3
- package/dist/monitor-fleet-contract.mjs +2 -2
- package/dist/monitor-input-contract.js +2 -2
- package/dist/monitor-input-contract.mjs +1 -1
- package/dist/plays/bundle-play-file.d.mts +3 -3
- package/dist/plays/bundle-play-file.d.ts +3 -3
- package/dist/plays/bundle-play-file.mjs +17 -5
- package/dist/plays/csv-data-input.js +3 -3
- package/dist/plays/csv-data-input.mjs +2 -2
- package/dist/plays/play-description.d.mts +2 -2
- package/dist/plays/play-description.d.ts +2 -2
- package/dist/plays/run-request.d.mts +2 -2
- package/dist/plays/run-request.d.ts +2 -2
- package/dist/plays/run-request.js +3 -3
- package/dist/plays/run-request.mjs +2 -2
- package/dist/release.d.mts +1 -1
- package/dist/release.d.ts +1 -1
- package/dist/release.js +2 -2
- package/dist/release.mjs +1 -1
- package/dist/server.d.mts +4 -4
- package/dist/server.d.ts +4 -4
- package/dist/server.js +12 -12
- package/dist/server.mjs +6 -6
- package/package.json +1 -1
- package/dist/cli/auth-VDCU3T6A.js +0 -43
- package/dist/cli/chunk-4QELPWUW.mjs +0 -405
- package/dist/cli/chunk-T7RBM2WX.js +0 -405
- package/dist/cli/describe-5BFNHT5V.js +0 -50
- package/dist/cli/describe-AWJUXE2U.mjs +0 -50
- package/dist/cli/git-HGMX52XU.js +0 -25
- package/dist/cli/pages-KXKWSCEV.mjs +0 -266
- package/dist/cli/pages-VTJGAI2D.js +0 -266
- package/dist/cli/search-J6EY7DQN.js +0 -33
- package/dist/cli/sessions-7HPIVSQ4.js +0 -22
- package/dist/cli/skills-WDGSSKJZ.js +0 -37
- package/dist/cli/tools-URNVXSTZ.js +0 -57
- package/dist/cli/update-Q6JW32IA.js +0 -35
package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts
CHANGED
|
@@ -73,12 +73,35 @@ const FAIR_SHARE_SLOT_WAIT_MS = 100;
|
|
|
73
73
|
const FAIR_SHARE_REQUESTER_IDLE_WINDOWS = 2;
|
|
74
74
|
/** Opportunistically reclaim idle requester rows without a whole-table lock. */
|
|
75
75
|
const FAIR_SHARE_REQUESTER_CLEANUP_BATCH_SIZE = 64;
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
// A declared concurrency rule opens at its declared limit; Gradient2 only
|
|
77
|
+
// lowers it from there on 429s or rising latency.
|
|
78
78
|
// Rate spacing cannot bound requests delayed between admission and the
|
|
79
79
|
// physical provider. Unknown scopes discover with at most two shared leases
|
|
80
80
|
// until a productive rate epoch establishes that the provider can sustain more.
|
|
81
81
|
const UNKNOWN_PROVIDER_CONCURRENCY_DISCOVERY_LIMIT = 2;
|
|
82
|
+
// Leaving discovery opens the lane one doubling above the discovery width at
|
|
83
|
+
// most. Gradient2 then grows it only after calls run near each new limit.
|
|
84
|
+
const UNKNOWN_PROVIDER_POST_DISCOVERY_LIMIT =
|
|
85
|
+
2 * UNKNOWN_PROVIDER_CONCURRENCY_DISCOVERY_LIMIT;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* SET clauses for a bucket UPDATE aliased `b`. When `endsDiscovery` holds,
|
|
89
|
+
* cap the learned limit at the first post-discovery width. A limit learned
|
|
90
|
+
* while the lane was held at the discovery width was never exercised there,
|
|
91
|
+
* so it must not take effect all at once when the gate opens.
|
|
92
|
+
*/
|
|
93
|
+
function capLearnedLimitAtDiscoveryExitSql(endsDiscovery: string): string {
|
|
94
|
+
const capped = `(${endsDiscovery})
|
|
95
|
+
AND b.learned_concurrency_limit > ${UNKNOWN_PROVIDER_POST_DISCOVERY_LIMIT}`;
|
|
96
|
+
return `learned_concurrency_limit = CASE WHEN ${capped}
|
|
97
|
+
THEN ${UNKNOWN_PROVIDER_POST_DISCOVERY_LIMIT}
|
|
98
|
+
ELSE b.learned_concurrency_limit END,
|
|
99
|
+
concurrency_window_limit = CASE WHEN ${capped}
|
|
100
|
+
THEN ${UNKNOWN_PROVIDER_POST_DISCOVERY_LIMIT}
|
|
101
|
+
ELSE b.concurrency_window_limit END,
|
|
102
|
+
concurrency_successful_samples = CASE WHEN ${capped}
|
|
103
|
+
THEN 0 ELSE b.concurrency_successful_samples END`;
|
|
104
|
+
}
|
|
82
105
|
/** A transport batch must stay bounded even when a runner completes huge maps. */
|
|
83
106
|
const MAX_CONCURRENCY_OBSERVATIONS_PER_ACQUIRE = 4_096;
|
|
84
107
|
/** Keep retry identities long enough for failed runtime work to recover. */
|
|
@@ -634,9 +657,10 @@ export async function ensurePostgresRateStateSchema(
|
|
|
634
657
|
ALTER TABLE ${bucketTableName(options)}
|
|
635
658
|
ADD COLUMN IF NOT EXISTS adaptive_max_configured boolean NOT NULL DEFAULT false
|
|
636
659
|
`);
|
|
637
|
-
// v37: durable Gradient2 checkpoint. Null limit marks a pre-v37
|
|
638
|
-
//
|
|
639
|
-
// width
|
|
660
|
+
// v37: durable Gradient2 checkpoint. Null limit marks a pre-v37 or new
|
|
661
|
+
// bucket: its next concurrency-bearing acquire starts an undeclared scope at
|
|
662
|
+
// the discovery width and a declared rule at its declared limit; rate-only
|
|
663
|
+
// rules leave these fields unused.
|
|
640
664
|
await client.query(`
|
|
641
665
|
ALTER TABLE ${bucketTableName(options)}
|
|
642
666
|
ADD COLUMN IF NOT EXISTS learned_concurrency_limit float8
|
|
@@ -2180,12 +2204,14 @@ async function grantWithConcurrency(
|
|
|
2180
2204
|
AND bucket.last_ramp_at_ms = 0
|
|
2181
2205
|
THEN ${UNKNOWN_PROVIDER_CONCURRENCY_DISCOVERY_LIMIT}
|
|
2182
2206
|
ELSE lim.max_concurrency END,
|
|
2207
|
+
-- A declared lane opens at its declared limit: the provider
|
|
2208
|
+
-- publishes it, so there is nothing to discover below it.
|
|
2183
2209
|
CEIL(
|
|
2184
2210
|
COALESCE(
|
|
2185
2211
|
bucket.learned_concurrency_limit,
|
|
2186
|
-
|
|
2212
|
+
CASE WHEN bucket.rule_id = 'default:provider-scope'
|
|
2187
2213
|
THEN ${UNKNOWN_PROVIDER_CONCURRENCY_DISCOVERY_LIMIT}
|
|
2188
|
-
ELSE
|
|
2214
|
+
ELSE lim.max_concurrency END
|
|
2189
2215
|
)
|
|
2190
2216
|
)
|
|
2191
2217
|
)::int AS max_concurrency
|
|
@@ -2320,7 +2346,12 @@ async function grantWithConcurrency(
|
|
|
2320
2346
|
-- confirmed success is sufficient demand; concurrency leases change
|
|
2321
2347
|
-- admission accounting, not the AIMD learning contract.
|
|
2322
2348
|
refill_per_sec = LEAST(r.max_rps, (SELECT next_refill_per_sec FROM provider_hold)),
|
|
2323
|
-
last_ramp_at_ms = (SELECT next_ramp_at_ms FROM provider_hold)
|
|
2349
|
+
last_ramp_at_ms = (SELECT next_ramp_at_ms FROM provider_hold),
|
|
2350
|
+
-- This statement's first ramp ends cold discovery for the next grant.
|
|
2351
|
+
${capLearnedLimitAtDiscoveryExitSql(`r.rule_id = 'default:provider-scope'
|
|
2352
|
+
AND NOT r.seen_backpressure
|
|
2353
|
+
AND r.last_ramp_at_ms = 0
|
|
2354
|
+
AND (SELECT next_ramp_at_ms FROM provider_hold) > 0`)}
|
|
2324
2355
|
FROM refreshed r
|
|
2325
2356
|
WHERE b.bucket_id = $1
|
|
2326
2357
|
AND b.rule_id = r.rule_id
|
|
@@ -2918,13 +2949,30 @@ function concurrencyObservationsFrom(
|
|
|
2918
2949
|
if (!Array.isArray(observations)) return [];
|
|
2919
2950
|
return observations
|
|
2920
2951
|
.slice(0, MAX_CONCURRENCY_OBSERVATIONS_PER_ACQUIRE)
|
|
2921
|
-
.flatMap((observation) =>
|
|
2922
|
-
(
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2952
|
+
.flatMap((observation) => {
|
|
2953
|
+
if (
|
|
2954
|
+
(observation.kind !== 'success' && observation.kind !== 'throttled') ||
|
|
2955
|
+
!Number.isFinite(observation.latencyMs) ||
|
|
2956
|
+
observation.latencyMs <= 0
|
|
2957
|
+
) {
|
|
2958
|
+
return [];
|
|
2959
|
+
}
|
|
2960
|
+
// Optional success occupancy from newer runners. Anything malformed is
|
|
2961
|
+
// treated as absent, which keeps the older counting rule for that
|
|
2962
|
+
// sample. Throttle attribution stays with the penalty's lease lookup.
|
|
2963
|
+
const inFlightAtStart = observation.inFlightAtStart;
|
|
2964
|
+
return [
|
|
2965
|
+
{
|
|
2966
|
+
kind: observation.kind,
|
|
2967
|
+
latencyMs: observation.latencyMs,
|
|
2968
|
+
...(observation.kind === 'success' &&
|
|
2969
|
+
Number.isSafeInteger(inFlightAtStart) &&
|
|
2970
|
+
(inFlightAtStart as number) >= 1
|
|
2971
|
+
? { inFlightAtStart: inFlightAtStart as number }
|
|
2972
|
+
: {}),
|
|
2973
|
+
},
|
|
2974
|
+
];
|
|
2975
|
+
});
|
|
2928
2976
|
}
|
|
2929
2977
|
|
|
2930
2978
|
async function concurrencyThrottleFrom(
|
|
@@ -3232,7 +3280,7 @@ async function applyConcurrencyObservations(
|
|
|
3232
3280
|
row.learned_concurrency_limit ??
|
|
3233
3281
|
(rule.ruleId === 'default:provider-scope'
|
|
3234
3282
|
? UNKNOWN_PROVIDER_CONCURRENCY_DISCOVERY_LIMIT
|
|
3235
|
-
:
|
|
3283
|
+
: maximumLimit),
|
|
3236
3284
|
),
|
|
3237
3285
|
);
|
|
3238
3286
|
limitsBefore.push(initialLimit);
|
|
@@ -3792,7 +3840,9 @@ async function penalizeRateStateStatements(
|
|
|
3792
3840
|
next_dispatch_at_ms = CASE WHEN e.new_episode
|
|
3793
3841
|
THEN e.deadline ELSE GREATEST(e.next_dispatch_at_ms, e.deadline) END
|
|
3794
3842
|
FROM learned e WHERE h.bucket_id = e.bucket_id
|
|
3795
|
-
RETURNING h.*, e.new_episode, e.cycle_ms, e.rate_successes AS successes_before
|
|
3843
|
+
RETURNING h.*, e.new_episode, e.cycle_ms, e.rate_successes AS successes_before,
|
|
3844
|
+
e.seen_backpressure AS seen_backpressure_before,
|
|
3845
|
+
e.last_ramp_at_ms AS last_ramp_at_ms_before
|
|
3796
3846
|
), locked_bucket_rows AS (
|
|
3797
3847
|
SELECT b.bucket_id, b.rule_id, b.refill_per_sec AS refill_before
|
|
3798
3848
|
FROM ${bucketTableName(input)} b
|
|
@@ -3814,7 +3864,12 @@ async function penalizeRateStateStatements(
|
|
|
3814
3864
|
tokens = CASE WHEN h.new_episode THEN 0 ELSE b.tokens END,
|
|
3815
3865
|
next_dispatch_at_ms = CASE WHEN h.new_episode
|
|
3816
3866
|
THEN h.next_dispatch_at_ms
|
|
3817
|
-
ELSE GREATEST(b.next_dispatch_at_ms, h.next_dispatch_at_ms) END
|
|
3867
|
+
ELSE GREATEST(b.next_dispatch_at_ms, h.next_dispatch_at_ms) END,
|
|
3868
|
+
-- The first backpressure also ends cold discovery.
|
|
3869
|
+
${capLearnedLimitAtDiscoveryExitSql(`b.rule_id = 'default:provider-scope'
|
|
3870
|
+
AND h.new_episode
|
|
3871
|
+
AND NOT h.seen_backpressure_before
|
|
3872
|
+
AND h.last_ramp_at_ms_before = 0`)}
|
|
3818
3873
|
FROM locked_bucket_rows locked CROSS JOIN provider_hold h
|
|
3819
3874
|
WHERE b.bucket_id = locked.bucket_id AND b.rule_id = locked.rule_id
|
|
3820
3875
|
RETURNING locked.refill_before, h.cycle_ms, h.successes_before,
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
PLATFORM_RECOVERY_ACTIVITY_ID,
|
|
3
|
+
SANDBOX_CAPACITY_ACTIVITY_ID,
|
|
4
|
+
} from '../activity-observation';
|
|
2
5
|
import { readPrebuiltResultQuality } from '../prebuilt-result-quality';
|
|
3
6
|
import {
|
|
4
7
|
terminalRuntimePerformanceFromStats,
|
|
@@ -221,6 +224,7 @@ import {
|
|
|
221
224
|
type WorkerRuntimeApiContext,
|
|
222
225
|
} from '../app-runtime-api';
|
|
223
226
|
import {
|
|
227
|
+
resolveAbsorbedLateRuntimeSandboxComputeItems,
|
|
224
228
|
resolveLateRuntimeSandboxComputeItems,
|
|
225
229
|
resolveRuntimeSandboxComputeItems,
|
|
226
230
|
} from '../sandbox-compute-usage';
|
|
@@ -9081,9 +9085,18 @@ export async function deferPostgresSchedulerAttemptForCapacity(
|
|
|
9081
9085
|
attempt: number;
|
|
9082
9086
|
leaseToken: string;
|
|
9083
9087
|
reason: string;
|
|
9088
|
+
/**
|
|
9089
|
+
* Set only when the workspace's live-sandbox cap is full. The first
|
|
9090
|
+
* deferral of an unbroken streak publishes a queued activity carrying the
|
|
9091
|
+
* limit, atomically with the requeue; later deferrals publish nothing
|
|
9092
|
+
* until an attempt records a sandbox, so a long wait does not rewrite the
|
|
9093
|
+
* projection every retry.
|
|
9094
|
+
*/
|
|
9095
|
+
sandboxCapacity?: { limit: number; nowMs: number };
|
|
9084
9096
|
},
|
|
9085
9097
|
options?: Pick<PostgresSchedulerOptions, 'schema'>,
|
|
9086
9098
|
): Promise<boolean> {
|
|
9099
|
+
const sandboxCapacity = input.sandboxCapacity ?? null;
|
|
9087
9100
|
const deferred = await client.query<{ run_id: string }>(
|
|
9088
9101
|
`
|
|
9089
9102
|
WITH ${runtimeSandboxCustodyLocksSql('run.run_id = $1', options)}, deferred_attempt AS (
|
|
@@ -9108,7 +9121,24 @@ export async function deferPostgresSchedulerAttemptForCapacity(
|
|
|
9108
9121
|
updated_at = now()
|
|
9109
9122
|
WHERE run_id IN (SELECT run_id FROM deferred_attempt)
|
|
9110
9123
|
AND status IN ('queued', 'running', 'waiting')
|
|
9111
|
-
RETURNING run_id
|
|
9124
|
+
RETURNING run_id, launch_json
|
|
9125
|
+
),
|
|
9126
|
+
sandbox_capacity_activity AS (
|
|
9127
|
+
INSERT INTO ${tableName('outbox', options)} (
|
|
9128
|
+
event_id, run_id, event_type, payload_json, created_at
|
|
9129
|
+
)
|
|
9130
|
+
SELECT 'run-sandbox-capacity:' || requeued_run.run_id || ':' || $2::text,
|
|
9131
|
+
requeued_run.run_id,
|
|
9132
|
+
${RUN_SCHEDULER_OUTBOX_EVENT_TYPE_SQL_LITERAL.runEvents},
|
|
9133
|
+
jsonb_build_object('events', jsonb_build_array(
|
|
9134
|
+
${sandboxCapacityActivityEventSql("jsonb_build_object('kind', 'queued', 'reason', 'capacity')", '$5::integer', '$6::bigint')}
|
|
9135
|
+
)),
|
|
9136
|
+
${causalOutboxCreatedAt('requeued_run.run_id', options)}
|
|
9137
|
+
FROM requeued_run
|
|
9138
|
+
WHERE $5::integer IS NOT NULL
|
|
9139
|
+
AND NOT ${outstandingSandboxCapacityWaitSql('requeued_run.run_id', '$2::integer', options)}
|
|
9140
|
+
ON CONFLICT (event_id) DO NOTHING
|
|
9141
|
+
RETURNING event_id
|
|
9112
9142
|
)
|
|
9113
9143
|
SELECT run_id FROM requeued_run
|
|
9114
9144
|
`,
|
|
@@ -9119,12 +9149,106 @@ export async function deferPostgresSchedulerAttemptForCapacity(
|
|
|
9119
9149
|
stringifyPostgresJson({
|
|
9120
9150
|
kind: 'scheduler_capacity',
|
|
9121
9151
|
message: input.reason,
|
|
9152
|
+
...(sandboxCapacity ? { sandboxCapacity: true } : {}),
|
|
9122
9153
|
}),
|
|
9154
|
+
sandboxCapacity?.limit ?? null,
|
|
9155
|
+
sandboxCapacity?.nowMs ?? null,
|
|
9123
9156
|
],
|
|
9124
9157
|
);
|
|
9125
9158
|
return deferred.rows.length > 0;
|
|
9126
9159
|
}
|
|
9127
9160
|
|
|
9161
|
+
/**
|
|
9162
|
+
* True while an earlier attempt's sandbox-capacity wait is still published:
|
|
9163
|
+
* some attempt before `attemptSql` deferred for sandbox capacity and no attempt
|
|
9164
|
+
* after it (and before `attemptSql`) recorded a sandbox, which would have
|
|
9165
|
+
* cleared it. Other deferrals in between (an executor-token outage, say) do
|
|
9166
|
+
* not end the wait.
|
|
9167
|
+
*/
|
|
9168
|
+
function outstandingSandboxCapacityWaitSql(
|
|
9169
|
+
runIdSql: string,
|
|
9170
|
+
attemptSql: string,
|
|
9171
|
+
options?: Pick<PostgresSchedulerOptions, 'schema'>,
|
|
9172
|
+
): string {
|
|
9173
|
+
return `EXISTS (
|
|
9174
|
+
SELECT 1 FROM ${tableName('attempts', options)} AS waited
|
|
9175
|
+
WHERE waited.run_id = ${runIdSql}
|
|
9176
|
+
AND waited.attempt < ${attemptSql}
|
|
9177
|
+
AND waited.error_json->>'sandboxCapacity' = 'true'
|
|
9178
|
+
AND NOT EXISTS (
|
|
9179
|
+
SELECT 1 FROM ${tableName('attempts', options)} AS started
|
|
9180
|
+
WHERE started.run_id = waited.run_id
|
|
9181
|
+
AND started.attempt > waited.attempt
|
|
9182
|
+
AND started.attempt < ${attemptSql}
|
|
9183
|
+
AND jsonb_path_exists(started.resource_json, '$[*].sandboxId')
|
|
9184
|
+
)
|
|
9185
|
+
)`;
|
|
9186
|
+
}
|
|
9187
|
+
|
|
9188
|
+
/**
|
|
9189
|
+
* The queued (or cleared) sandbox-capacity activity. The target carries the
|
|
9190
|
+
* optional `limit` so readers can name the plan limit without another read.
|
|
9191
|
+
*/
|
|
9192
|
+
function sandboxCapacityActivityEventSql(
|
|
9193
|
+
stateSql: string,
|
|
9194
|
+
limitSql: string,
|
|
9195
|
+
nowSql: string,
|
|
9196
|
+
): string {
|
|
9197
|
+
return `jsonb_build_object(
|
|
9198
|
+
'type', ${RUN_EVENT_KIND_SQL_LITERAL.activityObserved},
|
|
9199
|
+
'runId', requeued_run.run_id,
|
|
9200
|
+
'source', 'worker',
|
|
9201
|
+
'occurredAt', ${nowSql},
|
|
9202
|
+
'resumeEpoch', coalesce(requeued_run.launch_json->'resumeEpoch', '0'::jsonb),
|
|
9203
|
+
'observation', jsonb_build_object(
|
|
9204
|
+
'activityId', ${escapeLiteral(SANDBOX_CAPACITY_ACTIVITY_ID)},
|
|
9205
|
+
'target', jsonb_strip_nulls(jsonb_build_object(
|
|
9206
|
+
'kind', 'capacity', 'pool', 'runner',
|
|
9207
|
+
'label', 'a concurrency slot', 'limit', ${limitSql}
|
|
9208
|
+
)),
|
|
9209
|
+
'state', ${stateSql},
|
|
9210
|
+
'observedAt', ${nowSql}
|
|
9211
|
+
)
|
|
9212
|
+
)`;
|
|
9213
|
+
}
|
|
9214
|
+
|
|
9215
|
+
/**
|
|
9216
|
+
* Clear the sandbox-capacity activity once a run that waited for a slot has
|
|
9217
|
+
* its sandbox. Publishes only while a sandbox-capacity wait is outstanding, so
|
|
9218
|
+
* ordinary starts write nothing. Idempotent per attempt.
|
|
9219
|
+
*/
|
|
9220
|
+
export async function clearPostgresSandboxCapacityActivity(
|
|
9221
|
+
client: PostgresSchedulerQueryClient,
|
|
9222
|
+
input: { runId: string; attempt: number; nowMs: number },
|
|
9223
|
+
options?: Pick<PostgresSchedulerOptions, 'schema'>,
|
|
9224
|
+
): Promise<boolean> {
|
|
9225
|
+
const cleared = await client.query<{ event_id: string }>(
|
|
9226
|
+
`
|
|
9227
|
+
WITH requeued_run AS (
|
|
9228
|
+
SELECT run.run_id, run.launch_json
|
|
9229
|
+
FROM ${tableName('runs', options)} AS run
|
|
9230
|
+
WHERE run.run_id = $1
|
|
9231
|
+
AND ${outstandingSandboxCapacityWaitSql('run.run_id', '$2::integer', options)}
|
|
9232
|
+
)
|
|
9233
|
+
INSERT INTO ${tableName('outbox', options)} (
|
|
9234
|
+
event_id, run_id, event_type, payload_json, created_at
|
|
9235
|
+
)
|
|
9236
|
+
SELECT 'run-sandbox-capacity-cleared:' || requeued_run.run_id || ':' || $2::text,
|
|
9237
|
+
requeued_run.run_id,
|
|
9238
|
+
${RUN_SCHEDULER_OUTBOX_EVENT_TYPE_SQL_LITERAL.runEvents},
|
|
9239
|
+
jsonb_build_object('events', jsonb_build_array(
|
|
9240
|
+
${sandboxCapacityActivityEventSql("jsonb_build_object('kind', 'completed')", 'NULL::integer', '$3::bigint')}
|
|
9241
|
+
)),
|
|
9242
|
+
${causalOutboxCreatedAt('requeued_run.run_id', options)}
|
|
9243
|
+
FROM requeued_run
|
|
9244
|
+
ON CONFLICT (event_id) DO NOTHING
|
|
9245
|
+
RETURNING event_id
|
|
9246
|
+
`,
|
|
9247
|
+
[input.runId, input.attempt, input.nowMs],
|
|
9248
|
+
);
|
|
9249
|
+
return cleared.rows.length > 0;
|
|
9250
|
+
}
|
|
9251
|
+
|
|
9128
9252
|
/** `error_json.kind` stamped on an attempt retired by an executor-token
|
|
9129
9253
|
* outage. Consecutive attempts carrying it form one bounded outage. */
|
|
9130
9254
|
export const EXECUTOR_TOKEN_UNAVAILABLE_ATTEMPT_ERROR_KIND =
|
|
@@ -17901,6 +18025,49 @@ export async function finalizePostgresSchedulerComputeBilling(
|
|
|
17901
18025
|
workflowId: launch.runId,
|
|
17902
18026
|
runId: launch.runId,
|
|
17903
18027
|
});
|
|
18028
|
+
// Provider time the run did not plan for: a create that resolved after
|
|
18029
|
+
// its attempt ended, or one handed to cleanup. Logged once per settled
|
|
18030
|
+
// adjustment so that cost can be sized without reading billing rows.
|
|
18031
|
+
// Settlement is at-least-once; count distinct `sessionId`.
|
|
18032
|
+
console.info('[runtime.compute.late_resource_settled]', {
|
|
18033
|
+
event: 'runtime.compute.late_resource_settled',
|
|
18034
|
+
runId: launch.runId,
|
|
18035
|
+
orgId: launch.orgId,
|
|
18036
|
+
sessionId: adjustmentSessionId,
|
|
18037
|
+
itemId: item.itemId,
|
|
18038
|
+
source: item.source,
|
|
18039
|
+
billableSeconds: item.units,
|
|
18040
|
+
providerCostUsd: item.providerCostUsd,
|
|
18041
|
+
runSucceeded: success,
|
|
18042
|
+
customerBilled: true,
|
|
18043
|
+
});
|
|
18044
|
+
}
|
|
18045
|
+
// A sandbox handed to cleanup before it could run customer code is not
|
|
18046
|
+
// billed. Its provider time is Deepline's cost, so it is still logged, with
|
|
18047
|
+
// no billing session. Count distinct `runId` + `itemId`.
|
|
18048
|
+
const absorbedItems =
|
|
18049
|
+
lateResources.length === 0
|
|
18050
|
+
? []
|
|
18051
|
+
: resolveAbsorbedLateRuntimeSandboxComputeItems({
|
|
18052
|
+
resources: lateResources,
|
|
18053
|
+
endedAt: Date.now(),
|
|
18054
|
+
maxBillingDurationSeconds:
|
|
18055
|
+
sandboxRuntimeLimitsFromContractSnapshot(launch.contractSnapshot)
|
|
18056
|
+
.timeoutSeconds + PLAY_RUNNER_TERMINAL_GRACE_SECONDS,
|
|
18057
|
+
});
|
|
18058
|
+
for (const item of absorbedItems) {
|
|
18059
|
+
console.info('[runtime.compute.late_resource_settled]', {
|
|
18060
|
+
event: 'runtime.compute.late_resource_settled',
|
|
18061
|
+
runId: launch.runId,
|
|
18062
|
+
orgId: launch.orgId,
|
|
18063
|
+
sessionId: null,
|
|
18064
|
+
itemId: item.itemId,
|
|
18065
|
+
source: item.source,
|
|
18066
|
+
billableSeconds: item.units,
|
|
18067
|
+
providerCostUsd: item.providerCostUsd,
|
|
18068
|
+
runSucceeded: success,
|
|
18069
|
+
customerBilled: false,
|
|
18070
|
+
});
|
|
17904
18071
|
}
|
|
17905
18072
|
}
|
|
17906
18073
|
|
|
@@ -25,8 +25,8 @@ import { readComputeBillingJobStatus } from './compute-billing-job-state';
|
|
|
25
25
|
* every ordinary organization's observed peak (at most 46 live sandboxes in the
|
|
26
26
|
* week before 2026-10-29) and bounds a burst: on 2026-10-29 one organization
|
|
27
27
|
* held 2,838 live sandboxes polling the receipt gateway. Keep in sync with the
|
|
28
|
-
*
|
|
29
|
-
* packages/
|
|
28
|
+
* `play.concurrent_runs` default and maximum in
|
|
29
|
+
* packages/billing/org-limits/registry.ts (a Convex test asserts it).
|
|
30
30
|
*/
|
|
31
31
|
export const DEFAULT_PLAY_SANDBOX_CONCURRENCY = 50;
|
|
32
32
|
export const MAX_PLAY_SANDBOX_CONCURRENCY = 250;
|
|
@@ -285,6 +285,16 @@ type RuntimeSandboxReservationProof = {
|
|
|
285
285
|
sandbox_id: string | null;
|
|
286
286
|
};
|
|
287
287
|
|
|
288
|
+
/** A launch-carried limit inside the runtime's bounds, or null to ignore it. */
|
|
289
|
+
function entitlementLimit(value: number | null | undefined): number | null {
|
|
290
|
+
return typeof value === 'number' &&
|
|
291
|
+
Number.isSafeInteger(value) &&
|
|
292
|
+
value >= 1 &&
|
|
293
|
+
value <= MAX_PLAY_SANDBOX_CONCURRENCY
|
|
294
|
+
? value
|
|
295
|
+
: null;
|
|
296
|
+
}
|
|
297
|
+
|
|
288
298
|
export async function reserveRuntimeSandboxCapacityLease(
|
|
289
299
|
client: PostgresSchedulerQueryClient,
|
|
290
300
|
input: {
|
|
@@ -298,6 +308,11 @@ export async function reserveRuntimeSandboxCapacityLease(
|
|
|
298
308
|
mode?: RuntimeSandboxCapacityAdmissionMode;
|
|
299
309
|
/** Resume the one unresolved Daytona create for this run, if present. */
|
|
300
310
|
resumePendingDaytonaOperation?: boolean;
|
|
311
|
+
/**
|
|
312
|
+
* The `play.concurrent_runs` entitlement the launch carries. When set it
|
|
313
|
+
* is the limit; otherwise the mirrored cap, then the runtime default.
|
|
314
|
+
*/
|
|
315
|
+
entitlementLimit?: number | null;
|
|
301
316
|
},
|
|
302
317
|
options?: Pick<PostgresSchedulerOptions, 'schema'>,
|
|
303
318
|
): Promise<
|
|
@@ -376,7 +391,7 @@ export async function reserveRuntimeSandboxCapacityLease(
|
|
|
376
391
|
`
|
|
377
392
|
WITH observed AS MATERIALIZED (
|
|
378
393
|
SELECT
|
|
379
|
-
capacity.configured_limit AS "limit",
|
|
394
|
+
coalesce($14::integer, capacity.configured_limit) AS "limit",
|
|
380
395
|
capacity.active_leases,
|
|
381
396
|
coalesce((
|
|
382
397
|
SELECT jsonb_agg(pending)
|
|
@@ -517,6 +532,7 @@ export async function reserveRuntimeSandboxCapacityLease(
|
|
|
517
532
|
RUNTIME_SANDBOX_CAPACITY_LEASE_MS,
|
|
518
533
|
providerOperationToken,
|
|
519
534
|
runtimeSandboxOperationTargetState('reserve'),
|
|
535
|
+
entitlementLimit(input.entitlementLimit),
|
|
520
536
|
],
|
|
521
537
|
);
|
|
522
538
|
const limit = Number(
|
|
@@ -819,6 +835,7 @@ export async function reserveRuntimeSandboxOperation(
|
|
|
819
835
|
environment: 'preview' | 'production';
|
|
820
836
|
mode?: RuntimeSandboxCapacityAdmissionMode;
|
|
821
837
|
resumePendingDaytonaOperation?: boolean;
|
|
838
|
+
entitlementLimit?: number | null;
|
|
822
839
|
},
|
|
823
840
|
options?: Pick<PostgresSchedulerOptions, 'schema'>,
|
|
824
841
|
): ReturnType<typeof reserveRuntimeSandboxCapacityLease> {
|
|
@@ -836,6 +853,7 @@ export async function reserveRuntimeSandboxOperation(
|
|
|
836
853
|
environment: input.environment,
|
|
837
854
|
mode: input.mode,
|
|
838
855
|
resumePendingDaytonaOperation: input.resumePendingDaytonaOperation,
|
|
856
|
+
entitlementLimit: input.entitlementLimit,
|
|
839
857
|
},
|
|
840
858
|
options,
|
|
841
859
|
);
|
|
@@ -1267,7 +1285,11 @@ export async function recordDaytonaSandboxCleanupIntent(
|
|
|
1267
1285
|
'daytonaOrganizationId', $6::text,
|
|
1268
1286
|
'billingStartedAt', extract(epoch FROM promoted.created_at) * 1000,
|
|
1269
1287
|
'sandboxCapacityLeaseId', promoted.operation_key,
|
|
1270
|
-
'lateAcquired', true
|
|
1288
|
+
'lateAcquired', true,
|
|
1289
|
+
-- This operation is now deleting, which no writer promotes
|
|
1290
|
+
-- to live: the sandbox can never run customer code, so its
|
|
1291
|
+
-- provider time is Deepline's cost, not a customer charge.
|
|
1292
|
+
'customerCodeUnreachable', true
|
|
1271
1293
|
) AS value
|
|
1272
1294
|
FROM promoted
|
|
1273
1295
|
), recorded_attempt AS (
|
|
@@ -357,6 +357,26 @@ export function toolExecuteBillingRetryIdentity(input: {
|
|
|
357
357
|
if (failure.reason === 'provider_pacing_wait') {
|
|
358
358
|
return `app-pacing-refusal:${input.httpFailureAttempt}`;
|
|
359
359
|
}
|
|
360
|
+
// The runner resends a provider 5xx even over the app's `retryable: false`
|
|
361
|
+
// (an outcome category the app does not map, such as a DataForSEO task
|
|
362
|
+
// 5xxxx), and `billingReservationReleased` infers a release only from an
|
|
363
|
+
// explicit `retryable: true`. The app's confirmation is direct proof that
|
|
364
|
+
// this attempt's reservation is terminal and can never settle, so renewing
|
|
365
|
+
// cannot open a second chargeable reservation beside it.
|
|
366
|
+
const providerServerErrorReleased =
|
|
367
|
+
failure.reason === 'provider_server_error' &&
|
|
368
|
+
failure.billingReservationReleased;
|
|
369
|
+
const confirmedProviderRelease =
|
|
370
|
+
failure.billingReservationReleaseConfirmed &&
|
|
371
|
+
input.asyncExecutionRecovery !== true &&
|
|
372
|
+
(failure.reason === 'provider_server_error' ||
|
|
373
|
+
failure.reason === 'retry_safe_transient_5xx');
|
|
374
|
+
// The release proof applies to both fenced and unfenced sends. Resolve it
|
|
375
|
+
// before the fenced fallback, which otherwise skips a confirmed release
|
|
376
|
+
// when the response lacks the fields used to infer one.
|
|
377
|
+
if (confirmedProviderRelease) {
|
|
378
|
+
return `transient-retry:${input.httpFailureAttempt}`;
|
|
379
|
+
}
|
|
360
380
|
if (input.executionFenced) {
|
|
361
381
|
return failure.billingReservationReleased
|
|
362
382
|
? `transient-retry:${input.httpFailureAttempt}`
|
|
@@ -367,25 +387,11 @@ export function toolExecuteBillingRetryIdentity(input: {
|
|
|
367
387
|
// and halts the run. An unfenced call needs the renewal as much as a fenced
|
|
368
388
|
// one: a billed read that is not declared retry-safe is resent after a
|
|
369
389
|
// provider 5xx once `retryProviderServerErrors` is on.
|
|
370
|
-
if (
|
|
371
|
-
failure.billingReservationReleased &&
|
|
372
|
-
failure.reason === 'provider_server_error'
|
|
373
|
-
) {
|
|
374
|
-
return `transient-retry:${input.httpFailureAttempt}`;
|
|
375
|
-
}
|
|
376
|
-
// A `retrySafeTransientHttp` action bills through the same request identity,
|
|
377
|
-
// but its 502 shape is also sent while a hold is retained (an async hold with
|
|
378
|
-
// an attached provider job, an ambiguous launch) or after a release failed.
|
|
379
|
-
// Renewing there would open a second reservation beside one that can still
|
|
380
|
-
// settle, so only the app's explicit confirmation renews; without it the
|
|
381
|
-
// retry keeps its identity and recovers the reservation it already has.
|
|
382
|
-
if (
|
|
383
|
-
failure.billingReservationReleaseConfirmed &&
|
|
384
|
-
failure.reason === 'retry_safe_transient_5xx' &&
|
|
385
|
-
input.asyncExecutionRecovery !== true
|
|
386
|
-
) {
|
|
390
|
+
if (providerServerErrorReleased) {
|
|
387
391
|
return `transient-retry:${input.httpFailureAttempt}`;
|
|
388
392
|
}
|
|
393
|
+
// An unconfirmed unfenced retry-safe 5xx may retain an async hold or an
|
|
394
|
+
// ambiguous launch; keep its identity to recover that reservation.
|
|
389
395
|
return failure.backpressureDelayMs !== null ||
|
|
390
396
|
(failure.reason === 'rate_limit' && failure.knownNotDispatched)
|
|
391
397
|
? `provider-rate-limit-retry:${input.invocationAttempt}`
|
|
@@ -555,7 +561,7 @@ function isRuntimeSchedulerCapacityResponse(input: {
|
|
|
555
561
|
);
|
|
556
562
|
}
|
|
557
563
|
|
|
558
|
-
function isProviderPacingWaitResponse(input: {
|
|
564
|
+
export function isProviderPacingWaitResponse(input: {
|
|
559
565
|
status: number;
|
|
560
566
|
bodyText: string;
|
|
561
567
|
}): boolean {
|
|
@@ -686,31 +692,55 @@ export function parseToolExecuteAuthScopeChangedError(input: {
|
|
|
686
692
|
return new ToolExecuteAuthScopeChangedError(message);
|
|
687
693
|
}
|
|
688
694
|
|
|
689
|
-
/**
|
|
690
|
-
|
|
695
|
+
/**
|
|
696
|
+
* A 5xx the provider itself returned, rather than one from Deepline, that is
|
|
697
|
+
* not a timeout and not a model's own invalid answer. Owner rule: a timeout
|
|
698
|
+
* (a transport failure, or a 504 from the provider or the execute route) is
|
|
699
|
+
* never retried, and `model_output` is the model's answer, not an outage.
|
|
700
|
+
*/
|
|
701
|
+
export function isProviderServerErrorResponse(input: {
|
|
691
702
|
status: number;
|
|
692
703
|
bodyText: string;
|
|
693
704
|
}): boolean {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
);
|
|
705
|
+
if (input.status < 500 || input.status >= 600 || input.status === 504) {
|
|
706
|
+
return false;
|
|
707
|
+
}
|
|
708
|
+
const body = parseJsonObject(input.bodyText);
|
|
709
|
+
if (body?.failure_origin !== 'provider') return false;
|
|
710
|
+
if (body.error_category === 'model_output') return false;
|
|
711
|
+
if (body.error_category === 'network') return false;
|
|
712
|
+
if (typeof body.network_kind === 'string') return false;
|
|
713
|
+
// The execute route may answer a provider's 4xx (an ambiguous 402, say)
|
|
714
|
+
// with a 5xx; the provider's own status decides when it is present.
|
|
715
|
+
const upstream = body.upstream_status;
|
|
716
|
+
if (
|
|
717
|
+
typeof upstream === 'number' &&
|
|
718
|
+
upstream >= 400 &&
|
|
719
|
+
upstream <= 599 &&
|
|
720
|
+
(upstream < 500 || upstream === 504)
|
|
721
|
+
) {
|
|
722
|
+
return false;
|
|
723
|
+
}
|
|
724
|
+
return true;
|
|
699
725
|
}
|
|
700
726
|
|
|
701
727
|
/**
|
|
702
728
|
* How an action classifies for a provider 5xx (see
|
|
703
|
-
* `retry.providerServerErrorReplay` in the provider registry).
|
|
704
|
-
*
|
|
729
|
+
* `retry.providerServerErrorReplay` in the provider registry). Absent means
|
|
730
|
+
* unclassified, which retries like `idempotent_key` and `read_safe`.
|
|
705
731
|
*/
|
|
706
732
|
export type ProviderServerErrorReplay =
|
|
707
733
|
| 'idempotent_key'
|
|
708
734
|
| 'read_safe'
|
|
709
735
|
| 'never';
|
|
710
736
|
|
|
711
|
-
/**
|
|
737
|
+
/**
|
|
738
|
+
* Owner rule (2026-11-16): every provider 5xx is retried, writes included,
|
|
739
|
+
* because at-least-once beats a lost write. Only an action that explicitly
|
|
740
|
+
* declares `never` refuses; absent, unclassified and unknown values retry.
|
|
741
|
+
*/
|
|
712
742
|
export function providerServerErrorReplayAllowed(value: unknown): boolean {
|
|
713
|
-
return value
|
|
743
|
+
return value !== 'never';
|
|
714
744
|
}
|
|
715
745
|
|
|
716
746
|
function decideToolExecuteHttpRetry(input: {
|
|
@@ -718,7 +748,7 @@ function decideToolExecuteHttpRetry(input: {
|
|
|
718
748
|
/** A 5xx the provider itself returned (failure_origin provider). */
|
|
719
749
|
providerServerError?: boolean;
|
|
720
750
|
retryProviderServerErrors?: boolean;
|
|
721
|
-
/** The action's classification;
|
|
751
|
+
/** The action's classification; only `never` refuses a provider 5xx. */
|
|
722
752
|
providerServerErrorReplay?: ProviderServerErrorReplay;
|
|
723
753
|
idempotencyInProgress?: boolean;
|
|
724
754
|
gatewayInvocationInProgress?: boolean;
|
|
@@ -833,6 +863,25 @@ function decideToolExecuteHttpRetry(input: {
|
|
|
833
863
|
};
|
|
834
864
|
}
|
|
835
865
|
if (input.status >= 500 && input.status < 600) {
|
|
866
|
+
// A provider 5xx retries even when the response says it is not
|
|
867
|
+
// retryable: an API built before the owner's retry-all-5xx rule refused
|
|
868
|
+
// every unclassified action, so its refusal is not a decision this
|
|
869
|
+
// runner honors. The runner itself excludes timeouts, model output and
|
|
870
|
+
// an action that declares `never`.
|
|
871
|
+
if (
|
|
872
|
+
!input.transientHttpRetrySafe &&
|
|
873
|
+
input.retryProviderServerErrors === true &&
|
|
874
|
+
input.providerServerError === true &&
|
|
875
|
+
providerServerErrorReplayAllowed(input.providerServerErrorReplay)
|
|
876
|
+
) {
|
|
877
|
+
// Only successes are final: the same call is sent again with the same
|
|
878
|
+
// provider idempotency key, after a backoff with jitter.
|
|
879
|
+
return {
|
|
880
|
+
retryable: true,
|
|
881
|
+
attemptCap: TOOL_EXECUTE_TRANSIENT_HTTP_MAX_ATTEMPTS,
|
|
882
|
+
reason: 'provider_server_error',
|
|
883
|
+
};
|
|
884
|
+
}
|
|
836
885
|
if (input.explicitRetryable === false) {
|
|
837
886
|
return {
|
|
838
887
|
retryable: false,
|
|
@@ -857,20 +906,6 @@ function decideToolExecuteHttpRetry(input: {
|
|
|
857
906
|
reason: 'edge_gateway_transient',
|
|
858
907
|
};
|
|
859
908
|
}
|
|
860
|
-
if (
|
|
861
|
-
!input.transientHttpRetrySafe &&
|
|
862
|
-
input.retryProviderServerErrors === true &&
|
|
863
|
-
input.providerServerError === true &&
|
|
864
|
-
providerServerErrorReplayAllowed(input.providerServerErrorReplay)
|
|
865
|
-
) {
|
|
866
|
-
// Only successes are final: the same call is sent again with the same
|
|
867
|
-
// provider idempotency key, after a backoff with jitter.
|
|
868
|
-
return {
|
|
869
|
-
retryable: true,
|
|
870
|
-
attemptCap: TOOL_EXECUTE_TRANSIENT_HTTP_MAX_ATTEMPTS,
|
|
871
|
-
reason: 'provider_server_error',
|
|
872
|
-
};
|
|
873
|
-
}
|
|
874
909
|
if (!input.transientHttpRetrySafe) {
|
|
875
910
|
return {
|
|
876
911
|
retryable: false,
|
|
@@ -1024,11 +1059,11 @@ export function classifyToolExecuteHttpFailure(input: {
|
|
|
1024
1059
|
/** Defaults to `DURABLE_RUNS_ROLLOUT.retryProviderServerErrors`. */
|
|
1025
1060
|
retryProviderServerErrors?: boolean;
|
|
1026
1061
|
/**
|
|
1027
|
-
* The action's classification for a provider 5xx.
|
|
1028
|
-
*
|
|
1029
|
-
*
|
|
1030
|
-
*
|
|
1031
|
-
*
|
|
1062
|
+
* The action's classification for a provider 5xx. Only `never` refuses;
|
|
1063
|
+
* absent (unclassified) retries, writes included (owner rule 2026-11-16).
|
|
1064
|
+
* The gateway previous-outcome check passes `idempotent_key` because it
|
|
1065
|
+
* only validates the recorded outcome; the runner, which owns the resend,
|
|
1066
|
+
* has already applied the classification.
|
|
1032
1067
|
*/
|
|
1033
1068
|
providerServerErrorReplay?: ProviderServerErrorReplay;
|
|
1034
1069
|
providerLatencyMs?: number;
|