Commit Graph
2 Commits
Author SHA1 Message Date
yetoneandJuckZ c8ed37e126 sessions: each Codex response exported to Langfuse carries only its own reply and tool calls, with the turn's prompt, and a finished turn exports once (#2284, JuckZ)
JuckZ's Codex Desktop trace in Langfuse showed one reply repeated on every
later response of its turn, no prompt or tool linkage, and a completed turn
exported a second time as failed.

- token_usage_record copied t.output (the turn's last AgentMessage, a role-less
  text array) into every later response, including tool-call-only ones. Each
  generation now takes its bodies from the rollout's response_items: input is
  the base instructions (session_meta) as a system message, the turn's
  developer/user messages, and the tool results fed back since the previous
  response; output is only that response's assistant text and tool calls, in
  OpenAI chat shape with call IDs. Turn IDs fall back to the desktop's
  internal_chat_message_metadata_passthrough.turn_id, then the current turn
  (the CLI records none).
- task_complete/turn_aborted deleted the turn but left it current, so the
  following thread_settings_applied recreated it and the next task_started
  exported it again as an inferred, failed root under the same ID.
- Extension items (web search, image generation) get a span named by kind with
  query/action/prompt in and results/saved_path/failure out; FileChange gets
  its diff, ImageView its path. Never the image generation's base64 result.

Not copied from the reference: it rebuilt the whole turn history for every
response. That is quadratic, and the user's real rollouts carry 2-3MB
screenshots in tool outputs and 100-400KB data-URL images in prompts, which
it would repeat on each response. Here inline images in a prompt or fed-back
result are named ("[image image/png, N bytes not exported]"); the tool's own
span keeps the output as recorded. Siblings: Claude, Pi/omp, Gemini and
OpenCode already give each response its own message's content; the reused
output and the recreated root were Codex-only.

Fixture: internal/sessions/testdata/traces/codex-desktop-sanitized.jsonl is
JuckZ's file byte for byte (cmp against d96139c2), described in the README.

Run (worktree on origin/main 95e7c6bcc, sandbox HOME):
- go test ./internal/sessions -run 'Codex|Trace'; -race -count=20 -run Codex
- end to end through sessions.TraceReader.Poll + otlp.sessionRecord on the
  fixture: 2 roots, 28 generations, system+developer+user in, own reply out
- gofmt -l; go vet ./... (darwin), GOOS=windows, GOOS=linux -tags nogui
- go test -count=1 ./internal/sessions ./internal/otlp: ok
Full suite: SUITE_LINE

Broken by hand, each red: the original traces.go (all three new tests);
output from t.output; out not reset between responses (repeated tool call
id, 8 of 5 responses with text); data URL kept; Extension unhandled (0 of 4
web ops); current not cleared on completion (3 roots over 2 IDs); base
instructions dropped; native bodies dropped.

Not tried: a real Langfuse server, a live Codex Desktop or Windows run,
context compaction (the transcript is not reset on it), earlier turns'
context in a response's input, local_shell_call/web_search_call response
items. Masking of tool arguments and MCP result order from the reference
are left out of this commit.

Co-authored-by: JuckZ <35656100+JuckZ@users.noreply.github.com>
2026-10-15 23:08:00 +08:00
mofelee 38b4a9d984 feat: export gateway and agent conversation waterfalls to Langfuse (#581) 2026-10-03 01:43:32 +08:00