gateway: a plugin's 4xx turning the agent's prompt away asks the next member (plugins#1094)

The AutoClaw plugin answers 406 when a chat's system prompt carries
another agent's identity line it doesn't rewrite ("AutoClaw refuses
chats whose system prompt carries another agent's identity line …, so
an unknown one needs another provider in this group"). retryable only
read refusedWords at 400 and 422, so holdWriter.failed() was false for
the 406, the try never reached the promptRefused branch, and the group
stopped at AutoClaw while its other members, taking the same prompt,
were never asked.

refusedWords now also matches AutoClaw's own words, and retryable
counts a refusal at any 4xx. Like WorkBuddy's 400, the refusing account
isn't rested and its mates are asked last.

Run:
- wsl-run go test ./internal/gateway -run
  'PromptRefus|Restricted|Refus|TokenWall|Volcengine|Decide|Retryable':
  ok. TestPromptRefusalRestsNobody is now table-driven, with AutoClaw's
  406 body in a "next answers" case and a "nobody left" case.
- Broken by hand: with the new retryable case removed, both AutoClaw
  subtests go red ("tried [acct-1]"); restored, green.
- gofmt -l: clean.

Not tried: a real AutoClaw account. The plugin side, rewriting ZCode's
subagent line, is autoclaw 0.2.23 (plugins f053e327).

Reported-by: aynauynij
This commit is contained in:
yetone
2026-11-13 19:16:22 +08:00
parent 24cdfb5460
commit 414517ccf5
2 changed files with 34 additions and 10 deletions
+12 -1
View File
@@ -1745,7 +1745,13 @@ var zenModelGone = lazyre.New(`(^|[\s:"])Model [^"\s]+ is not supported("|\s*$)`
// client at all — WorkBuddy's "Illegal API invocation from an unapproved
// channel" to a chat opening with another agent's own system prompt — a
// refusal of the provider, not of the request, another member may serve.
var refusedWords = lazyre.New(`(?i)unapproved channel|illegal api invocation`)
// The AutoClaw plugin's 406 says it in its own words: "AutoClaw refuses
// chats whose system prompt carries another agent's identity line …, so an
// unknown one needs another provider in this group". Read as anything
// else, the group stopped at AutoClaw, and its six other members, which
// take the same prompt, were never asked (plugins#1094: ZCode's subagent
// line).
var refusedWords = lazyre.New(`(?i)unapproved channel|illegal api invocation|system prompt carries another agent's identity line`)
// promptRefused says a vendor answered with that refusal: the agent's
// prompt, not the account, is at fault.
@@ -2017,6 +2023,11 @@ func retryable(status int, body []byte) bool {
// 6,467 points and the empty one was never rested (#4095,
// mycf_711)
return true
case status >= 400 && status < 500 && refusedWords.Match(body):
// the vendor turning the agent's prompt away, at whatever 4xx it
// picks: the AutoClaw plugin's 406 (plugins#1094) as much as
// WorkBuddy's 400. Another member may take the same prompt
return true
case status == 400, status == 422:
return quotaWords.Match(body) || unservedWords.Match(body) || refusedWords.Match(body) || shapeWords.Match(body) || unsaidWords.Match(body) || regionWords.Match(body) || zhipuImageRefusal.Match(body) || wrongEndpoint(status, body) ||
// a relay's own word that the provider behind it turned the
+22 -9
View File
@@ -15,19 +15,32 @@ import (
// before, lemon's two WorkBuddy AI accounts both rested over one agent's
// chat, for every agent (Discord). Told as the agent's prompt, not a
// failure of the account.
//
// The AutoClaw plugin's 406 over another agent's identity line in the
// system prompt (plugins#1094, ZCode's subagent line) is the same refusal
// in its own words, which the group's next member was never asked after.
func TestPromptRefusalRestsNobody(t *testing.T) {
refuse := func(w http.ResponseWriter) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(400)
io.WriteString(w, `{"code":11128,"msg":"Illegal API invocation from an unapproved channel"}`)
refusalOf := func(status int, said string) func(w http.ResponseWriter) {
return func(w http.ResponseWriter) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
io.WriteString(w, said)
}
}
const autoclaw406 = `{"error":{"message":"406 Not Acceptable — AutoClaw refuses chats whose system prompt carries another agent's identity line (Claude Code, Claude Agent SDK, Codex, opencode, Cursor, Cline, Qwen Code, ZCode, Grok CLI, pi, DeepSeek Harness, Hermes Agent); this plugin rewrites the ones it knows, so an unknown one needs another provider in this group","type":"permission_error","code":null}}`
for _, x := range []struct {
name string
also []string // the second account refuses too
name string
status int
said string
word string // what the refusal passed on says
also []string // the second account refuses too
}{
{"next answers", nil},
{"nobody left", []string{"acct-2"}},
{"next answers", 400, `{"code":11128,"msg":"Illegal API invocation from an unapproved channel"}`, "unapproved channel", nil},
{"nobody left", 400, `{"code":11128,"msg":"Illegal API invocation from an unapproved channel"}`, "unapproved channel", []string{"acct-2"}},
{"AutoClaw's 406, next answers", 406, autoclaw406, "identity line", nil},
{"AutoClaw's 406, nobody left", 406, autoclaw406, "identity line", []string{"acct-2"}},
} {
refuse := refusalOf(x.status, x.said)
t.Run(x.name, func(t *testing.T) {
codexSignedIn(t, "spare@example.com")
if err := provider.SetRouting("codex", provider.Ordered); err != nil {
@@ -48,7 +61,7 @@ func TestPromptRefusalRestsNobody(t *testing.T) {
if code != 200 || !strings.Contains(body, "pong") || r.Tries[1].Status != 200 {
t.Fatalf("status %d: %s", code, body)
}
} else if code != 400 || !strings.Contains(body, "unapproved channel") || r.Tries[1].Fail != failPrompt || r.Tries[1].Rest != nil {
} else if code != x.status || !strings.Contains(body, x.word) || r.Tries[1].Fail != failPrompt || r.Tries[1].Rest != nil {
t.Fatalf("status %d: %s; tries %+v", code, body, r.Tries)
}
for _, c := range []string{"codex", "codex@me@example.com", "codex@spare@example.com"} {