Skip to content

fix(visualization): escape quotes and backslashes in DOT names#3712

Merged
seratch merged 1 commit into
openai:mainfrom
anxkhn:fix/visualization-escape-dot-names
Jul 1, 2026
Merged

fix(visualization): escape quotes and backslashes in DOT names#3712
seratch merged 1 commit into
openai:mainfrom
anxkhn:fix/visualization-escape-dot-names

Conversation

@anxkhn

@anxkhn anxkhn commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

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:

from agents import Agent
from agents.extensions.visualization import get_all_nodes

get_all_nodes(Agent(name='Weird"Name'))
# '"Weird"Name" [label="Weird"Name", ...]'   # the embedded quote closes the id -> invalid DOT

This wraps every name in a small _escape_label helper 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

  • Added test_names_with_quotes_and_backslashes_are_escaped: an agent named Weird"Name and a tool named Back\slash now emit "Weird\"Name" and "Back\\slash" in both nodes and edges, and the bare malformed form is gone.
  • make format and make lint are clean; make typecheck is clean on the changed files.
  • make tests passes (tests/test_visualization.py: 9 passed).

Note: I do not have the dot binary 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 the graphviz library escapes.

Issue number

No tracker issue. Self-identified defect.

Checks

  • I've added new tests, if relevant
  • I've run .agents/skills/code-change-verification/scripts/run.sh (equivalent: make format && make lint && make typecheck && make tests)
  • I've confirmed all verification steps pass
  • If using Codex, I've run /review before submitting this PR (not used)

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.
@seratch seratch added this to the 0.17.x milestone Jul 1, 2026
@seratch seratch enabled auto-merge (squash) July 1, 2026 00:32
@seratch seratch merged commit 655c805 into openai:main Jul 1, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants