Skip to content

fix: redact binary payloads in debug request logging - #154

Merged
tian-lan-landing merged 2 commits into
mainfrom
fix/redact-binary-debug-logging
Sep 7, 2026
Merged

tian-lan-landing merged 2 commits into
mainfrom
fix/redact-binary-debug-logging

Conversation

@tian-lan-landing

Copy link
Copy Markdown
Collaborator

The DEBUG "Request options" log line dumped uploaded file bytes verbatim. Harmless normally, but pytest's log capture prints every DEBUG record for a failed test, so a failing contract test flooded the CI log with megabytes of raw binary (e.g. https://github.com/landing-ai/ade-python/actions/runs/34082925303/job/101621522084).

Redacts bytes/bytearray values (from files and content) to a <N bytes> placeholder before logging.

Uploaded file bytes (and other raw content) were dumped verbatim by
the DEBUG "Request options" log line. Harmless when nothing consumes
it, but pytest's log capture prints every DEBUG record for a failed
test, so a failing contract test involving a file upload flooded the
CI log with megabytes of raw PDF bytes.
Copilot AI balanced review requested due to automatic review settings September 7, 2026 06:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new redaction behavior needs regression coverage for raw and multipart payloads.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Redacts binary request payloads from DEBUG logs to prevent oversized CI output.

Changes:

  • Adds recursive redaction for bytes and bytearray.
  • Applies redaction to logged request options.
File summaries
File Description
src/landingai_ade/_base_client.py Redacts binary values before request-option logging.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +501 to +502
_redact_binary_for_logging(
model_dump(
pyright strict flagged the recursive redact helper because narrowing an
Any-typed value via isinstance loses element types; switch to object with
explicit casts on each container branch. Also short-circuit via a
_contains_binary scan so the common case (no bytes anywhere, as in every
non-file request) returns the original object instead of allocating a new
dict/list/tuple every call, which was tripping the tracemalloc leak test
(pytest's log capture retains each call's redacted container).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings September 7, 2026 07:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The logging regression needs automated coverage for content and multipart payloads.

Review details

Suppressed comments (1)

src/landingai_ade/_base_client.py:520

  • The regression being fixed is not covered by an automated test, even though _build_request already has extensive coverage in tests/test_client.py. Please capture the DEBUG record for requests with direct content bytes and nested multipart files bytes/bytearrays, and assert that the payload is absent while the <N bytes> placeholders are present; otherwise this logging leak can be reintroduced unnoticed.
                _redact_binary_for_logging(
  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@tian-lan-landing
tian-lan-landing merged commit fe129b0 into main Sep 7, 2026
6 checks passed
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.

2 participants