mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2175] [CLOSED] serve: "env_to_user" (opt-in) moves opencode's <env> block into the first user message (new session's first request 11.9 -> 1.1 s) #3903
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3903
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2175
Author: @zsariboga
Created: 10/12/2026
Status: ❌ Closed
Base:
main← Head:pr-env-to-user📝 Commits (1)
f5f0300serve: "env_to_user" (opt-in) moves opencode's block into the first user message, so a new folder or day reuses the cached system prompt (11.9 -> 1.1 s first request)📊 Changes
4 files changed (+116 additions, -2 deletions)
View changed files
📝
docs/DETAILS.md(+7 -0)📝
serve/frontend.py(+38 -2)📝
serve/server.py(+5 -0)➕
serve/test_env_to_user.py(+66 -0)📄 Description
What
"env_to_user": trueinstrata-<model>.json(opt-in): opencode's<env>block (with its "Here is some usefulinformation about the environment you are running in:" line) is taken out of the system message and put at the front of
the first user message, for OpenAI and Anthropic requests (string content, or a leading text part before content parts).
Without the key nothing changes.
Why
opencode writes the block (working directory, today's date) near the start of its system message, about 3,000 characters
in, before ~41,000 characters of instructions and tool definitions that are the same in every session. The prefix cache
(and
--prefix-cache-diron disk) only reuses a prompt's start, so every new folder and every new day read the wholesystem turn again: ~14K tokens, 8-12 s on a 12 GB laptop, before the first token of every new session. I captured two
first requests from two folders with a fake server: the block was the only difference in the system message.
With the block in the user turn the system turn (and the tools the template writes into it) is the same for every
session, and the cache restores it. The model still reads the same lines, one turn later.
Measured
RTX 5070 Ti Laptop 12 GB, Swift 1.5 IQ3_XXS,
--prefix-cache-diron, opencode, a new session in a second folder:env_to_useroffenv_to_useronQuality check: a task that asks for the working directory and the date answered both correctly 3/3 with the switch on.
On my machine's history, 34 such cold reads averaged 10.3 s each.
Tests
serve/test_env_to_user.py(6): the block moves, two folders give the same system turn, content parts get a leading textpart, Anthropic requests too, and off / no block changes nothing.
serve/test_frontend.pypasses.docs/DETAILS.mdhas aparagraph next to
tool_call_recovery.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.