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).
67 lines
2.9 KiB
Go
67 lines
2.9 KiB
Go
// Package codexsummary is the compaction magpie answers Codex with when it
|
|
// compacts a conversation itself (a model of magpie's, or Codex's own
|
|
// models through magpie's accounts), and the message it stands for.
|
|
//
|
|
// Codex keeps a compaction item whole, encrypted_content and all, in its
|
|
// rollout, and sends it back as it is with every later turn. magpie's is
|
|
// "magpie1:" and the summary in base64, which only magpie reads: sent to
|
|
// OpenAI itself (magpie quit, or disconnected) it is refused as
|
|
// invalid_encrypted_content, and the conversation can't go on (LukeMa on
|
|
// X). What it is read as is the message Codex's own local compaction
|
|
// keeps in its place: its summary prefix, a newline and the summary, as a
|
|
// user message, which Codex knows for a summary (is_summary_message).
|
|
// The gateway sends that in place of the item, and a rollout is made
|
|
// portable by writing it there (sessions.PortCodexRollouts).
|
|
package codexsummary
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"strings"
|
|
)
|
|
|
|
// Mark begins the encrypted_content of a compaction item magpie made.
|
|
const Mark = "magpie1:"
|
|
|
|
// Prefix is Codex's own (Apache-2.0, openai/codex,
|
|
// prompts/templates/compact/summary_prefix.md).
|
|
const Prefix = `Another language model started to solve this problem and produced a summary of its thinking process. You also have access to the state of the tools that were used by that language model. Use this to build on the work that has already been done and avoid duplicating work. Here is the summary produced by the other language model, use the information in this summary to assist with your own analysis:`
|
|
|
|
// Encrypted is the encrypted_content of magpie's compaction item for a
|
|
// summary.
|
|
func Encrypted(summary string) string {
|
|
return Mark + base64.StdEncoding.EncodeToString([]byte(summary))
|
|
}
|
|
|
|
// Summary is the summary in a compaction item's encrypted_content: ours
|
|
// is false for one magpie didn't make, and ok false for one of magpie's
|
|
// whose summary can't be read.
|
|
func Summary(encrypted string) (summary string, ours, ok bool) {
|
|
b64, isOurs := strings.CutPrefix(encrypted, Mark)
|
|
if !isOurs {
|
|
return "", false, false
|
|
}
|
|
b, err := base64.StdEncoding.DecodeString(b64)
|
|
if err != nil {
|
|
return "", true, false
|
|
}
|
|
return string(b), true, true
|
|
}
|
|
|
|
// Message is what a compaction item's encrypted_content is read as: ours
|
|
// is false for one magpie didn't make (OpenAI's own, left as it is), and
|
|
// msg nil for one of magpie's whose summary can't be read, which is left
|
|
// out.
|
|
func Message(encrypted string) (msg map[string]any, ours bool) {
|
|
summary, ours, ok := Summary(encrypted)
|
|
if !ok {
|
|
return nil, ours
|
|
}
|
|
return UserMessage(Prefix + "\n" + summary), true
|
|
}
|
|
|
|
// UserMessage is a Responses input message of the user's.
|
|
func UserMessage(text string) map[string]any {
|
|
return map[string]any{"type": "message", "role": "user",
|
|
"content": []map[string]any{{"type": "input_text", "text": text}}}
|
|
}
|