LotusDecoder on X runs two magpies, each the other's provider. Codex says
store false, so the leg between them carried the whole conversation
every turn. Now passthrough asks a remote magpie to keep the Responses
turn (X-Magpie-Keep-Turn: magpie/<version>). A magpie that does answers
X-Magpie-Kept-Turn. This side records per route and scope a digest of
each input item as sent, the reply's output types and ids, and the
other magpie's id (remoteTurns: 16 per route and scope, 32 MB, prevTTL).
The next request that continues exactly that input and reply goes as
the items after them with previous_response_id. Anything else goes
whole: an edited history, another answer, a magpie that never said it
keeps (an older one). A refused delta is sent again whole at once, and
the route goes whole for 30 minutes.
The receiving magpie honours the header only from a magpie's hop
(keepTurnAsks): its value starts magpie/ and the User-Agent is magpie's,
or Codex's, which forwardOnce passes on for Codex turns. It keeps the
turn under the caller's prevScope and the usual caps. An id such a
caller names that isn't held gets previous_response_not_found before
any vendor is asked. withCaller takes the header off on arrival, and
X-Magpie- is never a passable request header, so no vendor gets it.
Run on mote (mote-run) at base 93d5c76c0 with this tree:
- gofmt -l internal/gateway internal/provider: clean
- GOOS=linux go vet -tags nogui ./internal/gateway: ok
- GOOS=windows go vet ./internal/gateway: ok
- go test -tags nogui -count=1 -timeout 45m ./internal/gateway:
ok (1123.7s)
- The five new tests, plus TestRemoteMagpie*, TestPreviousResponse*,
TestUnknownPreviousResponse and TestPrevStore: 54 passed.
- Again rebased on 538026e62, the same suite: one red,
TestUnroutedEmptyEncodedStreamIsBounded/gzip ("TempDir RemoveAll
cleanup: ... magpie/held: directory not empty"). It is #4775's test:
the held report is written from the timer after the 408, so the test
can end mid-write. Not this change; fixed in its own commit.
- At the pushed base 50aaa5726: gofmt clean, Linux and Windows vet ok,
the related tests above (57 passes) ok.
Broken by hand, each red, then restored:
- delta never sent: SentTheNewInput, LostTurnSentWhole and the
EditedHistory control go red.
- the header honoured from any client: KeepTurnOnlyFromAMagpie goes red
(curl told kept).
- refusal not remembered: LostTurnSentWhole goes red (turn 3 is tried as
a delta).
- deltas without the Kept-Turn reply: OlderRemoteMagpieSentWhole goes
red.
- keptTurnLost check removed: KeepTurnOnlyFromAMagpie goes red (the lost
id is relayed).
- output marks not compared: EditedHistory "other answer" goes red.
- the withCaller strip and the X-Magpie- never-pass prefix both removed:
KeepTurnOnlyFromAMagpie goes red (vendor sent the header). Either one
alone holds it, so removing only the strip stays green.
The new tests don't compile on the old code, since they name the new
header constants and remoteTurns.
Found on the way: a Codex turn reaches the remote magpie with Codex's
User-Agent, not magpie's, so callerFrom's existing X-Magpie-Agent/Via
reading never applies to Codex hops. Unchanged here; keepTurnAsks
accepts that shape.
Not tried:
- two real magpies over a real link, and a WebSocket-fed Codex (only
HTTP turns in tests);
- an SSE reply over the hop (tee parses SSE through prevReply, which
prev_response tests cover, but no remote-delta test streams);
- other platforms' test runs (Linux and Windows were vetted only).
Known gaps:
- the reply is matched by type and ids, so a client that edits the
last answer's text (no ids) gets a delta over the kept one;
- tools and instructions are still sent every turn;
- the remote's kept turns are in memory only;
- a client that copies a hop's headers gets its store-false turns kept
under its own scope and the caps.