deepline 0.3.546 → 0.3.547

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 (202) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +13 -0
  2. package/dist/bundling-sources/sdk/src/index.ts +7 -1
  3. package/dist/bundling-sources/sdk/src/integrations.ts +17 -7
  4. package/dist/bundling-sources/sdk/src/play.ts +71 -0
  5. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  6. package/dist/bundling-sources/sdk/src/runs/watch-polling.ts +13 -4
  7. package/dist/bundling-sources/sdk/src/types.ts +33 -0
  8. package/dist/bundling-sources/shared_libs/integration-contracts/calendar-delegation.ts +7 -0
  9. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-batch-operation.ts +2 -0
  10. package/dist/bundling-sources/shared_libs/monitors/tracking-provider-guidance.ts +1 -0
  11. package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +19 -1
  12. package/dist/bundling-sources/shared_libs/play-data-plane/r2.ts +17 -2
  13. package/dist/bundling-sources/shared_libs/play-runtime/async-operation.ts +57 -5
  14. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +295 -52
  15. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +10 -1
  16. package/dist/bundling-sources/shared_libs/play-runtime/docflow-decision-tracker.ts +135 -0
  17. package/dist/bundling-sources/shared_libs/play-runtime/docflow-fail-open.ts +177 -0
  18. package/dist/bundling-sources/shared_libs/play-runtime/docflow-node-io.ts +99 -2
  19. package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +16 -10
  20. package/dist/bundling-sources/shared_libs/play-runtime/fenced-call-diagnostics.ts +211 -0
  21. package/dist/bundling-sources/shared_libs/play-runtime/runtime-capacity-policy.ts +52 -14
  22. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +21 -2
  23. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +18 -0
  24. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +68 -0
  25. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +11 -3
  26. package/dist/bundling-sources/shared_libs/play-runtime/tool-cache-policy.ts +9 -1
  27. package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +48 -0
  28. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +6 -1
  29. package/dist/bundling-sources/shared_libs/plays/bundling/index.ts +716 -51
  30. package/dist/bundling-sources/shared_libs/plays/docflow-decision-arms.ts +146 -0
  31. package/dist/bundling-sources/shared_libs/plays/docflow-flow-order.ts +94 -0
  32. package/dist/bundling-sources/shared_libs/plays/docflow-unreached-reason.ts +10 -1
  33. package/dist/bundling-sources/shared_libs/plays/docflow.ts +787 -117
  34. package/dist/bundling-sources/shared_libs/plays/share/static-pipeline-summary.ts +8 -2
  35. package/dist/bundling-sources/shared_libs/plays/static-pipeline.ts +6 -0
  36. package/dist/bundling-sources/shared_libs/plays/trigger-config-contract.ts +13 -0
  37. package/dist/bundling-sources/shared_libs/product-notifications/billing-sales.ts +25 -0
  38. package/dist/bundling-sources/shared_libs/security/secret-redaction.ts +56 -0
  39. package/dist/cli/auth-AC5277PI.js +43 -0
  40. package/dist/cli/{auth-KFWG72AZ.mjs → auth-WJEY4IDX.mjs} +5 -5
  41. package/dist/cli/{billing-OQVOAZ4S.js → billing-IJITDDRQ.js} +96 -96
  42. package/dist/cli/{billing-MMZ336HO.mjs → billing-PHJUDYF3.mjs} +10 -10
  43. package/dist/cli/{chunk-TBWYZOSV.js → chunk-2AHY47SI.js} +3 -3
  44. package/dist/cli/{chunk-MXQP7CXZ.js → chunk-2HPTLBNB.js} +3 -3
  45. package/dist/cli/{chunk-TI6DTURF.js → chunk-4WAM6TLD.js} +7 -1
  46. package/dist/cli/{chunk-JARZ47OP.mjs → chunk-56MEAGWA.mjs} +2 -2
  47. package/dist/cli/{chunk-GYTSDSQD.mjs → chunk-5SFHPMBY.mjs} +11 -11
  48. package/dist/cli/{chunk-Z3UEBFIN.js → chunk-ABLTVG3J.js} +41 -41
  49. package/dist/cli/{chunk-LX2TC3HO.mjs → chunk-AEQ5VWZ5.mjs} +4 -4
  50. package/dist/cli/{chunk-MI7X6V6V.mjs → chunk-CKIRKYW7.mjs} +3 -3
  51. package/dist/cli/{chunk-2JHYYB3F.js → chunk-CSPHSNBW.js} +3 -3
  52. package/dist/cli/{chunk-IVWU7SJC.js → chunk-D6OIEH47.js} +5 -5
  53. package/dist/cli/{chunk-KUK7ARXA.mjs → chunk-DIUNDLSX.mjs} +2 -2
  54. package/dist/cli/{chunk-RO66FPTS.mjs → chunk-DJI5CLLW.mjs} +1 -1
  55. package/dist/cli/{chunk-LIJKRDDG.js → chunk-DZC7LMYM.js} +6 -6
  56. package/dist/cli/{chunk-UQJBV5PM.js → chunk-E2OIYPB4.js} +10 -10
  57. package/dist/cli/{chunk-JA633HRV.mjs → chunk-ECUD4QPD.mjs} +3 -3
  58. package/dist/cli/{chunk-VPERQ3U6.mjs → chunk-ESCVHDNY.mjs} +5 -5
  59. package/dist/cli/{chunk-JVOUQFHT.js → chunk-FFBXLFKV.js} +1 -1
  60. package/dist/cli/{chunk-3DUNNZB6.mjs → chunk-FMQXAOVE.mjs} +4 -4
  61. package/dist/cli/{chunk-HXIR3VQL.mjs → chunk-FZHMNK6F.mjs} +7 -1
  62. package/dist/cli/{chunk-PU3ZAG6V.mjs → chunk-G6KW764N.mjs} +1 -1
  63. package/dist/cli/{chunk-EEG46QZY.mjs → chunk-G6XTCG3J.mjs} +2 -2
  64. package/dist/cli/{chunk-EEJHB76U.js → chunk-GIGAYLY6.js} +12 -12
  65. package/dist/cli/{chunk-BLYW6FFB.js → chunk-GJA2PRHJ.js} +2 -2
  66. package/dist/cli/{chunk-H7Q5IDO3.js → chunk-GJOGFWX3.js} +20 -20
  67. package/dist/cli/{chunk-6Y5TU3R7.mjs → chunk-GPAWLXW3.mjs} +1 -1
  68. package/dist/cli/{chunk-5W4ENHWM.js → chunk-GZFZZQL4.js} +285 -264
  69. package/dist/cli/{chunk-P7A3H6G5.mjs → chunk-HARZ4AAX.mjs} +1 -1
  70. package/dist/cli/{chunk-MEGHIX4M.js → chunk-HFIFKP3A.js} +5 -5
  71. package/dist/cli/{chunk-LHE2TSV6.mjs → chunk-IGAK22XO.mjs} +1 -1
  72. package/dist/cli/{chunk-VTK3HGMN.mjs → chunk-IKYN6PLO.mjs} +5 -5
  73. package/dist/cli/{chunk-UREAIHUU.mjs → chunk-ITLZBDSR.mjs} +3 -3
  74. package/dist/cli/{chunk-6LG7MLJ2.js → chunk-IVFFCAV2.js} +44 -44
  75. package/dist/cli/{chunk-SYTWWVIQ.js → chunk-K3GMDSUX.js} +5 -5
  76. package/dist/cli/{chunk-WKHPLBJK.js → chunk-L5J6UJ2X.js} +15 -15
  77. package/dist/cli/{chunk-X5KOHDJN.mjs → chunk-L6QE2XVM.mjs} +1 -1
  78. package/dist/cli/{chunk-SH32HL7I.js → chunk-LMLSOHTU.js} +53 -53
  79. package/dist/cli/{chunk-JCWNF44W.js → chunk-MBQELFL7.js} +22 -22
  80. package/dist/cli/{chunk-Z7SXGOIQ.mjs → chunk-MF7PCM6C.mjs} +1 -1
  81. package/dist/cli/{chunk-F2VEFMU5.js → chunk-MO7TGNXB.js} +13 -13
  82. package/dist/cli/{chunk-7ZW67ME6.mjs → chunk-MOZEAGSR.mjs} +1 -1
  83. package/dist/cli/{chunk-5VNQMVCU.js → chunk-N63U5CRG.js} +26 -26
  84. package/dist/cli/{chunk-JCH4UNNS.js → chunk-NBYFQZ6O.js} +2 -2
  85. package/dist/cli/{chunk-BTFUAGHC.js → chunk-OVYXYTEP.js} +16 -16
  86. package/dist/cli/{chunk-J65HJCJO.mjs → chunk-PBMO36BP.mjs} +2 -2
  87. package/dist/cli/{chunk-F5YQXCP3.js → chunk-PVQCX6KQ.js} +50 -7
  88. package/dist/cli/{chunk-K2XELBPF.mjs → chunk-QLE3QKJ2.mjs} +5 -5
  89. package/dist/cli/{chunk-VAT2SXFF.js → chunk-QU3K3IY6.js} +12 -12
  90. package/dist/cli/{chunk-JYG4XZLT.js → chunk-REAFIEV5.js} +99 -99
  91. package/dist/cli/{chunk-5OEFXAKP.mjs → chunk-RMCCB3XY.mjs} +50 -7
  92. package/dist/cli/{chunk-HJR2DDJS.mjs → chunk-RXRC2COC.mjs} +2 -2
  93. package/dist/cli/{chunk-4AZLGNXV.js → chunk-SAJWYN4B.js} +4 -4
  94. package/dist/cli/{chunk-VXTTAYOT.mjs → chunk-TNJG4ZPN.mjs} +3 -3
  95. package/dist/cli/{chunk-PMDHY2YK.js → chunk-VNOQEDVC.js} +7 -7
  96. package/dist/cli/{chunk-GOOF7E2B.mjs → chunk-VPF54TXQ.mjs} +5 -5
  97. package/dist/cli/{chunk-2HSZCQMT.mjs → chunk-WYT3H6JD.mjs} +1 -1
  98. package/dist/cli/{chunk-OAKWSLKS.mjs → chunk-XMBVHJPR.mjs} +28 -7
  99. package/dist/cli/{chunk-7MY7KWJS.mjs → chunk-XNTDTAKC.mjs} +1 -1
  100. package/dist/cli/{chunk-5V7NZKGG.js → chunk-YURGAKI3.js} +2 -2
  101. package/dist/cli/{chunk-ND7SFRQL.js → chunk-YVKLF7RW.js} +2 -2
  102. package/dist/cli/{chunk-6FBDTYR2.mjs → chunk-Z2YGQZWV.mjs} +2 -2
  103. package/dist/cli/command-docs.js +2 -2
  104. package/dist/cli/command-docs.mjs +1 -1
  105. package/dist/cli/{concurrent-runs-help-C2O5YKQA.mjs → concurrent-runs-help-ZNGP563R.mjs} +6 -6
  106. package/dist/cli/concurrent-runs-help-ZYISYOQA.js +21 -0
  107. package/dist/cli/{csv-Z4DNGR54.mjs → csv-VAHQHYYV.mjs} +4 -4
  108. package/dist/cli/{csv-MJDNOIQJ.js → csv-X6D4ZELE.js} +13 -13
  109. package/dist/cli/{db-4RL2BNOF.mjs → db-4G4S2VOV.mjs} +7 -7
  110. package/dist/cli/{db-S5QVPK5E.js → db-YA5ZGVEX.js} +28 -28
  111. package/dist/cli/{describe-L4P5SZLQ.mjs → describe-EVXEM2S6.mjs} +19 -19
  112. package/dist/cli/describe-GYYSLZLV.js +50 -0
  113. package/dist/cli/describe-core.d.mts +4 -4
  114. package/dist/cli/describe-core.d.ts +4 -4
  115. package/dist/cli/{executions-MFZ2Z36O.js → executions-5YC7ABF6.js} +9 -9
  116. package/dist/cli/{executions-RR6O3XK5.mjs → executions-HR6CTN5M.mjs} +7 -7
  117. package/dist/cli/{feedback-EQBQ3ABB.mjs → feedback-GEU5SPLR.mjs} +6 -6
  118. package/dist/cli/{feedback-YDAG7VH2.js → feedback-MJHSYLFF.js} +14 -14
  119. package/dist/cli/git-FZIQZNI4.js +25 -0
  120. package/dist/cli/{git-YGLCCU35.mjs → git-NPFF6QUS.mjs} +5 -5
  121. package/dist/cli/index.js +146 -146
  122. package/dist/cli/index.mjs +45 -45
  123. package/dist/cli/{integrations-IQXYMRMW.js → integrations-YPHFI77G.js} +19 -17
  124. package/dist/cli/{integrations-FWYXSBHK.mjs → integrations-Z7EGVBHF.mjs} +11 -9
  125. package/dist/cli/{legacy-noops-U7LI7UXC.js → legacy-noops-246E3KKG.js} +9 -9
  126. package/dist/cli/{legacy-noops-I4YRIX5F.mjs → legacy-noops-5IYCFWWX.mjs} +6 -6
  127. package/dist/cli/{mcp-QJBMB6VS.mjs → mcp-WUYGZXPI.mjs} +4 -4
  128. package/dist/cli/{mcp-GX2UKKWU.js → mcp-YTYTW67G.js} +24 -24
  129. package/dist/cli/{monitors-Z6EGKYJP.mjs → monitors-73DQKCU7.mjs} +26 -8
  130. package/dist/cli/{monitors-WCJYINGX.js → monitors-SA6ILD6Z.js} +119 -101
  131. package/dist/cli/{org-NNHICBR2.mjs → org-WVQRB2KX.mjs} +7 -7
  132. package/dist/cli/{org-7SKG423N.js → org-X7ELDV7B.js} +89 -89
  133. package/dist/cli/{play-CXDFPJ7Z.mjs → play-QI6V2EUQ.mjs} +295 -67
  134. package/dist/cli/{play-4P4DTG3Q.js → play-QTYOAJPE.js} +897 -669
  135. package/dist/cli/{providers-VQLQ7DTR.mjs → providers-DPVMVDS4.mjs} +7 -7
  136. package/dist/cli/{providers-EE4TUE3O.js → providers-XXFLVREV.js} +10 -10
  137. package/dist/cli/{quickstart-RVXHK4WA.js → quickstart-33ISXQJU.js} +6 -6
  138. package/dist/cli/{quickstart-IYNJRB5G.mjs → quickstart-YWGNHULM.mjs} +4 -4
  139. package/dist/cli/{run-R3F34KU3.js → run-BWHZXLTD.js} +45 -45
  140. package/dist/cli/{run-VBQPPMEX.mjs → run-J6FCAKQC.mjs} +25 -25
  141. package/dist/cli/search-JCWJX2XD.js +32 -0
  142. package/dist/cli/{search-B7R62HX5.mjs → search-Z3UU3WBB.mjs} +8 -8
  143. package/dist/cli/{search-output-LNQQXIGZ.mjs → search-output-OJYY4J7E.mjs} +4 -4
  144. package/dist/cli/{search-output-LWHWEPOT.js → search-output-YIPV74ME.js} +6 -6
  145. package/dist/cli/{secrets-QBOZ7WTD.js → secrets-UXRJCEN4.js} +16 -16
  146. package/dist/cli/{secrets-NM3VAJLO.mjs → secrets-YZZN2WST.mjs} +7 -7
  147. package/dist/cli/{sessions-R5BSIJ4I.mjs → sessions-ITCGPD7Z.mjs} +6 -6
  148. package/dist/cli/sessions-NA4SJH6Q.js +22 -0
  149. package/dist/cli/{settings-POYWKNRD.js → settings-LAFYMILP.js} +86 -86
  150. package/dist/cli/{settings-S4PN7WLY.mjs → settings-ZP2LSVNM.mjs} +13 -13
  151. package/dist/cli/{setup-VHB4Z654.js → setup-4AL3XYM5.js} +49 -49
  152. package/dist/cli/{setup-PFLXVBTL.mjs → setup-WEQAQSYC.mjs} +9 -9
  153. package/dist/cli/{skills-W2TELEU7.mjs → skills-NQH4HFW2.mjs} +7 -7
  154. package/dist/cli/skills-XZ4Y6SZ7.js +36 -0
  155. package/dist/cli/{tools-M4FA6N3Y.mjs → tools-CXK2GSI4.mjs} +18 -18
  156. package/dist/cli/tools-WJQ6Y7E4.js +57 -0
  157. package/dist/cli/{update-W7LIHEA7.mjs → update-3ROF3Z75.mjs} +9 -9
  158. package/dist/cli/update-ZLRLTBRD.js +34 -0
  159. package/dist/cli/{views-KTVPV6UP.mjs → views-AOUHVGV2.mjs} +7 -7
  160. package/dist/cli/{views-DJXAGD7V.js → views-XJFO5CEH.js} +22 -22
  161. package/dist/cli/{workflow-NVZDJKH2.js → workflow-GY3DBHXX.js} +18 -18
  162. package/dist/cli/{workflow-LGKCRODX.mjs → workflow-KBS2QJK6.mjs} +8 -8
  163. package/dist/{client-Tp1LSULB.d.mts → client-D1uWA2Vc.d.mts} +1 -1
  164. package/dist/{client-CCyWJqAI.d.ts → client-Hz7SsBXs.d.ts} +1 -1
  165. package/dist/{client-core-BpYiYEfu.d.ts → client-core-D3Ad7Flt.d.ts} +554 -504
  166. package/dist/{client-core-D8eCZz3O.d.mts → client-core-Db_e63Hb.d.mts} +554 -504
  167. package/dist/{compiler-manifest-EBWEUj0b.d.ts → compiler-manifest-BqwVrOri.d.mts} +38 -18
  168. package/dist/{compiler-manifest-EBWEUj0b.d.mts → compiler-manifest-BqwVrOri.d.ts} +38 -18
  169. package/dist/{errors-CParKUQR.d.mts → errors-BU8FB99X.d.mts} +1 -1
  170. package/dist/{errors-Qt0OTA7_.d.ts → errors-DfVN_FUG.d.ts} +1 -1
  171. package/dist/{index-CoqDkIw0.d.ts → index-BGnvtYGc.d.ts} +6 -1
  172. package/dist/{index-BMUVCNp7.d.mts → index-DjZgwpGw.d.mts} +6 -1
  173. package/dist/index.d.mts +28 -8
  174. package/dist/index.d.ts +28 -8
  175. package/dist/index.js +64 -39
  176. package/dist/index.mjs +32 -7
  177. package/dist/install-integrity.json +133 -128
  178. package/dist/plays/bundle-play-file.d.mts +3 -3
  179. package/dist/plays/bundle-play-file.d.ts +3 -3
  180. package/dist/plays/bundle-play-file.mjs +620 -124
  181. package/dist/plays/play-description.d.mts +3 -3
  182. package/dist/plays/play-description.d.ts +3 -3
  183. package/dist/plays/run-request.d.mts +2 -2
  184. package/dist/plays/run-request.d.ts +2 -2
  185. package/dist/release.d.mts +1 -1
  186. package/dist/release.d.ts +1 -1
  187. package/dist/release.js +2 -2
  188. package/dist/release.mjs +1 -1
  189. package/dist/server.d.mts +4 -4
  190. package/dist/server.d.ts +4 -4
  191. package/dist/server.js +6 -6
  192. package/dist/server.mjs +4 -4
  193. package/package.json +1 -1
  194. package/dist/cli/auth-W32GMYND.js +0 -43
  195. package/dist/cli/concurrent-runs-help-6QT7ZR4W.js +0 -21
  196. package/dist/cli/describe-VLU2LUDJ.js +0 -50
  197. package/dist/cli/git-E6W44F5M.js +0 -25
  198. package/dist/cli/search-UUVFXZRA.js +0 -32
  199. package/dist/cli/sessions-K3PD73Q2.js +0 -22
  200. package/dist/cli/skills-QNE2EYT3.js +0 -36
  201. package/dist/cli/tools-3RLI4HGF.js +0 -57
  202. package/dist/cli/update-UT6KIW2W.js +0 -34
