magpie icon indicating copy to clipboard operation
magpie copied to clipboard

[Bug] gateway: OpenCode `Instructions from:` in splitMemory swallows trailing date, environment and skills blocks (fix branch)

Open wthsama opened this issue 4 days ago • 0 comments

magpie version

v0.1.5312

Where

GUI

OS

Windows 11

Agent, provider and model

OpenCode → magpie (local gateway)

Steps to reproduce

  1. On OpenCode with an empty ~/.claude/CLAUDE.md (0 bytes, fallback when no AGENTS.md exists), start a session routed through magpie.
  2. Open the Context window card in magpie GUI (or inspect Route.Prompt / PromptText) and click the CLAUDE.md memory 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 (base ebac9bbc5)
  • Summary: add openCodeFileEnd for s.openCodeish sections in splitMemory so it stops before Today'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 (without openCodeFileEnd): TestPromptOfOpenCodeMemoryEnds failed with environment 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 ./..., and GOOS=windows go vet -tags nogui ./...: all passed.
  • Not run: full go test -tags nogui ./... suite and Playwright GUI suite.

wthsama avatar Dec 01 '26 18:12 wthsama