Skip to content

fix(tracing): retain chatflow inputs for suggested questions - #45387

Closed
sipercai wants to merge 1 commit into
langgenius:mainfrom
sipercai:liuyu/fix-suggested-question-tracing
Closed

sipercai wants to merge 1 commit into
langgenius:mainfrom
sipercai:liuyu/fix-suggested-question-tracing

Conversation

@sipercai

@sipercai sipercai commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Chatflow messages can contain a user query while their stored model-prompt field is empty. Suggested-question trace assembly reads only that prompt field, so tracing providers receive an empty input even though the authorized message already contains the query.

Preserve recorded model prompts and fall back to the persisted user query inside the existing owner-scoped read. Generated questions, timings, correlation, and stored message data keep their existing behavior. The regression cases use real SQLite-backed messages, including empty string, list, and object prompts and an existing nonempty chat prompt.

This is based on main after #44673. It only changes input selection in shared record assembly; the proposed query fallback supplies context for the auxiliary tool span and does not reconstruct the actual suggestion-model prompt.

Fixes #45384.

Before / after

Message state Before After
Chatflow: empty model prompts, nonempty user query Empty suggested-question trace input Persisted user query
Chat: recorded model prompts Recorded prompts Same recorded prompts

Validation

  • New regression cases against unchanged main: 3 failed, 1 passed; all failures reproduce the missing chatflow input.
  • make test TARGET_TESTS="api/tests/unit_tests/repositories/test_trace_record_repository.py api/tests/unit_tests/services/tracing api/providers/trace/trace-aliyun/tests/unit_tests api/providers/trace/trace-sdk/tests/unit_tests": 527 passed.
  • Full make lint && make type-check on d5f610c: passed, with no PATH_TO_CHECK restriction. Type checking includes the backend, configured unit tests, and container tests.
  • Full lint left 4,393 files unchanged, passed the AST guards and dotenv checks, reported 762 valid / 0 mismatched response contracts, and kept 82 import contracts / 0 broken.
  • The 527-test regression suite was rerun successfully after installing the lockfile's default and development dependency sets.
  • Before/after persisted-record replay through the canonical builder and native Aliyun OTLP exporter, followed by monitoring-backend readback: 10 spans / 2 traces per side, unchanged parent relationships and fixture token usage; both suggested-question inputs change from empty to the saved query. This is a trace-pipeline replay with synthetic records, not a live model invocation or a full Web E2E.

Checklist

  • This change requires a documentation update in Dify Docs.
  • There is an associated issue, linked with Fixes #45384.
  • I understand that this PR may be closed in case there was no previous discussion or issues.
  • I verified the change and added regression coverage.
  • The inline contract documents the fallback and unchanged source-error behavior.
  • I ran the full make lint && make type-check for the backend. Frontend checks are not applicable; no frontend files changed.

From Codex

@github-actions github-actions Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Nov 3, 2026
@41tair 41tair closed this Nov 3, 2026
@sipercai

sipercai commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@41tair could you clarify why this was closed and what you would like adjusted before resubmission?

This was based on main after #44673. That refactor handles trace structure/correlation and represents suggested questions as auxiliary tool spans. This PR only changes shared record assembly: preserve message.message when present, otherwise use the already-authorized message's persisted query. The proposed fallback supplies context for the auxiliary span; it does not reconstruct the actual suggestion-model prompt.

I have now completed the full backend checks on the unchanged commit d5f610c, and updated the PR description:

  • make lint: passed; 4,393 files unchanged and 82 import contracts kept.
  • make type-check: passed without PATH_TO_CHECK, including the configured backend, unit-test and container-test checks.
  • Trace repository/pipeline/Aliyun/SDK regression suite: 527 passed again with the lockfile's default and development dependencies installed.

Is the query fallback appropriate for this auxiliary span, or would you prefer capturing its actual generation inputs in the event? I can adjust the implementation, coverage, or submission format based on your guidance. The related issue is #45384.

@sipercai

sipercai commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

This PR only adds the suggested-question query fallback on top of #44673; full make lint && make type-check and all 527 tracing regression tests pass locally. My account does not have permission to reopen it. @41tair could you reopen it for review, or point out what needs changing first?

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.

[Bug] Chatflow suggested-question traces lose the persisted user query

2 participants