@smoothbricks/lmao 0.1.2 → 0.1.4

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 (164) hide show
  1. package/dist/allocator.wasm +0 -0
  2. package/dist/es.d.ts.map +1 -1
  3. package/dist/es.js +1 -0
  4. package/dist/lib/archive/chunkCompaction.d.ts.map +1 -1
  5. package/dist/lib/archive/chunkCompaction.js +2 -0
  6. package/dist/lib/archive/chunkEnvelope.d.ts.map +1 -1
  7. package/dist/lib/archive/chunkRouting.d.ts.map +1 -1
  8. package/dist/lib/archive/chunkRouting.js +3 -0
  9. package/dist/lib/archive/chunkStats.d.ts.map +1 -1
  10. package/dist/lib/archive/chunkStats.js +1 -0
  11. package/dist/lib/arrow/capacityStats.d.ts.map +1 -1
  12. package/dist/lib/arrow/capacityStats.js +1 -0
  13. package/dist/lib/bufferStrategy.d.ts.map +1 -1
  14. package/dist/lib/capacityTuning.d.ts.map +1 -1
  15. package/dist/lib/capacityTuning.js +1 -0
  16. package/dist/lib/cleanupDiagnostics.d.ts +4 -0
  17. package/dist/lib/cleanupDiagnostics.d.ts.map +1 -0
  18. package/dist/lib/cleanupDiagnostics.js +42 -0
  19. package/dist/lib/codegen/evaluatorGenerator.d.ts.map +1 -1
  20. package/dist/lib/codegen/evaluatorGenerator.js +1 -0
  21. package/dist/lib/codegen/fixedPositionWriterGenerator.d.ts.map +1 -1
  22. package/dist/lib/codegen/fixedPositionWriterGenerator.js +1 -0
  23. package/dist/lib/codegen/spanLoggerGenerator.d.ts.map +1 -1
  24. package/dist/lib/codegen/spanLoggerGenerator.js +3 -0
  25. package/dist/lib/convertToArrow.d.ts.map +1 -1
  26. package/dist/lib/convertToArrow.js +6 -0
  27. package/dist/lib/defineOpContext.d.ts +5 -0
  28. package/dist/lib/defineOpContext.d.ts.map +1 -1
  29. package/dist/lib/defineOpContext.js +11 -1
  30. package/dist/lib/errors/Blocked.d.ts.map +1 -1
  31. package/dist/lib/errors/Transient.d.ts.map +1 -1
  32. package/dist/lib/errors/retry-policy.d.ts.map +1 -1
  33. package/dist/lib/flushScheduler.d.ts.map +1 -1
  34. package/dist/lib/flushScheduler.js +12 -0
  35. package/dist/lib/library.d.ts +5 -0
  36. package/dist/lib/library.d.ts.map +1 -1
  37. package/dist/lib/library.js +6 -0
  38. package/dist/lib/op.d.ts.map +1 -1
  39. package/dist/lib/op.js +2 -0
  40. package/dist/lib/opContext/createOpGroup.d.ts.map +1 -1
  41. package/dist/lib/opContext/createOpGroup.js +5 -0
  42. package/dist/lib/opContext/defineOp.d.ts.map +1 -1
  43. package/dist/lib/opContext/defineOp.js +5 -0
  44. package/dist/lib/result.d.ts.map +1 -1
  45. package/dist/lib/result.js +3 -0
  46. package/dist/lib/schema/builder.d.ts.map +1 -1
  47. package/dist/lib/schema/builder.js +1 -0
  48. package/dist/lib/schema/defineFeatureFlags.d.ts.map +1 -1
  49. package/dist/lib/schema/defineLogSchema.d.ts.map +1 -1
  50. package/dist/lib/schema/defineLogSchema.js +1 -0
  51. package/dist/lib/schema/evaluator.d.ts.map +1 -1
  52. package/dist/lib/schema/systemSchema.d.ts.map +1 -1
  53. package/dist/lib/schema/systemSchema.js +1 -0
  54. package/dist/lib/spanBuffer.d.ts.map +1 -1
  55. package/dist/lib/spanBuffer.js +8 -0
  56. package/dist/lib/spanBufferHelpers.d.ts.map +1 -1
  57. package/dist/lib/spanBufferHelpers.js +1 -0
  58. package/dist/lib/spanBufferStats.d.ts.map +1 -1
  59. package/dist/lib/spanContext.d.ts +8 -0
  60. package/dist/lib/spanContext.d.ts.map +1 -1
  61. package/dist/lib/spanContext.js +35 -0
  62. package/dist/lib/sqlite/index.d.ts +1 -0
  63. package/dist/lib/sqlite/index.d.ts.map +1 -1
  64. package/dist/lib/sqlite/sqlite-async-writer.d.ts.map +1 -1
  65. package/dist/lib/sqlite/sqlite-async-writer.js +16 -0
  66. package/dist/lib/sqlite/sqlite-common.d.ts.map +1 -1
  67. package/dist/lib/sqlite/sqlite-common.js +5 -1
  68. package/dist/lib/sqlite/sqlite-writer.d.ts.map +1 -1
  69. package/dist/lib/sqlite/sqlite-writer.js +22 -0
  70. package/dist/lib/testing/bun-harness.d.ts.map +1 -1
  71. package/dist/lib/testing/bun-harness.js +21 -0
  72. package/dist/lib/threadId.d.ts.map +1 -1
  73. package/dist/lib/threadId.js +2 -0
  74. package/dist/lib/traceId.d.ts.map +1 -1
  75. package/dist/lib/traceId.js +1 -0
  76. package/dist/lib/traceRoot.d.ts.map +1 -1
  77. package/dist/lib/traceRoot.es.d.ts.map +1 -1
  78. package/dist/lib/traceRoot.es.js +3 -0
  79. package/dist/lib/traceRoot.js +2 -0
  80. package/dist/lib/traceRoot.node.d.ts.map +1 -1
  81. package/dist/lib/traceRoot.node.js +1 -0
  82. package/dist/lib/tracer.d.ts.map +1 -1
  83. package/dist/lib/tracer.js +2 -0
  84. package/dist/lib/tracers/ArrayQueueTracer.d.ts.map +1 -1
  85. package/dist/lib/tracers/CompositeTracer.d.ts.map +1 -1
  86. package/dist/lib/tracers/CompositeTracer.js +6 -0
  87. package/dist/lib/tracers/NoOpTracer.d.ts.map +1 -1
  88. package/dist/lib/tracers/NoOpTracer.js +1 -0
  89. package/dist/lib/tracers/SQLiteTracer.d.ts.map +1 -1
  90. package/dist/lib/tracers/SQLiteTracer.js +11 -0
  91. package/dist/lib/tracers/StdioTracer.d.ts.map +1 -1
  92. package/dist/lib/tracers/StdioTracer.js +1 -0
  93. package/dist/lib/tracers/TestTracer.d.ts.map +1 -1
  94. package/dist/lib/tracers/TestTracer.js +1 -0
  95. package/dist/lib/types.d.ts.map +1 -1
  96. package/dist/lib/utf8Cache.d.ts.map +1 -1
  97. package/dist/lib/utf8Cache.js +1 -0
  98. package/dist/lib/wasm/WasmBufferStrategy.d.ts.map +1 -1
  99. package/dist/lib/wasm/WasmBufferStrategy.js +2 -0
  100. package/dist/lib/wasm/wasmAllocator.d.ts +2 -0
  101. package/dist/lib/wasm/wasmAllocator.d.ts.map +1 -1
  102. package/dist/lib/wasm/wasmSpanBuffer.d.ts.map +1 -1
  103. package/dist/lib/wasm/wasmTraceRoot.d.ts.map +1 -1
  104. package/dist/node.d.ts.map +1 -1
  105. package/dist/node.js +1 -0
  106. package/package.json +9 -6
  107. package/src/es.ts +2 -0
  108. package/src/lib/archive/chunkCompaction.ts +2 -0
  109. package/src/lib/archive/chunkEnvelope.ts +2 -0
  110. package/src/lib/archive/chunkRouting.ts +4 -0
  111. package/src/lib/archive/chunkStats.ts +2 -0
  112. package/src/lib/arrow/capacityStats.ts +2 -0
  113. package/src/lib/bufferStrategy.ts +2 -0
  114. package/src/lib/capacityTuning.ts +2 -0
  115. package/src/lib/cleanupDiagnostics.ts +52 -0
  116. package/src/lib/codegen/evaluatorGenerator.ts +2 -0
  117. package/src/lib/codegen/fixedPositionWriterGenerator.ts +2 -0
  118. package/src/lib/codegen/spanLoggerGenerator.ts +4 -0
  119. package/src/lib/convertToArrow.ts +6 -0
  120. package/src/lib/defineOpContext.ts +17 -1
  121. package/src/lib/errors/Blocked.ts +2 -0
  122. package/src/lib/errors/Transient.ts +2 -0
  123. package/src/lib/errors/retry-policy.ts +2 -0
  124. package/src/lib/flushScheduler.ts +12 -0
  125. package/src/lib/library.ts +7 -0
  126. package/src/lib/op.ts +8 -0
  127. package/src/lib/opContext/createOpGroup.ts +6 -0
  128. package/src/lib/opContext/defineOp.ts +6 -0
  129. package/src/lib/result.ts +4 -0
  130. package/src/lib/schema/builder.ts +2 -0
  131. package/src/lib/schema/defineFeatureFlags.ts +2 -0
  132. package/src/lib/schema/defineLogSchema.ts +2 -0
  133. package/src/lib/schema/evaluator.ts +2 -0
  134. package/src/lib/schema/systemSchema.ts +2 -0
  135. package/src/lib/spanBuffer.ts +10 -0
  136. package/src/lib/spanBufferHelpers.ts +2 -0
  137. package/src/lib/spanBufferStats.ts +2 -0
  138. package/src/lib/spanContext.ts +48 -1
  139. package/src/lib/sqlite/__tests__/sqlite-common.test.ts +40 -1
  140. package/src/lib/sqlite/index.ts +1 -0
  141. package/src/lib/sqlite/sqlite-async-writer.ts +8 -0
  142. package/src/lib/sqlite/sqlite-common.ts +5 -1
  143. package/src/lib/sqlite/sqlite-writer.ts +6 -0
  144. package/src/lib/testing/bun-harness.ts +21 -0
  145. package/src/lib/threadId.ts +2 -0
  146. package/src/lib/traceId.ts +4 -0
  147. package/src/lib/traceRoot.es.ts +4 -0
  148. package/src/lib/traceRoot.node.ts +2 -0
  149. package/src/lib/traceRoot.ts +4 -0
  150. package/src/lib/tracer.ts +4 -0
  151. package/src/lib/tracers/ArrayQueueTracer.ts +2 -0
  152. package/src/lib/tracers/CompositeTracer.ts +7 -0
  153. package/src/lib/tracers/NoOpTracer.ts +2 -0
  154. package/src/lib/tracers/SQLiteTracer.ts +11 -0
  155. package/src/lib/tracers/StdioTracer.ts +2 -0
  156. package/src/lib/tracers/TestTracer.ts +2 -0
  157. package/src/lib/types.ts +2 -0
  158. package/src/lib/utf8Cache.ts +2 -0
  159. package/src/lib/wasm/WasmBufferStrategy.ts +4 -0
  160. package/src/lib/wasm/allocator.zig +4 -1
  161. package/src/lib/wasm/wasmAllocator.ts +5 -0
  162. package/src/lib/wasm/wasmSpanBuffer.ts +4 -0
  163. package/src/lib/wasm/wasmTraceRoot.ts +4 -0
  164. package/src/node.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/lmao",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -118,7 +118,7 @@
