@smoothbricks/lmao 0.2.2 → 0.2.3

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 (276) hide show
  1. package/dist/allocator.wasm +0 -0
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +1 -0
  5. package/dist/lib/JsBufferStrategy.d.ts +4 -3
  6. package/dist/lib/JsBufferStrategy.d.ts.map +1 -1
  7. package/dist/lib/JsBufferStrategy.js +18 -11
  8. package/dist/lib/arrow/lease.d.ts +10 -0
  9. package/dist/lib/arrow/lease.d.ts.map +1 -0
  10. package/dist/lib/arrow/lease.js +33 -0
  11. package/dist/lib/arrow/utils.d.ts +3 -4
  12. package/dist/lib/arrow/utils.d.ts.map +1 -1
  13. package/dist/lib/arrow/utils.js +12 -13
  14. package/dist/lib/arrow/vocabularyDictionary.d.ts +21 -0
  15. package/dist/lib/arrow/vocabularyDictionary.d.ts.map +1 -0
  16. package/dist/lib/arrow/vocabularyDictionary.js +95 -0
  17. package/dist/lib/bufferStrategy.d.ts +3 -2
  18. package/dist/lib/bufferStrategy.d.ts.map +1 -1
  19. package/dist/lib/cloudflare/traceRows.d.ts.map +1 -1
  20. package/dist/lib/cloudflare/traceRows.js +3 -2
  21. package/dist/lib/codegen/evaluatorGenerator.d.ts.map +1 -1
  22. package/dist/lib/codegen/evaluatorGenerator.js +12 -11
  23. package/dist/lib/codegen/fixedPositionWriterGenerator.d.ts +44 -82
  24. package/dist/lib/codegen/fixedPositionWriterGenerator.d.ts.map +1 -1
  25. package/dist/lib/codegen/fixedPositionWriterGenerator.js +223 -162
  26. package/dist/lib/codegen/spanLoggerClosureMaterializer.d.ts +63 -0
  27. package/dist/lib/codegen/spanLoggerClosureMaterializer.d.ts.map +1 -0
  28. package/dist/lib/codegen/spanLoggerClosureMaterializer.js +447 -0
  29. package/dist/lib/codegen/spanLoggerGenerator.d.ts +36 -19
  30. package/dist/lib/codegen/spanLoggerGenerator.d.ts.map +1 -1
  31. package/dist/lib/codegen/spanLoggerGenerator.js +164 -158
  32. package/dist/lib/convertToArrow.d.ts +7 -2
  33. package/dist/lib/convertToArrow.d.ts.map +1 -1
  34. package/dist/lib/convertToArrow.js +499 -285
  35. package/dist/lib/defineOpContext.js +1 -1
  36. package/dist/lib/enumMetadata.d.ts +19 -0
  37. package/dist/lib/enumMetadata.d.ts.map +1 -0
  38. package/dist/lib/enumMetadata.js +86 -0
  39. package/dist/lib/flushScheduler.d.ts.map +1 -1
  40. package/dist/lib/flushScheduler.js +13 -4
  41. package/dist/lib/library.d.ts +16 -98
  42. package/dist/lib/library.d.ts.map +1 -1
  43. package/dist/lib/library.js +32 -525
  44. package/dist/lib/logBinding.d.ts +21 -27
  45. package/dist/lib/logBinding.d.ts.map +1 -1
  46. package/dist/lib/op.d.ts +30 -30
  47. package/dist/lib/op.d.ts.map +1 -1
  48. package/dist/lib/op.js +15 -22
  49. package/dist/lib/opContext/createOpGroup.d.ts +1 -1
  50. package/dist/lib/opContext/createOpGroup.d.ts.map +1 -1
  51. package/dist/lib/opContext/createOpGroup.js +22 -29
  52. package/dist/lib/opContext/defineOp.d.ts +4 -4
  53. package/dist/lib/opContext/defineOp.d.ts.map +1 -1
  54. package/dist/lib/opContext/defineOp.js +53 -10
  55. package/dist/lib/opContext/opGroupTypes.d.ts +2 -2
  56. package/dist/lib/opContext/opTypes.d.ts +1 -1
  57. package/dist/lib/opContext/opTypes.d.ts.map +1 -1
  58. package/dist/lib/opContext/spanContextTypes.d.ts +29 -14
  59. package/dist/lib/opContext/spanContextTypes.d.ts.map +1 -1
  60. package/dist/lib/opContext/types.d.ts +4 -4
  61. package/dist/lib/opContext/types.d.ts.map +1 -1
  62. package/dist/lib/physicalLayoutPlan.d.ts +89 -0
  63. package/dist/lib/physicalLayoutPlan.d.ts.map +1 -0
  64. package/dist/lib/physicalLayoutPlan.js +442 -0
  65. package/dist/lib/resolveMessage.d.ts +9 -0
  66. package/dist/lib/resolveMessage.d.ts.map +1 -0
  67. package/dist/lib/resolveMessage.js +63 -0
  68. package/dist/lib/result.d.ts +5 -7
  69. package/dist/lib/result.d.ts.map +1 -1
  70. package/dist/lib/result.js +19 -26
  71. package/dist/lib/runtimeHint.d.ts +35 -0
  72. package/dist/lib/runtimeHint.d.ts.map +1 -0
  73. package/dist/lib/runtimeHint.js +79 -0
  74. package/dist/lib/schema/types.d.ts +1 -1
  75. package/dist/lib/schema/types.d.ts.map +1 -1
  76. package/dist/lib/span-buffer/aot/v1.d.ts +2 -0
  77. package/dist/lib/span-buffer/aot/v1.d.ts.map +1 -0
  78. package/dist/lib/span-buffer/aot/v1.js +24 -0
  79. package/dist/lib/spanBuffer.d.ts +33 -4
  80. package/dist/lib/spanBuffer.d.ts.map +1 -1
  81. package/dist/lib/spanBuffer.js +583 -91
  82. package/dist/lib/spanBufferStats.d.ts +1 -1
  83. package/dist/lib/spanBufferStats.d.ts.map +1 -1
  84. package/dist/lib/spanContext.d.ts +27 -51
  85. package/dist/lib/spanContext.d.ts.map +1 -1
  86. package/dist/lib/spanContext.js +822 -344
  87. package/dist/lib/sqlite/sqlite-common.d.ts.map +1 -1
  88. package/dist/lib/sqlite/sqlite-common.js +20 -21
  89. package/dist/lib/testing/bun-harness.d.ts +8 -3
  90. package/dist/lib/testing/bun-harness.d.ts.map +1 -1
  91. package/dist/lib/testing/bun-harness.js +30 -18
  92. package/dist/lib/testing/extractFacts.d.ts +1 -1
  93. package/dist/lib/testing/extractFacts.d.ts.map +1 -1
  94. package/dist/lib/testing/extractFacts.js +55 -63
  95. package/dist/lib/testing/facts.d.ts +1 -1
  96. package/dist/lib/testing/facts.d.ts.map +1 -1
  97. package/dist/lib/testing/queryable-span.d.ts +1 -1
  98. package/dist/lib/testing/queryable-span.d.ts.map +1 -1
  99. package/dist/lib/testing/queryable-span.js +26 -28
  100. package/dist/lib/testing/span-query.d.ts.map +1 -1
  101. package/dist/lib/testing/span-query.js +19 -22
  102. package/dist/lib/testing/stdio-replay.d.ts.map +1 -1
  103. package/dist/lib/testing/stdio-replay.js +19 -8
  104. package/dist/lib/threadId.d.ts.map +1 -1
  105. package/dist/lib/threadId.js +6 -3
  106. package/dist/lib/traceRoot.d.ts +30 -8
  107. package/dist/lib/traceRoot.d.ts.map +1 -1
  108. package/dist/lib/traceRoot.es.d.ts +17 -15
  109. package/dist/lib/traceRoot.es.d.ts.map +1 -1
  110. package/dist/lib/traceRoot.es.js +68 -34
  111. package/dist/lib/traceRoot.js +11 -0
  112. package/dist/lib/traceRoot.node.d.ts +17 -19
  113. package/dist/lib/traceRoot.node.d.ts.map +1 -1
  114. package/dist/lib/traceRoot.node.js +66 -38
  115. package/dist/lib/traceTopology.d.ts +42 -0
  116. package/dist/lib/traceTopology.d.ts.map +1 -0
  117. package/dist/lib/traceTopology.js +260 -0
  118. package/dist/lib/tracer.d.ts +9 -5
  119. package/dist/lib/tracer.d.ts.map +1 -1
  120. package/dist/lib/tracer.js +65 -71
  121. package/dist/lib/tracers/ArrayQueueTracer.d.ts +1 -1
  122. package/dist/lib/tracers/ArrayQueueTracer.js +1 -1
  123. package/dist/lib/tracers/StdioTracer.d.ts.map +1 -1
  124. package/dist/lib/tracers/StdioTracer.js +15 -13
  125. package/dist/lib/tracers/TestTracer.d.ts +4 -6
  126. package/dist/lib/tracers/TestTracer.d.ts.map +1 -1
  127. package/dist/lib/tracers/TestTracer.js +6 -8
  128. package/dist/lib/types.d.ts +49 -32
  129. package/dist/lib/types.d.ts.map +1 -1
  130. package/dist/lib/vocabularyRegistry.d.ts +25 -0
  131. package/dist/lib/vocabularyRegistry.d.ts.map +1 -0
  132. package/dist/lib/vocabularyRegistry.js +372 -0
  133. package/dist/lib/wasm/WasmBufferStrategy.d.ts +6 -10
  134. package/dist/lib/wasm/WasmBufferStrategy.d.ts.map +1 -1
  135. package/dist/lib/wasm/WasmBufferStrategy.js +44 -37
  136. package/dist/lib/wasm/wasmAllocator.d.ts +27 -22
  137. package/dist/lib/wasm/wasmAllocator.d.ts.map +1 -1
  138. package/dist/lib/wasm/wasmAllocator.js +66 -44
  139. package/dist/lib/wasm/wasmPhysicalLayout.d.ts +67 -0
  140. package/dist/lib/wasm/wasmPhysicalLayout.d.ts.map +1 -0
  141. package/dist/lib/wasm/wasmPhysicalLayout.js +179 -0
  142. package/dist/lib/wasm/wasmSpanBuffer.d.ts +79 -31
  143. package/dist/lib/wasm/wasmSpanBuffer.d.ts.map +1 -1
  144. package/dist/lib/wasm/wasmSpanBuffer.js +442 -272
  145. package/dist/lib/wasm/wasmTraceRoot.d.ts +24 -22
  146. package/dist/lib/wasm/wasmTraceRoot.d.ts.map +1 -1
  147. package/dist/lib/wasm/wasmTraceRoot.js +110 -71
  148. package/dist/vocabulary/register/v1.d.ts +2 -0
  149. package/dist/vocabulary/register/v1.d.ts.map +1 -0
  150. package/dist/vocabulary/register/v1.js +1 -0
  151. package/dist/wasm.d.ts +5 -0
  152. package/dist/wasm.d.ts.map +1 -0
  153. package/dist/wasm.js +4 -0
  154. package/package.json +54 -6
  155. package/src/index.ts +1 -0
  156. package/src/lib/JsBufferStrategy.ts +27 -9
  157. package/src/lib/__tests__/arrow-builder-integration/arrow-conversion.test.ts +335 -37
  158. package/src/lib/__tests__/arrow-builder-integration/binary-arrow-conversion.test.ts +97 -26
  159. package/src/lib/__tests__/arrow-builder-integration/binary-comparison.test.ts +75 -15
  160. package/src/lib/__tests__/arrow-builder-integration/binary-format-compliance.test.ts +30 -6
  161. package/src/lib/__tests__/arrow-builder-integration/buffer-chaining.test.ts +18 -21
  162. package/src/lib/__tests__/arrow-builder-integration/foundation.test.ts +5 -2
  163. package/src/lib/__tests__/arrow-builder-integration/integration.test.ts +25 -7
  164. package/src/lib/__tests__/arrow-builder-integration/lazy-columns.test.ts +3 -2
  165. package/src/lib/__tests__/buffer-overflow.test.ts +24 -18
  166. package/src/lib/__tests__/capability-span-context.test.ts +505 -0
  167. package/src/lib/__tests__/capacity-tuning.test.ts +5 -3
  168. package/src/lib/__tests__/eager-columns.test.ts +345 -0
  169. package/src/lib/__tests__/enum-metadata-aot.test.ts +153 -0
  170. package/src/lib/__tests__/enum-metadata.test.ts +177 -0
  171. package/src/lib/__tests__/fixtures/empty-vocabulary-runtime.fixture.ts +15 -0
  172. package/src/lib/__tests__/flushScheduler.test.ts +5 -1
  173. package/src/lib/__tests__/identity-view.property.test.ts +179 -0
  174. package/src/lib/__tests__/library.test.ts +19 -235
  175. package/src/lib/__tests__/message-buffer-families.test.ts +878 -0
  176. package/src/lib/__tests__/nested-library-tasks.test.ts +14 -15
  177. package/src/lib/__tests__/op-metadata.test.ts +1 -1
  178. package/src/lib/__tests__/op-type-safety.test.ts +5 -16
  179. package/src/lib/__tests__/physical-layout-plan.test.ts +333 -0
  180. package/src/lib/__tests__/remap-descriptor-integration.test.ts +381 -0
  181. package/src/lib/__tests__/root-context-construction.test.ts +414 -0
  182. package/src/lib/__tests__/span-auto-runtime.test.ts +386 -0
  183. package/src/lib/__tests__/span-buffer-segment-stats.test.ts +221 -0
  184. package/src/lib/__tests__/span-lifecycle.test.ts +53 -25
  185. package/src/lib/__tests__/spanbuffer-materializer-parity.test.ts +266 -0
  186. package/src/lib/__tests__/sync-async-trace.test.ts +24 -23
  187. package/src/lib/__tests__/tag-writer-aot.test.ts +214 -0
  188. package/src/lib/__tests__/test-helpers.ts +67 -12
  189. package/src/lib/__tests__/threadId.test.ts +62 -0
  190. package/src/lib/__tests__/timestamp.test.ts +221 -93
  191. package/src/lib/__tests__/traceTopology.property.test.ts +383 -0
  192. package/src/lib/__tests__/type-narrowing.test.ts +63 -0
  193. package/src/lib/__tests__/vocabulary-dense-decoding.test.ts +405 -0
  194. package/src/lib/__tests__/vocabularyRegistry.test.ts +313 -0
  195. package/src/lib/arrow/lease.ts +43 -0
  196. package/src/lib/arrow/utils.ts +10 -14
  197. package/src/lib/arrow/vocabularyDictionary.ts +123 -0
  198. package/src/lib/bufferStrategy.ts +9 -1
  199. package/src/lib/cloudflare/traceRows.ts +3 -2
  200. package/src/lib/codegen/__tests__/evaluatorGenerator.test.ts +21 -141
  201. package/src/lib/codegen/__tests__/fixedPositionWriter-parity.test.ts +273 -0
  202. package/src/lib/codegen/__tests__/fixedPositionWriter-uint64.test.ts +61 -34
  203. package/src/lib/codegen/__tests__/nullBitmap.test.ts +33 -37
  204. package/src/lib/codegen/__tests__/spanLoggerGenerator.test.ts +34 -18
  205. package/src/lib/codegen/__tests__/spanLoggerMaterializerParity.test.ts +503 -0
  206. package/src/lib/codegen/evaluatorGenerator.ts +18 -13
  207. package/src/lib/codegen/fixedPositionWriterGenerator.ts +329 -245
  208. package/src/lib/codegen/spanLoggerClosureMaterializer.ts +598 -0
  209. package/src/lib/codegen/spanLoggerGenerator.ts +241 -177
  210. package/src/lib/convertToArrow.ts +598 -311
  211. package/src/lib/defineOpContext.ts +1 -1
  212. package/src/lib/enumMetadata.ts +121 -0
  213. package/src/lib/flushScheduler.ts +11 -5
  214. package/src/lib/library.ts +37 -595
  215. package/src/lib/logBinding.ts +21 -27
  216. package/src/lib/op.ts +75 -18
  217. package/src/lib/opContext/__tests__/retry.test.ts +27 -21
  218. package/src/lib/opContext/createOpGroup.ts +33 -31
  219. package/src/lib/opContext/defineOp.ts +88 -11
  220. package/src/lib/opContext/opGroupTypes.ts +2 -2
  221. package/src/lib/opContext/opTypes.ts +1 -1
  222. package/src/lib/opContext/spanContextTypes.ts +98 -17
  223. package/src/lib/opContext/types.ts +7 -3
  224. package/src/lib/physicalLayoutPlan.ts +598 -0
  225. package/src/lib/resolveMessage.ts +67 -0
  226. package/src/lib/result.ts +20 -33
  227. package/src/lib/runtimeHint.ts +98 -0
  228. package/src/lib/schema/__tests__/featureFlags.test.ts +2 -1
  229. package/src/lib/schema/builder.ts +1 -1
  230. package/src/lib/schema/types.ts +1 -1
  231. package/src/lib/span-buffer/aot/v1.ts +26 -0
  232. package/src/lib/spanBuffer.ts +658 -92
  233. package/src/lib/spanBufferStats.ts +1 -1
  234. package/src/lib/spanContext.ts +1350 -861
  235. package/src/lib/sqlite/sqlite-common.ts +20 -31
  236. package/src/lib/testing/__tests__/topology-traversal.test.ts +174 -0
  237. package/src/lib/testing/__tests__/vitest-harness.test.ts +2 -1
  238. package/src/lib/testing/bun-harness.ts +94 -43
  239. package/src/lib/testing/extractFacts.ts +64 -78
  240. package/src/lib/testing/facts.ts +1 -1
  241. package/src/lib/testing/queryable-span.ts +23 -30
  242. package/src/lib/testing/span-query.ts +16 -20
  243. package/src/lib/testing/stdio-replay.ts +25 -8
  244. package/src/lib/testing/vitest-harness.ts +1 -1
  245. package/src/lib/threadId.ts +6 -3
  246. package/src/lib/traceRoot.es.ts +77 -42
  247. package/src/lib/traceRoot.node.ts +75 -46
  248. package/src/lib/traceRoot.ts +41 -14
  249. package/src/lib/traceTopology.ts +279 -0
  250. package/src/lib/tracer.ts +109 -98
  251. package/src/lib/tracers/ArrayQueueTracer.ts +1 -1
  252. package/src/lib/tracers/StdioTracer.ts +15 -13
  253. package/src/lib/tracers/TestTracer.ts +6 -8
  254. package/src/lib/tracers/__tests__/ArrayQueueTracer.test.ts +15 -10
  255. package/src/lib/tracers/__tests__/TestTracer.test.ts +23 -13
  256. package/src/lib/types.ts +64 -33
  257. package/src/lib/vocabularyRegistry.ts +439 -0
  258. package/src/lib/wasm/WasmBufferStrategy.ts +56 -48
  259. package/src/lib/wasm/__tests__/WasmBufferStrategy.test.ts +215 -11
  260. package/src/lib/wasm/__tests__/allocatorFreeBlockClamp.test.ts +86 -0
  261. package/src/lib/wasm/__tests__/wasm-identity-view.test.ts +311 -0
  262. package/src/lib/wasm/__tests__/wasm-integration.test.ts +417 -44
  263. package/src/lib/wasm/__tests__/wasm-message-buffer-families.test.ts +588 -0
  264. package/src/lib/wasm/__tests__/wasmAllocator.test.ts +100 -668
  265. package/src/lib/wasm/__tests__/wasmSpanBuffer.test.ts +419 -63
  266. package/src/lib/wasm/__tests__/wasmTraceRoot.test.ts +24 -29
  267. package/src/lib/wasm/__tests__/wasmTracer.test.ts.disabled +2 -2
  268. package/src/lib/wasm/wasmAllocator.ts +131 -96
  269. package/src/lib/wasm/wasmPhysicalLayout.ts +309 -0
  270. package/src/lib/wasm/wasmSpanBuffer.ts +597 -341
  271. package/src/lib/wasm/wasmTraceRoot.ts +140 -78
  272. package/src/vocabulary/register/v1.ts +1 -0
  273. package/src/wasm.ts +19 -0
  274. package/src/lib/__tests__/remapped-buffer-view-integration.test.ts +0 -319
  275. package/src/lib/__tests__/remapped-buffer-view.test.ts +0 -635
  276. package/src/lib/wasm/allocator.zig +0 -948
