gateway: a relay rejects a routing-group request's foreign encrypted reasoning with 400 "Encrypted content is not supported", unretried
Summary
A conversation served through a routing group carries encrypted reasoning blocks from a previous provider. When a later request is routed to a different provider (a relay), the relay rejects the foreign encrypted reasoning with HTTP 400:
400: <relay>: Encrypted content is not supported.
Magpie does not strip the foreign encrypted reasoning before forwarding the request, and the 400 is not retried on another member. The agent harness retries the same turn, the routing lands on the same rejecting provider again, and the turn eventually fails with "The model provider failed after retries".
Reproduction
- Configure a routing group (routing=order) with members across different providers, one of them a relay that does not support encrypted reasoning content.
- Serve a conversation on a reasoning model whose responses include encrypted reasoning blocks.
- On a later turn, have the routing land on the relay.
- The relay returns 400 "Encrypted content is not supported".
Observed behavior (gateway log, v0.1.4341)
2026/11/17 02:20:44 gateway: hermes's call to group/agentcompass on imported failed: 400 after 2.631s: 积算: Encrypted content is not supported.
2026/11/17 02:20:45 gateway: dsh's call to group/agentcompass on imported failed: 400 after 550ms: 积算: Encrypted content is not supported.
2026/11/17 02:22:14 gateway: dsh's call to group/agentcompass on imported failed: 400 after 2.919s: 积算: Encrypted content is not supported. (and 1 times more like it since the last line)
Expected behavior
When routing a request whose history contains encrypted reasoning content to a different provider than the one that produced it, magpie should strip the foreign encrypted reasoning blocks from the request before forwarding it. The new provider cannot use them anyway — they are encrypted for the original provider.
Related issues
- #4798 — Responses routing sends incompatible encrypted reasoning before retrying with HTTP 400 (same core issue, Responses API path)
- #6409 — Provenance-aware handling of LiteLLM encrypted reasoning across route changes
- #3887 — [Bug] 包含联网搜索(web_search_call)历史的 Codex 会话在跨账号路由或 Affinity 冷却切换后必现 invalid_encrypted_content 400
- #3994 — gateway: Azure's "invalid encrypted summary" isn't read as foreign reasoning
- #3970 — [Bug] 跨模型续接后 Codex 会话水合失败:compaction 加密项(cmp_msg_*)无法被原厂解密
take
@yetone @ArmedHelicopter reported a routing group with a relay member that takes no encrypted content: the conversation a reasoning member served carries that member's sealed reasoning, the relay refuses the request with 400: Encrypted content is not supported., and nothing asked again — the turn was a final 400, and the agent harness's retries landed on the same member every time until it gave up ("The model provider failed after retries"), on v0.1.4341.
Root cause: foreignReasoning (internal/gateway/affinity.go:1198) is how magpie reads a refusal of reasoning another upstream sealed, and the relay's own wording — "Encrypted content is not supported." — matches none of its alternatives. So neither retry gate read the 400 as one (internal/gateway/gateway.go:4779 for the sealed reasoning a Chat, Messages or Gemini client's calls carry; gateway.go:4794 for a Responses client's sealed items), nothing was asked again without what the relay can't take, and every later turn carried it again.
The fix: the relay's wording joins foreignReasoning's alternatives, and the machinery behind the gates does what the reporter expected — following the reporter's own analysis (a new provider can't use what another one sealed): a Responses client's request is asked again without every sealed item it carries (withoutSeals), and what the relay refused is left out of its later requests there up front (refused, withoutRefused); a Chat, Messages or Gemini client's carried reasoning goes the same way (refuseCarried, withoutRefusedCarry); the ChatGPT backend's relays read it too (withoutUnreadable). The try is failForeign. Whether the items are foreign or this member's own is nothing a relay that takes none tells apart, so they all go — as an upstream that reads another account's seals is already asked without all of them.
patch: gateway: a relay's "Encrypted content is not supported." for a group's request is asked again without (#6967) — git am applies it as is; SHA-256 first 16: 3285330a9ee8aaa9
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ggbdpq <[email protected]>
Date: Tue, 17 Nov 2026 23:42:16 +0800
Subject: [PATCH] gateway: a relay's "Encrypted content is not supported." for
a group's request is asked again without (#6967)
A routing group's member that takes no encrypted content refused the
sealed reasoning another member's earlier turns left in the request with
"Encrypted content is not supported.", a 400 foreignReasoning didn't
read as a refusal of reasoning another upstream sealed, so nothing asked
again without it, the turn was a final 400, and the agent's retries
landed on the same member every time (ArmedHelicopter: a relay member of
group/agentcompass, v0.1.4341).
Now that refusal is read as the same one: the try is failForeign, and a
Responses client's request is asked again without every sealed item it
carries (withoutSeals), what it refused left out of its later requests
there (refused, withoutRefused); a Chat, Messages or Gemini client's
carried reasoning the same way (refuseCarried, withoutRefusedCarry).
Whether the items are foreign or this upstream's own is nothing a relay
that takes none tells apart, so they all go, as an upstream that reads
another account's seals is asked without all of them already.
Run at this head on the worktree:
- go test ./internal/gateway -tags nogui -run
'TestForeignSealRelayWithoutEncryptedContent|TestForeignReasoningWords'
-count=1: red before the fix (the turn died on the relay's 400, and
the words matched nothing), green after.
- go test ./internal/gateway -tags nogui -run
'TestForeign|TestSealedReasoning|TestReasonedID|TestBoundThinking|TestGrokReasoning|TestSealsTakenOut'
-count=1: ok.
Generated-by: GLM-5.3-Flash (ZCode)
---
internal/gateway/affinity.go | 6 +-
internal/gateway/foreign_seal_test.go | 79 +++++++++++++++++++++++++++
2 files changed, 83 insertions(+), 2 deletions(-)
diff --git a/internal/gateway/affinity.go b/internal/gateway/affinity.go
index 0576273ef..67746af82 100644
--- a/internal/gateway/affinity.go
+++ b/internal/gateway/affinity.go
@@ -1194,8 +1194,10 @@ func unanswered(key string, c candidate) {
// encrypted_content (zminds #4412) — "Could not decode the compaction
// blob", which names no item and says nothing of encrypted content,
// where the #3392 shaping (xaiBody's) never runs because the relay's
-// host isn't api.x.ai.
-var foreignReasoning = lazyre.New(`(?i)invalid_encrypted_content|invalid[ _]encrypted[ _](summary|content)|encrypted[ _]content.{0,80}could not be (verified|decrypted)|could not (decrypt|verify).{0,40}encrypted[ _]content|could not (decode|decrypt).{0,20}compaction[ _]blob`)
+// host isn't api.x.ai; and a relay's own word for a request that carries
+// any of it where it takes none (ArmedHelicopter #6967), "Encrypted
+// content is not supported.", which names no item and asks for nothing.
+var foreignReasoning = lazyre.New(`(?i)invalid_encrypted_content|invalid[ _]encrypted[ _](summary|content)|encrypted[ _]content.{0,80}could not be (verified|decrypted)|could not (decrypt|verify).{0,40}encrypted[ _]content|could not (decode|decrypt).{0,20}compaction[ _]blob|encrypted[ _]content is not supported`)
// refusedSeals remembers, per conversation and the key or account that
// refused it, what another one sealed: its reasoning, and the sealed copy
diff --git a/internal/gateway/foreign_seal_test.go b/internal/gateway/foreign_seal_test.go
index 235ab42bc..74937fa15 100644
--- a/internal/gateway/foreign_seal_test.go
+++ b/internal/gateway/foreign_seal_test.go
@@ -174,6 +174,8 @@ func TestForeignReasoningWords(t *testing.T) {
`{"error":{"message":"invalid encrypted summary","type":"invalid_request_error","param":null,"code":"validation_error"}}`,
relayCompaction,
"Could not decode the compaction blob. Ensure it is unmodified from the compact response.",
+ relayUnsupported,
+ "积算: Encrypted content is not supported.",
} {
if !foreignReasoning.MatchString(m) {
t.Errorf("not matched: %s", m)
@@ -504,6 +506,83 @@ func TestForeignSealGrokRelayCompactionBlob(t *testing.T) {
}
}
+// relayUnsupported is what a relay that takes no encrypted content
+// answers for reasoning another member sealed (#6967, ArmedHelicopter):
+// a 400 nothing asked again, so the harness's retries landed on the same
+// member every time and the turn died there.
+const relayUnsupported = `{"error":{"message":"Encrypted content is not supported.","type":"invalid_request_error","param":null}}`
+
+// A routing group of a reasoning member and a relay that takes no
+// encrypted content (#6967): the conversation the first served carries
+// its sealed reasoning, and the relay refuses it with "Encrypted content
+// is not supported.". Now the refusal is asked again without the
+// reasoning, the turn is answered there, and the next turn goes to it
+// without what it refused up front.
+func TestForeignSealRelayWithoutEncryptedContent(t *testing.T) {
+ fresh(t)
+ a, rel := &sealer{name: "a"}, &sealer{name: "relay", errJSON: relayUnsupported}
+ for _, u := range []struct {
+ id string
+ h http.Handler
+ }{{"a1", a}, {"relay1", rel}} {
+ up := httptest.NewServer(u.h)
+ t.Cleanup(up.Close)
+ if err := provider.Save(provider.Provider{ID: u.id, Name: u.id, Key: "k-" + u.id, Models: []string{"m"}, Responses: up.URL + "/v1"}); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if err := provider.SaveGroup(provider.Group{Name: "agentcompass", Members: []string{"a1/m", "relay1/m"}, Routing: provider.Ordered}); err != nil {
+ t.Fatal(err)
+ }
+ s := New()
+ turn := func(items ...string) (int, string) {
+ t.Helper()
+ in := `{"type":"message","role":"user","content":[{"type":"input_text","text":"count the lines"}]}`
+ for _, it := range items {
+ in += "," + it
+ }
+ rec := httptest.NewRecorder()
+ req := httptest.NewRequest("POST", "/v1/responses", strings.NewReader(`{"model":"group/agentcompass","stream":true,"input":[`+in+`]}`))
+ req.Header.Set("session_id", "thread-6967")
+ s.Handler().ServeHTTP(rec, req)
+ return rec.Code, rec.Body.String()
+ }
+ reasoning := func(by string) string {
+ return `{"type":"reasoning","id":"rs_` + by + `","summary":[],"encrypted_content":"sealed-by-` + by + `"}`
+ }
+ call := func(id string) string {
+ return `{"type":"function_call","call_id":"` + id + `","name":"shell","arguments":"{}"},{"type":"function_call_output","call_id":"` + id + `","output":"ok"}`
+ }
+
+ // a answers, and reads back what it sealed
+ if code, body := turn(); code != 200 || !strings.Contains(body, "from a") {
+ t.Fatalf("first: %d %s", code, body)
+ }
+
+ // a goes down: the relay takes the turn, refuses a's seal once, and
+ // answers without it
+ a.down = true
+ code, body := turn(reasoning("a"), call("c1"))
+ if code != 200 || !strings.Contains(body, "from relay") {
+ t.Fatalf("on the relay: %d %s", code, body)
+ }
+ if got := rel.sent(); len(got) != 2 || len(got[0]) != 1 || len(got[1]) != 0 {
+ t.Fatalf("relay was sent %q, want a's seal once, then none", got)
+ }
+ if r := lastRoute(s); len(r.Tries) != 3 || r.Tries[1].Fail != failForeign || r.Tries[2].Status != 200 {
+ t.Fatalf("tries: %+v", r.Tries)
+ }
+
+ // the next turn doesn't hit it again: a's seal is left out up front
+ if code, body := turn(reasoning("a"), call("c1")); code != 200 || !strings.Contains(body, "from relay") {
+ t.Fatalf("next turn: %d %s", code, body)
+ }
+ if got := rel.sent(); len(got) != 1 || len(got[0]) != 0 {
+ t.Fatalf("relay was then sent %q, want one request without the seal", got)
+ }
+ a.sent()
+}
+
// openaiUndecryptable is what OpenAI told hheei (#3887) of a web search
// another ChatGPT account ran, with code invalid_encrypted_content, and
// magpie passed on as "Codex: Encrypted content could not be decrypted or
--
2.50.1 (Apple Git-155)
Branch with the commit: fix/6967-strip-foreign-reasoning (head 2e164bf95250ab794df4d75b858c87d3730e05d2), rebased onto current upstream/main (ae94571d7); on a fresh checkout git am applies clean.
| Check | Result |
|---|---|
TestForeignSealRelayWithoutEncryptedContent (new) |
red before the fix (the turn died on the relay's 400), pass after |
TestForeignReasoningWords (the relay's wording in its lists) |
red before the fix, pass after |
TestForeignCarriedReasoningAskedAgainWithout, TestForeignSealAcrossGroupMembers, TestForeignSealedItemsMoveToAnotherAccount, TestForeignSealAzureSummary, TestForeignSealGrokRelayCompactionBlob, TestSealsTakenOutLeaveTheRest |
pass |
targeted -race over the foreign family |
pass |
go test ./internal/gateway/ -tags nogui -timeout 25m -count=1 |
every test ok but the Claude-bridge cascade (TestClaude*, TestAutoModeClassifierOnTheClaudeBridge, TestRefusalRetriesClaudeSubscription) — the known full-run red, the fake shim killed at 0s under this machine's parallel load; no foreign-reasoning test among them |
go test -tags nogui ./... |
every package ok but this machine's known reds — internal/gateway's TestHealthcheckFindsTheRunningGatewayWithoutMagpieAddr and TestUpdateRestartsTheGatewayItFindsWithoutMagpieAddr (the WithoutMagpieAddr family), internal/plugin's TestHostToldTheGatewayAddress (the known port race), and internal/provider's TestResolveVia, which fails the same on the untouched base ae94571d7 (same EOF); no failure in the touched code's paths |
gofmt -l |
prints nothing |
go vet ./...; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet ./... |
clean |
go build ./...; GOOS=linux go build -tags nogui ./...; GOOS=windows go build ./... |
clean |
| Ablation | internal/gateway/affinity.go reverted to the branch parent (28f27e07b), test kept: TestForeignSealRelayWithoutEncryptedContent red with the relay's 400; restored, green |
Re-verified on upstream/main ae94571d7 |
rebased (range-diff =), the named tests rerun green on the new head |
Source: reported in #6967 (ArmedHelicopter); the failing words are the reporter's gateway log, quoted as is.
Red without the fix (base 28f27e07b): with internal/gateway/affinity.go reverted and the new test kept, go test ./internal/gateway -tags nogui -run TestForeignSealRelayWithoutEncryptedContent fails: --- FAIL: TestForeignSealRelayWithoutEncryptedContent: on the relay: 400 {"error":{"message":"relay1: Encrypted content is not supported.","type":"invalid_request_error","param":null}}. With the fix: ok.
Siblings: rg -n "foreignReasoning" internal/gateway/ → 4 sites. Covered here: gateway.go:4779 (carried reasoning, non-Responses clients — the same regex feeds it), gateway.go:4794 (a Responses client's seals — the face the report hit), codex_backend.go:1953 (withoutUnreadable, the ChatGPT backend's relays). Already guarded: Anthropic's refused thinking signature (thinking_bound.go, strips and retries on Claude's own words), Gemini/Vertex thought signatures (signatureRefused, gemini_signature.go, asked again without), #3887's words (landed b59e4b747), #3994's "invalid encrypted summary" (landed 460687ff5), #3970's compaction blobs (withoutCompaction and the compaction-blob alternative, TestForeignSealGrokRelayCompactionBlob), xAI's own null-content shaping (#3392, xaiBody, keyed to api.x.ai hosts — a relay host is handled at refusal time, #4412). Different by design: #6409 (provenance tracking, a cognitive-layer proposal — the refusal-driven strip stays, this fix doesn't touch it); reasoningBackRefused (a Chat upstream demanding visible reasoning_content, a different content kind, already classified via shapeRefused's failover).
When the read fails: a request with nothing sealed is not rewritten — withoutSeals reports no change, the gate falls through, and the 400 ends the turn as before; a seal magpie can't parse stays in the request (worst case the same refusal again, nothing lost); a carried key magpie no longer holds is no reasoning — the step goes as it did (reasoning_carry.go).
Not verified: the reporter's relay itself, and a live cross-vendor group with real accounts.
Attribution: AI-written; I've read the whole diff and the tests pass. Please keep the author (ggbdpq) or add Co-authored-by: ggbdpq <[email protected]>.
Generated-by: GLM-5.3-Flash (ZCode)
Additional cascade observed: a refused compaction degrades subsequent tool-call JSON serialization.
After a dsh compaction replay was refused, the ACP session pinned its planning floor to 0 tokens for the session lifetime (planning floor 0 tok from the refused dsh compaction replay (#2490, sticky for the session lifetime)). In that same session, tool calls then began failing with malformed JSON.
Example (sanitized, no conversation content): a tool call routed through mcp__magpie__call_tool → remote-magpie__ssh__ssh_exec, whose command argument was a multi-line Python heredoc, was rejected with:
Expected ',' or '}' after property value in JSON at position 1480
The command contained three nested escape layers (JSON line escapes, Python string \n escapes, Python \" quote escapes). With the planning floor locked at 0, the model's ability to serialize this nesting correctly degrades, producing exactly this class of escape-sequence corruption.
So the refused compaction is not a self-contained failure: it lowers the quality of every subsequent tool call in the session via the pinned planning floor. A fix for the cross-provider foreign-reasoning carry (this issue, plus #4798 / #6409) should also prevent this downstream cascade.