Skip to content

fix(agent): route reasoning_content to reasoning channel#1907

Merged
yinwm merged 1 commit intosipeed:mainfrom
xiwuqi:wuxi/fix-reasoning-channel-content
Mar 23, 2026
Merged

fix(agent): route reasoning_content to reasoning channel#1907
yinwm merged 1 commit intosipeed:mainfrom
xiwuqi:wuxi/fix-reasoning-channel-content

Conversation

@xiwuqi
Copy link
Copy Markdown
Contributor

@xiwuqi xiwuqi commented Mar 23, 2026

📝 Description

Fixes the reasoning channel regression behind #1746: OpenAI-compatible providers can return reasoning in reasoning_content, but PicoClaw did not forward that content to the configured reasoning channel.

Problem summary:

  • reasoning_channel_id is expected to receive model reasoning for channels such as Telegram.
  • OpenAI-compatible providers can populate reasoning_content while leaving reasoning empty.
  • PicoClaw detected that reasoning existed, but the reasoning channel received nothing.

Root cause:

  • pkg/agent/loop.go passed only response.Reasoning into handleReasoning().
  • For OpenAI-compatible providers, the preserved reasoning often lives in response.ReasoningContent, so the publish path saw an empty string and returned early.

What changed:

  • Keep the existing response.Reasoning path unchanged when it is populated.
  • Fall back to response.ReasoningContent before calling handleReasoning().
  • Add a regression test that reproduces the OpenAI-compatible case and verifies the reasoning message is delivered to the configured channel.

Why this fix:

  • It is the smallest change that directly addresses the reported failure without broadening provider normalization behavior.
  • It preserves the current priority of response.Reasoning and only uses response.ReasoningContent when needed.

Risk / compatibility:

  • Low risk. This only affects the reasoning-channel publish path, and only when response.Reasoning is empty.
  • Providers that already populate response.Reasoning keep their existing behavior.

🗣️ Type of Change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 📖 Documentation update
  • ⚡ Code refactoring (no functional changes, no api changes)

🤖 AI Code Generation

  • 🤖 Fully AI-generated (100% AI, 0% Human)
  • 🛠️ Mostly AI-generated (AI draft, Human verified/modified)
  • 👨‍💻 Mostly Human-written (Human lead, AI assisted or none)

🔗 Related Issue

Fixes #1746

📚 Technical Context (Skip for Docs)

🧪 Test Environment

  • Hardware: PC
  • OS: Windows (local development environment)
  • Model/Provider: N/A (agent/unit tests only)
  • Channels: Telegram (simulated via channel manager test double)

📸 Evidence (Optional)

Click to view Logs/Screenshots

Passed:

  • go test ./pkg/agent -run TestProcessMessage_PublishesReasoningContentToReasoningChannel -count=1
  • go test ./pkg/agent -run TestHandleReasoning -count=1
  • go test ./pkg/providers/openai_compat -count=1

Additional broader validation:

  • go test ./pkg/agent -count=1 still fails in TestGlobalSkillFileContentChange.
  • I reproduced that same failure on a clean upstream/main worktree at commit 3500080, so it is pre-existing and not introduced by this PR.
  • codex review --base origin/main could not run in this environment because the local Codex config rejected approvals_reviewer = never.

☑️ Checklist

  • My code/docs follow the style of this project.
  • I have performed a self-review of my own changes.
  • I have updated the documentation accordingly.

@sipeed-bot sipeed-bot Bot added type: bug Something isn't working domain: agent go Pull requests that update go code labels Mar 23, 2026
Copy link
Copy Markdown
Collaborator

@yinwm yinwm left a comment

Choose a reason for hiding this comment

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

LGTM! This is a well-targeted bug fix with minimal code changes.

Summary:

  • Fixes the regression where reasoning_channel_id did not work with OpenAI-compatible providers
  • Root cause: handleReasoning only received response.Reasoning, which is empty for OpenAI-compatible providers
  • Fix: Fallback to response.ReasoningContent when response.Reasoning is empty

Why approve:

  1. Minimal change - 4 lines added, 1 modified
  2. Correct priority - keeps Reasoning as primary source
  3. Comprehensive regression test added
  4. Low risk - only affects reasoning channel publish path
  5. Directly addresses issue 1746

Thanks @xiwuqi!

@yinwm yinwm merged commit 2c48cd3 into sipeed:main Mar 23, 2026
4 checks passed
@yinwm yinwm mentioned this pull request Mar 27, 2026
10 tasks
andressg79 pushed a commit to andressg79/picoclaw that referenced this pull request Mar 30, 2026
…-content

fix(agent): route reasoning_content to reasoning channel
ra1phdd pushed a commit to ra1phdd/picoclaw-pkg that referenced this pull request Apr 12, 2026
…-content

fix(agent): route reasoning_content to reasoning channel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: agent go Pull requests that update go code type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] reasoning_channel_id not working with OpenAI-compatible provider in v0.2.3 despite PR #604

2 participants