@@ -1,10 +1,8 @@
1
1
  /* biome-ignore-all lint/complexity/noArguments: hot-path overload dispatch avoids rest-arg allocations */
2
- import { createTagWriter } from './codegen/fixedPositionWriterGenerator.js';
3
2
  import { createSpanLogger as createSpanLoggerFromGenerator, } from './codegen/spanLoggerGenerator.js';
4
- import { Blocked } from './errors/Blocked.js';
5
3
  import { TransientError } from './errors/Transient.js';
6
- import { Op } from './op.js';
7
4
  import { Err, hasErrorCode, Ok } from './result.js';
5
+ import { RUNTIME_HINT_DEPS, RUNTIME_HINT_FF, RUNTIME_HINT_FULL_CAPABILITIES, RUNTIME_HINT_LOG, RUNTIME_HINT_RESULT, RUNTIME_HINT_SCOPE, RUNTIME_HINT_SPAN, RUNTIME_HINT_TAG, } from './runtimeHint.js';
8
6
  import { ENTRY_TYPE_SPAN_ERR, ENTRY_TYPE_SPAN_EXCEPTION, ENTRY_TYPE_SPAN_OK, ENTRY_TYPE_SPAN_RETRY, } from './schema/systemSchema.js';
9
7
  // Note: TraceRoot.writeSpanStart() is used instead of direct timestamp writes.
10
8
  // The platform-specific TraceRoot (traceRoot.es.ts or traceRoot.node.ts) handles
