Skip to content

Fix #518: Add error rule for Invalid signature in thinking block#519

Merged
ding113 merged 1 commit intodevfrom
fix/issue-518-invalid-signature-thinking
Jan 3, 2026
Merged

Fix #518: Add error rule for Invalid signature in thinking block#519
ding113 merged 1 commit intodevfrom
fix/issue-518-invalid-signature-thinking

Conversation

@ding113
Copy link
Owner

@ding113 ding113 commented Jan 3, 2026

Summary

Added a new error rule to handle "Invalid `signature` in `thinking` block" error that commonly occurs when switching between Anthropic and non-Anthropic channels.

Problem

Fixes #518

The error "Invalid `signature` in `thinking` block" was not matched by existing error rules, causing unclear error messages for users. This error commonly occurs when requests alternate between Anthropic channels and non-Anthropic channels.

Solution

Added a new error rule in src/repository/error-rules.ts:

  • Pattern: Invalid \signature` in `thinking` block`
  • Match Type: contains (for precise matching)
  • Category: thinking_error
  • Priority: 71 (higher than the generic thinking error rule at priority 70)
  • Error Message: Clear Chinese explanation about the cross-channel incompatibility

Changes

Testing

  • TypeScript compilation passed
  • Biome lint check passed
  • Error rule follows existing pattern structure

Notes

This rule will be automatically synced to the database when the application starts or when users refresh the error rules cache.


Created by Claude AI in response to @claude mention

Greptile Summary

Added a new error rule to handle "Invalid signature in thinking block" errors that occur when switching between Anthropic and non-Anthropic channels. The implementation correctly:

  • Uses matchType: "contains" for precise string matching
  • Provides a clear Chinese error message explaining the cross-channel incompatibility
  • Sets category: "thinking_error" to group with related errors
  • Includes proper documentation linking to issue error rule 新增:Invalid signature in thinking block #518
  • Follows the existing error rule structure and formatting

The rule will be automatically synced to the database on application startup via syncDefaultErrorRules(). The pattern is specific enough that it won't conflict with the generic thinking error rule at priority 70.

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk
  • The change is a simple addition of a new error rule that follows established patterns. The implementation is correct and won't conflict with existing rules. The only minor improvement would be adjusting the priority number for better performance, but this doesn't affect correctness.
  • No files require special attention

Important Files Changed

Filename Overview
src/repository/error-rules.ts Added new error rule for Invalid signature in thinking block with correct pattern and format, though priority could be optimized

Sequence Diagram

sequenceDiagram
    participant Client
    participant ProxyServer
    participant ErrorDetector
    participant Database
    participant AnthropicAPI as Anthropic/Non-Anthropic API
    
    Note over ProxyServer: Application Startup
    ProxyServer->>Database: syncDefaultErrorRules()
    Database-->>ProxyServer: New rule inserted/updated
    ProxyServer->>ErrorDetector: reload() triggered
    ErrorDetector->>Database: getActiveErrorRules()
    Database-->>ErrorDetector: All enabled rules (sorted by priority)
    ErrorDetector->>ErrorDetector: Parse rules into containsPatterns
    Note over ErrorDetector: New rule added to cache at priority 71
    
    Note over Client: Runtime Error Occurs
    Client->>ProxyServer: API Request
    ProxyServer->>AnthropicAPI: Forward request
    AnthropicAPI-->>ProxyServer: Error: Invalid `signature` in `thinking` block
    ProxyServer->>ErrorDetector: detectAsync(errorMessage)
    ErrorDetector->>ErrorDetector: Iterate through containsPatterns (priority order)
    ErrorDetector->>ErrorDetector: Check generic thinking rule (priority 70) - no match
    ErrorDetector->>ErrorDetector: Check signature thinking rule (priority 71) - MATCH!
    ErrorDetector-->>ProxyServer: Return overrideResponse
    ProxyServer->>ProxyServer: Replace error message with Chinese translation
    ProxyServer-->>Client: Friendly error: "thinking 块签名无效..."
Loading

Fixes #518

Added new error rule to handle "Invalid \`signature\` in \`thinking\` block"
error that commonly occurs when switching between Anthropic and non-Anthropic
channels.

