You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf: prompt loop loads entire conversation history into memory on every step #18136
The prompt loop in prompt.ts calls filterCompacted(stream(sessionID)) on every iteration of its while(true) loop. For long-running sessions (e.g., 7,704 messages, 27,895 parts, ~91MB of data), this loads the entire conversation history into JS heap on each tool-call step.
The loaded WithParts[] array (~300MB after V8 object expansion) is then passed through toModelMessages → convertToModelMessages → ProviderTransform.message → convertToLanguageModelPrompt — 4-5 copy layers creating ~60MB of wrapper objects each. With 10-50 tool-call steps per prompt, peak RSS reaches 4-8GB.
Two issues compound this:
No context windowing: all messages are converted to ModelMessage format even though only ~200 fit in the LLM context window (~200K tokens ≈ 800KB of text)
No compaction boundary optimization: filterCompacted streams through all messages loading parts eagerly, even for compacted sessions where only messages after the boundary are needed
Steps to reproduce
Use opencode for several days with active sessions (1000+ messages)
Activity
docs(memory): add SQLite mmap and upstream issue findings to baseline
github-actions commentedon Jul 3, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.