deepline 0.3.484 → 0.3.485

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.
Files changed (209) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +91 -30
  2. package/dist/bundling-sources/sdk/src/compat.ts +13 -0
  3. package/dist/bundling-sources/sdk/src/plays/client-core.ts +4 -1
  4. package/dist/bundling-sources/sdk/src/plays/run-request.ts +143 -9
  5. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  6. package/dist/bundling-sources/sdk/src/runs/watch-polling.ts +31 -4
  7. package/dist/bundling-sources/sdk/src/tool-calls.ts +1 -1
  8. package/dist/bundling-sources/sdk/src/types.ts +7 -1
  9. package/dist/bundling-sources/shared_libs/play-data-plane/sheet-column-storage.ts +32 -3
  10. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +126 -41
  11. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +231 -25
  12. package/dist/bundling-sources/shared_libs/play-runtime/daytona-runtime-config.ts +9 -0
  13. package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-machines.ts +130 -19
  14. package/dist/bundling-sources/shared_libs/play-runtime/deployment/fly-registry.ts +105 -0
  15. package/dist/bundling-sources/shared_libs/play-runtime/execute-server-timing.ts +4 -2
  16. package/dist/bundling-sources/shared_libs/play-runtime/governor/app-runtime-rate-state-backend.ts +194 -56
  17. package/dist/bundling-sources/shared_libs/play-runtime/log-provenance.ts +11 -6
  18. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/job.ts +3 -0
  19. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/ports.ts +2 -0
  20. package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/postgres-adapter.ts +2 -1
  21. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +30 -0
  22. package/dist/bundling-sources/shared_libs/play-runtime/resource-governor.ts +195 -2
  23. package/dist/bundling-sources/shared_libs/play-runtime/run-failure.ts +20 -1
  24. package/dist/bundling-sources/shared_libs/play-runtime/run-ledger-projection-contract.ts +15 -0
  25. package/dist/bundling-sources/shared_libs/play-runtime/run-snapshot-stream.ts +2 -2
  26. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/index.ts +102 -23
  27. package/dist/bundling-sources/shared_libs/play-runtime/runner-app/progress-sidecar.ts +9 -1
  28. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-control-transport.ts +25 -5
  29. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-launch-transport.ts +133 -82
  30. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +58 -16
  31. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-sandbox-absence.ts +171 -0
  32. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-session-execution.ts +69 -0
  33. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +100 -40
  34. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/types.ts +8 -0
  35. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +67 -9
  36. package/dist/bundling-sources/shared_libs/play-runtime/runtime-incident-drills.ts +5 -5
  37. package/dist/bundling-sources/shared_libs/play-runtime/runtime-receipt-store-adapter.ts +6 -3
  38. package/dist/bundling-sources/shared_libs/play-runtime/runtime-sheet-errors.ts +14 -0
  39. package/dist/bundling-sources/shared_libs/play-runtime/runtime-sheet-row-writer.ts +87 -31
  40. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/contract.ts +18 -0
  41. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/index.ts +19 -0
  42. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/runner-backend-adapter.ts +14 -0
  43. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +204 -6
  44. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd.ts +39 -0
  45. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +12 -1
  46. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +26 -0
  47. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-scope.ts +44 -15
  48. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +60 -11
  49. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +649 -38
  50. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-ledger-outbox-recovery.ts +6 -1
  51. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-event-search.ts +17 -0
  52. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +25 -33
  53. package/dist/bundling-sources/shared_libs/play-runtime/suspension.ts +12 -0
  54. package/dist/bundling-sources/shared_libs/play-runtime/test-runtime-seams.ts +21 -0
  55. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +1 -1
  56. package/dist/bundling-sources/shared_libs/plays/source-authoring-edition.ts +1 -1
  57. package/dist/cli/auth-ABZBH55L.js +43 -0
  58. package/dist/cli/{auth-EBFOTF7X.mjs → auth-OWMUENCU.mjs} +5 -5
  59. package/dist/cli/{billing-G2G3EF3I.js → billing-2FMNQGOX.js} +80 -80
  60. package/dist/cli/{billing-2ZOIMW5V.mjs → billing-JX4H3VFF.mjs} +7 -7
  61. package/dist/cli/{chunk-M4PG7FGC.js → chunk-2ILND7XX.js} +2 -2
  62. package/dist/cli/{chunk-WXRM3UC6.mjs → chunk-2ZEQ43B7.mjs} +3 -3
  63. package/dist/cli/{chunk-PU52JXKA.mjs → chunk-3DBW6C7M.mjs} +13 -4
  64. package/dist/cli/{chunk-4OVHIWE7.mjs → chunk-3DYU3JQN.mjs} +2 -2
  65. package/dist/cli/{chunk-QIDDTIVZ.js → chunk-3OF7NSGR.js} +322 -294
  66. package/dist/cli/{chunk-YWC5AN26.mjs → chunk-3Z24NKW7.mjs} +62 -34
  67. package/dist/cli/{chunk-RLLEH2SP.js → chunk-5DCQWQCP.js} +26 -26
  68. package/dist/cli/{chunk-DEXSQGXB.mjs → chunk-62PJ6PK7.mjs} +5 -5
  69. package/dist/cli/{chunk-6NPWXE32.mjs → chunk-676NZ7K4.mjs} +1 -1
  70. package/dist/cli/{chunk-FRD5WFT4.js → chunk-775AZTO7.js} +323 -247
  71. package/dist/cli/{chunk-4OEOM6GP.mjs → chunk-ACTUAZYP.mjs} +5 -5
  72. package/dist/cli/{chunk-ZOKM7DVA.js → chunk-AFADYKFE.js} +8 -8
  73. package/dist/cli/{chunk-GVAENVIG.js → chunk-AUQQVDAB.js} +110 -21
  74. package/dist/cli/{chunk-U7IJAGWB.js → chunk-BSKPQB2P.js} +7 -7
  75. package/dist/cli/chunk-C6QWRSMQ.js +42 -0
  76. package/dist/cli/{chunk-AK7UKQ5R.js → chunk-CSBMKHTV.js} +5 -5
  77. package/dist/cli/{chunk-YHA3EV3I.mjs → chunk-CW6TAQBF.mjs} +15 -4
  78. package/dist/cli/{chunk-UT4YMA2N.js → chunk-DMNVM34J.js} +5 -4
  79. package/dist/cli/{chunk-XZXIWPT3.mjs → chunk-E73JXJA3.mjs} +1 -1
  80. package/dist/cli/{chunk-5KNRQWHE.js → chunk-EC2CVPN5.js} +3 -3
  81. package/dist/cli/{chunk-IXWQOVNW.js → chunk-ECIXZNSW.js} +87 -76
  82. package/dist/cli/{chunk-LTZXLYKE.mjs → chunk-FJY6K3BG.mjs} +93 -17
  83. package/dist/cli/{chunk-TRLDJNVE.mjs → chunk-G5PI3RNT.mjs} +1 -1
  84. package/dist/cli/{chunk-WYUCDLVR.mjs → chunk-GHHJWCMD.mjs} +2 -1
  85. package/dist/cli/{chunk-FQK7BULS.js → chunk-HKGXGGIV.js} +1 -1
  86. package/dist/cli/{chunk-2AWYJXBX.js → chunk-IHMYIHF4.js} +5 -5
  87. package/dist/cli/{chunk-SD7QWZTV.mjs → chunk-INW22YP7.mjs} +1 -1
  88. package/dist/cli/{chunk-OWUZKXE7.mjs → chunk-J7EENGKJ.mjs} +1 -1
  89. package/dist/cli/{chunk-TIRSKEZH.mjs → chunk-JD6HKNKD.mjs} +1 -1
  90. package/dist/cli/{chunk-OHKKDPA5.js → chunk-JQXUWYWX.js} +13 -13
  91. package/dist/cli/{chunk-EACX7QXO.mjs → chunk-KZTNNLIL.mjs} +2 -2
  92. package/dist/cli/{chunk-7K5CWKKZ.mjs → chunk-L352NOE3.mjs} +2 -2
  93. package/dist/cli/{chunk-KGOC6HGI.js → chunk-L7IQ3DFH.js} +53 -53
  94. package/dist/cli/{chunk-4IOY2SCQ.js → chunk-LOX3BISD.js} +4 -4
  95. package/dist/cli/{chunk-6GRZEYSG.js → chunk-NKPTM7SK.js} +7 -7
  96. package/dist/cli/{chunk-VEVGM6B5.js → chunk-NLRTFJGH.js} +14 -14
  97. package/dist/cli/{chunk-UKM74PAA.js → chunk-NRNWPWBW.js} +37 -37
  98. package/dist/cli/{chunk-HNRELVCS.mjs → chunk-ONONSV2Q.mjs} +96 -7
  99. package/dist/cli/{chunk-CYWBAV5H.js → chunk-OW4OTEFF.js} +16 -16
  100. package/dist/cli/{chunk-5K5CAND4.mjs → chunk-RZE5I2XJ.mjs} +4 -4
  101. package/dist/cli/{chunk-3XQIVEAT.js → chunk-S3WQJ5VG.js} +3 -3
  102. package/dist/cli/{chunk-4SFC2XUF.mjs → chunk-SR6S4EYG.mjs} +5 -5
  103. package/dist/cli/{chunk-UWOY74RU.js → chunk-T4G2T5DS.js} +21 -21
  104. package/dist/cli/{chunk-TN2GW57M.mjs → chunk-TMCC7ORQ.mjs} +1 -1
  105. package/dist/cli/{chunk-HEI3BWIV.mjs → chunk-TSCUWWTM.mjs} +1 -1
  106. package/dist/cli/{chunk-DBJ62RAO.js → chunk-TVW6USSG.js} +3 -3
  107. package/dist/cli/{chunk-NW4QJE54.js → chunk-U6WEGDD3.js} +2 -2
  108. package/dist/cli/{chunk-V7JCMBLU.mjs → chunk-UPHXGZCE.mjs} +4 -4
  109. package/dist/cli/{chunk-C62NI2X6.js → chunk-UQ3LQ6IF.js} +5 -5
  110. package/dist/cli/{chunk-5GOG5ZGC.mjs → chunk-VZYTLWOM.mjs} +2 -2
  111. package/dist/cli/{chunk-AF7MOUZP.mjs → chunk-W33OL4F2.mjs} +2 -2
  112. package/dist/cli/{chunk-ZM2YPJQJ.js → chunk-XK5DMLZE.js} +5 -1
  113. package/dist/cli/{chunk-LJ5747UC.mjs → chunk-XRDXNAAY.mjs} +5 -1
  114. package/dist/cli/{chunk-YGN77QA5.mjs → chunk-YDA3PMKK.mjs} +3 -3
  115. package/dist/cli/{csv-S3CHUKI6.js → csv-HFEQPGNY.js} +13 -13
  116. package/dist/cli/{csv-NLWVWD3H.mjs → csv-OHF3Y5KB.mjs} +4 -4
  117. package/dist/cli/{db-OGRPAEEM.mjs → db-M456OUXD.mjs} +7 -7
  118. package/dist/cli/{db-WBSKMMOH.js → db-VLQKCYQS.js} +28 -28
  119. package/dist/cli/describe-CP35DZ5Z.js +49 -0
  120. package/dist/cli/{describe-FAD3Z7LN.mjs → describe-M6VXFYVL.mjs} +21 -21
  121. package/dist/cli/describe-core.d.mts +3 -3
  122. package/dist/cli/describe-core.d.ts +3 -3
  123. package/dist/cli/describe-core.js +4 -4
  124. package/dist/cli/describe-core.mjs +3 -3
  125. package/dist/cli/{executions-LYCL344R.mjs → executions-4FGRBPJF.mjs} +7 -7
  126. package/dist/cli/{executions-SOAZHCY4.js → executions-GKINJZI6.js} +9 -9
  127. package/dist/cli/{feedback-AVF6V7SV.mjs → feedback-D2WMGK3V.mjs} +4 -4
  128. package/dist/cli/{feedback-OROUPUNJ.js → feedback-ZH5K7WV7.js} +8 -8
  129. package/dist/cli/git-IDALMZDN.js +25 -0
  130. package/dist/cli/{git-J5N5M57H.mjs → git-OCIJ5ME4.mjs} +5 -5
  131. package/dist/cli/index.js +142 -139
  132. package/dist/cli/index.mjs +45 -42
  133. package/dist/cli/{legacy-noops-QAQMZMEG.js → legacy-noops-QNIVP7LO.js} +8 -8
  134. package/dist/cli/{legacy-noops-ENRRM7BL.mjs → legacy-noops-V6Q2X34P.mjs} +5 -5
  135. package/dist/cli/{monitors-CKQ65WRL.mjs → monitors-2USHTG5G.mjs} +8 -8
  136. package/dist/cli/{monitors-SFMQ5LFR.js → monitors-5DNK7W2K.js} +92 -92
  137. package/dist/cli/{org-3UNTDLT2.js → org-RPGM5AN4.js} +73 -73
  138. package/dist/cli/{org-K4UIEU5P.mjs → org-TL2YPYSE.mjs} +7 -7
  139. package/dist/cli/{pages-NKZTGB4C.js → pages-PNUKPFWV.js} +18 -18
  140. package/dist/cli/{pages-6GPGBIAH.mjs → pages-XDEW6EE3.mjs} +7 -7
  141. package/dist/cli/{play-BDEADESI.js → play-F5LHRKV5.js} +858 -632
  142. package/dist/cli/{play-62BEE7IX.mjs → play-WINNQ4HZ.mjs} +372 -146
  143. package/dist/cli/{providers-SXGP44GH.js → providers-BD4IS5U5.js} +10 -10
  144. package/dist/cli/{providers-X3CUWMFP.mjs → providers-PXGL3FRE.mjs} +7 -7
  145. package/dist/cli/{quickstart-XQ4426M4.js → quickstart-7LVF6HZF.js} +6 -6
  146. package/dist/cli/{quickstart-7LN22BKX.mjs → quickstart-XTH3UQWZ.mjs} +4 -4
  147. package/dist/cli/{run-XXSN3B5A.mjs → run-MBMUENR7.mjs} +26 -26
  148. package/dist/cli/{run-PBJ4ZJ4W.js → run-NH2BAWPA.js} +41 -41
  149. package/dist/cli/{search-M75VMADD.mjs → search-BMRWBV66.mjs} +8 -8
  150. package/dist/cli/search-R3MQJQMT.js +32 -0
  151. package/dist/cli/{search-output-F6HCFYEI.js → search-output-5NNT337U.js} +22 -16
  152. package/dist/cli/{search-output-NUQAKWDM.mjs → search-output-QKKRD4MF.mjs} +14 -8
  153. package/dist/cli/{secrets-J2H6V33R.mjs → secrets-AWEXBTJV.mjs} +7 -7
  154. package/dist/cli/{secrets-LRYY4QPE.js → secrets-KQSTOREN.js} +16 -16
  155. package/dist/cli/{sessions-YPF62CZE.js → sessions-DSPLZYCJ.js} +6 -6
  156. package/dist/cli/{sessions-IMT336UV.mjs → sessions-RO25Q67X.mjs} +5 -5
  157. package/dist/cli/{settings-35YYC5WA.js → settings-7JXIKNKI.js} +79 -79
  158. package/dist/cli/{settings-PDWVQIGH.mjs → settings-JMGXGK4Z.mjs} +12 -12
  159. package/dist/cli/{setup-UR7GOR7H.js → setup-5QFAQQRW.js} +47 -47
  160. package/dist/cli/{setup-DG5DISSE.mjs → setup-ZQZ47FHB.mjs} +9 -9
  161. package/dist/cli/skills-EDZXY7DV.js +33 -0
  162. package/dist/cli/{skills-U6NJD5J7.mjs → skills-W3H2DL56.mjs} +7 -7
  163. package/dist/cli/{tools-2HGEOELR.mjs → tools-2BZCVNBS.mjs} +19 -19
  164. package/dist/cli/tools-2EY2ETCZ.js +56 -0
  165. package/dist/cli/{update-FRAYBAHK.mjs → update-GAWYMGAW.mjs} +9 -9
  166. package/dist/cli/update-UKDQKNBY.js +33 -0
  167. package/dist/cli/{workflow-DDKVTF36.mjs → workflow-M6LLHQ2I.mjs} +8 -8
  168. package/dist/cli/{workflow-JKKLOMBX.js → workflow-ZPTDFPKW.js} +18 -18
  169. package/dist/{client-DJ3r8VQJ.d.mts → client-BkbDHRIg.d.mts} +1 -1
  170. package/dist/{client-JPSNljtj.d.ts → client-D3hVHXjK.d.ts} +1 -1
  171. package/dist/{client-core-3SJlNsKU.d.mts → client-core-BZoSMKcY.d.mts} +30 -15
  172. package/dist/{client-core-rCoQ5Xz3.d.ts → client-core-DUdVqO_m.d.ts} +30 -15
  173. package/dist/{compiler-manifest-gkO9ZkVg.d.mts → compiler-manifest-BFTwq1HI.d.mts} +1 -1
  174. package/dist/{compiler-manifest-gkO9ZkVg.d.ts → compiler-manifest-BFTwq1HI.d.ts} +1 -1
  175. package/dist/{errors-Cc92LKH-.d.ts → errors-c3pMsylw.d.ts} +1 -1
  176. package/dist/{errors-CeCCOKSA.d.mts → errors-w31ybrQM.d.mts} +1 -1
  177. package/dist/{index-DJQKdV76.d.ts → index-CQ-15-QL.d.ts} +1 -1
  178. package/dist/{index-DsqWJL3Q.d.mts → index-DvNtxucX.d.mts} +1 -1
  179. package/dist/index.d.mts +7 -7
  180. package/dist/index.d.ts +7 -7
  181. package/dist/index.js +10 -10
  182. package/dist/index.mjs +7 -7
  183. package/dist/install-integrity.json +117 -116
  184. package/dist/plays/bundle-play-file.d.mts +3 -3
  185. package/dist/plays/bundle-play-file.d.ts +3 -3
  186. package/dist/plays/bundle-play-file.mjs +2 -2
  187. package/dist/plays/play-description.d.mts +2 -2
  188. package/dist/plays/play-description.d.ts +2 -2
  189. package/dist/plays/run-request.d.mts +2 -2
  190. package/dist/plays/run-request.d.ts +2 -2
  191. package/dist/plays/run-request.js +12 -2
  192. package/dist/plays/run-request.mjs +11 -1
  193. package/dist/release.d.mts +1 -1
  194. package/dist/release.d.ts +1 -1
  195. package/dist/release.js +2 -2
  196. package/dist/release.mjs +1 -1
  197. package/dist/server.d.mts +4 -4
  198. package/dist/server.d.ts +4 -4
  199. package/dist/server.js +6 -6
  200. package/dist/server.mjs +4 -4
  201. package/package.json +1 -1
  202. package/dist/cli/auth-L5CSV3UO.js +0 -43
  203. package/dist/cli/chunk-KA2LNIUP.js +0 -33
  204. package/dist/cli/describe-UIAYCHWW.js +0 -49
  205. package/dist/cli/git-ATMWC27D.js +0 -25
  206. package/dist/cli/search-IGHLRLBD.js +0 -32
  207. package/dist/cli/skills-4U5WC4MJ.js +0 -33
  208. package/dist/cli/tools-PYJTQVVS.js +0 -56
  209. package/dist/cli/update-344OTRFM.js +0 -33
