Commit Graph
10 Commits
Author SHA1 Message Date
yetone 7a56c83e72 gateway: a compaction Copilot sealed stays out of Codex's auto-review
echo_ts (Discord #feedback) runs Codex Desktop's turns on GitHub Copilot
through magpie, with Copilot's native compaction on, and Codex's
auto-review on its built-in codex-auto-review through the ChatGPT
sign-in. The guardian's review carries the conversation's history, so
after the first compaction it carried Copilot's sealed compaction item
too. A request for one of Codex's own models with no magpie Codex
account to route it is relayed to the sign-in as it came, and
codexInputAs keeps any non-magpie1: compaction ("OpenAI's own, for
OpenAI"), so OpenAI was sent Copilot's ciphertext and refused every
review: 400 invalid_encrypted_content "The encrypted content P4ih...bDU
could not be verified". After the next compaction, the new ciphertext.

The siblings: a side call routed through magpie (the auto-review set to
a magpie model, a subagent or a title on another provider's model)
met checkpointReaders, found no writer among its candidates and was
refused with checkpointError, so the review failed there too. A turn or
a /responses/compact on one of Codex's own models relayed to the sign-in
sent the seal to OpenAI to be refused (sealedCompact took a Copilot
writer for the sign-in's own and relayed it).

Now:
- compactionAside names the calls Codex makes beside the conversation
  with its history in them: the guardian (or anything asked on
  codex-auto-review), memory, subagent, title, description, thread
  summary, prediction and suggestion. In serve, when the writer of the
  sealed compaction isn't among such a call's candidates, it goes on
  without the compaction item (withoutCompaction, body and plain);
  instructions, developer/user messages, the turns since and their tool
  calls and outputs stay. The conversation's own turns are still held
  to the writer or refused saying why (#1099), unchanged.
- foreignToSignin: on the relay to Codex's own sign-in (codexBackend), a
  compaction magpie recorded as sealed by a provider other than the
  Codex subscription is never relayed. A side call goes without it; a
  turn or a /responses/compact is answered checkpointError, magpie's
  own explanation, with nothing sent to OpenAI. A seal with no record
  (OpenAI's own, compacted on the sign-in), one the codex provider
  sealed, and one whose provider can't be read are left as before.
No portable plaintext summary exists for a native compaction (only the
writer can read it), so the side call goes without it rather than with
a summary.

Run (on mote, through mote-run, at 9730e0199 + this change):
- go test -count=1 -timeout 45m ./internal/gateway/ ./internal/usage/: ok (gateway 926s, usage 35s)
- go test -run 'TestForeignCompaction|TestNativeCompaction|TestCodex'
  ./internal/gateway: ok, again after rebasing onto f1a4b5751
  (which changed internal/gateway: trace.go and others)
- go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet
  ./internal/gateway; GOOS=linux go build -tags nogui, GOOS=windows go
  build: clean; gofmt -l internal: clean

Broken by hand: with the three non-test files at 9730e0199,
TestForeignCompactionLeftOutOfAutoReview is red in 4 subtests: the
review through the sign-in gets the reporter's exact 400 ("The
encrypted content P4ih...bDU could not be verified ...
invalid_encrypted_content"), the review and a subagent on another
provider's model are refused "compacted natively by copilot@student",
and a gpt-5.5 turn and its /responses/compact sent Copilot's seal to
OpenAI.

Not tried: the reporter's real Codex Desktop, Copilot or ChatGPT
account; the shape is from their report (Copilot compaction item with
encrypted_content, guardian on codex-auto-review). A Copilot compaction
magpie has no record of (made before compactions.json, or older than
30 days) still goes to the sign-in as before. No full ./... run: mote's
suite lock has had full suites queued for 4h; the change is confined
to internal/gateway.

Reported-by: echo_ts
2026-11-08 22:33:12 +08:00
yetone 7a6211d047 providers: a model's own headers, in Model settings
axelburks on Discord: a vendor routes one model by a header of its own.
A key's provider (built-in or custom) can give each model headers
(settings.ModelHeaders["pid/model"]). They go on that provider's
requests for that model alone, after the provider's headers and after
auth: a name both have is sent once, as the model's, so a user's value
is never overridden by the provider's or magpie's key header. The
gateway names the model (provider.WithModel) on every route that asks
one: chat on each API, translated and streamed, count_tokens, System
One's decision, embeddings, images, videos and the model test. A
fallback provider serving the same model id gets its own headers only.
Accounts and plugins carry their sign-in's headers and take none.

The editor's "Name, price and reasoning level" panel is now "Model
settings" (every language), with + Add header per model, staged and
made with the Save; Restore default takes them away.
The rows being typed are kept out of the draft's
compare, so an untouched editor still closes without asking.

Broken by hand: dropping WithModel from gateway.go turns
TestModelHeadersReachTheirModelOnEveryRoute red; dropping the provider
id check in modelOf turns TestModelHeadersStayWithTheirProvider red.

Run, on this stack over origin/main 0fc3455e2 (mote's suite lock had
hours of queue, so the suites ran on WSL magpie-desktop under flock):
- go test -timeout 45m ./internal/{provider,gateway,gui,cli,settings,fx}
  on WSL, ok; ./internal/codexcat on mote, ok; gofmt -l clean;
  go vet on mac, GOOS=linux -tags nogui and GOOS=windows on mote, ok;
  TestCoreScriptBudget ok (paid by cutting comments, no raise).
- GUI, both engines, every language, on WSL at the pushed head and at
  0fc3455e2: every touched test file plus the provider-editor files a
  first run found red. No red at head that isn't red at 0fc3455e2. The
  shared reds have issues: i18n-keys #5332, model-chip-steady #4388,
  model-copy-id #4621, models-works-only #4391, plugin-move-unserved
  #4392, provider-fetch-again #5232, provider-levels-save #4394,
  provider-levels-scroll #4395, provider-models-rest #4396,
  provider-picks-stay #4397, provider-typed #4673, remote-magpie #4398,
  zero-priced-free #5262, model-reasonless (webkit de) #4100,
  name-suffix-no-names #1937.
- Rebased on origin/main 4ab1191bc (gateway.go moved under it) and run
  again at the pushed head: gateway and provider ok on WSL, gofmt,
  vet (mac, linux nogui, windows) and the budget ok, i18n-keys,
  model-headers and routing-groups-back with only #5332's red.
Not run at push: the whole GUI suite (1277 files).

Not tried: a real vendor that routes by header (Ark); fake vendors only.

Reported-by: axelburks (Discord)
2026-11-08 11:28:54 +08:00
yetone d10f377657 providers: Names & levels is Names, prices & levels, where a model's own price at one provider is set (ferock4669)
ferock4669 asked on Discord whether magpie has a screen to price each
model, since one model can cost differently on each provider. It has:
each row in a provider's per-model list has a price box (input, output,
cache read, cache write, 1h cache write, long-context tier, $ / 1M
tokens), saved in settings' ModelPrices under pid/model. It wins over
the list price in Usage (usage.Pricer through provider.BasePriceIn) and
in a key's spend cap (usage.KeySpent through NewCoster). Nothing has to
be built; the button opening it said only "Names & levels", so nobody
finds a price there.

What changed:
- The button, its panel's heading and fold, and every note that sends
  the user there say "Names, prices & levels" (zh 名称、价格与推理档位,
  zh-TW 名稱、價格與推理檔位, ja 名前・価格・推論レベル, de "Namen,
  Preise & Stufen"); the gateway's vision and compaction notes, the
  provider package's text, the subsystem pages and the site's start
  docs (en, zh, ja) follow.
- The button's tooltip says it sets what each model costs at this
  provider; Usage's "estimated" tooltip says where a provider's own
  price is set and that it counts over the list price. Both in en, zh,
  zh-TW, ja and de.
- Not changed: the Codex model description text in internal/codexcat
  (it goes to Codex, so a vendor sees it) and core_budget_test's
  history comment.
- app.js: a comment above the price box is shortened so the core
  script stays under its budget, not raised (app.js 116 bytes under
  origin/main).

Run at the pushed head (rebased on origin/main 1af868a15), on mote:
- go test -run 'Budget|ModelPrice|ModelPref|Vision|Compaction'
  ./internal/gui ./internal/provider ./internal/gateway: ok.
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows:
  ok (before the rebase, which touched no Go of this change).
- GUI, both engines, every language each file runs: the 149 files that
  name the label or open a provider's editor (before the rebase): 1191
  ok, 30 red in 7 files. Each of the 7 is red the same way alone at
  origin/main without this change: provider-fetch-again (#5057),
  provider-typed (#4673), provider-levels-scroll webkit (#4395),
  provider-picks-stay (#4397), usage-agents-hide (#3414), usage-ledger
  Requests (#5048), mobile-web (#3952, no .git in mote-run's copy).
  name-suffix-remote "chromium de" (ERR_NAME_NOT_RESOLVED once) passed
  alone at the head. After the rebase: model-price-edit, i18n-keys,
  name-suffix-remote, usage-ledger, usage-agents-hide again: go tests above ok; model-price-edit, i18n-keys and
  name-suffix-remote (all 10 cases) ok; usage-ledger Requests and
  usage-agents-hide red as at origin/main 1af868a15.
Broken by hand: model-price-edit.test.cjs at origin/main's label is red
in all 4 cases (the button "Names, prices & levels" is not found).
Not tried: the whole GUI suite (another session's full suite was on
mote, WSL at load ~100 with 31 test runners); the real app.
2026-11-03 17:00:38 +08:00
yetone fff05e55d8 gateway: Codex's compaction trigger is summarised, not refused, when no key that lists the model can carry it (#2725)
nativeCompactionFor kept Codex's compaction_trigger whenever the
provider asked had native compaction on and could be asked it on
Responses. When the vendor's lists held the model to a key that speaks
no Responses there (a key set to Chat), compactionCarriers then cleared
every candidate and Codex got 400 carrierError, with no upstream asked:
the dead end #2725 reports. The trigger is now kept only when a key or
account the request would go over (the provider's and its fallbacks',
or a group's members', held and capped ones too, not one whose own
list lacks the model) carries it (plannedCarrier). Otherwise
codexCompact gives magpie's summary through the listed key, as with
native compaction off.

Patch by ggbdpq (#2725): route (a) and both tests are theirs. Changed
from it: their planCarries ran s.plan / s.planGroup, which weighs the
keys, and a provider routed in turn moves its turn along there
(routes.Rotate). nativeCompactionFor runs on every Codex turn (handle,
codexBackend), so each decision would have skipped a key. plannedCarrier
reads perKeyBarred without weighing. Doc sentence in
docs/subsystems/gateway-routing.md.

Run (worktree at e54a7d50b):
- TestNativeCompactionTriggerSummarisedWhenNoListedKeyCarriesIt: red
  on the old native_compaction.go ("400, the relay asked 0 times ...
  none of the keys or accounts that serve fake/m1 now can be asked it
  on the Responses"), green now.
  TestNativeCompactionTriggerThroughTheListedKeyThatCarriesIt green.
- TestNativeCompactionDecisionLeavesTheTurnsAlone (new, three keys,
  Rotate): red with the patch's planCarries ("a turn began at k2, the
  next at k1"), green with plannedCarrier.
- -race -count=3 on those three; NativeCompaction|Compact|Checkpoint|
  CodexBackend ok; the whole internal/gateway package
  (-tags nogui -count=1 -timeout 45m) ok in 609s.
- gofmt -l clean; go vet ./internal/gateway for darwin, GOOS=windows,
  GOOS=linux -tags nogui clean.
Not tried: a real relay whose vendor lists a model to a Chat-only key.
2026-10-28 00:16:48 +08:00
yetoneandggbdpq 45b8c725cf gateway: a legacy /responses/compact carrying another account's native compaction goes to that account, or is refused saying why (#2727, ggbdpq)
codexBackend's /responses/compact relayed to Codex's sign-in (or, with the
sign-in paused, compactOn's account) before any seal check, so a compact
whose input carries a compaction magpie recorded another account as the
writer of reached an account that can't read it, and Codex got the
backend's bare 400. Now sealedCompact judges it, as /responses already is
(codexSealedFor -> serve, #2642): the writer on in magpie answers it,
signed as the writer (codexUpstreamOn); a writer gone (signed out, lapsed,
paused, switched off, kept from the model) is refused 400 with
checkpointError's reason; the sign-in's own seal, a key's seal, a request
naming its own chatgpt-account-id, and a sign-in state magpie can't read
relay as before. Two Team seats of one email still read as one (the
record holds the email).

Review fix on top of ggbdpq's 781381f4: a gateway key held to some
accounts (#905) was checked (compactSigninHeld) against the sign-in before
the compact was handed to the writer, so a key held to me@ spent the
writer biz@ (acct-2 asked, 200), and a key held to biz@ was refused 403
"goes through the account Codex is signed in to" though the compact
would go to biz@. The hold is now asked of the account the compact goes
to; a writer the key may not use gets 403 sealedCompactHeldError naming
the writer, with nothing asked. The test's fake backend now records under
a lock.

Reviewed and run (reviewer, at this commit with the #2739 commit under
it, on 89521b03d; rebased after onto origin/main, see the last line):
- Each fix broken by hand, TestNativeCompactionCompactJudgesItsWriter:
  M0 codex_backend.go as on main: 3 subtests red (writer answers, gone
  refused, compactOn gone). M1 the key '#' skip dropped: "a seal a key
  wrote is not judged" red (400). M2 the chatgpt-account-id skip
  dropped: its subtest red (400). M3 the writer never relayed to: the
  healthy-writer subtest red (backend saw ""). M4 gone never refused:
  2 red. M5 judged after compactOn's relay: the compactOn subtest red
  (backend saw acct-2). Each green with the code restored.
- TestNativeCompactionCompactKeepsTheKeysAccounts (new) on ggbdpq's
  781381f4: red both ways ("200, the backend saw acct-2" for a key held
  to me@; 403 "goes through the account Codex is signed in to" for a key
  held to biz@). Red again with the hold put back on the sign-in; green
  with this change. TestGatewayKeyAccountsHoldCodexCompact and
  TestGatewayKeyCompactOnCodexAPIKey still pass.
- -race -count=3 on both tests: ok.
- gofmt -l clean; go vet ./... and -tags nogui (darwin), GOOS=linux and
  GOOS=windows go vet -tags nogui ./...: clean; go build, GOOS=linux go
  build -tags nogui, GOOS=windows go build: ok.
- Full suite, set -o pipefail, go test -tags nogui -count=1 -timeout 45m
  ./... at 519bcc843 (both changes, on 89521b03d), load ~300: exit 0,
  66 packages ok (internal/agent 2246s, internal/gateway 2040s,
  internal/provider 786s); none timed out.
- Not run: a real Team-seat pair or a real sealed compaction through a
  ChatGPT account.
- After the rebase onto origin/main 1e643ba7e (a doc-line conflict in
  gateway-routing.md resolved by hand, main's text kept): go build,
  darwin/linux/windows go vet -tags nogui of internal/gateway and
  internal/provider, and the NativeCompaction|Compact|Checkpoint|
  GoesZstd|StayPlain|TestGatewayKey and TestCodexCompressed tests: ok.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-17 23:02:36 +08:00
yetone 717b69f78a routing: a conversation held to its native compaction's account says so, not "the only account on" (#2639)
A turn carrying a native compaction goes only to the account that
sealed it, so the route's order has one account, and Routing's first
line read "{who} is the only account on for {model}". On #2639 that
read as the other account not serving the model. The route now names
the sealer (Route.Compaction, compactionWho), and Routing says the
conversation stays on it because only it can read the compaction, and
that a new conversation uses the others. Translated in zh, zh-TW, ja
and de.

Run on origin/main f191d6423 with this change:
- TestNativeCompactionRouteNamesItsWriter: green; with Compaction taken
  off the route in gateway.go by hand, red (compaction "").
- go test -run 'NativeCompaction|Compact|TestCodex|Trace|Route|
  TestProtection' ./internal/gateway: ok. go vet ./internal/gateway on
  darwin, GOOS=linux and GOOS=windows -tags nogui: ok. gofmt -l clean.
- routing-compaction.test.cjs (chromium and webkit; en zh zh-TW ja de)
  with i18n-keys: 13/13; with the client.js line removed by hand,
  routing-compaction 10/10 red.

Earlier, on dccfefdf7 with an older series around this change (since
landed by bf931f82c in another form, so dropped here): full suite once,
go vet ./... on all three OSes ok, go test -timeout 45m ./... every
package ok except internal/gui's 7 real-window AppKit tests killed at
their deadlines at load ~290 (#2645). The routing-*, panel-routing* and
i18n-keys GUI files, one at a time: reds only in routing-bodies,
routing-keys-fold, routing-model-rest and routing-request-metrics, red
the same on origin/main 84cd686af (28 there, 25 with this; #2658,
#2559, #2571). Not run on f191d6423: the full suite.
2026-10-17 19:29:07 +08:00
bf931f82c3 gateway: a Codex conversation compacted natively is held to its account only when native compaction is on, and told why when it can't go there (#2642, #2582)
ScarfQian (#2642, still on v0.1.1279): after a native compaction by one
Codex account, routing to another answered 400 "only that key or account
can read the compaction it sealed ... switched off, removed, or no longer
serves". Three causes, one fix each:

- #2582 (Dony2050, ump45nose's patch): one of Codex's own models asked on
  the backend path through magpie's accounts (codexAccounts) kept the
  compaction_trigger whatever the codex provider's native compaction
  setting, so every compaction was sealed by and recorded to one account.
  It is now decided as a magpie model's is: codexInputAs with
  nativeCompactionFor("codex/<model>"); off (the default) gives
  codexCompact's magpie1: summary, which any account reads, and records
  no writer. Unlike ump45nose's branch, /responses/compact and Codex's
  own single sign-in relay are left as they were: the legacy endpoint's
  body has no trigger for codexCompact to answer, and a lone sign-in has
  no other account to move to.
- ggbdpq's fix (0ab41eba0, e1646488d, ported as is): a writer whose own
  model list has since dropped the model sat in planned.left, out of the
  candidates, so checkpointReaders never found it and refused although it
  was on. It is now taken back from planned.unlisted (plan, planLevel and
  the nested weighted plan), its row moved from left to order.
  sealedReaders, run before it for a sealed subagent task, narrows
  unlisted too (sibling).
- A request carrying a recorded seal while only Codex's own sign-in is on
  was relayed as it came (codexAccounts false), so with the writer
  switched off the one account left was sent it. codexSealedFor routes
  it through serve, where checkpointReaders holds it to the writer.
- checkpointError now says the reason magpie's settings give
  (checkpointGone: provider removed, account signed out, sign-in lapsed,
  paused while others are on, switched off, kept from the model in Names &
  levels, key off or gone, model disabled, or the model/group asked for
  not routing to it), the fix for that reason, and whether native
  compaction is on for the writer's provider now. The old catch-all
  sentence is gone.

The seal is still treated as readable only by the account that wrote it,
as #1099 and #2271 found; chestnutLeeeee's report that another account read
one in a direct canary was not tried here (no real accounts).

Tests (fake ChatGPT backend, sandbox HOME, nothing on the network):
TestCodexOwnModelCompactionHonoursTheToggle (off: summary, no trigger
upstream, no writer; on: native seal kept, writer recorded),
TestNativeCompactionWriterGoneSaysWhy (spare switched off, own paused,
Names & levels, signed out), ggbdpq's
TestNativeCompactionWriterWhoseListLacksTheModel and
...ThroughAGroupWhoseListLacksTheModel. All four are red on 7660399a1.
Broken by hand on this change, each went red: codexInputAs back to
(false,false) -> Toggle; codexSealedFor not called -> spare switched off;
the unlisted loop emptied -> both WhoseList tests; the Paused case
skipped -> own paused.

TestProtectionRefusalAskedOnceNobodyRests (vs's 502 "response protection
is unavailable" on a bare gpt-5.5 compaction through three accounts) was
about the native path, which that model now takes only with native
compaction on; it turns it on (nativeOn). Off, the compaction is magpie's
summary, as TestProtectionRefusedCompactionAsText already covers.

Run at this change on 7660399a1: gofmt -l clean; go vet ./... (darwin),
GOOS=linux and GOOS=windows go vet -tags nogui ./... ok;
full go test -tags nogui -timeout 45m ./... (load average ~140): every
package ok except internal/agent and internal/gateway, which ran past 45m
(#2544, #2108), and TestProtectionRefusalAskedOnceNobodyRests, mine,
fixed above. Then each alone: internal/gateway -timeout 45m finished in
2345s with one red, TestTranslatedStreamKeepsClientAlive/responses_to_chat
(a keepalive timing test under load, passes alone; filed as #2711, sibling
of #2169); internal/agent -timeout 100m ok in 2115s. The protection,
compaction and Codex tests (-run 'TestProtection|Compact|Compaction|TestCodex')
ok after the test change.
No GUI file changed. Not tried against the real ChatGPT backend.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
Co-authored-by: ump45nose <52391318+ump45nose@users.noreply.github.com>
2026-10-17 18:19:51 +08:00
yetone 440f66701f gateway: a 429 for native compaction's one account says the compaction pinned it, not that every account is capped (#2517)
When a conversation was compacted natively, only the key or account that
sealed the compaction can read it (#1099), so checkpointReaders keeps the
candidates to that one. When that account was at its usage cap, the 429
and the call record said "every account that serves X is held at the
usage cap", although the other accounts were never candidates. That sent
lm0711 looking at routing modes, which can't change it.

checkpointHeld tells this case apart: the plan held only the sealer's
account(s), and others were left out for the checkpoint. The error then
names the account and its window, says the compaction it sealed is what
keeps the conversation there, that routing mode and stays don't change
that, and to raise the cap / spend credits or start a new conversation.
The record reads "native compaction's account at its usage cap" (or its
credits / both variants). cappedError and cappedRecord are unchanged for
every other 429; their text is split into heldReasons and heldAdvice so
both share it. docs/subsystems/gateway-routing.md says so.

Test: TestNativeCompactionWriterAtItsCap seals a checkpoint on one
account, caps it, and checks the 429 body and the record. Broken by hand
(checkpointHeld returning nil), it fails with the old "every account"
text.

Run on origin/main d9b943555 (head 663db0ecf), with the #2517,
#2521 and #2522 changes, load ~240:
- gofmt -l clean; go vet -tags nogui for darwin, linux and windows: ok.
- go test -timeout 120m -count=1 ./... (pipefail): exit 0, every package
  ok (gateway 1416.8s, agent 1535.5s). Before the rebase, on 63be47717:
  - The 45m run had agent and gateway past 45m (#2544, #2108).
  - TestMainWindowCorners was killed at its deadline (#1936).
  - TestSkillRelinkKeepsUnreadableCopy failed (#2555; it passes alone).
  - gateway alone with 120m was ok.
- GUI, the 41 Requests/Usage files in serial, both engines, before the
  rebase: 493 pass, 3 fail. The 3 were usage-refresh "not yet 2 !== 1",
  the same on 63be47717 alone (1 of 3); seen again on #2184.
- Rebased, these all pass, 102/102: i18n-keys, usage-ledger-ttft,
  usage-ledger-key-split, usage-ledger, usage-speed, usage-ledger-detail,
  gui-ja, gui-de and gui-zh-tw.
- Rebased again onto 9b04c4e20, which touches ledger.go, request_page.go
  and gateway.go:
  - vet ×3: ok.
  - internal/usage, internal/usageapi and internal/cli: ok.
  - internal/gateway -run 'NativeCompaction|UsageOverGateway|Capped|Cap':
    ok.
  - usage-ledger-ttft, usage-ledger-key-split, usage-ledger and
    usage-speed: 86 pass. i18n-keys was red from main's own words (#2586,
    fixed in the next commit).
2026-10-16 21:59:32 +08:00
yetone 4ad929fd4d gateway: a native compaction a fallback seals is recorded to it, and its next turn goes there with the compaction, not answered 200 without it (#2271, JasonBuildAI)
With native compaction on for a provider, Codex's compaction_trigger
goes to any candidate whose wire carries it, a fallback included. The
compaction watcher recorded the writer only when the candidate that
answered had native compaction on itself (`if s.compactsNatively(...)
{ sealedBy = &c }`), so a fallback's seal went unrecorded. The next turn
carrying it then either went to another provider, which refused the
foreign item, and magpie dropped it (withoutCompaction, guarded only by
`checkpoint == nil`) and answered 200 without the compacted history; or
went to the fallback translated, since keepsCompaction kept a sealed
compaction only for a provider set to compact natively, and the
translation left the item out.

Fix:
- the writer is recorded whoever answered: the watcher exists only when
  the trigger was kept, so whoever answered sealed it;
- keepsCompaction also relays a sealed compaction to the provider
  recorded as its writer (checkpointOf), whatever its own setting;
- checkpointError no longer says "native compaction is on for <writer>",
  which isn't so for a fallback;
- docs/subsystems/gateway-routing.md says so.

Test: TestNativeCompactionFallbackSealStaysWithItsWriter (fa native,
falls back to fb, native off, which seals; a third provider). Broken by
hand, each part fails it:
- recording only native writers: the other provider answers 200 with
  the seal dropped;
- keepsCompaction ignoring the record: the writer's next turn (Codex's
  shape, offering web_search) goes translated without the seal;
- the old wording: the error says native compaction is on.

Run on the rebased head (origin/main plus #2274 and this):
go test ./internal/gateway/ -count=1, gofmt -l, go vet -tags nogui for
GOOS=darwin/linux/windows ./internal/gateway: see the ready note; all
green before this was handed over.
Full suite: SUITE_LINE
2026-10-15 23:08:00 +08:00
yetone 82f48f0935 gateway, provider, gui: a provider set to compact natively is asked Codex's compaction_trigger as sent and its sealed compaction goes back unchanged; a checkpoint stays with its writer (#1099)
A new per-provider option, off by default. With it on, Codex's
compaction_trigger reaches the provider as Codex sent it, and the
provider's encrypted compaction item goes back to Codex unchanged instead
of magpie's magpie1: summary. Off, nothing changes.

Where it can be on (provider.CarriesCompaction): a provider with a
Responses API (Sub2API and other OpenAI relays, a remote magpie), a
ChatGPT (codex) account, and the built-in GitHub Copilot on its GPT
Responses path. Copilot's Claude models are asked on chat completions, so
they still get magpie's summary (CompactsOn). A group compacts natively
only when every member does.

No silent downgrade:
- A turn carrying a sealed compaction goes only to the key or account that
  wrote it (compactions.json beside affinity.json, 0600, 1024 entries /
  30 days). With none left, Codex gets a 400 saying the conversation was
  compacted natively on <who>, not a summarised or dropped context.
- A provider whose request would have to be translated (not relayed) is
  refused with a 400 instead of losing the item.
- The upstream's own refusal goes back to Codex as it came, one call.
- base_instructions and Codex's identity are untouched.

Turning it on:
- GUI: the provider editor's Compaction row, "Codex compacts on this
  provider" (shown only where the wire can carry it; zh, zh-TW, ja, de).
- CLI: magpie provider set <id> compaction=native|magpie. A provider that
  can't carry it is refused.

Run on origin/main 00501401a, then rebased onto 84f14e555 (no file in
common) and reran gofmt, vet and go test for gateway, gui, provider,
cli, usage and sessions: all ok. Rebased again onto 8d2a4a7da (gateway.go
and codex_backend.go changed on both sides, merged clean) and reran
gofmt, vet (darwin, linux nogui, windows) and go test for gateway, cli,
provider and gui: all ok. Last rebased onto 7a3fed6bb (only
gateway-routing.md shared, merged clean): gofmt, vet on all three OSes,
and go test -run for the native compaction, sink, CORS, rebind and origin
tests in gateway plus the provider tests: ok.
- gofmt -l: clean. go vet darwin, GOOS=linux -tags nogui, GOOS=windows:
  clean.
- set -o pipefail; go test -timeout 40m ./...: every package ok but
  internal/provider's TestCopilotSecretToolUsername (copilot_cli_test.go:93
  token "", 10.05s), the open load flake #1627; it passes alone -count=5
  and this change doesn't touch it.
- GUI (node --test, chromium + webkit): the provider-editor files, 946
  pass, 0 fail; the new provider-native-compaction.test.cjs runs 5
  languages at 1100 and 420 (60 cases).
- New Go tests: TestNativeCompactionPassesTheTrigger, ...RefusalGoesBack,
  ...StaysWithItsWriter, ...Copilot (gateway), TestCarriesCompaction,
  TestSetNativeCompaction (provider), TestProviderSaveNativeCompaction
  (gui), TestProviderCompactionPair (cli).

Broken by hand, each red, then restored:
1. codexInputAs dropping the trigger even when native: all 4 gateway
   tests fail.
2. checkpoint filter off: StaysWithItsWriter fails.
3. forced relay off: all 4 gateway tests fail (the web_search tool sends
   the turn to translation).
4. GUI save sending nativeCompaction false: the GUI test's first case
   fails.

Not tried: any real upstream (Sub2API, ChatGPT, Copilot). Copilot may
refuse a compacted history holding web_search items; that refusal would
go back to Codex as-is.
2026-10-15 05:20:17 +08:00