@@ -1,4 +1,8 @@
1
1
  import { DURABLE_RUNS_ROLLOUT } from './durable-runs-rollout';
2
+ import {
3
+ createFencedCallDiagnosticsBudget,
4
+ startFencedCallDiagnostics,
5
+ } from './fenced-call-diagnostics';
2
6
  import { RuntimeSheetAdmissionRequestTooLargeError } from './runtime-sheet-errors';
3
7
  import {
4
8
  DatasetRowInputView,
@@ -234,6 +238,7 @@ import {
234
238
  projectToolResultListGetters,
235
239
  parseToolExecuteResponse,
236
240
  isToolExecuteResult,
241
+ docflowToolResultPreviewProjection,
237
242
  isSerializedToolExecuteResult,
238
243
  relayPublishedToolResultReference,
239
244
  serializeToolExecuteResult,
@@ -521,9 +526,21 @@ import {
521
526
  import {
522
527
  buildPlayDocflowNodeErrorPreview,
523
528
  buildPlayDocflowNodeInputPreviewMap,
529
+ isDocflowInvocationObserved,
524
530
  type PlayDocflowNodeInputCapture,
525
531
  } from './docflow-node-io';
526
532
  import type { DocflowObservationUpsert } from './docflow-observation';
533
+ import {
534
+ boundedText,
535
+ DocflowDecisionTracker,
536
+ } from './docflow-decision-tracker';
537
+ import {
538
+ DocflowTrackingFaultCounter,
539
+ guardDocflowTracking,
540
+ runDocflowObservationFailOpen,
541
+ type DocflowObservationSettlement,
542
+ type DocflowTrackingFaultStage,
543
+ } from './docflow-fail-open';
527
544
  import {
528
545
  assertNoSecretTaint,
529
546
  assertSecretAuthUsesTls,
@@ -3234,6 +3251,9 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
3234
3251
  private processedRowCount = 0;
3235
3252
  /** New retained-result consumers in this runner invocation; recovery is excluded. */
3236
3253
  private reusableResultCalls = 0;
3254
+ /** Bounds fenced-call platform diagnostics for this run attempt. */
3255
+ private readonly fencedCallDiagnosticsBudget =
3256
+ createFencedCallDiagnosticsBudget();
3237
3257
  private reuseCountSupported = true;
3238
3258
  /**
3239
3259
  * Sleep call positions are scoped per mapped row. A single global counter is
@@ -3244,6 +3264,20 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
3244
3264
  private sleepBoundaryIndex = 0;
3245
3265
  private readonly activeInlineInvocations = new Set<symbol>();
3246
3266
  private nextDocflowInvocationSequence = 0;
3267
+ /** Invocations of each box this attempt (`attempt:nodeId`), for sampling. */
3268
+ private readonly docflowInvocationCounts = new Map<string, number>();
3269
+ /**
3270
+ * @internal Declares that `__deeplineObserveDocflowNode` honours
3271
+ * `origin: 'helper'` (declines per-row helper observations and samples
3272
+ * repeated ones). The SDK routes helper-module boxes only to a runtime that
3273
+ * declares it, so a newer artifact on an older runtime observes nothing
3274
+ * there rather than one observation per dataset row.
3275
+ */
3276
+ readonly __deeplineDocflowHelperObservation = true;
3277
+ /** Decision boxes awaiting the arm the run takes (see the tracker). */
3278
+ private readonly docflowDecisions = new DocflowDecisionTracker<
3279
+ Extract<PlayExecutionEvent, { type: 'docflow.node.completed' }>
3280
+ >();
3247
3281
  /**
3248
3282
  * Whether this run captures the docflow trace at all (ADR 0019), decided at
3249
3283
  * admission and handed down through the signed runtime authority.
@@ -4051,38 +4085,119 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
4051
4085
  );
4052
4086
  }
4053
4087
 
4054
- /** @internal Compiler-injected authored-flow execution marker. */
4055
- async __deeplineDocflowHit(nodeId: string): Promise<void> {
4056
- const normalizedNodeId = nodeId.trim();
4057
- if (!normalizedNodeId) {
4058
- throw new Error('Docflow runtime node id must be non-empty.');
4088
+ /**
4089
+ * Bounded internal reporting for docflow tracking faults. Tracking is
4090
+ * display-only (`docflow-fail-open.ts`): a fault is counted and written to
4091
+ * the runner's stderr (forwarded by the runtime log shipper), never to the
4092
+ * customer's run log, and never thrown into the Play.
4093
+ */
4094
+ private readonly docflowTrackingFaults = new DocflowTrackingFaultCounter(
4095
+ (line) => console.warn(line),
4096
+ () => ({
4097
+ run_id: this.currentRunId,
4098
+ play_name: this.#options.playName ?? null,
4099
+ }),
4100
+ );
4101
+
4102
+ private reportDocflowTrackingFault(
4103
+ stage: DocflowTrackingFaultStage,
4104
+ nodeId: unknown,
4105
+ error: unknown,
4106
+ ): void {
4107
+ try {
4108
+ this.docflowTrackingFaults.record(stage, nodeId, error);
4109
+ } catch {
4110
+ // Reporting is best-effort as well.
4059
4111
  }
4060
- // These calls are COMPILER-INJECTED, so bundle-time gating cannot reach
4061
- // them: a prebuilt is compiled once, with its diagram, and then runs for
4062
- // every org. Without this check an ungated customer running a prebuilt gets
4063
- // `docflow.node.*` events on the wire and a `step docflow:*` sequence in
4064
- // `plays run --watch` — the vocabulary of a feature they do not have.
4065
- // The id is still validated above: a malformed injection is a compiler bug
4066
- // and stays loud whether or not the run is capturing.
4067
- if (!this.docflowCaptureEnabled) return;
4068
- this.emitExecutionEvent({
4069
- type: 'docflow.node.hit',
4070
- nodeId: `docflow:${normalizedNodeId}`,
4071
- at: Date.now(),
4072
- });
4073
4112
  }
4074
4113
 
4075
- /** @internal Compiler-injected bounded authored-node observation boundary. */
4114
+ /**
4115
+ * @internal Compiler-injected authored-flow execution marker.
4116
+ *
4117
+ * Never rejects: older artifacts `await` it inline in the Play body, so a
4118
+ * rejection here would fail the run over a display-only marker.
4119
+ */
4120
+ async __deeplineDocflowHit(nodeId: string): Promise<void> {
4121
+ guardDocflowTracking(
4122
+ 'hit',
4123
+ (stage, error) => this.reportDocflowTrackingFault(stage, nodeId, error),
4124
+ () => {
4125
+ const normalizedNodeId = nodeId.trim();
4126
+ if (!normalizedNodeId) {
4127
+ // A malformed injection is a compiler bug: reported as a fault,
4128
+ // never thrown into the Play.
4129
+ throw new Error('Docflow runtime node id must be non-empty.');
4130
+ }
4131
+ // These calls are COMPILER-INJECTED, so bundle-time gating cannot
4132
+ // reach them: a prebuilt is compiled once, with its diagram, and then
4133
+ // runs for every org. Without this check an ungated customer running a
4134
+ // prebuilt gets `docflow.node.*` events on the wire and a
4135
+ // `step docflow:*` sequence in `plays run --watch` — the vocabulary of
4136
+ // a feature they do not have.
4137
+ if (!this.docflowCaptureEnabled) return;
4138
+ this.recordDocflowDecisionArmsSafely(normalizedNodeId);
4139
+ this.emitExecutionEvent({
4140
+ type: 'docflow.node.hit',
4141
+ nodeId: `docflow:${normalizedNodeId}`,
4142
+ at: Date.now(),
4143
+ });
4144
+ },
4145
+ );
4146
+ }
4147
+
4148
+ /**
4149
+ * @internal Compiler-injected bounded authored-node observation boundary.
4150
+ *
4151
+ * Fail-open by construction (`runDocflowObservationFailOpen`): `execute`
4152
+ * runs exactly once and its value or throw reaches the Play unchanged,
4153
+ * whatever any capture, preview, emit, or decision stage does.
4154
+ */
4076
4155
  __deeplineObserveDocflowNode<T>(
4077
4156
  nodeId: string,
4078
4157
  inputCaptures: readonly PlayDocflowNodeInputCapture[],
4079
4158
  outputPaths: readonly string[],
4080
4159
  execute: () => T | Promise<T>,
4160
+ /**
4161
+ * Optional, absent from every artifact bundled before helper-module
4162
+ * observation: `origin: 'helper'` marks a box bound inside an imported
4163
+ * helper, reached through the SDK's run-context store.
4164
+ */
4165
+ options?: { origin?: 'helper' },
4081
4166
  ): T | Promise<T> {
4167
+ return runDocflowObservationFailOpen(
4168
+ execute,
4169
+ () =>
4170
+ this.beginDocflowObservation<T>(
4171
+ nodeId,
4172
+ inputCaptures,
4173
+ outputPaths,
4174
+ options,
4175
+ ),
4176
+ (stage, error) => this.reportDocflowTrackingFault(stage, nodeId, error),
4177
+ );
4178
+ }
4179
+
4180
+ /**
4181
+ * Captures inputs and emits `started`; returns how to settle the
4182
+ * observation, or null when this invocation is not tracked. Any throw is a
4183
+ * tracking fault: the caller still runs the statement, untracked.
4184
+ */
4185
+ private beginDocflowObservation<T>(
4186
+ nodeId: string,
4187
+ inputCaptures: readonly PlayDocflowNodeInputCapture[],
4188
+ outputPaths: readonly string[],
4189
+ options: { origin?: 'helper' } | undefined,
4190
+ ): DocflowObservationSettlement<T> | null {
4082
4191
  const normalizedNodeId = nodeId.trim();
4083
4192
  if (!normalizedNodeId) {
4084
4193
  throw new Error('Docflow runtime node id must be non-empty.');
4085
4194
  }
4195
+ // A helper can be called from a dataset's per-row resolver. Maps observe at
4196
+ // the node level, not per row (ADR 0016): per-row truth already lives in
4197
+ // the sheet, and an observation per row per box would grow with the input.
4198
+ if (options?.origin === 'helper' && rowContext.getStore()) {
4199
+ return null;
4200
+ }
4086
4201
  // Ungated, this boundary is a pass-through: the wrapped work still runs and
4087
4202
  // still returns what it returned, but nothing is previewed, redacted, or
4088
4203
  // emitted. Returning before `buildPlayDocflowNodeInputPreviewMap` is the
@@ -4090,17 +4205,25 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
4090
4205
  // customer outside the rollout should not pay for a capture they cannot
4091
4206
  // read. Same reasoning as `__deeplineDocflowHit` above: injected at compile
4092
4207
  // time, so the run is the only place left to decide.
4093
- if (!this.docflowCaptureEnabled) return execute();
4208
+ if (!this.docflowCaptureEnabled) return null;
4094
4209
  // Inline composition changes logical identity, but its gateway token and
4095
4210
  // durable observations remain owned by the executing receipt scope.
4096
4211
  const runId = this.currentReceiptOwnerRunId;
4097
4212
  const attempt = this.currentRunAttempt;
4213
+ // A box in a loop is invoked once per item: observe a bounded sample so the
4214
+ // durable writes per box stay O(log n) in the items processed.
4215
+ const invocationKey = `${attempt}:${normalizedNodeId}`;
4216
+ const ordinal = (this.docflowInvocationCounts.get(invocationKey) ?? 0) + 1;
4217
+ this.docflowInvocationCounts.set(invocationKey, ordinal);
4218
+ if (!isDocflowInvocationObserved(ordinal)) return null;
4098
4219
  const inputs = buildPlayDocflowNodeInputPreviewMap(inputCaptures, {
4099
4220
  redactor: this.secretRedactor,
4221
+ projectRoot: docflowToolResultPreviewProjection,
4100
4222
  });
4101
4223
  const invocationSeq = this.nextDocflowInvocationSequence++;
4102
4224
  const invocationId = `${attempt}:${invocationSeq}`;
4103
4225
  const observationNodeId = `docflow:${normalizedNodeId}`;
4226
+ this.recordDocflowDecisionArmsSafely(normalizedNodeId);
4104
4227
  this.emitExecutionEvent({
4105
4228
  type: 'docflow.node.started',
4106
4229
  nodeId: observationNodeId,
@@ -4143,9 +4266,15 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
4143
4266
  ? path.split('.')
4144
4267
  : path.split('.').slice(1),
4145
4268
  })),
4146
- { redactor: this.secretRedactor },
4269
+ {
4270
+ redactor: this.secretRedactor,
4271
+ projectRoot: docflowToolResultPreviewProjection,
4272
+ },
4147
4273
  );
4148
- this.emitExecutionEvent({
4274
+ const completed: Extract<
4275
+ PlayExecutionEvent,
4276
+ { type: 'docflow.node.completed' }
4277
+ > = {
4149
4278
  type: 'docflow.node.completed',
4150
4279
  nodeId: observationNodeId,
4151
4280
  attempt,
@@ -4155,7 +4284,19 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
4155
4284
  outputs: outputs.values,
4156
4285
  ...(outputs.truncated ? { outputsTruncated: true } : {}),
4157
4286
  at: Date.now(),
4158
- });
4287
+ };
4288
+ this.emitExecutionEvent(completed);
4289
+ guardDocflowTracking(
4290
+ 'decision',
4291
+ (stage, error) =>
4292
+ this.reportDocflowTrackingFault(stage, normalizedNodeId, error),
4293
+ () => {
4294
+ const docflow = this.currentStaticPipeline?.docflow;
4295
+ if (docflow && !rowContext.getStore()) {
4296
+ this.docflowDecisions.settle(docflow, normalizedNodeId, completed);
4297
+ }
4298
+ },
4299
+ );
4159
4300
  this.emitDocflowObservation({
4160
4301
  runId,
4161
4302
  attempt,
@@ -4201,18 +4342,73 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
4201
4342
  at: Date.now(),
4202
4343
  });
4203
4344
  };
4345
+ return { complete, fail };
4346
+ }
4204
4347
 
4205
- try {
4206
- const result = execute();
4207
- if (result instanceof Promise) {
4208
- void result.then(complete, fail);
4209
- return result;
4210
- }
4211
- complete(result);
4212
- return result;
4213
- } catch (error) {
4214
- fail(error);
4215
- throw error;
4348
+ /** Decision-arm recording is display-only: a fault never skips the node. */
4349
+ private recordDocflowDecisionArmsSafely(reachedNodeId: string): void {
4350
+ guardDocflowTracking(
4351
+ 'decision',
4352
+ (stage, error) =>
4353
+ this.reportDocflowTrackingFault(stage, reachedNodeId, error),
4354
+ () => this.recordDocflowDecisionArms(reachedNodeId),
4355
+ );
4356
+ }
4357
+
4358
+ /**
4359
+ * A bound box was reached: record the arm of every settled decision it names
4360
+ * (`DocflowDecisionTracker`). Two records, both runtime-owned:
4361
+ *
4362
+ * - the decision's completion is re-emitted with optional `decision`, which
4363
+ * folds into its node state (`nodeIo.decision`) so a canvas reads the arm
4364
+ * without another query;
4365
+ * - a run log line carrying the node id, arm, target and invocation as
4366
+ * structured context, which lands in the run's event stream and is
4367
+ * searchable by `$.context.docflowNode`. Once per arm per attempt, so a
4368
+ * loop re-deciding thousands of times cannot exhaust the log budget; its
4369
+ * counts live in the node state.
4370
+ *
4371
+ * Per-row decisions are not tracked here: a `runIf` records each row's arm in
4372
+ * the row's cell trace, counted into `conditionCounts`.
4373
+ */
4374
+ private recordDocflowDecisionArms(reachedNodeId: string): void {
4375
+ const docflow = this.currentStaticPipeline?.docflow;
4376
+ if (!docflow || rowContext.getStore()) return;
4377
+ for (const resolved of this.docflowDecisions.reach(
4378
+ docflow,
4379
+ reachedNodeId,
4380
+ )) {
4381
+ this.emitExecutionEvent({
4382
+ ...resolved.settled,
4383
+ decision: resolved.decision,
4384
+ });
4385
+ if (!resolved.firstForArm) continue;
4386
+ const node = docflow.nodes.find(
4387
+ (candidate) => candidate.id === resolved.decisionId,
4388
+ );
4389
+ const value = Object.values(resolved.settled.outputs)[0];
4390
+ const valuePreview =
4391
+ value?.kind === 'scalar'
4392
+ ? String(value.value)
4393
+ : value?.kind === 'null'
4394
+ ? 'null'
4395
+ : null;
4396
+ const context: Record<string, string> = {
4397
+ docflowNode: boundedText(resolved.decisionId),
4398
+ docflowArm: resolved.decision.arm,
4399
+ docflowArmTarget: resolved.decision.to,
4400
+ docflowInvocation: boundedText(resolved.settled.invocationId),
4401
+ ...(valuePreview !== null
4402
+ ? { docflowValue: boundedText(valuePreview) }
4403
+ : {}),
4404
+ };
4405
+ const message = `Decision ${JSON.stringify(node?.label ?? resolved.decisionId)}: ${resolved.decision.arm}`;
4406
+ assertNoSecretTaint(message, 'runtime log');
4407
+ this.appendRunLog(
4408
+ `[${new Date().toISOString()}] ${this.secretRedactor.redactRegisteredSecrets(boundRunLogLine(message))}`,
4409
+ false,
4410
+ normalizePlayLogContext(this.secretRedactor.redact(context)),
4411
+ );
4216
4412
  }
4217
4413
  }
4218
4414
 
@@ -7990,6 +8186,26 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
7990
8186
  await this.#options.getToolActionCacheVersion?.(input.dispatchToolId)
7991
8187
  )?.trim() ?? '';
7992
8188
  const alwaysFresh = !input.apiOptions.durableCallReceiptKey;
8189
+ // Diagnostics only (no behavior): an execution-fenced call reports when
8190
+ // its relay response arrives, when its receipt completion settles, and
8191
+ // when that completion is overdue, to the runner's internal stderr
8192
+ // telemetry (never the run log). Receipt key as a digest, never raw.
8193
+ const fencedDiagnostics =
8194
+ input.request.requiresExecutionFence === true
8195
+ ? startFencedCallDiagnostics({
8196
+ tool: input.dispatchToolId,
8197
+ callKeyHash: runtimeReceiptKeyDigest(
8198
+ input.resultReceiptKey ?? input.request.callId,
8199
+ ),
8200
+ attempt: this.currentRunAttempt,
8201
+ receiptWriter: alwaysFresh
8202
+ ? 'none'
8203
+ : input.resultReceipts
8204
+ ? 'call'
8205
+ : 'map',
8206
+ budget: this.fencedCallDiagnosticsBudget,
8207
+ })
8208
+ : null;
7993
8209
  const dispatcher = {
7994
8210
  dispatch: async ({
7995
8211
  providerOperationKey,
@@ -8064,7 +8280,18 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
8064
8280
  // the one whose result is delivered.
8065
8281
  onProviderBodyCompleted: (bodyCompletedAtMs) => {
8066
8282
  input.request.providerBodyCompletedAtMs = bodyCompletedAtMs;
8283
+ fencedDiagnostics?.responseArrived();
8067
8284
  },
8285
+ // Runner-local signal, chained: a native batch's own observer
8286
+ // still runs first, and nothing reaches the wire.
8287
+ ...(fencedDiagnostics
8288
+ ? {
8289
+ onProviderDispatched: () => {
8290
+ input.apiOptions.onProviderDispatched?.();
8291
+ fencedDiagnostics.dispatched();
8292
+ },
8293
+ }
8294
+ : {}),
8068
8295
  },
8069
8296
  );
8070
8297
  const wrapped = await this.wrapToolExecutionResult({
@@ -8093,6 +8320,7 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
8093
8320
  // this is the instant the row's result actually exists. Everything
8094
8321
  // after it is receipt publication, not provider work.
8095
8322
  this.observeDeliveryWrap(input.request);
8323
+ fencedDiagnostics?.wrapped();
8096
8324
  return wrapped;
8097
8325
  },
8098
8326
  };
@@ -8127,32 +8355,47 @@ export class PlayContextImpl implements ScalarPlayAuthoringRuntimeContext {
8127
8355
  };
8128
8356
  if (alwaysFresh) {
8129
8357
  try {
8130
- return await createAlwaysFreshToolCallAdapter({ dispatcher }).call(
8131
- call,
8132
- );
8358
+ const result = await createAlwaysFreshToolCallAdapter({
8359
+ dispatcher,
8360
+ }).call(call);
8361
+ fencedDiagnostics?.settled('recorded');
8362
+ return result;
8363
+ } catch (error) {
8364
+ fencedDiagnostics?.settled('failed');
8365
+ throw error;
8133
8366
  } finally {
8134
8367
  this.observeReceiptlessDeliveryPublication(input.request);
8135
8368
  }
8136
8369
  }
8137
8370
  if (!input.resultReceiptKey || !input.providerOperationKey) {
8371
+ fencedDiagnostics?.settled('failed');
8138
8372
  throw new Error('Receipt-backed map Tool Call needs durable identities.');
8139
8373
  }
8140
- return await createToolCallJob({
8141
- resultReceipts:
8142
- input.resultReceipts ??
8143
- createExternallyOwnedToolResultReceipts({
8374
+ try {
8375
+ // With the map's receipt cohort, this resolves only after this call's
8376
+ // receipt write settled; otherwise the map records it afterwards.
8377
+ const result = await createToolCallJob({
8378
+ resultReceipts:
8379
+ input.resultReceipts ??
8380
+ createExternallyOwnedToolResultReceipts({
8381
+ resultReceiptKey: input.resultReceiptKey,
8382
+ ownerRunId: this.currentReceiptOwnerRunId,
8383
+ leaseId: input.request.receiptLeaseId,
8384
+ }),
8385
+ dispatcher,
8386
+ }).call({
8387
+ ...call,
8388
+ compatibility: {
8144
8389
  resultReceiptKey: input.resultReceiptKey,
8145
- ownerRunId: this.currentReceiptOwnerRunId,
8146
- leaseId: input.request.receiptLeaseId,
8147
- }),
8148
- dispatcher,
8149
- }).call({
8150
- ...call,
8151
- compatibility: {
8152
- resultReceiptKey: input.resultReceiptKey,
8153
- providerOperationKey: input.providerOperationKey,
8154
- },
8155
- });
8390
+ providerOperationKey: input.providerOperationKey,
8391
+ },
8392
+ });
8393
+ fencedDiagnostics?.settled('recorded');
8394
+ return result;
8395
+ } catch (error) {
8396
+ fencedDiagnostics?.settled('failed');
8397
+ throw error;
8398
+ }
8156
8399
  }
8157
8400
 
8158
8401
  /** One replay-stable physical delivery identity for each invocation. */
@@ -54,7 +54,10 @@ import type { MapRowOutcome } from './durability-store';
54
54
  import type { WorkReceiptFailureKind } from './work-receipts';
55
55
  import type { RunExecutionScope } from './run-execution-scope';
56
56
  import type { PlayCallExecution } from './play-call-execution';
57
- import type { PlayDocflowNodeIoPreviewMap } from './docflow-node-io';
57
+ import type {
58
+ PlayDocflowNodeDecision,
59
+ PlayDocflowNodeIoPreviewMap,
60
+ } from './docflow-node-io';
58
61
  import type { PlayActivityEvent } from './activity-observation';
59
62
  import type {
60
63
  ToolExecutionErrorSchemaVersion,
@@ -649,6 +652,12 @@ export type PlayExecutionEvent =
649
652
  inputsTruncated?: boolean;
650
653
  outputs: PlayDocflowNodeIoPreviewMap;
651
654
  outputsTruncated?: boolean;
655
+ /**
656
+ * Optional, reader-first: a decision box's completion is re-emitted with
657
+ * the arm it took once the run reaches that arm's first bound box. Older
658
+ * readers fold the repeat as the same completion and ignore the field.
659
+ */
660
+ decision?: PlayDocflowNodeDecision;
652
661
  at: number;
653
662
  }
654
663
  | {
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Records which arm each drawn decision took, at run time.
3
+ *
4
+ * A decision box's observation settles with its computed value (`isEnterprise
5
+ * = false`); the branch statement acting on it is ordinary code. The arm is
6
+ * named by the first bound box the run reports next that the decision can
7
+ * reach, per the pure rule in `../plays/docflow-decision-arms`. The
8
+ * tracker holds each settled decision until such a box arrives, then hands the
9
+ * caller what to record: the arm, its target, and this attempt's per-arm counts
10
+ * (bounded by the drawn arms, so the state stays fixed-size however often a
11
+ * loop re-decides).
12
+ *
13
+ * Keyed by the diagram object, so an inline child play's decisions resolve
14
+ * only against its own diagram's boxes.
15
+ */
16
+ import type { PlayDocflow } from '../plays/docflow';
17
+ import {
18
+ docflowDecisionArmPlans,
19
+ resolveDocflowDecisionArm,
20
+ } from '../plays/docflow-decision-arms';
21
+ import {
22
+ DOCFLOW_NODE_IO_LIMITS,
23
+ type PlayDocflowNodeDecision,
24
+ } from './docflow-node-io';
25
+
26
+ export type DocflowDecisionResolved<Settled> = {
27
+ decisionId: string;
28
+ settled: Settled;
29
+ decision: PlayDocflowNodeDecision;
30
+ /** First time this attempt took this arm of this decision. */
31
+ firstForArm: boolean;
32
+ };
33
+
34
+ type ArmCount = { arm: string; to: string; count: number };
35
+
36
+ export class DocflowDecisionTracker<Settled> {
37
+ private readonly pending = new WeakMap<
38
+ PlayDocflow,
39
+ Map<string, Settled>
40
+ >();
41
+ private readonly counts = new WeakMap<
42
+ PlayDocflow,
43
+ Map<string, ArmCount[]>
44
+ >();
45
+
46
+ /** Whether `nodeId` is a decision whose arm this tracker can record. */
47
+ tracks(docflow: PlayDocflow, nodeId: string): boolean {
48
+ return docflowDecisionArmPlans(docflow).has(nodeId);
49
+ }
50
+
51
+ /**
52
+ * A decision box settled. A newer settlement of the same box replaces an
53
+ * unresolved older one: only the latest invocation's arm is knowable.
54
+ */
55
+ settle(docflow: PlayDocflow, decisionId: string, settled: Settled): void {
56
+ if (!this.tracks(docflow, decisionId)) return;
57
+ let pending = this.pending.get(docflow);
58
+ if (!pending) {
59
+ pending = new Map();
60
+ this.pending.set(docflow, pending);
61
+ }
62
+ pending.set(decisionId, settled);
63
+ }
64
+
65
+ /**
66
+ * A bound box was reached. Returns every pending decision it names an arm
67
+ * for, and forgets the ones it proves unresolvable.
68
+ */
69
+ reach(
70
+ docflow: PlayDocflow,
71
+ nodeId: string,
72
+ ): DocflowDecisionResolved<Settled>[] {
73
+ const pending = this.pending.get(docflow);
74
+ if (!pending || pending.size === 0) return [];
75
+ const plans = docflowDecisionArmPlans(docflow);
76
+ const resolved: DocflowDecisionResolved<Settled>[] = [];
77
+ for (const [decisionId, settled] of [...pending]) {
78
+ const plan = plans.get(decisionId);
79
+ if (!plan) {
80
+ pending.delete(decisionId);
81
+ continue;
82
+ }
83
+ const outcome = resolveDocflowDecisionArm(plan, nodeId);
84
+ if (outcome.kind === 'unrelated') continue;
85
+ pending.delete(decisionId);
86
+ if (outcome.kind === 'unresolvable') continue;
87
+ const arm = boundedText(outcome.arm.label);
88
+ const to = boundedText(outcome.arm.to);
89
+ let byDecision = this.counts.get(docflow);
90
+ if (!byDecision) {
91
+ byDecision = new Map();
92
+ this.counts.set(docflow, byDecision);
93
+ }
94
+ const counts = byDecision.get(decisionId) ?? [];
95
+ const existing = counts.find(
96
+ (entry) => entry.arm === arm && entry.to === to,
97
+ );
98
+ if (existing) existing.count += 1;
99
+ else if (counts.length < DOCFLOW_NODE_IO_LIMITS.maxDecisionArms) {
100
+ counts.push({ arm, to, count: 1 });
101
+ }
102
+ byDecision.set(decisionId, counts);
103
+ resolved.push({
104
+ decisionId,
105
+ settled,
106
+ decision: {
107
+ arm,
108
+ to,
109
+ counts: counts.map((entry) => ({ ...entry })),
110
+ },
111
+ firstForArm: !existing,
112
+ });
113
+ }
114
+ return resolved;
115
+ }
116
+ }
117
+
118
+ const utf8 = new TextEncoder();
119
+
120
+ /** Trim to the preview string bound without splitting a UTF-8 sequence. */
121
+ export function boundedText(
122
+ value: string,
123
+ maxBytes: number = DOCFLOW_NODE_IO_LIMITS.maxStringBytes,
124
+ ): string {
125
+ if (utf8.encode(value).byteLength <= maxBytes) return value;
126
+ let out = '';
127
+ let bytes = 0;
128
+ for (const char of value) {
129
+ const size = utf8.encode(char).byteLength;
130
+ if (bytes + size > maxBytes - 3) break;
131
+ out += char;
132
+ bytes += size;
133
+ }
134
+ return `${out}…`;
135
+ }