Changes:
- Added new error rule with pattern matching for signature validation error
- Category: thinking_error
- Match type: contains (for exact string matching)
- Priority: 71 (higher than generic thinking error rule at 70)
- Chinese error message for better user experience

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Jan 3, 2026

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

概述

src/repository/error-rules.ts 中的 DEFAULT_ERROR_RULES 常量中新增一条默认错误规则,用于匹配"Invalid signature in thinking block"错误,此错误常见于 Anthropic 和非 Anthropic 渠道的互相切换场景。

变更

文件组 / 文件 变更摘要
默认错误规则新增
src/repository/error-rules.ts
DEFAULT_ERROR_RULES 数组中新增一条错误规则条目(优先级 71):模式为"Invalid `signature` in `thinking` block",分类为"thinking_error",匹配方式为 contains,并包含对应的中文错误提示响应

预估代码审查工作量

🎯 1 (Trivial) | ⏱️ ~3 分钟

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确概括了主要变更:添加错误规则来处理"Invalid signature in thinking block"错误,直接关联到issue #518
Linked Issues check ✅ Passed Pull request完全满足issue #518的要求:添加了新的错误规则来匹配"Invalid signature in thinking block"消息,设置了适当的优先级和分类。
Out of Scope Changes check ✅ Passed 所有变更都在scope内,仅在DEFAULT_ERROR_RULES数组中添加了一条新的错误规则,直接对应issue #518的要求。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed PR description accurately describes the changeset: adds a new error rule for handling 'Invalid signature in thinking block' errors, with clear context about the problem, solution, and testing.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/issue-518-invalid-signature-thinking

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ding113, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the system's error handling capabilities by adding a dedicated rule for the 'Invalid signature in thinking block' error. This specific error frequently occurs when users alternate between Anthropic and non-Anthropic channels. The new rule ensures that users receive a precise and helpful error message, improving the overall user experience by clarifying the root cause of the issue.

Highlights

  • New Error Rule Added: A new error rule has been introduced to specifically handle the 'Invalid signature in thinking block' error.
  • Improved Error Clarity: This rule provides a clear Chinese error message to users, explaining that the issue often arises when switching between Anthropic and non-Anthropic channels.
  • Prioritization: The new rule is assigned a higher priority (71) than the generic thinking error rule (70), ensuring it takes precedence for this specific error.
  • Problem Resolution: This change directly addresses and fixes issue error rule 新增:Invalid signature in thinking block #518, which previously resulted in unclear error messages for this specific scenario.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a new error rule to handle the 'Invalid signature in thinking block' error, which improves error handling clarity for users switching between different channel types. The change is straightforward and well-implemented.

My review includes one main point regarding the priority setting for the new rule. There appears to be an inconsistency between the intended priority logic (higher number = higher priority) and the actual implementation in the database query (ascending sort). While your change works correctly in this specific instance due to differing matchTypes, I've suggested an adjustment to make the priority handling more robust and align with the existing code's behavior.

Overall, a good addition to improve user experience.

@github-actions github-actions bot added size/XS Extra Small PR (< 50 lines) bug Something isn't working area:Error Rule labels Jan 3, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 3, 2026

🧪 测试结果

测试类型 状态
代码质量
单元测试
集成测试
API 测试

总体结果: ✅ 所有测试通过

@ding113 ding113 merged commit 4f73185 into dev Jan 3, 2026
17 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in Claude Code Hub Roadmap Jan 3, 2026
@ding113 ding113 deleted the fix/issue-518-invalid-signature-thinking branch January 3, 2026 09:21
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code Review Summary

No significant issues identified in this PR.

PR Size: XS

  • Lines changed: 19
  • Files changed: 1

Review Coverage

  • Logic and correctness - Clean
  • Security (OWASP Top 10) - Clean
  • Error handling - Clean
  • Type safety - Clean
  • Documentation accuracy - Clean
  • Test coverage - Adequate
  • Code clarity - Good

Automated review by Codex AI

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

  • Identified PR #519 and applied the label size/XS (19 lines changed, 1 file).
  • Reviewed the diff (only src/repository/error-rules.ts#L625 changes) across logic/security/error-handling/types/docs/tests/simplification.
  • No issues in the changed lines met the reporting threshold (>=80 confidence), so no inline comments were posted; a summary review was submitted via gh pr review.

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

Labels

area:Error Rule bug Something isn't working size/XS Extra Small PR (< 50 lines)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant