GeezerVison is showing github.com — [FEATURE]: Validate and handle malformed fenced code blocks in user messages (follow-up to #20942) · Issue #20952 · anomalyco/opencode
[FEATURE]: Validate and handle malformed fenced code blocks in user messages (follow-up to #20942) #20952DescriptionPR #20942 introduces rendering of fenced code blocks in user messages. As a
direct consequence, unbalanced triple backticks — common when users paste
terminal output, incident reports, or AI-generated content that already
contains code fences — can produce malformed renders: broken code blocks,
incorrect collapse behavior, and confusing spacing.
A minimal fallback is already included in #20942: if the number of triple
backticks is odd, fall back to plain text. This prevents the worst case.
A more complete solution could include:
- Auto-closing unclosed fences at the render layer
- Escaping nested triple backticks before sending to the model
- Sanitizing user input at submission time, not just at render time
This pattern is a known limitation across major chat interfaces (ChatGPT,
Claude, Gemini) — addressing it at the input/render layer would improve
both UX and the quality of context sent to the model.
The current fix in #20942 is a starting point for discussion.
Related issues
Activityadded coreAnything pertaining to core functionality of the application (opencode server stuff) on Apr 4, 2026sandikodev commented on Apr 4, 2026 Progress update from PR #20942:
A minimal implementation is already in place at the render layer:
- If triple backticks are unbalanced (odd count), the last unclosed fence is auto-closed before rendering
- This is non-destructive — raw text sent to the model is unchanged
Open questions for discussion:
- Should we also sanitize at submission time (before sending to the model)?
- Pro: model receives cleaner context
- Con: silently mutates user input, harder to debug
- Should there be a visual indicator when a fence is auto-closed?
- Is a context-aware heuristic (detect if it's actually code vs plain text) worth the complexity?
Happy to hear maintainer's thoughts before going further. removed discussionUsed for feature requests, proposals, ideas, etc. Open discussion coreAnything pertaining to core functionality of the application (opencode server stuff) on May 3, 2026github-actions commented on Jul 3, 2026 To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|