Skip to content

fix: add adaptive memory pressure advisor to prevent madvise() storms - #1

Open
szh1118 wants to merge 14 commits into
DdogezD:mainfrom
szh1118:fix-memory-pressure-advisor-v2
Open

fix: add adaptive memory pressure advisor to prevent madvise() storms#1
szh1118 wants to merge 14 commits into
DdogezD:mainfrom
szh1118:fix-memory-pressure-advisor-v2

Conversation

@szh1118

@szh1118 szh1118 commented Apr 26, 2026

Copy link
Copy Markdown

Summary

  • Added src/utils/memoryPressureAdvisor.ts: Adaptive memory pressure monitoring module with 3-state machine (NORMAL → ELEVATED → CRITICAL) to prevent madvise() storms
  • Modified src/cli/print.ts: Replaced fixed 1-second GC interval with startMemoryPressureAdvisor() that adjusts GC frequency based on RSS memory pressure

Problem

At ~2000+ messages, React Fiber trees cause severe memory pressure. Bun's GC behavior triggers excessive mmap/munmap → madvise() storms → soft lockup.

Solution

Adaptive monitoring with RSS-based state machine that adjusts GC frequency and triggers more aggressive collection when memory pressure is elevated.

🤖 Generated with Claude Code

DdogezD and others added 14 commits April 11, 2026 09:56
Enable any OpenAI-compatible API (OpenAI, OpenRouter, DeepSeek, Ollama,
LM Studio, Together AI, Groq, Mistral, Azure OpenAI, etc.) as the
backend LLM by setting CLAUDE_CODE_USE_OPENAI=1.

New files:
- openaiShim.ts: Anthropic <-> OpenAI format translation + streaming
- codexShim.ts: ChatGPT Codex Responses API support
- providerConfig.ts: provider routing, model alias resolution

Modified files:
- client.ts: route to OpenAI shim when enabled
- providers.ts: add 'openai' provider type
- configs.ts: add openai model mappings per tier
- model.ts: respect OPENAI_MODEL env var
- auth.ts: recognize OpenAI as valid 3P provider
- README.md: add ANTHROPIC_BASE_URL config + OpenAI provider docs
- Add CLAUDE_CODE_SUMMARY_OUTPUT_TOKENS
- Add CLAUDE_CODE_AUTO_COMPACT_BUFFER_TOKENS
- Added src/utils/memoryPressureAdvisor.ts: adaptive memory monitoring with 3-state machine
- Modified src/cli/print.ts: replaced fixed 1-second GC interval with startMemoryPressureAdvisor()
@DdogezD
DdogezD force-pushed the main branch 8 times, most recently from 80656b6 to 43bf03f Compare June 29, 2026 06:34
@DdogezD
DdogezD force-pushed the main branch 7 times, most recently from 1e52c4b to 013fa0e Compare July 8, 2026 11:36
@DdogezD
DdogezD force-pushed the main branch 23 times, most recently from ce91207 to 080ff89 Compare July 11, 2026 19:41
DdogezD added a commit that referenced this pull request Jul 12, 2026
P0 #2: mapToolResultToToolResultBlockParam now prepends a banner
"[Advisor interrupted — reason: ...]" when the advisor was interrupted,
so the main agent can distinguish partial advice from completed analysis.

P0 #3: ADVISOR_SYSTEM_PROMPT now requires separating verified facts,
likely inferences, and unresolved unknowns.  Root causes must be backed
by direct evidence; tool absence must be reported as an observation,
not assumed to be a specific layer's fault.

P0 #1: Add 15 new tests (26 total):
- Module import smoke test (catches init-order crashes)
- ConversationLogTool creation and getUniqueReadCount
- Mixed-script tokenizer (测试API, API测试)
- BM25 search index, OR/ALL modes, empty results
- ConversationLog index: empty, manifest, offset, 60K budget
- ConversationLog search: no results, >64 tokens, 60K budget
- ConversationLog read: existing IDs, NOT FOUND, dedup
- Snapshot fingerprint consistency
- formatEntryLabel: USER, ASSISTANT, thinking, success/error marks
@DdogezD
DdogezD force-pushed the main branch 6 times, most recently from 5a8b9fb to 688c15c Compare July 13, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants