Skip to content

fix(chat): preserve punctuated fenced code language tags - #1061

Merged
dovvnloading merged 1 commit into
mainfrom
agent/fix-code-fence-language-tags
Nov 25, 2026
Merged

dovvnloading merged 1 commit into
mainfrom
agent/fix-code-fence-language-tags

Conversation

@dovvnloading

Copy link
Copy Markdown
Owner

Summary

Fixes #1036. Fenced model replies used a word-only language capture and an optional newline, so punctuation in language aliases was incorrectly inserted into generated code. Match the opening and closing fence lines, read the complete info string separately, and use its first token as the language.

What Changed

  • Preserve C++, C#, Objective-C and other punctuated language identifiers and the original code body (with the existing outer whitespace trimming).
  • Handle LF/CRLF, unlabelled fences, optional info metadata and nested <code_block> wrappers in both parser branches.
  • Keep inline triple-backtick spans in text and support backtick fences of length three or more, requiring the closer to be at least as long as the opener. Preserve existing snippet aggregation and first-fence language behavior.
  • Add 23 parser cases and extend the existing send/regenerate intent tests to assert the real generated code node's language and source for all three reported aliases, retaining Python coverage.

Why

The opening info line is metadata rather than source code. Explicit boundaries prevent the suffix of a language tag or a filename attribute from becoming the first line of the generated program. Requiring complete fence lines also avoids interpreting ordinary inline backtick spans as blocks.

Validation

  • Isolated pytest regression run on Python 3.13 with the repository's parser and actual reasoning-splitting function bodies/constants in a minimal provider import shim: 18 passed / 15 failed before; 33 passed / 0 failed after.
  • Isolated compileall for the parser, its tests and reasoning shim.
  • Verified both tested files' Git blob hashes match the committed content; inspected the committed diff (one commit, three intended files, zero commits behind main at comparison time).
  • App launches
  • Relevant workflow was exercised manually
  • python -m compileall -q . passes (run from the repo root - matches CI)
  • python -m pytest -q passes (run from the repo root - matches CI)
  • cd web_ui && npm run check passes (matches CI)

Local full checkout is blocked by GitHub DNS resolution. The local harness does not load the full provider module, application, or repository conftest; the send/regenerate integration tests are committed but not run locally. Required CI, full lint, build and manual checks remain pending.

Focused verification from a configured checkout with the repository's Python 3.12 environment:

python -m pytest -q -n0 backend/tests/test_response_parsing.py backend/tests/test_canvas.py::test_send_message_reply_with_code_fence_creates_code_child_and_edge backend/tests/test_canvas.py::test_regenerate_response_replaces_code_child_not_accumulates

Manual verification: send a chat asking for fenced C++, C#, and Objective-C examples; inspect each generated code node's language and first line. Regenerate the response, verify the old code child is replaced and the new source is intact, then save/reload. Check ordinary Python and unlabelled fences too.

UI Notes

  • Screenshots included if the change is visual
  • No screenshots needed (no styling or layout change)

Additional Context

This intentionally recognizes complete backtick fence lines, rather than the legacy permissive same-line pseudo-fences; inline triples remain text. This is not a full CommonMark tokenizer (e.g. tilde fences and nested blockquote parsing remain out of scope). Existing whitespace trimming, multiple-block combination, wrappers and reasoning handling are otherwise unchanged. The separate literal reasoning-tag issue #1047 is out of scope. No dependency, schema, frontend, or CI changes. Draft pending required checks and manual verification; do not merge until those pass.

@dovvnloading dovvnloading left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all three changed files against #1036. The new fence matcher separates the complete opening info line from the code, preserves punctuated aliases in both wrapped and unwrapped branches, supports CRLF and longer fences, and keeps ordinary inline triple-backtick text intact. The parametrized parser and real send/regenerate code-node regressions cover the reported cases. No blocking findings in the reviewed diff. Verified CI run 45587668309 for this head: frontend checks, Windows Python checks (including compile, lint, pytest and performance suite), POSIX checks and wheel build/install passed; optional Playwright boot smoke was skipped. Checked intervening main changes: four commits, no overlap with the three changed files. Native desktop launch/manual save-reload verification was not performed; for this focused backend fix I am relying on the passing automated integration coverage and the maintainer's request to process and merge. GitHub review is a comment rather than an approval because the connected account is also the PR author.

@dovvnloading
dovvnloading marked this pull request as ready for review November 25, 2026 10:26
@dovvnloading
dovvnloading merged commit ba97640 into main Nov 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(chat): fenced C++, C# and hyphenated language tags corrupt generated code

1 participant