Skip to content

fix(tracing): keep initiating /goal objective as turn input when user messages arrive mid-turn - #113

Open
deepanshupal wants to merge 2 commits into
langfuse:mainfrom
deepanshupal:fix-goal-turn-input-attribution
Open

deepanshupal wants to merge 2 commits into
langfuse:mainfrom
deepanshupal:fix-goal-turn-input-attribution

Conversation

@deepanshupal

Copy link
Copy Markdown

Fixes #110.

Root cause

A turn started by /goal receives its objective as a response_item user message wrapping <codex_internal_context source="goal">, which becomes userInputFallback. A user message sent while that turn is still running arrives as item_completed / UserMessage and sets userInput, and finishTurn() prefers userInput over the fallback - so the later in-flight message replaced the initiating goal as the root input.

Behavior change (both sides)

  • Fixed: the initiating input now wins for the whole turn. A user message that arrives mid-turn (via user_message or item_completed/UserMessage) no longer displaces an input already captured from either channel, so a goal-started turn keeps its goal as the root input and later messages stay distinguishable instead of replacing it.
  • Changed presentation: for a goal-started turn, the root input is now the <objective> text extracted from the <codex_internal_context source="goal"> wrapper, rather than the raw internal wrapper.

The deliberate "structured UserMessage rescues the prompt from an AGENTS.md-wrapped fallback" behavior is unchanged: in those cases the fallback is rejected (unset), so the gate does not engage, and that existing test suite passes unmodified.

Testing

New parse-goal-attribution.test.ts with the issue's synthetic fixture, covering a goal-started turn with and without a subsequent progress message, plus a guard that the raw wrapper is never exposed as input. On pristine main the first two tests fail (input = "What is the progress?", and the raw wrapper respectively); with the fix all three pass.

Full suite: 124/124 pass (pnpm run build && vitest run; the 3 hook-command tests fail without a prior build on a fresh checkout, on pristine main too - they execute the bundled hook). tsc --noEmit clean, prettier --check clean.

@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.

Bug: /goal turn input is replaced by a later in-flight user message

1 participant