Skip to content

Fix find_last_user_message_index skipping skill content injections#21119

Merged
alkispoly-db merged 1 commit intomlflow:masterfrom
alkispoly-db:mlflow-cc-tracing-bug
Feb 27, 2026
Merged

Fix find_last_user_message_index skipping skill content injections#21119
alkispoly-db merged 1 commit intomlflow:masterfrom
alkispoly-db:mlflow-cc-tracing-bug

Conversation

@alkispoly-db
Copy link
Collaborator

Related Issues/PRs

#xxx

What changes are proposed in this pull request?

find_last_user_message_index() incorrectly identifies skill content injection messages as the last user prompt. When Claude Code invokes a skill, the transcript contains a user message with the full skill instructions that passes all existing filters (no toolUseResult, content type is text, not empty). The trace input then shows thousands of characters of skill text instead of the actual user prompt.

This PR adds a check that detects skill content injections by inspecting the previous transcript entry. If the previous entry is a skill tool result (a user message with toolUseResult containing commandName), the current entry is skipped.

How is this PR tested?

  • New unit/integration tests

Three new tests for find_last_user_message_index:

  • test_find_last_user_message_skips_skill_injection — single skill invocation, verifies the function returns the actual user prompt
  • test_find_last_user_message_index_basic — normal multi-turn conversation without skills (no false positives)
  • test_find_last_user_message_skips_consecutive_skill_injections — two back-to-back skill invocations, verifies both injections are skipped

Does this PR require documentation update?

  • No. You can skip the rest of this section.

Does this PR require updating the MLflow Skills repository?

  • No. You can skip the rest of this section.

Release Notes

Is this a user-facing change?

  • Yes. Give a description of this change to be included in the release notes for MLflow users.

Fix Claude Code tracing to correctly identify the user prompt when skills are invoked, instead of capturing skill injection content as the trace input.

What component(s), interfaces, languages, and integrations does this PR affect?

Components

  • area/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionality

How should the PR be classified in the release notes? Choose one:

  • rn/bug-fix - A user-facing bug fix worth mentioning in the release notes

Should this PR be included in the next patch release?

  • Yes (this PR will be cherry-picked and included in the next patch release)
  • No (this PR will be included in the next minor release)

🤖 Generated with Claude Code

@github-actions github-actions bot added the size/L Large PR (200-499 LoC) label Feb 25, 2026
@github-actions
Copy link
Contributor

🛠 DevTools 🛠

Install mlflow from this PR

# mlflow
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/21119/merge
# mlflow-skinny
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/21119/merge#subdirectory=libs/skinny

For Databricks, use the following command:

%sh curl -LsSf https://raw.githubusercontent.com/mlflow/mlflow/HEAD/dev/install-skinny.sh | sh -s pull/21119/merge

@github-actions github-actions bot added area/tracing MLflow Tracing and its integrations rn/bug-fix Mention under Bug Fixes in Changelogs. v3.10.1 labels Feb 25, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 25, 2026

Documentation preview for 7b45a6c is available at:

More info
  • Ignore this comment if this PR does not change the documentation.
  • The preview is updated when a new commit is pushed to this PR.
  • This comment was created by this workflow run.
  • The documentation was built by this workflow run.

Copy link
Collaborator

@smoorjani smoorjani left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -222,6 +222,15 @@ def find_last_user_message_index(transcript: list[dict[str, Any]]) -> int | None
for i in range(len(transcript) - 1, -1, -1):
entry = transcript[i]
if entry.get(MESSAGE_FIELD_TYPE) == MESSAGE_TYPE_USER and not entry.get("toolUseResult"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

tiny nit: let's move toolUseResult (and maybe commandName) to constants

When Claude Code invokes a skill, the transcript contains a skill
content injection — a user message with text content that immediately
follows the skill tool result. This message passes all existing filters
in `find_last_user_message_index()`, causing the trace input to show
thousands of characters of skill text instead of the actual user prompt.

Detect and skip these injections by checking whether the previous
transcript entry is a skill tool result (a user message with
`toolUseResult` containing `commandName`).

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Alkis Polyzotis <alkis.polyzotis@databricks.com>
Copy link
Collaborator

@dbczumar dbczumar left a comment

Choose a reason for hiding this comment

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

LGTM

@alkispoly-db alkispoly-db added this pull request to the merge queue Feb 27, 2026
Merged via the queue into mlflow:master with commit 68353d2 Feb 27, 2026
50 of 52 checks passed
@alkispoly-db alkispoly-db deleted the mlflow-cc-tracing-bug branch February 27, 2026 18:16
daniellok-db pushed a commit to daniellok-db/mlflow that referenced this pull request Mar 5, 2026
…lflow#21119)

Signed-off-by: Alkis Polyzotis <alkis.polyzotis@databricks.com>
Co-authored-by: Claude <noreply@anthropic.com>
daniellok-db pushed a commit to daniellok-db/mlflow that referenced this pull request Mar 5, 2026
…lflow#21119)

Signed-off-by: Alkis Polyzotis <alkis.polyzotis@databricks.com>
Co-authored-by: Claude <noreply@anthropic.com>
daniellok-db pushed a commit that referenced this pull request Mar 5, 2026
…21119)

Signed-off-by: Alkis Polyzotis <alkis.polyzotis@databricks.com>
Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/tracing MLflow Tracing and its integrations rn/bug-fix Mention under Bug Fixes in Changelogs. size/L Large PR (200-499 LoC) v3.10.1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants