rohitg00/agentmemory · error · Error

POST ${url} failed: ${res.status} ${res.statusText}${suffix}

Error message

POST ${url} failed: ${res.status} ${res.statusText}${suffix}

What it means

This error is thrown by the CLI's internal HTTP POST helper when the iii-engine/agentmemory daemon responds with a non-2xx status. The message includes the URL, HTTP status code, status text, and up to 200 chars of the response body to help diagnose the server-side failure. It wraps any failed POST the CLI makes (session seed, events, etc.).

Source

Thrown at src/cli.ts:2841

    return null;
  }
}

async function postJsonStrict<T = unknown>(
  url: string,
  body: unknown,
  timeoutMs = 5000,
): Promise<T | null> {
  const res = await fetch(url, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(body),
    signal: AbortSignal.timeout(timeoutMs),
  });
  if (!res.ok) {
    const errBody = await res.text().catch(() => "");
    const suffix = errBody ? ` — ${errBody.slice(0, 200)}` : "";
    throw new Error(`POST ${url} failed: ${res.status} ${res.statusText}${suffix}`);
  }
  return (await res.json().catch(() => null)) as T | null;
}

async function seedDemoSession(
  base: string,
  project: string,
  session: DemoSession,
): Promise<number> {
  await postJsonStrict(`${base}/agentmemory/session/start`, {
    sessionId: session.id,
    project,
    cwd: project,
  });

  let stored = 0;
  for (const obs of session.observations) {
    const url = `${base}/agentmemory/observe`;

View on GitHub (pinned to e04ba88819)

Solutions

  1. Read the status and body suffix in the message to identify the server-side cause (404 = wrong path/version, 400 = bad payload, 401 = auth).
  2. Verify the daemon is running and the base URL/port matches (check AGENTMEMORY_URL or the default localhost endpoint with curl).
  3. Confirm CLI and daemon versions match; restart the daemon after upgrading.
  4. Retry the command once the daemon responds correctly; for transient 5xx add retry logic around the call.

Example fix

// before
await post(`${base}/agentmemory/events`, payload);
// after
try {
  await post(`${base}/agentmemory/events`, payload);
} catch (e) {
  console.error('daemon request failed, is agentmemory running at', base, e.message);
}
Defensive patterns

Strategy: try-catch

Validate before calling

const url = new URL(base + path);
if (!/^https?:$/.test(url.protocol)) throw new Error('bad URL');

Try / catch

try {
  const data = await post(url, body);
} catch (e) {
  if (e.message.includes(' 401 ')) handleAuthError();
  else if (e.message.includes(' 404 ')) handleVersionMismatch();
  else if (/ 5\d\d /.test(e.message)) scheduleRetry();
  else throw e;
}

Prevention

When it happens

Trigger: Any CLI command that POSTs to the REST API where the daemon returns 4xx/5xx: wrong port/URL, daemon not running (connection refused surfaces differently but 502/504 possible), invalid payload rejected with 400, auth denied with 401/403, or endpoint version mismatch.

Common situations: AGENTMEMORY_URL points at a stale port; the daemon crashed or was upgraded so the route no longer exists (404); a proxy returns 502; the CLI version sends fields the daemon rejects.

Related errors


AI-assisted analysis of rohitg00/agentmemory@e04ba88819 (2026-08-30). Data as JSON: /api/errors/0b2ef33802bcc97a. Report an issue: GitHub.