feat(runtime): add agent dimension to librefang_tool_execution_seconds (#6244)#6245
Merged
Conversation
#6244) The per-tool latency histogram carried only a `tool` label, so per-tool p95 was an unweighted blend across every calling agent. The sibling `librefang_tool_call_total` counter from the same function already carries `agent` (#6226), so tool failures were attributable per agent but tool latency was not. Adds the `agent` label to the histogram, sourced from the `agent_id` already in scope and sanitized + length-capped via the same `sanitize_tool_label` used for the counter, so it now emits `{agent,tool}`. Cardinality stays bounded (agent x tool, lower than the counter's agent x tool x outcome x failure_type). Updates `test_record_tool_call_metric_emits_latency_histogram` to assert the agent label is present.
houko
enabled auto-merge (squash)
June 20, 2026 01:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #6244.
librefang_tool_execution_seconds(the per-tool latency histogram added in #6228 / #6233) carried only atoollabel, while the siblinglibrefang_tool_call_totalcounter emitted from the same function already carriesagent(#6226). So tool failures were attributable per agent but tool latency was not — on a host running many agents that share tools, the per-tool p95 was an unweighted blend across callers (a slow agent and a fast agent on the same tool were indistinguishable).Change
record_tool_call_metric(crates/librefang-runtime/src/agent_loop/tool_call.rs) now emits the histogram with{agent, tool}.agentis sourced from theagent_idalready in scope and sanitized + length-capped via the samesanitize_tool_labelused for the counter, so cardinality stays bounded — agent×tool is lower than the counter's existing agent×tool×outcome×failure_type. Doc comment and the inline comment updated to match.Verification
Updated
test_record_tool_call_metric_emits_latency_histogram(tests/utilities.rs) to assert the histogram carries theagentlabel (agent=agent) alongsidetool=histtool.cargo test -p librefang-runtimeruns in CI.Closes #6244.