@@ -1,10 +1,16 @@
1
+ import {
2
+ isRuntimeRateStateDiagnosticBucket,
3
+ runtimeRateStateBucketDigest,
4
+ } from '../test-runtime-seams';
1
5
  import {
2
6
  acquireRateStateViaAppRuntime,
3
7
  AppRuntimeApiTransportError,
4
8
  capacityShedRetryAfterMs,
9
+ isAppRuntimeApiCapacityError,
5
10
  flushRateStateFeedbackViaAppRuntime,
6
11
  penalizeRateStateViaAppRuntime,
7
12
  releaseRateStateViaAppRuntime,
13
+ AppRuntimeApiResponseError,
8
14
  RateStateValidationUnavailableError,
9
15
  validateRateStateViaAppRuntime,
10
16
  type WorkerRuntimeApiContext,
@@ -216,6 +222,10 @@ interface PendingRelease {
216
222
  flushing: boolean;
217
223
  }
218
224
 
225
+ type RateStateDiagnostic = Readonly<
226
+ Record<string, string | number | boolean | null>
227
+ >;
228
+
219
229
  interface Options {
220
230
  schedulerSchema?: string | null;
221
231
  now?: () => number;
@@ -238,6 +248,9 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
238
248
  */
239
249
  readonly kind: RateStateBackendKind = 'app_runtime_postgres';
240
250
  private readonly port: AppRuntimeRatePort;
251
+ private onDiagnostic = (fields: RateStateDiagnostic): void => {
252
+ console.info('[runtime.provider.rate_state.decision]', fields);
253
+ };
241
254
  private readonly schedulerSchema: string | null;
242
255
  private readonly now: () => number;
243
256
  private readonly sleep: (
@@ -292,7 +305,7 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
292
305
  * grant). Demand-sizing reads this to request a block sized to the live wave
293
306
  * instead of a fixed floor, so a 200-row map fans into ~one round trip.
294
307
  */
295
- private readonly waiters = new Map<string, number>();
308
+ private readonly waiters = new Map<string, Set<{ signal?: AbortSignal }>>();
296
309
  /** Due retries precede fresh draws; already assigned tickets keep ownership. */
297
310
  private readonly retryAdmissions = new Map<string, Set<Promise<void>>>();
298
311
  /** Last-known server cooldown per bucket (surfaced for PROVIDER_EXHAUSTED). */
@@ -352,6 +365,20 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
352
365
  });
