From 245e798b79541f075e7e2e43459d75504f742c95 Mon Sep 17 00:00:00 2001 From: huanghuoguoguo <1051233107@qq.com> Date: Sat, 16 May 2026 11:35:20 +0800 Subject: [PATCH] fix(pipeline): handle empty longtext response chain (#2197) --- src/langbot/pkg/pipeline/longtext/longtext.py | 4 ++ tests/unit_tests/pipeline/test_longtext.py | 39 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/unit_tests/pipeline/test_longtext.py diff --git a/src/langbot/pkg/pipeline/longtext/longtext.py b/src/langbot/pkg/pipeline/longtext/longtext.py index 47f00843..32f0d416 100644 --- a/src/langbot/pkg/pipeline/longtext/longtext.py +++ b/src/langbot/pkg/pipeline/longtext/longtext.py @@ -76,6 +76,10 @@ class LongTextProcessStage(stage.PipelineStage): self.ap.logger.debug('Long message processing strategy is not set, skip long message processing.') return entities.StageProcessResult(result_type=entities.ResultType.CONTINUE, new_query=query) + if not query.resp_message_chain: + self.ap.logger.debug('Response message chain is empty, skip long message processing.') + return entities.StageProcessResult(result_type=entities.ResultType.CONTINUE, new_query=query) + # 检查是否包含非 Plain 组件 contains_non_plain = False diff --git a/tests/unit_tests/pipeline/test_longtext.py b/tests/unit_tests/pipeline/test_longtext.py new file mode 100644 index 00000000..be3c318a --- /dev/null +++ b/tests/unit_tests/pipeline/test_longtext.py @@ -0,0 +1,39 @@ +""" +LongTextProcessStage unit tests +""" + +from importlib import import_module +from unittest.mock import AsyncMock + +import pytest + + +def get_modules(): + """Lazy import to ensure proper initialization order""" + longtext = import_module('langbot.pkg.pipeline.longtext.longtext') + entities = import_module('langbot.pkg.pipeline.entities') + return longtext, entities + + +@pytest.mark.asyncio +async def test_empty_response_message_chain_continues_without_processing(mock_app, sample_query): + """Empty response chains should be a no-op for long text processing.""" + longtext, entities = get_modules() + + sample_query.resp_message_chain = [] + sample_query.pipeline_config = { + 'output': { + 'long-text-processing': { + 'threshold': 1, + }, + }, + } + + stage = longtext.LongTextProcessStage(mock_app) + stage.strategy_impl = AsyncMock() + + result = await stage.process(sample_query, 'LongTextProcessStage') + + assert result.result_type == entities.ResultType.CONTINUE + assert result.new_query == sample_query + stage.strategy_impl.process.assert_not_called()