@agentick/kernel 0.0.1

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 (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +401 -0
  3. package/dist/.tsbuildinfo.build +1 -0
  4. package/dist/channel-helpers.d.ts +32 -0
  5. package/dist/channel-helpers.d.ts.map +1 -0
  6. package/dist/channel-helpers.js +62 -0
  7. package/dist/channel-helpers.js.map +1 -0
  8. package/dist/channel.d.ts +164 -0
  9. package/dist/channel.d.ts.map +1 -0
  10. package/dist/channel.js +199 -0
  11. package/dist/channel.js.map +1 -0
  12. package/dist/context.d.ts +412 -0
  13. package/dist/context.d.ts.map +1 -0
  14. package/dist/context.js +289 -0
  15. package/dist/context.js.map +1 -0
  16. package/dist/event-buffer.d.ts +208 -0
  17. package/dist/event-buffer.d.ts.map +1 -0
  18. package/dist/event-buffer.js +335 -0
  19. package/dist/event-buffer.js.map +1 -0
  20. package/dist/execution-helpers.d.ts +179 -0
  21. package/dist/execution-helpers.d.ts.map +1 -0
  22. package/dist/execution-helpers.js +212 -0
  23. package/dist/execution-helpers.js.map +1 -0
  24. package/dist/execution-tracker.d.ts +61 -0
  25. package/dist/execution-tracker.d.ts.map +1 -0
  26. package/dist/execution-tracker.js +319 -0
  27. package/dist/execution-tracker.js.map +1 -0
  28. package/dist/guard.d.ts +65 -0
  29. package/dist/guard.d.ts.map +1 -0
  30. package/dist/guard.js +15 -0
  31. package/dist/guard.js.map +1 -0
  32. package/dist/index.d.ts +61 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +62 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/logger.d.ts +341 -0
  37. package/dist/logger.d.ts.map +1 -0
  38. package/dist/logger.js +346 -0
  39. package/dist/logger.js.map +1 -0
  40. package/dist/metrics-helpers.d.ts +40 -0
  41. package/dist/metrics-helpers.d.ts.map +1 -0
  42. package/dist/metrics-helpers.js +72 -0
  43. package/dist/metrics-helpers.js.map +1 -0
  44. package/dist/otel-provider.d.ts +54 -0
  45. package/dist/otel-provider.d.ts.map +1 -0
  46. package/dist/otel-provider.js +107 -0
  47. package/dist/otel-provider.js.map +1 -0
  48. package/dist/procedure-graph.d.ts +136 -0
  49. package/dist/procedure-graph.d.ts.map +1 -0
  50. package/dist/procedure-graph.js +272 -0
  51. package/dist/procedure-graph.js.map +1 -0
  52. package/dist/procedure.d.ts +757 -0
  53. package/dist/procedure.d.ts.map +1 -0
  54. package/dist/procedure.js +895 -0
  55. package/dist/procedure.js.map +1 -0
  56. package/dist/schema.d.ts +153 -0
  57. package/dist/schema.d.ts.map +1 -0
  58. package/dist/schema.js +385 -0
  59. package/dist/schema.js.map +1 -0
  60. package/dist/stream.d.ts +106 -0
  61. package/dist/stream.d.ts.map +1 -0
  62. package/dist/stream.js +186 -0
  63. package/dist/stream.js.map +1 -0
  64. package/dist/telemetry.d.ts +182 -0
  65. package/dist/telemetry.d.ts.map +1 -0
  66. package/dist/telemetry.js +124 -0
  67. package/dist/telemetry.js.map +1 -0
  68. package/dist/testing.d.ts +55 -0
  69. package/dist/testing.d.ts.map +1 -0
  70. package/dist/testing.js +96 -0
  71. package/dist/testing.js.map +1 -0
  72. package/package.json +48 -0
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Execution Helpers
3
+ *
4
+ * Utilities for understanding execution context - whether an execution
5
+ * is standalone, nested, what originated it, etc.
6
+ *
7
+ * Useful for persistence, logging, and conditional behavior based on
8
+ * execution hierarchy.
9
+ */
10
+ import { Context } from "./context";
11
+ import { ExecutionTracker } from "./execution-tracker";
12
+ /**
13
+ * Check if this is a standalone (root) execution or nested within another.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * if (isStandaloneExecution(ctx)) {
18
+ * // Create new execution record
19
+ * } else {
20
+ * // Link to parent execution
21
+ * }
22
+ * ```
23
+ */
24
+ export function isStandaloneExecution(ctx) {
25
+ return !ctx.procedureNode?.parentPid;
26
+ }
27
+ /**
28
+ * Check if this execution is nested within another procedure.
29
+ * Opposite of isStandaloneExecution.
30
+ */
31
+ export function isNestedExecution(ctx) {
32
+ return !!ctx.procedureNode?.parentPid;
33
+ }
34
+ /**
35
+ * Get the name of the procedure that originated this execution chain.
36
+ * Returns the origin's name if nested, or current procedure name if standalone.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const origin = getOriginName(ctx);
41
+ * // 'engine:stream', 'engine:execute', 'model:generate', etc.
42
+ * ```
43
+ */
44
+ export function getOriginName(ctx) {
45
+ return ctx.origin?.name ?? ctx.procedureNode?.name;
46
+ }
47
+ /**
48
+ * Get the origin procedure node if this is a nested execution.
49
+ * Returns undefined for standalone executions.
50
+ */
51
+ export function getOriginNode(ctx) {
52
+ return ctx.origin;
53
+ }
54
+ /**
55
+ * Check if this execution is within an engine execution (engine:execute or engine:stream).
56
+ * Useful for persistence to know if engine is handling top-level tracking.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * if (isWithinEngine(ctx)) {
61
+ * // Engine handles execution record - just track model-specific stuff
62
+ * } else {
63
+ * // Standalone model call - need full tracking
64
+ * }
65
+ * ```
66
+ */
67
+ export function isWithinEngine(ctx) {
68
+ if (!ctx.procedureGraph || !ctx.procedurePid) {
69
+ return false;
70
+ }
71
+ return ctx.procedureGraph.hasAncestor(ctx.procedurePid, (node) => node.name?.startsWith("engine:") ?? false);
72
+ }
73
+ /**
74
+ * Check if this execution has an ancestor with a specific procedure name.
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * if (hasAncestorNamed(ctx, 'engine:stream')) {
79
+ * // We're inside a streaming execution
80
+ * }
81
+ * ```
82
+ */
83
+ export function hasAncestorNamed(ctx, name) {
84
+ if (!ctx.procedureGraph || !ctx.procedurePid) {
85
+ return false;
86
+ }
87
+ return ctx.procedureGraph.hasAncestorWithName(ctx.procedurePid, name);
88
+ }
89
+ /**
90
+ * Check if this execution has an ancestor matching a predicate.
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * if (hasAncestorMatching(ctx, n => n.metadata?.type === 'agent')) {
95
+ * // We're inside an agent execution
96
+ * }
97
+ * ```
98
+ */
99
+ export function hasAncestorMatching(ctx, predicate) {
100
+ if (!ctx.procedureGraph || !ctx.procedurePid) {
101
+ return false;
102
+ }
103
+ return ctx.procedureGraph.hasAncestor(ctx.procedurePid, predicate);
104
+ }
105
+ /**
106
+ * Get the parent procedure node if one exists.
107
+ */
108
+ export function getParentNode(ctx) {
109
+ return ctx.procedureNode?.getParentNode();
110
+ }
111
+ /**
112
+ * Get the parent procedure's PID if one exists.
113
+ */
114
+ export function getParentPid(ctx) {
115
+ return ctx.procedureNode?.parentPid;
116
+ }
117
+ /**
118
+ * Get the root procedure ID (the origin of this execution chain).
119
+ * Returns current PID if this is a standalone execution.
120
+ */
121
+ export function getRootPid(ctx) {
122
+ return ctx.origin?.pid ?? ctx.procedurePid;
123
+ }
124
+ /**
125
+ * Get execution hierarchy info - useful for logging and persistence.
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const info = getExecutionInfo(ctx);
130
+ * // {
131
+ * // pid: 'abc-123',
132
+ * // parentPid: 'def-456',
133
+ * // rootPid: 'ghi-789',
134
+ * // name: 'model:generate',
135
+ * // originName: 'engine:stream',
136
+ * // isStandalone: false,
137
+ * // isWithinEngine: true,
138
+ * // depth: 2
139
+ * // }
140
+ * ```
141
+ */
142
+ export function getExecutionInfo(ctx) {
143
+ // Calculate depth by traversing up
144
+ let depth = 0;
145
+ let current = ctx.procedureNode;
146
+ while (current?.parentPid) {
147
+ depth++;
148
+ current = current.getParentNode();
149
+ }
150
+ return {
151
+ pid: ctx.procedurePid,
152
+ parentPid: ctx.procedureNode?.parentPid,
153
+ rootPid: getRootPid(ctx),
154
+ name: ctx.procedureNode?.name,
155
+ originName: getOriginName(ctx),
156
+ isStandalone: isStandaloneExecution(ctx),
157
+ isWithinEngine: isWithinEngine(ctx),
158
+ depth,
159
+ };
160
+ }
161
+ /**
162
+ * Create a named execution boundary around an operation.
163
+ *
164
+ * Use this to mark semantically meaningful operations that should appear
165
+ * as distinct executions in DevTools. The execution will be linked as a
166
+ * child of the current execution (if any).
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * // Simple usage with just a name
171
+ * const summary = await withExecution("Summarize Context", async () => {
172
+ * return model.generate(summarizePrompt);
173
+ * });
174
+ *
175
+ * // With options
176
+ * const result = await withExecution({
177
+ * name: "Validate Response",
178
+ * type: "validation",
179
+ * metadata: { validator: "schema" },
180
+ * }, async () => {
181
+ * return validateSchema(response);
182
+ * });
183
+ *
184
+ * // In a hook
185
+ * onAfterCompile: async (ctx) => {
186
+ * await withExecution("Context Compaction", async () => {
187
+ * const summary = await model.generate(compactPrompt);
188
+ * ctx.updateContext(summary);
189
+ * });
190
+ * }
191
+ * ```
192
+ *
193
+ * @param nameOrOptions - Execution name string or options object
194
+ * @param fn - The async function to execute within this boundary
195
+ * @returns The result of the function
196
+ */
197
+ export async function withExecution(nameOrOptions, fn) {
198
+ const options = typeof nameOrOptions === "string" ? { name: nameOrOptions } : nameOrOptions;
199
+ const { name, type = "custom", metadata } = options;
200
+ // ExecutionTracker.track with 'child' boundary automatically:
201
+ // - Links to parent procedure via ctx.procedurePid
202
+ // - Links to parent execution via ctx.executionId
203
+ // - Creates new executionId for this boundary
204
+ // - Uses Context.fork() internally for isolation
205
+ return ExecutionTracker.track(Context.tryGet() ?? Context.create(), {
206
+ name,
207
+ metadata: { ...metadata, type },
208
+ executionBoundary: "child",
209
+ executionType: type,
210
+ }, async () => fn());
211
+ }
212
+ //# sourceMappingURL=execution-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-helpers.js","sourceRoot":"","sources":["../src/execution-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAsB,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,q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H,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,aAA4C,EAC5C,EAAoB;IAEpB,MAAM,OAAO,GACX,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC;IAE9E,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAEpD,8DAA8D;IAC9D,mDAAmD;IACnD,kDAAkD;IAClD,8CAA8C;IAC9C,iDAAiD;IACjD,OAAO,gBAAgB,CAAC,KAAK,CAC3B,OAAO,CAAC,MAAM,EAAE,IAAI,OAAO,CAAC,MAAM,EAAE,EACpC;QACE,IAAI;QACJ,QAAQ,EAAE,EAAE,GAAG,QAAQ,EAAE,IAAI,EAAE;QAC/B,iBAAiB,EAAE,OAAO;QAC1B,aAAa,EAAE,IAAI;KACpB,EACD,KAAK,IAAI,EAAE,CAAC,EAAE,EAAE,CACjB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,61 @@
1
+ import { type KernelContext } from "./context";
2
+ import type { ProcedureNode } from "./procedure-graph";
3
+ /**
4
+ * Brand symbol for ExecutionHandle objects.
5
+ *
6
+ * ExecutionTracker uses this to distinguish handles (which are AsyncIterable
7
+ * but manage their own lifecycle) from pure async generators (where iteration
8
+ * IS the execution). Branded objects pass through the tracker without wrapping.
9
+ */
10
+ export declare const ExecutionHandleBrand: unique symbol;
11
+ /**
12
+ * Execution boundary behavior configuration.
13
+ *
14
+ * - `'always'`: Always create a new root execution (no parentExecutionId)
15
+ * - `'child'`: Always create a new child execution (with parentExecutionId from current context)
16
+ * - `'auto'`: Create only if not already in an execution (default behavior)
17
+ * - `false`: Never create an execution boundary, inherit from parent
18
+ */
19
+ export type ExecutionBoundaryConfig = "always" | "child" | "auto" | false;
20
+ export interface ExecutionTrackerOptions {
21
+ name?: string;
22
+ metadata?: Record<string, any>;
23
+ parentPid?: string;
24
+ /**
25
+ * Explicit execution ID to use if this becomes a boundary.
26
+ * If not provided, procedurePid is used as the executionId.
27
+ * Useful for Engine to correlate with ExecutionHandle.pid.
28
+ */
29
+ executionId?: string;
30
+ /**
31
+ * Declarative execution boundary configuration.
32
+ *
33
+ * - `'always'`: Always create a new root execution (engine:execute, engine:stream)
34
+ * - `'child'`: Always create a new child execution (component_tool, harness)
35
+ * - `'auto'`: Create only if not already in an execution (model:generate, model:stream)
36
+ * - `false`: Never create an execution boundary (compile:tick, internal procedures)
37
+ *
38
+ * @default 'auto'
39
+ */
40
+ executionBoundary?: ExecutionBoundaryConfig;
41
+ /**
42
+ * Explicit execution type (e.g., 'engine', 'model', 'component_tool', 'harness').
43
+ * If not provided, derived from procedure name.
44
+ */
45
+ executionType?: string;
46
+ }
47
+ /**
48
+ * Unified execution tracker for procedures and hooks.
49
+ * Handles automatic telemetry, metrics tracking, and propagation.
50
+ */
51
+ export declare class ExecutionTracker {
52
+ /**
53
+ * Track a procedure/hook execution with automatic telemetry and metrics
54
+ */
55
+ static track<T>(ctx: KernelContext, options: ExecutionTrackerOptions, fn: (node: ProcedureNode) => Promise<T>): Promise<T>;
56
+ /**
57
+ * Send metrics to telemetry system
58
+ */
59
+ private static sendMetricsToTelemetry;
60
+ }
61
+ //# sourceMappingURL=execution-tracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-tracker.d.ts","sourceRoot":"","sources":["../src/execution-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMvD;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,EAAE,OAAO,MAA4C,CAAC;AAEvF;;;;;;;GAOG;AACH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AAE1E,MAAM,WAAW,uBAAuB;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;;;;;OASG;IACH,iBAAiB,CAAC,EAAE,uBAAuB,CAAC;IAE5C;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B;;OAEG;WACU,KAAK,CAAC,CAAC,EAClB,GAAG,EAAE,aAAa,EAClB,OAAO,EAAE,uBAAuB,EAChC,EAAE,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC,CAAC,CAAC,GACtC,OAAO,CAAC,CAAC,CAAC;IAiUb;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;CAWtC"}
@@ -0,0 +1,319 @@
1
+ import { Context } from "./context";
2
+ import { ProcedureGraph } from "./procedure-graph";
3
+ import { Telemetry } from "./telemetry";
4
+ import { AbortError } from "@agentick/shared";
5
+ import { isAsyncIterable } from "./stream";
6
+ /**
7
+ * Brand symbol for ExecutionHandle objects.
8
+ *
9
+ * ExecutionTracker uses this to distinguish handles (which are AsyncIterable
10
+ * but manage their own lifecycle) from pure async generators (where iteration
11
+ * IS the execution). Branded objects pass through the tracker without wrapping.
12
+ */
13
+ export const ExecutionHandleBrand = Symbol("agentick.execution-handle");
14
+ /**
15
+ * Unified execution tracker for procedures and hooks.
16
+ * Handles automatic telemetry, metrics tracking, and propagation.
17
+ */
18
+ export class ExecutionTracker {
19
+ /**
20
+ * Track a procedure/hook execution with automatic telemetry and metrics
21
+ */
22
+ static async track(ctx, options, fn) {
23
+ // Initialize graph if needed
24
+ if (!ctx.procedureGraph) {
25
+ ctx.procedureGraph = new ProcedureGraph();
26
+ }
27
+ const procedurePid = crypto.randomUUID();
28
+ const parentPid = options.parentPid || ctx.procedurePid;
29
+ const effectiveName = options.name || "anonymous";
30
+ // Determine origin: if this is a root procedure (no parent), origin is undefined
31
+ // Otherwise, use existing origin or find root node
32
+ let origin;
33
+ if (!parentPid) {
34
+ // This is the root procedure - origin is undefined (it IS the origin)
35
+ origin = undefined;
36
+ }
37
+ else {
38
+ // Use existing origin if set, otherwise find root node
39
+ origin = ctx.origin;
40
+ if (!origin && ctx.procedureGraph) {
41
+ const rootNode = ctx.procedureGraph.getRoot();
42
+ origin = rootNode;
43
+ }
44
+ }
45
+ // Determine execution context (boundary detection)
46
+ // Use declarative executionBoundary config to decide behavior
47
+ const boundaryConfig = options.executionBoundary ?? "auto";
48
+ // Get current execution context from context (Phase 3 fields)
49
+ const currentExecutionId = ctx.executionId;
50
+ const contextHandlePid = ctx.executionHandle?.pid;
51
+ let executionId;
52
+ let isExecutionBoundary;
53
+ let executionType;
54
+ let parentExecutionId;
55
+ switch (boundaryConfig) {
56
+ case "always":
57
+ // Always create a new execution
58
+ // If ctx.parentExecutionId is set (e.g., from child execution), use it for child linking
59
+ // Otherwise, this is a root execution with no parent
60
+ executionId = options.executionId ?? contextHandlePid ?? procedurePid;
61
+ isExecutionBoundary = true;
62
+ // Use ctx.executionType (set by engine); fall back to options or derive from name
63
+ executionType =
64
+ ctx.executionType ??
65
+ options.executionType ??
66
+ (effectiveName.includes(":") ? effectiveName.split(":")[0] : effectiveName);
67
+ parentExecutionId = ctx.parentExecutionId; // May be undefined for true roots
68
+ break;
69
+ case "child":
70
+ // Always create a new child execution (with parentExecutionId)
71
+ executionId = options.executionId ?? procedurePid;
72
+ isExecutionBoundary = true;
73
+ // Use ctx.executionType (set by engine); fall back to options or derive from name
74
+ executionType =
75
+ ctx.executionType ??
76
+ options.executionType ??
77
+ (effectiveName.includes(":") ? effectiveName.split(":")[0] : effectiveName);
78
+ // Parent is the current execution from context
79
+ parentExecutionId = currentExecutionId;
80
+ break;
81
+ case "auto":
82
+ // Create only if not already in an execution
83
+ if (currentExecutionId) {
84
+ // Already in an execution - inherit
85
+ executionId = currentExecutionId;
86
+ isExecutionBoundary = false;
87
+ executionType = undefined;
88
+ parentExecutionId = undefined; // Not applicable, inheriting
89
+ }
90
+ else {
91
+ // Not in an execution - create new root
92
+ executionId = options.executionId ?? contextHandlePid ?? procedurePid;
93
+ isExecutionBoundary = true;
94
+ executionType =
95
+ options.executionType ??
96
+ (effectiveName.includes(":") ? effectiveName.split(":")[0] : effectiveName);
97
+ parentExecutionId = undefined; // Root execution
98
+ }
99
+ break;
100
+ case false:
101
+ // Never create an execution boundary - inherit from context (may be undefined)
102
+ executionId = currentExecutionId;
103
+ isExecutionBoundary = false;
104
+ executionType = undefined;
105
+ parentExecutionId = undefined;
106
+ break;
107
+ }
108
+ // Register procedure with execution context
109
+ const node = ctx.procedureGraph.register(procedurePid, parentPid, effectiveName, options.metadata, executionId, isExecutionBoundary, executionType);
110
+ // Start telemetry span
111
+ const span = Telemetry.startSpan(effectiveName);
112
+ span.setAttribute("procedure.pid", procedurePid);
113
+ span.setAttribute("procedure.execution_id", executionId);
114
+ if (isExecutionBoundary) {
115
+ span.setAttribute("procedure.is_execution_boundary", true);
116
+ if (executionType) {
117
+ span.setAttribute("procedure.execution_type", executionType);
118
+ }
119
+ }
120
+ if (parentPid) {
121
+ span.setAttribute("procedure.parent_pid", parentPid);
122
+ }
123
+ if (options.metadata) {
124
+ for (const [key, value] of Object.entries(options.metadata)) {
125
+ span.setAttribute(`procedure.metadata.${key}`, value);
126
+ }
127
+ }
128
+ // Create a new metrics object for this procedure's scope
129
+ // This prevents child procedures from modifying parent's metrics directly
130
+ const procedureMetrics = {};
131
+ // Create metrics proxy that writes to both procedure scope and node
132
+ // This allows existing code to write to ctx.metrics and it automatically tracks in node
133
+ const metricsProxy = new Proxy(procedureMetrics, {
134
+ set(target, key, value) {
135
+ const oldValue = target[key] || 0;
136
+ target[key] = value;
137
+ // Accumulate delta in node
138
+ const delta = value - oldValue;
139
+ if (delta !== 0) {
140
+ node.addMetric(key, delta);
141
+ }
142
+ return true;
143
+ },
144
+ get(target, key) {
145
+ // Return value from procedure scope
146
+ return target[key] || 0;
147
+ },
148
+ ownKeys(target) {
149
+ return Object.keys(target);
150
+ },
151
+ has(target, key) {
152
+ return key in target;
153
+ },
154
+ getOwnPropertyDescriptor(target, key) {
155
+ return Object.getOwnPropertyDescriptor(target, key);
156
+ },
157
+ });
158
+ // Use Context.fork to create an isolated child context for this procedure.
159
+ // This prevents race conditions when parallel procedures run - each gets its own
160
+ // context object with its own procedurePid, procedureNode, origin, and metrics.
161
+ // Shared state (events, procedureGraph, channels, signal) is still accessible.
162
+ //
163
+ // If this is an execution boundary, set the execution fields in the forked context.
164
+ // This ensures all nested procedures inherit executionId from context.
165
+ return Context.fork({
166
+ procedurePid,
167
+ procedureNode: node,
168
+ origin,
169
+ metrics: metricsProxy,
170
+ // Execution context (Phase 3): set if boundary, otherwise inherit from parent context
171
+ ...(isExecutionBoundary
172
+ ? {
173
+ executionId,
174
+ executionType,
175
+ parentExecutionId,
176
+ }
177
+ : {}),
178
+ }, async () => {
179
+ try {
180
+ // Check abort before starting
181
+ if (ctx.signal?.aborted) {
182
+ node.cancel();
183
+ const abortError = new AbortError();
184
+ span.recordError(abortError);
185
+ span.end();
186
+ throw abortError;
187
+ }
188
+ // Emit start event with execution context
189
+ Context.emit("procedure:start", {
190
+ pid: procedurePid,
191
+ name: effectiveName,
192
+ parentPid,
193
+ executionId: node.executionId,
194
+ isExecutionBoundary: node.isExecutionBoundary,
195
+ executionType: node.executionType,
196
+ parentExecutionId, // For DevTools execution tree linking
197
+ });
198
+ // Execute function
199
+ const result = await fn(node);
200
+ // If result is a pure AsyncIterable (not a branded ExecutionHandle), wrap it
201
+ // to maintain context and defer procedure:end until iteration completes.
202
+ // ExecutionHandles manage their own lifecycle — pass them through unchanged.
203
+ if (isAsyncIterable(result) && !result[ExecutionHandleBrand]) {
204
+ // Capture the forked context for use during iteration
205
+ const forkedContext = Context.get();
206
+ const wrappedIterable = (async function* () {
207
+ const iterator = result[Symbol.asyncIterator]();
208
+ try {
209
+ while (true) {
210
+ // Run iterator.next() inside the forked context to maintain procedurePid
211
+ const next = await Context.run(forkedContext, async () => iterator.next());
212
+ if (next.done)
213
+ break;
214
+ // Check abort after getting next value but before yielding
215
+ // This allows the producer to call abort() between yields
216
+ if (ctx.signal?.aborted) {
217
+ throw new AbortError();
218
+ }
219
+ // Emit stream:chunk event for consumers listening to the handle
220
+ // The value is emitted directly (not wrapped) - it's typically an engine event
221
+ await Context.run(forkedContext, async () => {
222
+ Context.emit("stream:chunk", next.value);
223
+ });
224
+ yield next.value;
225
+ }
226
+ // Completed successfully - update status and emit end
227
+ ctx.procedureGraph.updateStatus(procedurePid, "completed");
228
+ ExecutionTracker.sendMetricsToTelemetry(node, span);
229
+ span.end();
230
+ await Context.run(forkedContext, async () => {
231
+ Context.emit("procedure:end", {
232
+ pid: procedurePid,
233
+ executionId: node.executionId,
234
+ metrics: node.metrics,
235
+ durationMs: node.durationMs,
236
+ });
237
+ });
238
+ }
239
+ catch (error) {
240
+ // Handle errors during iteration
241
+ const isAbort = error?.name === "AbortError" ||
242
+ error?.message?.includes("aborted");
243
+ const status = isAbort ? "cancelled" : "failed";
244
+ ctx.procedureGraph.updateStatus(procedurePid, status, error);
245
+ span.recordError(error);
246
+ ExecutionTracker.sendMetricsToTelemetry(node, span);
247
+ span.end();
248
+ await Context.run(forkedContext, async () => {
249
+ Context.emit("procedure:error", {
250
+ pid: procedurePid,
251
+ executionId: node.executionId,
252
+ error,
253
+ });
254
+ });
255
+ throw error;
256
+ }
257
+ finally {
258
+ // Clean up iterator if it has a return method
259
+ if (iterator.return) {
260
+ await Context.run(forkedContext, async () => iterator.return());
261
+ }
262
+ }
263
+ })();
264
+ return wrappedIterable;
265
+ }
266
+ // Regular (non-AsyncIterable) result - complete immediately
267
+ ctx.procedureGraph.updateStatus(procedurePid, "completed");
268
+ this.sendMetricsToTelemetry(node, span);
269
+ span.end();
270
+ Context.emit("procedure:end", {
271
+ pid: procedurePid,
272
+ executionId: node.executionId,
273
+ result,
274
+ metrics: node.metrics,
275
+ durationMs: node.durationMs,
276
+ });
277
+ return result;
278
+ }
279
+ catch (error) {
280
+ // Determine if it was an abort
281
+ const isAbort = error?.name === "AbortError" ||
282
+ error?.message?.includes("aborted");
283
+ // Update status
284
+ const status = isAbort ? "cancelled" : "failed";
285
+ ctx.procedureGraph.updateStatus(procedurePid, status, error);
286
+ span.recordError(error);
287
+ this.sendMetricsToTelemetry(node, span);
288
+ span.end();
289
+ Context.emit("procedure:error", {
290
+ pid: procedurePid,
291
+ executionId: node.executionId,
292
+ error,
293
+ });
294
+ // Preserve error name and message
295
+ const err = error;
296
+ if (isAbort && err.name !== "AbortError") {
297
+ err.name = "AbortError";
298
+ }
299
+ throw err;
300
+ }
301
+ // No finally needed - Context.fork handles isolation automatically
302
+ // Parent context is never modified, so no restoration required
303
+ });
304
+ }
305
+ /**
306
+ * Send metrics to telemetry system
307
+ */
308
+ static sendMetricsToTelemetry(node, span) {
309
+ for (const [key, value] of Object.entries(node.metrics)) {
310
+ Telemetry.getHistogram(`procedure.${key}`).record(value, {
311
+ procedure: node.name || "anonymous",
312
+ procedure_pid: node.pid,
313
+ status: node.status,
314
+ });
315
+ span.setAttribute(`metrics.${key}`, value);
316
+ }
317
+ }
318
+ }
319
+ //# sourceMappingURL=execution-tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-tracker.js","sourceRoot":"","sources":["../src/execution-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAsB,MAAM,WAAW,CAAC;AAExD,OAAO,EAAE,cAAc,EAAwB,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C;;;;;;GAMG;AACH,MAAM,CAAC,MAA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