fix: add adaptive memory pressure advisor to prevent madvise() storms - #1
Open
szh1118 wants to merge 14 commits into
Open
fix: add adaptive memory pressure advisor to prevent madvise() storms#1szh1118 wants to merge 14 commits into
szh1118 wants to merge 14 commits into
Conversation
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
force-pushed
the
main
branch
8 times, most recently
from
June 29, 2026 06:34
80656b6 to
43bf03f
Compare
DdogezD
force-pushed
the
main
branch
7 times, most recently
from
July 8, 2026 11:36
1e52c4b to
013fa0e
Compare
DdogezD
force-pushed
the
main
branch
23 times, most recently
from
July 11, 2026 19:41
ce91207 to
080ff89
Compare
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
force-pushed
the
main
branch
6 times, most recently
from
July 13, 2026 21:34
5a8b9fb to
688c15c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/utils/memoryPressureAdvisor.ts: Adaptive memory pressure monitoring module with 3-state machine (NORMAL → ELEVATED → CRITICAL) to prevent madvise() stormssrc/cli/print.ts: Replaced fixed 1-second GC interval withstartMemoryPressureAdvisor()that adjusts GC frequency based on RSS memory pressureProblem
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