1 Commits
Author SHA1 Message Date
yetone 6bc5702cd4 agent: magpie's OpenCode provider sets setCacheKey, so OpenCode sends its session's prompt_cache_key (#5468)
mariamatrix (#5468) and mahiro233 on Discord: magpie writes OpenCode's
magpie provider with @ai-sdk/openai-compatible and only baseURL/apiKey, so
OpenCode sends no prompt_cache_key and an upstream that caches by it misses.
Checked against OpenCode's source and real runs (sandbox HOME on mote, a
recording Chat server):
- 2.2.5: v1/config/migrate.ts maps options.setCacheKey to
  compatibility.supportsPromptCacheKey, and openai-chat.ts sends
  prompt_cache_key only then. Without it: no key; with it:
  "prompt_cache_key":"ses_…" on the turn and the title request. A config
  with magpie's provider under providers, compatibility.supportsPromptCacheKey
  true, sends it too; without, none.
- 1.19.5: setCacheKey true sends camelCase promptCacheKey (the previous
  commit sends it on as prompt_cache_key).
- 2.0.25: ignores the option; the run answers as before, no error.

Now:
- the "opencode" shape's options have setCacheKey: true. Every writer of
  provider.magpie goes through it and openCodeKept: OpenCode, its
  OPENCODE_CONFIG_DIR copies, MiMo Code, DevEco, Air's OpenCode and
  OpenChamber's.
- openCodeNative writes it as OpenCode 2 does: compatibility
  .supportsPromptCacheKey, not a setting.
- a setCacheKey the file has already under provider.magpie.options, or a
  supportsPromptCacheKey under providers.magpie.compatibility, is the
  user's (false too) and stays, through a sync and a pick.
Kilo has no wiring in magpie; no other agent's config has this option.
TestAirProviderWritesKeepCustomFields compared every option as a string;
it now compares a bool as its JSON.

Run on mote: go test ./internal/agent (full package) ok; go test -run
'OpenCode|CacheKey|Air|OpenChamber|Deveco|Mimo|KeepTheir' ./internal/agent
./internal/gateway ok; go vet on darwin, GOOS=linux, GOOS=windows; go
build ./... (darwin, windows); gofmt clean.
Broken by hand, each failing TestOpenCodeSetsCacheKey: no setCacheKey in
the shape ("no setCacheKey"); no keep under provider ("the user's false not
kept"); no keep under providers (same); no move out of settings
("setCacheKey in OpenCode 2's settings").
Not tried: a config written by a running magpie fed to a real OpenCode
(the real runs used configs of the same shape, written by hand); a real
upstream's cache hit rate before and after.

Reported-by: mariamatrix
Reported-by: mahiro233
2026-11-06 15:02:53 +08:00