gateway: a Codex subagent refused for a sealed task is told the task itself is sealed, which fork_turns="none" doesn't change (#1855, hanekoo)
hanekoo's Codex Desktop lead on gpt-6.1-sol (Codex's own ChatGPT sign-in)
spawned a subagent on antigravity/gemini-3.8-flash with fork_turns="none"
and got the sealed-task refusal, which read as if the lead's turns were
the problem and fork_turns="none" should have avoided it.
What Codex rust-v0.162.0-alpha.17.2 sends (read from its source, not the
reporter's bytes, which aren't available): spawn.rs's fork_mode is None
for "none", so no turn of the lead's is copied in. The subagent's task is
spawn_agent's `message` argument; the ChatGPT backend returns it sealed
(the function call's encrypted_function_args), router.rs's direct_source
makes it ToolCallSource::Direct, agent_message_from_tool makes it
AgentMessage::Encrypted, and to_model_input_item writes it as the
agent_message's encrypted_content under the NEW_TASK header. So the one
sealed thing in the subagent's first request is the task itself: there is
nothing magpie can leave out and still give the subagent work, and no
request flag in Codex asks the backend for plaintext arguments. The
refusal stays; it now says why.
- codex_backend.go: sealedTaskItself, added to all three sealedTaskError
variants (lead unknown / Codex's own sign-in, a relay that sealed it,
plugins#70's earlier chat provider): what is sealed is the task the
spawning agent wrote in spawn_agent, and fork_turns="none" keeps only
the lead's turns out, not the seal. The existing advice (the lead's
model for the subagent, or a lead not on the ChatGPT backend) stays.
- docs/subsystems/gateway-routing.md: the same, under sealed tasks.
- sealed_fork_none_test.go: the fork_turns="none" first request rebuilt
from Codex's source (developer + environment_context + the sealed
NEW_TASK with Task name/Sender lines), a lead first on Codex's own
sign-in, the subagent on a chat provider. It is refused before the
provider is asked, with no ciphertext in the reply, and says the task
itself is sealed whatever fork_turns says.
Run: with the old codex_backend.go put back,
TestSealedTaskWithForkTurnsNoneSaysTheTaskItselfIsSealed fails ("the
refusal doesn't say the task itself is sealed whatever fork_turns
says"); with the change it passes. gofmt -l (empty), go vet / GOOS=linux
-tags nogui / GOOS=windows go vet ./internal/gateway, go build, GOOS=linux
-tags nogui and GOOS=windows go build ./..., go test -tags nogui
./internal/gateway (ok, 353s) under a sandbox HOME with a private GOCACHE.
Not run: the whole `go test ./...` (only the gateway package changed);
no real Codex Desktop or ChatGPT account was used, so the reporter's
bytes are not reproduced; the GUI's sealedKept text is unchanged. The
502 "context canceled" on gpt-6.1-sol in the report is Codex's own
sign-in request most likely cancelled by Codex itself (the client went away), a separate
request, and wasn't chased.
This commit is contained in:
@@ -36,7 +36,7 @@ served by a plugin are in [Provider and plugin ownership](provider-plugins.md).
|
||||
- With *Mask secrets* on, the user's own masking rules (`redactRules`, `redact.Rule`: a placeholder name and a prefix or an RE2 pattern, [`internal/redact/rules.go`](../../internal/redact/rules.go)) run before magpie's. Settings → Privacy adds them, removes them, and edits one in place (`POST /api/settings/redact-rule` with the rule's index and its current value, `editRedactRule` in [`internal/gui/api.go`](../../internal/gui/api.go)). Every rule is checked by `redact.CheckRules` when settings are saved; an edit that doesn't compile, matches the empty string, repeats another rule or names a rule no longer at that index is refused with the rules left as they were. The gateway reads the rules from settings on each request (`redactionOptions`), so a change applies to the next request.
|
||||
- `DecidesModel` gives a 400.
|
||||
- A gateway key held to some models (`keyHolds`, #882) gets a 403 for any other model.
|
||||
- Sealed tasks (#619) are checked here. A Codex subagent's task its lead's `spawn_agent` sealed goes only to a ChatGPT account, or back to the Responses provider that answered the lead (`leadProvider`, a relay of the ChatGPT backend such as Sub2API, #1109), relayed as it came even when web search is offered. A lead's turn carrying its subagent's sealed reply (`send_message`) goes back to the Responses provider that answered the lead's own conversation (`leadProvider` of the request's `conversationID`, #1237); otherwise it is refused before anyone is asked (`sealedReader`, `sealedTaskError`). A sealed message (`Message Type: MESSAGE`, not a task) that nobody asked can open is left out instead, an `input_text` note naming its sender in its place (`withoutSealedMessages`, #1613): a lead on a chat provider whose subagent is on one of Codex's own models goes on, as the subagent's final result still reaches it as text. Only a sealed task (`NEW_TASK`, or an item with neither header) is refused. Who answered is first what affinity remembers; when affinity has let it go (a day since, a restart past the 512 conversations `affinity.json` keeps, or the lead's last reply broken off, `unanswered`), the usage log's answers to the lead's thread and the request's own conversation in the last 30 days count too (`loggedAnswers`, #1367), and `leadFirst` reads the lead's key or account from them. A refused or failed call and a title answer nothing, and Codex's own sign-in is told of as the ChatGPT backend. The refusal names who sealed the task when it is known, and says how to go on with it.
|
||||
- Sealed tasks (#619) are checked here. A Codex subagent's task its lead's `spawn_agent` sealed goes only to a ChatGPT account, or back to the Responses provider that answered the lead (`leadProvider`, a relay of the ChatGPT backend such as Sub2API, #1109), relayed as it came even when web search is offered. A lead's turn carrying its subagent's sealed reply (`send_message`) goes back to the Responses provider that answered the lead's own conversation (`leadProvider` of the request's `conversationID`, #1237); otherwise it is refused before anyone is asked (`sealedReader`, `sealedTaskError`). A sealed message (`Message Type: MESSAGE`, not a task) that nobody asked can open is left out instead, an `input_text` note naming its sender in its place (`withoutSealedMessages`, #1613): a lead on a chat provider whose subagent is on one of Codex's own models goes on, as the subagent's final result still reaches it as text. Only a sealed task (`NEW_TASK`, or an item with neither header) is refused. Who answered is first what affinity remembers; when affinity has let it go (a day since, a restart past the 512 conversations `affinity.json` keeps, or the lead's last reply broken off, `unanswered`), the usage log's answers to the lead's thread and the request's own conversation in the last 30 days count too (`loggedAnswers`, #1367), and `leadFirst` reads the lead's key or account from them. A refused or failed call and a title answer nothing, and Codex's own sign-in is told of as the ChatGPT backend. The refusal names who sealed the task when it is known, and says how to go on with it. It also says what is sealed (`sealedTaskItself`, #1855): the task itself, `spawn_agent`'s `message`, which the backend returns sealed (`encrypted_function_args`) and Codex hands the subagent as it came, so `fork_turns="none"`, which only leaves the lead's turns out, doesn't help; nothing in it can be left out for the subagent to go on.
|
||||
- A model set for Codex's subagents (`settings.CodexSubagentModel`, the Agents page's Codex "subagent model", willz on Discord) is put on a Codex subagent's request (`x-openai-subagent` read as `kind:collab_spawn`) before this check, whatever model its lead's `spawn_agent` asked for (`codexSubagentPick` in [`codex_subagent.go`](../../internal/gateway/codex_subagent.go)): in `codexBackend` for one of Codex's own bare models, which then goes through `serveAgent`, and in `serve` for any other. Any model magpie serves can be set (`provider.SetCodexSubagentModel`, #1633): a task handed as text (a lead magpie served on a chat provider, or multi-agent V1) is read by any model. A request carrying a task the ChatGPT backend sealed (`sealedTaskIn`: a sealed agent message that isn't a `MESSAGE`, which `withoutSealedMessages` leaves out) is put only on a ChatGPT account's model; set to another, the subagent stays on the model asked for, which the sealed gate below handles as with nothing set. When magpie doesn't serve the model set now, or a gateway key held to some models may not use it, the subagent goes on the model asked for too. The route trace keeps both models and the reason it stayed (`Route.Subagent`), and the Routing page's `kindWhy` says it. The lead's turns, titles and every other kind are never moved.
|
||||
- Rules and image inputs are handled here too.
|
||||
- A rule is decided as a user's turn begins and held for the rest of it (`ruleFor`, [`rules.go`](../../internal/gateway/rules.go)). What counts as the user's own words is one helper, `userWords`/`userSaid` in [`prompt.go`](../../internal/gateway/prompt.go), which the turn count (`turnIn`), the classifier's question (`userText`), the conversation's key (`firstWords`, in `ruleKey` and the affinity scope), Copilot's Auto (`lastUserText`) and the prompt breakdown's turns (`userSays`) all go by. It drops `<system-reminder …>` blocks (a `source=` attribute too) and any text that begins as an agent writes for the model alone: Codex's `<environment_context>`, `<user_instructions>`, `<turn_aborted>`, `<user_shell_command>`, `<subagent_notification>` and `# AGENTS.md instructions for …`; Claude Code's and ZCode's `<task-notification>`, `<subagent-notification>`, agent lists ("Available agent types …", "New agent types are now available …"), TodoWrite and task-tool nudges and rewind notices; ZCode's `<plugin_reference>`; the Codex app's `<in-app-browser-context …>`. The Codex app's context before `## My request (for Codex):` is dropped and what follows it kept (the `injected` list beside `agentsFor`). A user message with nothing of the user's in it (and no image or file) begins no turn: after an answer or a tool round it carries the turn on (`within`), so the turn's rule and stick hold and the classifier isn't asked; right after the user's words it leaves their turn as it began. The classifier is asked about the last user message that has words of the user's, only those words. `firstWords` hashes the words of the first user message that has any, so an instruction file or notice the agent changes beside them doesn't move the conversation to a new key and lose its stick mid-turn (#1826: ZCode's TodoWrite nudge classified as a new, harder turn, and three keys for one ZCode session). `TestTurnInSkipsWhatTheAgentPutIn`, `TestUserTextSkipsWhatTheAgentPutIn`, `TestFirstWordsAreWhatTheUserSaid`, `TestIntentHoldsPastWhatTheAgentPutIn`.
|
||||
|
||||
@@ -170,17 +170,26 @@ func (s *Server) codexBackend(w http.ResponseWriter, r *http.Request) {
|
||||
// is said too (#1367). earlier is a provider that answered the lead's
|
||||
// earlier turns but can't have sealed the task (canSeal): the lead moved
|
||||
// on to Codex's own model, whose turns magpie keeps no record of, and the
|
||||
// task was sealed there (plugins#70).
|
||||
// task was sealed there (plugins#70). Each says what is sealed: the task
|
||||
// itself, which fork_turns="none" doesn't change (#1855).
|
||||
func sealedTaskError(model, lead, earlier string) string {
|
||||
if earlier != "" {
|
||||
return fmt.Sprintf("This subagent's task was sealed by the ChatGPT backend, which answered the agent that sent it on one of Codex's own models (a subagent of this thread put there, or the lead after a switch), and only a ChatGPT account can open it. %s can't. %s answered the lead's earlier turns, but it neither seals a task nor opens one. Set Codex's subagent model on magpie's Agents page to a model of a ChatGPT account added in magpie, or to one that isn't served by the ChatGPT backend, so subagents get tasks they can read. To go on with this task, have it spawned again from an agent that isn't on Codex's own models.", model, earlier)
|
||||
return fmt.Sprintf("This subagent's task was sealed by the ChatGPT backend, which answered the agent that sent it on one of Codex's own models (a subagent of this thread put there, or the lead after a switch), and only a ChatGPT account can open it. %s can't. %s answered the lead's earlier turns, but it neither seals a task nor opens one. "+sealedTaskItself+" Set Codex's subagent model on magpie's Agents page to a model of a ChatGPT account added in magpie, or to one that isn't served by the ChatGPT backend, so subagents get tasks they can read. To go on with this task, have it spawned again from an agent that isn't on Codex's own models.", model, earlier)
|
||||
}
|
||||
if lead != "" {
|
||||
return fmt.Sprintf("This subagent's task was sealed by the server that answered its lead (%s), and only that server can open it; %s can't. Give the subagent the lead's model, or a lead model that isn't served by the ChatGPT backend, so its subagents get a task they can read. To go on with this task, use a model on %s for the lead and the subagent, or have the lead spawn the subagent again.", lead, model, lead)
|
||||
return fmt.Sprintf("This subagent's task was sealed by the server that answered its lead (%s), and only that server can open it; %s can't. "+sealedTaskItself+" Give the subagent the lead's model, or a lead model that isn't served by the ChatGPT backend, so its subagents get a task they can read. To go on with this task, use a model on %s for the lead and the subagent, or have the lead spawn the subagent again.", lead, model, lead)
|
||||
}
|
||||
return fmt.Sprintf("This subagent's task was sealed by the ChatGPT backend that answered its lead, and only that backend can open it: a ChatGPT account, or the Responses API provider that answered the lead. %s is neither: magpie has no record of it answering the lead in the last 30 days. Give the subagent the lead's model, or a lead model that isn't served by the ChatGPT backend, so its subagents get a task they can read. To go on with this task, use the lead's model, or have the lead spawn the subagent again.", model)
|
||||
return fmt.Sprintf("This subagent's task was sealed by the ChatGPT backend that answered its lead, and only that backend can open it: a ChatGPT account, or the Responses API provider that answered the lead. %s is neither: magpie has no record of it answering the lead in the last 30 days. "+sealedTaskItself+" Give the subagent the lead's model, or a lead model that isn't served by the ChatGPT backend, so its subagents get a task they can read. To go on with this task, use the lead's model, or have the lead spawn the subagent again.", model)
|
||||
}
|
||||
|
||||
// sealedTaskItself says what a sealed task is (#1855): spawn_agent's
|
||||
// message, which the backend that answered the lead returns sealed (its
|
||||
// function call's encrypted_function_args), and which Codex hands the
|
||||
// subagent as it came, as its NEW_TASK (codex-rs multi_agents_v2.rs
|
||||
// agent_message_from_tool). fork_turns="none" leaves only the lead's
|
||||
// history out of the subagent's first request; the task is still sealed.
|
||||
const sealedTaskItself = `What is sealed is the task itself: the message the agent that spawned this subagent wrote in spawn_agent, which Codex hands on as the backend sealed it. fork_turns="none" keeps the lead's earlier turns out of the subagent, but not the seal on its task, so it doesn't help here.`
|
||||
|
||||
// canSeal says whether the provider id names could have sealed a
|
||||
// subagent's task, as sealedReader has who can open one: a ChatGPT
|
||||
// account, or a provider of no sign-in serving the Responses API (a relay
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// forkNoneTask is the first request Codex 0.162 (rust-v0.162.0-alpha.17.2)
|
||||
// sends for a subagent its lead spawned with fork_turns="none", rebuilt
|
||||
// from Codex's source, not the reporter's bytes (#1855 has none):
|
||||
// spawn.rs's fork_mode is None for "none", so no turn of the lead's is
|
||||
// copied in, and the input is the subagent's own context and its task.
|
||||
// The task is spawn_agent's message, which the ChatGPT backend returned
|
||||
// sealed (encrypted_function_args), so agent_message_from_tool makes it
|
||||
// AgentMessage::Encrypted and to_model_input_item writes it under the
|
||||
// NEW_TASK header as encrypted_content.
|
||||
const forkNoneTask = `{"model":"ag/gemini-3.8-flash","stream":true,"store":false,"instructions":"You are Codex.","tools":[],"tool_choice":"auto","parallel_tool_calls":true,"include":["reasoning.encrypted_content"],"input":[` +
|
||||
`{"type":"message","role":"developer","content":[{"type":"input_text","text":"<permissions instructions>Filesystem sandboxing: workspace-write.</permissions instructions>"}]},` +
|
||||
`{"type":"message","role":"user","content":[{"type":"input_text","text":"<environment_context>\n <cwd>/Users/u/proj</cwd>\n <shell>zsh</shell>\n</environment_context>"}]},` +
|
||||
`{"type":"agent_message","author":"/root","recipient":"/root/gemini_worker","content":[{"type":"input_text","text":"Message Type: NEW_TASK\nTask name: /root/gemini_worker\nSender: /root\nPayload:\n"},{"type":"encrypted_content","encrypted_content":"gAAAAABo_sealedTaskFromTheLead-Q3x9_aZ=="}]}]}`
|
||||
|
||||
// #1855 (hanekoo): Codex Desktop's lead on gpt-6.1-sol, Codex's own
|
||||
// ChatGPT sign-in, spawns a subagent on ag/gemini-3.8-flash with
|
||||
// fork_turns="none". The task is still sealed, since it is the task
|
||||
// itself that is, so the subagent is turned away before ag is asked, and
|
||||
// told so: fork_turns="none" isn't left looking like it should have helped.
|
||||
func TestSealedTaskWithForkTurnsNoneSaysTheTaskItselfIsSealed(t *testing.T) {
|
||||
fresh(t)
|
||||
chatgpt(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
io.ReadAll(r.Body)
|
||||
w.Header().Set("Content-Type", "text/event-stream")
|
||||
io.WriteString(w, sse(`data: {"type":"response.completed","response":{"id":"r1","status":"completed","output":[]}}`))
|
||||
})
|
||||
asked := chatOnlyOn(t, "ag")
|
||||
s := New()
|
||||
if rec := codexSubTurn(s, "gpt-6.1-sol", "lead-1855", "", leadAsk); rec.Code != 200 {
|
||||
t.Fatalf("lead on Codex's own sign-in: %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
// chatOnlyOn serves "dfmodel"; the subagent asks for the reporter's model
|
||||
body := strings.ReplaceAll(forkNoneTask, "ag/gemini-3.8-flash", "ag/dfmodel")
|
||||
req := httptest.NewRequest("POST", CodexPath+"/responses", strings.NewReader(body))
|
||||
req.Header.Set("Authorization", "Bearer chatgpt-token")
|
||||
req.Header.Set("chatgpt-account-id", "acct-1")
|
||||
req.Header.Set("User-Agent", "Codex Desktop/0.162.0-alpha.17.2 (Mac OS 15.7.3; arm64) unknown (Codex Desktop; 26.1007.30912)")
|
||||
req.Header.Set("session_id", "worker-1855")
|
||||
req.Header.Set("x-codex-parent-thread-id", "lead-1855")
|
||||
req.Header.Set("x-openai-subagent", "collab_spawn")
|
||||
rec := httptest.NewRecorder()
|
||||
s.Handler().ServeHTTP(rec, req)
|
||||
var got struct {
|
||||
Error struct {
|
||||
Message string `json:"message"`
|
||||
} `json:"error"`
|
||||
}
|
||||
json.Unmarshal(rec.Body.Bytes(), &got)
|
||||
msg := got.Error.Message
|
||||
if rec.Code != 400 || *asked != 0 || strings.Contains(rec.Body.String(), "gAAAAA") {
|
||||
t.Fatalf("subagent: %d %s (ag asked %d times)", rec.Code, rec.Body.String(), *asked)
|
||||
}
|
||||
if !strings.Contains(msg, "sealed by the ChatGPT backend that answered its lead") ||
|
||||
!strings.Contains(msg, "What is sealed is the task itself") ||
|
||||
!strings.Contains(msg, "spawn_agent") ||
|
||||
!strings.Contains(msg, `fork_turns="none" keeps the lead's earlier turns out of the subagent, but not the seal on its task`) ||
|
||||
!strings.Contains(msg, "Give the subagent the lead's model") {
|
||||
t.Fatalf("the refusal doesn't say the task itself is sealed whatever fork_turns says: %s", msg)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user