Repository navigation
feat(#126): trace research/dev runs and record code-gen model, usage and cost - #163
Conversation
sugat009
left a comment
There was a problem hiding this comment.
Thank you. The tracing and the shared CLI parser work well. No item blocks the merge.
Please merge #162 into this branch after #162 takes its suggestions. The #162 docs fix also corrects docs/observability.md:238-239 here.
Known gaps in the description:
- Gap 2 is not correct for CLI 2.1.281. A max-turns stop is ERROR. See
cli-envelope.ts:91. - Please add one gap: a CLI
is_erroron the provider path records no spend. Seeclaude-cli.ts:318.
CI is green. With all the suggestions applied, 1050 tests pass locally.
sugat009
left a comment
There was a problem hiding this comment.
Thank you. All 7 round-1 points are fixed. The failed-call spend is now fixed in code, not only listed as a gap. I checked each point on b4c08a0. Local gates pass with 1055 tests. The CI test job did not run on this head.
Please merge feat/langfuse-v4-migration (012d77e) into this branch, and then I will approve. My trial merge conflicts in two places only:
docs/observability.md: take #162's Delivery Semantics paragraph, and keep your warning-label sentence.test/observability/index.spec.ts: keep both new tests.
The merged tree passes all gates with 1057 tests. Also, the PR description still says "Handles the newer JSON array output" and "1047 tests passing".
The inline comments are non-blocking.
b4c08a0 to
2b093f9
Compare
2b093f9 to
a4590e4
Compare
- Trace research and development supervisor runs with per-step observations - Emit code-gen generations (CLI plan/execute/relaxed, API plan/file/continuation) under generate-code via observeActiveGeneration, with real model, usage and cost - Parse the CLI JSON array transcript (shared cli-envelope) and report the costliest model and summed usage from modelUsage - Carry modelUsed, tokensUsed and costUsd from the code-gen module through CodeGenerationAgent into the generate-code output and console summary
…rsing Select the latest result message and map an error result's errors list into result. Only lines that open JSON count as block starts, so long bracketed logs parse fast.
The provider now throws LLMCallError carrying the reported response, and traced generations copy its spend. Adds tracing tests for both code-gen modules.
a4590e4 to
cdc5ca4
Compare
sugat009
left a comment
There was a problem hiding this comment.
Approved. Thanks for the rebase. It covers my request: #163 now holds #162's head, so there is nothing to unstack. I reviewed #163 as the whole stack. All my comments are resolved, and CI is green.
suggestion (non-blocking): .env.example:66-67 sets the placeholder keys pk-lf-... and sk-lf-.... A developer who copies the file turns tracing on with invalid keys, and each local run then sends its prompts to cloud.langfuse.com. Please comment out the two lines, and change the comment above them to say that tracing stays off until both keys are set. These lines come from #127, so a follow-up is fine.
Description
Top of the #127 → #162 → #163 stack. It is rebased on the approved #162 (Langfuse v4 migration), and its diff here is the nine commits on top of #162.
Research and development tracing
Code-gen generations in Langfuse
generate-code, carrying the model that actually ran, token usage (including cache tokens), and cost where the path reports it.claude-code-cli:code-gen-plan,code-gen-execute,code-gen-execute-relaxedclaude-api:code-gen-plan,code-gen-file,code-gen-continuationis_errormarks the generation, and the trace, as ERROR.is_error, CLI or API output that is not valid JSON, and JSON that fails the triage/distill schema.observeActiveGenerationhelper attaches a generation to whatever step is running and records nothing outside a trace.CLI output parsing (shared
src/llm/cli-envelope.ts)--verboseor theverbosesetting.errorslist as the result text for error results such aserror_max_turns.modelUsageand sums usage across all models.Cost on the code-gen result
modelUsed,tokensUsedandcostUsd(new onCodeGenModuleOutput) are passed from the module throughCodeGenerationAgent.generate-codeoutput and on a new console summary line.Verification
generate-code,claude-opus-5-5, 81.2k tokens, $0.56, included in the trace total.Known gaps
is_erroris marked partial on the module result, and its generation is not ERROR. A real max-turns stop (error_max_turns,is_error: true) is ERROR.opencodeis still a stub with no LLM calls to trace.#126
Code review checklist
License
The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.