@tangle-network/agent-eval 0.173.3 → 0.175.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/README.md +1 -1
- package/dist/{proposal-findings-bko3GGy-.js → abort-signal-CtzAM_sJ.js} +11 -11
- package/dist/abort-signal-CtzAM_sJ.js.map +1 -0
- package/dist/adapters/http.d.ts +2 -2
- package/dist/agent-profile-_xPxqVJt.d.ts +488 -0
- package/dist/agent-profile-_xPxqVJt.d.ts.map +1 -0
- package/dist/analyst/index.d.ts +7 -9
- package/dist/analyst/index.d.ts.map +1 -1
- package/dist/analyst/index.js +8 -8
- package/dist/{benchmark-C4wk_Sjr.js → benchmark-DQKzykkO.js} +2 -2
- package/dist/{benchmark-C4wk_Sjr.js.map → benchmark-DQKzykkO.js.map} +1 -1
- package/dist/{benchmark-command-BY9oscke.js → benchmark-command-D_5xG9LG.js} +13 -13
- package/dist/{benchmark-command-BY9oscke.js.map → benchmark-command-D_5xG9LG.js.map} +1 -1
- package/dist/benchmarks/index.d.ts +3 -4
- package/dist/benchmarks/index.d.ts.map +1 -1
- package/dist/benchmarks/index.js +3 -3
- package/dist/campaign/index.d.ts +5 -9
- package/dist/campaign/index.js +7 -7
- package/dist/{campaign-B3kPMU8S.js → campaign-BzMSCejE.js} +8 -8
- package/dist/{campaign-B3kPMU8S.js.map → campaign-BzMSCejE.js.map} +1 -1
- package/dist/{opencode-sqlite-eK6HW6dr.js → claude-jsonl-CxZZrDJ3.js} +9 -149
- package/dist/claude-jsonl-CxZZrDJ3.js.map +1 -0
- package/dist/cli.js +9 -2
- package/dist/cli.js.map +1 -1
- package/dist/{client-DlqdbM7n.d.ts → client-vyYQg3bm.d.ts} +2 -2
- package/dist/{client-DlqdbM7n.d.ts.map → client-vyYQg3bm.d.ts.map} +1 -1
- package/dist/contract/index.d.ts +9 -10
- package/dist/contract/index.js +8 -8
- package/dist/{default-registry-B0bKikCb.js → default-registry-DBqVI4pq.js} +5 -5
- package/dist/{default-registry-B0bKikCb.js.map → default-registry-DBqVI4pq.js.map} +1 -1
- package/dist/{default-registry-BKwc8bN5.d.ts → default-registry-FfNzaUHV.d.ts} +3 -3
- package/dist/{default-registry-BKwc8bN5.d.ts.map → default-registry-FfNzaUHV.d.ts.map} +1 -1
- package/dist/{define-agent-eval-CY6qdlGV.d.ts → define-agent-eval-V1jQyCDR.d.ts} +102 -11
- package/dist/define-agent-eval-V1jQyCDR.d.ts.map +1 -0
- package/dist/{define-agent-eval-8h3lXXee.js → define-agent-eval-ox5McL6e.js} +331 -144
- package/dist/define-agent-eval-ox5McL6e.js.map +1 -0
- package/dist/{dspy-rlm-engine-CF0t2ITD.js → dspy-rlm-engine-Caz2pl4L.js} +3 -3
- package/dist/{dspy-rlm-engine-CF0t2ITD.js.map → dspy-rlm-engine-Caz2pl4L.js.map} +1 -1
- package/dist/{engine-DhFir3Ys.d.ts → engine-CvW_I72-.d.ts} +2 -2
- package/dist/{engine-DhFir3Ys.d.ts.map → engine-CvW_I72-.d.ts.map} +1 -1
- package/dist/experiment/index.d.ts +1 -4
- package/dist/experiment/index.d.ts.map +1 -1
- package/dist/{external-optimizer-process-BwITA9Jp.js → external-optimizer-process-CxnFL1hd.js} +2 -2
- package/dist/{external-optimizer-process-BwITA9Jp.js.map → external-optimizer-process-CxnFL1hd.js.map} +1 -1
- package/dist/{external-optimizer-subprocess-wBWeoG6A.js → external-optimizer-subprocess-CQi27uEI.js} +2 -2
- package/dist/{external-optimizer-subprocess-wBWeoG6A.js.map → external-optimizer-subprocess-CQi27uEI.js.map} +1 -1
- package/dist/fuzz.js +1 -1
- package/dist/fuzz.js.map +1 -1
- package/dist/hosted/index.d.ts +1 -1
- package/dist/{index-D0Db5X-4.d.ts → index-BAAiSF3_.d.ts} +5 -5
- package/dist/{index-D0Db5X-4.d.ts.map → index-BAAiSF3_.d.ts.map} +1 -1
- package/dist/{index-BQqOjerE.d.ts → index-BTrx5s8m.d.ts} +8 -9
- package/dist/index-BTrx5s8m.d.ts.map +1 -0
- package/dist/index-DKXuBPXf.d.ts +3840 -0
- package/dist/index-DKXuBPXf.d.ts.map +1 -0
- package/dist/index.d.ts +11 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -11
- package/dist/{integrity-BWywb34E.js → integrity-DsHWCebQ.js} +11 -435
- package/dist/integrity-DsHWCebQ.js.map +1 -0
- package/dist/{kind-factory-gP6lDySe.js → kind-factory-BLvL-E44.js} +2 -2
- package/dist/{kind-factory-gP6lDySe.js.map → kind-factory-BLvL-E44.js.map} +1 -1
- package/dist/{llm-judge-BfqMFo4h.js → llm-judge-DmNaBrXB.js} +2541 -2435
- package/dist/llm-judge-DmNaBrXB.js.map +1 -0
- package/dist/{matrix-DGu8KhSs.d.ts → matrix-CJtXz1ky.d.ts} +2 -2
- package/dist/{matrix-DGu8KhSs.d.ts.map → matrix-CJtXz1ky.d.ts.map} +1 -1
- package/dist/multishot/golden/index.d.ts +1 -1
- package/dist/multishot/index.d.ts +2 -2
- package/dist/openapi.json +1 -1
- package/dist/opencode-sqlite-CNw3vubS.js +145 -0
- package/dist/opencode-sqlite-CNw3vubS.js.map +1 -0
- package/dist/{produced-state-D91uDvQw.js → produced-state-B8mw6zj9.js} +2 -2
- package/dist/{produced-state-D91uDvQw.js.map → produced-state-B8mw6zj9.js.map} +1 -1
- package/dist/report-command-DKlXfU5r.js +1528 -0
- package/dist/report-command-DKlXfU5r.js.map +1 -0
- package/dist/rl.d.ts +1 -1
- package/dist/rl.d.ts.map +1 -1
- package/dist/rl.js.map +1 -1
- package/dist/rollout/index.js +3 -2
- package/dist/{rollout-C-znbbYg.js → rollout-CGlDq1GI.js} +3 -2
- package/dist/{rollout-C-znbbYg.js.map → rollout-CGlDq1GI.js.map} +1 -1
- package/dist/{semantic-concept-judge-Dok7_35a.js → semantic-concept-judge-E3s_fEjB.js} +3 -3
- package/dist/{semantic-concept-judge-Dok7_35a.js.map → semantic-concept-judge-E3s_fEjB.js.map} +1 -1
- package/dist/{skillopt-optimization-method-DDw3v3gA.js → skillopt-optimization-method-f7399oGb.js} +5 -5
- package/dist/{skillopt-optimization-method-DDw3v3gA.js.map → skillopt-optimization-method-f7399oGb.js.map} +1 -1
- package/dist/statistical-heldout-Cqb73yE9.d.ts +1127 -0
- package/dist/statistical-heldout-Cqb73yE9.d.ts.map +1 -0
- package/dist/{store-otlp-Dow0pk_5.js → store-otlp-DV_H2HDu.js} +2 -2
- package/dist/{store-otlp-Dow0pk_5.js.map → store-otlp-DV_H2HDu.js.map} +1 -1
- package/dist/{store-tool-spans-CCZNsihA.d.ts → store-tool-spans-4o55ABER.d.ts} +3 -3
- package/dist/{store-tool-spans-CCZNsihA.d.ts.map → store-tool-spans-4o55ABER.d.ts.map} +1 -1
- package/dist/{store-tool-spans-CeNj_m2L.js → store-tool-spans-B9tjys_h.js} +3 -3
- package/dist/{store-tool-spans-CeNj_m2L.js.map → store-tool-spans-B9tjys_h.js.map} +1 -1
- package/dist/supervisor-run/index.d.ts +71 -6
- package/dist/supervisor-run/index.d.ts.map +1 -1
- package/dist/supervisor-run/index.js +6 -1357
- package/dist/supervisor-run/index.js.map +1 -1
- package/dist/{task-failure-attributes-CZjZeBsY.js → task-failure-attributes-CUy9mkIY.js} +2 -2
- package/dist/{task-failure-attributes-CZjZeBsY.js.map → task-failure-attributes-CUy9mkIY.js.map} +1 -1
- package/dist/terminal-record-Ce9_UjRz.js +539 -0
- package/dist/terminal-record-Ce9_UjRz.js.map +1 -0
- package/dist/{tool-groups-Cp4Xdzrp.d.ts → tool-groups-DAe1t6zb.d.ts} +2 -2
- package/dist/tool-groups-DAe1t6zb.d.ts.map +1 -0
- package/dist/trace-repair/index.d.ts +1 -1
- package/dist/traces.d.ts +2 -2
- package/dist/traces.js +4 -4
- package/dist/{types-Ba5UQyVD.d.ts → types-BJz2CPTM.d.ts} +2 -2
- package/dist/{types-Ba5UQyVD.d.ts.map → types-BJz2CPTM.d.ts.map} +1 -1
- package/dist/{types-CiWITkGo.js → types-DQ0e2E7y.js} +2 -2
- package/dist/types-DQ0e2E7y.js.map +1 -0
- package/dist/{types-BDV4PiMR.d.ts → types-Dd1ejaeI.d.ts} +2 -2
- package/dist/{types-BDV4PiMR.d.ts.map → types-Dd1ejaeI.d.ts.map} +1 -1
- package/dist/{types-CoPUTiXb.d.ts → types-vUdAx2Cj.d.ts} +65 -3
- package/dist/types-vUdAx2Cj.d.ts.map +1 -0
- package/docs/campaign-proposers.md +42 -0
- package/package.json +1 -1
- package/dist/agent-profile-B9_GGsG8.d.ts +0 -84
- package/dist/agent-profile-B9_GGsG8.d.ts.map +0 -1
- package/dist/backend-integrity-CeuTgqsd.d.ts +0 -280
- package/dist/backend-integrity-CeuTgqsd.d.ts.map +0 -1
- package/dist/benchmark-BjLGkfnN.d.ts +0 -236
- package/dist/benchmark-BjLGkfnN.d.ts.map +0 -1
- package/dist/define-agent-eval-8h3lXXee.js.map +0 -1
- package/dist/define-agent-eval-CY6qdlGV.d.ts.map +0 -1
- package/dist/external-optimizer-contracts-CQCpyrIL.d.ts +0 -172
- package/dist/external-optimizer-contracts-CQCpyrIL.d.ts.map +0 -1
- package/dist/heldout-gate-Df5hsqmm.d.ts +0 -453
- package/dist/heldout-gate-Df5hsqmm.d.ts.map +0 -1
- package/dist/index-BQqOjerE.d.ts.map +0 -1
- package/dist/index-CFDffsKz.d.ts +0 -1135
- package/dist/index-CFDffsKz.d.ts.map +0 -1
- package/dist/integrity-BWywb34E.js.map +0 -1
- package/dist/llm-judge-BfqMFo4h.js.map +0 -1
- package/dist/opencode-sqlite-eK6HW6dr.js.map +0 -1
- package/dist/power-preflight-Ptse_Kq7.d.ts +0 -117
- package/dist/power-preflight-Ptse_Kq7.d.ts.map +0 -1
- package/dist/pre-registration-BoI4ucR3.d.ts +0 -592
- package/dist/pre-registration-BoI4ucR3.d.ts.map +0 -1
- package/dist/promotion-policy-CvMda3kU.d.ts +0 -134
- package/dist/promotion-policy-CvMda3kU.d.ts.map +0 -1
- package/dist/proposal-findings-bko3GGy-.js.map +0 -1
- package/dist/provenance-CRY67X50.d.ts +0 -1995
- package/dist/provenance-CRY67X50.d.ts.map +0 -1
- package/dist/statistical-heldout-DTyB_6-1.d.ts +0 -295
- package/dist/statistical-heldout-DTyB_6-1.d.ts.map +0 -1
- package/dist/tool-groups-Cp4Xdzrp.d.ts.map +0 -1
- package/dist/types-CiWITkGo.js.map +0 -1
- package/dist/types-CoPUTiXb.d.ts.map +0 -1
package/dist/{task-failure-attributes-CZjZeBsY.js.map → task-failure-attributes-CUy9mkIY.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-failure-attributes-CZjZeBsY.js","names":[],"sources":["../src/trace/error-classification.ts","../src/trace/execution-measurements.ts","../src/trace/task-failure-attributes.ts"],"sourcesContent":["import type { OtlpSpanRole } from './otlp-attributes'\n\nexport type TraceErrorRole = OtlpSpanRole\n\nexport interface TraceErrorSignal {\n id: string\n parentId?: string\n role: TraceErrorRole\n error: boolean\n processRoot: boolean\n}\n\nexport interface TraceErrorSummary {\n total: number\n execution: number\n process: number\n guardrail: number\n evaluation: number\n propagated: number\n unclassified: number\n}\n\n/**\n * Classify errored spans without counting a propagated parent status as a\n * second execution failure.\n */\nexport function summarizeTraceErrors(signals: readonly TraceErrorSignal[]): TraceErrorSummary {\n const byId = new Map<string, TraceErrorSignal>()\n for (const signal of signals) {\n if (byId.has(signal.id)) {\n throw new Error(`summarizeTraceErrors: duplicate span id '${signal.id}'`)\n }\n byId.set(signal.id, signal)\n }\n\n const propagated = new Set<string>()\n for (const signal of signals) {\n if (!signal.error) continue\n const visited = new Set<string>()\n let parentId = signal.parentId\n while (parentId && !visited.has(parentId)) {\n visited.add(parentId)\n const parent = byId.get(parentId)\n if (!parent) break\n if (parent.error) propagated.add(parent.id)\n parentId = parent.parentId\n }\n }\n\n const summary: TraceErrorSummary = {\n total: 0,\n execution: 0,\n process: 0,\n guardrail: 0,\n evaluation: 0,\n propagated: 0,\n unclassified: 0,\n }\n\n for (const signal of signals) {\n if (!signal.error) continue\n summary.total += 1\n if (signal.role === 'GUARDRAIL') {\n summary.guardrail += 1\n } else if (signal.role === 'EVALUATOR') {\n summary.evaluation += 1\n } else if (signal.processRoot) {\n summary.process += 1\n } else if (propagated.has(signal.id)) {\n summary.propagated += 1\n } else if (\n signal.role === 'AGENT' ||\n signal.role === 'CHAIN' ||\n signal.role === 'LLM' ||\n signal.role === 'TOOL'\n ) {\n summary.execution += 1\n } else {\n summary.unclassified += 1\n }\n }\n\n return summary\n}\n","import type { RunTokenUsage } from '../run-record'\nimport {\n LLM_CACHE_WRITE_TOKEN_ATTR_KEYS,\n LLM_CACHED_TOKEN_ATTR_KEYS,\n LLM_COST_ATTR_KEYS,\n LLM_INPUT_TOKEN_ATTR_KEYS,\n LLM_OUTPUT_TOKEN_ATTR_KEYS,\n LLM_REASONING_TOKEN_ATTR_KEYS,\n RUN_COST_ATTR_KEYS,\n} from './otlp-attributes'\n\nexport interface ExecutionMeasurementSpan {\n id: string\n parentId?: string\n attributes: Record<string, unknown>\n modelCall: boolean\n aggregate: boolean\n}\n\nexport interface MeasurementCoverage {\n value?: number\n reportingCalls: number\n complete: boolean\n}\n\nexport interface ExecutionMeasurements {\n tokenUsage: RunTokenUsage\n modelCallCount: number\n callSpanIds: string[]\n cost: MeasurementCoverage\n aggregate?: {\n tokenUsage: RunTokenUsage\n costUsd?: number\n }\n}\n\nconst TOKEN_MEASUREMENT_KEY_GROUPS = [\n LLM_INPUT_TOKEN_ATTR_KEYS,\n LLM_OUTPUT_TOKEN_ATTR_KEYS,\n LLM_REASONING_TOKEN_ATTR_KEYS,\n LLM_CACHED_TOKEN_ATTR_KEYS,\n LLM_CACHE_WRITE_TOKEN_ATTR_KEYS,\n] as const\n\nconst EXECUTION_MEASUREMENT_KEY_GROUPS = [\n ...TOKEN_MEASUREMENT_KEY_GROUPS,\n LLM_COST_ATTR_KEYS,\n] as const\n\ninterface RetainedCallSummary {\n callCount: number\n measurements: Array<{\n total: number\n reportingCalls: number\n }>\n}\n\n/**\n * Reconcile execution measurements across nested telemetry wrappers.\n * A measured parent is used only when a descendant call does not report the\n * same field, so aggregate wrappers neither duplicate complete child data nor\n * erase complementary parent fields.\n */\nexport function summarizeExecutionMeasurements(\n spans: ExecutionMeasurementSpan[],\n): ExecutionMeasurements {\n const byId = new Map<string, ExecutionMeasurementSpan>()\n for (const span of spans) {\n if (byId.has(span.id)) {\n throw new Error(`summarizeExecutionMeasurements: duplicate span id \"${span.id}\"`)\n }\n byId.set(span.id, span)\n }\n const tokenMeasurementKeys = TOKEN_MEASUREMENT_KEY_GROUPS.flat()\n const candidates = spans.filter(\n (span) =>\n span.modelCall ||\n (!span.aggregate && readNumber(span.attributes, tokenMeasurementKeys) !== undefined),\n )\n const candidateIds = new Set(candidates.map((span) => span.id))\n const candidateChildren = new Map<string, ExecutionMeasurementSpan[]>()\n for (const candidate of candidates) {\n const parentId = nearestCandidateParent(candidate, byId, candidateIds)\n if (!parentId) continue\n const children = candidateChildren.get(parentId) ?? []\n children.push(candidate)\n candidateChildren.set(parentId, children)\n }\n const aggregateIds = classifyAggregateSpans(candidates, candidateChildren)\n const untypedRunCostIds = new Set(\n spans\n .filter(\n (span) =>\n !span.modelCall &&\n !span.aggregate &&\n !candidateIds.has(span.id) &&\n readNumber(span.attributes, RUN_COST_ATTR_KEYS) !== undefined,\n )\n .map((span) => span.id),\n )\n const aggregateSourceIds = new Set(\n spans\n .filter(\n (span) => span.aggregate || aggregateIds.has(span.id) || untypedRunCostIds.has(span.id),\n )\n .map((span) => span.id),\n )\n\n const calls = candidates.filter((span) => !aggregateIds.has(span.id))\n const input = reconcileMeasurement(calls, byId, aggregateSourceIds, LLM_INPUT_TOKEN_ATTR_KEYS)\n const reasoning = reconcileMeasurement(\n calls,\n byId,\n aggregateSourceIds,\n LLM_REASONING_TOKEN_ATTR_KEYS,\n )\n const output = reconcileMeasurement(\n calls,\n byId,\n aggregateSourceIds,\n LLM_OUTPUT_TOKEN_ATTR_KEYS,\n LLM_REASONING_TOKEN_ATTR_KEYS,\n )\n const cached = reconcileMeasurement(calls, byId, aggregateSourceIds, LLM_CACHED_TOKEN_ATTR_KEYS)\n const cacheWrite = reconcileMeasurement(\n calls,\n byId,\n aggregateSourceIds,\n LLM_CACHE_WRITE_TOKEN_ATTR_KEYS,\n )\n const aggregate = summarizeAggregateMeasurements(\n spans,\n byId,\n new Set([...aggregateIds, ...untypedRunCostIds]),\n )\n\n return {\n tokenUsage: {\n input: input.value ?? 0,\n output: Math.max(output.value ?? 0, reasoning.value ?? 0),\n ...(reasoning.value !== undefined ? { reasoning: reasoning.value } : {}),\n ...(cached.value !== undefined ? { cached: cached.value } : {}),\n ...(cacheWrite.value !== undefined ? { cacheWrite: cacheWrite.value } : {}),\n },\n modelCallCount: calls.length,\n callSpanIds: calls.map((span) => span.id),\n cost: reconcileMeasurement(calls, byId, aggregateSourceIds, LLM_COST_ATTR_KEYS),\n ...(aggregate ? { aggregate } : {}),\n }\n}\n\nexport function recordAggregateMeasurements(\n raw: Record<string, number>,\n aggregate: ExecutionMeasurements['aggregate'],\n): void {\n if (!aggregate) return\n raw.aggregate_prompt_tokens = aggregate.tokenUsage.input\n raw.aggregate_completion_tokens = aggregate.tokenUsage.output\n if (aggregate.tokenUsage.reasoning !== undefined)\n raw.aggregate_reasoning_tokens = aggregate.tokenUsage.reasoning\n if (aggregate.tokenUsage.cached !== undefined)\n raw.aggregate_cached_tokens = aggregate.tokenUsage.cached\n if (aggregate.tokenUsage.cacheWrite !== undefined)\n raw.aggregate_cache_write_tokens = aggregate.tokenUsage.cacheWrite\n if (aggregate.costUsd !== undefined) raw.aggregate_cost_usd = aggregate.costUsd\n}\n\nfunction summarizeAggregateMeasurements(\n spans: ExecutionMeasurementSpan[],\n byId: Map<string, ExecutionMeasurementSpan>,\n aggregateIds: Set<string>,\n): ExecutionMeasurements['aggregate'] {\n const aggregates = spans.filter((span) => span.aggregate || aggregateIds.has(span.id))\n const input = reconcileTopLevelMeasurement(aggregates, byId, LLM_INPUT_TOKEN_ATTR_KEYS)\n const output = reconcileTopLevelMeasurement(aggregates, byId, LLM_OUTPUT_TOKEN_ATTR_KEYS)\n const reasoning = reconcileTopLevelMeasurement(aggregates, byId, LLM_REASONING_TOKEN_ATTR_KEYS)\n const cached = reconcileTopLevelMeasurement(aggregates, byId, LLM_CACHED_TOKEN_ATTR_KEYS)\n const cacheWrite = reconcileTopLevelMeasurement(aggregates, byId, LLM_CACHE_WRITE_TOKEN_ATTR_KEYS)\n const costUsd = reconcileTopLevelMeasurement(aggregates, byId, LLM_COST_ATTR_KEYS)\n if (\n input === undefined &&\n output === undefined &&\n reasoning === undefined &&\n cached === undefined &&\n cacheWrite === undefined &&\n costUsd === undefined\n )\n return undefined\n return {\n tokenUsage: {\n input: input ?? 0,\n output: output ?? reasoning ?? 0,\n ...(reasoning !== undefined ? { reasoning } : {}),\n ...(cached !== undefined ? { cached } : {}),\n ...(cacheWrite !== undefined ? { cacheWrite } : {}),\n },\n ...(costUsd !== undefined ? { costUsd } : {}),\n }\n}\n\nfunction reconcileTopLevelMeasurement(\n spans: ExecutionMeasurementSpan[],\n byId: Map<string, ExecutionMeasurementSpan>,\n keys: readonly string[],\n): number | undefined {\n const selected = new Map<string, number>()\n for (const span of spans) {\n const value = readNumber(span.attributes, keys)\n if (value !== undefined) selected.set(span.id, value)\n }\n for (const spanId of [...selected.keys()]) {\n const span = byId.get(spanId)\n if (!span) continue\n if (ancestorIds(span, byId).some((ancestorId) => selected.has(ancestorId))) {\n selected.delete(spanId)\n }\n }\n return selected.size > 0\n ? [...selected.values()].reduce((total, value) => total + value, 0)\n : undefined\n}\n\nfunction reconcileMeasurement(\n calls: ExecutionMeasurementSpan[],\n byId: Map<string, ExecutionMeasurementSpan>,\n aggregateSourceIds: Set<string>,\n keys: readonly string[],\n fallbackKeys?: readonly string[],\n): MeasurementCoverage {\n const selected = new Map<string, number>()\n const callIds = new Set(calls.map((call) => call.id))\n let reportingCalls = 0\n\n for (const call of calls) {\n const primary = nearestMeasurement(call, byId, callIds, aggregateSourceIds, keys)\n const fallback = fallbackKeys\n ? nearestMeasurement(call, byId, callIds, aggregateSourceIds, fallbackKeys)\n : undefined\n const source =\n primary && fallback && primary.span.id === fallback.span.id\n ? { span: primary.span, value: Math.max(primary.value, fallback.value) }\n : (primary ?? fallback)\n if (!source) continue\n reportingCalls += 1\n selected.set(source.span.id, source.value)\n }\n\n for (const spanId of [...selected.keys()]) {\n const span = byId.get(spanId)\n if (!span) continue\n if (\n ancestorIds(span, byId).some(\n (ancestorId) => selected.has(ancestorId) && !callIds.has(ancestorId),\n )\n ) {\n selected.delete(spanId)\n }\n }\n\n return {\n ...(selected.size > 0\n ? { value: [...selected.values()].reduce((total, value) => total + value, 0) }\n : {}),\n reportingCalls,\n complete: calls.length > 0 && reportingCalls === calls.length,\n }\n}\n\nfunction nearestMeasurement(\n call: ExecutionMeasurementSpan,\n byId: Map<string, ExecutionMeasurementSpan>,\n callIds: Set<string>,\n aggregateSourceIds: Set<string>,\n keys: readonly string[],\n): { span: ExecutionMeasurementSpan; value: number } | undefined {\n let current: ExecutionMeasurementSpan | undefined = call\n const seen = new Set<string>()\n while (current && !seen.has(current.id)) {\n seen.add(current.id)\n const value = readNumber(current.attributes, keys)\n if (\n value !== undefined &&\n (current.id === call.id || (!callIds.has(current.id) && aggregateSourceIds.has(current.id)))\n ) {\n return { span: current, value }\n }\n current = current.parentId ? byId.get(current.parentId) : undefined\n }\n return undefined\n}\n\nfunction classifyAggregateSpans(\n candidates: ExecutionMeasurementSpan[],\n childrenById: Map<string, ExecutionMeasurementSpan[]>,\n): Set<string> {\n const aggregateIds = new Set<string>()\n const summaries = new Map<string, RetainedCallSummary>()\n const visiting = new Set<string>()\n\n const visit = (span: ExecutionMeasurementSpan): RetainedCallSummary => {\n const cached = summaries.get(span.id)\n if (cached) return cached\n if (visiting.has(span.id)) return emptyRetainedCallSummary()\n visiting.add(span.id)\n\n const descendants = emptyRetainedCallSummary()\n for (const child of childrenById.get(span.id) ?? []) {\n const childDescendants = visit(child)\n if (!aggregateIds.has(child.id)) addRetainedCall(descendants, child)\n addRetainedCallSummary(descendants, childDescendants)\n }\n\n if (\n descendants.callCount > 0 &&\n (!span.modelCall || hasCompatibleDescendantMeasurements(span, descendants))\n ) {\n aggregateIds.add(span.id)\n }\n\n visiting.delete(span.id)\n summaries.set(span.id, descendants)\n return descendants\n }\n\n for (const candidate of candidates) visit(candidate)\n return aggregateIds\n}\n\nfunction emptyRetainedCallSummary(): RetainedCallSummary {\n return {\n callCount: 0,\n measurements: EXECUTION_MEASUREMENT_KEY_GROUPS.map(() => ({\n total: 0,\n reportingCalls: 0,\n })),\n }\n}\n\nfunction addRetainedCall(summary: RetainedCallSummary, span: ExecutionMeasurementSpan): void {\n summary.callCount += 1\n for (let index = 0; index < EXECUTION_MEASUREMENT_KEY_GROUPS.length; index += 1) {\n const value = readNumber(span.attributes, EXECUTION_MEASUREMENT_KEY_GROUPS[index]!)\n if (value === undefined) continue\n const measurement = summary.measurements[index]!\n measurement.total += value\n measurement.reportingCalls += 1\n }\n}\n\nfunction addRetainedCallSummary(target: RetainedCallSummary, source: RetainedCallSummary): void {\n target.callCount += source.callCount\n for (let index = 0; index < target.measurements.length; index += 1) {\n const measurement = target.measurements[index]!\n const sourceMeasurement = source.measurements[index]!\n measurement.total += sourceMeasurement.total\n measurement.reportingCalls += sourceMeasurement.reportingCalls\n }\n}\n\nfunction hasCompatibleDescendantMeasurements(\n span: ExecutionMeasurementSpan,\n descendants: RetainedCallSummary,\n): boolean {\n let parentMeasurements = 0\n let descendantMeasurements = 0\n for (let index = 0; index < EXECUTION_MEASUREMENT_KEY_GROUPS.length; index += 1) {\n const keys = EXECUTION_MEASUREMENT_KEY_GROUPS[index]!\n const parentValue = readNumber(span.attributes, keys)\n const measurement = descendants.measurements[index]!\n if (parentValue !== undefined) parentMeasurements += 1\n if (measurement.reportingCalls > 0) descendantMeasurements += 1\n if (parentValue === undefined || measurement.reportingCalls === 0) continue\n if (measurement.reportingCalls !== descendants.callCount) continue\n if (Math.abs(parentValue - measurement.total) > 1e-12) return false\n }\n return parentMeasurements === 0 || descendantMeasurements > 0\n}\n\nfunction ancestorIds(\n span: ExecutionMeasurementSpan,\n byId: Map<string, ExecutionMeasurementSpan>,\n): string[] {\n const ids: string[] = []\n const seen = new Set<string>()\n let parentId = span.parentId\n while (parentId && !seen.has(parentId)) {\n ids.push(parentId)\n seen.add(parentId)\n parentId = byId.get(parentId)?.parentId\n }\n return ids\n}\n\nfunction nearestCandidateParent(\n span: ExecutionMeasurementSpan,\n byId: Map<string, ExecutionMeasurementSpan>,\n candidateIds: Set<string>,\n): string | undefined {\n const seen = new Set<string>()\n let parentId = span.parentId\n while (parentId && !seen.has(parentId)) {\n if (candidateIds.has(parentId)) return parentId\n seen.add(parentId)\n parentId = byId.get(parentId)?.parentId\n }\n return undefined\n}\n\nfunction readNumber(\n attributes: Record<string, unknown>,\n keys: readonly string[],\n): number | undefined {\n for (const key of keys) {\n const value = attributes[key]\n const parsed =\n typeof value === 'number'\n ? value\n : typeof value === 'string' && value.length > 0\n ? Number(value)\n : Number.NaN\n if (Number.isFinite(parsed) && parsed >= 0) return parsed\n }\n return undefined\n}\n","import { ValidationError } from '../errors'\nimport { FAILURE_CLASSES, type FailureClass } from './schema'\n\nconst TASK_FAILURE_CLASS_ATTR = 'tangle.task.failure_class'\nconst TASK_FAILURE_MODE_ATTR = 'tangle.task.failure_mode'\n\ninterface AttributeCarrier {\n attributes: Record<string, unknown>\n}\n\nexport type TaskFailureLabels =\n | { failureClass?: undefined; failureMode?: undefined }\n | { failureClass: 'success'; failureMode?: undefined }\n | { failureClass: Exclude<FailureClass, 'success'>; failureMode?: string }\n\nexport function readTaskFailureLabels(\n roots: readonly AttributeCarrier[],\n context: string,\n): TaskFailureLabels {\n const failureClass = readConsistentRootString(roots, TASK_FAILURE_CLASS_ATTR, context)\n const failureMode = readConsistentRootString(roots, TASK_FAILURE_MODE_ATTR, context)\n\n if (failureClass !== undefined && !FAILURE_CLASSES.includes(failureClass as FailureClass)) {\n throw new ValidationError(\n `${context}: ${TASK_FAILURE_CLASS_ATTR} must be one of ${FAILURE_CLASSES.join(', ')}`,\n )\n }\n if (failureMode !== undefined && (failureClass === undefined || failureClass === 'success')) {\n throw new ValidationError(\n `${context}: ${TASK_FAILURE_MODE_ATTR} requires a non-success ${TASK_FAILURE_CLASS_ATTR}`,\n )\n }\n\n if (failureClass === undefined) return {}\n if (failureClass === 'success') return { failureClass }\n return {\n failureClass: failureClass as Exclude<FailureClass, 'success'>,\n ...(failureMode ? { failureMode } : {}),\n }\n}\n\nfunction readConsistentRootString(\n roots: readonly AttributeCarrier[],\n key: string,\n context: string,\n): string | undefined {\n const values = new Set<string>()\n for (const root of roots) {\n if (!Object.hasOwn(root.attributes, key)) continue\n const value = root.attributes[key]\n if (typeof value !== 'string' || value.trim().length === 0) {\n throw new ValidationError(`${context}: ${key} must be a non-empty string`)\n }\n values.add(value)\n }\n\n if (values.size > 1) {\n throw new ValidationError(\n `${context}: conflicting ${key} values: ${[...values].sort().join(', ')}`,\n )\n }\n return values.values().next().value\n}\n"],"mappings":";;;;;;;;;AA0BA,SAAgB,qBAAqB,SAAyD;CAC5F,MAAM,uBAAO,IAAI,IAA8B;CAC/C,KAAK,MAAM,UAAU,SAAS;EAC5B,IAAI,KAAK,IAAI,OAAO,EAAE,GACpB,MAAM,IAAI,MAAM,4CAA4C,OAAO,GAAG,EAAE;EAE1E,KAAK,IAAI,OAAO,IAAI,MAAM;CAC5B;CAEA,MAAM,6BAAa,IAAI,IAAY;CACnC,KAAK,MAAM,UAAU,SAAS;EAC5B,IAAI,CAAC,OAAO,OAAO;EACnB,MAAM,0BAAU,IAAI,IAAY;EAChC,IAAI,WAAW,OAAO;EACtB,OAAO,YAAY,CAAC,QAAQ,IAAI,QAAQ,GAAG;GACzC,QAAQ,IAAI,QAAQ;GACpB,MA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IAAI,GACxE;CAEF,OAAO,OAAO,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC;AAChC"}
|
|
1
|
+
{"version":3,"file":"task-failure-attributes-CUy9mkIY.js","names":[],"sources":["../src/trace/error-classification.ts","../src/trace/execution-measurements.ts","../src/trace/task-failure-attributes.ts"],"sourcesContent":["import type { OtlpSpanRole } from './otlp-attributes'\n\nexport type TraceErrorRole = OtlpSpanRole\n\nexport interface TraceErrorSignal {\n id: string\n parentId?: string\n role: TraceErrorRole\n error: boolean\n processRoot: boolean\n}\n\nexport interface TraceErrorSummary {\n total: number\n execution: number\n process: number\n guardrail: number\n evaluation: number\n propagated: number\n unclassified: number\n}\n\n/**\n * Classify errored spans without counting a propagated parent status as a\n * second execution failure.\n */\nexport function summarizeTraceErrors(signals: readonly TraceErrorSignal[]): TraceErrorSummary {\n const byId = new Map<string, TraceErrorSignal>()\n for (const signal of signals) {\n if (byId.has(signal.id)) {\n throw new Error(`summarizeTraceErrors: duplicate span id '${signal.id}'`)\n }\n byId.set(signal.id, signal)\n }\n\n const propagated = new Set<string>()\n for (const signal of signals) {\n if (!signal.error) continue\n const visited = new Set<string>()\n let parentId = signal.parentId\n while (parentId && !visited.has(parentId)) {\n visited.add(parentId)\n const parent = byId.get(parentId)\n if (!parent) break\n if (parent.error) propagated.add(parent.id)\n parentId = parent.parentId\n }\n }\n\n const summary: TraceErrorSummary = {\n total: 0,\n execution: 0,\n process: 0,\n guardrail: 0,\n evaluation: 0,\n propagated: 0,\n unclassified: 0,\n }\n\n for (const signal of signals) {\n if (!signal.error) continue\n summary.total += 1\n if (signal.role === 'GUARDRAIL') {\n summary.guardrail += 1\n } else if (signal.role === 'EVALUATOR') {\n summary.evaluation += 1\n } else if (signal.processRoot) {\n summary.process += 1\n } else if (propagated.has(signal.id)) {\n summary.propagated += 1\n } else if (\n signal.role === 'AGENT' ||\n signal.role === 'CHAIN' ||\n signal.role === 'LLM' ||\n signal.role === 'TOOL'\n ) {\n summary.execution += 1\n } else {\n summary.unclassified += 1\n }\n }\n\n return summary\n}\n","import type { RunTokenUsage } from '../run-record'\nimport {\n LLM_CACHE_WRITE_TOKEN_ATTR_KEYS,\n LLM_CACHED_TOKEN_ATTR_KEYS,\n LLM_COST_ATTR_KEYS,\n LLM_INPUT_TOKEN_ATTR_KEYS,\n LLM_OUTPUT_TOKEN_ATTR_KEYS,\n LLM_REASONING_TOKEN_ATTR_KEYS,\n RUN_COST_ATTR_KEYS,\n} from './otlp-attributes'\n\nexport interface ExecutionMeasurementSpan {\n id: string\n parentId?: string\n attributes: Record<string, unknown>\n modelCall: boolean\n aggregate: boolean\n}\n\nexport interface MeasurementCoverage {\n value?: number\n reportingCalls: number\n complete: boolean\n}\n\nexport interface ExecutionMeasurements {\n tokenUsage: RunTokenUsage\n modelCallCount: number\n callSpanIds: string[]\n cost: MeasurementCoverage\n aggregate?: {\n tokenUsage: RunTokenUsage\n costUsd?: number\n }\n}\n\nconst TOKEN_MEASUREMENT_KEY_GROUPS = [\n LLM_INPUT_TOKEN_ATTR_KEYS,\n LLM_OUTPUT_TOKEN_ATTR_KEYS,\n LLM_REASONING_TOKEN_ATTR_KEYS,\n LLM_CACHED_TOKEN_ATTR_KEYS,\n LLM_CACHE_WRITE_TOKEN_ATTR_KEYS,\n] as const\n\nconst EXECUTION_MEASUREMENT_KEY_GROUPS = [\n ...TOKEN_MEASUREMENT_KEY_GROUPS,\n LLM_COST_ATTR_KEYS,\n] as const\n\ninterface RetainedCallSummary {\n callCount: number\n measurements: Array<{\n total: number\n reportingCalls: number\n }>\n}\n\n/**\n * Reconcile execution measurements across nested telemetry wrappers.\n * A measured parent is used only when a descendant call does not report the\n * same field, so aggregate wrappers neither duplicate complete child data nor\n * erase complementary parent fields.\n */\nexport function summarizeExecutionMeasurements(\n spans: ExecutionMeasurementSpan[],\n): ExecutionMeasurements {\n const byId = new Map<string, ExecutionMeasurementSpan>()\n for (const span of spans) {\n if (byId.has(span.id)) {\n throw new Error(`summarizeExecutionMeasurements: duplicate span id \"${span.id}\"`)\n }\n byId.set(span.id, span)\n }\n const tokenMeasurementKeys = TOKEN_MEASUREMENT_KEY_GROUPS.flat()\n const candidates = spans.filter(\n (span) =>\n span.modelCall ||\n (!span.aggregate && readNumber(span.attributes, tokenMeasurementKeys) !== undefined),\n )\n const candidateIds = new Set(candidates.map((span) => span.id))\n const candidateChildren = new Map<string, ExecutionMeasurementSpan[]>()\n for (const candidate of candidates) {\n const parentId = nearestCandidateParent(candidate, byId, candidateIds)\n if (!parentId) continue\n const children = candidateChildren.get(parentId) ?? []\n children.push(candidate)\n candidateChildren.set(parentId, children)\n }\n const aggregateIds = classifyAggregateSpans(candidates, candidateChildren)\n const untypedRunCostIds = new Set(\n spans\n .filter(\n (span) =>\n !span.modelCall &&\n !span.aggregate &&\n !candidateIds.has(span.id) &&\n readNumber(span.attributes, RUN_COST_ATTR_KEYS) !== undefined,\n )\n .map((span) => span.id),\n )\n const aggregateSourceIds = new Set(\n spans\n .filter(\n (span) => span.aggregate || aggregateIds.has(span.id) || untypedRunCostIds.has(span.id),\n )\n .map((span) => span.id),\n )\n\n const calls = candidates.filter((span) => !aggregateIds.has(span.id))\n const input = reconcileMeasurement(calls, byId, aggregateSourceIds, LLM_INPUT_TOKEN_ATTR_KEYS)\n const reasoning = reconcileMeasurement(\n calls,\n byId,\n aggregateSourceIds,\n LLM_REASONING_TOKEN_ATTR_KEYS,\n )\n const output = reconcileMeasurement(\n calls,\n byId,\n aggregateSourceIds,\n LLM_OUTPUT_TOKEN_ATTR_KEYS,\n LLM_REASONING_TOKEN_ATTR_KEYS,\n )\n const cached = reconcileMeasurement(calls, byId, aggregateSourceIds, LLM_CACHED_TOKEN_ATTR_KEYS)\n const cacheWrite = reconcileMeasurement(\n calls,\n byId,\n aggregateSourceIds,\n LLM_CACHE_WRITE_TOKEN_ATTR_KEYS,\n )\n const aggregate = summarizeAggregateMeasurements(\n spans,\n byId,\n new Set([...aggregateIds, ...untypedRunCostIds]),\n )\n\n return {\n tokenUsage: {\n input: input.value ?? 0,\n output: Math.max(output.value ?? 0, reasoning.value ?? 0),\n ...(reasoning.value !== undefined ? { reasoning: reasoning.value } : {}),\n ...(cached.value !== undefined ? { cached: cached.value } : {}),\n ...(cacheWrite.value !== undefined ? { cacheWrite: cacheWrite.value } : {}),\n },\n modelCallCount: calls.length,\n callSpanIds: calls.map((span) => span.id),\n cost: reconcileMeasurement(calls, byId, aggregateSourceIds, LLM_COST_ATTR_KEYS),\n ...(aggregate ? { aggregate } : {}),\n }\n}\n\nexport function recordAggregateMeasurements(\n raw: Record<string, number>,\n aggregate: ExecutionMeasurements['aggregate'],\n): void {\n if (!aggregate) return\n raw.aggregate_prompt_tokens = aggregate.tokenUsage.input\n raw.aggregate_completion_tokens = aggregate.tokenUsage.output\n if (aggregate.tokenUsage.reasoning !== undefined)\n raw.aggregate_reasoning_tokens = aggregate.tokenUsage.reasoning\n if (aggregate.tokenUsage.cached !== undefined)\n raw.aggregate_cached_tokens = aggregate.tokenUsage.cached\n if (aggregate.tokenUsage.cacheWrite !== undefined)\n raw.aggregate_cache_write_tokens = aggregate.tokenUsage.cacheWrite\n if (aggregate.costUsd !== undefined) raw.aggregate_cost_usd = aggregate.costUsd\n}\n\nfunction summarizeAggregateMeasurements(\n spans: ExecutionMeasurementSpan[],\n byId: Map<string, ExecutionMeasurementSpan>,\n aggregateIds: Set<string>,\n): ExecutionMeasurements['aggregate'] {\n const aggregates = spans.filter((span) => span.aggregate || aggregateIds.has(span.id))\n const input = reconcileTopLevelMeasurement(aggregates, byId, LLM_INPUT_TOKEN_ATTR_KEYS)\n const output = reconcileTopLevelMeasurement(aggregates, byId, LLM_OUTPUT_TOKEN_ATTR_KEYS)\n const reasoning = reconcileTopLevelMeasurement(aggregates, byId, LLM_REASONING_TOKEN_ATTR_KEYS)\n const cached = reconcileTopLevelMeasurement(aggregates, byId, LLM_CACHED_TOKEN_ATTR_KEYS)\n const cacheWrite = reconcileTopLevelMeasurement(aggregates, byId, LLM_CACHE_WRITE_TOKEN_ATTR_KEYS)\n const costUsd = reconcileTopLevelMeasurement(aggregates, byId, LLM_COST_ATTR_KEYS)\n if (\n input === undefined &&\n output === undefined &&\n reasoning === undefined &&\n cached === undefined &&\n cacheWrite === undefined &&\n costUsd === undefined\n )\n return undefined\n return {\n tokenUsage: {\n input: input ?? 0,\n output: output ?? reasoning ?? 0,\n ...(reasoning !== undefined ? { reasoning } : {}),\n ...(cached !== undefined ? { cached } : {}),\n ...(cacheWrite !== undefined ? { cacheWrite } : {}),\n },\n ...(costUsd !== undefined ? { costUsd } : {}),\n }\n}\n\nfunction reconcileTopLevelMeasurement(\n spans: ExecutionMeasurementSpan[],\n byId: Map<string, ExecutionMeasurementSpan>,\n keys: readonly string[],\n): number | undefined {\n const selected = new Map<string, number>()\n for (const span of spans) {\n const value = readNumber(span.attributes, keys)\n if (value !== undefined) selected.set(span.id, value)\n }\n for (const spanId of [...selected.keys()]) {\n const span = byId.get(spanId)\n if (!span) continue\n if (ancestorIds(span, byId).some((ancestorId) => selected.has(ancestorId))) {\n selected.delete(spanId)\n }\n }\n return selected.size > 0\n ? [...selected.values()].reduce((total, value) => total + value, 0)\n : undefined\n}\n\nfunction reconcileMeasurement(\n calls: ExecutionMeasurementSpan[],\n byId: Map<string, ExecutionMeasurementSpan>,\n aggregateSourceIds: Set<string>,\n keys: readonly string[],\n fallbackKeys?: readonly string[],\n): MeasurementCoverage {\n const selected = new Map<string, number>()\n const callIds = new Set(calls.map((call) => call.id))\n let reportingCalls = 0\n\n for (const call of calls) {\n const primary = nearestMeasurement(call, byId, callIds, aggregateSourceIds, keys)\n const fallback = fallbackKeys\n ? nearestMeasurement(call, byId, callIds, aggregateSourceIds, fallbackKeys)\n : undefined\n const source =\n primary && fallback && primary.span.id === fallback.span.id\n ? { span: primary.span, value: Math.max(primary.value, fallback.value) }\n : (primary ?? fallback)\n if (!source) continue\n reportingCalls += 1\n selected.set(source.span.id, source.value)\n }\n\n for (const spanId of [...selected.keys()]) {\n const span = byId.get(spanId)\n if (!span) continue\n if (\n ancestorIds(span, byId).some(\n (ancestorId) => selected.has(ancestorId) && !callIds.has(ancestorId),\n )\n ) {\n selected.delete(spanId)\n }\n }\n\n return {\n ...(selected.size > 0\n ? { value: [...selected.values()].reduce((total, value) => total + value, 0) }\n : {}),\n reportingCalls,\n complete: calls.length > 0 && reportingCalls === calls.length,\n }\n}\n\nfunction nearestMeasurement(\n call: ExecutionMeasurementSpan,\n byId: Map<string, ExecutionMeasurementSpan>,\n callIds: Set<string>,\n aggregateSourceIds: Set<string>,\n keys: readonly string[],\n): { span: ExecutionMeasurementSpan; value: number } | undefined {\n let current: ExecutionMeasurementSpan | undefined = call\n const seen = new Set<string>()\n while (current && !seen.has(current.id)) {\n seen.add(current.id)\n const value = readNumber(current.attributes, keys)\n if (\n value !== undefined &&\n (current.id === call.id || (!callIds.has(current.id) && aggregateSourceIds.has(current.id)))\n ) {\n return { span: current, value }\n }\n current = current.parentId ? byId.get(current.parentId) : undefined\n }\n return undefined\n}\n\nfunction classifyAggregateSpans(\n candidates: ExecutionMeasurementSpan[],\n childrenById: Map<string, ExecutionMeasurementSpan[]>,\n): Set<string> {\n const aggregateIds = new Set<string>()\n const summaries = new Map<string, RetainedCallSummary>()\n const visiting = new Set<string>()\n\n const visit = (span: ExecutionMeasurementSpan): RetainedCallSummary => {\n const cached = summaries.get(span.id)\n if (cached) return cached\n if (visiting.has(span.id)) return emptyRetainedCallSummary()\n visiting.add(span.id)\n\n const descendants = emptyRetainedCallSummary()\n for (const child of childrenById.get(span.id) ?? []) {\n const childDescendants = visit(child)\n if (!aggregateIds.has(child.id)) addRetainedCall(descendants, child)\n addRetainedCallSummary(descendants, childDescendants)\n }\n\n if (\n descendants.callCount > 0 &&\n (!span.modelCall || hasCompatibleDescendantMeasurements(span, descendants))\n ) {\n aggregateIds.add(span.id)\n }\n\n visiting.delete(span.id)\n summaries.set(span.id, descendants)\n return descendants\n }\n\n for (const candidate of candidates) visit(candidate)\n return aggregateIds\n}\n\nfunction emptyRetainedCallSummary(): RetainedCallSummary {\n return {\n callCount: 0,\n measurements: EXECUTION_MEASUREMENT_KEY_GROUPS.map(() => ({\n total: 0,\n reportingCalls: 0,\n })),\n }\n}\n\nfunction addRetainedCall(summary: RetainedCallSummary, span: ExecutionMeasurementSpan): void {\n summary.callCount += 1\n for (let index = 0; index < EXECUTION_MEASUREMENT_KEY_GROUPS.length; index += 1) {\n const value = readNumber(span.attributes, EXECUTION_MEASUREMENT_KEY_GROUPS[index]!)\n if (value === undefined) continue\n const measurement = summary.measurements[index]!\n measurement.total += value\n measurement.reportingCalls += 1\n }\n}\n\nfunction addRetainedCallSummary(target: RetainedCallSummary, source: RetainedCallSummary): void {\n target.callCount += source.callCount\n for (let index = 0; index < target.measurements.length; index += 1) {\n const measurement = target.measurements[index]!\n const sourceMeasurement = source.measurements[index]!\n measurement.total += sourceMeasurement.total\n measurement.reportingCalls += sourceMeasurement.reportingCalls\n }\n}\n\nfunction hasCompatibleDescendantMeasurements(\n span: ExecutionMeasurementSpan,\n descendants: RetainedCallSummary,\n): boolean {\n let parentMeasurements = 0\n let descendantMeasurements = 0\n for (let index = 0; index < EXECUTION_MEASUREMENT_KEY_GROUPS.length; index += 1) {\n const keys = EXECUTION_MEASUREMENT_KEY_GROUPS[index]!\n const parentValue = readNumber(span.attributes, keys)\n const measurement = descendants.measurements[index]!\n if (parentValue !== undefined) parentMeasurements += 1\n if (measurement.reportingCalls > 0) descendantMeasurements += 1\n if (parentValue === undefined || measurement.reportingCalls === 0) continue\n if (measurement.reportingCalls !== descendants.callCount) continue\n if (Math.abs(parentValue - measurement.total) > 1e-12) return false\n }\n return parentMeasurements === 0 || descendantMeasurements > 0\n}\n\nfunction ancestorIds(\n span: ExecutionMeasurementSpan,\n byId: Map<string, ExecutionMeasurementSpan>,\n): string[] {\n const ids: string[] = []\n const seen = new Set<string>()\n let parentId = span.parentId\n while (parentId && !seen.has(parentId)) {\n ids.push(parentId)\n seen.add(parentId)\n parentId = byId.get(parentId)?.parentId\n }\n return ids\n}\n\nfunction nearestCandidateParent(\n span: ExecutionMeasurementSpan,\n byId: Map<string, ExecutionMeasurementSpan>,\n candidateIds: Set<string>,\n): string | undefined {\n const seen = new Set<string>()\n let parentId = span.parentId\n while (parentId && !seen.has(parentId)) {\n if (candidateIds.has(parentId)) return parentId\n seen.add(parentId)\n parentId = byId.get(parentId)?.parentId\n }\n return undefined\n}\n\nfunction readNumber(\n attributes: Record<string, unknown>,\n keys: readonly string[],\n): number | undefined {\n for (const key of keys) {\n const value = attributes[key]\n const parsed =\n typeof value === 'number'\n ? value\n : typeof value === 'string' && value.length > 0\n ? Number(value)\n : Number.NaN\n if (Number.isFinite(parsed) && parsed >= 0) return parsed\n }\n return undefined\n}\n","import { ValidationError } from '../errors'\nimport { FAILURE_CLASSES, type FailureClass } from './schema'\n\nconst TASK_FAILURE_CLASS_ATTR = 'tangle.task.failure_class'\nconst TASK_FAILURE_MODE_ATTR = 'tangle.task.failure_mode'\n\ninterface AttributeCarrier {\n attributes: Record<string, unknown>\n}\n\nexport type TaskFailureLabels =\n | { failureClass?: undefined; failureMode?: undefined }\n | { failureClass: 'success'; failureMode?: undefined }\n | { failureClass: Exclude<FailureClass, 'success'>; failureMode?: string }\n\nexport function readTaskFailureLabels(\n roots: readonly AttributeCarrier[],\n context: string,\n): TaskFailureLabels {\n const failureClass = readConsistentRootString(roots, TASK_FAILURE_CLASS_ATTR, context)\n const failureMode = readConsistentRootString(roots, TASK_FAILURE_MODE_ATTR, context)\n\n if (failureClass !== undefined && !FAILURE_CLASSES.includes(failureClass as FailureClass)) {\n throw new ValidationError(\n `${context}: ${TASK_FAILURE_CLASS_ATTR} must be one of ${FAILURE_CLASSES.join(', ')}`,\n )\n }\n if (failureMode !== undefined && (failureClass === undefined || failureClass === 'success')) {\n throw new ValidationError(\n `${context}: ${TASK_FAILURE_MODE_ATTR} requires a non-success ${TASK_FAILURE_CLASS_ATTR}`,\n )\n }\n\n if (failureClass === undefined) return {}\n if (failureClass === 'success') return { failureClass }\n return {\n failureClass: failureClass as Exclude<FailureClass, 'success'>,\n ...(failureMode ? { failureMode } : {}),\n }\n}\n\nfunction readConsistentRootString(\n roots: readonly AttributeCarrier[],\n key: string,\n context: string,\n): string | undefined {\n const values = new Set<string>()\n for (const root of roots) {\n if (!Object.hasOwn(root.attributes, key)) continue\n const value = root.attributes[key]\n if (typeof value !== 'string' || value.trim().length === 0) {\n throw new ValidationError(`${context}: ${key} must be a non-empty string`)\n }\n values.add(value)\n }\n\n if (values.size > 1) {\n throw new ValidationError(\n `${context}: conflicting ${key} values: ${[...values].sort().join(', ')}`,\n )\n }\n return values.values().next().value\n}\n"],"mappings":";;;;;;;;;AA0BA,SAAgB,qBAAqB,SAAyD;CAC5F,MAAM,uBAAO,IAAI,IAA8B;CAC/C,KAAK,MAAM,UAAU,SAAS;EAC5B,IAAI,KAAK,IAAI,OAAO,EAAE,GACpB,MAAM,IAAI,MAAM,4CAA4C,OAAO,GAAG,EAAE;EAE1E,KAAK,IAAI,OAAO,IAAI,MAAM;CAC5B;CAEA,MAAM,6BAAa,IAAI,IAAY;CACnC,KAAK,MAAM,UAAU,SAAS;EAC5B,IAAI,CAAC,OAAO,OAAO;EACnB,MAAM,0BAAU,IAAI,IAAY;EAChC,IAAI,WAAW,OAAO;EACtB,OAAO,YAAY,CAAC,QAAQ,IAAI,QAAQ,GAAG;GACzC,QAAQ,IAAI,QAAQ;GACpB,MAAM,SAAS,KAAK,IAAI,QAAQ;GAChC,IAAI,CAAC,QAAQ;GACb,IAAI,OAAO,OAAO,WAAW,IAAI,OAAO,EAAE;GAC1C,WAAW,OAAO;EACpB;CACF;CAEA,MAAM,UAA6B;EACjC,OAAO;EACP,WAAW;EACX,SAAS;EACT,WAAW;EACX,YAAY;EACZ,YAAY;EACZ,cAAc;CAChB;CAEA,KAAK,MAAM,UAAU,SAAS;EAC5B,IAAI,CAAC,OAAO,OAAO;EACnB,QAAQ,SAAS;EACjB,IAA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EnF,IAAI,iBAAiB,KAAA,KAAa,CAAC,gBAAgB,SAAS,YAA4B,GACtF,MAAM,IAAI,gBACR,GAAG,QAAQ,IAAI,wBAAwB,kBAAkB,gBAAgB,KAAK,IAAI,GACpF;CAEF,IAAI,gBAAgB,KAAA,MAAc,iBAAiB,KAAA,KAAa,iBAAiB,YAC/E,MAAM,IAAI,gBACR,GAAG,QAAQ,IAAI,uBAAuB,0BAA0B,yBAClE;CAGF,IAAI,iBAAiB,KAAA,GAAW,OAAO,CAAC;CACxC,IAAI,iBAAiB,WAAW,OAAO,EAAE,aAAa;CACtD,OAAO;EACS;EACd,GAAI,cAAc,EAAE,YAAY,IAAI,CAAC;CACvC;AACF;AAEA,SAAS,yBACP,OACA,KACA,SACoB;CACpB,MAAM,yBAAS,IAAI,IAAY;CAC/B,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,CAAC,OAAO,OAAO,KAAK,YAAY,GAAG,GAAG;EAC1C,MAAM,QAAQ,KAAK,WAAW;EAC9B,IAAI,OAAO,UAAU,YAAY,MAAM,KAAK,CAAC,CAAC,WAAW,GACvD,MAAM,IAAI,gBAAgB,GAAG,QAAQ,IAAI,IAAI,4BAA4B;EAE3E,OAAO,IAAI,KAAK;CAClB;CAEA,IAAI,OAAO,OAAO,GAChB,MAAM,IAAI,gBACR,GAAG,QAAQ,gBAAgB,IAAI,WAAW,CAAC,GAAG,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,GACxE;CAEF,OAAO,OAAO,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC;AAChC"}
|
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
//#region src/supervisor-run/source-facts.ts
|
|
2
|
+
function asRecord(v) {
|
|
3
|
+
return typeof v === "object" && v !== null ? v : {};
|
|
4
|
+
}
|
|
5
|
+
function num(v) {
|
|
6
|
+
return typeof v === "number" && Number.isFinite(v) ? v : 0;
|
|
7
|
+
}
|
|
8
|
+
function readSpend(v) {
|
|
9
|
+
const rec = asRecord(v);
|
|
10
|
+
const tok = asRecord(rec.tokens);
|
|
11
|
+
const cacheRead = tok.cacheRead ?? tok.cache_read;
|
|
12
|
+
const cacheWrite = tok.cacheWrite ?? tok.cache_write;
|
|
13
|
+
return {
|
|
14
|
+
tokens: {
|
|
15
|
+
input: num(tok.input),
|
|
16
|
+
output: num(tok.output),
|
|
17
|
+
cacheRead: num(cacheRead),
|
|
18
|
+
cacheWrite: num(cacheWrite),
|
|
19
|
+
hasCache: cacheRead !== void 0 || cacheWrite !== void 0,
|
|
20
|
+
breakdownKnown: tok.cacheBreakdownKnown !== false
|
|
21
|
+
},
|
|
22
|
+
tokensKnown: rec.tokensKnown !== false,
|
|
23
|
+
usd: num(rec.usd),
|
|
24
|
+
usdKnown: rec.usdKnown !== false
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function parseJsonl(text) {
|
|
28
|
+
return parseJsonlWithDiagnostics(text).rows;
|
|
29
|
+
}
|
|
30
|
+
function parseJsonlWithDiagnostics(text) {
|
|
31
|
+
if (text === null) return {
|
|
32
|
+
rows: [],
|
|
33
|
+
invalidRows: 0
|
|
34
|
+
};
|
|
35
|
+
const out = [];
|
|
36
|
+
let invalidRows = 0;
|
|
37
|
+
for (const line of text.split("\n")) {
|
|
38
|
+
const trimmed = line.trim();
|
|
39
|
+
if (!trimmed) continue;
|
|
40
|
+
try {
|
|
41
|
+
const parsed = JSON.parse(trimmed);
|
|
42
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) out.push(parsed);
|
|
43
|
+
else invalidRows += 1;
|
|
44
|
+
} catch {
|
|
45
|
+
invalidRows += 1;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
rows: out,
|
|
50
|
+
invalidRows
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function parseJson(text) {
|
|
54
|
+
if (text === null) return null;
|
|
55
|
+
try {
|
|
56
|
+
const parsed = JSON.parse(text);
|
|
57
|
+
return typeof parsed === "object" && parsed !== null ? parsed : null;
|
|
58
|
+
} catch {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function ms(at) {
|
|
63
|
+
if (typeof at !== "string") return null;
|
|
64
|
+
const t = Date.parse(at);
|
|
65
|
+
return Number.isFinite(t) ? t : null;
|
|
66
|
+
}
|
|
67
|
+
function readVerdict(v) {
|
|
68
|
+
if (typeof v === "string") return {
|
|
69
|
+
label: v,
|
|
70
|
+
valid: null,
|
|
71
|
+
score: null,
|
|
72
|
+
raw: v
|
|
73
|
+
};
|
|
74
|
+
if (typeof v !== "object" || v === null) return {
|
|
75
|
+
label: null,
|
|
76
|
+
valid: null,
|
|
77
|
+
score: null,
|
|
78
|
+
raw: null
|
|
79
|
+
};
|
|
80
|
+
const rec = v;
|
|
81
|
+
const valid = typeof rec.valid === "boolean" ? rec.valid : null;
|
|
82
|
+
return {
|
|
83
|
+
label: valid === null ? null : valid ? "valid" : "invalid",
|
|
84
|
+
valid,
|
|
85
|
+
score: typeof rec.score === "number" && Number.isFinite(rec.score) ? rec.score : null,
|
|
86
|
+
raw: v
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function workerSourceKey(worker) {
|
|
90
|
+
return worker.workerId ?? worker.label;
|
|
91
|
+
}
|
|
92
|
+
/** Event kinds this parser folds into the tree. */
|
|
93
|
+
const TREE_EVENT_KINDS = [
|
|
94
|
+
"spawned",
|
|
95
|
+
"settled",
|
|
96
|
+
"cancelled",
|
|
97
|
+
"metered"
|
|
98
|
+
];
|
|
99
|
+
/**
|
|
100
|
+
* Event kinds `agent-runtime` journals that this parser recognizes but does not model as
|
|
101
|
+
* tree nodes: `waiting` arms a wait node and `woken` settles it. They are counted by kind
|
|
102
|
+
* rather than dropped, so "understood, not modeled" can never be mistaken for "absent".
|
|
103
|
+
*/
|
|
104
|
+
const UNMODELLED_EVENT_KINDS = ["waiting", "woken"];
|
|
105
|
+
function treeEventKind(value) {
|
|
106
|
+
return TREE_EVENT_KINDS.includes(value) ? value : null;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Classify one parsed journal row. Every row lands in exactly one outcome — interpreted,
|
|
110
|
+
* recognized-but-not-modeled, or unreadable — because a row that falls through silently is
|
|
111
|
+
* how a run with events reads as a run with none.
|
|
112
|
+
*/
|
|
113
|
+
function readJournalRow(row) {
|
|
114
|
+
const kind = row.kind;
|
|
115
|
+
if (typeof kind !== "string") return { outcome: "unreadable" };
|
|
116
|
+
if (kind === "begin" && typeof row.root === "string") return {
|
|
117
|
+
outcome: "ignored",
|
|
118
|
+
dialect: "runtime-envelope",
|
|
119
|
+
kind: "begin"
|
|
120
|
+
};
|
|
121
|
+
if (kind === "event") {
|
|
122
|
+
const inner = row.event;
|
|
123
|
+
if (typeof inner !== "object" || inner === null || Array.isArray(inner)) return { outcome: "unreadable" };
|
|
124
|
+
const innerKind = inner.kind;
|
|
125
|
+
if (typeof innerKind !== "string") return { outcome: "unreadable" };
|
|
126
|
+
const tree = treeEventKind(innerKind);
|
|
127
|
+
if (tree !== null) return {
|
|
128
|
+
outcome: "event",
|
|
129
|
+
dialect: "runtime-envelope",
|
|
130
|
+
kind: tree,
|
|
131
|
+
event: inner
|
|
132
|
+
};
|
|
133
|
+
return {
|
|
134
|
+
outcome: "ignored",
|
|
135
|
+
dialect: "runtime-envelope",
|
|
136
|
+
kind: innerKind
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const tree = treeEventKind(kind);
|
|
140
|
+
if (tree !== null) return {
|
|
141
|
+
outcome: "event",
|
|
142
|
+
dialect: "flat",
|
|
143
|
+
kind: tree,
|
|
144
|
+
event: row
|
|
145
|
+
};
|
|
146
|
+
if (UNMODELLED_EVENT_KINDS.includes(kind)) return {
|
|
147
|
+
outcome: "ignored",
|
|
148
|
+
dialect: "flat",
|
|
149
|
+
kind
|
|
150
|
+
};
|
|
151
|
+
return { outcome: "unreadable" };
|
|
152
|
+
}
|
|
153
|
+
function summarizeDialect(seen) {
|
|
154
|
+
if (seen.size === 0) return "none";
|
|
155
|
+
if (seen.size > 1) return "mixed";
|
|
156
|
+
return seen.has("runtime-envelope") ? "runtime-envelope" : "flat";
|
|
157
|
+
}
|
|
158
|
+
function parseSupervisorTree(src) {
|
|
159
|
+
const parsedJournal = parseJsonlWithDiagnostics(src.journal);
|
|
160
|
+
const events = parsedJournal.rows;
|
|
161
|
+
const state = parseJson(src.state);
|
|
162
|
+
const spawns = [];
|
|
163
|
+
const closes = [];
|
|
164
|
+
let brainIn = 0;
|
|
165
|
+
let brainOut = 0;
|
|
166
|
+
let brainCacheRead = 0;
|
|
167
|
+
let brainCacheWrite = 0;
|
|
168
|
+
let brainHasCache = false;
|
|
169
|
+
let brainCacheBreakdownKnown = true;
|
|
170
|
+
let brainTokensKnownCount = 0;
|
|
171
|
+
let brainTokensUnknownCount = 0;
|
|
172
|
+
let brainUsd = 0;
|
|
173
|
+
let brainUsdKnownCount = 0;
|
|
174
|
+
let brainUsdUnknownCount = 0;
|
|
175
|
+
let meteredCount = 0;
|
|
176
|
+
let rootId = null;
|
|
177
|
+
let unreadableRows = 0;
|
|
178
|
+
const ignoredByKind = /* @__PURE__ */ new Map();
|
|
179
|
+
const dialectsSeen = /* @__PURE__ */ new Set();
|
|
180
|
+
const meteredRows = [];
|
|
181
|
+
for (const [sourceRow, row] of events.entries()) {
|
|
182
|
+
const reading = readJournalRow(row);
|
|
183
|
+
if (reading.outcome === "unreadable") {
|
|
184
|
+
unreadableRows += 1;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
dialectsSeen.add(reading.dialect);
|
|
188
|
+
if (reading.outcome === "ignored") {
|
|
189
|
+
ignoredByKind.set(reading.kind, (ignoredByKind.get(reading.kind) ?? 0) + 1);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
const { kind, event: ev } = reading;
|
|
193
|
+
const id = typeof ev.id === "string" ? ev.id : "";
|
|
194
|
+
if (kind === "spawned") {
|
|
195
|
+
const parent = typeof ev.parent === "string" && ev.parent.length > 0 ? ev.parent : null;
|
|
196
|
+
const label = typeof ev.label === "string" ? ev.label : "";
|
|
197
|
+
const invalidFields = [];
|
|
198
|
+
if (id.length === 0) invalidFields.push("id");
|
|
199
|
+
const parentOmittedForFirstRoot = ev.parent === void 0 && rootId === null;
|
|
200
|
+
if (ev.parent !== null && !parentOmittedForFirstRoot && !(typeof ev.parent === "string" && ev.parent.length > 0)) invalidFields.push("parent");
|
|
201
|
+
if (label.length === 0) invalidFields.push("label");
|
|
202
|
+
if (ev.role !== void 0 && ev.role !== "supervisor" && ev.role !== "worker") invalidFields.push("role");
|
|
203
|
+
if (ev.profileDigest !== void 0 && !(typeof ev.profileDigest === "string" && ev.profileDigest.length > 0)) invalidFields.push("profileDigest");
|
|
204
|
+
if (ev.runtime !== void 0 && !(typeof ev.runtime === "string" && ev.runtime.length > 0)) invalidFields.push("runtime");
|
|
205
|
+
const role = ev.role === "supervisor" || ev.role === "worker" ? ev.role : null;
|
|
206
|
+
const valid = invalidFields.length === 0;
|
|
207
|
+
if (valid && parent === null && rootId === null) rootId = id;
|
|
208
|
+
spawns.push({
|
|
209
|
+
sourceRow,
|
|
210
|
+
id,
|
|
211
|
+
parent,
|
|
212
|
+
label,
|
|
213
|
+
role,
|
|
214
|
+
profileDigest: typeof ev.profileDigest === "string" && ev.profileDigest.length > 0 ? ev.profileDigest : null,
|
|
215
|
+
runtime: typeof ev.runtime === "string" && ev.runtime.length > 0 ? ev.runtime : null,
|
|
216
|
+
at: ms(ev.at),
|
|
217
|
+
valid,
|
|
218
|
+
invalidFields
|
|
219
|
+
});
|
|
220
|
+
} else if (kind === "settled") {
|
|
221
|
+
const verdict = readVerdict(ev.verdict);
|
|
222
|
+
closes.push({
|
|
223
|
+
id,
|
|
224
|
+
kind: "settled",
|
|
225
|
+
status: typeof ev.status === "string" ? ev.status : null,
|
|
226
|
+
verdict: verdict.label,
|
|
227
|
+
valid: verdict.valid,
|
|
228
|
+
score: verdict.score,
|
|
229
|
+
rawVerdict: verdict.raw,
|
|
230
|
+
reason: typeof ev.reason === "string" ? ev.reason : null,
|
|
231
|
+
infra: typeof ev.infra === "boolean" ? ev.infra : null,
|
|
232
|
+
at: ms(ev.at),
|
|
233
|
+
spend: readSpend(ev.spent),
|
|
234
|
+
hasSpend: asRecord(ev.spent).tokens !== void 0
|
|
235
|
+
});
|
|
236
|
+
} else if (kind === "cancelled") closes.push({
|
|
237
|
+
id,
|
|
238
|
+
kind: "cancelled",
|
|
239
|
+
status: "cancelled",
|
|
240
|
+
verdict: typeof ev.reason === "string" ? ev.reason : null,
|
|
241
|
+
valid: null,
|
|
242
|
+
score: null,
|
|
243
|
+
rawVerdict: typeof ev.reason === "string" ? ev.reason : null,
|
|
244
|
+
reason: typeof ev.reason === "string" ? ev.reason : null,
|
|
245
|
+
infra: null,
|
|
246
|
+
at: ms(ev.at),
|
|
247
|
+
spend: {
|
|
248
|
+
tokens: {
|
|
249
|
+
input: 0,
|
|
250
|
+
output: 0,
|
|
251
|
+
cacheRead: 0,
|
|
252
|
+
cacheWrite: 0,
|
|
253
|
+
hasCache: false,
|
|
254
|
+
breakdownKnown: true
|
|
255
|
+
},
|
|
256
|
+
tokensKnown: true,
|
|
257
|
+
usd: 0,
|
|
258
|
+
usdKnown: true
|
|
259
|
+
},
|
|
260
|
+
hasSpend: false
|
|
261
|
+
});
|
|
262
|
+
else if (kind === "metered") meteredRows.push({
|
|
263
|
+
id,
|
|
264
|
+
spend: readSpend(ev.spend),
|
|
265
|
+
at: ms(ev.at)
|
|
266
|
+
});
|
|
267
|
+
else throw new Error(`unhandled journal event kind ${JSON.stringify(kind)}`);
|
|
268
|
+
}
|
|
269
|
+
for (const row of meteredRows) {
|
|
270
|
+
if (rootId === null || row.id !== rootId) continue;
|
|
271
|
+
if (row.spend.tokensKnown) {
|
|
272
|
+
brainIn += row.spend.tokens.input;
|
|
273
|
+
brainOut += row.spend.tokens.output;
|
|
274
|
+
brainCacheRead += row.spend.tokens.cacheRead;
|
|
275
|
+
brainCacheWrite += row.spend.tokens.cacheWrite;
|
|
276
|
+
brainHasCache = brainHasCache || row.spend.tokens.hasCache;
|
|
277
|
+
brainCacheBreakdownKnown = brainCacheBreakdownKnown && row.spend.tokens.breakdownKnown;
|
|
278
|
+
brainTokensKnownCount += 1;
|
|
279
|
+
} else brainTokensUnknownCount += 1;
|
|
280
|
+
if (row.spend.usdKnown) {
|
|
281
|
+
brainUsd += row.spend.usd;
|
|
282
|
+
brainUsdKnownCount += 1;
|
|
283
|
+
} else brainUsdUnknownCount += 1;
|
|
284
|
+
meteredCount += 1;
|
|
285
|
+
}
|
|
286
|
+
const workerSpawns = spawns.filter((s) => s.valid && s.id !== rootId);
|
|
287
|
+
const workerIds = new Set(workerSpawns.map((s) => s.id));
|
|
288
|
+
const workerCloses = closes.filter((c) => workerIds.has(c.id));
|
|
289
|
+
const workerLogs = /* @__PURE__ */ new Map();
|
|
290
|
+
const workerLogRows = [];
|
|
291
|
+
for (const [sourceIndex, w] of (src.workers ?? []).entries()) {
|
|
292
|
+
const facts = {
|
|
293
|
+
sourceIndex,
|
|
294
|
+
workerId: w.workerId ?? null,
|
|
295
|
+
label: w.label,
|
|
296
|
+
inboxCaptured: w.inbox !== null,
|
|
297
|
+
eventsCaptured: w.events !== null,
|
|
298
|
+
inboxInvalidRows: 0,
|
|
299
|
+
eventsInvalidRows: 0,
|
|
300
|
+
started: null,
|
|
301
|
+
finished: false,
|
|
302
|
+
finishedAt: null,
|
|
303
|
+
passed: null,
|
|
304
|
+
score: null,
|
|
305
|
+
finishedPatchBytes: null,
|
|
306
|
+
evidenceBytes: 0,
|
|
307
|
+
steersQueued: null,
|
|
308
|
+
steersDelivered: null,
|
|
309
|
+
steersQueuedUnavailable: null,
|
|
310
|
+
steersDeliveredUnavailable: null,
|
|
311
|
+
questions: 0,
|
|
312
|
+
steerRequests: [],
|
|
313
|
+
steerAcknowledgements: []
|
|
314
|
+
};
|
|
315
|
+
const parsedInbox = parseJsonlWithDiagnostics(w.inbox);
|
|
316
|
+
const parsedEvents = parseJsonlWithDiagnostics(w.events);
|
|
317
|
+
facts.inboxInvalidRows = parsedInbox.invalidRows;
|
|
318
|
+
facts.eventsInvalidRows = parsedEvents.invalidRows;
|
|
319
|
+
for (const [row, req] of parsedInbox.rows.entries()) {
|
|
320
|
+
if (typeof req.message !== "string" || req.message.trim().length === 0) continue;
|
|
321
|
+
facts.steerRequests.push({
|
|
322
|
+
requestId: typeof req.id === "string" && req.id.length > 0 ? req.id : null,
|
|
323
|
+
row
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
for (const [row, ev] of parsedEvents.rows.entries()) {
|
|
327
|
+
const kind = ev.kind;
|
|
328
|
+
if (kind === "message") {
|
|
329
|
+
if (ev.direction === "up") {
|
|
330
|
+
facts.questions += 1;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
facts.steerAcknowledgements.push({
|
|
334
|
+
requestId: typeof ev.requestId === "string" && ev.requestId.length > 0 ? ev.requestId : null,
|
|
335
|
+
delivered: typeof ev.delivered === "boolean" ? ev.delivered : null,
|
|
336
|
+
row
|
|
337
|
+
});
|
|
338
|
+
} else if (kind === "started") facts.started = ms(ev.at);
|
|
339
|
+
else if (kind === "finished") {
|
|
340
|
+
facts.finished = true;
|
|
341
|
+
facts.finishedAt = ms(ev.at);
|
|
342
|
+
facts.passed = typeof ev.passed === "boolean" ? ev.passed : null;
|
|
343
|
+
facts.score = typeof ev.score === "number" && Number.isFinite(ev.score) ? ev.score : null;
|
|
344
|
+
facts.finishedPatchBytes = typeof ev.patchBytes === "number" ? ev.patchBytes : null;
|
|
345
|
+
facts.evidenceBytes = typeof ev.evidence === "string" ? ev.evidence.length : 0;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const requestsById = /* @__PURE__ */ new Map();
|
|
349
|
+
for (const request of facts.steerRequests) {
|
|
350
|
+
if (request.requestId === null) continue;
|
|
351
|
+
requestsById.set(request.requestId, (requestsById.get(request.requestId) ?? 0) + 1);
|
|
352
|
+
}
|
|
353
|
+
const acknowledgementsById = /* @__PURE__ */ new Map();
|
|
354
|
+
for (const acknowledgement of facts.steerAcknowledgements) {
|
|
355
|
+
if (acknowledgement.requestId === null) continue;
|
|
356
|
+
const matches = acknowledgementsById.get(acknowledgement.requestId) ?? [];
|
|
357
|
+
matches.push(acknowledgement);
|
|
358
|
+
acknowledgementsById.set(acknowledgement.requestId, matches);
|
|
359
|
+
}
|
|
360
|
+
const queueProblems = [];
|
|
361
|
+
if (!facts.inboxCaptured) queueProblems.push("inbox absent");
|
|
362
|
+
if (!facts.eventsCaptured) queueProblems.push("events absent");
|
|
363
|
+
if (facts.inboxInvalidRows > 0) queueProblems.push("inbox contains malformed rows");
|
|
364
|
+
if (facts.eventsInvalidRows > 0) queueProblems.push("events contain malformed rows");
|
|
365
|
+
if (facts.steerRequests.some((request) => request.requestId === null)) queueProblems.push("queued request id missing");
|
|
366
|
+
if ([...requestsById.values()].some((count) => count > 1)) queueProblems.push("queued request id duplicated");
|
|
367
|
+
if (facts.steerAcknowledgements.some((acknowledgement) => acknowledgement.requestId === null)) queueProblems.push("acknowledgement request id missing");
|
|
368
|
+
if ([...acknowledgementsById.keys()].some((id) => !requestsById.has(id))) queueProblems.push("acknowledgement has no queued request");
|
|
369
|
+
if (queueProblems.length === 0) facts.steersQueued = requestsById.size;
|
|
370
|
+
else facts.steersQueuedUnavailable = [...new Set(queueProblems)].join("; ");
|
|
371
|
+
const deliveryProblems = [...queueProblems];
|
|
372
|
+
if ([...acknowledgementsById.values()].some((rows) => rows.length > 1)) deliveryProblems.push("acknowledgement request id duplicated");
|
|
373
|
+
if (facts.steerAcknowledgements.some((acknowledgement) => acknowledgement.delivered === null)) deliveryProblems.push("acknowledgement delivery status missing");
|
|
374
|
+
if (deliveryProblems.length === 0) facts.steersDelivered = [...requestsById.keys()].filter((id) => {
|
|
375
|
+
const acknowledgement = acknowledgementsById.get(id);
|
|
376
|
+
return acknowledgement?.length === 1 && acknowledgement[0]?.delivered === true;
|
|
377
|
+
}).length;
|
|
378
|
+
else facts.steersDeliveredUnavailable = [...new Set(deliveryProblems)].join("; ");
|
|
379
|
+
workerLogRows.push(facts);
|
|
380
|
+
workerLogs.set(workerSourceKey(w), facts);
|
|
381
|
+
}
|
|
382
|
+
const startedAt = ms(state?.startedAt) ?? spawns[0]?.at ?? null;
|
|
383
|
+
const rootClose = rootId === null ? null : closes.find((close) => close.id === rootId);
|
|
384
|
+
const completedAt = ms(state?.completedAt) ?? rootClose?.at ?? null;
|
|
385
|
+
let firstEventAt = null;
|
|
386
|
+
let lastEventAt = null;
|
|
387
|
+
const widenEventSpan = (at) => {
|
|
388
|
+
if (at === null) return;
|
|
389
|
+
if (firstEventAt === null || at < firstEventAt) firstEventAt = at;
|
|
390
|
+
if (lastEventAt === null || at > lastEventAt) lastEventAt = at;
|
|
391
|
+
};
|
|
392
|
+
for (const spawn of spawns) widenEventSpan(spawn.at);
|
|
393
|
+
for (const close of closes) widenEventSpan(close.at);
|
|
394
|
+
for (const metered of meteredRows) widenEventSpan(metered.at);
|
|
395
|
+
return {
|
|
396
|
+
rootId,
|
|
397
|
+
spawns,
|
|
398
|
+
closes,
|
|
399
|
+
workerSpawns,
|
|
400
|
+
workerCloses,
|
|
401
|
+
brain: {
|
|
402
|
+
tokensIn: brainIn,
|
|
403
|
+
tokensOut: brainOut,
|
|
404
|
+
cacheRead: brainCacheRead,
|
|
405
|
+
cacheWrite: brainCacheWrite,
|
|
406
|
+
hasCache: brainHasCache,
|
|
407
|
+
cacheBreakdownKnown: brainCacheBreakdownKnown,
|
|
408
|
+
tokensKnownCount: brainTokensKnownCount,
|
|
409
|
+
tokensUnknownCount: brainTokensUnknownCount,
|
|
410
|
+
usd: brainUsd,
|
|
411
|
+
usdKnownCount: brainUsdKnownCount,
|
|
412
|
+
usdUnknownCount: brainUsdUnknownCount,
|
|
413
|
+
meteredCount
|
|
414
|
+
},
|
|
415
|
+
workerLogs,
|
|
416
|
+
workerLogRows,
|
|
417
|
+
journalRows: events.length + parsedJournal.invalidRows,
|
|
418
|
+
journalInvalidRows: parsedJournal.invalidRows + unreadableRows,
|
|
419
|
+
journalMalformedJsonRows: parsedJournal.invalidRows,
|
|
420
|
+
journalIgnoredRowsByKind: Object.fromEntries(ignoredByKind),
|
|
421
|
+
journalMeteredRows: meteredRows.length,
|
|
422
|
+
journalDialect: summarizeDialect(dialectsSeen),
|
|
423
|
+
state,
|
|
424
|
+
startedAt,
|
|
425
|
+
completedAt,
|
|
426
|
+
firstEventAt,
|
|
427
|
+
lastEventAt
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
//#endregion
|
|
431
|
+
//#region src/supervisor-run/types.ts
|
|
432
|
+
function unavailable(reason) {
|
|
433
|
+
return { unavailable: reason };
|
|
434
|
+
}
|
|
435
|
+
function isUnavailable(v) {
|
|
436
|
+
return typeof v === "object" && v !== null && typeof v.unavailable === "string";
|
|
437
|
+
}
|
|
438
|
+
/** Render a measured scalar for the markdown/headline: `0` and `unavailable` stay distinct. */
|
|
439
|
+
function showMeasured(v) {
|
|
440
|
+
if (isUnavailable(v)) return `unavailable — ${v.unavailable}`;
|
|
441
|
+
if (v === null) return "null";
|
|
442
|
+
return String(v);
|
|
443
|
+
}
|
|
444
|
+
/** A source that carries every fact the analyzer can use. */
|
|
445
|
+
const NO_SOURCE_LIMITS = {
|
|
446
|
+
managerTokens: null,
|
|
447
|
+
workerTokens: null,
|
|
448
|
+
spendUsd: null,
|
|
449
|
+
workerVerdicts: null,
|
|
450
|
+
deliverables: null
|
|
451
|
+
};
|
|
452
|
+
const SUPERVISOR_RUN_SCHEMA = "tangle.supervisor-run@1";
|
|
453
|
+
const SUPERVISOR_RUN_ROLLUP_SCHEMA = "tangle.supervisor-run-rollup@1";
|
|
454
|
+
//#endregion
|
|
455
|
+
//#region src/supervisor-run/terminal-record.ts
|
|
456
|
+
/**
|
|
457
|
+
* The run's terminal record, read from the documents the store wrote when the
|
|
458
|
+
* run ended. Runtime's own record outranks every other source: `result.json` is
|
|
459
|
+
* the `SupervisedResult` that `supervise()` returned, verbatim, and its `kind`
|
|
460
|
+
* is the run's status. `failure.json` is the record Runtime writes when
|
|
461
|
+
* `supervise()` threw before a result landed. The control-plane-era loops
|
|
462
|
+
* documents (`state.json` `status`, `result.json` `sup_status`) stay readable
|
|
463
|
+
* as named legacy sources, so a report always says which record it read.
|
|
464
|
+
*
|
|
465
|
+
* Pure: takes already-parsed documents and returns `Measured` values. The
|
|
466
|
+
* analyzer and the rollout minter share it so a run never has two statuses.
|
|
467
|
+
*/
|
|
468
|
+
/** The reason every terminal field reads `unavailable` when no store wrote one. */
|
|
469
|
+
const NO_TERMINAL_RECORD = "no terminal record: Runtime result.json kind, Runtime failure.json, or legacy state.json / result.json status";
|
|
470
|
+
/** The status reported for a run whose directory holds Runtime's failure record and no result. */
|
|
471
|
+
const RUNTIME_FAILED_STATUS = "failed";
|
|
472
|
+
function str(value) {
|
|
473
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
474
|
+
}
|
|
475
|
+
function errorRecord(doc, source, earlierAttempt) {
|
|
476
|
+
if (typeof doc.error !== "object" || doc.error === null) return null;
|
|
477
|
+
const error = asRecord(doc.error);
|
|
478
|
+
return {
|
|
479
|
+
source,
|
|
480
|
+
name: str(error.name),
|
|
481
|
+
message: str(error.message),
|
|
482
|
+
at: str(doc.at),
|
|
483
|
+
earlierAttempt
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
function readTerminalRecord(input) {
|
|
487
|
+
const { state, result } = input;
|
|
488
|
+
const resultKind = str(result?.kind);
|
|
489
|
+
const settled = resultKind !== null && result !== null;
|
|
490
|
+
const failureRecord = input.failure === null || input.failure === void 0 ? null : errorRecord(input.failure, "runtime-failure", settled);
|
|
491
|
+
if (settled) return {
|
|
492
|
+
supStatus: resultKind,
|
|
493
|
+
supStatusSource: "runtime-result",
|
|
494
|
+
supReason: str(result.reason),
|
|
495
|
+
failure: failureRecord ?? errorRecord(result, "runtime-result", false),
|
|
496
|
+
completed: resultKind === "winner"
|
|
497
|
+
};
|
|
498
|
+
if (failureRecord !== null) return {
|
|
499
|
+
supStatus: RUNTIME_FAILED_STATUS,
|
|
500
|
+
supStatusSource: "runtime-failure",
|
|
501
|
+
supReason: null,
|
|
502
|
+
failure: failureRecord,
|
|
503
|
+
completed: false
|
|
504
|
+
};
|
|
505
|
+
if (input.failure !== null && input.failure !== void 0) return {
|
|
506
|
+
supStatus: RUNTIME_FAILED_STATUS,
|
|
507
|
+
supStatusSource: "runtime-failure",
|
|
508
|
+
supReason: null,
|
|
509
|
+
failure: unavailable("Runtime failure.json carries no error record"),
|
|
510
|
+
completed: false
|
|
511
|
+
};
|
|
512
|
+
const legacyStateStatus = str(state?.status);
|
|
513
|
+
if (legacyStateStatus !== null) return {
|
|
514
|
+
supStatus: legacyStateStatus,
|
|
515
|
+
supStatusSource: "legacy-state",
|
|
516
|
+
supReason: null,
|
|
517
|
+
failure: unavailable("legacy state.json records no failure document"),
|
|
518
|
+
completed: legacyStateStatus === "completed"
|
|
519
|
+
};
|
|
520
|
+
const legacyResultStatus = str(result?.sup_status);
|
|
521
|
+
if (legacyResultStatus !== null) return {
|
|
522
|
+
supStatus: legacyResultStatus,
|
|
523
|
+
supStatusSource: "legacy-result",
|
|
524
|
+
supReason: null,
|
|
525
|
+
failure: unavailable("legacy result.json records no failure document"),
|
|
526
|
+
completed: legacyResultStatus === "completed"
|
|
527
|
+
};
|
|
528
|
+
return {
|
|
529
|
+
supStatus: unavailable(NO_TERMINAL_RECORD),
|
|
530
|
+
supStatusSource: unavailable(NO_TERMINAL_RECORD),
|
|
531
|
+
supReason: unavailable(NO_TERMINAL_RECORD),
|
|
532
|
+
failure: unavailable(NO_TERMINAL_RECORD),
|
|
533
|
+
completed: null
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
//#endregion
|
|
537
|
+
export { SUPERVISOR_RUN_ROLLUP_SCHEMA as a, showMeasured as c, parseJson as d, parseJsonl as f, NO_SOURCE_LIMITS as i, unavailable as l, workerSourceKey as m, RUNTIME_FAILED_STATUS as n, SUPERVISOR_RUN_SCHEMA as o, parseSupervisorTree as p, readTerminalRecord as r, isUnavailable as s, NO_TERMINAL_RECORD as t, asRecord as u };
|
|
538
|
+
|
|
539
|
+
//# sourceMappingURL=terminal-record-Ce9_UjRz.js.map
|