Skip to content

fix: read the user prompt from the structured item event - #54

Open
milanagm wants to merge 1 commit into
langfuse:mainfrom
milanagm:lfe-15178-trace-input-contains-the-instructions-preamble-instead-of-the-users
Open

fix: read the user prompt from the structured item event#54
milanagm wants to merge 1 commit into
langfuse:mainfrom
milanagm:lfe-15178-trace-input-contains-the-instructions-preamble-instead-of-the-users

Conversation

@milanagm

Copy link
Copy Markdown
Contributor

Fixes #47 (LFE-15178).

Problem

Both paths that resolved a turn's prompt missed on current Codex CLI versions. No user_message event is emitted any more, so the fallback took over — and that fallback accepted the first user message whose text did not start with a wrapper element. Codex concatenates the injected context into one message, so with an AGENTS.md present it starts with the AGENTS preamble, the anchored test failed, and the whole wrapper was exported as the prompt.

Fix

  • Prefer the item_completed event carrying a UserMessage item: it holds the bare prompt with no context attached.
  • In the fallback, match the wrapper elements anywhere in the text (plus the AGENTS preamble), for CLI versions that emit neither structured event.

Both changes are needed independently, as the issue notes: fixing only the fallback leaves a heuristic in the hot path that has already changed shape three times (<environment_context>, <recommended_plugins>, # AGENTS.md instructions for …).

Tests

Fixture built from a real 0.149 rollout. Two cases pin the structured path (including a prompt that merely mentions a wrapper tag, which the fallback must not rescue), one pins the fallback with the structured event removed. Verified failing without each half of the fix.

Also verified end to end against a local Langfuse instance: with an AGENTS.md in the working directory, the trace input is now the prompt (34 chars) instead of a 1177-char wrapper.

Known gap

A CLI that emits neither structured event and a prompt that mentions a wrapper tag still yields an empty input. No known version behaves that way — 0.147+ emits item_completed, older versions emitted user_message.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trace input contains the instructions preamble instead of the user's prompt (Codex CLI 0.147.0)

1 participant