118
118
  "dependencies": {
119
119
  "@msgpack/msgpack": "^3.1.3",
120
120
  "@neophi/sieve-cache": "^1.5.0",
121
- "@smoothbricks/arrow-builder": "0.1.1",
121
+ "@smoothbricks/arrow-builder": "0.1.2",
122
122
  "@smoothbricks/validation": "0.1.1",
123
123
  "@uwdata/flechette": "^2.3.0",
124
124
  "tslib": "^2.8.1"
@@ -126,7 +126,8 @@
126
126
  "scripts": {
127
127
  "bench": "bun run benchmarks/*.bench.ts",
128
128
  "bench:wasm": "bun run benchmarks/js-vs-wasm.bench.ts",
129
- "build:wasm": "zig build -Doptimize=ReleaseSmall"
129
+ "build:wasm": "zig build -Doptimize=ReleaseSmall",
130
+ "test": "nx run lmao:test --outputStyle=stream"
130
131
  },
131
132
  "nx": {
132
133
  "sourceRoot": "packages/lmao/src",
@@ -140,10 +141,12 @@
140
141
  ]
141
142
  },
142
143
  "test": {
143
- "executor": "nx:run-commands",
144
+ "executor": "@smoothbricks/nx-plugin:bounded-exec",
144
145
  "options": {
145
- "command": "bun test",
146
- "cwd": "packages/lmao"
146
+ "command": "bun test --timeout=30000",
147
+ "cwd": "{projectRoot}",
148
+ "timeoutMs": 120000,
149
+ "killAfterMs": 1e4
147
150
  }
148
151
  }