353
366
  }
354
367
 
368
+ /** Route selected diagnostics through the owning runner's retained log. */
369
+ setDiagnosticSink(sink: (fields: RateStateDiagnostic) => void): void {
370
+ this.onDiagnostic = sink;
371
+ }
372
+
373
+ private emitDiagnostic(fields: RateStateDiagnostic): void {
374
+ try {
375
+ this.onDiagnostic(fields);
376
+ } catch {
377
+ // Diagnostics are advisory. A failing log sink must never turn a
378
+ // committed admission into a store retry and mint another grant.
379
+ }
380
+ }
381
+
355
382
  /**
356
383
  * Last-known server cooldown for a bucket, or null if the bucket has never
357
384
  * reported one. Minimal read surface for the PROVIDER_EXHAUSTED task: it lets
@@ -362,8 +389,30 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
362
389
  return this.cooldowns.get(bucketId) ?? null;
363
390
  }
364
391
 
365
- private serverNow(bucketId: string): number {
366
- return this.now() + (this.serverClockOffsetsMs.get(bucketId) ?? 0);
392
+ private serverNow(bucketId: string, localNowMs = this.now()): number {
393
+ return localNowMs + (this.serverClockOffsetsMs.get(bucketId) ?? 0);
394
+ }
395
+
396
+ private providerExhaustedAtServerDeadline(
397
+ bucketId: string,
398
+ retryAtMs: number,
399
+ localNowMs: number,
400
+ ): ProviderExhaustedError {
401
+ return new ProviderExhaustedError({
402
+ provider: providerNameFromBucketId(bucketId),
403
+ retryAtMs,
404
+ ...(this.serverClockOffsetsMs.has(bucketId)
405
+ ? {
406
+ // Keep the provider's absolute deadline unchanged. A caller uses
407
+ // its own wall clock, while this backend deliberately retains a
408
+ // conservative server clock across uncertain response transit.
409
+ localRetryAtMs: Math.ceil(
410
+ localNowMs +
411
+ Math.max(0, retryAtMs - this.serverNow(bucketId, localNowMs)),
412
+ ),
413
+ }
414
+ : {}),
415
+ });
367
416
  }
368
417
 
369
418
  /**
@@ -382,9 +431,10 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
382
431
  if (exhausted) throw exhausted;
383
432
  const stall = this.providerStalls.get(bucketId);
384
433
  if (!stall) return;
385
- const elapsedMs = this.now() - stall.startedAt;
434
+ const localNowMs = this.now();
435
+ const elapsedMs = localNowMs - stall.startedAt;
386
436
  const cooldown = this.cooldowns.get(bucketId);
387
- const serverNowMs = this.serverNow(bucketId);
437
+ const serverNowMs = this.serverNow(bucketId, localNowMs);
388
438
  const retryAtMs = Math.max(
389
439
  cooldown?.coolUntilMs ?? 0,
390
440
  cooldown?.claimedRetryAtMs ?? 0,
@@ -403,10 +453,11 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
403
453
  (elapsedMs >= RATE_ACQUIRE_MAX_WAIT_MS ||
404
454
  retryAtMs - serverNowMs > RATE_ACQUIRE_MAX_WAIT_MS - elapsedMs)
405
455
  ) {
406
- throw new ProviderExhaustedError({
407
- provider: providerNameFromBucketId(bucketId),
456
+ throw this.providerExhaustedAtServerDeadline(
457
+ bucketId,
408
458
  retryAtMs,
409
- });
459
+ localNowMs,
460
+ );
410
461
  }
411
462
  if (!stall.warned && elapsedMs >= PROVIDER_NO_PROGRESS_WARNING_MS) {
412
463
  stall.warned = true;
@@ -424,7 +475,8 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
424
475
  ): ProviderExhaustedError | null {
425
476
  const cooldown = this.cooldowns.get(bucketId);
426
477
  if (!cooldown) return null;
427
- const now = this.serverNow(bucketId);
478
+ const localNowMs = this.now();
479
+ const now = this.serverNow(bucketId, localNowMs);
428
480
  const coolActive = cooldown.coolUntilMs - now > 0;
429
481
  const claimActive = cooldown.claimedRetryAtMs - now > 0;
430
482
  if (!coolActive && !claimActive) return null;
@@ -445,10 +497,11 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
445
497
  coolActive ? cooldown.coolUntilMs : 0,
446
498
  claimActive ? cooldown.claimedRetryAtMs : 0,
447
499
  );
448
- return new ProviderExhaustedError({
449
- provider: providerNameFromBucketId(bucketId),
500
+ return this.providerExhaustedAtServerDeadline(
501
+ bucketId,
450
502
  retryAtMs,
451
- });
503
+ localNowMs,
504
+ );
452
505
  }
453
506
 
454
507
  tryAcquire(input: {
@@ -657,7 +710,10 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
657
710
  // Count this acquirer as waiting on the refill so the single-flight refill
658
711
  // can size its block to the live wave. Decremented once a block lands (or
659
712
  // the refill errors) — see the finally in `refillBlock`.
660
- this.waiters.set(laneKey, (this.waiters.get(laneKey) ?? 0) + 1);
713
+ const waiter = { signal };
714
+ const waiters = this.waiters.get(laneKey) ?? new Set();
715
+ waiters.add(waiter);
716
+ this.waiters.set(laneKey, waiters);
661
717
  try {
662
718
  await this.refillBlock(
663
719
  bucketId,
@@ -669,9 +725,8 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
669
725
  input.yieldProviderHolds === true,
670
726
  );
671
727
  } finally {
672
- const remaining = (this.waiters.get(laneKey) ?? 1) - 1;
673
- if (remaining > 0) this.waiters.set(laneKey, remaining);
674
- else this.waiters.delete(laneKey);
728
+ waiters.delete(waiter);
729
+ if (waiters.size === 0) this.waiters.delete(laneKey);
675
730
  }
676
731
  }
677
732
  }
@@ -708,9 +763,10 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
708
763
  learnedRps < DEFAULT_UNKNOWN_PROVIDER_FAST_RECOVERY_RPS &&
709
764
  rules.some((rule) => rule.ruleId === 'default:provider-scope') &&
710
765
  rules.every((rule) => rule.ruleId.startsWith('default:'));
711
- // Below recovered capacity, one dispatch interval (500/250/125ms at
712
- // 2/4/8 RPS) can prove the next step. Reserve only that interval so cached
713
- // old-pace tickets cannot postpone the next fresh-feedback refill.
766
+ // During fast recovery, one dispatch interval at the learned pace can
767
+ // prove the next step. Reserve only that interval so cached old-pace
768
+ // tickets cannot delay fresh-feedback refills. Once recovered, batch over
769
+ // the normal horizon and preserve the round-trip savings for steady traffic.
714
770
  const horizonMs = Math.min(
715
771
  recoveringUnknownProvider ? 1_000 / currentRps : RATE_BLOCK_HORIZON_MS,
716
772
  leasedBlockTtlMs(rules),
@@ -720,7 +776,7 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
720
776
  Math.floor((currentRps * horizonMs) / 1_000),
721
777
  );
722
778
  if (!Number.isFinite(rateBudget) || rateBudget <= 0) return floor;
723
- const waiters = this.waiters.get(laneKey) ?? 1;
779
+ const waiters = this.waiters.get(laneKey)?.size ?? 1;
724
780
  const concurrencyLimits = rules.flatMap((rule) =>
725
781
  rule.maxConcurrency != null &&
726
782
  Number.isFinite(rule.maxConcurrency) &&
@@ -960,7 +1016,8 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
960
1016
  claimedRetryAtMs?: number;
961
1017
  },
962
1018
  ): ProviderExhaustedError {
963
- const now = this.serverNow(bucketId);
1019
+ const localNowMs = this.now();
1020
+ const now = this.serverNow(bucketId, localNowMs);
964
1021
  const claimedRetryAtMs = Number(response.claimedRetryAtMs);
965
1022
  const coolUntilMs = Number(response.coolUntilMs);
966
1023
  const retryAtMs =
@@ -970,10 +1027,11 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
970
1027
  : 0,
971
1028
  Number.isFinite(coolUntilMs) && coolUntilMs > now ? coolUntilMs : 0,
972
1029
  ) || now + Math.max(0, response.waitMs);
973
- return new ProviderExhaustedError({
974
- provider: providerNameFromBucketId(bucketId),
1030
+ return this.providerExhaustedAtServerDeadline(
1031
+ bucketId,
975
1032
  retryAtMs,
976
- });
1033
+ localNowMs,
1034
+ );
977
1035
  }
978
1036
 
979
1037
  /**
@@ -1046,6 +1104,9 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
1046
1104
  await pendingPenalty;
1047
1105
  continue;
1048
1106
  }
1107
+ let acquireRpcStartedAtMs: number | null = null;
1108
+ let acquireRpcRequested: number | null = null;
1109
+ let acquireRpcPending = false;
1049
1110
  try {
1050
1111
  let releaseSignal = this.leaseReleaseSignals.get(bucketId);
1051
1112
  if (
@@ -1059,15 +1120,42 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
1059
1120
  const releaseGeneration = releaseSignal?.generation;
1060
1121
  const successKey = pendingSuccessKey(bucketId, ordered);
1061
1122
  const feedback = this.snapshotSuccessFeedback(successKey);
1123
+ const requested = this.requestedForBucket(laneKey, ordered);
1062
1124
  const requestStartedAtMs = this.now();
1125
+ acquireRpcStartedAtMs = requestStartedAtMs;
1126
+ acquireRpcRequested = requested;
1127
+ acquireRpcPending = true;
1063
1128
  const rawResponse = await this.port.acquire({
1064
1129
  bucketId,
1065
1130
  rateScopeToken,
1066
1131
  rules: withAdaptiveMaxRps(ordered),
1067
- requested: this.requestedForBucket(laneKey, ordered),
1132
+ requested,
1068
1133
  ...feedback,
1069
1134
  schedulerSchema: this.schedulerSchema,
1070
1135
  });
1136
+ const acquireRpcElapsedMs = Math.max(
1137
+ 0,
1138
+ this.now() - requestStartedAtMs,
1139
+ );
1140
+ acquireRpcPending = false;
1141
+ // The receiver opts in using authenticated Play identity. Older receivers
1142
+ // omit this snapshot; neither its absence nor this trace affects pacing.
1143
+ if (
1144
+ rawResponse.governorSnapshot &&
1145
+ isRuntimeRateStateDiagnosticBucket(bucketId)
1146
+ ) {
1147
+ this.emitDiagnostic({
1148
+ observationStage: 'caller_acquire',
1149
+ action: 'rate_state_acquire',
1150
+ bucketDigest: runtimeRateStateBucketDigest(bucketId),
1151
+ requested,
1152
+ granted: rawResponse.granted,
1153
+ waitMs: rawResponse.waitMs,
1154
+ acquireRpcElapsedMs,
1155
+ serverNowMs: rawResponse.serverNowMs ?? null,
1156
+ ...rawResponse.governorSnapshot,
1157
+ });
1158
+ }
1071
1159
  const serverElapsedMs = rawResponse.serverClockElapsedMs;
1072
1160
  const validServerElapsed =
1073
1161
  typeof rawResponse.serverNowMs === 'number' &&
@@ -1130,16 +1218,40 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
1130
1218
  );
1131
1219
  }
1132
1220
  if (response.granted > 0) {
1133
- // Merge the whole grant into the block and let acquirers re-draw. No
1134
- // permit is handed out here, so nothing is double-drawn.
1135
- this.mergeGrantedBlock(
1221
+ const permits = this.grantedPermits(
1136
1222
  bucketId,
1137
- rateScopeToken,
1138
1223
  ordered,
1139
- rulesKey,
1140
1224
  laneKey,
1141
1225
  response,
1142
1226
  );
1227
+ // A committed grant can arrive after every owner of this refill
1228
+ // cancelled. Nobody will draw or lazily expire that block: return
1229
+ // its exact unsent reservations before another backend needs slots.
1230
+ // The first caller's signal alone cannot cancel a live sibling.
1231
+ if (
1232
+ ![...(this.waiters.get(laneKey) ?? [])].some(
1233
+ (waiter) => !waiter.signal?.aborted,
1234
+ )
1235
+ ) {
1236
+ // A refund failure rejects this flight; it must not enter the
1237
+ // store-acquire retry ladder and mint another ownerless grant.
1238
+ return this.cancelReserved({
1239
+ bucketId,
1240
+ rateScopeToken,
1241
+ rules: ordered,
1242
+ leaseIds: permits.flatMap(([, id]) => (id ? [id] : [])),
1243
+ reservationIds: permits.flatMap(([, , id]) => (id ? [id] : [])),
1244
+ });
1245
+ }
1246
+ // No permit is handed out here: matching live acquirers re-draw.
1247
+ this.mergeBlock(
1248
+ bucketId,
1249
+ rateScopeToken,
1250
+ permits,
1251
+ rulesKey,
1252
+ laneKey,
1253
+ ordered,
1254
+ );
1143
1255
  return;
1144
1256
  }
1145
1257
  if (yieldProviderHolds) {
@@ -1195,6 +1307,37 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
1195
1307
  }
1196
1308
  return;
1197
1309
  } catch (error) {
1310
+ // A thrown RPC has an unknown grant/commit outcome, not a zero grant.
1311
+ // The caller lacks authenticated Play identity; only this reserved
1312
+ // synthetic bucket is eligible for error timing (no snapshot arrived).
1313
+ if (
1314
+ acquireRpcPending &&
1315
+ acquireRpcStartedAtMs !== null &&
1316
+ isRuntimeRateStateDiagnosticBucket(bucketId)
1317
+ ) {
1318
+ const errorName = error instanceof Error ? error.name : '';
1319
+ this.emitDiagnostic({
1320
+ observationStage: 'caller_acquire_error',
1321
+ action: 'rate_state_acquire',
1322
+ bucketDigest: runtimeRateStateBucketDigest(bucketId),
1323
+ requested: acquireRpcRequested,
1324
+ acquireRpcElapsedMs: Math.max(
1325
+ 0,
1326
+ this.now() - acquireRpcStartedAtMs,
1327
+ ),
1328
+ outcome: 'unknown',
1329
+ errorClassification:
1330
+ signal?.aborted || errorName === 'AbortError'
1331
+ ? 'cancelled'
1332
+ : errorName === 'TimeoutError'
1333
+ ? 'timeout'
1334
+ : isAppRuntimeApiCapacityError(error)
1335
+ ? 'capacity'
1336
+ : error instanceof AppRuntimeApiResponseError
1337
+ ? 'http'
1338
+ : 'transport_or_store',
1339
+ });
1340
+ }
1198
1341
  // A provider hold is not a store failure. Preserve its deadline for
1199
1342
  // the caller's durable suspension or non-durable error path.
1200
1343
  if (error instanceof ProviderExhaustedError) throw error;
@@ -1237,16 +1380,14 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
1237
1380
  }
1238
1381
 
1239
1382
  /**
1240
- * Validate a granted acquire response and merge its permits into the bucket's
1241
- * local block. Concurrency rules carry one lease token per permit (release
1383
+ * Validate a granted acquire response and prepare its scheduled permits.
1384
+ * Concurrency rules carry one lease token per permit (release
1242
1385
  * semantics); pure-rate rules carry untracked window permits the store already
1243
1386
  * decremented.
1244
1387
  */
