Skip to content

Bug: /compact command ignores agent-specific auth (missing agentDir param) #23812

@0xSatoriSync

Description

@0xSatoriSync

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.tshandleCompactCommand

Reproduction

  1. Configure multiple agents (e.g. work + personal) with per-agent auth-profiles.json
  2. Do NOT have a main agent directory (or have it without auth)
  3. Send /compact to a non-default agent via Telegram
  4. Compaction fails looking for auth in ~/.openclaw/agents/main/agent/

Environment

  • OpenClaw 2026.2.17
  • macOS arm64
  • Two agents: work and personal (no main agent)
  • Patched locally in dist; will revert on update

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions