Fix duplicate DOM ids in chat_ui tool-call partials#802
Conversation
The chat_ui tool-call partial was rendered once per tool call used the parent message id, which caused duplicated ids when a single assistant message contained multiple tool calls (when parellel tool calling happens). Use tool_call.id as the element id source so each rendered tool-call row has a unique id. Also update id prefixes to keep tool_call and tool_result ids distinct from message ids.
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #802 +/- ##
==========================================
+ Coverage 88.47% 88.48% +0.01%
==========================================
Files 122 122
Lines 5898 5898
Branches 1405 1405
==========================================
+ Hits 5218 5219 +1
+ Misses 680 679 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
crmne
left a comment
There was a problem hiding this comment.
This fixes the default chat_ui templates, but the Tailwind template for custom tool partials still uses the parent message id:
lib/generators/ruby_llm/tool/templates/tailwind/tool_call.html.erb.tt
id="message_<%= message.id %>"Because ruby_llm:tool uses this when --ui=tailwind, and also via --ui=auto in Tailwind apps, custom tool-call partials can still generate duplicate DOM ids for parallel tool calls. Could you update this one to use tool_call.id as well, e.g. message_tool_call_<%= tool_call.id %>?
What this does
Fix #804
When an assistant message has multiple tool calls, the chat_ui tool-call partial renders each one with the same id because it uses the parent message's id instead of the individual call's id. That's invalid HTML (the
idattribute must be unique in a document)The bug only surfaces with parallel tool calls (multiple calls per message). Sequential calling produces one call per message, keeping ids naturally unique.
Use tool_call.id for the element id (it's unique and already available in the partial). Namespace ids with tool_call and tool_result prefixes to keep them distinct from message ids.
Before:
After:
Type of change
Scope check
Required for new features
N/A — bug fix.
Quality check
overcommit --installand all hooks passbundle exec rspecmodels.json,aliases.json)AI-generated code
API changes