Skip to content

fix(agents): avoid classifying reasoning-required errors as context overflow#24593

Merged
vincentkoc merged 3 commits intomainfrom
vincentkoc-code/fix-24520-reasoning-overflow
Feb 23, 2026
Merged

fix(agents): avoid classifying reasoning-required errors as context overflow#24593
vincentkoc merged 3 commits intomainfrom
vincentkoc-code/fix-24520-reasoning-overflow

Conversation

@vincentkoc
Copy link
Member

@vincentkoc vincentkoc commented Feb 23, 2026

Summary

  • Problem: provider invalid-request errors like Reasoning is mandatory for this endpoint and cannot be disabled. could be misrouted into context-overflow handling.
  • Why it matters: users see misleading Context overflow guidance and embedded recovery paths may attempt the wrong remediation.
  • What changed: added explicit reasoning-constraint exclusions in overflow classifiers and a dedicated user-facing message in assistant error formatting.
  • What did NOT change (scope boundary): no model/provider routing changes, no compaction policy changes, and no fallback-chain behavior changes outside this specific error classification path.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

  • Invalid-request responses that state reasoning is required (for example, Reasoning is mandatory for this endpoint and cannot be disabled.) are no longer treated as context overflow.
  • Users now receive a direct remediation message: enable reasoning (/think minimal or another non-off level) and retry.

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (No)
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node 22+, pnpm
  • Model/provider: OpenRouter-style invalid-request payloads for reasoning-required endpoints
  • Integration/channel (if any): embedded agent error formatting/classification
  • Relevant config (redacted): N/A

Steps

  1. Feed formatAssistantErrorText / overflow classifiers with 400 Reasoning is mandatory for this endpoint and cannot be disabled.
  2. Verify overflow detectors return false.
  3. Verify formatted output provides reasoning-required remediation, not context overflow.

Expected

  • No context-overflow classification for reasoning-required invalid-request errors.
  • Friendly message points users to enabling reasoning.

Actual

  • Before this fix, these messages could be funneled into context-overflow handling in downstream recovery paths.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: updated tests for isContextOverflowError, isLikelyContextOverflowError, and formatAssistantErrorText for reasoning-required messages.
  • Edge cases checked: JSON-wrapped invalid-request message variants and generic requires reasoning phrasing.
  • What you did not verify: live provider/channel end-to-end run.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: revert the three commits in this PR.
  • Files/config to restore: src/agents/pi-embedded-helpers/errors.ts, related tests.
  • Known bad symptoms reviewers should watch for: reasoning-required errors still being surfaced as context overflow.

Risks and Mitigations

  • Risk: matching text could miss alternate provider wording for reasoning constraints.
    • Mitigation: guard covers multiple common phrases and includes JSON-wrapped variants in tests.

Greptile Summary

This PR prevents reasoning-constraint invalid-request errors from being misclassified as context overflow errors by adding explicit exclusions in overflow classifiers and a dedicated user-facing message.

Key changes:

  • Added isReasoningConstraintErrorMessage() helper that checks for phrases like "reasoning is mandatory", "reasoning is required", "requires reasoning", or "reasoning" + "cannot be disabled"
  • Updated isContextOverflowError() and isLikelyContextOverflowError() to exclude reasoning-constraint errors before checking overflow patterns
  • Added user-friendly message in formatAssistantErrorText() directing users to enable reasoning with /think minimal
  • Comprehensive test coverage across all three functions with multiple test cases including JSON-wrapped variants

The fix follows the same pattern as the recent Groq TPM fix (commit 652099c) by adding early-exit guards to prevent false classification.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are narrow in scope, well-tested, and follow established patterns in the codebase. The new guard is positioned correctly as an early exclusion before overflow checks. Test coverage is thorough with multiple variants including JSON-wrapped errors. No logic bugs or edge cases identified.
  • No files require special attention

Last reviewed commit: de2f65c

