fix(wand): stop markdown code fences landing in generated code - #6289
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Fence stripping: New History reset: Prompts: The wand API adds server-side “raw function body only, no markdown” reinforcement for Removed: Reviewed by Cursor Bugbot for commit 68e1192. Configure here. |
Greptile SummaryThe PR sanitizes markdown-fenced Wand responses, resets generation history when Function blocks switch languages, and strengthens raw-code prompting.
Confidence Score: 4/5The PR does not appear safe to merge until the outstanding sanitizer path that removes a valid trailing embedded fence is resolved. The current sanitizer still unconditionally removes a final fence-like line, so a response truncated immediately after a delimiter embedded in generated code is persisted in corrupted form. Files Needing Attention: apps/sim/lib/wand/strip-code-fences.ts and apps/sim/lib/wand/strip-code-fences.test.ts
|
| Filename | Overview |
|---|---|
| apps/sim/lib/wand/strip-code-fences.ts | Introduces conservative outer-fence removal while retaining the previously reported corruption when a truncated embedded delimiter is the final line. |
| apps/sim/lib/wand/strip-code-fences.test.ts | Covers wrapped, truncated, nested, multi-block, and untouched output cases, including the acknowledged trailing-delimiter behavior. |
| apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-wand.ts | Sanitizes completed output and uses an epoch guard to keep retired language turns out of conversation history. |
| apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/code/code.tsx | Keys Wand history resets to Function block language changes and expands Python generation guidance. |
| apps/sim/app/api/wand/route.ts | Adds language-neutral server-side instructions requiring raw function-body output. |
Reviews (6): Last reviewed commit: "test(wand): record the trailing-fence am..." | Re-trigger Greptile
3742f1b to
2a70483
Compare
|
@cursor review |
Strip fences from wand output for raw-value generation types, reset the conversation history when a Function block switches language, and give the Python prompt the worked example the JavaScript one already had.
Slice only the outermost fence delimiters so a fenced body containing line-leading backticks keeps every interior line, and skip the history append when a language reset retired the request mid-flight.
The trimStart check made the -1 branch dead and stated "opens with a fence" twice. Derive it once from the first fence line's position.
2a70483 to
fb8337a
Compare
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
2 issues from previous reviews remain unresolved.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit fb8337a. Configure here.
No call site ever passed it, so the branch never ran. The props interface makes the removal compile-time verified.
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
2 issues from previous reviews remain unresolved.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit c89adb2. Configure here.
A truncated response whose body embeds line-leading backticks lost every line after the first embedded delimiter. Only the opening line and a final fence line are removed now. Sync the history epoch in a layout effect so a request settling before the passive flush cannot append to already-reset history.
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 5985357. Configure here.
A bare fence on the last line closes the wrapper in every well-formed response and is content only when generation stopped exactly on an embedded delimiter. Nothing separates the two, so assert the chosen behavior instead of leaving it implicit.
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 68e1192. Configure here.

Summary
maintainHistorywas replaying the previous language's assistant turn, which kept steering generations back to itPYTHON_AI_PROMPTthe worked example the JavaScript prompt already had, and align its import rule with the sandbox package listjavascript-function-body, matching whatcron-expressionandjson-objectalready doTwo known non-goals: a response that starts with prose before the fence, and mid-stream display (the editor may briefly show a fence before the final value replaces it). Both are deliberate — per-chunk stripping would mean guessing whether a trailing backtick run opens a fence or is part of the code.
Type of Change
Testing
15 unit tests on the sanitizer covering full wrap, missing closing fence, untagged fence, indentation preservation, multi-fence, idempotence, and the must-not-touch cases. Verified the tests fail when the util is stubbed out. Full suite green (18,597 passing), typecheck, biome, and
check:api-validationall clean.Checklist