149
152
  },
package/src/es.ts CHANGED
@@ -8,4 +8,6 @@
8
8
  export * from './index.js';
9
9
 
10
10
  // Export browser-specific TraceRoot factory for Tracer construction
11
+ //#region smoo/lmao!n/trace-root-timestamps.entry-points #es
11
12
  export { createTraceRoot } from './lib/traceRoot.es.js';
13
+ //#endregion smoo/lmao!n/trace-root-timestamps.entry-points
@@ -14,6 +14,7 @@ export interface CompactedChunkSet {
14
14
  readonly window: CompactionWindow;
15
15
  }
16
16
 
17
+ //#region smoo/lmao!n/trace-archive-compaction.manifest
17
18
  export function compactTraceChunks(chunks: readonly TraceChunkEnvelope[], window: CompactionWindow): CompactedChunkSet {
18
19
  const sourceChunkIds = [...new Set(chunks.map((chunk) => chunk.chunk_id))].sort();
19
20
  const totalRows = chunks.reduce((sum, chunk) => sum + chunk.row_count, 0);
@@ -29,6 +30,7 @@ export function compactTraceChunks(chunks: readonly TraceChunkEnvelope[], window
29
30
  window,
30
31
  };
31
32
  }
33
+ //#endregion smoo/lmao!n/trace-archive-compaction.manifest
32
34
 
