ac4af582301a4e8a29245dbba767eba31334ddf9
4
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
93bbcc8bfb |
gateway: a Responses conversation another resource made goes whole, without its item ids
hykql (Discord) uses Azure OpenAI behind a relay that spreads one key over several resources. A turn after the first was answered by another resource, which turned it away: "The requested item was created under a different Azure OpenAI resource. Use the same resource that created the item to access it." prevRefused only knew "previous_response", so the 400 reached the client, and sending the conversation whole would not have helped: the items magpie brings back still carry the first resource's ids. - prevForeign knows that refusal. A request whose conversation magpie holds is asked once more, whole, with the ids of the items magpie brought back taken out (prevElsewhere): an item that may go without its id (idOptional) loses it, reasoning stays only with its encrypted_content, the client's own new input is as sent. Nothing is asked again when magpie doesn't hold the conversation, or when the body would be the same, so an unknown previous_response_id is still relayed as sent and its refusal passed on. - A kept turn remembers the provider and key whose reply it is (made). Going on with another one, those ids are left out at once: it never made them. The same provider and key gets them as before. - No setting and no GUI. This is the part of hykql's branches (feat/responses-state-client-profile, feat/provider-editor-responses- state) the review kept; their retry stripped previous_response_id from a delta magpie doesn't hold (a 200 with the history gone), and their client profiles included Claude Code's User-Agent. Neither is taken. Run on mote (lockf ~/suite.lock mote-run), at |
||
|
|
127f1e77dc |
gateway: a turn to another magpie goes as its new input after the turn it kept
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 |
||
|
|
ed5872d186 |
gateway: a kept previous response holds its input, not the body it came in
previousResponse kept each turn's input items as views into the request body, so every response kept for previous_response_id held its whole body: tools, instructions and anything else the client sent. own counted only the items, so prevCap's 256 MB bounded far less than was held. The input is now copied out (ownItems, as the Codex socket does since |
||
|
|
ba3a7384fb |
gateway: a Responses request may name the response it follows (previous_response_id, kevinzhow on X)
kevinzhow on X: magpie didn't support previous_response_id on /v1/responses, so every turn carried the whole conversation, images included, and each turn was slow. Before: magpie kept no responses. previous_response_id went on as sent, so a provider that never made that id (or a route that translates to Chat or Messages) had nothing but the new input to give the model. After (prev_response.go, run in serveAgent before anything reads the body): - Each Responses reply passed with 200 (not failed/cancelled, not cut at 64 MB) is kept by its id with input + output, in memory, LRU to 256 MB of own bytes, 6h TTL. store:false keeps nothing. - Kept per caller (prevScope): gateway key, remote magpie, keyless remote address. Another caller naming the id is told it isn't there. - A kept id expands the request to the whole conversation, so routing, translation and masking see what they would have seen had the client sent it all. Masking runs on each request as it goes (deterministic placeholders), so a stored secret is masked the same on every turn; TestPreviousResponseMasked. - An unknown id gets OpenAI's 400 previous_response_not_found on a route that translates (and on Claude/Codex accounts), before anything is sent. A Responses relay is sent the id as it came. - Where the provider keeps responses itself (prevKeeps: API key, no plugin; api.openai.com, Azure, or Ark /api/v3 pay-as-you-go) and it answered the previous turn on the same key, with store not off, only the new input goes with the provider's own id (prevDelta). A provider that says it doesn't know the id (prevRefused) is sent the whole conversation at once. Codex: its HTTP ResponsesApiRequest has no previous_response_id; only the websocket's ResponseCreateWsRequest has it (openai/codex 9def09a, codex-rs/codex-api/src/common.rs:341, client.rs:2284). Over HTTP it sends store:false with the whole input, so nothing it sends or keeps changes. No prompt is touched. Ark checked with a real pay-as-you-go key (10-29): store:true then previous_response_id returned the stored word; an unknown id answers 400 InvalidParameter.PreviousResponseNotFound (param previous_response_id), which prevRefused matches. Tests (prev_response_test.go): GivenWholeToChat (3 turns), NotFound (unknown, other key, no key, store:false; upstream not called), UnknownPreviousResponseRelayedAsSent, KeptUpstreamSentNewInputOnly (200 KB image; delta < 2000 bytes; refusal retried whole), Masked, PrevStoreBounded. Broken by hand, each red, then restored: - previousResponse a no-op: GivenWholeToChat, NotFound, KeptUpstream, Masked red. - prevDelta off: KeptUpstream red (200355 bytes sent, no prev id). - prevRefused always false: KeptUpstream red at the retry turn (400 relayed). Timings on mote (BenchmarkImageRequest / BenchmarkPreviousResponseTurn, 8 images, 20.18 MB conversation): - whole Responses -> Responses: 277 ms, 145.6 MB/op before; 263 ms, 145.6 MB/op after (a first version that json.Unmarshal'd the input cost 364 ms and +20 MB; it now reads items over the body's bytes). - whole Responses -> Chat: 273 ms before, 224 ms after. - previous_response_id to a provider that keeps responses: client sends 82 B, upstream gets 122 B (was 20.18 MB each way), 309 ms locally. - previous_response_id to Chat: client sends 83 B, upstream gets the whole 20.18 MB, 295 ms. Run at this head on mote: gofmt -l clean; go vet ./internal/gateway for darwin, linux, windows ok; go test -count=1 -timeout 45m ./internal/gateway ./internal/redact: gateway ok (464.4s), redact ok (1.8s). Not tried: a real OpenAI or Azure key (Ark's real key only); Ark's Coding Plan Responses path (not in prevKeeps). The store is in memory, so ids are lost on restart (a translated route then answers 400, a relay passes the id on). A kept-id request is still read and masked whole on this computer before the delta is cut (~300 ms local for 20 MB). Doc: docs/subsystems/gateway-routing.md, "A Responses request that names the response it follows". |