feat(core): make system prompt immutable after session creation - #33246
0byte-coding wants to merge 5 commits into
Conversation
|
The following comment was made by an LLM, it may be inaccurate: Based on the search results, I found several related PRs that involve system prompt and caching optimizations: Potentially Related PRs:
These PRs address similar domains of system prompt caching and session initialization, though none appear to be exact duplicates of PR #33246's specific implementation (in-memory HashMap caching per session ID). However, PRs #31867, #14743, and #29949 are closest in addressing cache efficiency and system prompt immutability concepts. |
|
Bumping this — it's still the right fix, and it's more urgent than when it was filed. Credit for the approach goes to @0byte-coding (original #33246); it had gone Why it's urgent. The system prompt is rebuilt on every request — Evidence: two consecutive requests with byte-identical Fix + validation. Freeze the environment + instruction + MCP system parts once per session (on the first LLM call) and reuse them for the session's lifetime, keeping skills fresh. Rebased onto current
(#47816 handles the date-only case; this is the general fix.) |
The system prompt is rebuilt on every LLM call, re-reading the instruction files (AGENTS.md / memory.md), git status, and the calendar date. Any change to those — a mid-session AGENTS.md edit, or the date rolling over at midnight — mutates the prefix and forces a full re-prefill of the whole conversation. Compute the environment + instruction + MCP system parts once per session on the first LLM call and reuse them for the session's lifetime, keeping the cached prefix stable. Skills stay computed per call. The per-session map is capped at 2048 entries. Rebased onto current dev from anomalyco#33246 by @0byte-coding. Co-authored-by: 0byte-coding <git@susnext.com> Co-Authored-By: OpenCode <noreply@opencode.ai>
Issue for this PR
Closes #29672
Type of change
What does this PR do?
Caches the system prompt in-memory per session ID so it becomes immutable after the session is created. This prevents unnecessary cache misses when the same session makes multiple requests.
The implementation stores system prompts in a HashMap keyed by session ID. This is very minimal and focused - just enough to lock the prompt after initialization.
How did you verify your code works?
I tested locally that:
Screenshots / recordings
N/A - This is not a UI change
Checklist