@openclaw-barnacle openclaw-barnacle bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Feb 23, 2026
@vincentkoc vincentkoc marked this pull request as ready for review February 23, 2026 15:36
@vincentkoc vincentkoc merged commit 4f340b8 into main Feb 23, 2026
30 checks passed
@vincentkoc vincentkoc deleted the vincentkoc-code/fix-24520-reasoning-overflow branch February 23, 2026 15:38
vincentkoc added a commit that referenced this pull request Feb 23, 2026
jaydiamond42 pushed a commit to jaydiamond42/bloomtbot that referenced this pull request Feb 23, 2026
…verflow (openclaw#24593)

* Agents: exclude reasoning-required errors from overflow detection

* Tests: cover reasoning-required overflow classification guard

* Tests: format reasoning-required endpoint errors
jaydiamond42 pushed a commit to jaydiamond42/bloomtbot that referenced this pull request Feb 23, 2026
carlosrivera pushed a commit to myascendai/meshiclaw that referenced this pull request Feb 23, 2026
…verflow (openclaw#24593)

* Agents: exclude reasoning-required errors from overflow detection

* Tests: cover reasoning-required overflow classification guard

* Tests: format reasoning-required endpoint errors
carlosrivera pushed a commit to myascendai/meshiclaw that referenced this pull request Feb 23, 2026
mreedr pushed a commit to mreedr/openclaw-custom that referenced this pull request Feb 24, 2026
…verflow (openclaw#24593)

* Agents: exclude reasoning-required errors from overflow detection

* Tests: cover reasoning-required overflow classification guard

* Tests: format reasoning-required endpoint errors
mreedr pushed a commit to mreedr/openclaw-custom that referenced this pull request Feb 24, 2026
plgs2005 pushed a commit to plgs2005/openclaw that referenced this pull request Feb 24, 2026
…verflow (openclaw#24593)

* Agents: exclude reasoning-required errors from overflow detection

* Tests: cover reasoning-required overflow classification guard

* Tests: format reasoning-required endpoint errors
plgs2005 pushed a commit to plgs2005/openclaw that referenced this pull request Feb 24, 2026
margulans pushed a commit to margulans/Neiron-AI-assistant that referenced this pull request Feb 25, 2026
…verflow (openclaw#24593)

* Agents: exclude reasoning-required errors from overflow detection

* Tests: cover reasoning-required overflow classification guard

* Tests: format reasoning-required endpoint errors
margulans pushed a commit to margulans/Neiron-AI-assistant that referenced this pull request Feb 25, 2026
brianleach pushed a commit to brianleach/openclaw that referenced this pull request Feb 26, 2026
…verflow (openclaw#24593)

* Agents: exclude reasoning-required errors from overflow detection

* Tests: cover reasoning-required overflow classification guard

* Tests: format reasoning-required endpoint errors
brianleach pushed a commit to brianleach/openclaw that referenced this pull request Feb 26, 2026
mylukin pushed a commit to mylukin/openclaw that referenced this pull request Feb 26, 2026
…verflow (openclaw#24593)

* Agents: exclude reasoning-required errors from overflow detection

* Tests: cover reasoning-required overflow classification guard

* Tests: format reasoning-required endpoint errors
mylukin pushed a commit to mylukin/openclaw that referenced this pull request Feb 26, 2026
r4jiv007 pushed a commit to r4jiv007/openclaw that referenced this pull request Feb 28, 2026
…verflow (openclaw#24593)

* Agents: exclude reasoning-required errors from overflow detection

* Tests: cover reasoning-required overflow classification guard

* Tests: format reasoning-required endpoint errors
r4jiv007 pushed a commit to r4jiv007/openclaw that referenced this pull request Feb 28, 2026
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 1, 2026
(cherry picked from commit 5e1dd5f)

# Conflicts:
#	CHANGELOG.md
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 3, 2026
(cherry picked from commit 5e1dd5f)

# Conflicts:
#	CHANGELOG.md
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…verflow (openclaw#24593)

* Agents: exclude reasoning-required errors from overflow detection

* Tests: cover reasoning-required overflow classification guard

* Tests: format reasoning-required endpoint errors
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Context overflow on fresh session with Kimi K2.5 via OpenRouter — likely error misclassification

1 participant