fix(visualization): escape quotes and backslashes in DOT names#3712
Merged
Conversation
Agent, tool, MCP server, and handoff names were interpolated into Graphviz DOT identifiers and labels with no escaping, so a name containing a double quote or backslash closed the DOT string early and produced a malformed graph. Add a small _escape_label helper that backslash-escapes backslashes then quotes and apply it at every name interpolation site. Normal names render unchanged; add a regression test for names with quotes and backslashes.
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
The visualization extension builds Graphviz DOT by interpolating agent, tool, MCP-server, and handoff names straight into double-quoted IDs and labels with no escaping. Any name that contains a
"or\terminates the DOT string early and produces a malformed graph that Graphviz cannot render.On current
main:This wraps every name in a small
_escape_labelhelper that escapes\first, then", so the names round-trip as valid quoted DOT IDs. Normal names (no"or\) are emitted byte-for-byte as before, so existing tests are unaffected. No public API changes.Test plan
test_names_with_quotes_and_backslashes_are_escaped: an agent namedWeird"Nameand a tool namedBack\slashnow emit"Weird\"Name"and"Back\\slash"in both nodes and edges, and the bare malformed form is gone.make formatandmake lintare clean;make typecheckis clean on the changed files.make testspasses (tests/test_visualization.py: 9 passed).Note: I do not have the
dotbinary installed locally, so I assert on the emitted DOT string (the same way the existing visualization tests do) rather than rendering. The escaping order (backslash first, then quote) follows the DOT spec and matches how thegraphvizlibrary escapes.Issue number
No tracker issue. Self-identified defect.
Checks
.agents/skills/code-change-verification/scripts/run.sh(equivalent:make format && make lint && make typecheck && make tests)/reviewbefore submitting this PR (not used)