Skip to content

fix(api): decode complete suggested question arrays - #44916

Merged
crazywoola merged 2 commits into
langgenius:mainfrom
MindOfqc:fix/suggested-question-bracket-payload
Oct 29, 2026
Merged

crazywoola merged 2 commits into
langgenius:mainfrom
MindOfqc:fix/suggested-question-bracket-payload

Conversation

@MindOfqc

Copy link
Copy Markdown
Contributor

Summary

Fixes #44914.

A valid suggested-questions response such as ["How do I use arr[0]?", "What should I try next?"] currently returns no questions. The non-greedy array regex stops at the closing bracket inside the first string, so JSON decoding receives a truncated payload.

Use JSONDecoder.raw_decode from the first opening bracket. The decoder determines the array boundary while respecting quoted brackets, escaped quotes, and nested values. Keep the existing prose/code-fence tolerance, string-item filtering, first-array selection, and malformed-input fallback.

Move the parser beside its single production caller in services/, update that caller, and relocate the existing pure parser tests to the matching service test module. This follows the migration-only policy for api/core without adding a forwarding wrapper.

Validation

  • Original parser against the nine new regression/control cases: 5 failed / 4 passed.
  • Updated parser suite, including the eleven existing prompt/parser cases: 20 passed.
  • Scoped Ruff check/format and Pyrefly (parser and parser tests): passed, 0 type diagnostics.
  • Normal repository staged hook and the no-new-test-doubles, no-new-session-mock, and no-spec-mock guards: passed.
  • git diff --check: passed.

Command from the repository root, using Python 3.13.7 and an isolated dependency environment:

uv run --project api --no-sync python -m pytest -c api/pyproject.toml \
  --confcutdir=api/tests/unit_tests/services \
  api/tests/unit_tests/services/test_message_suggested_questions_parser.py -q

The hook reused the prepared dependency environment without syncing the entire backend. Full service import was attempted but the local SQLAlchemy 2.1.6 installation rejects an existing model's simultaneous default and insert_default arguments. The complete API suite, provider invocation, and deployed UI were not run. These tests exercise the actual parser used by the shared generation service and make no live model calls.

Reasoning-tag stripping is outside this fix; #34652, #41881, and #42192 address that separate behavior and retain the array-boundary regex.

AI assistance was used for investigation, implementation, and review.

Checklist

  • This change requires a documentation update in Dify Document (no user-facing configuration changes).
  • 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.
  • I ran the full make lint && make type-check commands (scoped checks were run instead).

From Codex

@github-actions github-actions Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Oct 28, 2026
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 79.83% 79.83% +0.00%
Strict coverage 79.52% 79.52% +0.00%
Typed symbols 76,435 76,440 +5
Untyped symbols 19,388 19,386 -2
Modules 3977 3978 +1

@autofix-ci
autofix-ci Bot requested a review from a team October 28, 2026 01:59

MindOfqc commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

CI follow-up: the API jobs stopped before test collection at uv lock --project api --check (controller log, integration log). The same check fails locally with uv 0.13.6.

The lock is api/uv.lock: api/pyproject.toml is the UV workspace root and references ../dify-agent; there is no repository-root uv.lock. All 43 checked-in Python dependency/configuration inputs (pyproject.toml, uv.lock, uv.toml, .python-version, setup and requirements files) have identical Git blobs between base 60429fd39ff6f4fb97ead5331c32d38b0d77c8a1 and this PR head d92e0f05423841f60def698d36dc9712f1914543.

The autofix job identifies exactly one inherited metadata difference in api/uv.lock: the dify-agent server-extra Pillow requirement still says >=11.3.0,<13, while dify-agent/pyproject.toml already declares >=13.0.0,<14 on the base revision. No parser or import failure was reached. These blocked API jobs did not run the parser tests. The original parser commit did not include dependency changes.

Update: the official autofix.ci bot has now appended commit b31ec2101e0f92e6f1157b47a9ad40edb9335515 with exactly that one-line lock metadata synchronization. I preserved the bot commit and fast-forwarded my local branch. CI has restarted on the new head; its final results are still pending.

@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.52%. Comparing base (60429fd) to head (b31ec21).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #44916      +/-   ##
==========================================
- Coverage   89.52%   89.52%   -0.01%     
==========================================
  Files        6009     6009              
  Lines      376773   376772       -1     
  Branches    76234    76234              
==========================================
- Hits       337311   337310       -1     
  Misses      33462    33462              
  Partials     6000     6000              
Flag Coverage Δ
api 89.38% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@crazywoola
crazywoola enabled auto-merge October 29, 2026 02:32
@crazywoola
crazywoola added this pull request to the merge queue Oct 29, 2026
Merged via the queue into langgenius:main with commit 668c73c Oct 29, 2026
51 checks passed
@laipz8200 laipz8200 mentioned this pull request Nov 3, 2026
1 task done
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.

Suggested questions disappear when a valid question contains a closing square bracket

3 participants