Skip to content

Add opt-in raw HTTP request/response logging - #93

Open
jcheng5 wants to merge 2 commits into
mainfrom
raw-http-logging
Open

Add opt-in raw HTTP request/response logging#93
jcheng5 wants to merge 2 commits into
mainfrom
raw-http-logging

Conversation

@jcheng5

@jcheng5 jcheng5 commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Adds a fetch wrapper (raw-http-logging.ts) that captures byte-faithful .http request/response pairs for wire-level debugging of provider rejections — the AI SDK-structured JsonRequestLogger view in the monorepo shows the SDK's interpretation of a call, not the actual bytes on the wire, which is exactly what you need when a provider returns a 400 you can't explain.

Behavior

  • Opt-in and dynamic. Logging is active while the configured raw-http/ directory exists — late binding, checked per chat call, so you can mkdir mid-session to enable capture without a restart. PA_RAW_HTTP_LOG_DIR turns it on unconditionally.
  • Redaction. Credential-bearing header values are redacted; bodies are always byte-for-byte.
  • Never breaks a request. All logging errors are swallowed.
  • Bundle-safe. node:fs is looked up lazily via process.getBuiltinModule rather than a static node: import, so the module can be bundled into the Positron webview frontend (which shares chunks with the model clients). Outside Node, logging simply disables itself.

Wired into every AI SDK-backed model client — OpenAI, Anthropic, DeepSeek, Gemini, Vertex, Ollama, OpenRouter, Posit AI, Snowflake, Bedrock — composing with each client's existing custom-fetch wrappers rather than replacing them.

Consumer

Needed by posit-dev/assistant#2015, which pins this branch and adds the per-deployment raw-http/ log directories plus the rawHttpLogging.md memory-bank doc. That PR can't merge until this one does.

🤖 Generated with Claude Code

A fetch wrapper (raw-http-logging.ts) that captures byte-faithful .http
request/response pairs for wire-level debugging of provider rejections,
unlike the AI SDK-structured JsonRequestLogger view.

Opt-in and dynamic: active while the configured raw-http/ directory
exists (late binding, checked per chat call — mkdir mid-session to
enable), or always-on via PA_RAW_HTTP_LOG_DIR. Credential-bearing header
values are redacted; bodies are always byte-for-byte. All logging errors
are swallowed so capture can never break a request.

Wired into every AI SDK-backed model client (OpenAI, Anthropic, DeepSeek,
Gemini, Vertex, Ollama, OpenRouter, Posit AI, Snowflake, Bedrock),
composing with existing custom-fetch wrappers.
Look up node:fs lazily via process.getBuiltinModule instead of static
node: imports so the module can be bundled into the Positron webview
frontend (which shares chunks with the model clients). Outside Node,
logging is simply disabled.
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