@@ -17,8 +15,15 @@ import { ENTRY_TYPE_SPAN_ERR, ENTRY_TYPE_SPAN_EXCEPTION, ENTRY_TYPE_SPAN_OK, ENT
17
15
  * Used for type guards and prototype chain detection
18
16
  */
19
17
  export const SPAN_CONTEXT_MARKER = Symbol.for('lmao.SpanContext');
18
+ function isOpLike(value) {
19
+ return (typeof value === 'object' &&
20
+ value !== null &&
21
+ typeof Reflect.get(value, 'fn') === 'function' &&
22
+ typeof Reflect.get(value, 'callsitePlan') === 'object' &&
23
+ typeof Reflect.get(value, 'metadata') === 'object');
24
+ }
20
25
  function isOpInstance(value) {
21
- return value instanceof Op;
26
+ return isOpLike(value);
22
27
  }
23
28
  // WHY: resolveSpanTarget() accepts either an Op instance or a raw span
24
29
  // function. TypeScript needs an explicit predicate here to preserve the call
@@ -26,43 +31,19 @@ function isOpInstance(value) {
26
31
  function isSpanDispatchFn(value) {
27
32
  return typeof value === 'function';
28
33
  }
29
- function isSpanBufferConstructorForSchema(value, schema) {
30
- return (typeof value === 'function' &&
31
- Reflect.get(value, 'schema') === schema &&
32
- typeof Reflect.get(value, 'stats') === 'object');
33
- }
34
- function getBufferConstructor(buffer) {
35
- const ctor = buffer.constructor;
36
- if (!isSpanBufferConstructorForSchema(ctor, buffer._logSchema)) {
37
- throw new TypeError('Span buffer constructor does not match the buffer schema');
38
- }
39
- return ctor;
40
- }
41
- function isSpanBufferForSchema(buffer, schema) {
42
- return (typeof buffer === 'object' &&
43
- buffer !== null &&
44
- Reflect.get(buffer, '_logSchema') === schema &&
45
- isSpanBufferConstructorForSchema(Reflect.get(buffer, 'constructor'), schema));
46
- }
47
34
  function isSpanContextInstance(value) {
48
35
  return (isSpanContext(value) &&
36
+ Reflect.has(value, '_spanBuffer') &&
49
37
  Reflect.has(value, '_buffer') &&
50
- Reflect.has(value, '_spanLogger') &&
51
- Reflect.has(value, '_schema'));
38
+ Reflect.has(value, '_schema') &&
39
+ Reflect.has(value, '_logBinding') &&
40
+ Reflect.has(value, '_physicalLayoutPlan'));
52
41
  }
53
- function createInheritedContext(parent) {
54
- const child = Object.create(parent);
55
- if (!isSpanContextInstance(child)) {
56
- throw new TypeError('Failed to create child span context');
42
+ function asSpanContextInstance(value) {
43
+ if (!isSpanContextInstance(value)) {
44
+ throw new TypeError('Callsite plan created an invalid child span context');
57
45
  }
58
- return child;
59
- }
60
- function createInheritedContextWithOverrides(parent, overrides) {
61
- const child = Object.assign(Object.create(parent), overrides);
62
- if (!isSpanContextInstance(child)) {
63
- throw new TypeError('Failed to create overridden child span context');
64
- }
65
- return child;
46
+ return value;
66
47
  }
67
48
  function readStringArgument(args, index, label) {
68
49
  const value = args[index];
@@ -71,11 +52,10 @@ function readStringArgument(args, index, label) {
71
52
  }
72
53
  return value;
73
54
  }
74
- function resolveSpanTarget(value, fallbackBuffer) {
55
+ function resolveSpanTarget(value, fallbackPlan, fallbackMetadata) {
75
56
  if (isOpInstance(value)) {
76
57
  return {
77
- SpanBufferClass: value.SpanBufferClass,
78
- remappedViewClass: value.remappedViewClass,
58
+ callsitePlan: value.callsitePlan,
79
59
  opMetadata: value.metadata,
80
60
  fn: value.fn,
81
61
  };
@@ -84,12 +64,19 @@ function resolveSpanTarget(value, fallbackBuffer) {
84
64
  throw new TypeError('span() expects an Op or function');
85
65
  }
86
66
  return {
87
- SpanBufferClass: getBufferConstructor(fallbackBuffer),
88
- remappedViewClass: undefined,
89
- opMetadata: fallbackBuffer._opMetadata,
67
+ callsitePlan: fallbackPlan,
68
+ opMetadata: fallbackMetadata,
90
69
  fn: value,
91
70
  };
92
71
  }
72
+ function isSynchronousResult(value) {
73
+ return value instanceof Ok || value instanceof Err;
74
+ }
75
+ function getRetryableError(result, attempt) {
76
+ if (!(result instanceof Err) || !(result.error instanceof TransientError))
77
+ return undefined;
78
+ return attempt < result.error.policy.maxAttempts ? result.error : undefined;
79
+ }
93
80
  // =============================================================================
94
81
  // Helper Functions
95
82
  // =============================================================================
@@ -109,21 +96,12 @@ function resolveSpanTarget(value, fallbackBuffer) {
109
96
  */
110
97
  export function writeSpanStart(buffer, spanName) {
111
98
  // Delegate to TraceRoot - platform-specific implementation handles timestamps
112
- buffer._traceRoot.writeSpanStart(buffer, spanName);
99
+ buffer._traceRoot._writeSpanStart(buffer._traceRoot, buffer, spanName);
113
100
  }
114
101
  //#endregion smoo/lmao!n/lmao-entry-span-lifecycle-entry-types.start
115
- /**
116
- * Create a SpanLogger for the given buffer.
117
- *
118
- * Per specs/lmao/01i_span_scope_attributes.md: Scope values are stored directly on buffer._scopeValues.
119
- * The SpanLogger reads/writes scope via buffer._scopeValues - no separate Scope class needed.
120
- *
121
- * @param schema - Tag attribute schema with field definitions
122
- * @param buffer - SpanBuffer to write entries to (per-span instance)
123
- * @returns SpanLogger with typed methods matching schema
124
- */
125
- export function createSpanLogger(schema, buffer) {
126
- return createSpanLoggerFromGenerator(schema, buffer);
102
+ /** Create a SpanLogger bound to an existing SpanContext writer state. */
103
+ export function createSpanLogger(schema, state) {
104
+ return createSpanLoggerFromGenerator(schema, state);
127
105
  }
128
106
  //#region smoo/lmao!n/op-retry.delay
129
107
  /**
@@ -175,9 +153,9 @@ function calculateDelay(policy, attempt) {
175
153
  function writeRetryEntry(buffer, attempt, error, delayMs) {
176
154
  // Get current write index and advance for next write
177
155
  const index = buffer._writeIndex;
178
- // Write entry via TraceRoot for timestamp handling
179
- // TraceRoot.writeLogEntry writes timestamp and entry_type at the given index
180
- buffer._traceRoot.writeLogEntry(buffer, ENTRY_TYPE_SPAN_RETRY);
156
+ const traceRoot = buffer._traceRoot;
157
+ const appendLogEntry = buffer._opMetadata._physicalLayoutPlan?.appendLogEntry ?? traceRoot._appendLogEntry;
158
+ appendLogEntry(traceRoot, buffer, ENTRY_TYPE_SPAN_RETRY);
181
159
  // Write retry-specific message: retry:op:{opName} for prefix-based querying
182
160
  const opName = buffer._opMetadata?.name ?? 'unknown';
183
161
  buffer.message(index, `retry:op:${opName}`);
@@ -200,54 +178,130 @@ function writeRetryEntry(buffer, attempt, error, delayMs) {
200
178
  function sleep(ms) {
201
179
  return new Promise((resolve) => setTimeout(resolve, ms));
202
180
  }
203
- /**
204
- * Execute function with retry loop for TransientError handling.
205
- *
206
- * Per plan 19-03: Op class handles retry loop internally.
207
- * - TransientError from op body triggers retry based on error.policy
208
- * - Retry respects maxAttempts from TransientError.policy
209
- * - span-retry entry written for each transient failure
210
- * - Only final result written as span-ok or span-err
211
- * - BlockedError returns immediately without retry
212
- *
213
- * @param buffer - SpanBuffer to write retry entries to
214
- * @param fn - Function to execute (may be retried)
215
- * @returns Final result (success, non-transient error, or exhausted transient error)
216
- */
217
- async function executeWithRetry(buffer, fn) {
181
+ async function executeWithRetry0(buffer, fn, ctx) {
218
182
  let attempt = 0;
219
183
  while (true) {
220
184
  attempt++;
221
- // Execute the function
222
- const result = await fn();
223
- // Success - return immediately
224
- if (result instanceof Ok) {
185
+ const result = await fn(ctx);
186
+ if (!(result instanceof Err) || !(result.error instanceof TransientError))
225
187
  return result;
226
- }
227
- // Error result - check error type for retry behavior
228
- const error = result.error;
229
- // BlockedError - return immediately, no retry
230
- if (error instanceof Blocked) {
188
+ if (attempt >= result.error.policy.maxAttempts)
231
189
  return result;
232
- }
233
- // TransientError - check if we should retry
234
- if (error instanceof TransientError) {
235
- const { policy } = error;
236
- // Check attempt limit (maxAttempts includes initial attempt)
237
- if (attempt >= policy.maxAttempts) {
238
- // Exhausted - return final error
239
- return result;
240
- }
241
- // Calculate delay based on policy and attempt number
242
- const delay = calculateDelay(policy, attempt);
243
- // Write span-retry entry to buffer for observability
244
- writeRetryEntry(buffer, attempt, error, delay);
245
- // Wait before retry
246
- await sleep(delay);
247
- continue;
248
- }
249
- // Non-transient error - return immediately
250
- return result;
190
+ const delay = calculateDelay(result.error.policy, attempt);
191
+ writeRetryEntry(buffer, attempt, result.error, delay);
192
+ await sleep(delay);
193
+ }
194
+ }
195
+ async function executeWithRetry1(buffer, fn, ctx, a1) {
196
+ let attempt = 0;
197
+ while (true) {
198
+ attempt++;
199
+ const result = await fn(ctx, a1);
200
+ if (!(result instanceof Err) || !(result.error instanceof TransientError))
201
+ return result;
202
+ if (attempt >= result.error.policy.maxAttempts)
203
+ return result;
204
+ const delay = calculateDelay(result.error.policy, attempt);
205
+ writeRetryEntry(buffer, attempt, result.error, delay);
206
+ await sleep(delay);
207
+ }
208
+ }
209
+ async function executeWithRetry2(buffer, fn, ctx, a1, a2) {
210
+ let attempt = 0;
211
+ while (true) {
212
+ attempt++;
213
+ const result = await fn(ctx, a1, a2);
214
+ if (!(result instanceof Err) || !(result.error instanceof TransientError))
215
+ return result;
216
+ if (attempt >= result.error.policy.maxAttempts)
217
+ return result;
218
+ const delay = calculateDelay(result.error.policy, attempt);
219
+ writeRetryEntry(buffer, attempt, result.error, delay);
220
+ await sleep(delay);
221
+ }
222
+ }
223
+ async function executeWithRetry3(buffer, fn, ctx, a1, a2, a3) {
224
+ let attempt = 0;
225
+ while (true) {
226
+ attempt++;
227
+ const result = await fn(ctx, a1, a2, a3);
228
+ if (!(result instanceof Err) || !(result.error instanceof TransientError))
229
+ return result;
230
+ if (attempt >= result.error.policy.maxAttempts)
231
+ return result;
232
+ const delay = calculateDelay(result.error.policy, attempt);
233
+ writeRetryEntry(buffer, attempt, result.error, delay);
234
+ await sleep(delay);
235
+ }
236
+ }
237
+ async function executeWithRetry4(buffer, fn, ctx, a1, a2, a3, a4) {
238
+ let attempt = 0;
239
+ while (true) {
240
+ attempt++;
241
+ const result = await fn(ctx, a1, a2, a3, a4);
242
+ if (!(result instanceof Err) || !(result.error instanceof TransientError))
243
+ return result;
244
+ if (attempt >= result.error.policy.maxAttempts)
245
+ return result;
246
+ const delay = calculateDelay(result.error.policy, attempt);
247
+ writeRetryEntry(buffer, attempt, result.error, delay);
248
+ await sleep(delay);
249
+ }
250
+ }
251
+ async function executeWithRetry5(buffer, fn, ctx, a1, a2, a3, a4, a5) {
252
+ let attempt = 0;
253
+ while (true) {
254
+ attempt++;
255
+ const result = await fn(ctx, a1, a2, a3, a4, a5);
256
+ if (!(result instanceof Err) || !(result.error instanceof TransientError))
257
+ return result;
258
+ if (attempt >= result.error.policy.maxAttempts)
259
+ return result;
260
+ const delay = calculateDelay(result.error.policy, attempt);
261
+ writeRetryEntry(buffer, attempt, result.error, delay);
262
+ await sleep(delay);
263
+ }
264
+ }
265
+ async function executeWithRetry6(buffer, fn, ctx, a1, a2, a3, a4, a5, a6) {
266
+ let attempt = 0;
267
+ while (true) {
268
+ attempt++;
269
+ const result = await fn(ctx, a1, a2, a3, a4, a5, a6);
270
+ if (!(result instanceof Err) || !(result.error instanceof TransientError))
271
+ return result;
272
+ if (attempt >= result.error.policy.maxAttempts)
273
+ return result;
274
+ const delay = calculateDelay(result.error.policy, attempt);
275
+ writeRetryEntry(buffer, attempt, result.error, delay);
276
+ await sleep(delay);
277
+ }
278
+ }
279
+ async function executeWithRetry7(buffer, fn, ctx, a1, a2, a3, a4, a5, a6, a7) {
280
+ let attempt = 0;
281
+ while (true) {
282
+ attempt++;
283
+ const result = await fn(ctx, a1, a2, a3, a4, a5, a6, a7);
284
+ if (!(result instanceof Err) || !(result.error instanceof TransientError))
285
+ return result;
286
+ if (attempt >= result.error.policy.maxAttempts)
287
+ return result;
288
+ const delay = calculateDelay(result.error.policy, attempt);
289
+ writeRetryEntry(buffer, attempt, result.error, delay);
290
+ await sleep(delay);
291
+ }
292
+ }
293
+ async function executeWithRetry8(buffer, fn, ctx, a1, a2, a3, a4, a5, a6, a7, a8) {
294
+ let attempt = 0;
295
+ while (true) {
296
+ attempt++;
297
+ const result = await fn(ctx, a1, a2, a3, a4, a5, a6, a7, a8);
298
+ if (!(result instanceof Err) || !(result.error instanceof TransientError))
299
+ return result;
300
+ if (attempt >= result.error.policy.maxAttempts)
301
+ return result;
302
+ const delay = calculateDelay(result.error.policy, attempt);
303
+ writeRetryEntry(buffer, attempt, result.error, delay);
304
+ await sleep(delay);
251
305
  }
252
306
  }
253
307
  //#endregion smoo/lmao!n/op-retry.loop
@@ -264,13 +318,18 @@ async function executeWithRetry(buffer, fn) {
264
318
  * @param buffer - SpanBuffer to write to
265
319
  * @param result - The result returned by the span function
266
320
  */
321
+ function writeSpanEndEntry(buffer, entryType) {
322
+ const appenders = buffer._opMetadata._physicalLayoutPlan?.appenders;
323
+ if (appenders === undefined)
324
+ throw new TypeError('SpanBuffer metadata is missing physical lifecycle appenders');
325
+ appenders.writeSpanEnd(buffer, entryType);
326
+ }
267
327
  export function writeSpanEnd(buffer, result) {
268
- // Write entry_type and timestamp via TraceRoot (platform-specific)
269
328
  if (result instanceof Ok) {
270
- buffer._traceRoot.writeSpanEnd(buffer, ENTRY_TYPE_SPAN_OK);
329
+ writeSpanEndEntry(buffer, ENTRY_TYPE_SPAN_OK);
271
330
  }
272
331
  else if (result instanceof Err) {
273
- buffer._traceRoot.writeSpanEnd(buffer, ENTRY_TYPE_SPAN_ERR);
332
+ writeSpanEndEntry(buffer, ENTRY_TYPE_SPAN_ERR);
274
333
  // Write error_code if the error has a code property
275
334
  if (hasErrorCode(result.error)) {
276
335
  buffer.error_code(1, result.error.code);
@@ -281,6 +340,19 @@ export function writeSpanEnd(buffer, result) {
281
340
  // =============================================================================
282
341
  // SpanContext Class Factory
283
342
  // =============================================================================
343
+ const spanContextClassCaches = new WeakMap();
344
+ function isSpanContextClass(value) {
345
+ return typeof value === 'function';
346
+ }
347
+ export function isPhysicalLayoutPlanForContext(value, schema) {
348
+ return (typeof value === 'object' &&
349
+ value !== null &&
350
+ Reflect.get(value, 'schema') === schema &&
351
+ isSpanContextClass(Reflect.get(value, 'SpanContextClass')));
352
+ }
353
+ function isFlagEvaluatorForContext(value) {
354
+ return typeof value === 'object' && value !== null && typeof Reflect.get(value, 'forContext') === 'function';
355
+ }
284
356
  /**
285
357
  * Create a SpanContext class for the given schema and logBinding.
286
358
  *
@@ -288,14 +360,33 @@ export function writeSpanEnd(buffer, result) {
288
360
  * - Closes over schema/logBinding (available to all methods)
289
361
  * - Constructor takes buffer, spanLogger, tag directly (no temp object allocation)
290
362
  * - Uses prototype methods for internal methods (_spanPre, _spanException, span0-span8)
291
- * - Supports context inheritance via Object.create(parent) for child spans
292
- * - Supports context overrides via own properties shadowing inherited ones
363
+ * - Reuses the parent context as the zero-override source without allocating a carrier object
364
+ * - Context overrides use the plan's schema-specific context factory
293
365
  *
294
366
  * @param schemaOnly - Tag attribute schema
295
367
  * @param logBinding - LogBinding with schema and stats
296
368
  * @returns Class constructor for SpanContext instances
297
369
  */
298
- export function createSpanContextClass(_schemaOnly, logBinding) {
370
+ export function createSpanContextClass(_schemaOnly, logBinding, capabilities = RUNTIME_HINT_FULL_CAPABILITIES, userContextKeys = []) {
371
+ const canonicalUserContextKeys = [...userContextKeys].sort();
372
+ const layoutKey = canonicalUserContextKeys.join('\u0000');
373
+ const cacheKey = `${capabilities}:${layoutKey}`;
374
+ let cache = spanContextClassCaches.get(logBinding);
375
+ if (!cache) {
376
+ cache = new Map();
377
+ spanContextClassCaches.set(logBinding, cache);
378
+ }
379
+ const cached = cache.get(cacheKey);
380
+ if (isSpanContextClass(cached))
381
+ return cached;
382
+ const hasTag = (capabilities & RUNTIME_HINT_TAG) !== 0;
383
+ const hasLog = (capabilities & RUNTIME_HINT_LOG) !== 0;
384
+ const hasFf = (capabilities & RUNTIME_HINT_FF) !== 0;
385
+ const hasSpan = (capabilities & RUNTIME_HINT_SPAN) !== 0;
386
+ const hasResult = (capabilities & RUNTIME_HINT_RESULT) !== 0;
387
+ const hasScope = (capabilities & RUNTIME_HINT_SCOPE) !== 0;
388
+ const hasDeps = (capabilities & RUNTIME_HINT_DEPS) !== 0;
389
+ const needsLogger = hasLog || hasFf || hasScope;
299
390
  /**
300
391
  * SpanContext implementation class.
301
392
  *
@@ -303,39 +394,57 @@ export function createSpanContextClass(_schemaOnly, logBinding) {
303
394
  * avoiding both temp object allocation and property lookups in hot paths.
304
395
  */
305
396
  class SpanContextImpl {
306
- // Core properties set via constructor
307
- _buffer;
308
- _schema;
309
- _spanLogger;
310
- _logBinding = logBinding;
311
- // User-facing properties
312
- tag;
313
- log;
314
- ff;
315
- deps;
316
- // Arrow functions that close over constructor args directly
317
- setScope;
318
- ok;
319
- err;
320
- span;
321
- spanSync;
322
- constructor(buffer, schema, spanLogger, tag) {
397
+ constructor(buffer, schema, callsitePlan, contextSource, contextOverrides, deps, ffSource) {
323
398
  //#region smoo/lmao!n/codegen-destructured-context
324
399
  // Destructured-context assembly (01g): every property an op destructures —
325
400
  // tag, log, scope (setScope), ok, err, span — is wired here as a closed-over
326
401
  // field/closure so `op(({ tag, log, span, ok, err }) => ...)` needs no ctx drilling.
402
+ this._spanBuffer = buffer;
327
403
  this._buffer = buffer;
404
+ this._appendLogEntry = callsitePlan.appendLogEntry;
328
405
  this._schema = schema;
329
- this._spanLogger = spanLogger;
330
- this.tag = tag;
331
- this.log = spanLogger;
406
+ this._logBinding = logBinding;
407
+ this._physicalLayoutPlan = callsitePlan;
408
+ const spanLogger = callsitePlan.newSpanLogger?.(this);
409
+ const tag = callsitePlan.newTagWriter?.(this);
410
+ if (needsLogger) {
411
+ if (!spanLogger)
412
+ throw new TypeError('SpanContext capability requires a logger');
413
+ this._spanLogger = spanLogger;
414
+ }
415
+ if (hasTag) {
416
+ if (!tag)
417
+ throw new TypeError('SpanContext tag capability requires a tag writer');
418
+ this.tag = tag;
419
+ }
420
+ if (hasLog && spanLogger)
421
+ this.log = spanLogger;
422
+ if (hasDeps)
423
+ this.deps = deps ?? {};
424
+ if (hasFf && ffSource)
425
+ this.ff = ffSource.forContext(this);
426
+ for (const key of canonicalUserContextKeys) {
427
+ let value = contextSource?.[key];
428
+ if (contextOverrides && Object.prototype.propertyIsEnumerable.call(contextOverrides, key)) {
429
+ const overrideValue = contextOverrides[key];
430
+ if (overrideValue !== undefined)
431
+ value = overrideValue;
432
+ }
433
+ this[key] = value;
434
+ }
332
435
  // Regular functions close over constructor args directly - no property lookups
333
436
  // Using regular function (not arrow) allows destructuring while closing over args
334
- this.setScope = (attributes) => {
335
- spanLogger._setScope(attributes ?? {});
336
- };
337
- this.ok = (value) => new Ok(value, schema, buffer);
338
- this.err = (error) => new Err(error, schema, buffer);
437
+ if (hasScope) {
438
+ if (!spanLogger)
439
+ throw new TypeError('SpanContext scope capability requires a logger');
440
+ this.setScope = (attributes) => {
441
+ spanLogger._setScope(attributes ?? {});
442
+ };
443
+ }
444
+ if (hasResult) {
445
+ this.ok = (value) => new Ok(value, this);
446
+ this.err = (error) => new Err(error, this);
447
+ }
339
448
  //#endregion smoo/lmao!n/codegen-destructured-context
340
449
  //#region smoo/lmao!n/context-flow-span-promise
341
450
  // 01c "Why span() Is Promise-Based" + "Child Span Creation via span()" + "spanSync()".
@@ -346,61 +455,63 @@ export function createSpanContextClass(_schemaOnly, logBinding) {
346
455
  // span uses regular function to access `arguments` (no ...rest spread allocation)
347
456
  // Closes over `self` for calling prototype methods
348
457
  // Named function for better stack traces
349
- const self = this;
350
- const span = function span(nameOrLine, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11) {
351
- // Use arguments.length instead of ...rest to avoid array allocation
352
- const len = arguments.length;
353
- // Detect call pattern:
354
- // - span(name, fn) - len=2, typeof arg0 === 'string'
355
- // - span(line, name, fn) - len=3, typeof arg0 === 'number'
356
- // - span(name, overrides, fn) - len=3, typeof arg0 === 'string', typeof arg1 === 'object'
357
- // - span(line, name, overrides, fn) - len=4, typeof arg0 === 'number', typeof arg2 === 'object'
358
- // Plus additional args for span arguments
359
- const hasLine = typeof nameOrLine === 'number';
360
- const spanLine = hasLine ? nameOrLine : 0;
361
- const spanName = hasLine ? readStringArgument(arguments, 1, 'span name') : nameOrLine;
362
- // Index where fn/op or overrides starts
363
- const checkIdx = hasLine ? 2 : 1;
364
- const maybeOverrides = arguments[checkIdx];
365
- // Check if it's an overrides object (not Op, not function)
366
- const hasOverrides = maybeOverrides !== null &&
367
- typeof maybeOverrides === 'object' &&
368
- !(maybeOverrides instanceof Op) &&
369
- typeof maybeOverrides !== 'function';
370
- const fnIdx = checkIdx + (hasOverrides ? 1 : 0);
371
- const target = resolveSpanTarget(arguments[fnIdx], self._buffer);
372
- // Create child context - use _newCtx0 or _newCtx1 based on overrides
373
- const childCtx = hasOverrides ? self._newCtx1(maybeOverrides) : self._newCtx0();
374
- // Dispatch to monomorphic methods with all Op properties extracted
375
- const argCount = len - fnIdx - 1;
376
- switch (argCount) {
377
- case 0:
378
- return self.span0(spanLine, spanName, childCtx, target.SpanBufferClass, target.remappedViewClass, target.opMetadata, target.fn);
379
- case 1:
380
- return self.span1(spanLine, spanName, childCtx, target.SpanBufferClass, target.remappedViewClass, target.opMetadata, target.fn, arguments[fnIdx + 1]);
381
- case 2:
382
- return self.span2(spanLine, spanName, childCtx, target.SpanBufferClass, target.remappedViewClass, target.opMetadata, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2]);
383
- case 3:
384
- return self.span3(spanLine, spanName, childCtx, target.SpanBufferClass, target.remappedViewClass, target.opMetadata, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2], arguments[fnIdx + 3]);
385
- case 4:
386
- return self.span4(spanLine, spanName, childCtx, target.SpanBufferClass, target.remappedViewClass, target.opMetadata, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2], arguments[fnIdx + 3], arguments[fnIdx + 4]);
387
- case 5:
388
- return self.span5(spanLine, spanName, childCtx, target.SpanBufferClass, target.remappedViewClass, target.opMetadata, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2], arguments[fnIdx + 3], arguments[fnIdx + 4], arguments[fnIdx + 5]);
389
- case 6:
390
- return self.span6(spanLine, spanName, childCtx, target.SpanBufferClass, target.remappedViewClass, target.opMetadata, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2], arguments[fnIdx + 3], arguments[fnIdx + 4], arguments[fnIdx + 5], arguments[fnIdx + 6]);
391
- case 7:
392
- return self.span7(spanLine, spanName, childCtx, target.SpanBufferClass, target.remappedViewClass, target.opMetadata, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2], arguments[fnIdx + 3], arguments[fnIdx + 4], arguments[fnIdx + 5], arguments[fnIdx + 6], arguments[fnIdx + 7]);
393
- case 8:
394
- return self.span8(spanLine, spanName, childCtx, target.SpanBufferClass, target.remappedViewClass, target.opMetadata, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2], arguments[fnIdx + 3], arguments[fnIdx + 4], arguments[fnIdx + 5], arguments[fnIdx + 6], arguments[fnIdx + 7], arguments[fnIdx + 8]);
395
- default:
396
- throw new Error(`span() supports up to 8 arguments, got ${argCount}`);
397
- }
398
- };
399
- this.span = span;
400
- this.spanSync = function spanSync(name, fn) {
401
- const childCtx = self._newCtx0();
402
- return self.spanSync0(0, name, childCtx, getBufferConstructor(self._buffer), undefined, self._buffer._opMetadata, fn);
403
- };
458
+ if (hasSpan) {
459
+ const self = this;
460
+ const span = function span(nameOrLine, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11) {
461
+ // Use arguments.length instead of ...rest to avoid array allocation
462
+ const len = arguments.length;
463
+ // Detect call pattern:
464
+ // - span(name, fn) - len=2, typeof arg0 === 'string'
465
+ // - span(line, name, fn) - len=3, typeof arg0 === 'number'
466
+ // - span(name, overrides, fn) - len=3, typeof arg0 === 'string', typeof arg1 === 'object'
467
+ // - span(line, name, overrides, fn) - len=4, typeof arg0 === 'number', typeof arg2 === 'object'
468
+ // Plus additional args for span arguments
469
+ const hasLine = typeof nameOrLine === 'number';
470
+ const spanLine = hasLine ? nameOrLine : 0;
471
+ const spanName = hasLine ? readStringArgument(arguments, 1, 'span name') : nameOrLine;
472
+ // Index where fn/op or overrides starts
473
+ const checkIdx = hasLine ? 2 : 1;
474
+ const maybeOverrides = arguments[checkIdx];
475
+ // Check if it's an overrides object (not Op, not function)
476
+ const hasOverrides = maybeOverrides !== null &&
477
+ typeof maybeOverrides === 'object' &&
478
+ !isOpLike(maybeOverrides) &&
479
+ typeof maybeOverrides !== 'function';
480
+ const fnIdx = checkIdx + (hasOverrides ? 1 : 0);
481
+ const target = resolveSpanTarget(arguments[fnIdx], self._physicalLayoutPlan, self._spanBuffer._opMetadata);
482
+ const childCtx = asSpanContextInstance(hasOverrides ? target.callsitePlan.newCtx1(self, maybeOverrides) : target.callsitePlan.newCtx0(self));
483
+ // Dispatch to monomorphic methods with all Op properties extracted
484
+ const argCount = len - fnIdx - 1;
485
+ switch (argCount) {
486
+ case 0:
487
+ return self.span0(spanLine, spanName, childCtx, target.callsitePlan, target.fn);
488
+ case 1:
489
+ return self.span1(spanLine, spanName, childCtx, target.callsitePlan, target.fn, arguments[fnIdx + 1]);
490
+ case 2:
491
+ return self.span2(spanLine, spanName, childCtx, target.callsitePlan, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2]);
492
+ case 3:
493
+ return self.span3(spanLine, spanName, childCtx, target.callsitePlan, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2], arguments[fnIdx + 3]);
494
+ case 4:
495
+ return self.span4(spanLine, spanName, childCtx, target.callsitePlan, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2], arguments[fnIdx + 3], arguments[fnIdx + 4]);
496
+ case 5:
497
+ return self.span5(spanLine, spanName, childCtx, target.callsitePlan, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2], arguments[fnIdx + 3], arguments[fnIdx + 4], arguments[fnIdx + 5]);
498
+ case 6:
499
+ return self.span6(spanLine, spanName, childCtx, target.callsitePlan, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2], arguments[fnIdx + 3], arguments[fnIdx + 4], arguments[fnIdx + 5], arguments[fnIdx + 6]);
500
+ case 7:
501
+ return self.span7(spanLine, spanName, childCtx, target.callsitePlan, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2], arguments[fnIdx + 3], arguments[fnIdx + 4], arguments[fnIdx + 5], arguments[fnIdx + 6], arguments[fnIdx + 7]);
502
+ case 8:
503
+ return self.span8(spanLine, spanName, childCtx, target.callsitePlan, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2], arguments[fnIdx + 3], arguments[fnIdx + 4], arguments[fnIdx + 5], arguments[fnIdx + 6], arguments[fnIdx + 7], arguments[fnIdx + 8]);
504
+ default:
505
+ throw new Error(`span() supports up to 8 arguments, got ${argCount}`);
506
+ }
507
+ };
508
+ this.span = span;
509
+ this.spanSync = function spanSync(name, op) {
510
+ const callsitePlan = op.callsitePlan;
511
+ const childCtx = asSpanContextInstance(callsitePlan.newCtx0(self));
512
+ return self.spanSync0(0, name, childCtx, callsitePlan, op.fn);
513
+ };
514
+ }
404
515
  //#endregion smoo/lmao!n/context-flow-span-promise
405
516
  }
406
517
  // =========================================================================
@@ -410,35 +521,43 @@ export function createSpanContextClass(_schemaOnly, logBinding) {
410
521
  return true;
411
522
  }
412
523
  get module() {
413
- return this._buffer._opMetadata;
524
+ return this._spanBuffer._opMetadata;
414
525
  }
415
526
  get callee_package() {
416
- return this._buffer._opMetadata.package_name;
527
+ return this._spanBuffer._opMetadata.package_name;
417
528
  }
418
529
  get callee_file() {
419
- return this._buffer._opMetadata.package_file;
530
+ return this._spanBuffer._opMetadata.package_file;
420
531
  }
421
532
  get callee_line() {
422
533
  // Access the line_values array directly to read line number at row 0
423
534
  // line_values is a Float64Array per the system schema (LazyNumberSchema)
424
- return this._buffer.line_values[0];
535
+ return this._spanBuffer.line_values[0];
425
536
  }
426
537
  get callee_git_sha() {
427
- return this._buffer._opMetadata.git_sha;
538
+ return this._spanBuffer._opMetadata.git_sha;
428
539
  }
429
540
  get buffer() {
430
- return this._buffer;
541
+ return this._spanBuffer;
431
542
  }
432
543
  //#region smoo/lmao!n/scope-attributes.read
433
544
  // 01i read-only scope view: the immutable _scopeValues snapshot (setScope is wired in the
434
545
  // destructured-context region; the immutable merge is _setScope in spanLoggerGenerator).
435
546
  get scope() {
436
- return this._buffer._scopeValues;
547
+ return this._spanBuffer._scopeValues;
437
548
  }
438
549
  //#endregion smoo/lmao!n/scope-attributes.read
439
550
  // =========================================================================
440
551
  // Internal methods (on prototype)
441
552
  // =========================================================================
553
+ _appendWriterEntry(entryType) {
554
+ if (this._buffer._writeIndex >= this._buffer._capacity) {
555
+ this._buffer = this._buffer.getOrCreateOverflow();
556
+ this._spanLogger._prefillScopedAttributesOn(this._buffer);
557
+ }
558
+ const traceRoot = this._buffer._traceRoot;
559
+ return this._appendLogEntry(traceRoot, this._buffer, entryType);
560
+ }
442
561
  /**
443
562
  * Create a new child context with prototype chain inheritance.
444
563
  * Called by transformer for spans without overrides.
@@ -446,7 +565,7 @@ export function createSpanContextClass(_schemaOnly, logBinding) {
446
565
  * Transformer emits: ctx.span0(line, name, ctx._newCtx0(), fn)
447
566
  */
448
567
  _newCtx0() {
449
- return createInheritedContext(this);
568
+ return asSpanContextInstance(this._physicalLayoutPlan.newCtx0(this));
450
569
  }
451
570
  /**
452
571
  * Create a new child context with prototype chain inheritance + user overrides.
@@ -455,7 +574,7 @@ export function createSpanContextClass(_schemaOnly, logBinding) {
455
574
  * Transformer emits: ctx.span0(line, name, ctx._newCtx1({ requestId }), fn)
456
575
  */
457
576
  _newCtx1(overrides) {
458
- return createInheritedContextWithOverrides(this, overrides);
577
+ return asSpanContextInstance(this._physicalLayoutPlan.newCtx1(this, overrides));
459
578
  }
460
579
  /**
461
580
  * Complete child span context setup - creates buffer, registers with parent.
@@ -468,116 +587,27 @@ export function createSpanContextClass(_schemaOnly, logBinding) {
468
587
  * @param line - Source line number (0 if not provided by transformer)
469
588
  * @param name - Child span name
470
589
  * @param SpanBufferClass - Buffer class to use (Op's class or parent's class for plain functions)
471
- * @param remappedViewClass - Optional view class for prefixed ops (wraps buffer for Arrow conversion)
590
+ * @param remapDescriptor - Optional immutable cold-path output mapping
472
591
  * @param opMetadata - Metadata for the executing op (Op's metadata or parent's for plain functions)
473
592
  */
474
593
  //#region smoo/lmao!n/context-flow-child-span
475
594
  // 01c "Child Span Creation via span()" / "How span() Works" and 01e "Op's Responsibility:
476
- // Buffer Creation and Registration": _spanPre is where the child SpanBuffer is created
477
- // (via the buffer strategy, using the Op's SpanBufferClass for cross-library schema),
478
- // wrapped in a RemappedBufferView when the dep is prefixed/mapped, registered in the
479
- // parent's _children, and span-start (row 0) is written with the caller's line number.
480
- _spanPre(childCtx, line, name, SpanBufferClass, remappedViewClass, opMetadata) {
481
- // Get Op's schema for cross-library calls (child may have different schema than parent)
482
- const childSchema = SpanBufferClass.schema;
483
- // Use buffer strategy for child span creation (supports both JS and WASM buffers)
484
- // Pass schema for cross-library calls where child has different schema than parent
485
- const createdBuffer = this._buffer._traceRoot.tracer.bufferStrategy.createChildSpanBuffer(this._buffer, // parentBuffer
486
- this._buffer._opMetadata, // callsiteMetadata - WHO called span() (for row 0)
487
- opMetadata, // opMetadata - WHICH op is executing (for rows 1+)
488
- undefined, // capacity - use default
489
- childSchema);
490
- if (!isSpanBufferForSchema(createdBuffer, childSchema)) {
491
- throw new TypeError('Child span buffer does not match the requested schema');
492
- }
595
+ // _spanPre creates the child through the planned schema/capacity, attaches the immutable
596
+ // cold-path remap descriptor to the raw buffer, registers it, and writes row 0.
597
+ _spanPre(childCtx, line, name, callsitePlan, opMetadata) {
598
+ const childSchema = callsitePlan.schema;
599
+ const createdBuffer = this._spanBuffer._traceRoot.tracer.bufferStrategy.createChildSpanBuffer(this._spanBuffer, this._spanBuffer._opMetadata, opMetadata, callsitePlan.capacityTier, childSchema, callsitePlan.SpanBufferClass);
493
600
  const childBuffer = createdBuffer;
494
- // Why wrap buffer: RemappedBufferView translates prefixed column names during Arrow conversion
495
- // Parent sees remapped names, child sees unprefixed names (transparent to child)
496
- const bufferOrView = remappedViewClass ? new remappedViewClass(childBuffer) : childBuffer;
497
- // Why push wrapped buffer: Parent's _children see remapped names for Arrow conversion
498
- this._buffer._children.push(bufferOrView);
499
- // Write span-start for child span (row 0) and pre-initialize span-end (row 1)
500
- writeSpanStart(childBuffer, name);
501
- // Write line number to row 0 (line() takes pos and value)
601
+ childBuffer._remapDescriptor = callsitePlan.remapDescriptor ?? undefined;
602
+ callsitePlan.appenders.writeSpanStart(childBuffer, name);
502
603
  childBuffer.line(0, line);
503
- const childLogger = createSpanLogger(childSchema, childBuffer);
504
- const childTagAPI = createTagWriter(childSchema, childBuffer);
505
- // Cast to impl for property assignment
506
- const ctx = childCtx;
507
- // ═══════════════════════════════════════════════════════════════════
508
- // PROPERTY ASSIGNMENT ORDER: HOT → COLD (V8 in-object slots optimization)
509
- // First ~10-12 properties get fast in-object slots per spec
510
- // ═══════════════════════════════════════════════════════════════════
511
- // SLOT 1-4: HOTTEST - accessed on every span operation
512
- ctx._buffer = childBuffer;
513
- ctx._spanLogger = childLogger;
514
- ctx.tag = childTagAPI;
515
- ctx.log = childLogger;
516
- // SLOT 5-7: HOT - reserved keys copied from parent for O(1) access
517
- ctx.deps = this.deps;
518
- // Create child-bound FF evaluator so flag access logs to child buffer
519
- // If no evaluator (ff is EMPTY_SCOPE), just copy the reference
520
- ctx.ff = this.ff.forContext ? this.ff.forContext(ctx) : this.ff;
521
- // Note: user-defined extras (env, requestId, etc.) inherited via prototype chain
522
- // SLOT 8-11: WARM - function properties (created per-context for destructuring)
523
- // Regular functions close over local variables directly - no property lookups
524
- const childSpan = function span(nameOrLine, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10, _arg11) {
525
- const len = arguments.length;
526
- const hasLine = typeof nameOrLine === 'number';
527
- const spanLine = hasLine ? nameOrLine : 0;
528
- const spanName = hasLine ? readStringArgument(arguments, 1, 'span name') : nameOrLine;
529
- const checkIdx = hasLine ? 2 : 1;
530
- const maybeOverrides = arguments[checkIdx];
531
- const hasOverrides = maybeOverrides !== null &&
532
- typeof maybeOverrides === 'object' &&
533
- !(maybeOverrides instanceof Op) &&
534
- typeof maybeOverrides !== 'function';
535
- const fnIdx = checkIdx + (hasOverrides ? 1 : 0);
536
- const target = resolveSpanTarget(arguments[fnIdx], childBuffer);
537
- // Create child context - use _newCtx0 or _newCtx1 based on overrides
538
- const newChildCtx = hasOverrides ? ctx._newCtx1(maybeOverrides) : ctx._newCtx0();
539
- const argCount = len - fnIdx - 1;
540
- switch (argCount) {
541
- case 0:
542
- return ctx.span0(spanLine, spanName, newChildCtx, target.SpanBufferClass, target.remappedViewClass, target.opMetadata, target.fn);
543
- case 1:
544
- return ctx.span1(spanLine, spanName, newChildCtx, target.SpanBufferClass, target.remappedViewClass, target.opMetadata, target.fn, arguments[fnIdx + 1]);
545
- case 2:
546
- return ctx.span2(spanLine, spanName, newChildCtx, target.SpanBufferClass, target.remappedViewClass, target.opMetadata, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2]);
547
- case 3:
548
- return ctx.span3(spanLine, spanName, newChildCtx, target.SpanBufferClass, target.remappedViewClass, target.opMetadata, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2], arguments[fnIdx + 3]);
549
- case 4:
550
- return ctx.span4(spanLine, spanName, newChildCtx, target.SpanBufferClass, target.remappedViewClass, target.opMetadata, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2], arguments[fnIdx + 3], arguments[fnIdx + 4]);
551
- case 5:
552
- return ctx.span5(spanLine, spanName, newChildCtx, target.SpanBufferClass, target.remappedViewClass, target.opMetadata, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2], arguments[fnIdx + 3], arguments[fnIdx + 4], arguments[fnIdx + 5]);
553
- case 6:
554
- return ctx.span6(spanLine, spanName, newChildCtx, target.SpanBufferClass, target.remappedViewClass, target.opMetadata, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2], arguments[fnIdx + 3], arguments[fnIdx + 4], arguments[fnIdx + 5], arguments[fnIdx + 6]);
555
- case 7:
556
- return ctx.span7(spanLine, spanName, newChildCtx, target.SpanBufferClass, target.remappedViewClass, target.opMetadata, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2], arguments[fnIdx + 3], arguments[fnIdx + 4], arguments[fnIdx + 5], arguments[fnIdx + 6], arguments[fnIdx + 7]);
557
- case 8:
558
- return ctx.span8(spanLine, spanName, newChildCtx, target.SpanBufferClass, target.remappedViewClass, target.opMetadata, target.fn, arguments[fnIdx + 1], arguments[fnIdx + 2], arguments[fnIdx + 3], arguments[fnIdx + 4], arguments[fnIdx + 5], arguments[fnIdx + 6], arguments[fnIdx + 7], arguments[fnIdx + 8]);
559
- default:
560
- throw new Error(`span() supports up to 8 arguments, got ${argCount}`);
561
- }
562
- };
563
- ctx.span = childSpan;
564
- ctx.spanSync = function spanSync(name, fn) {
565
- const newChildCtx = ctx._newCtx0();
566
- return ctx.spanSync0(0, name, newChildCtx, getBufferConstructor(childBuffer), undefined, childBuffer._opMetadata, fn);
567
- };
568
- ctx.ok = function ok(value) {
569
- return new Ok(value, childSchema, childBuffer);
570
- };
571
- ctx.err = function err(error) {
572
- return new Err(error, childSchema, childBuffer);
573
- };
574
- ctx.setScope = function setScope(attributes) {
575
- childLogger._setScope(attributes ?? {});
576
- };
577
- // SLOT 12+: COLD - internal/rarely accessed
578
- ctx._schema = childSchema;
579
- ctx._logBinding = logBinding;
580
- return ctx;
604
+ const childFfSource = Object.hasOwn(this, 'ff')
605
+ ? this.ff
606
+ : this._spanBuffer._traceRoot.tracer.getFlagEvaluatorForContext();
607
+ if (!isFlagEvaluatorForContext(childFfSource)) {
608
+ throw new TypeError('Span context requires a context evaluator');
609
+ }
610
+ return new callsitePlan.SpanContextClass(childBuffer, childSchema, callsitePlan, childCtx, undefined, this.deps, childFfSource);
581
611
  }
