@rasputin-ai/node 0.11.4 → 0.12.0

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/index.js CHANGED
@@ -674,9 +674,6 @@ import {
674
674
  var DEFAULT_FULL_CAPTURE_DURATION_MS = 24 * 60 * 60 * 1e3;
675
675
  var MIN_FULL_CAPTURE_DURATION_MS = 1e3;
676
676
  var MAX_FULL_CAPTURE_DURATION_MS = 7 * 24 * 60 * 60 * 1e3;
677
- var sanitizeRecorderMode = (mode) => {
678
- return mode === "adaptive" ? "adaptive" : "full";
679
- };
680
677
  var sanitizeFullCaptureDurationMs = (value) => {
681
678
  if (typeof value !== "number" || !Number.isFinite(value)) {
682
679
  return DEFAULT_FULL_CAPTURE_DURATION_MS;
@@ -686,6 +683,68 @@ var sanitizeFullCaptureDurationMs = (value) => {
686
683
  Math.max(MIN_FULL_CAPTURE_DURATION_MS, Math.floor(value))
687
684
  );
688
685
  };
686
+ var sanitizeDynamicDurationSampling = (value) => value === true;
687
+
688
+ // src/execution-recorder/dynamic-duration-sampling.ts
689
+ var DYNAMIC_DURATION_SAMPLE_STAGES = [
690
+ { below: 10, divisor: 1 },
691
+ { below: 30, divisor: 2 },
692
+ { below: 100, divisor: 3 },
693
+ { below: 500, divisor: 11 },
694
+ { below: 1e3, divisor: 23 },
695
+ { below: 5e3, divisor: 53 }
696
+ ];
697
+ var DYNAMIC_DURATION_SAMPLE_TAIL_AFTER = 5e3;
698
+ var DYNAMIC_DURATION_SAMPLE_TAIL_DIVISOR = 100;
699
+ var DYNAMIC_DURATION_SAMPLE_RESET_MS = 60 * 60 * 1e3;
700
+ var MAX_DYNAMIC_DURATION_SAMPLE_BUCKETS = 4096;
701
+ var dynamicDurationSampleDivisor = (index) => {
702
+ for (const stage of DYNAMIC_DURATION_SAMPLE_STAGES) {
703
+ if (index < stage.below) return stage.divisor;
704
+ }
705
+ return DYNAMIC_DURATION_SAMPLE_TAIL_DIVISOR;
706
+ };
707
+ var shouldSampleDynamicDuration = (index) => {
708
+ return index % dynamicDurationSampleDivisor(index) === 0;
709
+ };
710
+ var nextDurationSampleIndex = (index) => {
711
+ if (index < Number.MAX_SAFE_INTEGER) return index + 1;
712
+ return DYNAMIC_DURATION_SAMPLE_TAIL_AFTER + (index - DYNAMIC_DURATION_SAMPLE_TAIL_AFTER + 1) % DYNAMIC_DURATION_SAMPLE_TAIL_DIVISOR;
713
+ };
714
+ var createDynamicDurationSampleBuckets = (options) => {
715
+ const buckets = /* @__PURE__ */ new Map();
716
+ const maxBuckets = options.maxBuckets ?? MAX_DYNAMIC_DURATION_SAMPLE_BUCKETS;
717
+ const resetMs = options.resetMs ?? DYNAMIC_DURATION_SAMPLE_RESET_MS;
718
+ let lastResetAtMs = options.nowMs();
719
+ const reset = () => {
720
+ buckets.clear();
721
+ lastResetAtMs = options.nowMs();
722
+ };
723
+ const resetTimer = setInterval(reset, resetMs);
724
+ resetTimer.unref?.();
725
+ return {
726
+ take: (executionType, callerFunctionId, functionId) => {
727
+ if (options.nowMs() - lastResetAtMs >= resetMs) reset();
728
+ const key = `${executionType}\0${callerFunctionId}\0${functionId}`;
729
+ const existing = buckets.get(key);
730
+ if (existing !== void 0) {
731
+ buckets.delete(key);
732
+ buckets.set(key, nextDurationSampleIndex(existing));
733
+ return shouldSampleDynamicDuration(existing);
734
+ }
735
+ while (buckets.size >= maxBuckets) {
736
+ const oldest = buckets.keys().next().value;
737
+ if (oldest === void 0) break;
738
+ buckets.delete(oldest);
739
+ }
740
+ buckets.set(key, nextDurationSampleIndex(0));
741
+ return shouldSampleDynamicDuration(0);
742
+ },
743
+ stop: () => {
744
+ clearInterval(resetTimer);
745
+ }
746
+ };
747
+ };
689
748
 
690
749
  // src/execution-recorder/error-observation.ts
691
750
  var bindings = /* @__PURE__ */ new WeakMap();
@@ -734,15 +793,17 @@ var KIND_SUPPRESSED = 4;
734
793
  var ARGS_OMITTED = Symbol("rasputin.argsOmitted");
735
794
  var NO_PARENT = 4294967295;
736
795
  var NO_SUPPRESSION = 4294967295;
796
+ var TIMING_UNAVAILABLE = -1n;
737
797
  var MAX_POOLED_JOURNALS = 8;
738
798
  var MAX_POOLED_JOURNAL_CAPACITY = 4096;
739
799
  var INITIAL_JOURNAL_STORAGE = 32;
740
800
  var BYTES_PER_EVENT = Uint8Array.BYTES_PER_ELEMENT + Uint32Array.BYTES_PER_ELEMENT * 4 + BigInt64Array.BYTES_PER_ELEMENT * 2;
741
- var DEFAULT_MAX_EVENTS_PER_EXECUTION = 500;
801
+ var DEFAULT_MAX_EVENTS_PER_EXECUTION = 1500;
742
802
  var MAX_JOURNAL_EVENTS = 16384;
743
803
  var elapsedMs = (startedAtNs, endedAtNs) => Number(endedAtNs - startedAtNs) / 1e6;
744
804
  var roundedMilliseconds = (nanoseconds) => Math.round(Number(nanoseconds) / 1e6 * 1e4) / 1e4;
745
805
  var relativeMs = (relativeNs) => Number(relativeNs) / 1e6;
806
+ var measuredRelativeMs = (relativeNs) => relativeNs === TIMING_UNAVAILABLE ? void 0 : relativeMs(relativeNs);
746
807
  var sanitizeJournalCapacity = (value) => {
747
808
  const requested = value ?? DEFAULT_MAX_EVENTS_PER_EXECUTION;
748
809
  if (!Number.isFinite(requested)) return DEFAULT_MAX_EVENTS_PER_EXECUTION;
@@ -924,44 +985,53 @@ var ExecutionJournal = class {
924
985
  if (!functionId) return void 0;
925
986
  const parentCallId = this.parentCallId[index] ?? NO_PARENT;
926
987
  const payload = this.payloads[index];
988
+ const timestampMs = measuredRelativeMs(this.timestampNs[index] ?? TIMING_UNAVAILABLE);
927
989
  return {
928
990
  type: "function_enter",
929
991
  callId: this.callId[index] ?? 0,
930
992
  functionId,
931
- timestampMs: relativeMs(this.timestampNs[index] ?? 0n),
993
+ ...timestampMs === void 0 ? {} : { timestampMs },
932
994
  ...payload === ARGS_OMITTED ? { argsOmitted: true } : { args: Array.isArray(payload) ? payload : [] },
933
995
  ...parentCallId === NO_PARENT ? {} : { parentCallId }
934
996
  };
935
997
  }
936
998
  if (kind === KIND_EXIT) {
937
999
  const payload = this.payloads[index];
1000
+ const timestampMs = measuredRelativeMs(this.timestampNs[index] ?? TIMING_UNAVAILABLE);
1001
+ const durationMs = measuredRelativeMs(this.durationNs[index] ?? TIMING_UNAVAILABLE);
938
1002
  return {
939
1003
  type: "function_exit",
940
1004
  callId: this.callId[index] ?? 0,
941
- timestampMs: relativeMs(this.timestampNs[index] ?? 0n),
942
- durationMs: relativeMs(this.durationNs[index] ?? 0n),
1005
+ ...timestampMs === void 0 ? {} : { timestampMs },
1006
+ ...durationMs === void 0 ? {} : { durationMs },
943
1007
  ...payload === ARGS_OMITTED ? {} : { returnValue: payload }
944
1008
  };
945
1009
  }
946
1010
  if (kind === KIND_THROW) {
1011
+ const timestampMs = measuredRelativeMs(this.timestampNs[index] ?? TIMING_UNAVAILABLE);
1012
+ const durationMs = measuredRelativeMs(this.durationNs[index] ?? TIMING_UNAVAILABLE);
947
1013
  return {
948
1014
  type: "function_throw",
949
1015
  callId: this.callId[index] ?? 0,
950
- timestampMs: relativeMs(this.timestampNs[index] ?? 0n),
951
- durationMs: relativeMs(this.durationNs[index] ?? 0n),
1016
+ ...timestampMs === void 0 ? {} : { timestampMs },
1017
+ ...durationMs === void 0 ? {} : { durationMs },
952
1018
  error: this.payloads[index]
953
1019
  };
954
1020
  }
955
1021
  if (kind === KIND_SUPPRESSED) {
956
1022
  const group = this.suppressions[this.suppressionIndex[index] ?? 0];
957
1023
  if (!group) return void 0;
1024
+ const sampledDurationCount = group.sampledDurationCount;
1025
+ const allTimed = sampledDurationCount === group.count && group.count > 0;
958
1026
  return {
959
1027
  type: "function_calls_suppressed",
960
1028
  functionId: group.functionId,
961
- timestampMs: elapsedMs(executionStartedAtNs, group.firstTimestampNs),
962
- lastTimestampMs: elapsedMs(executionStartedAtNs, group.lastTimestampNs),
963
1029
  suppressedCallCount: group.count,
964
- totalDurationMs: roundedMilliseconds(group.totalDurationNs),
1030
+ sampledDurationCount,
1031
+ ...group.firstTimed ? { timestampMs: elapsedMs(executionStartedAtNs, group.firstTimestampNs) } : {},
1032
+ ...group.lastTimed ? { lastTimestampMs: elapsedMs(executionStartedAtNs, group.lastTimestampNs) } : {},
1033
+ ...allTimed ? { totalDurationMs: roundedMilliseconds(group.sampledDurationNs) } : {},
1034
+ ...sampledDurationCount > 0 ? { sampledDurationMs: roundedMilliseconds(group.sampledDurationNs) } : {},
965
1035
  ...group.parentCallId === void 0 ? {} : { parentCallId: group.parentCallId }
966
1036
  };
967
1037
  }
@@ -1118,6 +1188,69 @@ var ExecutionJournalPool = class {
1118
1188
  var EVENT_PAIR_BASE_ESTIMATED_BYTES = 512;
1119
1189
  var estimatedCallBytesFor = (functionId) => EVENT_PAIR_BASE_ESTIMATED_BYTES + Buffer.byteLength(functionId, "utf8") * 2;
1120
1190
 
1191
+ // src/execution-recorder/publish-runtime-state.ts
1192
+ var measured = (value) => typeof value === "number";
1193
+ var eventsAreFullyTimed = (events) => {
1194
+ for (const event of events) {
1195
+ if (event.type === "function_enter" || event.type === "awaited" || event.type === "expression_observed") {
1196
+ if (!measured(event.timestampMs)) return false;
1197
+ continue;
1198
+ }
1199
+ if (event.type === "function_exit" || event.type === "function_throw") {
1200
+ if (!measured(event.timestampMs) || !measured(event.durationMs)) return false;
1201
+ continue;
1202
+ }
1203
+ const sampled = event.sampledDurationCount ?? (measured(event.totalDurationMs) ? event.suppressedCallCount : 0);
1204
+ if (!measured(event.timestampMs) || !measured(event.totalDurationMs) || sampled !== event.suppressedCallCount) {
1205
+ return false;
1206
+ }
1207
+ }
1208
+ return true;
1209
+ };
1210
+ var retainedTimingsCoverage = (events) => {
1211
+ let sawMeasured = false;
1212
+ let sawMissing = false;
1213
+ const mark = (complete) => {
1214
+ if (complete) sawMeasured = true;
1215
+ else sawMissing = true;
1216
+ };
1217
+ for (const event of events) {
1218
+ if (event.type === "function_enter" || event.type === "awaited" || event.type === "expression_observed") {
1219
+ mark(measured(event.timestampMs));
1220
+ continue;
1221
+ }
1222
+ if (event.type === "function_exit" || event.type === "function_throw") {
1223
+ const stamped = measured(event.timestampMs);
1224
+ const timed = measured(event.durationMs);
1225
+ if (stamped && timed) mark(true);
1226
+ else if (!stamped && !timed) mark(false);
1227
+ else {
1228
+ sawMeasured = true;
1229
+ sawMissing = true;
1230
+ }
1231
+ continue;
1232
+ }
1233
+ const sampled = event.sampledDurationCount ?? (measured(event.totalDurationMs) ? event.suppressedCallCount : 0);
1234
+ if (sampled > 0) sawMeasured = true;
1235
+ if (sampled < event.suppressedCallCount || !measured(event.timestampMs)) sawMissing = true;
1236
+ }
1237
+ if (sawMeasured && sawMissing) return "partial";
1238
+ if (sawMeasured) return "full";
1239
+ return "none";
1240
+ };
1241
+ var asFullyTimedEvents = (events) => events.map((event) => {
1242
+ if (event.type !== "function_calls_suppressed") return event;
1243
+ return {
1244
+ type: "function_calls_suppressed",
1245
+ functionId: event.functionId,
1246
+ suppressedCallCount: event.suppressedCallCount,
1247
+ ...event.parentCallId === void 0 ? {} : { parentCallId: event.parentCallId },
1248
+ ...event.timestampMs === void 0 ? {} : { timestampMs: event.timestampMs },
1249
+ ...event.lastTimestampMs === void 0 ? {} : { lastTimestampMs: event.lastTimestampMs },
1250
+ ...event.totalDurationMs === void 0 ? {} : { totalDurationMs: event.totalDurationMs }
1251
+ };
1252
+ });
1253
+
1121
1254
  // src/execution-recorder/recorder-memory-budget.ts
1122
1255
  var EXECUTION_BASE_ESTIMATED_BYTES = 1024;
1123
1256
  var SUMMARY_EVENT_BASE_ESTIMATED_BYTES = 256;
@@ -1301,7 +1434,7 @@ var dropEventValues = (events) => {
1301
1434
  const marker = () => rasputinUnavailable(VALUE_OMITTED_REASON);
1302
1435
  const bounded2 = events.map((event) => {
1303
1436
  if (event.type === "function_enter") {
1304
- if (event.args === void 0) return { ...event };
1437
+ if (event.args === void 0) return event;
1305
1438
  dropped += event.args.length;
1306
1439
  return { ...event, args: event.args.map(marker) };
1307
1440
  }
@@ -1313,7 +1446,7 @@ var dropEventValues = (events) => {
1313
1446
  dropped++;
1314
1447
  return { ...event, error: marker() };
1315
1448
  }
1316
- return { ...event };
1449
+ return event;
1317
1450
  });
1318
1451
  return { events: bounded2, dropped };
1319
1452
  };
@@ -1354,7 +1487,7 @@ var minimalState = (state, size) => {
1354
1487
  startedAt: truncateUtf8(state.startedAt, 128) ?? "",
1355
1488
  durationMs: Number.isFinite(state.durationMs) ? state.durationMs : 0,
1356
1489
  recorder: {
1357
- inlineWallTimeMs: Number.isFinite(state.recorder?.inlineWallTimeMs) ? state.recorder.inlineWallTimeMs : 0
1490
+ inlineWallTimeMs: state.recorder && Number.isFinite(state.recorder.inlineWallTimeMs) ? state.recorder.inlineWallTimeMs : 0
1358
1491
  },
1359
1492
  execution,
1360
1493
  functions: [],
@@ -1372,20 +1505,14 @@ var enforceRuntimeStateSizeBudget = (input) => {
1372
1505
  const originalBytes = existingSize?.originalBytes ?? initialBytes;
1373
1506
  const size = sizeMetadata(originalBytes);
1374
1507
  let state = input;
1508
+ const captureProfile = {
1509
+ ...state.captureProfile,
1510
+ functionValues: state.captureProfile.functionValues === "none" ? "none" : "selective"
1511
+ };
1375
1512
  const stripped = dropEventValues(state.events);
1376
1513
  size.eventValuesDropped += stripped.dropped;
1377
1514
  state = settleFinalBytes(
1378
- withSizeMetadata(
1379
- {
1380
- ...state,
1381
- captureProfile: {
1382
- ...state.captureProfile,
1383
- functionValues: state.captureProfile.functionValues === "none" ? "none" : "selective"
1384
- },
1385
- events: stripped.events
1386
- },
1387
- size
1388
- )
1515
+ withSizeMetadata({ ...state, captureProfile, events: stripped.events }, size)
1389
1516
  );
1390
1517
  if (encodedBytes(state) <= MAX_RUNTIME_STATE_BYTES) return state;
1391
1518
  size.eventsDropped += state.events.length;
@@ -2543,6 +2670,7 @@ var warnIfMissingAsyncContextFrame = () => {
2543
2670
 
2544
2671
  // src/execution-recorder/execution-recorder.ts
2545
2672
  var DEFAULT_MAX_ACTIVE_MEMORY_BYTES = 64 * 1024 * 1024;
2673
+ var DEFAULT_MAX_CAPTURED_CALLS_PER_FUNCTION = 1;
2546
2674
  var DEFAULT_MAX_EXECUTION_HOLD_MS = 6e4;
2547
2675
  var DEFAULT_MAX_RETAINED_ERROR_RECORDINGS = 32;
2548
2676
  var EMPTY_ARGS = [];
@@ -2660,7 +2788,9 @@ var noOpExecution = {
2660
2788
  resume: (value) => value
2661
2789
  }),
2662
2790
  trace: (_functionId, fn) => fn,
2663
- getStats: () => ({ ...emptyStats })
2791
+ getStats: () => ({ ...emptyStats }),
2792
+ close: () => {
2793
+ }
2664
2794
  };
2665
2795
  var mergeExecutionMetadata = (target, metadata) => {
2666
2796
  if (metadata.kind) target.kind = metadata.kind;
@@ -2672,35 +2802,44 @@ var newRepeatedGroup = (plan) => ({
2672
2802
  functionId: plan.functionId,
2673
2803
  runtimePlanId: plan.runtimePlanId
2674
2804
  });
2675
- var newSuppression = (group, parentCallId, startedAtNs, endedAtNs) => ({
2676
- count: 1,
2677
- firstTimestampNs: startedAtNs,
2678
- lastTimestampNs: endedAtNs,
2679
- totalDurationNs: endedAtNs - startedAtNs,
2680
- functionId: group.functionId,
2681
- runtimePlanId: group.runtimePlanId,
2682
- ...parentCallId === void 0 ? {} : { parentCallId },
2683
- storageIndex: -1,
2684
- retainedIndex: -1
2685
- });
2805
+ var newSuppression = (group, parentCallId, startedAtNs, endedAtNs, timed) => {
2806
+ const durationNs = timed ? endedAtNs - startedAtNs : 0n;
2807
+ return {
2808
+ count: 1,
2809
+ firstTimestampNs: timed ? startedAtNs : 0n,
2810
+ lastTimestampNs: timed ? endedAtNs : 0n,
2811
+ sampledDurationNs: durationNs,
2812
+ sampledDurationCount: timed ? 1 : 0,
2813
+ firstTimed: timed,
2814
+ lastTimed: timed,
2815
+ functionId: group.functionId,
2816
+ runtimePlanId: group.runtimePlanId,
2817
+ ...parentCallId === void 0 ? {} : { parentCallId },
2818
+ storageIndex: -1,
2819
+ retainedIndex: -1
2820
+ };
2821
+ };
2686
2822
  var EMPTY_POLICY_SNAPSHOT = /* @__PURE__ */ new Map();
2687
2823
  var EMPTY_SESSION_SNAPSHOT = /* @__PURE__ */ new Map();
2688
2824
  var createExecutionRecorder = (options, hooks = {}) => {
2689
2825
  if (!options?.enabled) return noOpExecution;
2690
2826
  warnIfMissingAsyncContextFrame();
2691
- const recorderMode = sanitizeRecorderMode(options.mode);
2827
+ const adaptiveEnabled = options.adaptive?.enabled === true;
2692
2828
  const fullCaptureDurationMs = sanitizeFullCaptureDurationMs(
2693
2829
  options.adaptive?.fullCaptureDurationMs
2694
2830
  );
2695
- const localActivations = /* @__PURE__ */ new Map();
2831
+ const durationSamplingEnabled = adaptiveEnabled && sanitizeDynamicDurationSampling(options.adaptive?.dynamicDurationSampling);
2832
+ const readCallClock = () => process.hrtime.bigint();
2696
2833
  const nowMs = () => hooks.nowMs?.() ?? Date.now();
2834
+ const durationSamples = durationSamplingEnabled ? createDynamicDurationSampleBuckets({ nowMs }) : void 0;
2835
+ const localActivations = /* @__PURE__ */ new Map();
2697
2836
  const policySnapshotFor = () => hooks.policySnapshot?.() ?? localActivations;
2698
2837
  const keyIsActive = (snapshot, key, atMs) => {
2699
2838
  const expiresAt = snapshot.get(key);
2700
2839
  return expiresAt !== void 0 && expiresAt > atMs;
2701
2840
  };
2702
2841
  const captureValuesFor = (metadata, snapshot, atMs) => {
2703
- if (recorderMode !== "adaptive") return true;
2842
+ if (!adaptiveEnabled) return true;
2704
2843
  const key = executionTypeKey(metadata);
2705
2844
  if (!key) return false;
2706
2845
  return keyIsActive(snapshot, key, atMs);
@@ -2742,7 +2881,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
2742
2881
  const maxEventsPerExecution = sanitizeJournalCapacity(options.maxEventsPerExecution);
2743
2882
  const maxCapturedCallsPerFunction = Math.max(
2744
2883
  1,
2745
- Math.floor(options.maxCapturedCallsPerFunction ?? 3)
2884
+ Math.floor(options.maxCapturedCallsPerFunction ?? DEFAULT_MAX_CAPTURED_CALLS_PER_FUNCTION)
2746
2885
  );
2747
2886
  const maxActiveMemoryBytes = Math.max(
2748
2887
  0,
@@ -2852,7 +2991,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
2852
2991
  return captureValue(recording, value);
2853
2992
  };
2854
2993
  const admitSession = (recording, session) => {
2855
- const wasLight = recorderMode === "adaptive" && !recording.captureValues;
2994
+ const wasLight = adaptiveEnabled && !recording.captureValues;
2856
2995
  recording.retainSuccess = true;
2857
2996
  recording.sessionId = session.sessionId;
2858
2997
  recording.captureValues = true;
@@ -2877,6 +3016,18 @@ var createExecutionRecorder = (options, hooks = {}) => {
2877
3016
  }
2878
3017
  };
2879
3018
  const skipCapture = (store, plan) => store.suppressCapture || plan.excluded || Boolean(store.recording.sessionExcludes?.(plan.definition));
3019
+ const durationSamplingApplies = (recording) => durationSamplingEnabled && recording.identityResolved === true && !recording.captureValues && !recording.retainSuccess;
3020
+ const callerStore = (store, functionId, callId) => ({
3021
+ ...store,
3022
+ currentFunctionId: functionId,
3023
+ ...callId === void 0 ? {} : { currentCallId: callId }
3024
+ });
3025
+ const decideCallTiming = (recording, plan, callerFunctionId) => {
3026
+ if (!durationSamplingApplies(recording) || !durationSamples) return true;
3027
+ const typeKey = executionTypeKey(recording.execution);
3028
+ if (!typeKey) return true;
3029
+ return durationSamples.take(typeKey, callerFunctionId ?? "", plan.functionId);
3030
+ };
2880
3031
  const capturedCallLimitFor = (recording) => recording.sessionMaxCapturedCalls ?? maxCapturedCallsPerFunction;
2881
3032
  const tryAdmitLiveSession = (recording) => {
2882
3033
  if (recording.retainSuccess || recording.finished) return;
@@ -2902,7 +3053,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
2902
3053
  if (!key) return;
2903
3054
  recording.identityResolved = true;
2904
3055
  tryAdmitFromStartSnapshot(recording);
2905
- if (recording.captureValues || recorderMode !== "adaptive") return;
3056
+ if (recording.captureValues || !adaptiveEnabled) return;
2906
3057
  if (keyIsActive(recording.policySnapshot, key, recording.startedAtMs)) {
2907
3058
  recording.captureValues = true;
2908
3059
  stats.adaptiveLightExecutions = Math.max(0, stats.adaptiveLightExecutions - 1);
@@ -2910,7 +3061,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
2910
3061
  }
2911
3062
  };
2912
3063
  const maybeActivateAdaptive = (recording) => {
2913
- if (recorderMode !== "adaptive" || recording.adaptiveActivated) return;
3064
+ if (!adaptiveEnabled || recording.adaptiveActivated) return;
2914
3065
  if (isHttpClientErrorStatus(recording.execution.request?.status)) return;
2915
3066
  const key = executionTypeKey(recording.execution);
2916
3067
  if (!key) return;
@@ -3011,11 +3162,12 @@ var createExecutionRecorder = (options, hooks = {}) => {
3011
3162
  };
3012
3163
  }
3013
3164
  const droppedEvents = Boolean(truncated?.eventsDropped || capture?.eventsDropped);
3165
+ const evidence = retainedTimingsCoverage(events);
3014
3166
  return {
3015
3167
  source,
3016
3168
  functionBoundaries: droppedEvents ? "partial" : "full",
3017
3169
  functionValues: recording.captureValues ? eventsHaveOmittedValues(events) ? "selective" : "full" : "none",
3018
- timings: droppedEvents ? "partial" : "full"
3170
+ timings: droppedEvents && evidence === "full" ? "partial" : evidence
3019
3171
  };
3020
3172
  };
3021
3173
  const stateFrom = (recording, endedAtNs = process.hrtime.bigint()) => {
@@ -3069,9 +3221,11 @@ var createExecutionRecorder = (options, hooks = {}) => {
3069
3221
  recording.journal = void 0;
3070
3222
  }
3071
3223
  }
3224
+ const captureProfile = resolveCaptureProfile(recording, events, truncated, capture);
3225
+ const fullyTimed = eventsAreFullyTimed(events);
3072
3226
  const state = {
3073
3227
  version: 4,
3074
- captureProfile: resolveCaptureProfile(recording, events, truncated, capture),
3228
+ captureProfile,
3075
3229
  executionId: recording.executionId,
3076
3230
  startedAt: new Date(recording.startedAtMs).toISOString(),
3077
3231
  durationMs: elapsedMs2(recording.startedAtNs, endedAtNs),
@@ -3081,7 +3235,8 @@ var createExecutionRecorder = (options, hooks = {}) => {
3081
3235
  ...recording.execution.request ? { request: { ...recording.execution.request } } : {}
3082
3236
  },
3083
3237
  functions: functions.slice(),
3084
- events: events.slice(),
3238
+ events: fullyTimed ? asFullyTimedEvents(events) : events.slice(),
3239
+ ...fullyTimed || !durationSamplingEnabled ? {} : { durationSampling: { policy: "progressive" } },
3085
3240
  ...truncated ? { truncated: { ...truncated } } : {},
3086
3241
  ...capture ? { capture: { ...capture } } : {}
3087
3242
  };
@@ -3351,7 +3506,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
3351
3506
  }
3352
3507
  };
3353
3508
  };
3354
- const captureCompletedThrow = (recording, plan, args, parentCallId, startedAtNs, error, capturedArgs) => {
3509
+ const captureCompletedThrow = (recording, plan, args, parentCallId, startedAtNs, error, timed, capturedArgs) => {
3355
3510
  if (!recording.journal) {
3356
3511
  return;
3357
3512
  }
@@ -3361,17 +3516,17 @@ var createExecutionRecorder = (options, hooks = {}) => {
3361
3516
  const callId = ++recording.nextCallId;
3362
3517
  const capturedError = serializedError(recording, error, callId);
3363
3518
  const recordedArgs = capturedArgs ?? (recording.captureValues ? mapArrayLike(args, (argument) => captureValue(recording, argument)) : ARGS_OMITTED);
3364
- const endedAtNs = process.hrtime.bigint();
3519
+ const endedAtNs = readCallClock();
3365
3520
  const droppedBefore = recording.journal.dropped;
3366
3521
  const retained = recording.journal.forceCompletedCall(
3367
3522
  plan.runtimePlanId,
3368
3523
  callId,
3369
3524
  parentCallId,
3370
- startedAtNs - recording.startedAtNs,
3525
+ timed ? startedAtNs - recording.startedAtNs : TIMING_UNAVAILABLE,
3371
3526
  recordedArgs,
3372
3527
  KIND_THROW,
3373
3528
  endedAtNs - recording.startedAtNs,
3374
- endedAtNs - startedAtNs,
3529
+ timed ? endedAtNs - startedAtNs : TIMING_UNAVAILABLE,
3375
3530
  capturedError.value
3376
3531
  );
3377
3532
  if (retained) {
@@ -3382,17 +3537,23 @@ var createExecutionRecorder = (options, hooks = {}) => {
3382
3537
  }
3383
3538
  countDroppedEvents(recording, droppedBefore);
3384
3539
  };
3385
- const recordSuppressedCall = (recording, group, parentCallId, startedAtNs, endedAtNs) => {
3540
+ const recordSuppressedCall = (recording, group, parentCallId, startedAtNs, endedAtNs, timed) => {
3386
3541
  stats.repeatedCallsSuppressed++;
3387
3542
  if (!group.suppressed) {
3388
- group.suppressed = newSuppression(group, parentCallId, startedAtNs, endedAtNs);
3543
+ group.suppressed = newSuppression(group, parentCallId, startedAtNs, endedAtNs, timed);
3389
3544
  appendSuppressedPlaceholder(recording, group.suppressed);
3390
3545
  return;
3391
3546
  }
3392
3547
  const suppressed = group.suppressed;
3393
3548
  suppressed.count++;
3394
- suppressed.lastTimestampNs = endedAtNs;
3395
- suppressed.totalDurationNs += endedAtNs - startedAtNs;
3549
+ if (timed) {
3550
+ suppressed.lastTimestampNs = endedAtNs;
3551
+ suppressed.lastTimed = true;
3552
+ suppressed.sampledDurationCount++;
3553
+ suppressed.sampledDurationNs += endedAtNs - startedAtNs;
3554
+ } else {
3555
+ suppressed.lastTimed = false;
3556
+ }
3396
3557
  if (suppressed.retainedIndex < 0) {
3397
3558
  appendSuppressedPlaceholder(recording, suppressed);
3398
3559
  }
@@ -3505,10 +3666,10 @@ var createExecutionRecorder = (options, hooks = {}) => {
3505
3666
  };
3506
3667
  const identityComplete = executionTypeKey(execution) !== void 0;
3507
3668
  const captureValues = captureValuesFor(execution, livePolicy, startedAtMs);
3508
- const policySnapshot = recorderMode === "adaptive" && !identityComplete ? new Map(livePolicy) : EMPTY_POLICY_SNAPSHOT;
3669
+ const policySnapshot = adaptiveEnabled && !identityComplete ? new Map(livePolicy) : EMPTY_POLICY_SNAPSHOT;
3509
3670
  const liveSessions = hooks.sessionCaptureSnapshot?.() ?? EMPTY_SESSION_SNAPSHOT;
3510
3671
  const sessionCaptureSnapshot = identityComplete ? EMPTY_SESSION_SNAPSHOT : new Map(liveSessions);
3511
- if (recorderMode === "adaptive") {
3672
+ if (adaptiveEnabled) {
3512
3673
  if (captureValues) stats.adaptiveFullExecutions++;
3513
3674
  else stats.adaptiveLightExecutions++;
3514
3675
  }
@@ -3655,25 +3816,36 @@ var createExecutionRecorder = (options, hooks = {}) => {
3655
3816
  if (group.observedCalls === 1) journal?.notePlan(plan.runtimePlanId);
3656
3817
  } catch {
3657
3818
  }
3819
+ const timed = durationSamplingEnabled ? decideCallTiming(recording, plan, store.currentFunctionId) : true;
3658
3820
  if (group.observedCalls > capturedCallLimitFor(recording)) {
3659
- const startedAtNs2 = process.hrtime.bigint();
3821
+ const startedAtNs2 = timed ? readCallClock() : 0n;
3660
3822
  try {
3661
- const result = runStore(store, function __rasputinHandleRun__5() {
3662
- return callback();
3663
- });
3664
- recordSuppressedCall(recording, group, parentCallId, startedAtNs2, process.hrtime.bigint());
3823
+ const result = runStore(
3824
+ callerStore(store, plan.functionId),
3825
+ function __rasputinHandleRun__5() {
3826
+ return callback();
3827
+ }
3828
+ );
3829
+ recordSuppressedCall(
3830
+ recording,
3831
+ group,
3832
+ parentCallId,
3833
+ startedAtNs2,
3834
+ timed ? readCallClock() : 0n,
3835
+ timed
3836
+ );
3665
3837
  settleInFlight(recording);
3666
3838
  return result;
3667
3839
  } catch (error) {
3668
- captureCompletedThrow(recording, plan, args, parentCallId, startedAtNs2, error);
3840
+ captureCompletedThrow(recording, plan, args, parentCallId, startedAtNs2, error, timed);
3669
3841
  settleInFlight(recording);
3670
3842
  throw error;
3671
3843
  }
3672
3844
  }
3673
- const startedAtNs = process.hrtime.bigint();
3845
+ const startedAtNs = timed ? readCallClock() : 0n;
3674
3846
  if (!journal) {
3675
3847
  memoryBudget.reserveCall(recording.memory, plan.estimatedCallBytes);
3676
- return runStore(store, function __rasputinHandleRun__5() {
3848
+ return runStore(callerStore(store, plan.functionId), function __rasputinHandleRun__5() {
3677
3849
  return observeRecordedCallback(
3678
3850
  recording,
3679
3851
  recorderStartedAtNs,
@@ -3692,38 +3864,40 @@ var createExecutionRecorder = (options, hooks = {}) => {
3692
3864
  countDroppedEvents(recording, droppedBefore);
3693
3865
  settleInFlight(recording);
3694
3866
  };
3695
- return runStore(store, function __rasputinHandleRun__5() {
3867
+ return runStore(callerStore(store, plan.functionId), function __rasputinHandleRun__5() {
3696
3868
  return observeRecordedCallback(
3697
3869
  recording,
3698
3870
  recorderStartedAtNs,
3699
3871
  callback,
3700
3872
  captureSuccess,
3701
3873
  (error) => {
3702
- captureCompletedThrow(recording, plan, args, parentCallId, startedAtNs, error);
3874
+ captureCompletedThrow(recording, plan, args, parentCallId, startedAtNs, error, timed);
3703
3875
  settleInFlight(recording);
3704
3876
  }
3705
3877
  );
3706
3878
  });
3707
3879
  }
3708
3880
  if (!memoryBudget.reserveCall(recording.memory, plan.estimatedCallBytes)) {
3709
- return observeRecordedCallback(
3710
- recording,
3711
- recorderStartedAtNs,
3712
- callback,
3713
- () => settleInFlight(recording),
3714
- (_error) => {
3715
- settleInFlight(recording);
3716
- }
3717
- );
3881
+ return runStore(callerStore(store, plan.functionId), function __rasputinHandleRun__5() {
3882
+ return observeRecordedCallback(
3883
+ recording,
3884
+ recorderStartedAtNs,
3885
+ callback,
3886
+ () => settleInFlight(recording),
3887
+ (_error) => {
3888
+ settleInFlight(recording);
3889
+ }
3890
+ );
3891
+ });
3718
3892
  }
3719
3893
  const callId = ++recording.nextCallId;
3720
- const enterTimestampNs = process.hrtime.bigint() - recording.startedAtNs;
3894
+ const enterTimestampNs = timed ? readCallClock() - recording.startedAtNs : TIMING_UNAVAILABLE;
3721
3895
  const capturedArgs = enterPayload(recording, omitCallValues, args);
3722
3896
  try {
3723
3897
  journal.startCall(plan.runtimePlanId, callId, parentCallId, enterTimestampNs, capturedArgs);
3724
3898
  } catch {
3725
3899
  journal.dropCall();
3726
- return runStore(store, function __rasputinHandleRun__5() {
3900
+ return runStore(callerStore(store, plan.functionId), function __rasputinHandleRun__5() {
3727
3901
  return observeRecordedCallback(
3728
3902
  recording,
3729
3903
  recorderStartedAtNs,
@@ -3735,7 +3909,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
3735
3909
  );
3736
3910
  });
3737
3911
  }
3738
- const callStore = { recording, currentCallId: callId };
3912
+ const callStore = callerStore(store, plan.functionId, callId);
3739
3913
  return runStore(callStore, function __rasputinHandleRun__5() {
3740
3914
  return observeRecordedCallback(
3741
3915
  recording,
@@ -3743,15 +3917,25 @@ var createExecutionRecorder = (options, hooks = {}) => {
3743
3917
  callback,
3744
3918
  (value) => {
3745
3919
  if (recording.journal) {
3746
- const endedAtNs = process.hrtime.bigint();
3920
+ const endedAtNs = timed ? readCallClock() : void 0;
3747
3921
  const returnValue = exitPayload(recording, omitCallValues, value);
3748
- recording.journal.finishCall(
3749
- KIND_EXIT,
3750
- callId,
3751
- endedAtNs - recording.startedAtNs,
3752
- endedAtNs - startedAtNs,
3753
- returnValue
3754
- );
3922
+ if (endedAtNs !== void 0) {
3923
+ recording.journal.finishCall(
3924
+ KIND_EXIT,
3925
+ callId,
3926
+ endedAtNs - recording.startedAtNs,
3927
+ endedAtNs - startedAtNs,
3928
+ returnValue
3929
+ );
3930
+ } else {
3931
+ recording.journal.finishCall(
3932
+ KIND_EXIT,
3933
+ callId,
3934
+ TIMING_UNAVAILABLE,
3935
+ TIMING_UNAVAILABLE,
3936
+ returnValue
3937
+ );
3938
+ }
3755
3939
  stats.functionCallsCaptured++;
3756
3940
  }
3757
3941
  settleInFlight(recording);
@@ -3762,12 +3946,12 @@ var createExecutionRecorder = (options, hooks = {}) => {
3762
3946
  return;
3763
3947
  }
3764
3948
  const capturedError = serializedError(recording, error, callId);
3765
- const endedAtNs = process.hrtime.bigint();
3949
+ const endedAtNs = readCallClock();
3766
3950
  recording.journal.finishCall(
3767
3951
  KIND_THROW,
3768
3952
  callId,
3769
3953
  endedAtNs - recording.startedAtNs,
3770
- endedAtNs - startedAtNs,
3954
+ timed ? endedAtNs - startedAtNs : TIMING_UNAVAILABLE,
3771
3955
  capturedError.value
3772
3956
  );
3773
3957
  stats.functionCallsCaptured++;
@@ -3779,21 +3963,22 @@ var createExecutionRecorder = (options, hooks = {}) => {
3779
3963
  };
3780
3964
  const noopHandle2 = passthroughHandle();
3781
3965
  class CallFrame {
3782
- constructor(mode, recording, parentStore, activeStore, plan, args, omitCallValues, parentCallId, startedAtNs, callId, group, captureDroppedThrow) {
3966
+ constructor(mode, recording, parentStore, activeStore, plan, args, omitCallValues, parentCallId, startedAtNs, timed, callId, group, captureDroppedThrow) {
3783
3967
  this.mode = mode;
3784
3968
  this.status = "open";
3785
3969
  this.pendingReturn = void 0;
3786
3970
  this.ended = false;
3787
3971
  this.suspended = false;
3788
3972
  this.startedAtNs = startedAtNs;
3973
+ this.timed = timed;
3789
3974
  this.callId = callId;
3790
3975
  this.recording = recording;
3791
3976
  this.plan = plan;
3792
3977
  this.args = args;
3793
3978
  this.omitCallValues = omitCallValues;
3794
3979
  this.parentCallId = parentCallId;
3795
- this.parentStore = parentStore;
3796
3980
  this.activeStore = activeStore;
3981
+ this.parentStore = parentStore;
3797
3982
  this.group = group;
3798
3983
  this.captureDroppedThrow = captureDroppedThrow;
3799
3984
  }
@@ -3821,6 +4006,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
3821
4006
  this.parentCallId,
3822
4007
  this.startedAtNs,
3823
4008
  error,
4009
+ this.timed,
3824
4010
  this.recording.captureValues ? void 0 : ARGS_OMITTED
3825
4011
  );
3826
4012
  } else if (this.mode === "dropped" && this.captureDroppedThrow && this.plan) {
@@ -3831,6 +4017,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
3831
4017
  this.parentCallId,
3832
4018
  this.startedAtNs,
3833
4019
  error,
4020
+ this.timed,
3834
4021
  this.recording.captureValues ? void 0 : ARGS_OMITTED
3835
4022
  );
3836
4023
  }
@@ -3849,7 +4036,8 @@ var createExecutionRecorder = (options, hooks = {}) => {
3849
4036
  this.group,
3850
4037
  this.parentCallId,
3851
4038
  this.startedAtNs,
3852
- process.hrtime.bigint()
4039
+ this.timed ? readCallClock() : 0n,
4040
+ this.timed
3853
4041
  );
3854
4042
  } else if (this.mode === "dropped") {
3855
4043
  const droppedBefore = this.recording.journal?.dropped ?? 0;
@@ -3920,47 +4108,59 @@ var createExecutionRecorder = (options, hooks = {}) => {
3920
4108
  };
3921
4109
  const writeCapturedExit = (frame, value) => {
3922
4110
  if (!frame.recording.journal) return;
3923
- const endedAtNs = process.hrtime.bigint();
4111
+ const endedAtNs = frame.timed ? readCallClock() : void 0;
3924
4112
  const returnValue = exitPayload(frame.recording, frame.omitCallValues, value);
3925
- frame.recording.journal.finishCall(
3926
- KIND_EXIT,
3927
- frame.callId,
3928
- endedAtNs - frame.recording.startedAtNs,
3929
- endedAtNs - frame.startedAtNs,
3930
- returnValue
3931
- );
4113
+ if (endedAtNs !== void 0) {
4114
+ frame.recording.journal.finishCall(
4115
+ KIND_EXIT,
4116
+ frame.callId,
4117
+ endedAtNs - frame.recording.startedAtNs,
4118
+ endedAtNs - frame.startedAtNs,
4119
+ returnValue
4120
+ );
4121
+ } else {
4122
+ frame.recording.journal.finishCall(
4123
+ KIND_EXIT,
4124
+ frame.callId,
4125
+ TIMING_UNAVAILABLE,
4126
+ TIMING_UNAVAILABLE,
4127
+ returnValue
4128
+ );
4129
+ }
3932
4130
  stats.functionCallsCaptured++;
3933
4131
  };
3934
4132
  const writeCapturedThrow = (frame, error) => {
3935
4133
  if (!frame.recording.journal) return;
3936
- const endedAtNs = process.hrtime.bigint();
4134
+ const endedAtNs = readCallClock();
3937
4135
  const capturedError = serializedError(frame.recording, error, frame.callId);
3938
4136
  frame.recording.journal.finishCall(
3939
4137
  KIND_THROW,
3940
4138
  frame.callId,
3941
4139
  endedAtNs - frame.recording.startedAtNs,
3942
- endedAtNs - frame.startedAtNs,
4140
+ frame.timed ? endedAtNs - frame.startedAtNs : TIMING_UNAVAILABLE,
3943
4141
  capturedError.value
3944
4142
  );
3945
4143
  stats.functionCallsCaptured++;
3946
4144
  capturedError.commit();
3947
4145
  };
3948
- const activateUncaptured = (mode, recording, parentStore, plan, args, omitCallValues, parentCallId, startedAtNs, group, captureDroppedThrow) => {
4146
+ const activateUncaptured = (mode, recording, parentStore, plan, args, omitCallValues, parentCallId, startedAtNs, timed, group, captureDroppedThrow) => {
4147
+ const activeStore = callerStore(parentStore, plan.functionId);
3949
4148
  const frame = new CallFrame(
3950
4149
  mode,
3951
4150
  recording,
3952
4151
  parentStore,
3953
- parentStore,
4152
+ activeStore,
3954
4153
  plan,
3955
4154
  args,
3956
4155
  omitCallValues,
3957
4156
  parentCallId,
3958
4157
  startedAtNs,
4158
+ timed,
3959
4159
  0,
3960
4160
  group,
3961
4161
  captureDroppedThrow
3962
4162
  );
3963
- enterStore(frame, parentStore);
4163
+ enterStore(frame, activeStore);
3964
4164
  return frame;
3965
4165
  };
3966
4166
  const enterPreparedFunctionFromStore = (store, plan, args, omitValues) => {
@@ -3982,6 +4182,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
3982
4182
  false,
3983
4183
  void 0,
3984
4184
  0n,
4185
+ true,
3985
4186
  0,
3986
4187
  void 0,
3987
4188
  false
@@ -4004,6 +4205,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
4004
4205
  false,
4005
4206
  void 0,
4006
4207
  0n,
4208
+ true,
4007
4209
  0,
4008
4210
  void 0,
4009
4211
  false
@@ -4019,7 +4221,8 @@ var createExecutionRecorder = (options, hooks = {}) => {
4019
4221
  if (group.observedCalls === 1) journal?.notePlan(plan.runtimePlanId);
4020
4222
  } catch {
4021
4223
  }
4022
- const startedAtNs = process.hrtime.bigint();
4224
+ const timed = durationSamplingEnabled ? decideCallTiming(recording, plan, store.currentFunctionId) : true;
4225
+ const startedAtNs = timed ? readCallClock() : 0n;
4023
4226
  const parentStore = store;
4024
4227
  const retainedArgs = recording.captureValues ? args : EMPTY_ARGS;
4025
4228
  if (group.observedCalls > capturedCallLimitFor(recording)) {
@@ -4032,6 +4235,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
4032
4235
  omitCallValues,
4033
4236
  parentCallId,
4034
4237
  startedAtNs,
4238
+ timed,
4035
4239
  group,
4036
4240
  false
4037
4241
  );
@@ -4047,6 +4251,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
4047
4251
  omitCallValues,
4048
4252
  parentCallId,
4049
4253
  startedAtNs,
4254
+ timed,
4050
4255
  group,
4051
4256
  false
4052
4257
  );
@@ -4061,6 +4266,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
4061
4266
  omitCallValues,
4062
4267
  parentCallId,
4063
4268
  startedAtNs,
4269
+ timed,
4064
4270
  group,
4065
4271
  true
4066
4272
  );
@@ -4075,12 +4281,13 @@ var createExecutionRecorder = (options, hooks = {}) => {
4075
4281
  omitCallValues,
4076
4282
  parentCallId,
4077
4283
  startedAtNs,
4284
+ timed,
4078
4285
  group,
4079
4286
  false
4080
4287
  );
4081
4288
  }
4082
4289
  const callId = ++recording.nextCallId;
4083
- const enterTimestampNs = process.hrtime.bigint() - recording.startedAtNs;
4290
+ const enterTimestampNs = timed ? readCallClock() - recording.startedAtNs : TIMING_UNAVAILABLE;
4084
4291
  const capturedArgs = enterPayload(recording, omitCallValues, args);
4085
4292
  try {
4086
4293
  journal.startCall(plan.runtimePlanId, callId, parentCallId, enterTimestampNs, capturedArgs);
@@ -4095,11 +4302,12 @@ var createExecutionRecorder = (options, hooks = {}) => {
4095
4302
  omitCallValues,
4096
4303
  parentCallId,
4097
4304
  startedAtNs,
4305
+ timed,
4098
4306
  group,
4099
4307
  false
4100
4308
  );
4101
4309
  }
4102
- const callStore = { recording, currentCallId: callId };
4310
+ const callStore = callerStore(store, plan.functionId, callId);
4103
4311
  const captured = new CallFrame(
4104
4312
  "captured",
4105
4313
  recording,
@@ -4110,6 +4318,7 @@ var createExecutionRecorder = (options, hooks = {}) => {
4110
4318
  omitCallValues,
4111
4319
  parentCallId,
4112
4320
  startedAtNs,
4321
+ timed,
4113
4322
  callId,
4114
4323
  group,
4115
4324
  false
@@ -4178,6 +4387,9 @@ var createExecutionRecorder = (options, hooks = {}) => {
4178
4387
  runPreparedFunction,
4179
4388
  enterPreparedFunction,
4180
4389
  trace,
4390
+ close: () => {
4391
+ durationSamples?.stop();
4392
+ },
4181
4393
  getStats: () => ({
4182
4394
  ...stats,
4183
4395
  ...memoryBudget.getStats(),
@@ -5079,7 +5291,7 @@ var createExecutionRecordingCoordinator = (options) => {
5079
5291
  // src/execution-recorder/bind-adaptive-recorder.ts
5080
5292
  var bindAdaptiveRecorder = (input) => {
5081
5293
  const options = input.executionRecorder;
5082
- const mode = sanitizeRecorderMode(options?.mode);
5294
+ const adaptiveEnabled = options?.adaptive?.enabled === true;
5083
5295
  const activation = resolveClientActivation({
5084
5296
  enabled: input.enabled,
5085
5297
  dsn: input.dsn,
@@ -5098,14 +5310,14 @@ var bindAdaptiveRecorder = (input) => {
5098
5310
  release: activation.release,
5099
5311
  recorderOptions: options,
5100
5312
  scrubPII: input.scrubPII,
5101
- mode,
5313
+ mode: adaptiveEnabled ? "adaptive" : "full",
5102
5314
  fetch: input.fetch
5103
5315
  }) : void 0;
5104
5316
  const runtime = createExecutionRecorder(
5105
5317
  { ...options, enabled: input.recorderEnabled },
5106
5318
  coordinator ? {
5107
5319
  policySnapshot: coordinator.peek,
5108
- onQualifyingFailure: mode === "adaptive" ? coordinator.activate : void 0,
5320
+ onQualifyingFailure: adaptiveEnabled ? coordinator.activate : void 0,
5109
5321
  getStats: coordinator.getStats,
5110
5322
  sessionCaptureSnapshot: coordinator.peekSessions,
5111
5323
  consumeSession: coordinator.consumeSession,
@@ -5254,7 +5466,7 @@ var installGlobalHandlers = (client, options = {}) => {
5254
5466
 
5255
5467
  // src/sdk-meta.ts
5256
5468
  var SDK_NAME = "@rasputin-ai/node";
5257
- var SDK_VERSION = "0.11.4";
5469
+ var SDK_VERSION = "0.12.0";
5258
5470
 
5259
5471
  // src/rasputin-init.ts
5260
5472
  var publicExecution = (runtime) => ({
@@ -5299,6 +5511,7 @@ var withExecution = (client, runtime, installRuntime, manifest, uninstallHandler
5299
5511
  close: async () => {
5300
5512
  uninstallHandlers();
5301
5513
  uninstallRuntime();
5514
+ runtime.close();
5302
5515
  manifestUpload.disconnect();
5303
5516
  const startedAt = Date.now();
5304
5517
  await policy?.close();