fix: Telegram polling regression and thinking blocks corruption (AI-assisted)#20050
fix: Telegram polling regression and thinking blocks corruption (AI-assisted)#20050Vaibhavee89 wants to merge 9 commits intoopenclaw:mainfrom
Conversation
f2f296a to
6304baa
Compare
Fix three critical bugs affecting v2026.2.17: 1. Telegram polling/media fetch broken (openclaw#20020, openclaw#20027) - Revert autoSelectFamily default from true to false for Node 22+ - The Happy Eyeballs algorithm was causing connection timeouts - Users can explicitly enable via OPENCLAW_TELEGRAM_ENABLE_AUTO_SELECT_FAMILY 2. Thinking blocks corruption during compaction (openclaw#20039) - Add thinking-block-guard module to safely preserve thinking blocks - Fix sanitizeAntigravityThinkingBlocks to never strip thinking blocks - Per Anthropic API: thinking blocks must remain byte-for-byte identical - Drop entire messages rather than partially modifying thinking content 3. Enhanced safeguards and documentation - Add warnings when thinking blocks are being summarized - Document thinking block preservation requirements - Add comprehensive test suite for thinking block handling Changed files: - src/telegram/network-config.ts (revert autoSelectFamily default) - src/telegram/fetch.ts (update comments) - src/telegram/network-config.test.ts (update test expectations) - src/agents/thinking-block-guard.ts (new guard utilities) - src/agents/thinking-block-guard.test.ts (new test suite) - src/agents/pi-embedded-runner/google.ts (fix thinking block handling) - src/agents/pi-extensions/compaction-safeguard.ts (add warnings) - src/agents/session-transcript-repair.ts (add documentation) - THINKING_BLOCKS_FIX.md (comprehensive fix documentation) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Fix formatting and linting issues detected by CI: - Add blank lines after markdown headers and before lists - Sort imports alphabetically - Break long arrays onto multiple lines for readability - Replace 'any' with 'unknown' in tests per eslint rules Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Fix TypeScript compilation errors in tests: - Add helper function to create properly typed mock AssistantMessage objects - Include all required fields (api, provider, model, usage, stopReason) - Remove unnecessary 'unknown' type assertions - Use proper type casting for edge cases (invalid/redacted thinking blocks) This ensures tests compile correctly while maintaining test validity. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Fix TypeScript compilation errors: - Use correct usage structure (input/output instead of inputTokens/outputTokens) - Add 'as const' assertions for literal types (api, stopReason, type fields) - Use 'as unknown as AssistantMessage' for test mocks with edge cases - This ensures proper type checking while allowing test edge cases Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Fix TS2742 error: 'The inferred type of createModelAuthMockModule cannot be named without a reference to @vitest/spy'. Solution: Declare resolveApiKeyForProvider with explicit type annotation before assigning vi.fn(), preventing TypeScript from inferring internal vitest types that aren't portable. This resolves the pre-existing TypeScript compilation error. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Remove unnecessary type assertion per oxlint no-unnecessary-type-assertion. TypeScript can infer the type after role === 'assistant' check. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Fix TS2742 error in cron-tool.test-helpers.ts: 'The inferred type of callGatewayMock cannot be named without a reference to @vitest/spy'. Solution: Add explicit type annotation to exported const before the cast, similar to the fix applied to model-auth-mock.ts. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
2cd3577 to
ac2a6b8
Compare
Use isThinkingBlock() from thinking-block-guard module instead of manual type check. This correctly handles both 'thinking' and 'redacted_thinking' blocks, ensuring messages with only redacted_thinking blocks are properly dropped per Anthropic API requirements. Fixes code review comment: redacted_thinking blocks were incorrectly treated as non-thinking content. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Reword warning to avoid implying all N messages contain thinking blocks. The message now clarifies that we're summarizing N total messages, some of which contain thinking blocks. Fixes code review comment: misleading message count. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
|
Thanks for the substantial effort here. Right now this PR bundles two different tracks (Telegram polling + thinking-block compaction), and CI shows protocol failures. For merge readiness, please split this into focused PRs:
Also rebase on current |
|
Thanks for the feedback! I've split this PR into two focused PRs as requested:
Both PRs are rebased on the current |
|
Thanks for the large contribution and deep analysis. I’m closing this version because it bundles unrelated tracks (Telegram polling + thinking block behavior + docs) and is not viable to merge safely as one unit. Please reopen as split follow-ups with focused scope so we can review and land credit cleanly:
|
Summary
Fixes three critical bugs affecting v2026.2.17:
Issues Fixed
Changes
1. Telegram Network Fix (Issues #20020, #20027)
Root Cause: Changed autoSelectFamily default from false to true for Node 22+ in v2026.2.17, causing Happy Eyeballs timeouts with Telegram API.
Fix:
autoSelectFamilydefault back tofalsefor Node 22+OPENCLAW_TELEGRAM_ENABLE_AUTO_SELECT_FAMILYFiles:
src/telegram/network-config.tssrc/telegram/fetch.tssrc/telegram/network-config.test.ts2. Thinking Blocks Corruption Fix (Issue #20039)
Root Cause: Per Anthropic's API requirements, thinking/redacted_thinking blocks must remain byte-for-byte identical to how they were originally returned. Message transformation during compaction was inadvertently modifying or stripping these blocks.
Fix:
thinking-block-guardmodule with safe handling utilitiessanitizeAntigravityThinkingBlocks()to never strip thinking blocksFiles:
src/agents/thinking-block-guard.ts(new - 148 lines)src/agents/thinking-block-guard.test.ts(new - 166 lines)src/agents/pi-embedded-runner/google.tssrc/agents/pi-extensions/compaction-safeguard.tssrc/agents/session-transcript-repair.ts3. Documentation
THINKING_BLOCKS_FIX.md- Comprehensive documentation of the thinking blocks fix (106 lines)Testing
✅ Telegram Fix:
✅ Thinking Blocks Fix:
pnpm build && pnpm check && pnpm testwhich should be run in CI.Behavior After Fix
Telegram
Thinking Blocks
AI Assistance Details
Checklist
Files Changed
Total: 9 files, +455 lines, -7 lines
Greptile Summary
This PR fixes three issues: a Telegram polling/media fetch regression caused by Happy Eyeballs timeouts (reverts
autoSelectFamilydefault tofalsefor Node 22+), thinking blocks corruption during context compaction, and adds documentation/tests for thinking block handling.network-config.ts,fetch.ts): Clean one-line revert with updated comments and tests. Low risk.google.ts):sanitizeAntigravityThinkingBlocksnow preserves thinking blocks with invalid signatures instead of stripping them, and drops messages that have only thinking content. However, the guard only checks fortype === "thinking"and missesredacted_thinkingblocks — these will be incorrectly classified as non-thinking content, which could prevent proper message dropping.thinking-block-guard.tsmodule: Provides utilities for safe thinking block handling. OnlycontainsThinkingBlocksis used in production; the other exported functions (safeFilterAssistantContent,validateThinkingBlocks) are unused dead code.compaction-safeguard.ts): Adds aconsole.warnwhen messages with thinking blocks are about to be summarized. The warning message is slightly misleading (logs total message count, not the count of messages with thinking blocks).session-transcript-repair.ts): Adds helpful comments clarifying that thinking blocks must be preserved. No logic changes.THINKING_BLOCKS_FIX.md: Detailed standalone documentation of the fix. A standalone root-level markdown file for a single fix is unusual for this repo.Confidence Score: 3/5
redacted_thinkingblocks.sanitizeAntigravityThinkingBlocksonly checks fortype === "thinking"and missesredacted_thinkingblocks, meaning those blocks are incorrectly classified as non-thinking content. This creates an inconsistency with the new guard module and could prevent correct message dropping when onlyredacted_thinkingblocks remain.src/agents/pi-embedded-runner/google.tsneeds the guard condition extended to includeredacted_thinkingblocks.Last reviewed commit: 4c12ba1
(2/5) Greptile learns from your feedback when you react with thumbs up/down!
Context used:
dashboard- CLAUDE.md (source)dashboard- AGENTS.md (source)