582
612
  //#endregion smoo/lmao!n/context-flow-child-span
583
613
  //#region smoo/lmao!n/lmao-entry-span-lifecycle-entry-types.exception
@@ -586,8 +616,7 @@ export function createSpanContextClass(_schemaOnly, logBinding) {
586
616
  * Called in catch blocks of span methods.
587
617
  */
588
618
  _spanException(childBuffer, error) {
589
- // Write entry_type and timestamp via TraceRoot (platform-specific)
590
- childBuffer._traceRoot.writeSpanEnd(childBuffer, ENTRY_TYPE_SPAN_EXCEPTION);
619
+ writeSpanEndEntry(childBuffer, ENTRY_TYPE_SPAN_EXCEPTION);
591
620
  const errorMessage = error instanceof Error ? error.message : String(error);
592
621
  const errorStack = error instanceof Error ? error.stack : undefined;
593
622
  childBuffer.message(1, errorMessage);
@@ -596,18 +625,466 @@ export function createSpanContextClass(_schemaOnly, logBinding) {
596
625
  }
597
626
  }
598
627
  //#endregion smoo/lmao!n/lmao-entry-span-lifecycle-entry-types.exception
628
+ _spanAutoPre(line, name, op) {
629
+ const child = asSpanContextInstance(op.callsitePlan.newCtx0(this));
630
+ return this._spanPre(child, line, name, op.callsitePlan, op.metadata);
631
+ }
632
+ spanAuto0(line, name, op) {
633
+ const ctx = this._spanAutoPre(line, name, op);
634
+ const buffer = ctx._spanBuffer;
635
+ buffer._traceRoot.tracer.onSpanStart(buffer);
636
+ let isAsync = false;
637
+ try {
638
+ const result = op.fn(ctx);
639
+ if (!isSynchronousResult(result) || getRetryableError(result, 1) !== undefined) {
640
+ isAsync = true;
641
+ return this._spanAutoAsync0(ctx, buffer, op, result);
642
+ }
643
+ writeSpanEnd(buffer, result);
644
+ return result;
645
+ }
646
+ catch (error) {
647
+ this._spanException(buffer, error);
648
+ throw error;
649
+ }
650
+ finally {
651
+ if (!isAsync) {
652
+ buffer._traceRoot.tracer.onSpanEnd(buffer);
653
+ }
654
+ }
655
+ }
656
+ async _spanAutoAsync0(ctx, buffer, op, first) {
657
+ try {
658
+ let attempt = 1;
659
+ let result = await first;
660
+ while (true) {
661
+ const retryError = getRetryableError(result, attempt);
662
+ if (!retryError)
663
+ break;
664
+ const delay = calculateDelay(retryError.policy, attempt);
665
+ writeRetryEntry(buffer, attempt, retryError, delay);
666
+ await sleep(delay);
667
+ attempt++;
668
+ result = await op.fn(ctx);
669
+ }
670
+ writeSpanEnd(buffer, result);
671
+ return result;
672
+ }
673
+ catch (error) {
674
+ this._spanException(buffer, error);
675
+ throw error;
676
+ }
677
+ finally {
678
+ buffer._traceRoot.tracer.onSpanEnd(buffer);
679
+ }
680
+ }
681
+ spanAuto1(line, name, op, a1) {
682
+ const ctx = this._spanAutoPre(line, name, op);
683
+ const buffer = ctx._spanBuffer;
684
+ buffer._traceRoot.tracer.onSpanStart(buffer);
685
+ let isAsync = false;
686
+ try {
687
+ const result = op.fn(ctx, a1);
688
+ if (!isSynchronousResult(result) || getRetryableError(result, 1) !== undefined) {
689
+ isAsync = true;
690
+ return this._spanAutoAsync1(ctx, buffer, op, result, a1);
691
+ }
692
+ writeSpanEnd(buffer, result);
693
+ return result;
694
+ }
695
+ catch (error) {
696
+ this._spanException(buffer, error);
697
+ throw error;
698
+ }
699
+ finally {
700
+ if (!isAsync) {
701
+ buffer._traceRoot.tracer.onSpanEnd(buffer);
702
+ }
703
+ }
704
+ }
705
+ async _spanAutoAsync1(ctx, buffer, op, first, a1) {
706
+ try {
707
+ let attempt = 1;
708
+ let result = await first;
709
+ while (true) {
710
+ const retryError = getRetryableError(result, attempt);
711
+ if (!retryError)
712
+ break;
713
+ const delay = calculateDelay(retryError.policy, attempt);
714
+ writeRetryEntry(buffer, attempt, retryError, delay);
715
+ await sleep(delay);
716
+ attempt++;
717
+ result = await op.fn(ctx, a1);
718
+ }
719
+ writeSpanEnd(buffer, result);
720
+ return result;
721
+ }
722
+ catch (error) {
723
+ this._spanException(buffer, error);
724
+ throw error;
725
+ }
726
+ finally {
727
+ buffer._traceRoot.tracer.onSpanEnd(buffer);
728
+ }
729
+ }
730
+ spanAuto2(line, name, op, a1, a2) {
731
+ const ctx = this._spanAutoPre(line, name, op);
732
+ const buffer = ctx._spanBuffer;
733
+ buffer._traceRoot.tracer.onSpanStart(buffer);
734
+ let isAsync = false;
735
+ try {
736
+ const result = op.fn(ctx, a1, a2);
737
+ if (!isSynchronousResult(result) || getRetryableError(result, 1) !== undefined) {
738
+ isAsync = true;
739
+ return this._spanAutoAsync2(ctx, buffer, op, result, a1, a2);
740
+ }
741
+ writeSpanEnd(buffer, result);
742
+ return result;
743
+ }
744
+ catch (error) {
745
+ this._spanException(buffer, error);
746
+ throw error;
747
+ }
748
+ finally {
749
+ if (!isAsync) {
750
+ buffer._traceRoot.tracer.onSpanEnd(buffer);
751
+ }
752
+ }
753
+ }
754
+ async _spanAutoAsync2(ctx, buffer, op, first, a1, a2) {
755
+ try {
756
+ let attempt = 1;
757
+ let result = await first;
758
+ while (true) {
759
+ const retryError = getRetryableError(result, attempt);
760
+ if (!retryError)
761
+ break;
762
+ const delay = calculateDelay(retryError.policy, attempt);
763
+ writeRetryEntry(buffer, attempt, retryError, delay);
764
+ await sleep(delay);
765
+ attempt++;
766
+ result = await op.fn(ctx, a1, a2);
767
+ }
768
+ writeSpanEnd(buffer, result);
769
+ return result;
770
+ }
771
+ catch (error) {
772
+ this._spanException(buffer, error);
773
+ throw error;
774
+ }
775
+ finally {
776
+ buffer._traceRoot.tracer.onSpanEnd(buffer);
777
+ }
778
+ }
779
+ spanAuto3(line, name, op, a1, a2, a3) {
780
+ const ctx = this._spanAutoPre(line, name, op);
781
+ const buffer = ctx._spanBuffer;
782
+ buffer._traceRoot.tracer.onSpanStart(buffer);
783
+ let isAsync = false;
784
+ try {
785
+ const result = op.fn(ctx, a1, a2, a3);
786
+ if (!isSynchronousResult(result) || getRetryableError(result, 1) !== undefined) {
787
+ isAsync = true;
788
+ return this._spanAutoAsync3(ctx, buffer, op, result, a1, a2, a3);
789
+ }
790
+ writeSpanEnd(buffer, result);
791
+ return result;
792
+ }
793
+ catch (error) {
794
+ this._spanException(buffer, error);
795
+ throw error;
796
+ }
797
+ finally {
798
+ if (!isAsync) {
799
+ buffer._traceRoot.tracer.onSpanEnd(buffer);
800
+ }
801
+ }
802
+ }
803
+ async _spanAutoAsync3(ctx, buffer, op, first, a1, a2, a3) {
804
+ try {
805
+ let attempt = 1;
806
+ let result = await first;
807
+ while (true) {
808
+ const retryError = getRetryableError(result, attempt);
809
+ if (!retryError)
810
+ break;
811
+ const delay = calculateDelay(retryError.policy, attempt);
812
+ writeRetryEntry(buffer, attempt, retryError, delay);
813
+ await sleep(delay);
814
+ attempt++;
815
+ result = await op.fn(ctx, a1, a2, a3);
816
+ }
817
+ writeSpanEnd(buffer, result);
818
+ return result;
819
+ }
820
+ catch (error) {
821
+ this._spanException(buffer, error);
822
+ throw error;
823
+ }
824
+ finally {
825
+ buffer._traceRoot.tracer.onSpanEnd(buffer);
826
+ }
827
+ }
828
+ spanAuto4(line, name, op, a1, a2, a3, a4) {
829
+ const ctx = this._spanAutoPre(line, name, op);
830
+ const buffer = ctx._spanBuffer;
831
+ buffer._traceRoot.tracer.onSpanStart(buffer);
832
+ let isAsync = false;
833
+ try {
834
+ const result = op.fn(ctx, a1, a2, a3, a4);
835
+ if (!isSynchronousResult(result) || getRetryableError(result, 1) !== undefined) {
836
+ isAsync = true;
837
+ return this._spanAutoAsync4(ctx, buffer, op, result, a1, a2, a3, a4);
838
+ }
839
+ writeSpanEnd(buffer, result);
840
+ return result;
841
+ }
842
+ catch (error) {
843
+ this._spanException(buffer, error);
844
+ throw error;
845
+ }
846
+ finally {
847
+ if (!isAsync) {
848
+ buffer._traceRoot.tracer.onSpanEnd(buffer);
849
+ }
850
+ }
851
+ }
852
+ async _spanAutoAsync4(ctx, buffer, op, first, a1, a2, a3, a4) {
853
+ try {
854
+ let attempt = 1;
855
+ let result = await first;
856
+ while (true) {
857
+ const retryError = getRetryableError(result, attempt);
858
+ if (!retryError)
859
+ break;
860
+ const delay = calculateDelay(retryError.policy, attempt);
861
+ writeRetryEntry(buffer, attempt, retryError, delay);
862
+ await sleep(delay);
863
+ attempt++;
864
+ result = await op.fn(ctx, a1, a2, a3, a4);
865
+ }
866
+ writeSpanEnd(buffer, result);
867
+ return result;
868
+ }
869
+ catch (error) {
870
+ this._spanException(buffer, error);
871
+ throw error;
872
+ }
873
+ finally {
874
+ buffer._traceRoot.tracer.onSpanEnd(buffer);
875
+ }
876
+ }
877
+ spanAuto5(line, name, op, a1, a2, a3, a4, a5) {
878
+ const ctx = this._spanAutoPre(line, name, op);
879
+ const buffer = ctx._spanBuffer;
880
+ buffer._traceRoot.tracer.onSpanStart(buffer);
881
+ let isAsync = false;
882
+ try {
883
+ const result = op.fn(ctx, a1, a2, a3, a4, a5);
884
+ if (!isSynchronousResult(result) || getRetryableError(result, 1) !== undefined) {
885
+ isAsync = true;
886
+ return this._spanAutoAsync5(ctx, buffer, op, result, a1, a2, a3, a4, a5);
887
+ }
888
+ writeSpanEnd(buffer, result);
889
+ return result;
890
+ }
891
+ catch (error) {
892
+ this._spanException(buffer, error);
893
+ throw error;
894
+ }
895
+ finally {
896
+ if (!isAsync) {
897
+ buffer._traceRoot.tracer.onSpanEnd(buffer);
898
+ }
899
+ }
900
+ }
901
+ async _spanAutoAsync5(ctx, buffer, op, first, a1, a2, a3, a4, a5) {
902
+ try {
903
+ let attempt = 1;
904
+ let result = await first;
905
+ while (true) {
906
+ const retryError = getRetryableError(result, attempt);
907
+ if (!retryError)
908
+ break;
909
+ const delay = calculateDelay(retryError.policy, attempt);
910
+ writeRetryEntry(buffer, attempt, retryError, delay);
911
+ await sleep(delay);
912
+ attempt++;
913
+ result = await op.fn(ctx, a1, a2, a3, a4, a5);
914
+ }
915
+ writeSpanEnd(buffer, result);
916
+ return result;
917
+ }
918
+ catch (error) {
919
+ this._spanException(buffer, error);
920
+ throw error;
921
+ }
922
+ finally {
923
+ buffer._traceRoot.tracer.onSpanEnd(buffer);
924
+ }
925
+ }
926
+ spanAuto6(line, name, op, a1, a2, a3, a4, a5, a6) {
927
+ const ctx = this._spanAutoPre(line, name, op);
928
+ const buffer = ctx._spanBuffer;
929
+ buffer._traceRoot.tracer.onSpanStart(buffer);
930
+ let isAsync = false;
931
+ try {
932
+ const result = op.fn(ctx, a1, a2, a3, a4, a5, a6);
933
+ if (!isSynchronousResult(result) || getRetryableError(result, 1) !== undefined) {
934
+ isAsync = true;
935
+ return this._spanAutoAsync6(ctx, buffer, op, result, a1, a2, a3, a4, a5, a6);
936
+ }
937
+ writeSpanEnd(buffer, result);
938
+ return result;
939
+ }
940
+ catch (error) {
941
+ this._spanException(buffer, error);
942
+ throw error;
943
+ }
944
+ finally {
945
+ if (!isAsync) {
946
+ buffer._traceRoot.tracer.onSpanEnd(buffer);
947
+ }
948
+ }
949
+ }
950
+ async _spanAutoAsync6(ctx, buffer, op, first, a1, a2, a3, a4, a5, a6) {
951
+ try {
952
+ let attempt = 1;
953
+ let result = await first;
954
+ while (true) {
955
+ const retryError = getRetryableError(result, attempt);
956
+ if (!retryError)
957
+ break;
958
+ const delay = calculateDelay(retryError.policy, attempt);
959
+ writeRetryEntry(buffer, attempt, retryError, delay);
960
+ await sleep(delay);
961
+ attempt++;
962
+ result = await op.fn(ctx, a1, a2, a3, a4, a5, a6);
963
+ }
964
+ writeSpanEnd(buffer, result);
965
+ return result;
966
+ }
967
+ catch (error) {
968
+ this._spanException(buffer, error);
969
+ throw error;
970
+ }
971
+ finally {
972
+ buffer._traceRoot.tracer.onSpanEnd(buffer);
973
+ }
974
+ }
975
+ spanAuto7(line, name, op, a1, a2, a3, a4, a5, a6, a7) {
976
+ const ctx = this._spanAutoPre(line, name, op);
977
+ const buffer = ctx._spanBuffer;
978
+ buffer._traceRoot.tracer.onSpanStart(buffer);
979
+ let isAsync = false;
980
+ try {
981
+ const result = op.fn(ctx, a1, a2, a3, a4, a5, a6, a7);
982
+ if (!isSynchronousResult(result) || getRetryableError(result, 1) !== undefined) {
983
+ isAsync = true;
984
+ return this._spanAutoAsync7(ctx, buffer, op, result, a1, a2, a3, a4, a5, a6, a7);
985
+ }
986
+ writeSpanEnd(buffer, result);
987
+ return result;
988
+ }
989
+ catch (error) {
990
+ this._spanException(buffer, error);
991
+ throw error;
992
+ }
993
+ finally {
994
+ if (!isAsync) {
995
+ buffer._traceRoot.tracer.onSpanEnd(buffer);
996
+ }
997
+ }
998
+ }
999
+ async _spanAutoAsync7(ctx, buffer, op, first, a1, a2, a3, a4, a5, a6, a7) {
1000
+ try {
1001
+ let attempt = 1;
1002
+ let result = await first;
1003
+ while (true) {
1004
+ const retryError = getRetryableError(result, attempt);
1005
+ if (!retryError)
1006
+ break;
1007
+ const delay = calculateDelay(retryError.policy, attempt);
1008
+ writeRetryEntry(buffer, attempt, retryError, delay);
1009
+ await sleep(delay);
1010
+ attempt++;
1011
+ result = await op.fn(ctx, a1, a2, a3, a4, a5, a6, a7);
1012
+ }
1013
+ writeSpanEnd(buffer, result);
1014
+ return result;
1015
+ }
1016
+ catch (error) {
1017
+ this._spanException(buffer, error);
1018
+ throw error;
1019
+ }
1020
+ finally {
1021
+ buffer._traceRoot.tracer.onSpanEnd(buffer);
1022
+ }
1023
+ }
1024
+ spanAuto8(line, name, op, a1, a2, a3, a4, a5, a6, a7, a8) {
1025
+ const ctx = this._spanAutoPre(line, name, op);
1026
+ const buffer = ctx._spanBuffer;
1027
+ buffer._traceRoot.tracer.onSpanStart(buffer);
1028
+ let isAsync = false;
1029
+ try {
1030
+ const result = op.fn(ctx, a1, a2, a3, a4, a5, a6, a7, a8);
1031
+ if (!isSynchronousResult(result) || getRetryableError(result, 1) !== undefined) {
1032
+ isAsync = true;
1033
+ return this._spanAutoAsync8(ctx, buffer, op, result, a1, a2, a3, a4, a5, a6, a7, a8);
1034
+ }
1035
+ writeSpanEnd(buffer, result);
1036
+ return result;
1037
+ }
1038
+ catch (error) {
1039
+ this._spanException(buffer, error);
1040
+ throw error;
1041
+ }
1042
+ finally {
1043
+ if (!isAsync) {
1044
+ buffer._traceRoot.tracer.onSpanEnd(buffer);
1045
+ }
1046
+ }
1047
+ }
1048
+ async _spanAutoAsync8(ctx, buffer, op, first, a1, a2, a3, a4, a5, a6, a7, a8) {
1049
+ try {
1050
+ let attempt = 1;
1051
+ let result = await first;
1052
+ while (true) {
1053
+ const retryError = getRetryableError(result, attempt);
1054
+ if (!retryError)
1055
+ break;
1056
+ const delay = calculateDelay(retryError.policy, attempt);
1057
+ writeRetryEntry(buffer, attempt, retryError, delay);
1058
+ await sleep(delay);
1059
+ attempt++;
1060
+ result = await op.fn(ctx, a1, a2, a3, a4, a5, a6, a7, a8);
1061
+ }
1062
+ writeSpanEnd(buffer, result);
1063
+ return result;
1064
+ }
1065
+ catch (error) {
1066
+ this._spanException(buffer, error);
1067
+ throw error;
1068
+ }
1069
+ finally {
1070
+ buffer._traceRoot.tracer.onSpanEnd(buffer);
1071
+ }
1072
+ }
599
1073
  // =========================================================================
600
1074
  // Monomorphic span methods (for transformer output)
601
- // Transformer emits: ctx.span0(line, name, ctx, fn) or
602
- // ctx.span0(line, name, Object.assign(Object.create(ctx), overrides), fn)
603
- // childCtx inherits from parent via prototype chain, may have user overrides as own properties
1075
+ // Transformer emits: ctx.span0(line, name, plan.newCtx0(ctx), plan, fn)
1076
+ // The frozen plan supplies the exact context source factory for each callsite.
1077
+ // User overrides are materialized by plan.newCtx1 without prototype allocation.
604
1078
  // =========================================================================
605
- spanSync0(line, name, childCtx, SpanBufferClass, remappedViewClass, opMetadata, fn) {
606
- const ctx = this._spanPre(childCtx, line, name, SpanBufferClass, remappedViewClass, opMetadata);
607
- const buffer = ctx._buffer;
1079
+ spanSync0(line, name, childCtx, callsitePlan, fn) {
1080
+ const ctx = this._spanPre(childCtx, line, name, callsitePlan, callsitePlan.metadata);
1081
+ const buffer = ctx._spanBuffer;
608
1082
  buffer._traceRoot.tracer.onSpanStart(buffer);
609
1083
  try {
610
1084
  const result = fn(ctx);
1085
+ if (!isSynchronousResult(result)) {
1086
+ throw new TypeError('spanSync operation returned a Promise');
1087
+ }
611
1088
  writeSpanEnd(buffer, result);
612
1089
  return result;
613
1090
  }
@@ -619,13 +1096,13 @@ export function createSpanContextClass(_schemaOnly, logBinding) {
619
1096
  buffer._traceRoot.tracer.onSpanEnd(buffer);
620
1097
  }
621
1098
  }
622
- async span0(line, name, childCtx, SpanBufferClass, remappedViewClass, opMetadata, fn) {
623
- const ctx = this._spanPre(childCtx, line, name, SpanBufferClass, remappedViewClass, opMetadata);
624
- const buffer = ctx._buffer;
1099
+ async span0(line, name, childCtx, callsitePlan, fn) {
1100
+ const ctx = this._spanPre(childCtx, line, name, callsitePlan, callsitePlan.metadata);
1101
+ const buffer = ctx._spanBuffer;
625
1102
  buffer._traceRoot.tracer.onSpanStart(buffer);
626
1103
  try {
627
1104
  // Execute with retry loop - TransientError triggers retry, BlockedError returns immediately
628
- const result = await executeWithRetry(buffer, () => fn(ctx));
1105
+ const result = await executeWithRetry0(buffer, fn, ctx);
629
1106
  writeSpanEnd(buffer, result);
630
1107
  return result;
631
1108
  }
@@ -637,13 +1114,13 @@ export function createSpanContextClass(_schemaOnly, logBinding) {
637
1114
  buffer._traceRoot.tracer.onSpanEnd(buffer);
638
1115
  }
639
1116
  }
640
- async span1(line, name, childCtx, SpanBufferClass, remappedViewClass, opMetadata, fn, a1) {
641
- const ctx = this._spanPre(childCtx, line, name, SpanBufferClass, remappedViewClass, opMetadata);
642
- const buffer = ctx._buffer;
1117
+ async span1(line, name, childCtx, callsitePlan, fn, a1) {
1118
+ const ctx = this._spanPre(childCtx, line, name, callsitePlan, callsitePlan.metadata);
1119
+ const buffer = ctx._spanBuffer;
643
1120
  buffer._traceRoot.tracer.onSpanStart(buffer);
644
1121
  try {
645
1122
  // Execute with retry loop - TransientError triggers retry, BlockedError returns immediately
646
- const result = await executeWithRetry(buffer, () => fn(ctx, a1));
1123
+ const result = await executeWithRetry1(buffer, fn, ctx, a1);
647
1124
  writeSpanEnd(buffer, result);
648
1125
  return result;
649
1126
  }
@@ -655,13 +1132,13 @@ export function createSpanContextClass(_schemaOnly, logBinding) {
655
1132
  buffer._traceRoot.tracer.onSpanEnd(buffer);
656
1133
  }
657
1134
  }
658
- async span2(line, name, childCtx, SpanBufferClass, remappedViewClass, opMetadata, fn, a1, a2) {
659
- const ctx = this._spanPre(childCtx, line, name, SpanBufferClass, remappedViewClass, opMetadata);
660
- const buffer = ctx._buffer;
1135
+ async span2(line, name, childCtx, callsitePlan, fn, a1, a2) {
1136
+ const ctx = this._spanPre(childCtx, line, name, callsitePlan, callsitePlan.metadata);
1137
+ const buffer = ctx._spanBuffer;
661
1138
  buffer._traceRoot.tracer.onSpanStart(buffer);
662
1139
  try {
663
1140
  // Execute with retry loop - TransientError triggers retry, BlockedError returns immediately
664
- const result = await executeWithRetry(buffer, () => fn(ctx, a1, a2));
1141
+ const result = await executeWithRetry2(buffer, fn, ctx, a1, a2);
665
1142
  writeSpanEnd(buffer, result);
666
1143
  return result;
667
1144
  }
@@ -673,13 +1150,13 @@ export function createSpanContextClass(_schemaOnly, logBinding) {
673
1150
  buffer._traceRoot.tracer.onSpanEnd(buffer);
674
1151
  }
675
1152
  }
676
- async span3(line, name, childCtx, SpanBufferClass, remappedViewClass, opMetadata, fn, a1, a2, a3) {
677
- const ctx = this._spanPre(childCtx, line, name, SpanBufferClass, remappedViewClass, opMetadata);
678
- const buffer = ctx._buffer;
1153
+ async span3(line, name, childCtx, callsitePlan, fn, a1, a2, a3) {
1154
+ const ctx = this._spanPre(childCtx, line, name, callsitePlan, callsitePlan.metadata);
1155
+ const buffer = ctx._spanBuffer;
679
1156
  buffer._traceRoot.tracer.onSpanStart(buffer);
680
1157
  try {
681
1158
  // Execute with retry loop - TransientError triggers retry, BlockedError returns immediately
682
- const result = await executeWithRetry(buffer, () => fn(ctx, a1, a2, a3));
1159
+ const result = await executeWithRetry3(buffer, fn, ctx, a1, a2, a3);
683
1160
  writeSpanEnd(buffer, result);
684
1161
  return result;
685
1162
  }
@@ -691,13 +1168,13 @@ export function createSpanContextClass(_schemaOnly, logBinding) {
691
1168
  buffer._traceRoot.tracer.onSpanEnd(buffer);
692
1169
  }
693
1170
  }
694
- async span4(line, name, childCtx, SpanBufferClass, remappedViewClass, opMetadata, fn, a1, a2, a3, a4) {
695
- const ctx = this._spanPre(childCtx, line, name, SpanBufferClass, remappedViewClass, opMetadata);
696
- const buffer = ctx._buffer;
1171
+ async span4(line, name, childCtx, callsitePlan, fn, a1, a2, a3, a4) {
1172
+ const ctx = this._spanPre(childCtx, line, name, callsitePlan, callsitePlan.metadata);
1173
+ const buffer = ctx._spanBuffer;
697
1174
  buffer._traceRoot.tracer.onSpanStart(buffer);
698
1175
  try {
699
1176
  // Execute with retry loop - TransientError triggers retry, BlockedError returns immediately
700
- const result = await executeWithRetry(buffer, () => fn(ctx, a1, a2, a3, a4));
1177
+ const result = await executeWithRetry4(buffer, fn, ctx, a1, a2, a3, a4);
701
1178
  writeSpanEnd(buffer, result);
702
1179
  return result;
703
1180
  }
@@ -709,13 +1186,13 @@ export function createSpanContextClass(_schemaOnly, logBinding) {
709
1186
  buffer._traceRoot.tracer.onSpanEnd(buffer);
710
1187
  }
711
1188
  }
712
- async span5(line, name, childCtx, SpanBufferClass, remappedViewClass, opMetadata, fn, a1, a2, a3, a4, a5) {
713
- const ctx = this._spanPre(childCtx, line, name, SpanBufferClass, remappedViewClass, opMetadata);
714
- const buffer = ctx._buffer;
1189
+ async span5(line, name, childCtx, callsitePlan, fn, a1, a2, a3, a4, a5) {
1190
+ const ctx = this._spanPre(childCtx, line, name, callsitePlan, callsitePlan.metadata);
1191
+ const buffer = ctx._spanBuffer;
715
1192
  buffer._traceRoot.tracer.onSpanStart(buffer);
716
1193
  try {
717
1194
  // Execute with retry loop - TransientError triggers retry, BlockedError returns immediately
718
- const result = await executeWithRetry(buffer, () => fn(ctx, a1, a2, a3, a4, a5));
1195
+ const result = await executeWithRetry5(buffer, fn, ctx, a1, a2, a3, a4, a5);
719
1196
  writeSpanEnd(buffer, result);
720
1197
  return result;
721
1198
  }
@@ -727,13 +1204,13 @@ export function createSpanContextClass(_schemaOnly, logBinding) {
727
1204
  buffer._traceRoot.tracer.onSpanEnd(buffer);
728
1205
  }
729
1206
  }
730
- async span6(line, name, childCtx, SpanBufferClass, remappedViewClass, opMetadata, fn, a1, a2, a3, a4, a5, a6) {
731
- const ctx = this._spanPre(childCtx, line, name, SpanBufferClass, remappedViewClass, opMetadata);
732
- const buffer = ctx._buffer;
1207
+ async span6(line, name, childCtx, callsitePlan, fn, a1, a2, a3, a4, a5, a6) {
1208
+ const ctx = this._spanPre(childCtx, line, name, callsitePlan, callsitePlan.metadata);
1209
+ const buffer = ctx._spanBuffer;
733
1210
  buffer._traceRoot.tracer.onSpanStart(buffer);
734
1211
  try {
735
1212
  // Execute with retry loop - TransientError triggers retry, BlockedError returns immediately
736
- const result = await executeWithRetry(buffer, () => fn(ctx, a1, a2, a3, a4, a5, a6));
1213
+ const result = await executeWithRetry6(buffer, fn, ctx, a1, a2, a3, a4, a5, a6);
737
1214
  writeSpanEnd(buffer, result);
738
1215
  return result;
739
1216
  }
@@ -745,13 +1222,13 @@ export function createSpanContextClass(_schemaOnly, logBinding) {
745
1222
  buffer._traceRoot.tracer.onSpanEnd(buffer);
746
1223
  }
747
1224
  }
748
- async span7(line, name, childCtx, SpanBufferClass, remappedViewClass, opMetadata, fn, a1, a2, a3, a4, a5, a6, a7) {
749
- const ctx = this._spanPre(childCtx, line, name, SpanBufferClass, remappedViewClass, opMetadata);
750
- const buffer = ctx._buffer;
1225
+ async span7(line, name, childCtx, callsitePlan, fn, a1, a2, a3, a4, a5, a6, a7) {
1226
+ const ctx = this._spanPre(childCtx, line, name, callsitePlan, callsitePlan.metadata);
1227
+ const buffer = ctx._spanBuffer;
751
1228
  buffer._traceRoot.tracer.onSpanStart(buffer);
752
1229
  try {
753
1230
  // Execute with retry loop - TransientError triggers retry, BlockedError returns immediately
754
- const result = await executeWithRetry(buffer, () => fn(ctx, a1, a2, a3, a4, a5, a6, a7));
1231
+ const result = await executeWithRetry7(buffer, fn, ctx, a1, a2, a3, a4, a5, a6, a7);
755
1232
  writeSpanEnd(buffer, result);
756
1233
  return result;
757
1234
  }
@@ -763,13 +1240,13 @@ export function createSpanContextClass(_schemaOnly, logBinding) {
763
1240
  buffer._traceRoot.tracer.onSpanEnd(buffer);
764
1241
  }
765
1242
  }
766
- async span8(line, name, childCtx, SpanBufferClass, remappedViewClass, opMetadata, fn, a1, a2, a3, a4, a5, a6, a7, a8) {
767
- const ctx = this._spanPre(childCtx, line, name, SpanBufferClass, remappedViewClass, opMetadata);
768
- const buffer = ctx._buffer;
1243
+ async span8(line, name, childCtx, callsitePlan, fn, a1, a2, a3, a4, a5, a6, a7, a8) {
1244
+ const ctx = this._spanPre(childCtx, line, name, callsitePlan, callsitePlan.metadata);
1245
+ const buffer = ctx._spanBuffer;
769
1246
  buffer._traceRoot.tracer.onSpanStart(buffer);
770
1247
  try {
771
1248
  // Execute with retry loop - TransientError triggers retry, BlockedError returns immediately
772
- const result = await executeWithRetry(buffer, () => fn(ctx, a1, a2, a3, a4, a5, a6, a7, a8));
1249
+ const result = await executeWithRetry8(buffer, fn, ctx, a1, a2, a3, a4, a5, a6, a7, a8);
773
1250
  writeSpanEnd(buffer, result);
774
1251
  return result;
775
1252
  }
@@ -783,6 +1260,7 @@ export function createSpanContextClass(_schemaOnly, logBinding) {
783
1260
  }
784
1261
  }
785
1262
  const SpanContextCtor = SpanContextImpl;
1263
+ cache.set(cacheKey, SpanContextCtor);
786
1264
  return SpanContextCtor;
787
1265
  }
788
1266
  // =============================================================================