Files
magpie/internal/gateway/testdata
yetone 9da9bfabdc gateway: Grok's reasoning goes back to it through a Claude, Chat or Gemini client (jenryai on X)
jenryai uses Grok through Claude Desktop and sees repeats and broken tool
calls that Grok Build doesn't make. Diffing Grok Build 1.0.67's captured
requests against magpie's: Grok Build asks for
include ["reasoning.encrypted_content"] and sends every reasoning item,
encrypted_content and all, before the function_call it led to. Through a
Messages (or Chat, Gemini) client magpie never asked for that reasoning,
and those clients have no place to keep a Responses item. So every step
of a tool loop reached Grok without the reasoning behind its earlier
calls.

Now, for a Grok plugin request from a client that isn't Responses:
- the request asks for reasoning.encrypted_content (askSealedReasoning);
- the sealed reasoning items before a call are kept on disk by hash, the
  same store as Gemini's thought signatures, and the call's id carries
  the key: <id>__rk16__<key> (carryReasoning, on both the whole and the
  streamed paths);
- on the way back afterParse strips the key from the call and its result
  and puts the items in front of that assistant turn (unreasonCalls).
  buildResponses already sends such sealed parts back.
A key magpie no longer has, or an id cut short, goes as before. A
Responses client keeps its own items and is unchanged.

The test fixture testdata/grok_reasoning_then_call.sse is a real Grok
stream (reasoning, then message, then function_call, interleaved).

Run (mote):
- at the base 85e37162e: go vet ./internal/gateway on darwin,
  GOOS=windows and GOOS=linux; go test ./internal/gateway -count=1
  -timeout 45m: ok (969.6s)
- at the pushed head, rebased on 276c806db (which changes host.js, no
  internal/gateway file): go vet ./internal/gateway and go test
  ./internal/gateway -run 'Reasoning|Sealed|Grok|Plugin|Signature'
  -count=1: ok (108.9s). The whole package was not run again there.
- real Grok account (opencode-grok-auth 0.2.3, grok-4.7, effort high)
  through a sandbox magpie built from this tree, Messages client, a
  three-call tool loop (read, read, write the sum), streamed and whole:
  both wrote 462. A mitm capture of each of the 8 upstream requests
  shows the include, and turn N carries N reasoning items
  (encrypted_content 383/179/891 bytes) before their function_calls
  under the plain call ids; every reply was 200.
Broken by hand:
- carryReasoning returning dec unchanged:
  TestGrokReasoningGoesBackThroughOtherAPIs red ("carries 0 items").
- asksSealedReasoning false: TestSealedReasoningAskedOfGrokAlone red
  ("include []" for anthropic, chat, gemini).
Not tried:
- the reporter's broken calls themselves were never reproduced (a real
  10-turn Claude Code run through the live gateway had none); the cause
  is from the diff with Grok Build.
- Claude Desktop itself; a Gemini client end to end (unit-tested only).
- reasoning before a text-only turn is not carried (no call id to ride).
- magpie's own search rounds (search.go) don't know the client's API and
  are left as they were.
No plugin change; the mover's min stays.
2026-11-01 22:21:00 +08:00
..
…