From a463b3ede23448a21154ba012b0a8001f64b812d Mon Sep 17 00:00:00 2001 From: ggbdpq Date: Sat, 24 Oct 2026 10:08:45 +0800 Subject: [PATCH] gateway: the Codex app's page state is metadata, not the user's words (#3418) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit What: joins the injected leads in prompt.go, beside the Codex app's : 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 ({"page_id":null}), 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. --- internal/gateway/prompt.go | 1 + internal/gateway/user_said_test.go | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/internal/gateway/prompt.go b/internal/gateway/prompt.go index 50854569c..3a2069fcd 100644 --- a/internal/gateway/prompt.go +++ b/internal/gateway/prompt.go @@ -725,6 +725,7 @@ var ( injected = []string{ "", "", "", "", "", "", "", "", "", "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:", diff --git a/internal/gateway/user_said_test.go b/internal/gateway/user_said_test.go index a676e4454..39c4e7ca6 100644 --- a/internal/gateway/user_said_test.go +++ b/internal/gateway/user_said_test.go @@ -30,6 +30,9 @@ const ( envContext = "\n /Users/me/app\n zsh\n 2026-10-12\n" codexAgents = "# AGENTS.md instructions for /Users/me/app\n\n\nRun the tests.\n" inAppBrowser = "# Context from my IDE setup:\n\n# In app browser:\n\nhttps://example.test/ — Example\n\n\n" + codexPage = `{"page_id":null}` + 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, - "\nThe user interrupted.\n", inAppBrowser + "## My request:\n"} { + "\nThe user interrupted.\n", inAppBrowser + "## My request:\n", codexPage} { if userSays(s) { t.Errorf("said: %.40q", s) }