Repository navigation
fix(llm)!: preserve complete messages and final usage - #390
Conversation
5d5799e to
1447e0a
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The implementation satisfies the documented replay-preservation requirements with focused regression coverage.
0 open findings
What changed in this PR
Preserves replay state and ordered content blocks in blocking LLM invocations.
Changes:
- Adds shared chunk aggregation for ordinary and structured-output invocations.
- Preserves falsy opaque snapshots, mixed content, tool calls, and usage.
- Adds comprehensive regression coverage.
| File | Description |
|---|---|
src/dify_plugin/entities/model/message.py |
Treats replay state and tool calls as nonempty. |
src/dify_plugin/invocations/model/llm.py |
Adds shared replay-aware chunk merging. |
src/dify_plugin/invocations/model/llm_structured_output.py |
Reuses shared chunk merging. |
tests/invocations/test_llm.py |
Covers replay state, content ordering, and invocation isolation. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
Blocking model invocations lose provider replay state and content blocks, and streaming collectors can overwrite earlier tool calls or count cumulative usage more than once.
Preserve complete assistant messages through ordinary and structured output invocations, append complete tool calls in order, and retain the final non-
Noneusage snapshot.Agent usage totals copy the first response before adding later responses so saved per-response usage remains intact.
Closes #389.
Compatibility
This targets SDK 0.11.0 (unreleased).
Providers must assemble each complete tool call before emitting it exactly once, either in separate batches or a final list.
IDs must be nonempty and unique within a response; invalid batches fail before changing the collected result.
Arguments retain their original string representation.
Usage updates are cumulative snapshots for one response, while Agent totals add across responses.
Blocking content can be an ordered list of content blocks.
Display consumers should use
message.get_text_content(), and Agent loops should preserve the complete message, including falsyopaque_bodyvalues.The coordinated upgrade includes daemon #828, provider and Agent changes #4034, OpenAI and endpoint #4035, and Dify #44502.
Its Graphon candidate is published for reproducible dependency installation.
Final release versions and minimum Dify versions still need to be selected together.
Validation
just test: 1,650 passed.just check,just build, andgit diff --checkpassed.Each executed both tools once, retained replay data, and reported 131 tokens for responses of 120 and 11 tokens.
Vendor HTTP and daemon HTTP were controlled test endpoints.
Live vendor signature acceptance and production deployment remain untested.
Pull Request Checklist
Compatibility Check
Available Checks
just buildpassed.