33
35
  function hashDeterministic(input: string): string {
34
36
  let hash = 0xcbf29ce484222325n;
@@ -1,3 +1,4 @@
1
+ //#region smoo/lmao!n/trace-archive-envelope.build
1
2
  export interface TraceChunkEnvelopeInput {
2
3
  readonly file_ref: string;
3
4
  readonly chunk_ref: string;
@@ -77,3 +78,4 @@ function fnv1a64(input: string): string {
77
78
 
78
79
  return hash.toString(16).padStart(16, '0');
79
80
  }
81
+ //#endregion smoo/lmao!n/trace-archive-envelope.build
@@ -7,6 +7,7 @@ export interface PartitionSplit<T> {
7
7
  readonly rows: readonly T[];
8
8
  }
9
9
 
10
+ //#region smoo/lmao!n/trace-archive-partition-inspect.inspect
10
11
  export function inspectPartitionCardinality<T>(
11
12
  rows: readonly T[],
12
13
  partitionOf: (row: T) => string | null | undefined,
@@ -29,7 +30,9 @@ export function inspectPartitionCardinality<T>(
29
30
 
30
31
  return partitions.size === 1 ? 'single' : 'unknown';
31
32
  }
33
+ //#endregion smoo/lmao!n/trace-archive-partition-inspect.inspect
32
34
 
35
+ //#region smoo/lmao!n/trace-archive-partition-split.split
33
36
  export function splitChunkByPartition<T>(
34
37
  rows: readonly T[],
35
38
  partitionOf: (row: T) => string | null | undefined,
@@ -68,3 +71,4 @@ export function splitChunkByPartition<T>(
68
71
  };
69
72
  });
70
73
  }
74
+ //#endregion smoo/lmao!n/trace-archive-partition-split.split
@@ -10,6 +10,7 @@ export interface TraceChunkStats {
10
10
  readonly duration_ms: number;
11
11
  }
12
12
 
13
+ //#region smoo/lmao!n/trace-archive-stats.chunk-level
13
14
  export function extractChunkStats<T>(
14
15
  envelope: TraceChunkEnvelope,
15
16
  partitions: readonly PartitionSplit<T>[] = [],
@@ -23,3 +24,4 @@ export function extractChunkStats<T>(
23
24
  duration_ms: Math.max(0, envelope.ended_at_ms - envelope.started_at_ms),
24
25
  };
25
26
  }
27
+ //#endregion smoo/lmao!n/trace-archive-stats.chunk-level
@@ -57,6 +57,7 @@ function append(entries: [string, Column<unknown>][], name: string, column: Colu
57
57
  entries.push([name, column]);
58
58
  }
59
59
 
60
+ //#region smoo/lmao!n/buffer-tuning-stats-logging
60
61
  export function createCapacityStatsTable(
61
62
  entriesToLog: CapacityStatsEntry[],
62
63
  periodStartNs: bigint,
@@ -338,3 +339,4 @@ export function createCapacityStatsTable(
338
339
 
339
340
  return tableFromColumns(cols);
340
341
  }
342
+ //#endregion smoo/lmao!n/buffer-tuning-stats-logging
@@ -1,3 +1,4 @@
1
+ //#region corpos/billing!n/audit-pricing-metering.lmao-buffer-strategy
1
2
  /**
2
3
  * BufferStrategy - Abstraction for SpanBuffer memory management and Arrow conversion.
3
4
  *
@@ -104,3 +105,4 @@ export interface BufferStrategy<T extends LogSchema = LogSchema> {
104
105
  */
105
106
  releaseBuffer(buffer: AnySpanBuffer): void;
106
107
  }
108
+ //#endregion corpos/billing!n/audit-pricing-metering.lmao-buffer-strategy
@@ -26,6 +26,7 @@
26
26
 
27
27
  import type { SpanBufferStats } from './spanBufferStats.js';
28
28
 
29
+ //#region smoo/lmao!n/buffer-tuning-capacity
29
30
  /** Minimum spans needed before tuning decisions */
30
31
  const MIN_SPANS_FOR_TUNING = 10;
31
32
 
@@ -100,3 +101,4 @@ export function shouldTuneCapacity(stats: SpanBufferStats): void {
100
101
  resetStats(stats);
101
102
  }
102
103
  }
