| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
The system prompt was being joined into a single string, which meant the static agent/provider prompt and dynamic content (environment info, instruction files) shared one cache breakpoint. Any change in dynamic content (e.g. instruction files modified by the agent, date rollover) invalidated the entire cache, causing 100% cache miss. Split into two separate system messages: - Message 1: Static agent/provider prompt (stable across all calls) - Message 2: Dynamic content (environment, instructions, user system) This allows Anthropic's prompt caching to cache the static prefix independently, enabling cache hits on subsequent calls within a session.
|
Hey! Your PR title prompt caching issue ifx doesn't follow conventional commit format. Please update it to start with one of:
Where scope is the package name (e.g., app, desktop, opencode). See CONTRIBUTING.md for details. |
Sorry, something went wrong.
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found one potentially related PR:
The searches suggest these are related to different issues, but both deal with prompt caching. Since PR #14203 specifically closes issue #14065, they appear to be addressing separate prompt caching concerns rather than being exact duplicates. |
Sorry, something went wrong.
There was a problem hiding this comment.
Adjusts how system prompts are assembled for LLM.stream to improve provider prompt-caching effectiveness (aiming to address low/zero cache hit rate reported in #14065).
Changes:
packages/opencode/src/session/llm.ts:100
const header = system[0]
const original = clone(system)
await Plugin.trigger(
"experimental.chat.system.transform",
{ sessionID: input.sessionID, model: input.model },
{ system },
)
if (system.length === 0) {
system.push(...original)
}
if (system.length > 2 && system[0] === header) {
const rest = system.slice(1)
system.length = 0
system.push(header, rest.join("\n"))
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
| const system: string[] = [] | ||
|
|
||
| const staticPrompt = [ | ||
| ...(input.agent.prompt ? [input.agent.prompt] : isCodex ? [] : SystemPrompt.provider(input.model)), | ||
| ] | ||
| .filter((x) => x) | ||
| .join("\n") | ||
|
|
||
| if (staticPrompt) system.push(staticPrompt) | ||
|
|
||
| const dynamicPrompt = [ | ||
| ...input.system, | ||
| ...(input.user.system ? [input.user.system] : []), | ||
| ] | ||
| .filter((x) => x) | ||
| .join("\n") | ||
|
|
||
| if (dynamicPrompt) system.push(dynamicPrompt) |
There was a problem hiding this comment.
This change introduces new behavior that splits system prompts into static vs dynamic parts to improve prompt caching, but there’s no test asserting the resulting messages structure (e.g., that the first system message stays constant when input.system / user.system changes, and that dynamic content is isolated in a later system message). Since this file already has request-shape tests for LLM.stream, adding an assertion against the captured request payload would prevent regressions in caching behavior.
Sorry, something went wrong.
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Sorry, something went wrong.
…mpt caching (upstream PR anomalyco#14203)
|
Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Issue for this PR
Closes #14065
Type of change
What does this PR do?
In llm.ts lines 67-80, the entire system prompt (static agent/provider prompt + dynamic environment info + dynamic instruction files) is joined into a single string via .join("\n") and pushed as one entry to the system array.
This causes 100% cache miss because:
The fix splits the system prompt construction into two separate entries:
This works with existing infrastructure:
How did you verify your code works?
Traced the full code path from prompt.ts → llm.ts → transform.ts → applyCaching() to confirm:
Screenshots / recordings
N/A — backend change, no UI impact.
Checklist