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
[Bug]Deep clone of entire message history causes 30+ second delay with 200 messages #10187
Deep clone of entire message history causes 30+ second delay with 200 messages
Description
In long sessions (~200 messages), sending a new message takes 30+ seconds before getting any response. The delay is caused by a deep clone of the entire message history on every loop iteration.
Location
packages/opencode/src/session/prompt.ts, line 573:
constsessionMessages=clone(msgs)
Why this is slow
The clone() function from remeda recursively copies:
Every message object
Every part (text, tool calls, attachments)
All nested content including large tool outputs
With 200 messages × 5 parts each = 1000+ objects deep cloned per iteration.
Plugins
No response
OpenCode version
Latest
Steps to reproduce
Build up a session with 100+ messages (long refactoring task)
Send a new message
Wait 30+ seconds before the model starts responding
changed the title [-]Deep clone of entire message history causes 30+ second delay with 200 messages[/-][+][Bug]Deep clone of entire message history causes 30+ second delay with 200 messages[/+]on Jan 23, 2026
Reproduced this issue on latest main commit and took a flamegraph with bun run --cpu-prof src/index.ts serve while continuing a long session.
This causes 100% CPU usage and really slow conversation. The PR #10190 seems to be fixing this issue properly.
After fixing that cloning issue the flamegraph looks something like
This can be fixed with a 1-line patch like const sessionMessages = clone(msgs) -> const sessionMessages = step > 1 && lastFinished ? structuredClone(msgs) : msgs utilizing Bun fast structuredClone.
Activity
[-]Deep clone of entire message history causes 30+ second delay with 200 messages[/-][+][Bug]Deep clone of entire message history causes 30+ second delay with 200 messages[/+]github-actions commentedon Jan 23, 2026
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if none of these address your specific case.
perf(opencode): replace deep clone with lazy shallow copy in prompt loop
Jaakkonen commentedon Feb 19, 2026
Reproduced this issue on latest main commit and took a flamegraph with
bun run --cpu-prof src/index.ts servewhile continuing a long session.This causes 100% CPU usage and really slow conversation. The PR #10190 seems to be fixing this issue properly.
After fixing that cloning issue the flamegraph looks something like
This can be fixed with a 1-line patch like
const sessionMessages = clone(msgs)->const sessionMessages = step > 1 && lastFinished ? structuredClone(msgs) : msgsutilizing Bun fast structuredClone.github-actions commentedon Apr 21, 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.