104
+ //#endregion smoo/lmao!n/buffer-tuning-capacity
@@ -0,0 +1,52 @@
1
+ /// <reference types="bun" />
2
+
3
+ function isTruthyEnvFlag(value: unknown): boolean {
4
+ return value === true || value === '1' || value === 'true';
5
+ }
6
+
7
+ export function isCleanupDebugEnabled(): boolean {
8
+ const globalDebug = Reflect.get(globalThis, '__LMAO_TEST_CLEANUP_DEBUG__');
9
+ if (isTruthyEnvFlag(globalDebug)) {
10
+ return true;
11
+ }
12
+
13
+ return isTruthyEnvFlag(process.env.LMAO_TEST_CLEANUP_DEBUG);
14
+ }
15
+
16
+ export function cleanupDebug(label: string, details?: Record<string, unknown>): void {
17
+ if (!isCleanupDebugEnabled()) {
18
+ return;
19
+ }
20
+
21
+ const suffix = details ? ` ${JSON.stringify(details)}` : '';
22
+ console.error(`[lmao/cleanup] ${label}${suffix}`);
23
+ }
24
+
25
+ export function cleanupDebugActiveHandles(label: string): void {
26
+ if (!isCleanupDebugEnabled()) {
27
+ return;
28
+ }
29
+
30
+ const getActiveHandles = Reflect.get(process, '_getActiveHandles');
31
+ if (typeof getActiveHandles !== 'function') {
32
+ cleanupDebug(label, { activeHandles: 'unavailable' });
33
+ return;
34
+ }
35
+
36
+ const handles = getActiveHandles.call(process);
37
+ if (!Array.isArray(handles)) {
38
+ cleanupDebug(label, { activeHandles: 'unavailable' });
39
+ return;
40
+ }
41
+
42
+ const names = handles.map((handle) => {
43
+ if (typeof handle !== 'object' || handle === null) {
44
+ return typeof handle;
45
+ }
46
+ const constructor = Reflect.get(handle, 'constructor');
47
+ const name = typeof constructor === 'function' ? Reflect.get(constructor, 'name') : undefined;
48
+ return typeof name === 'string' && name.length > 0 ? name : 'Object';
49
+ });
50
+
51
+ cleanupDebug(label, { activeHandleCount: handles.length, activeHandles: names });
52
+ }
@@ -1,3 +1,4 @@
1
+ //#region corpos/billing!n/audit-flag-evaluator.lmao-evaluator-generator
1
2
  /**
2
3
  * Worker-safe feature-flag evaluator generation.
3
4
  *
@@ -307,3 +308,4 @@ export function createEvaluatorClass<Ctx extends OpContext>(
307
308
 
308
309
  return generatedEvaluatorClass;
309
310
  }
311
+ //#endregion corpos/billing!n/audit-flag-evaluator.lmao-evaluator-generator
@@ -183,6 +183,7 @@ function generateWithMethod(schemaFields: readonly ColumnEntry[], enumFieldNames
183
183
  }`;
184
184
  }
185
185
 
186
+ //#region smoo/lmao!n/codegen-architecture
186
187
  /**
187
188
  * Generate the complete fixed-position writer class code.
188
189
  *
@@ -442,3 +443,4 @@ export function createResultWriter<T extends LogSchema, R = unknown, E = unknown
442
443
  const WriterClass = getResultWriterClass(schema);
443
444
  return new WriterClass(buffer, resultOrError, isError);
444
445
  }
446
+ //#endregion smoo/lmao!n/codegen-architecture
@@ -261,6 +261,7 @@ function generateEnumFluentSetters(enumFieldNames: Set<string>): string {
261
261
  return setters.join('\n');
262
262
  }
263
263
 
264
+ //#region smoo/lmao!n/codegen-spanlogger.scope
264
265
  /**
265
266
  * Generate _setScope() method code - IMMUTABLE scope semantics
266
267
  *
@@ -365,7 +366,9 @@ function generatePrefillScopedAttributesMethod(
365
366
  ${columnFills.join('\n')}
366
367
  }`;
367
368
  }
369
+ //#endregion smoo/lmao!n/codegen-spanlogger.scope
368
370
 
371
+ //#region smoo/lmao!n/codegen-spanlogger
369
372
  /**
370
373
  * Build the extension for SpanLogger that extends ColumnWriter
371
374
  */
@@ -713,3 +716,4 @@ export function createSpanLogger<T extends LogSchema>(schema: T, buffer: SpanBuf
713
716
  const SpanLoggerClass = createSpanLoggerClass(schema);
714
717
  return new SpanLoggerClass(buffer);
715
718
  }
719
+ //#endregion smoo/lmao!n/codegen-spanlogger
@@ -186,6 +186,11 @@ function getAllocatedBinaryColumn(buffer: AnySpanBuffer, columnName: string): un
186
186
  return Array.isArray(column) ? column : undefined;
187
187
  }
188
188
 
189
+ //#region smoo/lmao!n/scope-attributes.arrow-fill
190
+ // Cold-path scope materialization (01i): scope values fill NULL cells (no direct write) at
191
+ // Arrow conversion. These typed readers pull from the buffer's immutable _scopeValues; the
192
+ // per-column fill loops below call them so a row with a direct write keeps its value and scope
193
+ // only fills the gaps.
189
194
  function getStringScopeValue(buffer: AnySpanBuffer, fieldName: string): string | undefined {
190
195
  const value = buffer._scopeValues?.[fieldName];
191
196
  return typeof value === 'string' ? value : undefined;
@@ -200,6 +205,7 @@ function getBooleanScopeValue(buffer: AnySpanBuffer, fieldName: string): boolean
200
205
  const value = buffer._scopeValues?.[fieldName];
201
206
  return typeof value === 'boolean' ? value : undefined;
202
207
  }
208
+ //#endregion smoo/lmao!n/scope-attributes.arrow-fill
203
209
 
204
210
  function requireUint8Array(value: unknown, message: string): Uint8Array {
205
211
  if (!(value instanceof Uint8Array)) {
@@ -250,9 +250,15 @@ function buildOpContextFactory<
250
250
  };
251
251
  }
252
252
 
