Skip to Content
IssuesBrand Scorer: cwd undefined — All Brand Scoring Calls Crash

Brand Scorer: cwd undefined — All Brand Scoring Calls Crash

Status: Fixed Severity: High — brand voice scores never stored; every social post and landing page silently skips scoring File: packages/agents/src/lib/brand-scorer.ts Observed: 2026-05-06 00:36 onwards (all social post and landing page completions)

Symptom

ERROR [brand-scorer] Brand scoring failed with exception TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined at mkdir (node:internal/fs/promises:855:10) at execute (packages/adapters/claude-local/src/server/execute.ts:72:11) at scoreBrandVoice (packages/agents/src/lib/brand-scorer.ts:65:26) at async Worker.processLandingPageWriterJob (landing-page-writer.worker.ts:405:24)

Fires on every social post, landing page, and blog post completion. Brand scores are never stored in the DB — brandScore, brandIssues, brandScoredAt always null.

Root Cause

scoreBrandVoice() calls the Claude adapter without a cwd in the config:

// BROKEN const result = await adapter({ config: { model: "claude-haiku-4", // wrong model ID dangerouslySkipPermissions: true, timeoutSec: 30, // cwd: MISSING }, ... });

execute.ts:72 calls mkdir(config.cwd, { recursive: true }) unconditionally. config.cwd is undefined -> mkdir(undefined) throws ERR_INVALID_ARG_TYPE.

Secondary issue: model: "claude-haiku-4" is not a valid model ID. The correct ID is "claude-haiku-4-5-20251001".

Fix Applied

packages/agents/src/lib/brand-scorer.ts:

// Added imports import path from "path"; import os from "os"; // Added cwd variable before the try block const cwd = path.join(os.tmpdir(), "leadmetrics-agents", tenantId, "brand-scorer"); // Updated adapter config config: { cwd, model: "claude-haiku-4-5-20251001", dangerouslySkipPermissions: true, allowedTools: [], maxTurnsPerRun: 1, timeoutSec: 60, },

Requires agents server restart to take effect.

Affected Workers

  • social-post-writer.worker.ts — scores every generated social post
  • landing-page-writer.worker.ts — scores every generated landing page
  • blog-writer.worker.ts — scores every generated blog post

© 2026 Leadmetrics — Internal use only