Commit Graph

57 Commits

Author SHA1 Message Date
Peter Steinberger
bcbfb357be refactor(src): split oversized modules 2026-01-14 01:17:56 +00:00
Peter Steinberger
e8779ac329 fix: handle Anthropic overloaded_error gracefully (#832) (thanks @danielz1z) 2026-01-13 08:32:06 +00:00
danielz1z
36725ce153 fix: handle Anthropic overloaded_error gracefully
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)
2026-01-13 08:18:59 +00:00
Peter Steinberger
9faa95d558 fix: recover from compaction overflow 2026-01-13 08:03:11 +00:00
Peter Steinberger
755a7e1b20 feat: add configurable bootstrap truncation 2026-01-13 04:27:03 +00:00
Marc
c4e8b60d2c fix: strip thought_signature fields for cross-provider compatibility
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>
2026-01-13 04:11:02 +00:00
Sebastian
c4014c0092 fix: treat credential validation failures as auth errors for fallback (#761) 2026-01-12 22:53:21 -05:00
Peter Steinberger
0edbdb1948 fix: downgrade Gemini tool history 2026-01-13 01:19:13 +00:00
Peter Steinberger
48fdf3775d test: cover user turn merging 2026-01-13 00:42:15 +00:00
Peter Steinberger
6f75feaeb8 refactor: reuse model selection assertions 2026-01-13 00:20:08 +00:00
Peter Steinberger
ce23c70855 fix: validate Anthropic turn order (#804) (thanks @ThomsenDrake) 2026-01-12 23:43:25 +00:00
Drake Thomsen
c5fa757ef6 fix(agents): prevent Anthropic 400 'Incorrect role information' error
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
2026-01-12 23:42:13 +00:00
Peter Steinberger
3ffb9a3b5e fix: keep session sanitizer stable 2026-01-12 18:19:30 +00:00
Peter Steinberger
44e1f271c8 fix: keep image sanitizer scoped 2026-01-12 17:55:45 +00:00
Peter Steinberger
e91aa0657e fix: add copilot tests and lint fixes 2026-01-12 17:48:08 +00:00
Peter Steinberger
f5d5661adf fix: guard session tool results 2026-01-12 17:28:46 +00:00
Keith the Silly Goose
efdf874407 fix(agent): correctly strip <final> tags from reasoning providers
- 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
2026-01-12 08:34:06 +00:00
Peter Steinberger
67743325ee fix: reset session after compaction overflow 2026-01-12 00:28:16 +00:00
Peter Steinberger
dbe156e881 fix(agents): sanitize transcripts for strict tool APIs 2026-01-11 04:46:18 +00:00
Jonathan Wilkins
0afa370869 fix: add 'usage limit' to rate limit detection patterns
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>
2026-01-10 23:11:06 +01:00
Peter Steinberger
08cc8f2281 refactor(agents): extract transcript repair module 2026-01-10 22:07:25 +00:00
Peter Steinberger
98377c7c6b fix(agents): harden tool transcript repair 2026-01-10 21:45:15 +00:00
Peter Steinberger
cf192f8551 style: biome format 2026-01-10 19:47:17 +00:00
Peter Steinberger
9f9098406c feat(sandbox): add sandbox explain inspector 2026-01-10 20:28:43 +01:00
Peter Steinberger
212b13b099 fix: repair tool-use history for anthropic 2026-01-10 19:15:57 +00:00
Peter Steinberger
7c925aa5a0 style: format helper 2026-01-10 18:15:15 +00:00
Peter Steinberger
651a9e9be4 fix: restore minimax tool calling 2026-01-10 18:15:15 +00:00
Peter Steinberger
0d98e93253 fix: harden cloud code assist tool schema sanitizing (#665) (thanks @sebslight) 2026-01-10 18:07:26 +01:00
Sebastian Barrios
64babcac7a fix(agents): harden Cloud Code Assist compatibility
- 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
2026-01-10 18:06:35 +01:00
Peter Steinberger
70c1732dd1 refactor: centralize messaging dedupe helpers 2026-01-10 16:02:56 +01:00
Peter Steinberger
53ec8e36cb refactor: centralize failover error parsing 2026-01-10 01:26:06 +01:00
Jefferson Warrior
5843733978 Fix Cloud Code Assist API errors (429/400)
- Enhanced rate limit detection for Cloud Code Assist quota exhaustion
- Added tool call ID sanitization to fix invalid request format errors
- Integrated Cloud Code Assist format error detection into failover system
- Added comprehensive error pattern matching for Cloud Code Assist APIs

Fixes #cloud-code-assist-api-errors
2026-01-10 01:10:23 +01:00
Jefferson Warrior
74485f171b CLI: fix Cloud Code Assist 400 API errors and missing session exports
- 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'
2026-01-10 01:07:51 +01:00
Peter Steinberger
374aa856f2 refactor(agents): centralize failover handling 2026-01-09 21:31:18 +01:00
Peter Steinberger
65cb9dc3f7 fix(agents): fail over on billing/credits errors 2026-01-09 21:17:07 +01:00
Peter Steinberger
e6a7429ac7 refactor: add helper for empty assistant content 2026-01-09 18:29:27 +01:00
Peter Steinberger
79b3abd797 refactor: drop empty error messages in history 2026-01-09 18:23:26 +01:00
Josh Palmer
2fae8eda66 🤖 codex: strip empty assistant blocks from history (#210) 2026-01-08 21:53:33 +01:00
mneves75
33e2d53be3 feat(telegram): wire replyToMode config, add forum topic support, fix messaging tool duplicates
Changes:
- Default replyToMode from "off" to "first" for better threading UX
- Add messageThreadId and replyToMessageId params for forum topic support
- Add messaging tool duplicate detection to suppress redundant block replies
- Add sendMessage action to telegram tool schema
- Add @grammyjs/types devDependency for proper TypeScript typing
- Remove @ts-nocheck and fix all type errors in send.ts
- Add comprehensive docs/telegram.md documentation
- Add PR-326-REVIEW.md with John Carmack-level code review

Test coverage:
- normalizeTextForComparison: 5 cases
- isMessagingToolDuplicate: 7 cases
- sendMessageTelegram thread params: 5 cases
- handleTelegramAction sendMessage: 4 cases
- Forum topic isolation: 4 cases

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-08 00:50:47 +00:00
Peter Steinberger
67d1f61872 fix: harden session caching and topic transcripts 2026-01-07 22:51:26 +00:00
hsrvc
79d8384d26 Fix Gemini API function call turn ordering errors in multi-topic conversations
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>
2026-01-07 22:51:26 +00:00
Peter Steinberger
98d4e8034d refactor(agent): centralize google turn-order fixup 2026-01-07 22:08:22 +01:00
Jonáš Jančařík
974619d285 fix(google): repair Cloud Code Assist tool-call ordering (#406) 2026-01-07 21:49:40 +01:00
alejandro maza
579828b2d5 Handle 413 context overflow errors gracefully
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
2026-01-07 19:08:13 +00:00
Peter Steinberger
e8420bd047 fix: refine bootstrap injections 2026-01-07 10:04:23 +00:00
Tobias Bischoff
412990a139 Reduce prompt token overhead with leaner context injections 2026-01-07 10:04:23 +00:00
Peter Steinberger
b04c838c15 feat!: redesign model config + auth profiles 2026-01-06 00:56:58 +00:00
Peter Steinberger
f790f3f3ba fix/heartbeat ok delivery filter (#246)
* 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>
2026-01-05 22:52:13 +00:00
CI
d9cdf3b8ac fix(model): treat quota errors as rate limits 2026-01-05 21:34:08 +00:00
CI
c627efce3e fix(model): retry with supported thinking level 2026-01-05 21:34:08 +00:00