1245
- private mergeGrantedBlock(
1388
+ private grantedPermits(
1246
1389
  bucketId: string,
1247
- rateScopeToken: string | null,
1248
1390
  ordered: PacingRule[],
1249
- rulesKey: string,
1250
1391
  laneKey: string,
1251
1392
  response: {
1252
1393
  granted: number;
@@ -1259,7 +1400,7 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
1259
1400
  claimedRetryAtMs?: number;
1260
1401
  dispatchValidationSupported?: boolean;
1261
1402
  },
1262
- ): void {
1403
+ ): LeasedBlock['permits'] {
1263
1404
  const hasConcurrency = ordered.some((rule) => rule.maxConcurrency != null);
1264
1405
  const leaseIds = Array.isArray(response.leaseIds)
1265
1406
  ? response.leaseIds.filter(
@@ -1452,23 +1593,16 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
1452
1593
  `Rate-state store granted ${response.granted} permits for ${bucketId} with ${scheduledAtMs.length} dispatch timestamps.`,
1453
1594
  );
1454
1595
  }
1455
- this.mergeBlock(
1456
- bucketId,
1457
- rateScopeToken,
1458
- scheduledAtMs.map(
1459
- (scheduledAtMs, index): LeasedBlock['permits'][number] => [
1460
- scheduledAtMs,
1461
- hasConcurrency ? (leaseIds[index] ?? null) : null,
1462
- reservationIds[index] ?? null,
1463
- concurrencyGrants[index] ?? null,
1464
- pacingGrant,
1465
- Math.max(0, response.claimedRetryAtMs ?? 0),
1466
- response.dispatchValidationSupported === true,
1467
- ],
1468
- ),
1469
- rulesKey,
1470
- laneKey,
1471
- ordered,
1596
+ return scheduledAtMs.map(
1597
+ (scheduledAtMs, index): LeasedBlock['permits'][number] => [
1598
+ scheduledAtMs,
1599
+ hasConcurrency ? (leaseIds[index] ?? null) : null,
1600
+ reservationIds[index] ?? null,
1601
+ concurrencyGrants[index] ?? null,
1602
+ pacingGrant,
1603
+ Math.max(0, response.claimedRetryAtMs ?? 0),
1604
+ response.dispatchValidationSupported === true,
1605
+ ],
1472
1606
  );
1473
1607
  }
1474
1608
 
@@ -1729,7 +1863,7 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
1729
1863
  rateScopeToken,
1730
1864
  rules,
1731
1865
  leaseIds: leaseId ? [leaseId] : [],
1732
- reservationId,
1866
+ reservationIds: [reservationId],
1733
1867
  });
1734
1868
  };
1735
1869
  return {
@@ -2038,15 +2172,19 @@ export class AppRuntimeRateStateBackend implements RateStateBackend {
2038
2172
  rateScopeToken: string | null;
2039
2173
  rules: readonly PacingRule[];
2040
2174
  leaseIds: readonly string[];
2041
- reservationId: string;
2175
+ reservationIds: readonly string[];
2042
2176
  }): Promise<void> {
2177
+ // Outgoing gateways can omit refundable identities. Preserve their
2178
+ // forfeited rate tokens while still returning any concurrency leases.
2179
+ if (input.leaseIds.length === 0 && input.reservationIds.length === 0)
2180
+ return;
2043
2181
  try {
2044
2182
  await this.port.release({
2045
2183
  bucketId: input.bucketId,
2046
2184
  rateScopeToken: input.rateScopeToken,
2047
2185
  rules: [...input.rules],
2048
2186
  leaseIds: [...input.leaseIds],
2049
- refundReservationIds: [input.reservationId],
2187
+ refundReservationIds: [...input.reservationIds],
2050
2188
  schedulerSchema: this.schedulerSchema,
2051
2189
  });
2052
2190
  if (input.leaseIds.length > 0) this.signalLeaseRelease(input.bucketId);
@@ -43,7 +43,8 @@ export type LogProvenance =
43
43
  * replay copy is churn. */
44
44
  | 'replay'
45
45
  /** Scheduler / sandbox / worker internals: run-file prep, sandbox
46
- * lifecycle, `[perf]` timings, batch-drain bookkeeping. Operator-facing. */
46
+ * lifecycle, `[perf]` and `[perf-trace]` timings, batch-drain bookkeeping.
47
+ * Operator-facing. */
47
48
  | 'infra'
48
49
  /** Warnings and diagnostics: `[warn]`, `[error]`, `[runtime.*_failure]`,
49
50
  * and forward-looking hints. Surfaced because a human may need to act. */
@@ -127,10 +128,12 @@ export function isDurableDirectRunnerLog(event: {
127
128
  source?: unknown;
128
129
  line?: unknown;
129
130
  }): boolean {
131
+ if (typeof event.line !== 'string' || event.line.length === 0) return false;
132
+ if (event.source !== 'worker') return true;
133
+ const tagged = readProvenanceTag(event.line);
130
134
  return (
131
- typeof event.line === 'string' &&
132
- event.line.length > 0 &&
133
- (event.source !== 'worker' || event.line.startsWith('[perf-trace] '))
135
+ (tagged.provenance === null || tagged.provenance === 'infra') &&
136
+ tagged.line.startsWith('[perf-trace] ')
134
137
  );
135
138
  }
136
139
 
@@ -319,8 +322,9 @@ export function stripProvenanceTag(line: string): string {
319
322
  * Legacy classifier for old persisted log strings that carry NO structural
320
323
  * tag. Mirrors — and supersedes — the two ad-hoc filters that used to live in
321
324
  * `PlayRunDetailPanel.isInternalLogLine` and `formatPlayLogLine`. The patterns
322
- * are the historical `[worker] ...` / `[event] ...` / `[perf] ...` shapes plus
323
- * the checkpoint-replay marker. Order matters: most specific first.
325
+ * are the historical `[worker] ...` / `[event] ...` / `[perf] ...` /
326
+ * `[perf-trace] ...` shapes plus the checkpoint-replay marker. Order matters:
327
+ * most specific first.
324
328
  *
325
329
  * A legacy line the classifier can't place defaults to `user` — old runs
326
330
  * predate structural tagging, and the safe default for an unrecognized line is
@@ -341,6 +345,7 @@ export function classifyLegacyLogLine(line: string): LogProvenance {
341
345
 
342
346
  // Scheduler / sandbox / worker internals.
343
347
  if (
348
+ /^\[perf-trace\]/i.test(message) ||
344
349
  /^\[perf\]/i.test(message) ||
345
350
  /^\[runtime\.(?:phase_summary|logs|log_transport)\]/i.test(message) ||
346
351
  /\[worker\] picked up run\b/.test(message) ||
@@ -43,6 +43,7 @@ export function createSandboxCleanupJob(
43
43
  input,
44
44
  deletion.detail,
45
45
  confirmationReadDelay(input.resource.failureCount + 1),
46
+ { code: deletion.code },
46
47
  );
47
48
  }
48
49
  if (deletion.kind === 'failed') {
@@ -129,11 +130,13 @@ async function scheduleRetry(
129
130
  input: SandboxCleanupInput,
130
131
  error: string,
131
132
  retryAfterMs = retryDelay(input.resource.failureCount + 1),
133
+ confirmationPending?: { code: string },
132
134
  ): Promise<SandboxCleanupOutcome> {
133
135
  const scheduled = await ports.store.retry({
134
136
  resource: input.resource,
135
137
  error,
136
138
  retryAfterMs,
139
+ ...(confirmationPending ? { confirmationPending } : {}),
137
140
  });
138
141
  return scheduled === 'retry_scheduled'
139
142
  ? { kind: 'retry_scheduled', retryAfterMs }
@@ -29,6 +29,8 @@ export type SandboxCleanupStore = {
29
29
  resource: SandboxCleanupResource;
30
30
  error: string;
31
31
  retryAfterMs: number;
32
+ /** The provider is still confirming deletion, rather than reporting failure. */
33
+ confirmationPending?: { code: string };
32
34
  }): Promise<'retry_scheduled' | 'rejected'>;
33
35
  block(input: {
34
36
  resource: SandboxCleanupResource;
@@ -61,7 +61,7 @@ export function createPostgresSandboxCleanupStore(
61
61
  ),
62
62
  );
63
63
  },
64
- async retry({ resource, error, retryAfterMs }) {
64
+ async retry({ resource, error, retryAfterMs, confirmationPending }) {
65
65
  const outcome = await input.runWithClient(
66
66
  async (client) =>
67
67
  await retryPostgresSchedulerSandboxCleanupJob(
@@ -74,6 +74,7 @@ export function createPostgresSandboxCleanupStore(
74
74
  claimGeneration: resource.cleanupAttempt,
75
75
  error,
76
76
  retryAfterMs,
77
+ confirmationPending,
77
78
  },
78
79
  options,
79
80
  ),
@@ -83,7 +83,37 @@ export type PlayRunnerRateStateConcurrencyGrant = {
83
83
  minimumRttMs: number | null;
84
84
  };
85
85
 
86
+ /** Fixed scalar acquisition facts, present only for the scoped synthetic diagnostic. */
87
+ export type PlayRunnerRateStateGovernorSnapshot = {
88
+ previousRefillPerSecond: number;
89
+ previousRateSuccesses: number;
90
+ previousObservationStartedAtMs: number | null;
91
+ previousRecoveryIntervalMs: number;
92
+ previousThrottleCeilingRps: number | null;
93
+ fastRecovery: boolean;
94
+ tokensAfterRefill: number;
95
+ refillPerSecond: number;
96
+ tokens: number;
97
+ rateSuccesses: number;
98
+ observationStartedAtMs: number | null;
99
+ recoveryIntervalMs: number;
100
+ throttleCeilingRps: number | null;
101
+ probeStartedAtMs: number | null;
102
+ probeSuccessesAtRamp: number | null;
103
+ lastRampAtMs: number;
104
+ refilledAtMs: number;
105
+ nextDispatchAtMs: number;
106
+ retryAtMs: number;
107
+ coolUntilMs: number;
108
+ seenBackpressure: boolean;
109
+ activeConcurrency: number | null;
110
+ freeConcurrency: number | null;
111
+ concurrencyLimit: number | null;
112
+ };
113
+
86
114
  export type PlayRunnerRateStateAcquireResult = {
115
+ /** Diagnostic only; absence never changes admission, clocks or retries. */
116
+ governorSnapshot?: PlayRunnerRateStateGovernorSnapshot;
87
117
  granted: number;
88
118
  waitMs: number;
89
119
  /** This receiver serves rate_state_validate. Absent on pre-expansion readers. */