deepline 0.3.546 → 0.3.548
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 +13 -0
- package/dist/bundling-sources/sdk/src/index.ts +7 -1
- package/dist/bundling-sources/sdk/src/integrations.ts +17 -7
- package/dist/bundling-sources/sdk/src/play.ts +71 -0
- package/dist/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/sdk/src/runs/watch-polling.ts +13 -4
- package/dist/bundling-sources/sdk/src/types.ts +33 -0
- package/dist/bundling-sources/shared_libs/integration-contracts/calendar-delegation.ts +7 -0
- package/dist/bundling-sources/shared_libs/monitors/provider-monitor-batch-operation.ts +2 -0
- package/dist/bundling-sources/shared_libs/monitors/tracking-provider-guidance.ts +1 -0
- package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +19 -1
- package/dist/bundling-sources/shared_libs/play-data-plane/r2.ts +17 -2
- package/dist/bundling-sources/shared_libs/play-runtime/async-operation.ts +57 -5
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +295 -52
- package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +10 -1
- package/dist/bundling-sources/shared_libs/play-runtime/docflow-decision-tracker.ts +135 -0
- package/dist/bundling-sources/shared_libs/play-runtime/docflow-fail-open.ts +177 -0
- package/dist/bundling-sources/shared_libs/play-runtime/docflow-node-io.ts +99 -2
- package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +16 -10
- package/dist/bundling-sources/shared_libs/play-runtime/fenced-call-diagnostics.ts +211 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-capacity-policy.ts +52 -14
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +68 -2
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +18 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +68 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +100 -3
- package/dist/bundling-sources/shared_libs/play-runtime/tool-cache-policy.ts +9 -1
- package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +48 -0
- package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +6 -1
- package/dist/bundling-sources/shared_libs/plays/bundling/index.ts +716 -51
- package/dist/bundling-sources/shared_libs/plays/docflow-decision-arms.ts +146 -0
- package/dist/bundling-sources/shared_libs/plays/docflow-flow-order.ts +94 -0
- package/dist/bundling-sources/shared_libs/plays/docflow-unreached-reason.ts +10 -1
- package/dist/bundling-sources/shared_libs/plays/docflow.ts +787 -117
- package/dist/bundling-sources/shared_libs/plays/share/static-pipeline-summary.ts +8 -2
- package/dist/bundling-sources/shared_libs/plays/static-pipeline.ts +6 -0
- package/dist/bundling-sources/shared_libs/plays/trigger-config-contract.ts +13 -0
- package/dist/bundling-sources/shared_libs/product-notifications/billing-sales.ts +25 -0
- package/dist/bundling-sources/shared_libs/security/email-blacklist.ts +3 -0
- package/dist/bundling-sources/shared_libs/security/email-domain.ts +24 -0
- package/dist/bundling-sources/shared_libs/security/secret-redaction.ts +56 -0
- package/dist/cli/auth-7UJFY5BY.js +43 -0
- package/dist/cli/{auth-KFWG72AZ.mjs → auth-YOOVLLUL.mjs} +5 -5
- package/dist/cli/{billing-MMZ336HO.mjs → billing-2NCNX6L2.mjs} +10 -10
- package/dist/cli/{billing-OQVOAZ4S.js → billing-HETIOUD6.js} +96 -96
- package/dist/cli/{chunk-JVOUQFHT.js → chunk-2OG2KBYJ.js} +1 -1
- package/dist/cli/{chunk-JA633HRV.mjs → chunk-3QRU6RY7.mjs} +3 -3
- package/dist/cli/{chunk-TI6DTURF.js → chunk-4WAM6TLD.js} +7 -1
- package/dist/cli/{chunk-RO66FPTS.mjs → chunk-53QLWPZK.mjs} +1 -1
- package/dist/cli/{chunk-6LG7MLJ2.js → chunk-5OJOFUMO.js} +44 -44
- package/dist/cli/{chunk-F2VEFMU5.js → chunk-5XFJBIQT.js} +13 -13
- package/dist/cli/{chunk-UQJBV5PM.js → chunk-5XXPP3PR.js} +10 -10
- package/dist/cli/{chunk-6FBDTYR2.mjs → chunk-64BFUBXX.mjs} +2 -2
- package/dist/cli/{chunk-VAT2SXFF.js → chunk-6GIZNOXQ.js} +12 -12
- package/dist/cli/{chunk-7MY7KWJS.mjs → chunk-7AJ5V3BK.mjs} +1 -1
- package/dist/cli/{chunk-MEGHIX4M.js → chunk-7H6TQ6W2.js} +5 -5
- package/dist/cli/{chunk-PMDHY2YK.js → chunk-7JIOJLTS.js} +7 -7
- package/dist/cli/{chunk-EEJHB76U.js → chunk-7UJZWI5Z.js} +12 -12
- package/dist/cli/{chunk-X5KOHDJN.mjs → chunk-ATTURFOV.mjs} +1 -1
- package/dist/cli/{chunk-SH32HL7I.js → chunk-AUYBBFPT.js} +53 -53
- package/dist/cli/{chunk-JCWNF44W.js → chunk-BDBEEV6X.js} +22 -22
- package/dist/cli/{chunk-WKHPLBJK.js → chunk-BWJZ4NQJ.js} +15 -15
- package/dist/cli/{chunk-2JHYYB3F.js → chunk-CSPHSNBW.js} +3 -3
- package/dist/cli/{chunk-4AZLGNXV.js → chunk-CXZLHBNK.js} +4 -4
- package/dist/cli/{chunk-J65HJCJO.mjs → chunk-F4ON5COB.mjs} +2 -2
- package/dist/cli/{chunk-KUK7ARXA.mjs → chunk-FMQA7UZZ.mjs} +2 -2
- package/dist/cli/{chunk-UREAIHUU.mjs → chunk-FUUYWEF4.mjs} +3 -3
- package/dist/cli/{chunk-HXIR3VQL.mjs → chunk-FZHMNK6F.mjs} +7 -1
- package/dist/cli/{chunk-PU3ZAG6V.mjs → chunk-GCEGQ7TQ.mjs} +1 -1
- package/dist/cli/{chunk-BLYW6FFB.js → chunk-GJA2PRHJ.js} +2 -2
- package/dist/cli/{chunk-TBWYZOSV.js → chunk-GUIYFOG2.js} +3 -3
- package/dist/cli/{chunk-BTFUAGHC.js → chunk-HDLMX7SG.js} +16 -16
- package/dist/cli/{chunk-VTK3HGMN.mjs → chunk-HIMZ57QD.mjs} +5 -5
- package/dist/cli/{chunk-JYG4XZLT.js → chunk-HTZIJORU.js} +99 -99
- package/dist/cli/{chunk-VPERQ3U6.mjs → chunk-HU3DDLGD.mjs} +5 -5
- package/dist/cli/{chunk-H7Q5IDO3.js → chunk-I2JIWKCQ.js} +20 -20
- package/dist/cli/{chunk-MXQP7CXZ.js → chunk-IIWXBRDK.js} +3 -3
- package/dist/cli/{chunk-MI7X6V6V.mjs → chunk-IQBXX54G.mjs} +3 -3
- package/dist/cli/{chunk-SYTWWVIQ.js → chunk-JQWX377P.js} +5 -5
- package/dist/cli/{chunk-Z3UEBFIN.js → chunk-LAVPP6WD.js} +41 -41
- package/dist/cli/{chunk-JCH4UNNS.js → chunk-M2OZORIH.js} +2 -2
- package/dist/cli/{chunk-Z7SXGOIQ.mjs → chunk-MF7PCM6C.mjs} +1 -1
- package/dist/cli/{chunk-7ZW67ME6.mjs → chunk-MQSKSISW.mjs} +1 -1
- package/dist/cli/{chunk-JARZ47OP.mjs → chunk-MWQ4WWZF.mjs} +2 -2
- package/dist/cli/{chunk-EEG46QZY.mjs → chunk-NFMX7BRF.mjs} +2 -2
- package/dist/cli/{chunk-VXTTAYOT.mjs → chunk-OGDQFVCP.mjs} +3 -3
- package/dist/cli/{chunk-3DUNNZB6.mjs → chunk-OQCYSLML.mjs} +4 -4
- package/dist/cli/{chunk-5W4ENHWM.js → chunk-PVE3A2BO.js} +285 -264
- package/dist/cli/{chunk-F5YQXCP3.js → chunk-PVQCX6KQ.js} +50 -7
- package/dist/cli/{chunk-GYTSDSQD.mjs → chunk-QQBRXMZM.mjs} +11 -11
- package/dist/cli/{chunk-6Y5TU3R7.mjs → chunk-QZ74ZC55.mjs} +1 -1
- package/dist/cli/{chunk-5OEFXAKP.mjs → chunk-RMCCB3XY.mjs} +50 -7
- package/dist/cli/{chunk-5V7NZKGG.js → chunk-T3RDWG5J.js} +2 -2
- package/dist/cli/{chunk-OAKWSLKS.mjs → chunk-TKGFHRHE.mjs} +28 -7
- package/dist/cli/{chunk-HJR2DDJS.mjs → chunk-U35ZLVBA.mjs} +2 -2
- package/dist/cli/{chunk-ND7SFRQL.js → chunk-U7HJXE6Y.js} +2 -2
- package/dist/cli/{chunk-LX2TC3HO.mjs → chunk-UBQQR56I.mjs} +4 -4
- package/dist/cli/{chunk-5VNQMVCU.js → chunk-VK2GSTRN.js} +26 -26
- package/dist/cli/{chunk-K2XELBPF.mjs → chunk-VSACOMIA.mjs} +5 -5
- package/dist/cli/{chunk-IVWU7SJC.js → chunk-WI4MCR7M.js} +5 -5
- package/dist/cli/{chunk-LIJKRDDG.js → chunk-WIHQAZPV.js} +6 -6
- package/dist/cli/{chunk-LHE2TSV6.mjs → chunk-WVZF4DU7.mjs} +1 -1
- package/dist/cli/{chunk-2HSZCQMT.mjs → chunk-WYT3H6JD.mjs} +1 -1
- package/dist/cli/{chunk-GOOF7E2B.mjs → chunk-XKEBQVCP.mjs} +5 -5
- package/dist/cli/{chunk-P7A3H6G5.mjs → chunk-XU3D2KFR.mjs} +1 -1
- package/dist/cli/command-docs.js +2 -2
- package/dist/cli/command-docs.mjs +1 -1
- package/dist/cli/concurrent-runs-help-A2IQVZRJ.js +21 -0
- package/dist/cli/{concurrent-runs-help-C2O5YKQA.mjs → concurrent-runs-help-FDCCZ45D.mjs} +6 -6
- package/dist/cli/{csv-Z4DNGR54.mjs → csv-GJYLQ52D.mjs} +4 -4
- package/dist/cli/{csv-MJDNOIQJ.js → csv-OCEQWZO3.js} +13 -13
- package/dist/cli/{db-4RL2BNOF.mjs → db-5MA2UUHQ.mjs} +7 -7
- package/dist/cli/{db-S5QVPK5E.js → db-G5QGXFAX.js} +28 -28
- package/dist/cli/{describe-L4P5SZLQ.mjs → describe-4DOJ4DHA.mjs} +19 -19
- package/dist/cli/describe-SD7DRTBW.js +50 -0
- package/dist/cli/describe-core.d.mts +4 -4
- package/dist/cli/describe-core.d.ts +4 -4
- package/dist/cli/{executions-RR6O3XK5.mjs → executions-C7SMBHHB.mjs} +7 -7
- package/dist/cli/{executions-MFZ2Z36O.js → executions-IYEVUPJI.js} +9 -9
- package/dist/cli/{feedback-YDAG7VH2.js → feedback-GYAF46GA.js} +14 -14
- package/dist/cli/{feedback-EQBQ3ABB.mjs → feedback-XUU2UKM6.mjs} +6 -6
- package/dist/cli/git-7YYVMY6L.js +25 -0
- package/dist/cli/{git-YGLCCU35.mjs → git-WVCMK5AH.mjs} +5 -5
- package/dist/cli/index.js +146 -146
- package/dist/cli/index.mjs +45 -45
- package/dist/cli/{integrations-FWYXSBHK.mjs → integrations-FXADGAX2.mjs} +11 -9
- package/dist/cli/{integrations-IQXYMRMW.js → integrations-YYBJJFVX.js} +19 -17
- package/dist/cli/{legacy-noops-I4YRIX5F.mjs → legacy-noops-LJY7LDUE.mjs} +6 -6
- package/dist/cli/{legacy-noops-U7LI7UXC.js → legacy-noops-REZCYES2.js} +9 -9
- package/dist/cli/{mcp-GX2UKKWU.js → mcp-L5PURE5S.js} +24 -24
- package/dist/cli/{mcp-QJBMB6VS.mjs → mcp-XSB3ZJFR.mjs} +4 -4
- package/dist/cli/{monitors-WCJYINGX.js → monitors-I5EIHSGV.js} +119 -101
- package/dist/cli/{monitors-Z6EGKYJP.mjs → monitors-UBPF2OLO.mjs} +26 -8
- package/dist/cli/{org-NNHICBR2.mjs → org-PHHIN2ER.mjs} +7 -7
- package/dist/cli/{org-7SKG423N.js → org-SGSTGGUD.js} +89 -89
- package/dist/cli/{play-CXDFPJ7Z.mjs → play-LEJNJLWY.mjs} +295 -67
- package/dist/cli/{play-4P4DTG3Q.js → play-WQEKMANL.js} +897 -669
- package/dist/cli/{providers-VQLQ7DTR.mjs → providers-3W26ZDAV.mjs} +7 -7
- package/dist/cli/{providers-EE4TUE3O.js → providers-RSDXBXIS.js} +10 -10
- package/dist/cli/{quickstart-IYNJRB5G.mjs → quickstart-LGJD2M36.mjs} +4 -4
- package/dist/cli/{quickstart-RVXHK4WA.js → quickstart-U3QX4EMI.js} +6 -6
- package/dist/cli/{run-R3F34KU3.js → run-F2UPZUJS.js} +45 -45
- package/dist/cli/{run-VBQPPMEX.mjs → run-YWZ3W5HK.mjs} +25 -25
- package/dist/cli/search-K6ANAXLF.js +32 -0
- package/dist/cli/{search-B7R62HX5.mjs → search-O2OJH3PY.mjs} +8 -8
- package/dist/cli/{search-output-LNQQXIGZ.mjs → search-output-H5BF6SJ3.mjs} +4 -4
- package/dist/cli/{search-output-LWHWEPOT.js → search-output-W7OCBYBU.js} +6 -6
- package/dist/cli/{secrets-NM3VAJLO.mjs → secrets-65XCAA7U.mjs} +7 -7
- package/dist/cli/{secrets-QBOZ7WTD.js → secrets-BN4GYVRI.js} +16 -16
- package/dist/cli/sessions-M52QWLA6.js +22 -0
- package/dist/cli/{sessions-R5BSIJ4I.mjs → sessions-SVEVESCQ.mjs} +6 -6
- package/dist/cli/{settings-POYWKNRD.js → settings-7YMDAFCN.js} +86 -86
- package/dist/cli/{settings-S4PN7WLY.mjs → settings-HAU2NP2H.mjs} +13 -13
- package/dist/cli/{setup-PFLXVBTL.mjs → setup-5RXHZ6YI.mjs} +9 -9
- package/dist/cli/{setup-VHB4Z654.js → setup-G37QXQGM.js} +49 -49
- package/dist/cli/{skills-W2TELEU7.mjs → skills-Q7A3XFAU.mjs} +7 -7
- package/dist/cli/skills-ZK4D5BJW.js +36 -0
- package/dist/cli/tools-DBZTLYFM.js +57 -0
- package/dist/cli/{tools-M4FA6N3Y.mjs → tools-ZG4NYRGB.mjs} +18 -18
- package/dist/cli/{update-W7LIHEA7.mjs → update-2CMZTZCL.mjs} +9 -9
- package/dist/cli/update-LC5HGEEH.js +34 -0
- package/dist/cli/{views-KTVPV6UP.mjs → views-A6IIY4OQ.mjs} +7 -7
- package/dist/cli/{views-DJXAGD7V.js → views-XUMDMDIE.js} +22 -22
- package/dist/cli/{workflow-NVZDJKH2.js → workflow-4EEW6MCD.js} +18 -18
- package/dist/cli/{workflow-LGKCRODX.mjs → workflow-74MYISHU.mjs} +8 -8
- package/dist/{client-Tp1LSULB.d.mts → client-D1uWA2Vc.d.mts} +1 -1
- package/dist/{client-CCyWJqAI.d.ts → client-Hz7SsBXs.d.ts} +1 -1
- package/dist/{client-core-BpYiYEfu.d.ts → client-core-D3Ad7Flt.d.ts} +554 -504
- package/dist/{client-core-D8eCZz3O.d.mts → client-core-Db_e63Hb.d.mts} +554 -504
- package/dist/{compiler-manifest-EBWEUj0b.d.ts → compiler-manifest-BqwVrOri.d.mts} +38 -18
- package/dist/{compiler-manifest-EBWEUj0b.d.mts → compiler-manifest-BqwVrOri.d.ts} +38 -18
- package/dist/{errors-CParKUQR.d.mts → errors-BU8FB99X.d.mts} +1 -1
- package/dist/{errors-Qt0OTA7_.d.ts → errors-DfVN_FUG.d.ts} +1 -1
- package/dist/{index-CoqDkIw0.d.ts → index-BGnvtYGc.d.ts} +6 -1
- package/dist/{index-BMUVCNp7.d.mts → index-DjZgwpGw.d.mts} +6 -1
- package/dist/index.d.mts +28 -8
- package/dist/index.d.ts +28 -8
- package/dist/index.js +64 -39
- package/dist/index.mjs +32 -7
- package/dist/install-integrity.json +133 -128
- 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 +620 -124
- package/dist/plays/play-description.d.mts +3 -3
- package/dist/plays/play-description.d.ts +3 -3
- package/dist/plays/run-request.d.mts +2 -2
- package/dist/plays/run-request.d.ts +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 +6 -6
- package/dist/server.mjs +4 -4
- package/package.json +1 -1
- package/dist/cli/auth-W32GMYND.js +0 -43
- package/dist/cli/concurrent-runs-help-6QT7ZR4W.js +0 -21
- package/dist/cli/describe-VLU2LUDJ.js +0 -50
- package/dist/cli/git-E6W44F5M.js +0 -25
- package/dist/cli/search-UUVFXZRA.js +0 -32
- package/dist/cli/sessions-K3PD73Q2.js +0 -22
- package/dist/cli/skills-QNE2EYT3.js +0 -36
- package/dist/cli/tools-3RLI4HGF.js +0 -57
- package/dist/cli/update-UT6KIW2W.js +0 -34
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Docflow tracking is display-only, so it must never change what a Play does.
|
|
3
|
+
*
|
|
4
|
+
* Every compiler-injected observation funnels through
|
|
5
|
+
* {@link runDocflowObservationFailOpen}, which guarantees by construction:
|
|
6
|
+
*
|
|
7
|
+
* - `execute` runs exactly once, synchronously, in the caller's turn;
|
|
8
|
+
* - its return value (the same object, the same Promise instance) or its
|
|
9
|
+
* throw reaches the Play unchanged;
|
|
10
|
+
* - no tracking stage (start/capture, decision arms, completion, failure,
|
|
11
|
+
* fault reporting) can throw into the Play or leave an unhandled rejection.
|
|
12
|
+
*
|
|
13
|
+
* A tracking stage that throws is counted and reported to the caller's
|
|
14
|
+
* `onFault`, which must itself be bounded (see `DocflowTrackingFaultCounter`).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export type DocflowTrackingFaultStage =
|
|
18
|
+
/** Validating the node id, capturing inputs, emitting `started`. */
|
|
19
|
+
| 'start'
|
|
20
|
+
/** Recording a decision's arm (tracker, decision log line). */
|
|
21
|
+
| 'decision'
|
|
22
|
+
/** Previewing outputs and emitting `completed`. */
|
|
23
|
+
| 'complete'
|
|
24
|
+
/** Previewing the error and emitting `failed`. */
|
|
25
|
+
| 'fail'
|
|
26
|
+
/** A compiler-injected `__deeplineDocflowHit` marker. */
|
|
27
|
+
| 'hit';
|
|
28
|
+
|
|
29
|
+
export type DocflowObservationSettlement<T> = {
|
|
30
|
+
complete(result: T): void;
|
|
31
|
+
fail(error: unknown): void;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type DocflowTrackingFaultReporter = (
|
|
35
|
+
stage: DocflowTrackingFaultStage,
|
|
36
|
+
error: unknown,
|
|
37
|
+
) => void;
|
|
38
|
+
|
|
39
|
+
/** Runs `stage`, routing anything it throws to `onFault` (which cannot throw). */
|
|
40
|
+
export function guardDocflowTracking(
|
|
41
|
+
stage: DocflowTrackingFaultStage,
|
|
42
|
+
onFault: DocflowTrackingFaultReporter,
|
|
43
|
+
body: () => void,
|
|
44
|
+
): void {
|
|
45
|
+
try {
|
|
46
|
+
body();
|
|
47
|
+
} catch (error) {
|
|
48
|
+
reportFaultSafely(onFault, stage, error);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function reportFaultSafely(
|
|
53
|
+
onFault: DocflowTrackingFaultReporter,
|
|
54
|
+
stage: DocflowTrackingFaultStage,
|
|
55
|
+
error: unknown,
|
|
56
|
+
): void {
|
|
57
|
+
try {
|
|
58
|
+
onFault(stage, error);
|
|
59
|
+
} catch {
|
|
60
|
+
// The reporter is the last line: nothing it does may reach the Play.
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Observe one authored statement without changing it. `begin` runs before the
|
|
66
|
+
* statement (capture + `started`) and returns how to settle the observation,
|
|
67
|
+
* or null to skip tracking; a throw from it is a fault and the statement still
|
|
68
|
+
* runs, untracked.
|
|
69
|
+
*/
|
|
70
|
+
export function runDocflowObservationFailOpen<T>(
|
|
71
|
+
execute: () => T | Promise<T>,
|
|
72
|
+
begin: () => DocflowObservationSettlement<T> | null,
|
|
73
|
+
onFault: DocflowTrackingFaultReporter,
|
|
74
|
+
): T | Promise<T> {
|
|
75
|
+
let settlement: DocflowObservationSettlement<T> | null = null;
|
|
76
|
+
try {
|
|
77
|
+
settlement = begin();
|
|
78
|
+
} catch (error) {
|
|
79
|
+
reportFaultSafely(onFault, 'start', error);
|
|
80
|
+
settlement = null;
|
|
81
|
+
}
|
|
82
|
+
if (!settlement) return execute();
|
|
83
|
+
const settle = settlement;
|
|
84
|
+
|
|
85
|
+
let result: T | Promise<T>;
|
|
86
|
+
try {
|
|
87
|
+
result = execute();
|
|
88
|
+
} catch (error) {
|
|
89
|
+
guardDocflowTracking('fail', onFault, () => settle.fail(error));
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
// Only a native Promise is observed asynchronously: calling `.then` on an
|
|
93
|
+
// authored thenable would run authored code the uninstrumented Play never
|
|
94
|
+
// ran. The derived promise's handlers cannot throw, so it never rejects.
|
|
95
|
+
if (isNativePromise(result)) {
|
|
96
|
+
try {
|
|
97
|
+
void result.then(
|
|
98
|
+
(value) =>
|
|
99
|
+
guardDocflowTracking('complete', onFault, () =>
|
|
100
|
+
settle.complete(value),
|
|
101
|
+
),
|
|
102
|
+
(error: unknown) =>
|
|
103
|
+
guardDocflowTracking('fail', onFault, () => settle.fail(error)),
|
|
104
|
+
);
|
|
105
|
+
} catch (error) {
|
|
106
|
+
// A Promise subclass with a throwing `then`.
|
|
107
|
+
reportFaultSafely(onFault, 'complete', error);
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
const value = result;
|
|
112
|
+
guardDocflowTracking('complete', onFault, () => settle.complete(value));
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** `instanceof` reads the prototype, which a hostile Proxy can make throw. */
|
|
117
|
+
function isNativePromise(value: unknown): value is Promise<unknown> {
|
|
118
|
+
try {
|
|
119
|
+
return value instanceof Promise;
|
|
120
|
+
} catch {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Bounded fault reporting: the first fault of each stage and then powers of
|
|
127
|
+
* two, each carrying the running count, so a hot loop whose observation keeps
|
|
128
|
+
* failing reports O(log n) lines. Lines never carry values, messages, or
|
|
129
|
+
* inputs (they may hold secrets): only the stage, node id and error class.
|
|
130
|
+
*/
|
|
131
|
+
export class DocflowTrackingFaultCounter {
|
|
132
|
+
private readonly counts = new Map<DocflowTrackingFaultStage, number>();
|
|
133
|
+
total = 0;
|
|
134
|
+
|
|
135
|
+
constructor(
|
|
136
|
+
private readonly write: (line: string) => void,
|
|
137
|
+
private readonly identity: () => Record<string, unknown> = () => ({}),
|
|
138
|
+
) {}
|
|
139
|
+
|
|
140
|
+
record(
|
|
141
|
+
stage: DocflowTrackingFaultStage,
|
|
142
|
+
nodeId: unknown,
|
|
143
|
+
error: unknown,
|
|
144
|
+
): void {
|
|
145
|
+
this.total += 1;
|
|
146
|
+
const count = (this.counts.get(stage) ?? 0) + 1;
|
|
147
|
+
this.counts.set(stage, count);
|
|
148
|
+
if ((count & (count - 1)) !== 0) return;
|
|
149
|
+
let identity: Record<string, unknown> = {};
|
|
150
|
+
try {
|
|
151
|
+
identity = this.identity();
|
|
152
|
+
} catch {
|
|
153
|
+
identity = {};
|
|
154
|
+
}
|
|
155
|
+
this.write(
|
|
156
|
+
JSON.stringify({
|
|
157
|
+
event: 'docflow_tracking_fault',
|
|
158
|
+
stage,
|
|
159
|
+
node_id:
|
|
160
|
+
typeof nodeId === 'string' ? nodeId.slice(0, 128) : typeof nodeId,
|
|
161
|
+
error_class: docflowFaultErrorClass(error),
|
|
162
|
+
stage_fault_count: count,
|
|
163
|
+
total_fault_count: this.total,
|
|
164
|
+
...identity,
|
|
165
|
+
}),
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function docflowFaultErrorClass(error: unknown): string {
|
|
171
|
+
try {
|
|
172
|
+
if (error instanceof Error) return error.name.slice(0, 64) || 'Error';
|
|
173
|
+
} catch {
|
|
174
|
+
return 'unknown';
|
|
175
|
+
}
|
|
176
|
+
return error === null ? 'null' : typeof error;
|
|
177
|
+
}
|
|
@@ -11,8 +11,29 @@ export const DOCFLOW_NODE_IO_LIMITS = {
|
|
|
11
11
|
maxStringBytes: 256,
|
|
12
12
|
maxPhaseBytes: 2_000,
|
|
13
13
|
maxErrorBytes: 512,
|
|
14
|
+
/** Arms counted on one decision's recorded outcome. */
|
|
15
|
+
maxDecisionArms: 16,
|
|
16
|
+
/**
|
|
17
|
+
* Invocations of one box observed per attempt before sampling. A box inside
|
|
18
|
+
* a loop (or a helper called per item) is invoked once per item; past this
|
|
19
|
+
* many, only power-of-two invocations are observed, so a run writes
|
|
20
|
+
* O(log n) observations per box however many items it processes.
|
|
21
|
+
*/
|
|
22
|
+
maxObservedInvocationsPerNode: 16,
|
|
14
23
|
} as const;
|
|
15
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Whether the `ordinal`-th (1-based) invocation of one box in one attempt is
|
|
27
|
+
* observed: every one up to the limit, then only powers of two. Display-only:
|
|
28
|
+
* an unobserved invocation still runs, untracked.
|
|
29
|
+
*/
|
|
30
|
+
export function isDocflowInvocationObserved(ordinal: number): boolean {
|
|
31
|
+
return (
|
|
32
|
+
ordinal <= DOCFLOW_NODE_IO_LIMITS.maxObservedInvocationsPerNode ||
|
|
33
|
+
(Number.isSafeInteger(ordinal) && (ordinal & (ordinal - 1)) === 0)
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
16
37
|
export type PlayDocflowNodeValuePreview =
|
|
17
38
|
| { kind: 'null' }
|
|
18
39
|
| { kind: 'scalar'; value: string | number | boolean }
|
|
@@ -70,12 +91,42 @@ export type PlayDocflowNodeIoState = {
|
|
|
70
91
|
inputsTruncated?: boolean;
|
|
71
92
|
outputsTruncated?: boolean;
|
|
72
93
|
error?: string | null;
|
|
94
|
+
/**
|
|
95
|
+
* The arm a DECISION box took, recorded by the runtime when the run reached
|
|
96
|
+
* the first bound box on that arm (`../plays/docflow-decision-arms`).
|
|
97
|
+
* Optional and reader-first: absent on non-decision boxes, on runs from
|
|
98
|
+
* runtimes that predate it, and when the graph names no single arm.
|
|
99
|
+
*/
|
|
100
|
+
decision?: PlayDocflowNodeDecision;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/** One decision box's recorded outcome. Fixed size: bounded by its drawn arms. */
|
|
104
|
+
export type PlayDocflowNodeDecision = {
|
|
105
|
+
/** The drawn edge label of the arm taken by this invocation. */
|
|
106
|
+
arm: string;
|
|
107
|
+
/** That edge's target node id. */
|
|
108
|
+
to: string;
|
|
109
|
+
/**
|
|
110
|
+
* How often each arm was taken by this attempt, when the decision ran more
|
|
111
|
+
* than once (a loop or repeated helper call). One entry per drawn arm taken.
|
|
112
|
+
*/
|
|
113
|
+
counts?: Array<{ arm: string; to: string; count: number }>;
|
|
73
114
|
};
|
|
74
115
|
|
|
75
116
|
type PreviewOptions = {
|
|
76
117
|
redactor?: Pick<SecretRedactionContext, 'redactRegisteredSecrets'>;
|
|
77
118
|
};
|
|
78
119
|
|
|
120
|
+
type CapturePreviewOptions = PreviewOptions & {
|
|
121
|
+
/**
|
|
122
|
+
* Replaces a captured root with a plain-data view before it is traversed and
|
|
123
|
+
* previewed: runtime-owned values (a tool result) expose their data through
|
|
124
|
+
* getters the previewer never invokes on authored values. Must not throw;
|
|
125
|
+
* a throw makes the capture unavailable.
|
|
126
|
+
*/
|
|
127
|
+
projectRoot?: (value: unknown) => unknown;
|
|
128
|
+
};
|
|
129
|
+
|
|
79
130
|
const utf8Encoder = new TextEncoder();
|
|
80
131
|
const PLAY_DATASET_BRAND = Symbol.for('deepline.play.dataset');
|
|
81
132
|
const MAX_CONVEX_PREVIEW_KEY_LENGTH = 1_024;
|
|
@@ -356,6 +407,13 @@ export function buildPlayDocflowNodeIoPreviewMap(
|
|
|
356
407
|
return { values: previews, truncated };
|
|
357
408
|
}
|
|
358
409
|
|
|
410
|
+
/**
|
|
411
|
+
* One step of a captured path (`input.crm_owner`), read the way the step's
|
|
412
|
+
* own optional read would: a field the value does not have, or a field of a
|
|
413
|
+
* null or undefined value, is `undefined` (the run did not provide it), not
|
|
414
|
+
* a failed read. Only a getter, or a read that throws, fails (`ok: false`,
|
|
415
|
+
* captured as `access_error`).
|
|
416
|
+
*/
|
|
359
417
|
function readDataProperty(
|
|
360
418
|
value: unknown,
|
|
361
419
|
property: PropertyKey,
|
|
@@ -363,6 +421,7 @@ function readDataProperty(
|
|
|
363
421
|
ok: boolean;
|
|
364
422
|
value?: unknown;
|
|
365
423
|
} {
|
|
424
|
+
if (value === null || value === undefined) return { ok: true, value: undefined };
|
|
366
425
|
if (
|
|
367
426
|
(typeof value !== 'object' || value === null) &&
|
|
368
427
|
typeof value !== 'function'
|
|
@@ -383,12 +442,13 @@ function readDataProperty(
|
|
|
383
442
|
} catch {
|
|
384
443
|
return { ok: false };
|
|
385
444
|
}
|
|
386
|
-
|
|
445
|
+
// Not there at all: the run did not provide it.
|
|
446
|
+
return { ok: true, value: undefined };
|
|
387
447
|
}
|
|
388
448
|
|
|
389
449
|
export function buildPlayDocflowNodeInputPreviewMap(
|
|
390
450
|
captures: readonly PlayDocflowNodeInputCapture[],
|
|
391
|
-
options:
|
|
451
|
+
options: CapturePreviewOptions = {},
|
|
392
452
|
): { values: PlayDocflowNodeIoPreviewMap; truncated: boolean } {
|
|
393
453
|
const values: PlayDocflowNodeIoPreviewMap = {};
|
|
394
454
|
let truncated = false;
|
|
@@ -397,6 +457,7 @@ export function buildPlayDocflowNodeInputPreviewMap(
|
|
|
397
457
|
let available = true;
|
|
398
458
|
try {
|
|
399
459
|
current = capture.readRoot();
|
|
460
|
+
if (options.projectRoot) current = options.projectRoot(current);
|
|
400
461
|
} catch {
|
|
401
462
|
available = false;
|
|
402
463
|
}
|
|
@@ -602,6 +663,7 @@ export function normalizePlayDocflowNodeIoState(
|
|
|
602
663
|
};
|
|
603
664
|
const inputs = normalizeMap(value.inputs);
|
|
604
665
|
const outputs = normalizeMap(value.outputs);
|
|
666
|
+
const decision = normalizePlayDocflowNodeDecision(value.decision);
|
|
605
667
|
const error =
|
|
606
668
|
typeof value.error === 'string'
|
|
607
669
|
? buildPlayDocflowNodeErrorPreview(value.error)
|
|
@@ -623,5 +685,40 @@ export function normalizePlayDocflowNodeIoState(
|
|
|
623
685
|
...(value.inputsTruncated === true ? { inputsTruncated: true } : {}),
|
|
624
686
|
...(value.outputsTruncated === true ? { outputsTruncated: true } : {}),
|
|
625
687
|
...(error !== undefined ? { error } : {}),
|
|
688
|
+
...(decision ? { decision } : {}),
|
|
626
689
|
};
|
|
627
690
|
}
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* Bounded copy of a recorded decision, or undefined when the value is not one.
|
|
694
|
+
* Unknown keys are dropped: the state is fixed-size by contract.
|
|
695
|
+
*/
|
|
696
|
+
export function normalizePlayDocflowNodeDecision(
|
|
697
|
+
value: unknown,
|
|
698
|
+
): PlayDocflowNodeDecision | undefined {
|
|
699
|
+
if (!isRecord(value)) return undefined;
|
|
700
|
+
const text = (raw: unknown): string | null =>
|
|
701
|
+
typeof raw === 'string' && raw.trim()
|
|
702
|
+
? truncateUtf8(raw.trim(), DOCFLOW_NODE_IO_LIMITS.maxStringBytes)
|
|
703
|
+
: null;
|
|
704
|
+
const arm = text(value.arm);
|
|
705
|
+
const to = text(value.to);
|
|
706
|
+
if (!arm || !to) return undefined;
|
|
707
|
+
const counts = Array.isArray(value.counts)
|
|
708
|
+
? value.counts
|
|
709
|
+
.slice(0, DOCFLOW_NODE_IO_LIMITS.maxDecisionArms)
|
|
710
|
+
.flatMap((entry) => {
|
|
711
|
+
if (!isRecord(entry)) return [];
|
|
712
|
+
const entryArm = text(entry.arm);
|
|
713
|
+
const entryTo = text(entry.to);
|
|
714
|
+
const count =
|
|
715
|
+
typeof entry.count === 'number' && Number.isSafeInteger(entry.count)
|
|
716
|
+
? entry.count
|
|
717
|
+
: -1;
|
|
718
|
+
return entryArm && entryTo && count >= 0
|
|
719
|
+
? [{ arm: entryArm, to: entryTo, count }]
|
|
720
|
+
: [];
|
|
721
|
+
})
|
|
722
|
+
: undefined;
|
|
723
|
+
return { arm, to, ...(counts?.length ? { counts } : {}) };
|
|
724
|
+
}
|
|
@@ -52,19 +52,23 @@ export const DURABLE_RUNS_ROLLOUT = {
|
|
|
52
52
|
* request when the relay's acknowledgement covers exactly those writes.
|
|
53
53
|
*
|
|
54
54
|
* Skew-safe both ways: an older relay ignores the plan (the runner writes as
|
|
55
|
-
* before) and a newer relay without a plan relays untouched.
|
|
56
|
-
*
|
|
57
|
-
*
|
|
55
|
+
* before) and a newer relay without a plan relays untouched. On since the
|
|
56
|
+
* runtime speed rollout flip: the relay reader shipped in #10000 and is in
|
|
57
|
+
* the Production release. On the execution relay this also selects the
|
|
58
|
+
* finish commit lanes ({heavy 1, light 2}). Off again stops new plans and
|
|
59
|
+
* restores the relay's ordinary commit lanes; rows already committed are
|
|
60
|
+
* ordinary immutable receipts.
|
|
58
61
|
*/
|
|
59
|
-
finishInExecute:
|
|
62
|
+
finishInExecute: true,
|
|
60
63
|
/**
|
|
61
64
|
* A direct policy-0 tool call reads the result receipt it would claim in
|
|
62
65
|
* the same request as its operation slots (one fixed batch of direct keys),
|
|
63
66
|
* instead of a second read after the operation answer. Off: the call reads
|
|
64
|
-
* exactly as before. Reader-only, so safe in either direction
|
|
65
|
-
*
|
|
67
|
+
* exactly as before. Reader-only, so safe in either direction. On since the
|
|
68
|
+
* runtime speed rollout flip (with `localPermitReadThrough`); off again
|
|
69
|
+
* restores the second read.
|
|
66
70
|
*/
|
|
67
|
-
toolResultCompanionRead:
|
|
71
|
+
toolResultCompanionRead: true,
|
|
68
72
|
/**
|
|
69
73
|
* Local-permit read-through: a warm policy-0 direct call whose dispatch
|
|
70
74
|
* capacity is already on hand sends its receipt keys (#10008's slots and its
|
|
@@ -72,10 +76,12 @@ export const DURABLE_RUNS_ROLLOUT = {
|
|
|
72
76
|
* reading first. The relay executes only when every key reads empty; any
|
|
73
77
|
* record (a pre-binding one included) falls back to the ordinary #10027
|
|
74
78
|
* classification, and a fresh invocation never uses read-through. Never
|
|
75
|
-
* offered with a legacy operation key.
|
|
76
|
-
*
|
|
79
|
+
* offered with a legacy operation key. Requires `finishInExecute`. An older
|
|
80
|
+
* relay refuses the named action (403 route not allowed) before any work, and
|
|
81
|
+
* the runner then reads for itself on that relay. On since the runtime speed
|
|
82
|
+
* rollout flip; off again keeps the runner's own read on every call.
|
|
77
83
|
*/
|
|
78
|
-
localPermitReadThrough:
|
|
84
|
+
localPermitReadThrough: true,
|
|
79
85
|
/**
|
|
80
86
|
* #10002: one Node process materializes the payload and then becomes the
|
|
81
87
|
* runtime watchdog (two Node starts instead of three). Off: the established
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runner-internal diagnostics for an execution-fenced (execution-lock) Tool
|
|
3
|
+
* Call in a map batch: when the relay's response arrived, when the result was
|
|
4
|
+
* wrapped, when the call's receipt completion settled, and a watchdog when a
|
|
5
|
+
* response has waited too long for its completion.
|
|
6
|
+
*
|
|
7
|
+
* Platform telemetry, not run log: lines go to the runner's stderr as
|
|
8
|
+
* `[play-runner.fenced-call] {json}` (the `play-runner.*` diagnostic family),
|
|
9
|
+
* never to the customer-visible run log or its event store. Logging only:
|
|
10
|
+
* nothing here schedules, retries or decides; the watchdog timer is unref'd
|
|
11
|
+
* and cleared at settlement. Lines carry a receipt-key digest, the attempt
|
|
12
|
+
* and elapsed times only: no tool input, row key, dataset name or provider
|
|
13
|
+
* body.
|
|
14
|
+
*
|
|
15
|
+
* Bounded per runner context (one run attempt): response and settlement lines
|
|
16
|
+
* for the first `detailedCalls` fenced calls only; overdue warnings for any
|
|
17
|
+
* call, the first `overdueFirst` and then every `overdueEvery`th.
|
|
18
|
+
*
|
|
19
|
+
* Why: a fenced row post once stalled after its relay answered 200 and before
|
|
20
|
+
* its receipt was committed (PR #10713's first Preview run), with no runner
|
|
21
|
+
* line between the two. These lines place the next stall on one side of the
|
|
22
|
+
* wrap or the commit.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** A response this long without its completion is logged as overdue. */
|
|
26
|
+
export const FENCED_CALL_COMPLETION_WATCHDOG_MS = 10_000;
|
|
27
|
+
/** Fenced calls per runner context whose response/settlement lines are kept. */
|
|
28
|
+
export const FENCED_CALL_DETAILED_CALLS = 50;
|
|
29
|
+
/** Overdue warnings kept before sampling. */
|
|
30
|
+
export const FENCED_CALL_OVERDUE_FIRST = 20;
|
|
31
|
+
/** After the first ones, every this-many-th overdue warning is kept. */
|
|
32
|
+
export const FENCED_CALL_OVERDUE_EVERY = 50;
|
|
33
|
+
|
|
34
|
+
export const FENCED_CALL_DIAGNOSTIC_PREFIX = '[play-runner.fenced-call]';
|
|
35
|
+
|
|
36
|
+
export type FencedCallDiagnosticEvent =
|
|
37
|
+
| 'fenced_call_relay_response'
|
|
38
|
+
| 'fenced_call_receipt_settled'
|
|
39
|
+
| 'fenced_call_completion_overdue';
|
|
40
|
+
|
|
41
|
+
export type FencedCallDiagnosticLine = {
|
|
42
|
+
event: FencedCallDiagnosticEvent;
|
|
43
|
+
level: 'info' | 'warn';
|
|
44
|
+
tool: string;
|
|
45
|
+
/** Short digest of the call's result receipt key; never the key itself. */
|
|
46
|
+
call_key_hash: string;
|
|
47
|
+
attempt: number;
|
|
48
|
+
/** Since the call entered the fenced dispatch on this runner. */
|
|
49
|
+
elapsed_ms: number;
|
|
50
|
+
/** Relay responses read so far for this call (retries re-send). */
|
|
51
|
+
responses: number;
|
|
52
|
+
/** Since the latest relay response; absent before the first one. */
|
|
53
|
+
since_response_ms?: number;
|
|
54
|
+
/** Whether the relay response had been turned into the call's result. */
|
|
55
|
+
wrapped: boolean;
|
|
56
|
+
/** Settlement only: whether the receipt completion was recorded. */
|
|
57
|
+
outcome?: 'recorded' | 'failed';
|
|
58
|
+
/**
|
|
59
|
+
* Settlement only: `call` when this call's own receipt write settled
|
|
60
|
+
* before it returned; `map` when the map owns the write and records it
|
|
61
|
+
* after this call returns; `none` for an always-fresh call with no receipt.
|
|
62
|
+
*/
|
|
63
|
+
receipt_writer?: 'call' | 'map' | 'none';
|
|
64
|
+
/** Overdue only: overdue calls seen in this runner context, this included. */
|
|
65
|
+
overdue_seen?: number;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type FencedCallDiagnostics = {
|
|
69
|
+
/** A new physical send left the runner; a pending watchdog is disarmed. */
|
|
70
|
+
dispatched(): void;
|
|
71
|
+
/** The relay's response body was read; logs and arms the watchdog. */
|
|
72
|
+
responseArrived(): void;
|
|
73
|
+
/** The response was wrapped into the call's result (before the commit). */
|
|
74
|
+
wrapped(): void;
|
|
75
|
+
/** The call's receipt completion settled; logs once and disarms. */
|
|
76
|
+
settled(outcome: 'recorded' | 'failed'): void;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export type FencedCallDiagnosticsBudget = {
|
|
80
|
+
/** Whether a new fenced call's response/settlement lines are kept. */
|
|
81
|
+
admitCall(): boolean;
|
|
82
|
+
/** Counts an overdue call and says whether its warning is kept. */
|
|
83
|
+
admitOverdue(): { keep: boolean; seen: number };
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export function createFencedCallDiagnosticsBudget(
|
|
87
|
+
limits: {
|
|
88
|
+
detailedCalls?: number;
|
|
89
|
+
overdueFirst?: number;
|
|
90
|
+
overdueEvery?: number;
|
|
91
|
+
} = {},
|
|
92
|
+
): FencedCallDiagnosticsBudget {
|
|
93
|
+
const detailedCalls = limits.detailedCalls ?? FENCED_CALL_DETAILED_CALLS;
|
|
94
|
+
const overdueFirst = limits.overdueFirst ?? FENCED_CALL_OVERDUE_FIRST;
|
|
95
|
+
const overdueEvery = limits.overdueEvery ?? FENCED_CALL_OVERDUE_EVERY;
|
|
96
|
+
let calls = 0;
|
|
97
|
+
let overdue = 0;
|
|
98
|
+
return {
|
|
99
|
+
admitCall() {
|
|
100
|
+
calls += 1;
|
|
101
|
+
return calls <= detailedCalls;
|
|
102
|
+
},
|
|
103
|
+
admitOverdue() {
|
|
104
|
+
overdue += 1;
|
|
105
|
+
return {
|
|
106
|
+
keep: overdue <= overdueFirst || overdue % overdueEvery === 0,
|
|
107
|
+
seen: overdue,
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The runner's internal diagnostic sink: stderr, never the run log. */
|
|
114
|
+
export function writeFencedCallDiagnostic(
|
|
115
|
+
line: FencedCallDiagnosticLine,
|
|
116
|
+
): void {
|
|
117
|
+
console.warn(`${FENCED_CALL_DIAGNOSTIC_PREFIX} ${JSON.stringify(line)}`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function startFencedCallDiagnostics(input: {
|
|
121
|
+
tool: string;
|
|
122
|
+
callKeyHash: string;
|
|
123
|
+
attempt: number;
|
|
124
|
+
receiptWriter: 'call' | 'map' | 'none';
|
|
125
|
+
budget: FencedCallDiagnosticsBudget;
|
|
126
|
+
log?: (line: FencedCallDiagnosticLine) => void;
|
|
127
|
+
watchdogMs?: number;
|
|
128
|
+
}): FencedCallDiagnostics {
|
|
129
|
+
const watchdogMs = input.watchdogMs ?? FENCED_CALL_COMPLETION_WATCHDOG_MS;
|
|
130
|
+
const log = input.log ?? writeFencedCallDiagnostic;
|
|
131
|
+
const detailed = input.budget.admitCall();
|
|
132
|
+
const startedAtMs = Date.now();
|
|
133
|
+
let responses = 0;
|
|
134
|
+
let lastResponseAtMs: number | null = null;
|
|
135
|
+
let wrapped = false;
|
|
136
|
+
let watchdog: ReturnType<typeof setTimeout> | null = null;
|
|
137
|
+
let settled = false;
|
|
138
|
+
|
|
139
|
+
const line = (
|
|
140
|
+
event: FencedCallDiagnosticEvent,
|
|
141
|
+
level: 'info' | 'warn',
|
|
142
|
+
nowMs: number,
|
|
143
|
+
): FencedCallDiagnosticLine => ({
|
|
144
|
+
event,
|
|
145
|
+
level,
|
|
146
|
+
tool: input.tool,
|
|
147
|
+
call_key_hash: input.callKeyHash,
|
|
148
|
+
attempt: input.attempt,
|
|
149
|
+
elapsed_ms: Math.max(0, nowMs - startedAtMs),
|
|
150
|
+
responses,
|
|
151
|
+
...(lastResponseAtMs === null
|
|
152
|
+
? {}
|
|
153
|
+
: { since_response_ms: Math.max(0, nowMs - lastResponseAtMs) }),
|
|
154
|
+
wrapped,
|
|
155
|
+
});
|
|
156
|
+
const disarm = () => {
|
|
157
|
+
if (watchdog === null) return;
|
|
158
|
+
clearTimeout(watchdog);
|
|
159
|
+
watchdog = null;
|
|
160
|
+
};
|
|
161
|
+
const emit = (value: FencedCallDiagnosticLine): void => {
|
|
162
|
+
// A diagnostic must never fail the call it describes.
|
|
163
|
+
try {
|
|
164
|
+
log(value);
|
|
165
|
+
} catch {
|
|
166
|
+
// The sink owns its own failure reporting.
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
dispatched() {
|
|
172
|
+
if (settled) return;
|
|
173
|
+
disarm();
|
|
174
|
+
},
|
|
175
|
+
responseArrived() {
|
|
176
|
+
if (settled) return;
|
|
177
|
+
responses += 1;
|
|
178
|
+
const nowMs = Date.now();
|
|
179
|
+
lastResponseAtMs = nowMs;
|
|
180
|
+
if (detailed) emit(line('fenced_call_relay_response', 'info', nowMs));
|
|
181
|
+
disarm();
|
|
182
|
+
watchdog = setTimeout(() => {
|
|
183
|
+
watchdog = null;
|
|
184
|
+
if (settled) return;
|
|
185
|
+
const admitted = input.budget.admitOverdue();
|
|
186
|
+
if (!admitted.keep) return;
|
|
187
|
+
emit({
|
|
188
|
+
...line('fenced_call_completion_overdue', 'warn', Date.now()),
|
|
189
|
+
overdue_seen: admitted.seen,
|
|
190
|
+
});
|
|
191
|
+
}, watchdogMs);
|
|
192
|
+
(watchdog as { unref?: () => void }).unref?.();
|
|
193
|
+
},
|
|
194
|
+
wrapped() {
|
|
195
|
+
wrapped = true;
|
|
196
|
+
},
|
|
197
|
+
settled(outcome) {
|
|
198
|
+
if (settled) return;
|
|
199
|
+
settled = true;
|
|
200
|
+
disarm();
|
|
201
|
+
// A call that failed before any relay response is already reported by
|
|
202
|
+
// tool_call_failed; only a post-response settlement is news here.
|
|
203
|
+
if (!detailed || (outcome === 'failed' && responses === 0)) return;
|
|
204
|
+
emit({
|
|
205
|
+
...line('fenced_call_receipt_settled', 'info', Date.now()),
|
|
206
|
+
outcome,
|
|
207
|
+
receipt_writer: input.receiptWriter,
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
}
|