When Anthropic's API returns an overloaded_error (temporary capacity issue),
the raw JSON error was being sent to users instead of a friendly message.
Changes:
- Add overloaded error pattern detection
- Return user-friendly message for overloaded errors
- Classify overloaded as failover-worthy (triggers retry logic)
Claude's extended thinking feature generates thought_signature fields
(message IDs like "msg_abc123...") in content blocks. When these are
sent to Google's Gemini API, it expects Base64-encoded bytes and
rejects Claude's format with a 400 error.
This commit adds stripThoughtSignatures() to remove these fields from
assistant message content blocks during sanitization, enabling session
histories to be shared across different providers (e.g., Claude → Gemini).
Fixes cross-provider session bug where switching from Claude-thinking
to Gemini (or vice versa) would fail with:
"Invalid value at 'thought_signature' (TYPE_BYTES), Base64 decoding failed"
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add validateAnthropicTurns() to merge consecutive user messages that can
occur when steering messages are injected during streaming. This prevents
the API from rejecting requests due to improper role alternation.
Changes:
- Add validateAnthropicTurns() function in pi-embedded-helpers.ts
- Integrate validation into sanitization pipeline in pi-embedded-runner.ts
- Add user-friendly error message for role ordering errors
- Add comprehensive tests for the new validation function
- Added src/utils/provider-utils.ts to track reasoning provider logic
- Updated isReasoningTagProvider to loosely match 'google-antigravity' (fixes sub-models)
- Enabled enforceFinalTag in reply.ts when provider matches
- Verified <final> tag stripping logic in pi-embedded-subscribe.ts
- Updated pi-embedded-runner to use consistent provider check for prompt hints
OpenAI/ChatGPT returns "You have hit your ChatGPT usage limit (plus plan)"
when users exceed their plan quota. This error wasn't being recognized as a
rate limit, so fallback to alternative models wasn't triggering.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Expand schema scrubber to strip additional constraint keywords rejected
by Cloud Code Assist (examples, minLength, maxLength, minimum, maximum,
multipleOf, pattern, format, minItems, maxItems, uniqueItems,
minProperties, maxProperties)
- Extend tool call ID sanitization to cover toolUse and toolCall block
types (previously only functionCall was sanitized)
- Update pi-tools test to include 'examples' in unsupported keywords
Fixes 400 errors when using google-antigravity/claude-opus-4-5-thinking:
- tools.N.custom.input_schema: JSON schema is invalid
- messages.N.content.N.tool_use.id: String should match pattern
- Add sanitizeToolCallId() to fix Cloud Code Assist tool call ID validation
- Apply sanitization in sanitizeSessionMessagesImages() for toolResult and assistant messages
- Add legacy CONFIG_PATH_CLAWDIS and STATE_DIR_CLAWDIS exports for backward compatibility
- Resolves Cloud Code Assist rejection of invalid tool call IDs with pipe characters
- Fixes missing session export functions that were blocking system startup
Addresses Cloud Code Assist API 400 errors from invalid tool call IDs like 'call_abc123|item_456'
Add conversation turn validation to prevent "400 function call turn comes immediately
after a user turn or after a function response turn" errors when using Gemini models
in multi-topic/multi-channel Telegram conversations.
Changes:
1. Added validateGeminiTurns() function to detect and fix turn sequence violations
- Merges consecutive assistant messages into single message
- Preserves metadata (usage, stopReason, errorMessage) from later message
- Handles edge cases: empty arrays, single messages, tool results
2. Applied validation at two critical message points in pi-embedded-runner.ts:
- Compaction flow (lines 674-678): Before compact() call
- Normal agent run (lines 989-993): Before replaceMessages() call
3. Comprehensive test coverage with 8 test cases:
- Empty arrays and single messages
- Alternating user/assistant sequences (no change needed)
- Consecutive assistant message merging with metadata preservation
- Tool result message handling
- Real-world corrupted sequences with mixed content types
Testing:
✓ All 7 test cases pass (pi-embedded-helpers.test.ts)
✓ Full build succeeds with no TypeScript errors
✓ No breaking changes to existing functionality
This is Phase 1 of a two-phase fix:
- Phase 1 (completed): Turn validation to suppress Gemini errors
- Phase 2 (pending): Root cause analysis of why history gets corrupted with topic switching
🤖 Generated with Claude Code
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
When the conversation context exceeds the model's limit, instead of
throwing an opaque error or returning raw JSON, we now:
1. Detect context overflow errors (413, request_too_large, etc.)
2. Return a user-friendly message explaining the issue
3. Suggest using /new or /reset to start fresh
This prevents the assistant from becoming completely unresponsive
when context grows too large (e.g., from many screenshots or long
tool outputs).
Addresses issue #394
* cron: skip delivery for HEARTBEAT_OK responses
When an isolated cron job has deliver:true, skip message delivery if the
response is just HEARTBEAT_OK (or contains HEARTBEAT_OK at edges with
short remaining content <= 30 chars). This allows cron jobs to silently
ack when nothing to report but still deliver actual content when there
is something meaningful to say.
Media is still delivered even if text is HEARTBEAT_OK, since the
presence of media indicates there's something to share.
* fix(heartbeat): make ack padding configurable
* chore(deps): update to latest
---------
Co-authored-by: Josh Lehman <josh@martian.engineering>