openclaw - 💡(How to fix) Fix [Feature]: Session prep phase (~48s) re-executes on EVERY turn, not cached within session [4 comments, 5 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#76186Fetched 2026-05-03 04:41:09
View on GitHub
Comments
4
Participants
5
Timeline
6
Reactions
3
Author
Timeline (top)
commented ×4labeled ×1unsubscribed ×1

Every user message within the same session triggers a full rebuild of the prep pipeline costing ~48-50 seconds before the model even starts generating. system-prompt, core-plugin-tools, and stream-setup are re-executed from scratch on every turn, with no session-level caching.

Root Cause

Every user message within the same session triggers a full rebuild of the prep pipeline costing ~48-50 seconds before the model even starts generating. system-prompt, core-plugin-tools, and stream-setup are re-executed from scratch on every turn, with no session-level caching.

Code Example

runId=d07b3925  prep=48.8s  (turn 1)
runId=9c8ec9da  prep=48.6s  (turn 2)
runId=d2713a35  prep=49.7s  (turn 3)
runId=e13a1265  prep=49.1s  (turn 4)
runId=9dbe850f  prep=50.1s  (turn 5)
runId=cd10c082  prep=138.5s (turn 6, after disconnect — context grew large)
runId=6ba9c856  prep=48.2s  (turn 7)
runId=3a745e1a  prep=49.3s  (turn 8)
runId=08013320  prep=47.5s  (turn 9, current)
RAW_BUFFERClick to expand / collapse

Summary

Every user message within the same session triggers a full rebuild of the prep pipeline costing ~48-50 seconds before the model even starts generating. system-prompt, core-plugin-tools, and stream-setup are re-executed from scratch on every turn, with no session-level caching.

Problem to solve

Environment

  • OpenClaw version: v2026.4.29
  • Node: v22.22.0
  • OS: macOS 15.4 (arm64)
  • Model: deepseek/deepseek-v4-pro, thinking=high, 1M context window
  • Workspace context: ~4.3KB of project files (AGENTS.md, SOUL.md, MEMORY.md, etc.)

Evidence

9 consecutive turns within the same session (sessionId=8a344dc3-c8de-43f8-b667-8a47cb30ac24), each showing identical prep overhead:

runId=d07b3925  prep=48.8s  (turn 1)
runId=9c8ec9da  prep=48.6s  (turn 2)
runId=d2713a35  prep=49.7s  (turn 3)
runId=e13a1265  prep=49.1s  (turn 4)
runId=9dbe850f  prep=50.1s  (turn 5)
runId=cd10c082  prep=138.5s (turn 6, after disconnect — context grew large)
runId=6ba9c856  prep=48.2s  (turn 7)
runId=3a745e1a  prep=49.3s  (turn 8)
runId=08013320  prep=47.5s  (turn 9, current)

Per-stage breakdown (from [trace:embedded-run] prep stages log entries):

StageAvg TimeEvery Turn?
system-prompt assembly~24s✅ Yes
core-plugin-tools loading~14s✅ Yes
stream-setup~7s✅ Yes
Others (bootstrap, sandbox, etc.)~3s✅ Yes
Total prep~48s

Real user experience: 48s prep + ~20s model inference + tool call execution = 65-80s per message.

Proposed solution

Expected Behavior

Within a single session, system-prompt content (workspace files, identity, tool schemas) does not change between turns. These should be computed once at session start and reused. core-plugin-tools schemas are also static within a session. Only the conversation context delta should need recomputation.

Suggestion

Cache system-prompt, core-plugin-tools, and stream-setup results within the session lifetime. Recompute only when the underlying inputs change (e.g., workspace files modified on disk, tool list changed). This would reduce per-turn overhead from ~48s to ~3-5s (bootstrap-context only), a 10x improvement for multi-turn conversations.

Alternatives considered

No response

Impact

Impact

This makes long conversations (10+ turns) extremely painful. For reference, with a 48s fixed overhead per turn:

  • 5 turns: ~4 minutes of pure prep overhead
  • 10 turns: ~8 minutes of pure prep overhead
  • 20 turns: ~16 minutes of pure prep overhead

The user literally waits more time for prep than for actual model generation.

Evidence/examples

No response

Additional information

No response

extent analysis

TL;DR

Cache system-prompt, core-plugin-tools, and stream-setup results within a session to reduce per-turn overhead.

Guidance

  • Identify the inputs that change between turns and only recompute when necessary, such as workspace files modified on disk or tool list changes.
  • Implement a caching mechanism for system-prompt, core-plugin-tools, and stream-setup results, with a lifetime tied to the session.
  • Measure the performance impact of caching on per-turn overhead to ensure the expected 10x improvement.
  • Consider logging cache hits and misses to monitor the effectiveness of the caching strategy.

Example

No code snippet is provided as the issue does not contain sufficient implementation details.

Notes

The proposed solution assumes that the inputs to system-prompt, core-plugin-tools, and stream-setup do not change frequently within a session. If this assumption is incorrect, the caching strategy may not yield the expected performance improvement.

Recommendation

Apply a caching workaround to reduce per-turn overhead, as it has the potential to significantly improve the user experience for long conversations.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix [Feature]: Session prep phase (~48s) re-executes on EVERY turn, not cached within session [4 comments, 5 participants]