Repository navigation
feat(pr-verify): log the upstream error type for a refused proxy request - #17024
Conversation
For every non-2xx upstream answer, on the socket and the loopback
listener alike, key-proxy.mjs writes one more JSON line to its log, for
the main request and for its count_tokens preflight:
- method, path, upstreamPath and upstreamStatus;
- errorType: the body's error.type when it matches ^[a-z_]{1,64}$,
else "unrecognized";
- errorMessage: the first 120 characters of error.message, after the
real key, the client key and any sk-ant- run are replaced by [key],
every control, format and line or paragraph separator character by a
space, "::" by ": :" and "##" by "# #";
- model when it matches ^[A-Za-z0-9][A-Za-z0-9._[\]-]{0,79}$, else
"unrecognized";
- betas: the anthropic-beta names matching ^[a-z0-9][a-z0-9._-]{0,79}$,
others dropped;
- maxTokens only when max_tokens is a number.
Only the first 8,192 bytes of an error body are kept, beside the relay;
a longer body, or one that is not UTF-8 JSON with string error.type and
error.message, logs upstreamError "error body unreadable" instead of
the two error fields. The client still gets the upstream bytes
unchanged. The line has no status field, so the usage report's counts
are unchanged.
The proxy log never reached the Actions log: the usage report printed
only numbers. Both workflows' "Report the key proxy's usage" step now
also prints the fields of the first 20 such lines, cut to printable
ASCII with "::" and "##" broken again.
Refs: #16564
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- key-proxy.mjs inert(): every UUID in an upstream error message is replaced by [id] before the 120-character cut, since a rate-limit message may name the organization id and the logs are public. - Both workflows' "Report the key proxy's usage" jq (kept identical): up to 10 refused-request lines per listener instead of 20 overall, then "N more refused upstream requests not shown" when any were left out; a betas value that is not an array prints as empty instead of stopping jq. - Comments: the key-proxy.mjs header says the logged message may quote request content; pr-verify-capture.yml's "Start the key proxy" note says the log also holds refused requests' error fields; the report step's note gives the per-listener limit. - Tests: a 429 message with lower- and upper-case UUIDs; a real key and a client key straddling the 120-character cut leave no prefix of either; workflow.test.mjs runs the report jq read out of the workflow against a log with hostile fields, a non-array betas and 12 lines on one listener, asserting single inert lines starting with "key proxy", the per-listener limit and the left-out count. Refs: #16564 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
claude-review reviewed Code review: no findingsThis PR makes the pr-verify key proxy write one extra log line for every non-2xx upstream answer. That covers the main forward path and the count_tokens preflight, on both listeners. The line has the error type, the message cut to 120 characters with keys and UUIDs masked, and the request's model, beta names and I read the whole diff and the parts of
The bounds match on both paths. The jq report step is the same in both workflows. The existing shared-step check in The PR refs #16564 but closes no issue, so there are no acceptance criteria to check. Security is out of scope here because a separate security lane runs. The PR body notes that a logged upstream message may quote request content; the owner approved that on #16564. Spend: none beyond the existing runs. The change adds no lane runs, turns or model changes. Loosened-check verdict: fail (default; the prompt gave no Verifier dropped 0 of 0 candidates. |
|
claude-security-review reviewed Security review: no security issues foundThis PR adds one log line to the pr-verify key proxy for each non-2xx upstream answer, and prints those lines in the "Report the key proxy's usage" step of What I checked:
No critical-findings: 0 |
Refs: #16564
Summary
The pr-verify key proxy logged only the status of an upstream error. In every capture and whole-map run since 2026-11-18T02:09Z, the driven session's typed terminal turns got status 400 (the screen showed "Credit balance too low") while print-mode requests on the same key got 200, and nothing readable says why. This logs why an upstream request was refused, and prints it in the two workflows' report step.
The owner approved this on #16564 (Q23, "Yes, go with recommendations."): for non-2xx upstream answers only, the error type, the first 120 characters of the message, and the request's
model,anthropic-betanames andmax_tokens.Fix
key-proxy.mjs: one extra log line per non-2xx upstream answer, on both listeners and for the count_tokens preflight. It has nostatuskey, so the report's request counts and token totals do not change. The client still receives the upstream answer byte for byte; the capture reads at most 8,192 bytes beside the relay.sk-ant-run are replaced by[key]and any UUID by[id]before the cut; control, format and line-separator characters become spaces;::and##are broken; then it is cut to 120 code points.error.type,modeland each beta name must match a conservative pattern or are logged asunrecognizedor dropped;max_tokensonly when it is a number. A body that is not the expected JSON shape logserror body unreadableand nothing from it.::and##broken. Each line starts withkey proxy. The proxy's own log never reaches the Actions log, so without this step the new line has no reader.Not built, on the security review's advice: masking for encoded or escaped forms of the key (the key travels only in the upstream request header and no client holds it), and passing the client key to the socket listener.
Verification
node --test --test-concurrency=4onkey-proxy.test.mjs,workflow.test.mjs,whole-map/workflow.test.mjs,check-kill-switch.test.mjsandresolve-config/callers.test.mjs: 499 pass, 0 fail (reported by the builder; not rerun by the session that opened this).::error::,##[group], both keys, ansk-ant-string, control and bidi characters, 5,000 characters); non-JSON, wrong-shape and over-bound bodies; no line for a 2xx; a streamed 529 reaching the client unchanged; a UUID in a 429 message; a key straddling the 120-character cut; and the report step's jq, read out of the workflow and run against a hostile sample log.Left out: a real run. The workflows install the proxy from the base branch, so the new line appears only in runs after this merges; the next capture with a typed turn is what shows the cause.
Related
Remaining
🤖 Generated with Claude Code