Files
magpie/internal/gateway/codex_compact_model.go
T
yetone 19782923c5 codex: the compaction magpie makes can go on a model of its own (0neB1aze on X)
Codex's memories had a model of their own, its compaction did not. Codex's row has a compaction model square (compact_model, settings.CodexCompactModel), read by the gateway on each compaction (codexCompactTo, before codexCompact). Only a compaction magpie makes is moved: it asks for a plain-text summary any model reads back. One a ChatGPT account seals, or a pick that compacts natively, is left, since only the writing account reads it (#1099); a disabled, unserved or key-barred pick is left with a log line. The text sent to the model is unchanged.

Run on mote: TestCodexCompactOnItsOwnModel (red with the move taken out) and TestCodexCompactToLeavesNative; go test for gui, settings, settingsapi, agent, provider, gateway; darwin, linux and windows vet; the GUI files in both engines. Not tried: a real Codex session compacting on the chosen model.
2026-11-11 20:57:11 +08:00

37 lines
1.3 KiB
Go

package gateway
import (
"log"
"net/http"
"github.com/yetone/magpie/internal/provider"
)
// codexCompactTo is the model a Codex compaction that magpie makes (the
// session's model is one of magpie's, asked for the summary as a turn)
// goes on: the one set for Codex's compactions, "" to leave it on asked.
// A compaction sealed by a ChatGPT account (native) is only read by the
// account that wrote it, so neither it nor one put on such a model is
// moved: the summary magpie asks for is plain text any model reads back.
// The model set must be enabled, served by its exact id and allowed to
// the gateway key; when it isn't, the compaction goes on as asked and the
// log says why. nativeOf says whether a model compacts natively.
func codexCompactTo(r *http.Request, asked string, native bool, nativeOf func(string) bool) string {
if native {
return ""
}
to := provider.CodexCompactModel()
if to == "" || to == asked {
return ""
}
if nativeOf(to) {
log.Printf("gateway: Codex's compaction stays on %s, not %s: %s compacts natively, and its summary only its own account reads", asked, to, to)
return ""
}
if why := compactRefused(r, to); why != "" {
log.Printf("gateway: Codex's compaction stays on %s, not %s: %s", asked, to, why)
return ""
}
return to
}