[Bug]: Dynamic runtime context blocks in system prompt invalidate tools KV cache across sessions and workspaces

Open
#638 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript

Research direction

Start by tracing where the system prompt, tool definitions, and runtime context blocks are assembled; the issue does not name specific files or tests. Check how session and workspace context enters the request, then verify that the system and tools prefix stays invariant across sessions while the context remains available in messages. Done means this ordering is covered by an appropriate test.

Written by the indexing model from the issue text.

Description

Summary

Because prefix caching evaluates requests in system → tools → messages order, embedding workspace- and session-specific runtime context blocks directly in system invalidates the KV cache for both system and the entire tools definition block on every new session or workspace switch.

Current Behavior

Dynamic/workspace-dependent sections (environment/OS/cwd/date, session info, memory, skills, project instructions / AGENTS.md, etc.) are placed directly into the system prompt.

As a result:

  • Changing workspace, project instructions, memory, or session metadata changes the system prefix.
  • Because tools sit after system in the prefix cache (system → tools → messages), the entire tools schema block misses the cache at session startup, even though tool definitions are identical across sessions and projects.
Expected Behavior / Suggestion

Remove the dynamic/workspace-dependent runtime context blocks from system (keeping system strictly static and invariant across sessions/workspaces) and place those runtime context blocks after tools (in messages).

This keeps the system + tools prefix stable and reusable across new sessions and workspaces, giving immediate token/cost and latency savings from cache hits right from the start of each session.

Dominant language
TypeScript
Stars
2.3k
Forks
315
Avg merge
3h 54m
Merged PRs (30d)
9

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from MiniMax-AI/minimax-code

All issues in MiniMax-AI/minimax-code

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.