Stop sequences configured on non-workflow apps are never sent to the model

Open Beginner friendly
#41,460 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
ai, backend

Research direction

Start with ModelConfigManager.convert and ModelConfigConverter.convert in core/app/app_config/easy_ui_based_app/model_config, then inspect the affected consumers at core/app/apps/base_app_runner.py:167, core/agent/cot_agent_runner.py:150, and core/agent/fc_agent_runner.py:182. Run or extend the regression test mentioned in the issue and confirm that configured stop sequences reach invoke_llm for non-workflow and agent apps.

Written by the indexing model from the issue text.

Description

1.17.0
Self Checks
  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report.
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.
Dify version

1.17.0

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce
  1. Create a Chatbot app (this also affects Agent, Completion and Agent Chat apps).
  2. Switch the prompt to expert mode.
  3. Open the model parameter panel and add a stop sequence, for example ###.
  4. Publish, then send a message that makes the model produce ### mid answer.
  5. The model keeps generating past ###.

The saved app model config is correct, the loss happens during runtime conversion. ModelConfigManager.convert moves stop out of completion_params and onto ModelConfigEntity.stop, but ModelConfigConverter.convert still looks for stop inside model_config.parameters, where it no longer exists, and never reads model_config.stop. ModelConfigWithCredentialsEntity.stop is therefore always empty, and ModelConfigEntity.stop has no readers anywhere in the codebase.

from types import SimpleNamespace
from unittest.mock import MagicMock, patch
from core.app.app_config.easy_ui_based_app.model_config.converter import ModelConfigConverter
from core.app.app_config.easy_ui_based_app.model_config.manager import ModelConfigManager

M = "core.app.app_config.easy_ui_based_app.model_config.converter"
saved = {"model": {"provider": "openai", "name": "gpt-4", "mode": "chat",
                   "completion_params": {"temperature": 0.5, "stop": ["###"]}}}
entity = ModelConfigManager.convert(saved)
print("ModelConfigEntity.stop      ->", entity.stop)

with (patch(f"{M}.create_plugin_provider_manager"),
      patch(f"{M}.ModelConfigWithCredentialsEntity", side_effect=lambda **kw: SimpleNamespace(**kw))):
    runtime = ModelConfigConverter.convert(MagicMock(tenant_id="t", model=entity))
print("stop actually sent to model ->", runtime.stop)
ModelConfigEntity.stop      -> ['###']
stop actually sent to model -> []

Affected consumers are core/app/apps/base_app_runner.py:167 for the advanced prompt path and core/agent/cot_agent_runner.py:150 and core/agent/fc_agent_runner.py:182 for agent apps.

I have a fix ready with a regression test and would be happy to be assigned to this issue.

✔️ Expected Behavior

The stop sequences saved in the model configuration reach invoke_llm, so generation stops at the configured sequence.

❌ Actual Behavior

ModelConfigWithCredentialsEntity.stop is always an empty list, so the model is invoked with no stop sequences and generation runs past them.

Dominant language
TypeScript
Stars
157k
Forks
24.7k
Avg merge
22h 32m
Merged PRs (30d)
611

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from langgenius/dify

All issues in langgenius/dify

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.