253
+ //#region smoo/lmao!n/opcontext-definition
253
254
  /**
254
255
  * Define an Op context factory
255
256
  *
257
+ * 01j "Module Definition", renamed: this is the shipped entry point (defineOpContext,
258
+ * not defineModule().ctx().make()). Returns { defineOp, defineOps }; user context is the
259
+ * `ctx` config field (runtime defaults, reserved-key-guarded — see the nested
260
+ * n/schema-env-config region), deps carry their own prefix, and per-Op attribution is OpMetadata.
261
+ *
256
262
  * Creates a factory for defining Ops that share the same schema, deps, and context.
257
263
  * This is the main entry point for the Op-centric API.
258
264
  *
@@ -334,7 +340,14 @@ export function defineOpContext<
334
340
  Deps extends DepsConfig = Record<string, never>,
335
341
  UserCtx extends Record<string, unknown> = Record<string, never>,
336
342
  >(config: OpContextConfig<T, FF, Deps, UserCtx>) {
337
- // Runtime validation: check for reserved property names in user context
343
+ //#region smoo/lmao!n/schema-env-config
344
+ // Runtime validation: check for reserved property names in user context.
345
+ // The `ctx` config object is the env/deployment-config surface from
346
+ // 01a "Environment Variable Configuration" — a plain user object (env, services,
347
+ // requestId, ...) spread into SpanContext, guarded only against reserved/internal keys.
348
+ //#region smoo/lmao!n/schema-env-config.reserved
349
+ // 01l "Reserved Names": ctx keys cannot collide with built-in SpanContext members
350
+ // (buffer/tag/log/scope/setScope/ok/err/span/ff/deps) or start with `_` (internal).
338
351
  if (config.ctx) {
339
352
  const userKeys = Object.keys(config.ctx);
340
353
  for (const key of userKeys) {
@@ -350,6 +363,8 @@ export function defineOpContext<
350
363
  }
351
364
  }
352
365
  }
366
+ //#endregion smoo/lmao!n/schema-env-config.reserved
367
+ //#endregion smoo/lmao!n/schema-env-config
353
368
 
354
369
  // Compute effective schema by combining app schema with dep contributions.
355
370
  // This merges app fields + all dep contributed fields (after prefix/mapping).
@@ -387,6 +402,7 @@ export function defineOpContext<
387
402
 
388
403
  return buildOpContextFactory(effectiveFields, config.flags, config.deps, config.ctx);
389
404
  }
405
+ //#endregion smoo/lmao!n/opcontext-definition
390
406
 
391
407
  // Re-export everything from opContext for convenience
392
408
  export * from './opContext/index.js';
@@ -53,6 +53,7 @@
53
53
 
54
54
  import type { TaggedError } from '../result.js';
55
55
 
56
+ //#region smoo/lmao!n/op-context-tagged-errors.blocked
56
57
  /**
57
58
  * Reason why an Op is blocked.
58
59
  */
@@ -163,3 +164,4 @@ export class Blocked extends Error implements TaggedError<'Blocked'> {
163
164
  };
164
165
  }
165
166
  }
167
+ //#endregion smoo/lmao!n/op-context-tagged-errors.blocked
@@ -1,3 +1,4 @@
1
+ //#region smoo/lmao!n/op-retry.transient
1
2
  /**
2
3
  * TransientError - typed transient error codes with embedded retry policy.
3
4
  *
@@ -166,3 +167,4 @@ function isRetryPolicyLike(value: unknown): value is Partial<RetryPolicy> {
166
167
 
167
168
  // Re-export policy helpers for convenience
168
169
  export { exponentialBackoff, fixedDelay, linearBackoff, mergePolicy, type RetryPolicy } from './retry-policy.js';
170
+ //#endregion smoo/lmao!n/op-retry.transient
@@ -1,3 +1,4 @@
1
+ //#region smoo/lmao!n/op-retry.policy
1
2
  /**
2
3
  * RetryPolicy - configures retry behavior for transient failures.
3
4
  *
@@ -85,3 +86,4 @@ export function mergePolicy(base: RetryPolicy, override?: Partial<RetryPolicy>):
85
86
  if (!override) return base;
86
87
  return { ...base, ...override };
87
88
  }
89
+ //#endregion smoo/lmao!n/op-retry.policy
@@ -9,6 +9,7 @@
9
9
 
10
10
  import { Column, type Table, tableFromColumns } from '@uwdata/flechette';
11
11
  import type { CapacityStatsEntry } from './arrow/capacityStats.js';
12
+ import { cleanupDebug } from './cleanupDiagnostics.js';
12
13
  import { convertSpanTreeToArrowTable } from './convertToArrow.js';
13
14
  import type { SpanBufferConstructor } from './spanBuffer.js';
14
15
  import type { AnySpanBuffer, OpMetadata } from './types.js';
@@ -119,6 +120,7 @@ export interface FlushSchedulerConfig {
119
120
  * Background flush scheduler
120
121
  * Manages automatic flushing of span buffers to Arrow tables
121
122
  */
123
+ //#region smoo/lmao!n/buffer-tuning-flush
122
124
  export class FlushScheduler {
123
125
  private config: Required<FlushSchedulerConfig>;
124
126
  private handler: FlushHandler;
@@ -178,6 +180,7 @@ export class FlushScheduler {
178
180
  this.isRunning = true;
179
181
  this.lastFlushTime = Date.now();
180
182
  this.lastActivityTime = Date.now();
183
+ cleanupDebug('flushScheduler.start', this.config);
181
184
 
182
185
  // Set up periodic flush timer
183
186
  this.flushTimer = setInterval(() => {
@@ -208,6 +211,7 @@ export class FlushScheduler {
208
211
  stop(): void {
209
212
  if (!this.isRunning) return;
210
213
 
214
+ cleanupDebug('flushScheduler.stop:start', { pendingBuffers: this.buffers.size });
211
215
  this.isRunning = false;
212
216
 
213
217
  if (this.flushTimer) {
@@ -224,6 +228,7 @@ export class FlushScheduler {
224
228
  clearInterval(this.memoryTimer);
225
229
  this.memoryTimer = undefined;
226
230
  }
231
+ cleanupDebug('flushScheduler.stop:end', { pendingBuffers: this.buffers.size });
227
232
  }
228
233
 
229
234
  /**
@@ -443,6 +448,12 @@ export class FlushScheduler {
443
448
  }
444
449
  } catch (error) {
445
450
  console.error('Error in flush handler:', error);
451
+ cleanupDebug('flushScheduler.doFlush:error', {
452
+ reason,
453
+ totalRows,
454
+ totalBuffers,
455
+ pendingBuffers: this.buffers.size,
456
+ });
446
457
  // Do NOT reset buffers on failure to avoid data loss
447
458
  }
448
459
  }
@@ -454,6 +465,7 @@ export class FlushScheduler {
454
465
  this.lastActivityTime = Date.now();
455
466
  }
456
467
  }
468
+ //#endregion smoo/lmao!n/buffer-tuning-flush
457
469
 
458
470
  /**
459
471
  * Global flush scheduler instance (optional)
@@ -71,10 +71,16 @@ function isRemappedSpanLoggerClass<T extends LogSchema>(value: unknown): value i
71
71
  );
72
72
  }
73
73
 
74
+ //#region smoo/lmao!n/codegen-prefixed-remap
74
75
  /**
75
76
  * Prefix a tag attribute schema
76
77
  * Renames all fields with a prefix to avoid conflicts
77
78
  *
79
+ * 01j "Library Compilation (Prefixed)": a library defines clean field names
80
+ * (status, method); the consumer applies a prefix (http) at wire time. This block
81
+ * generates the prefixed schema, the clean->prefixed mapping, and the RemappedSpanLogger /
82
+ * RemappedBufferView classes whose clean methods write to prefixed columns.
83
+ *
78
84
  * Example:
79
85
  * - Input: { status: S.number(), method: S.enum(['GET', 'POST']) }
80
86
  * - Prefix: 'http'
@@ -680,3 +686,4 @@ export function createRemappedSpanLoggerClass<T extends LogSchema>(
680
686
 
681
687
  return GeneratedClass;
682
688
  }
689
+ //#endregion smoo/lmao!n/codegen-prefixed-remap
package/src/lib/op.ts CHANGED
@@ -31,6 +31,11 @@ import type { SpanBufferConstructor } from './spanBuffer.js';
31
31
  * Includes pre-encoded UTF-8 entries for Arrow dictionary building -
32
32
  * encode once at Op definition time, reuse for every span conversion.
33
33
  */
34
+ //#region smoo/lmao!n/opcontext-hierarchy
35
+ // 01j "ModuleContext", renamed: per-Op source-attribution metadata
36
+ // (package_name/package_file/git_sha) + pre-encoded UTF-8 entries for Arrow
37
+ // dictionary building. One per defineOp; SpanBuffer/SpanContext are the other
38
+ // two levels of the 01j Context Hierarchy.
34
39
  export interface OpMetadata {
35
40
  /** Op name for metrics tracking (distinct from span names which are provided at call sites) */
36
41
  readonly name: string;
@@ -50,11 +55,13 @@ export interface OpMetadata {
50
55
  /** Pre-encoded git_sha for Arrow dictionary building */
51
56
  readonly git_sha_entry: PreEncodedEntry;
52
57
  }
58
+ //#endregion smoo/lmao!n/opcontext-hierarchy
53
59
 
54
60
  // =============================================================================
55
61
  // Op Class
56
62
  // =============================================================================
57
63
 
64
+ //#region smoo/lmao!n/op-class
58
65
  /**
59
66
  * Op - Traced operation (Phase 2 architecture)
60
67
  *
@@ -101,3 +108,4 @@ export class Op<Ctx extends OpContext, Args extends unknown[], S, E> {
101
108
  readonly _opContextBinding?: OpContextBinding,
102
109
  ) {}
103
110
  }
111
+ //#endregion smoo/lmao!n/op-class
@@ -34,6 +34,11 @@ import type {
34
34
  import { validateOpName } from './opGroupTypes.js';
35
35
  import type { OpContext } from './types.js';
36
36
 
37
+ //#region smoo/lmao!n/column-mapping-api
38
+ // 01l "Dependencies with Column Mapping" + 01e "Column Mapping API": .prefix(name) and
39
+ // .mapColumns({ col: 'new' | 'shared' | null }) are realized here. Each call clones the
40
+ // OpGroup's ops with a fresh RemappedBufferView (cold-path codegen via library.ts), so the
41
+ // hot path still writes the clean unprefixed columns; the view remaps clean->target for Arrow.
37
42
  // =============================================================================
38
43
  // INTERNAL HELPERS
39
44
  // =============================================================================
@@ -454,3 +459,4 @@ export function createOpGroup<Ctx extends OpContext, Ops extends OpGroupOps<Ctx>
454
459
  assertGroupCarriesOps<Ctx, Ops>(group, ops);
455
460
  return group;
456
461
  }
462
+ //#endregion smoo/lmao!n/column-mapping-api
@@ -14,6 +14,11 @@ import type { OpGroup, OpGroupOps } from './opGroupTypes.js';
14
14
  import type { Op, OpFn, OpMetadata, OpsFromRecord } from './opTypes.js';
15
15
  import type { OpContext } from './types.js';
16
16
 
17
+ //#region smoo/lmao!n/metadata-injection
18
+ // 01l "Metadata Injection (Transformer)": package_name/package_file/git_sha/line are the
19
+ // per-Op OpMetadata the transformer injects at the defineOpContext call site. createOpMetadata
20
+ // pre-encodes the dictionary entries (interned UTF-8); DEFAULT_METADATA is the un-injected
21
+ // placeholder; extractMetadataFromStack is the no-transformer dev fallback (parses the stack).
17
22
  // =============================================================================
18
23
  // METADATA HELPERS
19
24
  // =============================================================================
@@ -130,6 +135,7 @@ export function extractMetadataFromStack(skipFrames = 2): OpMetadata {
130
135
 
131
136
  return createOpMetadata('unknown', packageName, filePath, 'runtime', lineNumber);
132
137
  }
138
+ //#endregion smoo/lmao!n/metadata-injection
133
139
 
134
140
  // =============================================================================
135
141
  // FACTORY CONFIG
package/src/lib/result.ts CHANGED
@@ -104,6 +104,7 @@ function createCodeErrorValue<Code extends string, Fields extends object>(
104
104
  // OK CLASS
105
105
  // =============================================================================
106
106
 
107
+ //#region smoo/lmao!n/lmao-entry-fluentok
107
108
  /**
108
109
  * Success result with fluent tag application.
109
110
  *
@@ -240,11 +241,13 @@ export class Ok<V, T extends LogSchema = LogSchema> {
240
241
  return { ok: true, value: this.value };
241
242
  }
242
243
  }
244
+ //#endregion smoo/lmao!n/lmao-entry-fluentok
243
245
 
244
246
  // =============================================================================
245
247
  // ERR CLASS
246
248
  // =============================================================================
247
249
 
250
+ //#region smoo/lmao!n/lmao-entry-fluenterr
248
251
  /**
249
252
  * Error result with fluent tag application.
250
253
  *
@@ -410,6 +413,7 @@ export class Err<E, T extends LogSchema = LogSchema> {
410
413
  return { ok: false, error: this.error };
411
414
  }
412
415
  }
416
+ //#endregion smoo/lmao!n/lmao-entry-fluenterr
413
417
 
414
418
  // =============================================================================
415
419
  // RESULT TYPE
@@ -66,6 +66,7 @@ function createSchemaWithFlagBuilder<Value, TSchema extends Schema<Value>>(
66
66
  return schemaWithBuilder;
67
67
  }
68
68
 
69
+ //#region smoo/lmao!n/schema-string-types
69
70
  /**
70
71
  * Schema builder that wraps arrow-builder's S with feature flag support
71
72
  *
@@ -199,3 +200,4 @@ const schemaBuilderImpl: SchemaBuilder = {
199
200
  // Export as S for convenience
200
201
  // Note: The SchemaBuilder type is exported from types.ts
201
202
  export const S = schemaBuilderImpl;
203
+ //#endregion smoo/lmao!n/schema-string-types
@@ -1,3 +1,4 @@
1
+ //#region corpos/billing!n/audit-flag-evaluator.lmao-flag-schema
1
2
  import type { Output } from '@smoothbricks/arrow-builder';
2
3
  import type { FeatureFlagDefinition } from './types.js';
3
4
 
@@ -89,3 +90,4 @@ export interface UsageContext {
89
90
  value?: number;
90
91
  metadata?: Record<string, string | number | boolean>;
91
92
  }
93
+ //#endregion corpos/billing!n/audit-flag-evaluator.lmao-flag-schema
@@ -229,6 +229,7 @@ function assertValidatedObject<T extends SchemaFields>(
229
229
  }
230
230
  }
231
231
 
232
+ //#region smoo/lmao!n/schema-log-schema
232
233
  export function defineLogSchema<T extends SchemaFields>(
233
234
  schema: T,
234
235
  options?: DefineLogSchemaOptions,
@@ -289,3 +290,4 @@ export function defineLogSchema<T extends SchemaFields>(
289
290
  // Return logSchema (still a LogSchema instance with added methods)
290
291
  return result;
291
292
  }
293
+ //#endregion smoo/lmao!n/schema-log-schema
@@ -1,3 +1,4 @@
1
+ //#region corpos/billing!n/audit-flag-evaluator.lmao-evaluator
1
2
  import type { Schema, SchemaWithMetadata } from '@smoothbricks/arrow-builder';
2
3
  import { createEvaluatorClass, type GeneratedEvaluatorInstance } from '../codegen/evaluatorGenerator.js';
3
4
  import type { FluentLogEntry } from '../codegen/spanLoggerGenerator.js';
@@ -402,3 +403,4 @@ export class InMemoryFlagEvaluator<Ctx extends OpContext = OpContext> implements
402
403
  return createFeatureFlagEvaluator(this.ffSchema, ctx, this);
403
404
  }
404
405
  }
406
+ //#endregion corpos/billing!n/audit-flag-evaluator.lmao-evaluator
@@ -203,6 +203,7 @@ export function mergeWithSystemSchema<T extends Record<string, unknown>>(userSch
203
203
  return merged;
204
204
  }
205
205
 
206
+ //#region smoo/lmao!n/lmao-entry-entry-type-definitions
206
207
  // =============================================================================
207
208
  // Entry Type Constants
208
209
  // =============================================================================
@@ -337,3 +338,4 @@ export const ENTRY_TYPE_NAMES = [
337
338
  'buffer-spans', // 23
338
339
  'buffer-capacity', // 24
339
340
  ] as const;
341
+ //#endregion smoo/lmao!n/lmao-entry-entry-type-definitions