[Bug] gateway: OpenCode `Instructions from:` in splitMemory swallows trailing date, environment and skills blocks (fix branch)
magpie version
v0.1.5312
Where
GUI
OS
Windows 11
Agent, provider and model
OpenCode → magpie (local gateway)
Steps to reproduce
- On OpenCode with an empty
~/.claude/CLAUDE.md(0 bytes, fallback when noAGENTS.mdexists), start a session routed through magpie. - Open the Context window card in magpie GUI (or inspect
Route.Prompt/PromptText) and click theCLAUDE.mdmemory entry.
What happened, and what you expected
What happened:
The empty CLAUDE.md is shown as taking ~1.6K tokens, and clicking it displays OpenCode's Today's date:, <env> block, worktree note, and any trailing proxy-appended text (such as billion-context's instructions) inside the CLAUDE.md memory item.
Expected:
Instructions from: <path> stops before OpenCode's date, environment, or skills sections, so an empty CLAUDE.md accounts for only its header (~10 tokens) and the environment/harness sections remain under System prompt.
Root cause
In internal/gateway/prompt.go, splitMemory matches OpenCode's Instructions from: <path> via instructionsFrom and records openCodeish: true on the section, but never bounds where the section ends (unlike piFileEnd for s.pi). As a result, chunk runs all the way to the next instruction section, </system-reminder>, or the end of the message.
Fix branch & verification
Since external PRs are restricted to collaborators, a fix with regression tests is available on my fork branch:
- Branch: https://github.com/wthsama/magpie/tree/fix/opencode-memory-end
- Commit:
091003364(baseebac9bbc5) - Summary: add
openCodeFileEndfors.openCodeishsections insplitMemoryso it stops beforeToday's date:,Here is some useful information about the environment you are running in:,The environment you are running in is now:,<env>, and OpenCode/Agent-Skills blocks.
Verification (Windows 11, go1.27.3, sandboxed temp HOME):
- Red on
main(withoutopenCodeFileEnd):TestPromptOfOpenCodeMemoryEndsfailed withenvironment block was swallowed into memory: "". - Green with fix:
go test -v -tags nogui ./internal/gateway -run "TestPrompt|TestSplitSkills|TestFilesOfCommand"passed (2.908s). gofmt -l internal/gateway/prompt.go internal/gateway/prompt_test.go: clean.go vet -tags nogui ./...,GOOS=linux go vet -tags nogui ./..., andGOOS=windows go vet -tags nogui ./...: all passed.- Not run: full
go test -tags nogui ./...suite and Playwright GUI suite.