Skip to content

OAuth credentials saved to wrong path - WhatsApp auto-reply fails to find them #338

Description

@swiftlysingh

Bug Description

WhatsApp auto-reply fails with "No credentials found for profile X" even though OAuth credentials were successfully saved via clawdbot onboard or clawdbot configure.

Root Cause

Credentials are saved to one path but loaded from a different path:

Action Path Used
onboard/configure saves credentials ~/.clawdbot/agent/auth-profiles.json
WhatsApp auto-reply loads credentials ~/.clawdbot/agents/main/agent/auth-profiles.json

Where the Issue Occurs

Saving (uses global agent dir)

File: src/agents/agent-paths.ts

export function resolveClawdbotAgentDir(): string {
  const defaultAgentDir = path.join(resolveConfigDir(), "agent");
  // Returns: ~/.clawdbot/agent/
}

Loading (uses per-agent dir)

File: src/agents/agent-scope.ts

export function resolveAgentDir(cfg: ClawdbotConfig, agentId: string) {
  // ...
  return path.join(root, "agents", id, "agent");
  // Returns: ~/.clawdbot/agents/main/agent/
}

File: src/auto-reply/reply.ts (line ~231)

const agentDir = resolveAgentDir(cfg, agentId);
// This agentDir is passed to runEmbeddedPiAgent → ensureAuthProfileStore(agentDir)

Workaround

Manually copy the credentials file:

mkdir -p ~/.clawdbot/agents/main/agent
cp ~/.clawdbot/agent/auth-profiles.json ~/.clawdbot/agents/main/agent/auth-profiles.json

Suggested Fix

In src/agents/auth-profiles.ts, make ensureAuthProfileStore() fall back to the global agent dir:

export function ensureAuthProfileStore(agentDir?: string): AuthProfileStore {
  const authPath = resolveAuthStorePath(agentDir);
  const raw = loadJsonFile(authPath);
  const asStore = coerceAuthStore(raw);
  if (asStore) return asStore;

  // NEW: Fall back to global agent dir if per-agent path not found
  const globalAuthPath = resolveAuthStorePath(resolveClawdbotAgentDir());
  if (globalAuthPath !== authPath) {
    const globalRaw = loadJsonFile(globalAuthPath);
    const globalStore = coerceAuthStore(globalRaw);
    if (globalStore) return globalStore;
  }

  // ... rest of legacy migration code
}

Alternatively, make onboard/configure save to the per-agent location (or both).

Environment

  • Clawdbot version: 2026.1.5-3
  • OS: macOS + Ubuntu (reproduced on both)
  • Auth mode: OAuth (google-antigravity and anthropic providers)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions