Skip to content

Fix CodeTailor raw Parsons markup leaking into LLM pipeline and clipboard - #1425

Merged
bnmnetp merged 4 commits into
RunestoneInteractive:mainfrom
aspadiyath:fix-codetailor-clipboard-and-block-merging
Aug 27, 2026
Merged

Fix CodeTailor raw Parsons markup leaking into LLM pipeline and clipboard#1425
bnmnetp merged 4 commits into
RunestoneInteractive:mainfrom
aspadiyath:fix-codetailor-clipboard-and-block-merging

Conversation

@aspadiyath

Copy link
Copy Markdown
Contributor

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.

…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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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/#paired markup from leaking downstream and into clipboard fallbacks.
  • In generate_parsons_blocks.py, aggregate_code_to_full_Parsons_block now 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.

aspadiyath and others added 2 commits August 26, 2026 10:00
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>
@aspadiyath

Copy link
Copy Markdown
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 "&lt;"
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 &lt; 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>
@bnmnetp
bnmnetp merged commit bfca7d5 into RunestoneInteractive:main Aug 27, 2026
2 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.

3 participants