fix(collection): unbreak Wave 10 §K.13 summary regen Tier 1#1822
Merged
Conversation
…found) PR #1786 turned ``query_bot``'s default into ``exclude_system=True``, but ``collection_regen_service`` Stage 1 Tier 1 still routes through ``chat_service.create_chat`` + ``TurnService.get_chat_and_bot``, both of which call ``query_bot`` and additionally enforce ``bot.type == AGENT``. The hidden ``BotType.SUMMARY`` bot fails both gates, surfacing as ``Bot not found: bot…`` 404 toasts on the FE Regen button — Tier 2 fallback never runs because the exception propagates up out of ``_invoke_summary_agent``. Add a ``_allow_system_bot`` keyword on both methods (default ``False`` keeps the user-facing API safe). When ``True``, pass ``exclude_system=False`` to ``query_bot`` and accept SUMMARY in addition to AGENT — both share the agent-runtime infrastructure (the SUMMARY toolset is restricted by ``aperag/domains/agent_runtime`` based on ``bot.type``). ``_invoke_summary_agent`` now opts in. Tests: 6 new unit tests covering both default-deny and ``_allow_system_bot=True`` branches on ``create_chat`` / ``get_chat_and_bot`` / ``create_or_get_turn``. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
4 tasks
earayu
added a commit
that referenced
this pull request
Apr 28, 2026
…t the summary bot's empty config (#1825) Per @earayu2 directive (msg=107cbfa3): "用 collection 的大语言模型, 没配就不支持" — the hidden ``Summary Generation Bot`` carries no ``completion`` config (its config is just ``{"agent": {"system_prompt_template": null}}``), so Stage 1 Tier 1 was raising ``Model specification is required for agent runtime v3`` against ``_resolve_request`` on every call after PR #1822 unblocked the ``Bot not found`` gate. Tier 2 was silently catching the regen, but the agent-driven path never ran. Read ``collection.config.completion.model_id`` and forward it to the agent runtime via ``CreateTurnRequest.completion``. When the collection itself has no completion model configured (or the JSON fails to parse), Tier 1 short-circuits to ``None`` so Tier 2 takes over — Tier 2 already requires the same collection LLM through ``build_collection_llm_callable``, so both tiers honour the same "model state is bound to ``collection.config``" invariant. Tests: 3 new unit tests covering missing ``completion`` block, blank ``model_id``, and unparseable JSON. Existing ``regen_summary`` state-machine tests (15 total) continue to pass. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix the
Bot not found: bot…404 toast on the FE collection settings "重新生成摘要 / 重新生成描述" buttons (reproduced via msg=6e36e981 / msg=3d6024a2 — bot ID confirmed as the user's hidden Summary Generation Bot in DB).Root cause (two compounding gates against the SUMMARY bot, neither one updated by Wave 10):
query_botdefault toexclude_system=True, hiding the per-user hiddenBotType.SUMMARYbot from any caller that did not opt in.chat_service.create_chat(line 138-139 pre-fix) andTurnService.get_chat_and_bot(line 319 pre-fix) additionally enforcedbot.type == BotType.AGENT, so even withexclude_system=Falsethe SUMMARY bot would have been rejected withValidationException.collection_regen_service._invoke_summary_agentroutes through both, so Stage 1 Tier 1 has been raising on every call since Wave 10 launch — Tier 2 fallback never runs because the exception propagates up out ofregen_summary, and the regen endpoint returns 404 to the FE.Fix: introduce a
_allow_system_bot=Falsekeyword on both methods. WhenTrue,query_botis called withexclude_system=Falseand the type check accepts{AGENT, SUMMARY}. DefaultFalsekeeps user-facing endpoints (POST /api/v2/bots/{bot_id}/chats, etc.) on the original strict path._invoke_summary_agentopts in at both call sites.The SUMMARY bot is correct to share the agent-runtime pipeline — its toolset is restricted by
aperag/domains/agent_runtimebased onbot.type, not by an entirely separate runtime.Files
aperag/domains/conversation/service/chat_service.py—create_chat(_allow_system_bot=False)aperag/domains/agent_runtime/services.py—get_chat_and_bot(_allow_system_bot=False)+create_or_get_turn(_allow_system_bot=False)thread-throughaperag/domains/knowledge_base/service/collection_regen_service.py—_invoke_summary_agentopts in on both call sitestests/unit_test/chat/test_chat_service_summary_bot.py— 6 new tests (default-deny vs trusted-internal ×create_chat/get_chat_and_bot/create_or_get_turn)tests/unit_test/agent_runtime/test_agent_runtime_v3.py— fakequery_botacceptsexclude_systemkwargTest plan
uv run pytest tests/unit_test/chat tests/unit_test/agent_runtime/test_agent_runtime_v3.py tests/unit_test/knowledge_base/test_collection_regen* tests/unit_test/conversation— 61 passed locallyuv run ruff check ./aperag tests/unit_test/— cleanuv run ruff format --checkon touched files — clean🤖 Generated with Claude Code