hentulong on X: after routing Codex through WorkBuddy and switching back,
Codex couldn't connect, and a fork said "Persisted response contains
hosted-tool, compaction, or unverifiable hidden reasoning state that
Rustponses cannot replay".
Cause: while Codex is routed through magpie to another vendor, the
reasoning items magpie hands it stay in the thread's rollout. After the
switch back Codex talks to chatgpt.com itself, and OpenAI refuses every
reasoning item it didn't seal. On the owner's real account:
- summary only, no encrypted_content: unsupported_persisted_item_context
(the reporter's Rustponses error) on a previous_response_id
continuation;
- with content (reasoning_text, what Codex 0.165 writes for DeepSeek via
magpie): 400 array_above_max_length "Invalid 'input[5].content'";
- foreign encrypted_content: invalid_encrypted_content.
Codex treats each as fatal, so that thread and its forks fail while new
threads work. No stale config: Unwire/EndFailover drop openai_base_url.
Fix: when Codex is no longer routed or failing over (Unwire, quit,
uninstall and the periodic pass), PortCodexRolloutsLeft rewrites, in
threads begun on openai/magpie, every reasoning item (and every one in a
compacted line's replacement_history) whose encrypted_content isn't an
OpenAI Fernet token ("gAAAA") into type "magpie_reasoning", without id
and encrypted_content. Codex reads an unknown type as Other and never
sends it; magpie's sessions readers still show it. The edit keeps member
order and line length (same fitLine/lock path as the existing port),
has its own state entry, and starts at 2026-09-21. A survey of 150 live
rollouts found 340 of 340 OpenAI reasoning items in the gAAAA shape.
Run (mote, at f1d0c0bfd + this): go vet ./... for darwin, linux and
windows; go build for the three; go test -tags nogui -timeout 45m ./...:
every package ok but internal/gui, whose one red is
TestSettingsSaveKeepsWhatItDoesNotSend (SearchAll), open on main as #4514; gofmt -l clean.
Broken by hand: with the retire step off, and with Unwire passing false,
TestPortCodexRolloutsLeftRetiresUnsealedReasoning,
TestPortCodexRolloutsLeftKeepsItsOwnState and
TestCodexDisconnectRetiresMagpieReasoning go red.
Real Codex 0.165, sandbox CODEX_HOME, owner's account: a turn via magpie
with auto/deepseek-flash, then `codex exec resume` on gpt-6-sol direct
failed with array_above_max_length; after the left port the same resume
answered. The summary-only Rustponses refusal was reproduced with a
websocket probe against chatgpt.com and is retired by the same rule.
Not tried: the reporter's exact case in the interactive TUI (exec
resume doesn't warm up, so it never sends previous_response_id). A
thread Codex holds open keeps its in-memory history until reopened; a
switch not made through Unwire is caught by the periodic pass within
10 minutes.
Rebased after the full run onto 9551fadcb (5174c0970 GUI assets,
9551fadcb gateway/usage; no file here). At the pushed head:
go test -tags nogui -run Codex ./internal/sessions ./internal/agent ok,
go vet ./internal/sessions ./internal/agent ok.
82 lines
2.6 KiB
Go
82 lines
2.6 KiB
Go
package agent
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/sessions"
|
|
)
|
|
|
|
// A Codex conversation magpie compacted can't go on once Codex talks to
|
|
// OpenAI itself, unless its rollout is written portable
|
|
// (sessions.PortCodexRollouts, LukeMa on X): done while magpie runs, for
|
|
// the threads no Codex has open, and again as magpie lets Codex go (quit,
|
|
// Disconnect), for those it has just let go. Once Codex no longer goes
|
|
// through magpie, magpie's reasoning items are written so too
|
|
// (sessions.PortCodexRolloutsLeft): OpenAI won't take a thread holding
|
|
// one as the base of its next turn (hentulong on X).
|
|
|
|
// codexPortEvery is how often a running magpie makes the rollouts written
|
|
// since portable; codexPortAfter how long after it starts it first does.
|
|
var codexPortEvery, codexPortAfter = 10 * time.Minute, 2 * time.Minute
|
|
|
|
// codexPortUnwire is how long Disconnect spends on it; what is left is
|
|
// done by the next pass.
|
|
const codexPortUnwire = 3 * time.Second
|
|
|
|
// portCodexHome makes the rollouts of the Codex home dir portable, for
|
|
// up to d; left says Codex no longer goes through magpie.
|
|
func portCodexHome(dir string, d time.Duration, left bool) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), d)
|
|
defer cancel()
|
|
port := sessions.PortCodexRollouts
|
|
if left {
|
|
port = sessions.PortCodexRolloutsLeft
|
|
}
|
|
res, err := port(ctx, dir)
|
|
if err != nil {
|
|
log.Println("codex rollouts:", err)
|
|
}
|
|
if len(res.Rewritten) > 0 || len(res.Held) > 0 {
|
|
log.Printf("codex rollouts: %d written portable, %d left while a Codex has them open", len(res.Rewritten), len(res.Held))
|
|
}
|
|
}
|
|
|
|
// PortCodexRollouts makes this machine's Codex rollouts portable, for up
|
|
// to d: as magpie quits.
|
|
func PortCodexRollouts(d time.Duration) {
|
|
if home, err := os.UserHomeDir(); err == nil {
|
|
portCodexHome(here(home).codexHome(), d, codexLeft(home))
|
|
}
|
|
}
|
|
|
|
// codexLeft says this machine's Codex doesn't go through magpie: neither
|
|
// routed to it nor failing over by it.
|
|
func codexLeft(home string) bool {
|
|
a := codex(home)
|
|
return !(a.Routed != nil && a.Routed()) && !(a.FailingOver != nil && a.FailingOver())
|
|
}
|
|
|
|
// KeepCodexRolloutsPortable makes this machine's Codex rollouts portable
|
|
// every so often until ctx ends.
|
|
func KeepCodexRolloutsPortable(ctx context.Context) {
|
|
home, err := os.UserHomeDir()
|
|
if err != nil {
|
|
return
|
|
}
|
|
dir := here(home).codexHome()
|
|
wait := codexPortAfter
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-time.After(wait):
|
|
}
|
|
wait = codexPortEvery
|
|
// a pass that is cut short goes on from where it was next time
|
|
portCodexHome(dir, codexPortEvery/2, codexLeft(home))
|
|
}
|
|
}
|