Skip to content

fix(proxy): record upstream status on failed-closed metadata lookups - #3822

Merged
kojiwakayama merged 2 commits into
mainfrom
fix/proxy-lookup-upstream-status
Aug 17, 2026
Merged

fix(proxy): record upstream status on failed-closed metadata lookups#3822
kojiwakayama merged 2 commits into
mainfrom
fix/proxy-lookup-upstream-status

Conversation

@kojiwakayama

@kojiwakayama kojiwakayama commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

The proxy now records the upstream HTTP status when a routing or access metadata lookup fails closed. Public status codes and response messages remain unchanged.

Root cause

A non-success metadata response was converted to a public 502 or 503 without retaining the upstream status, which made transient API failures difficult to distinguish in proxy logs.

What changed

  • ProxyLookupFailure carries an optional upstreamStatus.
  • Rejected, invalid-content-type, and invalid-response paths populate that status.
  • Both failed-closed handler logs include the status.
  • Upstream response bodies are never retained or logged. The initial body-snippet implementation was removed after review because error payloads can contain sensitive or internal data.
  • Removing the diagnostic body reader also preserves the original failed-closed timeout and capacity behavior.

Testing

  • RED: regression assertions failed while the failure and log objects still exposed the upstream body.
  • GREEN: deno test --preload=src/testing/preload.ts --no-check --allow-all src/proxy/project-metadata-client.test.ts src/proxy/handler.test.ts, 2 tests, 82 steps.
  • Broader: same command with --unstable-net src/proxy/, 51 tests, 502 steps.
  • deno check, changed-file lint and format checks, and git diff --check pass.

Risk

Low. This adds one numeric internal diagnostic field. Client-facing behavior is unchanged, and no upstream payload is logged.

Refs VERYFRONT-STUDIO-60

@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown

Caution

Review failed

An error occurred during the review process. Please try again later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

📦 Client bundle boundary

Entrypoint Modules Source size Server leaks
src/index.client.ts 325 1937 KiB ✅ 0

A server module in a client graph aborts hydration in the browser. New leaks fail CI; known leaks are tracked in scripts/lint/client-bundle-baseline.json to burn down.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6f5aac125a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/proxy/handler.ts Outdated
Comment thread src/proxy/project-metadata-client.ts Outdated
@kojiwakayama

Copy link
Copy Markdown
Contributor Author

@codex review exact head 7bff73f006a0e316d088f0901064fd072477299a. The review fixes remove all upstream body retention/logging and delete the diagnostic reader; status-only observability remains.

When the API answers a proxy routing/access metadata lookup with a
non-ok, non-401/403/404 response (e.g. a transient 500 from a DB blip),
the proxy correctly fails closed with a public 502 "Proxy access
metadata request was rejected" — but it recorded nothing about the
upstream response, so every such incident was undiagnosable from the
proxy's own logs. Confirmed in production on 2026-08-17: an API 500 on
/projects/-/proxy-access/... matched a failed-closed proxy log that
carried no upstream detail.

ProxyLookupFailure now carries two structured diagnostic fields:
upstreamStatus and a bounded (<=256 bytes, best-effort) upstream body
snippet. They are populated in the !response.ok rejection branch and in
the invalid-content-type / invalid-response branches (there the status
is 200 but the snippet still identifies the payload). The handler's
"Proxy metadata lookup failed closed" log statements include both
fields explicitly.

Observability only: public status codes and client-facing messages are
byte-identical — the handler sends error.message verbatim to end users,
so the upstream status deliberately stays out of the message string.
The snippet read never throws; abort, stream errors, and adversarial
chunking all degrade to an absent snippet, and the reader is cancelled
so body-settlement guarantees are unchanged.

src/proxy: 51 passed (502 steps), 0 failed.

Refs VERYFRONT-STUDIO-60
@kojiwakayama
kojiwakayama force-pushed the fix/proxy-lookup-upstream-status branch from 7bff73f to 1eadc0a Compare August 17, 2026 13:51
@kojiwakayama

Copy link
Copy Markdown
Contributor Author

@codex review exact rebased head 1eadc0a7ea8d995a2897e1b22be192d343b8cc85. This is the status-only, no-upstream-body implementation after all prior threads were fixed and resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 1eadc0a7ea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@kojiwakayama
kojiwakayama added this pull request to the merge queue Aug 17, 2026
Merged via the queue into main with commit 2c2091a Aug 17, 2026
34 checks passed
@kojiwakayama
kojiwakayama deleted the fix/proxy-lookup-upstream-status branch August 17, 2026 14:13
@kwakayama kwakayama mentioned this pull request Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant