Skip to content

fix: sanitize apply content before file edits#12015

Open
yzlu0917 wants to merge 1 commit intocontinuedev:mainfrom
yzlu0917:codex/issue-10783-apply-filter
Open

fix: sanitize apply content before file edits#12015
yzlu0917 wants to merge 1 commit intocontinuedev:mainfrom
yzlu0917:codex/issue-10783-apply-filter

Conversation

@yzlu0917
Copy link
Copy Markdown

@yzlu0917 yzlu0917 commented Apr 3, 2026

Summary

  • strip <think>...</think> blocks and Harmony protocol wrappers before apply/edit content is treated as file content
  • sanitize apply payloads in the VS Code apply manager so search/replace, empty-file writes, and diff previews stop carrying leaked reasoning into files
  • sanitize applyCodeBlock() input and add regression tests covering both <think> contamination and Harmony analysis/final channel output

Why

When upstream local-model stacks leak reasoning into the assistant content field, Continue's apply flow can treat that reasoning as the edit itself. In the worst case that means file edits and previews include model thoughts or Harmony control tokens instead of code.

This hardens the apply path against two concrete contamination patterns reported in #10783:

  • <think>...</think> reasoning blocks
  • Harmony-style analysis and final channel wrappers

Validation

  • ran npm run vitest -- util/stripReasoningFromApplyContent.vitest.ts edit/lazy/applyCodeBlock.vitest.ts in core

Closes #10783


Summary by cubic

Sanitizes apply/edit content to strip <think> blocks and Harmony wrappers so model reasoning never gets written to files, previews, or search/replace results. Closes #10783.

  • Bug Fixes
    • Added stripReasoningFromApplyContent() in core/util to remove <think> blocks and extract the Harmony final channel (and strip tokens).
    • Applied sanitization in core/edit/lazy/applyCodeBlock and extensions/vscode/src/apply/ApplyManager so deterministic apply, diff previews, search/replace, and empty-file writes use clean text.
    • Added unit tests for both contamination patterns.

Written for commit 5a511e6. Summary will update on new commits.

@yzlu0917 yzlu0917 requested a review from a team as a code owner April 3, 2026 06:07
@yzlu0917 yzlu0917 requested review from sestinj and removed request for a team April 3, 2026 06:07
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 3, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 5 files

@chatgpt-codex-connector
Copy link
Copy Markdown

💡 Codex Review

if (options.tools?.length && ollamaMessages.at(-1)?.role === "user") {

P1 Badge Skip Ollama tools when the model template lacks support

This now always attaches chatOptions.tools whenever tools are present and the last message is from the user, but the previous guard that suppressed tools for templates without .Tools support was removed. For Ollama models whose templates do not implement tool calling, /api/chat requests can fail instead of falling back to plain chat, which breaks tool-enabled conversations for those models.


return processedText.replace(HARMONY_TOKEN_REGEX, "");

P2 Badge Do not strip Harmony tokens from normal file content

stripReasoningFromApplyContent is now run on every apply path and unconditionally removes literals like <|start|>, <|end|>, and <|message|> from the final text. If a user is intentionally editing prompt templates/tests/docs that contain these token strings, the applied file is silently corrupted because those literals are deleted even when the content is not a Harmony wrapper.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Apply/edit writes raw model reasoning into files instead of filtering

1 participant