Commit Graph
1 Commits
Author SHA1 Message Date
yetone c863904338 gateway: Command Code's Zero Data Retention refusal rests nothing and goes to another member (plugins #246)
Command Code plugin 0.1.14 sends x-cmd-zdr: 1 when its Zero Data
Retention switch is on. A model with no ZDR upstream is refused with
the Provider API's 422 (code "cmd_zdr_no_providers") or, on Go, a 400
the plugin makes with type "cmd_zdr_no_providers". The refusal is about
that request's setting, not the model or the account.

Before, on the plugin path (moved commandcode-plan):
- Go's 400 was rewritten with type invalid_request_error, read as the
  model unserved (unservedWords), rested commandcode-plan@<acct>/<model>
  for a minute, and the account's second key was asked the same thing.
- The 422 went to the agent as api_error, and in a group the next
  member was never asked.
- Raw bodies (restAfter, a decision group's decideFailed) read as
  modelRefused too.

Now:
- zdrRefused (fallback.go) matches only that code as the error's type
  or code, on 400/422. modelRefused and tooLongUnsaid leave it out.
- keepRetry notes it from the vendor's raw body (X-Magpie-ZDR-Refused)
  since the Anthropic error shape keeps no code; pass/keepAlive strip
  the note.
- The candidate loop skips the provider's mates at the same model
  (notMates, they'd be sent the same header), tries the next member,
  rests nobody, and returns the refusal alone.
- restAfterMarked and decideFailed rest nothing for it.
- docs/subsystems/gateway-routing.md says so.

Tests (internal/gateway/plugin_zdr_test.go), with the literal bodies
from plugins' zdr.test.mjs:
- TestCommandCodeZDRRefusalRestsNothing (422 and 400, plugin path,
  two accounts): alone the agent gets Command Code's words and one
  account is asked; group G answers from b over chat and over
  /v1/messages; nothing rests; switch off, Command Code answers first.
- TestZDRRefusalIsCommandCodesCodeOnly: the same words without the
  code, OpenAI model_not_found, unsupported_api_for_model and the code
  named in a message still read as model refusals.
- TestZDRRefusalNeverRests: restAfter with the raw 422/400 and the
  noted Anthropic body rests nothing; without the note it rests.

Broken by hand:
- old sources (zdrRefused stubbed false): e2e red in both subtests
  ("group: 422 ... (commandcode 1, b 0)", "alone: 400 ... (asked 2)"),
  classifier table red.
- restAfter guard removed: TestZDRRefusalNeverRests red ("422 ...
  rests: {Why:other Status:422 ...").
- loop branch removed: e2e red. keepRetry note removed: e2e red.

Run at this head: gofmt -l (clean); go vet ./...,
GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./... (clean);
go test -timeout 45m ./... (go1.26.8, load avg ~300 from other
sessions): every package ok except
- internal/agent, internal/gateway, internal/library: past -timeout
  45m (TestClaudeTiers, TestMessageReasoningRefused,
  TestProjectServersQoderCodeBuddyDroid running), as #2869;
- internal/gui TestSetAnswersWhileDevinAndProvidersHang (13.8s), #1375;
- internal/plugin TestGatewayHookMixedPiPackage, #2865.
After rebasing on dd70c5e6a (b749cffbb's room retry in the same loop):
vet x3 clean again; ZDR tests pass; go test -timeout 60m
./internal/gateway alone: ok but TestIntentClassifierFails' 1.5s slow
bound (1.78s), #1829, which passes -count=5 alone.
2026-10-19 22:27:07 +08:00