Skip to content

fix(llm): preserve opaque snapshots and content blocks in blocking invocation #389

Closed

Description

@WH-2099

Delivery status — 2026-11-02

Implementation is completed through merged #390; this issue remains closed as completed.
SDK 0.11.0 publication for Dify 1.19.0 is tracked separately in #413.

Blocking LLM invocation drops the opaque_body returned by model plugins, although the SDK assistant message already declares the field.
The streaming branch preserves that payload, so changing stream=True to False loses provider replay state.
The blocking aggregation also ignores content arrays: a string chunk followed by a content block and another string returns only the concatenated strings.
Ordinary and structured-output blocking invocations have the same problem.

Required behavior

  • Preserve the last non-None message snapshot, including {}, [], "", 0, and false.
  • Retain mixed strings and content blocks in order, including block-level opaque metadata and boundaries between unannotated text blocks.
  • Treat an assistant containing opaque state or tool calls as nonempty.
  • Start each invocation with fresh state and retain a captured snapshot across trailing empty chunks.
  • Keep string-only responses as strings and preserve the existing invocation signatures and message fields.

Block boundaries matter even without opaque metadata: the current Gemini provider processes a thinking prefix separately on each text block.
Text consumers should extract text at their output boundary rather than changing replay data in the SDK.

Implementation and validation

PR #390 implements the SDK fix and regression tests.
Its final scope preserves the existing Agent token-counting and output-budget behavior.
Generic GPT-2 estimates do not provide a sufficient basis for introducing a new rejection policy across providers, so reasoning-budget policy is separate work.

The regression coverage uses the real Session and invocation paths with an HTTP transport fixture, ordinary and structured-output APIs, both stream settings, consecutive calls, nested state, falsy snapshots, and text-block boundaries.
Current local validation: just check, just test (333 passed, 1 skipped), just build, and git diff --check passed.
The skipped test requires the Dify CLI.

Related integration requirements

The official OAIcompat endpoint and Dify's structured-output blocking parser also need to handle content arrays in their respective repositories.
The SDK cannot repair content already discarded or rejected before it receives a response.
General JSON numeric precision outside opaque replay data, Agent v2, and cross-session history restoration are separate work.

This issue tracks the SDK data-preservation defect.
A complete deployment still requires coordinated provider, Agent, host, and daemon validation; live provider APIs and that deployed combination have not been tested.

Activity

  1. self-assigned this
    on Sep 23, 2026
  2. added this to the 1.19.0 milestone on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions