Skip to content

feat(core): make system prompt immutable after session creation#33241

Closed
0byte-coding wants to merge 2 commits into
anomalyco:devfrom
0byte-coding:fix/immutable-system-prompt
Closed

feat(core): make system prompt immutable after session creation#33241
0byte-coding wants to merge 2 commits into
anomalyco:devfrom
0byte-coding:fix/immutable-system-prompt

Conversation

@0byte-coding

@0byte-coding 0byte-coding commented Jun 21, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #29672

Type of change

  • New feature
  • Bug fix
  • Refactor / code improvement
  • Documentation

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:

  • Session initialization caches the system prompt correctly
  • Subsequent requests retrieve the cached prompt instead of regenerating it
  • Cache lookups return the exact same prompt object

What it does NOT do

  • System prompt is not persisted across OpenCode restarts, so a cache miss can happen after restart
  • Does not tell other sessions that the prompt changed; clients handle dynamic updates via mechanisms like <system-reminder> for things like date changes

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found several PRs related to system prompt handling and caching:

Potentially Related PRs:

  1. PR fix(cache): improve Anthropic prompt cache hit rate with system split and tool stability #14743 - fix(cache): improve Anthropic prompt cache hit rate with system split and tool stability

    • Related to improving prompt cache hit rates through system prompt manipulation
  2. PR fix(session): move env block to tail of system prompt for cache stability #29949 - fix(session): move env block to tail of system prompt for cache stability

    • Related to system prompt structure and cache stability for sessions
  3. PR feat: improve deepseek prompt cache reuse #31867 - feat: improve deepseek prompt cache reuse

    • Related to prompt caching mechanisms across different providers

These PRs address related concerns about system prompt caching and session-level prompt stability, though none appear to be direct duplicates. PR #33241 (the current PR) takes a more comprehensive approach with in-memory HashMap-based caching per session, while the others focus on specific provider optimizations or structural changes for cache stability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Modify system prompt to improve cache hit rate

1 participant