Repository navigation
chore(anthropic): log hygiene, drop obsolete pdfs beta header, remove dead stream branches - #3725
hpiclaranet wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
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.
| verbose_markers = ( | ||
| "Anthropic API Request", | ||
| "Anthropic API Tools", | ||
| "Blocks:", | ||
| ) |
|
|
||
| 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()}") |
There was a problem hiding this comment.
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).
c260550 to
485b5f3
Compare
crazywoola
left a comment
There was a problem hiding this comment.
DRY
if logging.getLogger().isEnabledFor(logging.DEBUG):
|
Addressed in f93177b: the six repeated guards are now DRYd into a module-level |
… 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.
f93177b to
a673930
Compare
|
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) — |
Mairuis
left a comment
There was a problem hiding this comment.
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.
Summary
Three low-risk hygiene fixes in the Anthropic provider, each verified against the installed
anthropicSDK (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:main.py+ the SDK'splugin_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.pdfs-2024-09-25beta 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.redacted_thinkingdelta branches removed from the stream handler. The SDK'sRawContentBlockDeltaunion isTextDelta | InputJSONDelta | CitationsDelta | ThinkingDelta | SignatureDelta— there is no redacted-thinking delta type, so bothelif chunk.delta.type == "redacted_thinking"branches could never execute. Redacted thinking arrives viacontent_block_start(aRedactedThinkingBlock), which is still handled; the two close-tag conditions simplify fromin ("thinking", "redacted_thinking")to== "thinking".Release Notes
pdfs-2024-09-25beta header for PDF input (PDF support is GA)Change Type
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)
Version
versioninmanifest.yaml(not the one undermeta) — 0.3.29 → 0.3.31 (0.3.29 taken by feat(models): add Claude Fable 5.1 and Gemini 3.8 Flash support #3811, 0.3.30 by fix(anthropic): stream tag duplication, 529 mapping, image fetch hardening #3757)dify_plugin>=0.10.2is declared inpyproject.tomland locked inuv.lock(locked at 0.10.2, inherited from feat(models): add Claude Fable 5.1 and Gemini 3.8 Flash support #3811)Testing
uvvenv aligned withmanifest.yaml,pyproject.toml, anduv.lock: full anthropic suite passes on the rebased head (a6739300, main9e1fb9d5, SDK 1.3.0) — 85 passed, 15 skipped. The four bug-target tests fail against the base commit (verified by checking out7af2283): 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 checkreports zero new findings.Known limitations (pre-existing, out of scope here):
anthropic_api_urlcredential that still required the legacypdfs-2024-09-25header would not receive it — no such requirement exists in any official endpoint.claude-3-5-sonnet-20240620max-tokens beta header assignment uses direct assignment rather than comma-join composition (pre-existing; that model does not combine with the other beta features).