← Back to Pull requests

Show Lens plugin sessions like native Claude Code sessions #233

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 22, 2026 19:06 UTC
Author

Summary

A session recorded by a LiteLLM Lens plugin (Claude Code, Codex, OpenCode) grouped correctly into one trace, but Lens did not present it like a session recorded through Claude Code's own telemetry, which is the reference here. The trace list showed a dash for Last Output and a generic agent icon, the Steps view listed invoke_agent <agent> rows where the reference shows Turn 1/2/3 [prompt] rows with per-turn cost, and selecting a turn showed no reply.

Scope recognition. normalize/instrumentation/claude_code.rs accepts the plugin scope berriai.lens.claude-code next to the two native scopes, so plugin spans get framework = claude-code. normalize/instrumentation/opencode.rs accepts berriai.lens.opencode, so those spans get framework = opencode. Codex plugin spans already resolve to openai-codex through their codex-cli service name.

Turn rows. traces/turns.ts treated a parentless agent span as a turn only for claude-code; it now also does for openai-codex and opencode.

Last Output. It came only from claude_code.assistant_response child spans, which a plugin does not send; a plugin records the reply on the turn span itself. Migration 0033 widens the ReplyPreview default to also cover a parentless agent span, reading content from an output object or from the last message of an output array. resolve/view.rs falls back to the latest parentless agent span with a reply preview when no reply span exists under a turn.

Turn details. TurnPane.tsx showed the agent's reply only from a claude_code.assistant_response child; it now falls back to the turn span's own output. A native claude_code.interaction turn is left as it was, since that span never has output.

Design decisions

1. The fix is in Lens. The plugins are not changed to imitate the native span names.
2. The Last Output fallback is not specific to one agent: any trace whose parentless agent span carries its reply as {content} or [{role, content}, ...] gets Last Output.
3. A recorded claude_code.assistant_response still wins over a reply on the turn, in Last Output and in the turn details, so native sessions resolve as before.
4. Turn rows key on the framework, with no plugin-only marker, so they apply to any Claude Code, Codex or OpenCode trace that has parentless agent spans.
5. The worker's own turn rule in resolve/view.rs stays Claude Code only. It feeds the lookup of native reply spans; plugins get Last Output from the fallback.
6. No OpenCode logo is added. Lens has no asset for it, so OpenCode traces keep the generic icon.
7. The new column default applies to spans written after the migration. Plugin traces already stored keep a dash for Last Output.

User-facing changes

Plugin-recorded Claude Code sessions show Last Output in the trace list, the Claude logo and claude-code framework, numbered turn rows with the prompt and per-turn cost, and the reply in the turn details. Because their spans are now Claude Code spans, the Claude Code specific status and tool-failure handling in resolve/ applies to them as well.

Codex and OpenCode plugin sessions show Last Output, numbered turn rows with cost, and the reply in the turn details. OpenCode plugin traces are labelled with the opencode framework.

OpenCode 1.x telemetry traces also gain numbered turn rows, since they already carry one parentless opencode.turn agent span per prompt. Native Codex telemetry traces gain them too, from their parentless session_task.turn spans. Other traces with a reply on a parentless agent span gain a Last Output value where they showed a dash.

Testing

cargo test -p litellm-traces --test normalize --test normalization_formats --test resolve passes, and vitest run src/components/lens/traces passes. New cases: a real Claude Code plugin export as a fixture (claude_code_plugin_session.json) normalizing to Claude Code spans, OpenCode plugin turn, model-call and tool spans normalizing to OpenCode, the last reply taken from turns that carry their own reply in either row order while a subagent's reply is ignored, a recorded reply winning over a reply on the turn, turn rows for the two added frameworks, and the turn details showing a reply recorded on the turn.

Real runs on a local Lens built from this branch behind a local LiteLLM gateway.

Claude Code 2.1.330: the same four prompts (a three-turn session resumed twice with a failed read and a subagent, plus a separate one-turn session) through the plugin and through native telemetry. Both gave two traces, 3 turns, 8 priced model calls, 5 tool steps and 1 error for the long session. The plugin traces show Last Output, the logo and Turn 1/2/3 rows with cost, matching the native ones.

OpenCode 2.3.2 with its plugin: one opencode run followed by two --continue runs gave one trace with Turn 1/2/3 [prompt] rows, per-turn cost, Last Output and the failed read marked as an error.

The migration applied on the existing local ClickHouse.

Not tested here: a Codex plugin trace on this branch (checked separately by the Codex plugin work), and a multi-node ClickHouse. Native Codex telemetry was checked in the same separate work: a real two-turn Codex 0.171.0 session has two parentless agent spans, one per prompt, and shows Turn 1 and Turn 2 with the right prompts. Two OpenCode differences from the reference remain and are on the plugin side: the Thread view repeats earlier messages before each model call, and a subagent arrives as its own trace.

<details>
<summary>Details</summary>

Link to Devin session: https://app.devin.ai/sessions/e12c28ee068b4097a18cb8f738454dd0
Open in Devin Desktop: https://app.devin.ai/desktop/session/e12c28ee068b4097a18cb8f738454dd0?variant=devin
Requested by: @kerry-berri

</details>

<!-- CURSOR_SUMMARY -->
---

[!NOTE]

Medium Risk

Touches trace normalization, ClickHouse column defaults, and trace summary resolution—data shown in the trace list and turn UI—but changes are additive with native reply behavior preserved and migration only affecting new writes.

> Overview

Lens now treats LiteLLM Lens plugin sessions (Claude Code, Codex, OpenCode) like native Claude Code sessions in the UI and trace pipeline.

> Ingestion / normalization recognizes plugin OTLP scopes (berriai.lens.claude-code, berriai.lens.opencode) so spans get the right framework and agent labels.

> Turn grouping in the Steps view keys off claude-code, openai-codex, and opencode parentless agent spans, not only native Claude Code telemetry.

> Last Output no longer depends solely on claude_code.assistant_response children: ClickHouse ReplyPreview defaults also read reply text from parentless agent span output, and trace resolution falls back to the latest such span when no reply child exists (recorded reply spans still win).

> Turn details show the agent answer from the turn span’s own output when plugins store the reply there, while native claude_code.interaction turns keep using the child reply span.

> Tests and fixtures cover plugin normalization, reply fallback ordering, and UI turn/reply behavior.

> <sup>Reviewed by Cursor Bugbot for commit 72067a9616b2580edf7c95d55094e2fb64735033. Bugbot is set up for automated code reviews on this repo. Configure here.</sup>

<!-- /CURSOR_SUMMARY -->

Diff: 650 lines (+487 / -163) across 8 files Reviewer: cursor[bot] Review duration: 34m
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.57) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
0.57
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.388
Shallow Review Depth shallow_review_depth
0.344
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #233"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 57% (MEDIUM) · Higher = larger blast radius
57%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 30.4% · Safe to merge
30.4%
Repository