Skip to content

Update claude_desktop_parser.py - #171

Open
MaddipatlaChetan24 wants to merge 1 commit into
uber:mainfrom
MaddipatlaChetan24:patch-10
Open

MaddipatlaChetan24 wants to merge 1 commit into
uber:mainfrom
MaddipatlaChetan24:patch-10

Conversation

@MaddipatlaChetan24

Copy link
Copy Markdown
Contributor

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Related issue: N/A

What changed?

In Sensor/adr_sensor/parsers/claude_desktop_parser.py, _extract_message_data applied the single root-level tool_use_result override to every tool_result block in a user turn. The fix now only applies that override when there is exactly one tool_result block, and only when its result is non-empty.

Why?

When a turn contains more than one tool_result (parallel tool calls), the shared override overwrote every block with the same single value, discarding each tool's own distinct result and corrupting the parsed chat history. This is the same bug pattern already fixed in Detection/main_benchmark.py._extract_text_from_content, which guards the override the same way — that fix just wasn't carried over to this parser.

How did you test it?

Verified empirically with targeted reproductions calling _extract_message_data directly:

  • Two tool_result blocks + one shared tool_use_result: before the fix both blocks were overwritten with the same value; after the fix each keeps its own distinct content.
  • Single tool_result block: override still applies as intended (no regression).
  • Single block with an explicitly empty tool_use_result["result"]: real existing content is no longer discarded.

Also confirmed the file compiles (py_compile).

Potential risks

Low risk — this only narrows when the override is applied (from "always" to "only when unambiguous and non-empty"), so it can only make the recovered content more accurate, not less. No change to any other parser or to the public AgentEvent/ChatMessage schema.

This branch has not been deployed

No deployments
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.

1 participant