Skip to content

Comments

fix: 改进 prompt_limit 错误规则的正则匹配#226

Merged
ding113 merged 1 commit intoding113:devfrom
sususu98:fix/error-rules
Nov 28, 2025
Merged

fix: 改进 prompt_limit 错误规则的正则匹配#226
ding113 merged 1 commit intoding113:devfrom
sususu98:fix/error-rules

Conversation

@sususu98
Copy link
Contributor

Summary

  • 修复 prompt_limit 错误规则的正则表达式,使其能同时匹配两种格式:
    • prompt is too long...tokens...maximum
    • prompt is too long...maximum...tokens

Changes

将原来的 prompt is too long.*maximum.*tokens 改为 prompt is too long.*(tokens.*maximum|maximum.*tokens),以覆盖不同 API 返回的错误消息格式。

Test plan

  • 验证正则表达式能正确匹配两种格式的错误消息

🤖 Generated with Claude Code

修复正则表达式以同时匹配 "tokens...maximum" 和 "maximum...tokens" 两种格式。

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

Co-Authored-By: Claude <noreply@anthropic.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @sususu98, 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!

此拉取请求旨在增强系统识别和分类来自不同 API 响应中“提示过长”错误的能力。通过更新一个关键的正则表达式,系统现在可以处理错误消息中不同词语顺序的情况,确保更一致的错误处理和用户反馈。

Highlights

  • 改进 prompt_limit 错误规则的正则表达式: 修复了 prompt_limit 错误规则的正则表达式,使其能够匹配两种不同的错误消息格式(tokens...maximummaximum...tokens),从而提高错误识别的鲁棒性。
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

这个 PR 改进了 prompt_limit 错误规则的正则表达式,使其能够匹配两种不同顺序的错误消息格式。这个改动是正确的,并且解决了描述中提到的问题。我有一个关于正则表达式性能的小建议,使用非捕获组可以略微提高效率。

const DEFAULT_ERROR_RULES = [
{
pattern: "prompt is too long.*maximum.*tokens",
pattern: "prompt is too long.*(tokens.*maximum|maximum.*tokens)",
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

为了略微提高正则表达式的性能,建议使用非捕获组 (?:...) 来代替捕获组 (...)。非捕获组在匹配时不会保存子字符串,因此效率会更高一些。

Suggested change
pattern: "prompt is too long.*(tokens.*maximum|maximum.*tokens)",
pattern: "prompt is too long.*(?:tokens.*maximum|maximum.*tokens)",

@ding113 ding113 added the size/XS Extra Small PR (< 50 lines) label Nov 28, 2025
@ding113
Copy link
Owner

ding113 commented Nov 28, 2025

🔒 Security Scan Results

No security vulnerabilities detected

This PR has been scanned against OWASP Top 10, CWE Top 25, and common security anti-patterns. No security issues were identified in the code changes.

Change Summary

The PR modifies a single regex pattern in src/repository/error-rules.ts:

  • Before: "prompt is too long.*maximum.*tokens"
  • After: "prompt is too long.*(tokens.*maximum|maximum.*tokens)"

This is a pattern improvement to match both word orderings in error messages.

Security Analysis

Category Status
ReDoS (Regex DoS) ✅ Safe - Pattern passes safe-regex validation
Injection Attacks ✅ N/A - Static constant, not user input
Authentication ✅ N/A - No auth changes
Access Control ✅ N/A - No access control changes
Sensitive Data ✅ N/A - No secrets or PII
XSS ✅ N/A - Server-side code only
SSRF ✅ N/A - No network requests

Scanned Categories

  • ✅ Injection attacks (SQL, NoSQL, Command, LDAP, etc.)
  • ✅ Authentication and session management
  • ✅ Sensitive data exposure
  • ✅ Access control and authorization
  • ✅ Security misconfiguration
  • ✅ Cross-site scripting (XSS)
  • ✅ Insecure deserialization
  • ✅ SSRF and path traversal
  • ✅ Cryptographic weaknesses
  • ✅ ReDoS (Regular Expression Denial of Service)

Code Context

The codebase already implements robust ReDoS protection via the safe-regex library in src/lib/error-rule-detector.ts:162, which validates all regex patterns before compilation. The new pattern passes this validation.


🤖 Automated security scan by Claude AI - OWASP Top 10 & CWE coverage

Copy link
Owner

@ding113 ding113 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

This PR improves the prompt_limit error rule regex pattern to handle two different API error message formats. The change is minimal, well-targeted, and correctly implements the stated goal.

🔍 Issues Found

  • Critical (🔴): 0 issues
  • High (🟠): 0 issues
  • Medium (🟡): 0 issues
  • Low (🟢): 0 issues

🎯 Priority Actions

No issues requiring action were identified. The change is ready for merge.

💡 General Observations

  1. Regex correctness verified: The new pattern prompt is too long.*(tokens.*maximum|maximum.*tokens) correctly matches both orderings:

    • prompt is too long...tokens...maximum
    • prompt is too long...maximum...tokens
  2. No ReDoS vulnerability: The pattern was tested with adversarial inputs (up to 1000 characters between tokens) and completed in <1ms.

  3. Backward compatible: The new pattern matches all strings that the old pattern matched, plus the additional format.

  4. Test alignment: The existing test suite uses test strings that align with the new regex pattern, suggesting this change fixes a mismatch between test expectations and implementation.


🤖 Automated review by Claude AI - focused on identifying issues for improvement

Copy link
Owner

@ding113 ding113 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

This PR improves the prompt_limit error rule regex pattern to handle two different API error message formats. The change is minimal, well-targeted, and correctly implements the stated goal.

🔍 Issues Found

  • Critical (🔴): 0 issues
  • High (🟠): 0 issues
  • Medium (🟡): 0 issues
  • Low (🟢): 0 issues

🎯 Priority Actions

No issues requiring action were identified. The change is ready for merge.

💡 General Observations

  1. Regex correctness verified: The new pattern prompt is too long.*(tokens.*maximum|maximum.*tokens) correctly matches both orderings:

    • prompt is too long...tokens...maximum
    • prompt is too long...maximum...tokens
  2. No ReDoS vulnerability: The pattern was tested with adversarial inputs (up to 1000 characters between tokens) and completed in <1ms.

  3. Backward compatible: The new pattern matches all strings that the old pattern matched, plus the additional format.

  4. Test alignment: The existing test suite uses test strings that align with the new regex pattern, suggesting this change fixes a mismatch between test expectations and implementation.


🤖 Automated review by Claude AI - focused on identifying issues for improvement

@ding113 ding113 merged commit 6529ea7 into ding113:dev Nov 28, 2025
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Extra Small PR (< 50 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants