fix(stage5): drop broken mermaid fence on terminal mmdc failure#64
Merged
Merged
Conversation
…ax — closes #61 When mermaid generation exhausts MAX_ATTEMPTS with mmdc syntax errors, the artifact previously shipped with BOTH a `<!-- HIL: HIL-NNN -->` marker AND the broken ```mermaid fence. The fence is strictly harmful: every viewer (GitHub, IDE preview, mkdocs) renders it as a blank/error block. Readers see a code fence that produces nothing. Three live cases in the agent-brain dogfood (HIL-003, HIL-010, HIL-012) all ship as broken-fence blocks for the same reason — a `;` in a relationship label that mmdc's parser rejects. This change branches the `## Diagram` section builder on whether the terminal verdict was an mmdc syntax failure (any issue with category="syntax") vs an LLM-semantic failure (mmdc-passing, content- disputed): * mmdc syntax failure: drop the fence entirely, replace with a "Diagram unavailable; see HIL-NNN" line. Reader gets a clear signal. * LLM-semantic failure: keep the fence (the diagram renders fine; the dispute is about quality, not parseability). * pass: unchanged. Refactored the section-building into _build_diagram_section() so the three-way branch is testable as a pure function. The discriminator _is_mmdc_syntax_failure() reads MermaidIssue.category instead of string-matching verdict.summary — robust against future prompt changes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
When mermaid generation exhausts MAX_ATTEMPTS with mmdc syntax errors, drop the ```mermaid fence entirely. Ship only the HIL marker + a 'diagram unavailable' line. LLM-semantic disputes (mmdc-passing, content-disputed) still keep the fence.
Why
Discovered during the agent-brain trust-eval pass (`docs/gen/agent-brain/EVAL.md`). Three live cases (HIL-003 `SummarizationConfig`, HIL-010 `TestGeminiConverter`, HIL-012 `TestGraphStoreManagerEdgeCases`) ship as `` markers plus a syntactically broken ```mermaid block. Every viewer (GitHub, IDE preview, mkdocs) renders the fence as a blank/error — the reader sees a code block that produces nothing AND a TODO marker. A flagged-but-unrenderable block is strictly worse than no diagram.
Root cause in every case: a relationship label like `Settings ..> ValidationError : calls get_api_key(); raises ValidationError`. The `;` breaks mmdc's lexer. (The per-package merger got the label-strip retry treatment in #60; per-class diagrams don't have that escape hatch because each is a single LLM-authored unit — when the LLM keeps producing the same bad label across 3 attempts, the only sane move is to stop pretending we have a diagram.)
Closes #61.
Changes
Invariants
Verification
Related