gateway: the Codex app's page state is metadata, not the user's words (#3418)

What: <external_codex_apps_open_page> joins the injected leads in
prompt.go, beside the Codex app's <in-app-browser-context …>: a user
text that begins with it is what the agent put in as the user, not
words of theirs. Codex sends the open page's state as a user message
(<external_codex_apps_open_page>{"page_id":null}</external_codex_apps_open_page>),
and userWords took it for the user's. With pasted files and an empty
"My request" — which keeps only what follows the heading — it was the
only text left, so the classifier was asked about the page state alone
and an order group fell to its first member for the whole turn.

Everything that goes by userWords skips it alike now: no turn of its
own (turnIn, the prompt breakdown's turns), no words for the classifier
(userText, firstWords), nothing for a plugin's query or Copilot's Auto
to pick on, and — through agentNotice — a page state after a tool
result closes the result without being marked as the user's. The title
digest already skipped the marker (title_link.go); the two lists say
the same again. Whatever the marker wraps goes with it, JSON or not
(the check is the prefix); a "My request" that holds the user's words
still classifies on those alone.

Run: user_said_test.go grows the page state (three rows in
TestUserTextSkipsWhatTheAgentPutIn, codexPage in
TestUserSaysPastAReminderWithASource) and
TestIntentSkipsWhatTheCodexAppPutIn asks the group end to end. All
three are red on the parent (the classifier is asked once, with the
page state alone, and a rule matches on it) and green here, beside the
#1826 tests they extend; with prompt.go alone put back they are red
again. go test -tags nogui ./internal/gateway -count=1 green (357s);
gofmt -l clean; go vet ./... on darwin, GOOS=linux -tags nogui and
GOOS=windows clean; go build ./... on darwin and the nogui CLI on
linux and windows.

Generated-by: GLM-5.3-Flash (ZCode)

Ported from ggbdpq's fork (hunt75-b-page-metadata, f8347ce50), as
written, onto origin/main 4c1fb7758 (321sssrt on X asked after it).
At this head on mote: the three tests above plus the TestUserText,
TestUserSays and TestIntent families green; with the prompt.go line
taken out, TestUserTextSkipsWhatTheAgentPutIn,
TestUserSaysPastAReminderWithASource and
TestIntentSkipsWhatTheCodexAppPutIn red. gofmt -l clean; go vet
./internal/gateway on darwin, GOOS=linux -tags nogui and GOOS=windows
clean. Not run at this head: the whole gateway package (the author ran
it green at dd1e8822d) and a real Codex app turn.
This commit is contained in:
ggbdpq
2026-10-28 14:15:40 +08:00
committed by yetone
parent 4c1fb7758b
commit a463b3ede2
2 changed files with 23 additions and 1 deletions
+1
View File
@@ -725,6 +725,7 @@ var (
injected = []string{
"<system-reminder", "<environment_context>", "<user_instructions>", "<turn_aborted>",
"<user_shell_command>", "<subagent_notification>", "<in-app-browser-context",
"<external_codex_apps_open_page>",
"<task-notification>", "<subagent-notification>", "<plugin_reference>",
"Available agent types for the Agent tool:", "Available agent types and the tools they have access to:",
"New agent types are now available for the Agent tool:",
+22 -1
View File
@@ -30,6 +30,9 @@ const (
envContext = "<environment_context>\n <cwd>/Users/me/app</cwd>\n <shell>zsh</shell>\n <current_date>2026-10-12</current_date>\n</environment_context>"
codexAgents = "# AGENTS.md instructions for /Users/me/app\n\n<INSTRUCTIONS>\nRun the tests.\n</INSTRUCTIONS>"
inAppBrowser = "# Context from my IDE setup:\n\n# In app browser:\n<in-app-browser-context source=\"ambient-ui-state\">\nhttps://example.test/ — Example\n</in-app-browser-context>\n\n"
codexPage = `<external_codex_apps_open_page>{"page_id":null}</external_codex_apps_open_page>`
pastedRequest = "# Files pasted by the user:\n\n## \"Fix a race...\": /tmp/fixture/task.txt\n\n" +
"Pasted text contains the user's request.\n\n## My request:\n"
)
func userMsg(texts ...string) Message {
@@ -107,6 +110,9 @@ func TestUserTextSkipsWhatTheAgentPutIn(t *testing.T) {
{"a todo nudge after the turn", []Message{userMsg(q), saidAnswer, userMsg(zcodeTodo)}, q},
{"Codex", []Message{userMsg(codexAgents, envContext, "fix the bug")}, "fix the bug"},
{"the Codex app", []Message{userMsg(inAppBrowser + "## My request for Codex:\nwhat is this page?")}, "what is this page?"},
{"the Codex app's page state", []Message{userMsg(codexPage)}, ""},
{"page state, pasted files and an empty request", []Message{userMsg(codexPage), userMsg(pastedRequest)}, ""},
{"page state beside the request", []Message{userMsg(codexPage, pastedRequest+"fix the race")}, "fix the race"},
{"a reminder with a source", []Message{userMsg(goalContinuation + "\nship it")}, "ship it"},
} {
if got := userText(&Request{Messages: tc.ms}); got != tc.want {
@@ -176,9 +182,24 @@ func TestIntentHoldsPastWhatTheAgentPutIn(t *testing.T) {
}
}
// The Codex app's page state is not words of the user's: alone, or beside
// pasted files when "My request" is empty, it asks the classifier nothing
// (#3418) — there is nothing of the user's to classify.
func TestIntentSkipsWhatTheCodexAppPutIn(t *testing.T) {
s, _, _, c := intented(t, provider.Rule{Use: "b/big", Intent: "complex tasks"})
c.set("1", 0)
body := `{"model":"group/r","messages":[` +
`{"role":"user","content":` + quote(codexPage) + `},` +
`{"role":"user","content":` + quote(pastedRequest) + `}]}`
_, r := postOK(t, s, "s1", body)
if n := c.n(); n != 0 {
t.Fatalf("classifier asked %d time(s): %.120q (%+v)", n, c.last(), r.Rule.Classified)
}
}
func TestUserSaysPastAReminderWithASource(t *testing.T) {
for _, s := range []string{goalContinuation, taskNotification, pluginRef, agentList, zcodeAgentList, zcodeTodo, envContext, codexAgents,
"<turn_aborted>\nThe user interrupted.\n</turn_aborted>", inAppBrowser + "## My request:\n"} {
"<turn_aborted>\nThe user interrupted.\n</turn_aborted>", inAppBrowser + "## My request:\n", codexPage} {
if userSays(s) {
t.Errorf("said: %.40q", s)
}