Files
magpie/internal/sessions/testdata/traces/README.md
T
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

33 lines
1.8 KiB
Markdown

These fixtures were derived from real sessions supplied by the PR author:
- Pi: Niulai session `01a0fce1-4bdb-7357-909d-1fc983a98dad` (56 records).
- Codex: deer session `01a0fce4-eacb-7890-b42c-f140d51b593d` (43 records).
Record order, event types, timestamps, token counts and timing fields are
retained. Event, response, process and tool-call IDs are consistently replaced
with anonymous IDs, preserving their relationships. Only the two session IDs
above remain as fixture labels.
Prompts, replies, reasoning, tool arguments/results, command output, paths,
model/provider configuration and unknown fields are replaced with placeholders.
Account/user identifiers, instructions, signatures, encrypted reasoning,
environment/permission configuration, tool definitions, headers and URLs are
removed. Remaining string values were checked against an explicit allowlist.
These are sanitized real transcripts, not synthetic event sequences. Pi and
Codex have been tested end to end. Claude Code/Cowork, Oh My Pi, OpenCode and
Gemini CLI have format tests but are **not tested end to end** by the PR author.
## codex-desktop-sanitized.jsonl
Supplied by JuckZ with #2284, copied byte for byte. In their words:
This fixture preserves event ordering, message/content types, timing, token
usage, and native/response-item echoes from two Windows Codex desktop turns
recorded on 2026-10-14. Session/message/call IDs are consistently renamed;
instructions, user text, replies, paths, arguments, diffs, URLs, and tool results
are replaced with fixture values. No credentials or private conversation text
are included. The 28 usage records contain eight distinct recorded assistant
messages, including model responses that emit only a tool call and multi-part
user inputs whose native UI echo contains fewer parts.