You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When applying AI-generated code suggestions in Void, the code is not inserted/merged if the assistant’s response begins with a <think>...</think> block. The reasoning section (the r1 model’s hidden chain-of-thought) occupies multiple lines at the start of the answer, which throws off the diff algorithm that Void uses to merge changes. Essentially, these extra lines cause a desync: the editor can’t correctly match the AI’s suggested code with the corresponding lines in the document, so no synced diff edits can be applied.
Steps to Reproduce:
Use an AI model (such as DeepSeek-R1) that includes a reasoning section wrapped in `<think>...</think>` tags.
Ask the model to generate or modify code. The assistant’s response will start with a block like:
<think>
... (internal reasoning content) ...
</think>
Actual code starts here...
In the chat interface, click the “Apply” button on the code block suggestion.
Observed: desync in the entire document; the code from the suggestion can not be applied.
Cause:
The <think>...</think> tags and their content are mistakenly included as part of the applied code. When the diff algorithm compares the AI’s suggested code with the document, these extra lines cause a misalignment because they don’t exist in the file. As a result, the computed diff is empty, and the BulkEditService applies no changes.
Affected Components:
Chat Response Parsing: The AI’s raw output is not pre-processed to filter out the `<think>` section. This means that both the chat UI and the underlying code used for generating diffs see the extra lines.
Code Apply Logic: The function responsible for computing and applying code edits (likely in chatCodeblockActions.ts or similar) processes the AI’s response with the `<think> block still intact, resulting in an desynced diff.
Proposed Solution:
Introduce a preprocessing step to strip out the first <think>...</think> section from the AI response before it is used in either the chat display or the diff computation. Specifically:
As soon as the AI’s response is received, check if it begins with `<think>`.
If it does, remove everything from the opening `<think>` to the corresponding closing `</think>` (inclusive).
Proceed to process the remaining text as the actual answer.
This will ensure that:
The chat view displays only the final answer (with a possible placeholder indicating processing time, if desired).
The diff algorithm compares only the actual code, allowing it to compute the correct changes and apply them to the document.
Notes:
The fix should remove the initial ... block only if it appears at the very beginning of the response. To handle cases where the block might include nested tags (for example, if the block contains self-referential or meta-thinking content), the implementation must use a robust parsing strategy (such as a stack-based approach or an XML/HTML parser) to correctly match each opening tag with its corresponding closing tag. This ensures that the entire intended block is removed—even when nested tags are present—while leaving any subsequent tags (that might be legitimately part of the actual answer) intact. If the tags are malformed or improperly nested, the algorithm should fail gracefully, either by removing content only up to the first detectable closing tag or by issuing a warning, so that the remainder of the response can be processed correctly.
Future improvements may include an option to view the internal reasoning in the chat window as a collapsible section without being included with the diff process.
This change aligns with the existing feature request to handle <think> tags more gracefully and should resolve the “Apply” button failure when using AI models like DeepSeek-R1.
The text was updated successfully, but these errors were encountered:
Description:
When applying AI-generated code suggestions in Void, the code is not inserted/merged if the assistant’s response begins with a
<think>...</think>
block. The reasoning section (the r1 model’s hidden chain-of-thought) occupies multiple lines at the start of the answer, which throws off the diff algorithm that Void uses to merge changes. Essentially, these extra lines cause a desync: the editor can’t correctly match the AI’s suggested code with the corresponding lines in the document, so no synced diff edits can be applied.Steps to Reproduce:
Cause:
The
<think>...</think>
tags and their content are mistakenly included as part of the applied code. When the diff algorithm compares the AI’s suggested code with the document, these extra lines cause a misalignment because they don’t exist in the file. As a result, the computed diff is empty, and the BulkEditService applies no changes.Affected Components:
Proposed Solution:
Introduce a preprocessing step to strip out the first
<think>...</think>
section from the AI response before it is used in either the chat display or the diff computation. Specifically:This will ensure that:
Notes:
The fix should remove the initial ... block only if it appears at the very beginning of the response. To handle cases where the block might include nested tags (for example, if the block contains self-referential or meta-thinking content), the implementation must use a robust parsing strategy (such as a stack-based approach or an XML/HTML parser) to correctly match each opening tag with its corresponding closing tag. This ensures that the entire intended block is removed—even when nested tags are present—while leaving any subsequent tags (that might be legitimately part of the actual answer) intact. If the tags are malformed or improperly nested, the algorithm should fail gracefully, either by removing content only up to the first detectable closing tag or by issuing a warning, so that the remainder of the response can be processed correctly.
Future improvements may include an option to view the internal reasoning in the chat window as a collapsible section without being included with the diff process.
This change aligns with the existing feature request to handle
<think>
tags more gracefully and should resolve the “Apply” button failure when using AI models like DeepSeek-R1.The text was updated successfully, but these errors were encountered: