-
-
Notifications
You must be signed in to change notification settings - Fork 52.6k
Description
Summary
The /compact command fails for non-default agents because handleCompactCommand does not forward agentDir to compactEmbeddedPiSession. This causes the compaction to always look for auth credentials in ~/.openclaw/agents/main/agent/auth-profiles.json (the hardcoded DEFAULT_AGENT_ID) instead of the correct agent directory.
Error:
⚙️ Compaction failed: No API key found for provider "anthropic".
Auth store: ~/.openclaw/agents/main/agent/auth-profiles.json
(agentDir: ~/.openclaw/agents/main/agent)
Root Cause
In handleCompactCommand, the call to compactEmbeddedPiSession omits agentDir:
// handleCompactCommand
const result = await compactEmbeddedPiSession({
sessionId,
sessionKey: params.sessionKey,
workspaceDir: params.workspaceDir,
// ❌ agentDir not passed — falls back to DEFAULT_AGENT_ID ("main")
config: params.cfg,
...
});The fallback in compactEmbeddedPiSessionDirect:
const agentDir = params.agentDir ?? resolveOpenClawAgentDir();
// resolveOpenClawAgentDir() hardcodes DEFAULT_AGENT_ID = "main"Note: The auto-compaction path (context overflow in runEmbeddedAttempt) correctly passes agentDir. Only the manual /compact command is affected.
Fix
One-liner — params.agentDir is already available in the handler scope, it just needs to be forwarded:
const result = await compactEmbeddedPiSession({
sessionId,
sessionKey: params.sessionKey,
workspaceDir: params.workspaceDir,
+ agentDir: params.agentDir,
config: params.cfg,Estimated source location: src/auto-reply/reply/get-reply-inline-actions.ts — handleCompactCommand
Reproduction
- Configure multiple agents (e.g.
work+personal) with per-agentauth-profiles.json - Do NOT have a
mainagent directory (or have it without auth) - Send
/compactto a non-default agent via Telegram - Compaction fails looking for auth in
~/.openclaw/agents/main/agent/
Environment
- OpenClaw
2026.2.17 - macOS arm64
- Two agents:
workandpersonal(nomainagent) - Patched locally in dist; will revert on update