Fix CodeTailor raw Parsons markup leaking into LLM pipeline and clipboard - #1425
Merged
bnmnetp merged 4 commits intoAug 27, 2026
Conversation
…oard
The "Example" field fed into the personalized-Parsons LLM pipeline was the
raw pp-authoring markup ("---"-delimited blocks with #distractor/#paired
tags), not compilable code. That raw text is used verbatim as the LLM
prompt's [sample-solution] and, on generation/validation failure, is
returned directly as the "fixed" solution -- which then gets copied to the
clipboard by the codetailor "copy to clipboard" feature.
Also fix aggregate_code_to_full_Parsons_block, which merged any run of
same-indentation-level lines into one block regardless of whether they were
actually nested under something. This silently collapsed unrelated
sibling statements (even across separate top-level statements) into a
single undraggable block, most visibly for flat/sequential code where the
entire example became one block. It was previously masked because the
leaked raw markup's own "---" lines were incidentally reinterpreted by the
frontend as block boundaries.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes CodeTailor’s personalized-Parsons pipeline so the LLM (and clipboard fallback) receives compilable example solution code instead of raw Parsons authoring markup, and it corrects Python full-Parsons block aggregation so top-level sibling statements don’t get collapsed into a single undraggable block.
Changes:
- In
coach.py, the"Example"value sent into the LLM pipeline is now the extracted solution code (unless it’s the"LLM-example"sentinel), preventing raw---/#distractor/#pairedmarkup from leaking downstream and into clipboard fallbacks. - In
generate_parsons_blocks.py,aggregate_code_to_full_Parsons_blocknow avoids merging root-level sibling statements, while still merging contiguous nested runs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| bases/rsptx/book_server_api/routers/personalized_parsons/generate_parsons_blocks.py | Adjusts full-Parsons block aggregation rules to prevent unintended root-level block merging. |
| bases/rsptx/book_server_api/routers/coach.py | Sends compilable example solution code (not raw Parsons markup) into the LLM personalization request payload. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
startswith(("def", "return")) matched any line beginning with those
substrings, not just the keywords -- e.g. "default_value = 5" or
"returned_value = x" were misclassified as def/return statements,
splitting/merging blocks incorrectly. Use a word-boundary regex instead.
Similarly, the import-grouping check only matched "import ...", not
"from ... import ...", so from-imports were split into separate blocks
despite the docstring's claim that all imports are grouped together.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
fulltext.trim() stripped real leading indentation off only the first block's first line whenever the browser's <pre>-tag newline-eating quirk left that indentation at the very start of the string, while every later block (after its own "---") kept its indent untouched. This showed up as a spurious extra indent level on personalized CodeTailor Parsons puzzles. Blank leading/trailing lines within a block are already discarded further down per block, so trimEnd() is enough to clean up the template's trailing whitespace without eating real code indentation. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
Author
|
Added a line of code that was causing an issue with another half of the bug solved by #1416 |
extract_parsons_code() deliberately leaves HTML entities like "<" escaped, since its result also gets re-embedded into a <pre> block for the Parsons widget to re-render (a real "<" there would be misread as an HTML tag). extract_parsons_solution() reused that same escaped text for the plain-text "copy answer to clipboard" solution and code_answer without ever unescaping it, so any source line containing an escaped entity (e.g. "lst[index] % 2 != 0" preceded by "index < len(lst)") copied to the clipboard with the literal entity instead of "<", making the copied code fail to compile. Co-Authored-By: Claude Sonnet 5 <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.
The "Example" field fed into the personalized-Parsons LLM pipeline was the raw pp-authoring markup ("---"-delimited blocks with #distractor/#paired tags), not compilable code. That raw text is used verbatim as the LLM prompt's [sample-solution] and, on generation/validation failure, is returned directly as the "fixed" solution -- which then gets copied to the clipboard by the codetailor "copy to clipboard" feature.
Also fix aggregate_code_to_full_Parsons_block, which merged any run of same-indentation-level lines into one block regardless of whether they were actually nested under something. This silently collapsed unrelated sibling statements (even across separate top-level statements) into a single undraggable block, most visibly for flat/sequential code where the entire example became one block. It was previously masked because the leaked raw markup's own "---" lines were incidentally reinterpreted by the frontend as block boundaries.