Add comprehensive integration tests demonstrating that re-running sanitization
after limitHistoryTurns correctly handles:
- Orphaned tool_result blocks (when tool_use is separated by compaction)
- Consecutive assistant messages
- Complex scenarios with both issues
- Preservation of valid tool pairings
These tests verify the fix in PR #4736 works as intended.
After limitHistoryTurns or compaction operations, the message history can
end up with:
1. Orphaned tool_result blocks (tool_use IDs not in preceding message)
2. Consecutive assistant messages that violate API format requirements
Root cause: sanitizeToolUseResultPairing and turn validation functions
(validateGeminiTurns, validateAnthropicTurns) were only running BEFORE
limitHistoryTurns, but history limiting can create new issues by cutting
off tool_use blocks or creating consecutive assistant messages during
compaction.
Solution: Re-run both sanitizeToolUseResultPairing and turn validation
AFTER limitHistoryTurns in both main code paths:
- src/agents/pi-embedded-runner/run/attempt.ts
- src/agents/pi-embedded-runner/compact.ts
This ensures tool_use/tool_result pairing is maintained and consecutive
assistant/user messages are properly merged after any history modification.
Changes:
- Added transcriptPolicy checks before applying repairs (respects config)
- Re-run validateGeminiTurns after sanitizeToolUseResultPairing
- Re-run validateAnthropicTurns after validateGeminiTurns
- Added import for sanitizeToolUseResultPairing in compact.ts
OAuth credentials with a refresh token auto-renew on first API call,
so the doctor should not warn about access token expiration when a
refresh token is present. This avoids unnecessary "expired" warnings
that prompt users to re-auth when no action is needed.
Fixes#3032
Co-authored-by: Ayush Ojha <ayushozha@outlook.com>
Fixes#4529
The moltbot compatibility package was broken because bin/moltbot.js
was missing. This file is referenced in package.json but was never
created during the openclaw rename.
This commit adds the missing binary that:
- Forwards all commands to openclaw
- Shows clear deprecation warning
- Guides users to migrate to openclaw package
Without this fix, users who upgraded from moltbot to openclaw by
git pull could not use the gateway because their global moltbot
installation had no working binary.
Test: node packages/moltbot/bin/moltbot.js --version
(requires built openclaw)
Unify style and link closing in render.ts to use LIFO order across
both element types, fixing cases where bold/italic spans containing
autolinks produced invalid HTML like <b><a></b></a>.
The react action used readStringParam for messageId and chatId, which
rejected numeric values with a misleading "messageId required" error.
Switched to readStringOrNumberParam to match the delete/edit actions.
Closes#1459
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Fixes#4038
The global fetch in Node.js doesn't support undici's dispatcher option,
which is required for ProxyAgent to work. This fix imports fetch from
undici directly to enable proper proxy support for Telegram API calls.
Root cause: makeProxyFetch() was using global fetch with { dispatcher: agent },
but Node.js's global fetch ignores the dispatcher option. Using undici.fetch
ensures the ProxyAgent dispatcher is properly respected.
Tested: Build passes, TypeScript compilation successful.
Implements WebSocket ping/pong keepalive mechanism to prevent random
disconnects with close code 1006 (abnormal closure).
Changes:
- Add 20-second ping interval when WebSocket connection is open
- Monitor pong responses for connection health
- Enhanced error and close event logging with detailed diagnostics
- Clean up ping interval when connection closes
This fix addresses the root cause of issue #4142 where network
intermediaries (NAT, firewalls, proxies) timeout idle WebSocket
connections. The 20-second ping interval is industry standard practice
for preventing idle connection timeouts.
Fixes#4142
Fixes#4107
Problem:
- Cron jobs with systemEvent payloads enqueue events as passive text
- Agent sees events but doesn't autonomously process them
- Expected behavior: agent should execute complex tasks (spawn subagents, etc.)
Root Cause:
- systemEvents are injected as 'System: [timestamp] text' messages
- Standard heartbeat prompt is passive: 'Read HEARTBEAT.md... reply HEARTBEAT_OK'
- No explicit instruction to process and act on systemEvents
- Exec completion events already had directive prompt, but generic events didn't
Solution:
- Added SYSTEM_EVENT_PROMPT constant with directive language
- Modified heartbeat runner to detect generic (non-exec) systemEvents
- When generic events are present, use directive prompt instead of passive one
- Directive prompt explicitly instructs agent to:
1. Check HEARTBEAT.md for event-specific handling
2. Execute required actions (spawn subagent, perform task, etc.)
3. Reply HEARTBEAT_OK only if no action needed
Changes:
- src/infra/heartbeat-runner.ts:
- Added SYSTEM_EVENT_PROMPT constant (lines 100-105)
- Modified prompt selection logic to detect generic systemEvents (lines 510-523)
- Updated Provider field to reflect 'system-event' context
Testing:
- Build passes (TypeScript compilation successful)
- Pattern follows existing exec-event precedent
- Backward compatible (only affects sessions with pending systemEvents)
Follow-up:
- Add integration test for cron → subagent spawn workflow
- Update documentation on systemEvent best practices
- Enhanced SubagentRunOutcome type with errorType and errorHint fields
- Added categorizeError() helper to classify common error patterns:
* File system errors (ENOENT, EACCES, etc.)
* API/model errors (rate limits, auth failures, invalid requests)
* Network errors (connection refused, DNS failures)
* Timeout errors
* Configuration errors (missing credentials, quota limits)
- Updated error emission in agent-runner-execution.ts to categorize errors
- Updated subagent-registry.ts to capture and propagate new error fields
- Added buildErrorStatusLabel() helper for user-friendly error messages
- Error announcements now include error type and remediation hints
Example improved messages:
- Before: 'failed: unknown error'
- After: 'failed (tool error): ENOENT — File or directory not found'
This makes subagent failures much easier to understand and debug while
maintaining backward compatibility.
The message processing pipeline had a synchronization bug where
limitHistoryTurns() truncated conversation history AFTER
repairToolUseResultPairing() had already fixed tool_use/tool_result
pairings. This could split assistant messages (with tool_use) from
their corresponding tool_result blocks, creating orphaned tool_result
blocks that the Anthropic API rejects.
This fix calls sanitizeToolUseResultPairing() AFTER limitHistoryTurns()
to repair any pairings broken by truncation, ensuring the transcript
remains valid before being sent to the LLM API.
Changes:
- Added import for sanitizeToolUseResultPairing from session-transcript-repair.js
- Call sanitizeToolUseResultPairing() on the limited message array
- Updated variable name from 'limited' to 'repaired' for clarity
registerTelegramNativeCommands() calls listSkillCommandsForAgents()
without passing agentIds, causing ALL agents' skill commands to be
registered on EVERY Telegram bot. When multiple agents share skill
names (e.g. two agents both have a "butler" skill), the shared `used`
Set in listSkillCommandsForAgents causes de-duplication suffixes
(_2, _3) and all commands appear on every bot regardless of agent
binding.
This fix uses the existing resolveAgentRoute() (already imported) to
find the bound agent for the current Telegram accountId, then passes
that agentId to listSkillCommandsForAgents(). The function already
accepts an optional agentIds parameter — it just wasn't wired from
the Telegram registration path.
Before: All agents' skill commands registered on every Telegram bot,
causing /butler_2, /housekeeper_2 dedup suffixes and potential
BOT_COMMANDS_TOO_MUCH errors when total exceeds 100.
After: Each Telegram bot only registers skill commands for its own
bound agent. No cross-agent dedup, no command limit overflow.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat: add Kimi K2.5 model to synthetic catalog
Add hf:moonshotai/Kimi-K2.5 to the synthetic model catalog.
This model is available via dev.synthetic.new API.
- 256k context window
- 8192 max tokens
- Supports reasoning
* chore: fix formatting in onboard-helpers.ts
* fix: update config candidate ordering test (#4407) (thanks @manikv12)
---------
Co-authored-by: Peter Steinberger <steipete@gmail.com>
Resolves#4315. The slug-generator embedded run was hardcoded to use
DEFAULT_MODEL (claude-opus-4-5) regardless of the user's configured
agents.defaults.model.primary. This caused unexpected Opus charges on
every /new command.
Now uses resolveDefaultModelForAgent() to honor the user's configured
default model, falling back to DEFAULT_MODEL only when no config exists.
Replaced the static image with a responsive logo using the <picture> element for light/dark mode support. Updated contributor name from 'Clawd' to 'Molty'.
Replaces the previous ASCII art in both the CLI banner and the wizard header with a new, wider design and updates the label to 'OPENCLAW' for consistency.