Skip to content

Conversation

@Gardelll
Copy link

@Gardelll Gardelll commented Jan 1, 2026

Summary by Sourcery

Preserve LLM response splitter markers when protecting and cleaning chat content.

New Features:

  • Support treating LLM response splitter markers as special blocks to avoid re-protection and unintended cleanup.

Bug Fixes:

  • Avoid removing bracketed content such as LLM splitter markers when the response splitter is in LLM mode.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 1, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts special-block protection and system-format cleaning logic so that LLM-specific reply split markers like [SPLIT] are preserved when split_mode is 'llm', avoiding them being re-protected or stripped by generic cleanup.

Flow diagram for filter_system_format_content cleaning with LLM split_mode

flowchart TD
    A[Start filter_system_format_content] --> B[Input content]
    B --> C[Apply system format specific cleanup]
    C --> D{Is split_mode llm?}
    D -->|Yes| F[Skip generic [.*?] removal to preserve markers like [SPLIT]]
    D -->|No| E[Remove all patterns matching [.*?] using regex]
    E --> F
    F --> G[Remove @<...> patterns using regex]
    G --> H[Return cleaned_content]
Loading

File-Level Changes

Change Details Files
Preserve LLM reply split markers when protecting special blocks and cleaning formatted content, conditioned on the response splitter configuration.
  • Extend the guard in protect_special_blocks to skip matches that are either existing placeholders or the [SPLIT] marker when split_mode is set to 'llm', preventing them from being wrapped again.
  • Change the generic bracketed-text cleanup in filter_system_format_content to run only when split_mode is not 'llm', so that [SPLIT] and similar markers are not removed in LLM split mode.
src/chat/utils/utils.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-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.

Hey - I've found 1 issue, and left some high level feedback:

  • Consider extracting the [SPLIT] marker into a shared constant or into response_splitter config instead of hardcoding the string in protect_special_blocks, so the split token stays consistent across the codebase.
  • The condition if "__SPECIAL_" in match or global_config.response_splitter.split_mode == "llm" and match == "[SPLIT]": relies on operator precedence; adding parentheses or assigning intermediate booleans would improve readability and reduce the chance of future mistakes when editing this logic.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider extracting the `[SPLIT]` marker into a shared constant or into `response_splitter` config instead of hardcoding the string in `protect_special_blocks`, so the split token stays consistent across the codebase.
- The condition `if "__SPECIAL_" in match or global_config.response_splitter.split_mode == "llm" and match == "[SPLIT]":` relies on operator precedence; adding parentheses or assigning intermediate booleans would improve readability and reduce the chance of future mistakes when editing this logic.

## Individual Comments

### Comment 1
<location> `src/chat/utils/utils.py:967` </location>
<code_context>
     # 在处理完回复格式后,再清理其他简单的格式
     # 新增:移除所有残余的 [...] 格式,例如 [at=...]-    cleaned_content = re.sub(r"\[.*?\]", "", cleaned_content)
+    if global_config.response_splitter.split_mode != "llm":
+        cleaned_content = re.sub(r"\[.*?\]", "", cleaned_content)

     # 移除@格式:@<xxx>
</code_context>

<issue_to_address>
**question (bug_risk):** Guarding the bracket-stripping on `split_mode` is correct but may hide unexpected formats in LLM mode.

Because we now skip `"[... ]"` cleanup when `split_mode == "llm"`, any other bracketed control sequences (not just the splitter markers) will appear in the final output. If you only need to retain the splitter markers, consider narrowing the condition or regex so that only those specific patterns are preserved, while other bracketed metadata is still stripped.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@LuisKlee LuisKlee requested review from LuisKlee and tt-P607 January 2, 2026 05:07
Copy link
Collaborator

@LuisKlee LuisKlee left a comment

Choose a reason for hiding this comment

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

可能暂时不会合并
image
建议先解决这个可能存在的风险

@LuisKlee LuisKlee self-requested a review January 2, 2026 14:04
LuisKlee

This comment was marked as outdated.

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.

2 participants