Repository navigation
Description
Regression after d53a513 (#1664): agent-sdk fallback silently overrides a configured OpenAI-compatible provider; compression retry loop spawns headless claude sessions
Summary
Commit d53a513 (PR #1664) replaced provider auto-detection with an explicit
AGENTMEMORY_LLM_PROVIDER opt-in. For users upgrading from ≤0.9.31 with an existing
~/.agentmemory/.env that contains both a working OPENAI_API_KEY (OpenAI-compatible
endpoint, e.g. DeepSeek) and AGENTMEMORY_ALLOW_AGENT_SDK=true, the upgrade silently
switches all LLM compression from their configured provider to the claude-agent-sdk
fallback — spawning headless claude CLI child sessions that authenticate with the
ambient Claude Code login and burn the user's Claude subscription quota.
In our incident this combined with two further gaps (retry queue ignores
AGENTMEMORY_AUTO_COMPRESS=false; every new observation still gets one ungated
compression dispatch) into a self-sustaining loop: with the Claude quota exhausted,
each retry spawned a new headless claude.exe, every ~40–90 seconds for hours —
11–12 concurrent instances (~2.8 GB RAM), each initializing the full MCP stack from
~/.claude.json (12 serena processes), and enough failed session starts that the
account got flagged by Anthropic.
Environment
- agentmemory 0.9.33 (daemon via Worker Compose, native Windows 11)
~/.agentmemory/.env(relevant keys):AGENTMEMORY_ALLOW_AGENT_SDK=true # carried over from earlier experiments OPENAI_API_KEY=sk-... # DeepSeek OPENAI_BASE_URL=https://api.deepseek.com OPENAI_MODEL=deepseek-chat # AGENTMEMORY_LLM_PROVIDER not set (upgraded from 0.9.31 where it was not needed)
Before / after
≤ 0.9.31 (detectProvider) |
0.9.33 (after d53a513) | |
|---|---|---|
| Provider chosen with the env above | openai (auto-detected from OPENAI_API_KEY) → DeepSeek |
noop → agent-sdk fallback → headless claude.exe using the Claude Code login |
| Compression traffic | DeepSeek API | Claude subscription quota |
| If the provider fails | DeepSeek error, no side effects | Retry loop spawns a new claude session per attempt |
Reproduction
- Configure the env above on a machine with Claude Code logged in.
- Let observations flow (any capture hooks) until a batch triggers compression.
- Watch
claude.exe(path:node_modules/@anthropic-ai/claude-agent-sdk-win32-x64/)
spawn per compression call, each starting MCP servers from~/.claude.json. - Exhaust the Claude quota → every call fails →
compression-recoveryre-dispatches
indefinitely (see related bugs) → process pile-up.
Incident chain (verified live, 2026-11-11/12)
- Compression dispatched via
AgentSDKProvider→ headlessclaude.exeper batch. - Each
claude.exeinitializes the full Claude Code MCP stack (~/.claude.json),
including serena — so the symptom surfaced as "serena processes multiplying". - Quota exhausted →
compression_failed→ observation retained for retry. compression-recoveryre-dispatched regardless of
AGENTMEMORY_AUTO_COMPRESS=false(set early in the incident — did not help).- New observations kept receiving one ungated compression dispatch despite the flag.
- Net: ~1 new
claude.exe+serena every 40–90 s for ~4 h; 53+ "retained for compression
retry" warnings in one worker-log window; account/IP flagged by Anthropic.
Worker log, line 2 (the tool's own warning — present but easy to miss in daemon stdout):
stderr [agentmemory] WARNING: agent-sdk fallback enabled via AGENTMEMORY_ALLOW_AGENT_SDK=true.
This spawns @anthropic-ai/claude-agent-sdk child sessions ...
Related bugs found during the incident (candidates for separate issues)
compression-recoveryignoresAGENTMEMORY_AUTO_COMPRESS=false— keeps LLM-retrying
a feature the user disabled.- New observations get one ungated
mem::compressdispatch even with the flag off. mem::compressfails withcompression_failedvia the OpenAI-compatible provider
(DeepSeek) whilemem::summarizesucceeds on the same provider — compress path bug.- Engine crashes at startup (<100 ms, misleading
os error 5) when allengine.log*
are exactly at the 10 MiB rotation cap incompose-state; workaround: move logs away. .envtemplate shipsAGENTMEMORY_ALLOW_AGENT_SDK=truewith a leading space
(line 64) — fragile against dotenv parsing differences.
Suggested fixes
- Provider precedence: never let the agent-sdk fallback win over a configured
OPENAI_API_KEY/explicit provider; at minimum emit a loud migration warning on
upgrade when auto-detection previously selected a provider and no
AGENTMEMORY_LLM_PROVIDERis set. - Gate
compression-recoveryand the per-observation dispatch behind
AGENTMEMORY_AUTO_COMPRESS=false(mark backlog synthetic instead of retrying). - Investigate the compress-vs-summarize asymmetry on OpenAI-compatible providers.
- Fix startup rotation with capped logs; surface the real engine error instead of the
secondaryos error 5. - Remove the leading space in the
.envtemplate.
Workaround (current production config here)
AGENTMEMORY_AUTO_COMPRESS=false
AGENTMEMORY_ALLOW_AGENT_SDK=false
AGENTMEMORY_LLM_PROVIDER=openai # explicit; routes retries to DeepSeekVerified: zero claude.exe spawns over 10+ minutes of heavy observation traffic;
summarization works via DeepSeek (qualityScore 100).
Evidence available on request
- Live process listings during the incident (12×
claude.exewith command lines/RAM,
12× serena with parents, spawner chainiii.exe → node dist/index.mjs → claude.exe) - Worker-log excerpts with original line numbers (
retained for compression retry×53) - 21 client-side session transcripts (
~/.claude/projects/...) created by the spawned
SDK sessions in the incident window agentmemory-incident-evidence-20261112.txt,agentmemory-log-fragments-20261112.txt
Activity
nobyArdor commentedon Nov 11, 2026
Evidence 1: live process listings during the incident
Evidence 2: worker-log fragments (original line numbers preserved, skips marked)