Skip to content

chore(anthropic): log hygiene, drop obsolete pdfs beta header, remove dead stream branches - #3725

Closed
hpiclaranet wants to merge 5 commits into
langgenius:mainfrom
hpiclaranet:fix/anthropic-hygiene-logging-beta-deadcode
Closed

hpiclaranet wants to merge 5 commits into
langgenius:mainfrom
hpiclaranet:fix/anthropic-hygiene-logging-beta-deadcode

Conversation

@hpiclaranet

@hpiclaranet hpiclaranet commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Three low-risk hygiene fixes in the Anthropic provider, each verified against the installed anthropic SDK (0.120.0 at analysis time; the plugin now locks 1.3.0 via #3811 and the full suite was re-verified on 1.3.0) and current official documentation:

  1. Full-payload logging demoted from INFO to DEBUG — six log statements dumped complete request bodies, transformed tool schemas, the pruned cache-block list, the full API response, and every streamed chunk at INFO. The plugin daemon runs at INFO by default (main.py + the SDK's plugin_logger_handler), so every user prompt, system prompt, and response was written to daemon stdout on every invocation. They are now DEBUG: hidden in normal operation, available when debugging.
  2. Obsolete pdfs-2024-09-25 beta header removed — PDF (document) support is GA; the current official docs show PDF requests with no beta header. The document block itself is unchanged and continues to be sent.
  3. Unreachable redacted_thinking delta branches removed from the stream handler. The SDK's RawContentBlockDelta union is TextDelta | InputJSONDelta | CitationsDelta | ThinkingDelta | SignatureDelta — there is no redacted-thinking delta type, so both elif chunk.delta.type == "redacted_thinking" branches could never execute. Redacted thinking arrives via content_block_start (a RedactedThinkingBlock), which is still handled; the two close-tag conditions simplify from in ("thinking", "redacted_thinking") to == "thinking".

Release Notes

  • Reduced plugin log volume: full API request/response dumps now log at DEBUG instead of INFO
  • Stop sending the obsolete pdfs-2024-09-25 beta header for PDF input (PDF support is GA)
  • Removed dead stream-handling code for a delta type the Anthropic SDK does not emit

Change Type

  • Documentation / non-plugin change
  • Non-LLM plugin (tools, extensions, datasource, etc.)
  • LLM plugin

Screenshots / Videos

Not applicable — logging levels, request headers, and dead code removal, covered by unit tests.

LLM Plugin Checklist

Areas affected by this change (check all that apply)
  • Message flow (system messages, user ↔ assistant turn-taking)
  • Tool interaction flow (multi-round usage, Agent App and Agent Node)
  • Multimodal input (images, PDFs, audio, video, etc.)
  • Multimodal output (images, audio, video, etc.)
  • Structured output (JSON, XML, etc.)
  • Token consumption metrics
  • Other LLM functionality (reasoning, grounding, prompt caching, etc.)
  • New models / model parameter fixes

Version

Testing

  • Local deployment — clean uv venv aligned with manifest.yaml, pyproject.toml, and uv.lock: full anthropic suite passes on the rebased head (a6739300, main 9e1fb9d5, SDK 1.3.0) — 85 passed, 15 skipped. The four bug-target tests fail against the base commit (verified by checking out 7af2283): the two PDF tests (old code adds the header / comma-joins it) and the two log-level tests (old code logs at INFO). The stream test is a regression guard that passes on both. ruff check reports zero new findings.
  • SaaS (cloud.dify.ai)

Known limitations (pre-existing, out of scope here):

  • The beta-header removal is validated for the official Anthropic API (GA per current docs). A non-standard third-party proxy configured via the anthropic_api_url credential that still required the legacy pdfs-2024-09-25 header would not receive it — no such requirement exists in any official endpoint.
  • The legacy claude-3-5-sonnet-20240620 max-tokens beta header assignment uses direct assignment rather than comma-join composition (pre-existing; that model does not combine with the other beta features).

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 22, 2026
@crazywoola
crazywoola requested a balanced review from Copilot August 24, 2026 02:00

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.

Pull request overview

Improves Anthropic provider logging hygiene and removes obsolete API handling.

Changes:

  • Demotes verbose payload logging to DEBUG.
  • Removes the obsolete PDF beta header and unreachable stream branches.
  • Adds regression tests and bumps the plugin version.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
models/anthropic/models/llm/llm.py Updates logging, PDF headers, and stream handling.
models/anthropic/tests/test_hygiene.py Adds hygiene regression tests.
models/anthropic/manifest.yaml Bumps version to 0.3.30.

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

Comment on lines +154 to +158
verbose_markers = (
"Anthropic API Request",
"Anthropic API Tools",
"Blocks:",
)
Comment thread models/anthropic/models/llm/llm.py Outdated

for chunk in response:
logging.info(f"Anthropic API Stream Response Chunk: {chunk.model_dump_json()}")
logging.debug(f"Anthropic API Stream Response Chunk: {chunk.model_dump_json()}")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in c260550. The eager-evaluation cost was real, and it affected five other payload log sites in the same file (request JSON x2, tools JSON, blocking response, blocks list), so the isEnabledFor guard covers all six now.

Added regression tests that spy the serializers (json.dumps / model_dump_json) rather than log records — record-level filtering alone would not have caught this:

  • at INFO: zero serialization calls, no chunk/request records
  • at DEBUG: one serialization per chunk / once per request (positive control)

Verified the new tests fail on the pre-guard code and the full anthropic suite passes (36 passed, 14 pre-existing skips).

@hpiclaranet
hpiclaranet force-pushed the fix/anthropic-hygiene-logging-beta-deadcode branch from c260550 to 485b5f3 Compare August 25, 2026 19:04

@crazywoola crazywoola left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

DRY

 if logging.getLogger().isEnabledFor(logging.DEBUG):

@hpiclaranet

Copy link
Copy Markdown
Contributor Author

Addressed in f93177b: the six repeated guards are now DRYd into a module-level _debug_logging_enabled() helper (returns logging.getLogger().isEnabledFor(logging.DEBUG)), and all call sites updated. Behavior unchanged — the full anthropic suite passes (80 passed, 14 skipped), including the four serialization-spy regression tests.

… dead stream branches

- Demote full request/response/stream-chunk dumps from INFO to DEBUG:
  they contain complete user prompt content and were flooding daemon
  logs at the default level.
- Stop sending the obsolete 'pdfs-2024-09-25' anthropic-beta header for
  document (PDF) content: PDF support is GA and the current official
  docs show no beta header requirement.
- Remove the unreachable 'redacted_thinking' delta branches from the
  stream handler: the installed SDK's RawContentBlockDelta union
  (TextDelta, InputJSONDelta, CitationsDelta, ThinkingDelta,
  SignatureDelta) has no redacted type; redacted thinking arrives via
  content_block_start, which is still handled.

5 new tests: PDF no-beta-header (x2, incl. combined with task-budget),
request logging at DEBUG not INFO, no verbose API logging at INFO, and a
stream regression guard for real redacted_thinking block starts.
DocumentPromptMessageContent stores the payload in base64_data; data is a
computed data-URI property, so the old fixture silently sent an empty
payload. Use base64_data and assert the emitted document block carries it.

Review finding from the second-opinion validation round of this PR.
f-string log arguments (json.dumps / model_dump_json) are evaluated
before logging.debug() filters the record, so the payload logs paid
their serialization cost at the default INFO level — per chunk on the
streaming hot path. Guard all six payload log sites with
isEnabledFor(DEBUG) so normal operation pays no cost, and add
regression tests that spy the serializers to prove the cost is skipped
at INFO and still incurred at DEBUG.
…led()

Addresses maintainer review: DRY the six repeated
logging.getLogger().isEnabledFor(logging.DEBUG) guards into a single
module-level helper. Behavior unchanged; suite 80 passed, 14 skipped.
@hpiclaranet
hpiclaranet force-pushed the fix/anthropic-hygiene-logging-beta-deadcode branch from f93177b to a673930 Compare September 5, 2026 00:19
@hpiclaranet

Copy link
Copy Markdown
Contributor Author

Updated for the current main: rebased onto 9e1fb9d (#3811 Fable 5.1 / SDK 1.3.0), version bumped to 0.3.31 (0.3.29 taken by #3811, 0.3.30 by #3757). The DRY refactor from the review stands as commit 4 (a673930) — _debug_logging_enabled() helper, 6 call sites. Full suite on SDK 1.3.0: 85 passed, 15 skipped. Re-requesting review.

@Mairuis Mairuis 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.

Re-reviewed the DRY feedback: the shared _debug_logging_enabled helper is in place. Checked the guarded debug serialization, PDF header removal and stream handling tests. Updated the branch from main and advanced the version to 0.3.32 to avoid the 0.3.31 already proposed in #3788. Local suite on the updated branch: 90 passed, 15 skipped (not counted as validated). Approving to run plugin CI; merge remains pending CI.

@hpiclaranet

Copy link
Copy Markdown
Contributor Author

Superseded by #3976 — same change set rebased onto current main (60fd1784), version bumped to 0.3.34 (main carries 0.3.33 via #3907), squashed to a single commit. Suite: 132 passed, 15 skipped; ruff clean. Thanks for the review!

This branch was successfully deployed

1 active deployment
models/anthropic — b277ab18 Deployed Sep 7, 2026 by Mairuis via test (models/anthropic) #2676
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants