hey_boyce on X: Codex, talking to OpenAI itself, got 400
invalid_encrypted_content "The encrypted content for item
cmp_magpie_1794916786407450000 could not be verified".
Cause: PortCodexRollouts writes magpie's compaction item (magpie1:
base64 summary) as Codex's own summary message, keeping each line's
length, since a paginated rollout keeps places by byte. A message
longer than the line (a short summary under Codex's ~400-char prefix)
was left as it was, so the magpie1: seal stayed in the rollout, Codex
replayed it to OpenAI every turn, and the thread was stuck. The
incremental pass never looked at such a rollout again.
Change:
- fitShorter: when the full message doesn't fit, the summary goes
under a short heading, then cut to fit (rune-safe, "…"), then
with no heading. If nothing fits, a standalone item is retired as
{"type":"magpie_compaction"}, which Codex reads as unknown and
never sends.
- In replacement_history an unknown item IS sent (as "other"), and
OpenAI refuses it ("Invalid value: 'other'"; seen with real
codex-cli 0.165.0 and 0.169.1). So a compaction or reasoning item
retired there is left out with its metadata entry, and
magpie_reasoning items main's PortCodexRolloutsLeft already wrote
there are taken out (retiredInList). That was a sibling bug: those
threads failed the same way.
- codex-portable.json gains refit: a state from before makes one
whole pass again, so rollouts already left with the seal are fixed.
- The gateway's last line: a 400 naming an item of magpie's own
compaction asks again with its summary message in its place
(withoutItem), not with the summary dropped.
- codexsummary.Summary decodes the seal; Message uses it.
- docs/subsystems/gateway-routing.md says all of this.
Run (on mica, at this head rebased on a265632da):
- red on the old code, green now: TestPortCodexRolloutsLongerLine
(short, cut), TestPortCodexRolloutsDropsRetiredFromHistory,
TestPortCodexRolloutsRefitsOnce,
TestPortCodexRolloutsLeftRetiresUnsealedReasoning,
TestRefusedMagpieCompactionGoesAsText (old withoutItem: 2 items,
the summary gone).
- broken by hand: without `&& was.Refit` RefitsOnce is red.
- real Codex, sandbox HOME with a copy of the owner's ChatGPT auth,
codex-cli 0.169.1, gpt-6-sol, against OpenAI:
- the reporter's item (id cmp_magpie_1794916786407450000, summary
"ok") gave the same 400 word for word. Ported by this code, resume
answered.
- an id-less item plus a magpie_reasoning in replacement_history
(as main left it) failed "Invalid value: 'other'" before. Ported,
resume answered.
- go test -count=1 -timeout 45m ./internal/codexsummary
./internal/sessions ./internal/gateway ./internal/agent: all ok
(gateway 1026s, agent 221s), log kept in enc-scratch/pkgs.log;
TestLoopGuard* again after the doc edit: ok.
- rebased on 53db3e389 (stream keepalive; only the doc page is
shared): the refusal, seal, compaction, LoopGuard and Quiet tests
in internal/gateway again at this head: ok.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./..., go build ./... ok.
Not tried: a summary cut to fit with real Codex (the unit test checks
it is a plain user message, the same shape as the case that was run);
a Codex in WSL; the full ./... suite: mote was over its cores and both mote and
mica were running another session's GUI suite, so only the changed
packages and internal/agent, which ports rollouts, ran (above).
60 lines
2.7 KiB
Go
60 lines
2.7 KiB
Go
package gateway
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/codexsummary"
|
|
)
|
|
|
|
// hey_boyce on X: OpenAI turned a turn away for magpie's own compaction
|
|
// ("The encrypted content for item cmp_magpie_1794916786407450000 could
|
|
// not be verified"). Asked again, the item goes as the summary it holds,
|
|
// not dropped with it, and every other item stays; an item of OpenAI's
|
|
// own that it refuses is still left out.
|
|
func TestRefusedMagpieCompactionGoesAsText(t *testing.T) {
|
|
msg := []byte(`{"error":{"code":"invalid_encrypted_content","message":"The encrypted content for item cmp_magpie_1794916786407450000 could not be verified. Reason: Encrypted content could not be decrypted or parsed.","param":null,"type":"invalid_request_error"}}`)
|
|
body, _ := json.Marshal(map[string]any{"model": "gpt-5.4", "input": []any{
|
|
map[string]any{"type": "message", "role": "user", "content": []any{map[string]any{"type": "input_text", "text": "first"}}},
|
|
map[string]any{"type": "compaction", "id": "cmp_magpie_1794916786407450000", "encrypted_content": codexsummary.Encrypted("we fixed the parser")},
|
|
map[string]any{"type": "message", "role": "user", "content": []any{map[string]any{"type": "input_text", "text": "next"}}},
|
|
}})
|
|
got, ok := withoutUnreadable(body, msg)
|
|
if !ok {
|
|
t.Fatal("not asked again")
|
|
}
|
|
var q struct {
|
|
Input []struct {
|
|
Type string `json:"type"`
|
|
ID string `json:"id"`
|
|
Content []struct {
|
|
Text string `json:"text"`
|
|
} `json:"content"`
|
|
} `json:"input"`
|
|
}
|
|
if err := json.Unmarshal(got, &q); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(q.Input) != 3 {
|
|
t.Fatalf("%d items asked again, want 3: %s", len(q.Input), got)
|
|
}
|
|
mid := q.Input[1]
|
|
if mid.Type != "message" || len(mid.Content) != 1 || !strings.HasSuffix(mid.Content[0].Text, "\nwe fixed the parser") || !strings.HasPrefix(mid.Content[0].Text, codexsummary.Prefix) {
|
|
t.Fatalf("the compaction went as %+v", mid)
|
|
}
|
|
if strings.Contains(string(got), "magpie1:") {
|
|
t.Fatalf("the sealed form still goes: %s", got)
|
|
}
|
|
|
|
// OpenAI's own compaction it can't read is left out
|
|
body, _ = json.Marshal(map[string]any{"model": "gpt-5.4", "input": []any{
|
|
map[string]any{"type": "compaction", "id": "cmp_0abc", "encrypted_content": "gAAAAB"},
|
|
map[string]any{"type": "message", "role": "user", "content": []any{map[string]any{"type": "input_text", "text": "next"}}},
|
|
}})
|
|
msg = []byte(`{"error":{"code":"invalid_encrypted_content","message":"The encrypted content for item cmp_0abc could not be verified."}}`)
|
|
if got, ok = withoutUnreadable(body, msg); !ok || strings.Contains(string(got), "cmp_0abc") || !strings.Contains(string(got), "next") {
|
|
t.Fatalf("OpenAI's own: %v %s", ok, got)
|
|
}
|
|
}
|