Skip to content

Commit 3cd2aa8

Browse files
[MISC] Propagate line-item executor usage_records up the prompt chain (#1970)
LINE_ITEM prompts dispatch to the cloud line_item_extractor executor via `_run_line_item_extraction`, but the legacy executor's `_execute_single_prompt` returned `[]` instead of the executor's flushed usage records. The records existed in `line_item_result.metadata["usage_records"]` and were dropped on the floor, so the structure_pipeline / answer_prompt outer ExecutionResult never carried them to executor/tasks.py — and the token_usage table stayed empty for line-item prompts. Drain `line_item_result.metadata.usage_records`, return them from `_run_line_item_extraction`, and forward through the LINE_ITEM branch of `_execute_single_prompt` so they ride along with the per-prompt usage accumulator like every other prompt type. Paired with the cloud-side fix in unstract-cloud#1498 which adds the flush at the line_item / agentic_table / etc. executor side. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 993f676 commit 3cd2aa8

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

workers/executor/executors/legacy_executor.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,7 @@ def _execute_single_prompt(
17201720
return []
17211721

17221722
if output.get(PSKeys.TYPE) == PSKeys.LINE_ITEM:
1723-
self._run_line_item_extraction(
1723+
return self._run_line_item_extraction(
17241724
output=output,
17251725
context=context,
17261726
structured_output=structured_output,
@@ -1739,7 +1739,6 @@ def _execute_single_prompt(
17391739
},
17401740
shim=shim,
17411741
)
1742-
return []
17431742

17441743
usage_kwargs = {"run_id": run_id, "execution_id": execution_id}
17451744
llm, embedding, vector_db = self._init_llm_and_retrieval(
@@ -2070,7 +2069,7 @@ def _run_line_item_extraction(
20702069
metrics: dict[str, Any],
20712070
prompt_run_args: dict[str, Any],
20722071
shim: Any,
2073-
) -> None:
2072+
) -> list[dict[str, Any]]:
20742073
"""Delegate LINE_ITEM prompt to the line_item executor plugin.
20752074
20762075
``prompt_run_args`` bundles the per-prompt scalars passed from
@@ -2118,6 +2117,10 @@ def _run_line_item_extraction(
21182117
shim.stream_log(f"Running line-item extraction for: `{prompt_name}`")
21192118
line_item_result = line_item_executor.execute(line_item_ctx)
21202119

2120+
usage_records: list[dict[str, Any]] = list(
2121+
(line_item_result.metadata or {}).get("usage_records") or []
2122+
)
2123+
21212124
if line_item_result.success:
21222125
data = line_item_result.data or {}
21232126
structured_output[prompt_name] = data.get("output", "")
@@ -2143,6 +2146,7 @@ def _run_line_item_extraction(
21432146
f"Line-item extraction failed for `{prompt_name}`: {error_msg}",
21442147
level=LogLevel.ERROR,
21452148
)
2149+
return usage_records
21462150

21472151
@staticmethod
21482152
def _apply_type_conversion(

0 commit comments

Comments
 (0)