Skip to content

fix(collection): unbreak Wave 10 §K.13 summary regen Tier 1#1822

Merged
earayu merged 1 commit into
mainfrom
bryce/wave10-regen-summary-bot-bypass
Apr 28, 2026
Merged

fix(collection): unbreak Wave 10 §K.13 summary regen Tier 1#1822
earayu merged 1 commit into
mainfrom
bryce/wave10-regen-summary-bot-bypass

Conversation

@earayu
Copy link
Copy Markdown
Collaborator

@earayu earayu commented Apr 28, 2026

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):

  1. PR feat(collection): Wave 10 Chunks C+D — regen service + 2 OpenAPI endpoints #1786 made query_bot default to exclude_system=True, hiding the per-user hidden BotType.SUMMARY bot from any caller that did not opt in.
  2. chat_service.create_chat (line 138-139 pre-fix) and TurnService.get_chat_and_bot (line 319 pre-fix) additionally enforced bot.type == BotType.AGENT, so even with exclude_system=False the SUMMARY bot would have been rejected with ValidationException.

collection_regen_service._invoke_summary_agent routes 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 of regen_summary, and the regen endpoint returns 404 to the FE.

Fix: introduce a _allow_system_bot=False keyword on both methods. When True, query_bot is called with exclude_system=False and the type check accepts {AGENT, SUMMARY}. Default False keeps user-facing endpoints (POST /api/v2/bots/{bot_id}/chats, etc.) on the original strict path. _invoke_summary_agent opts in at both call sites.

The SUMMARY bot is correct to share the agent-runtime pipeline — its toolset is restricted by aperag/domains/agent_runtime based on bot.type, not by an entirely separate runtime.

Files

  • aperag/domains/conversation/service/chat_service.pycreate_chat(_allow_system_bot=False)
  • aperag/domains/agent_runtime/services.pyget_chat_and_bot(_allow_system_bot=False) + create_or_get_turn(_allow_system_bot=False) thread-through
  • aperag/domains/knowledge_base/service/collection_regen_service.py_invoke_summary_agent opts in on both call sites
  • tests/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 — fake query_bot accepts exclude_system kwarg

Test 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 locally
  • uv run ruff check ./aperag tests/unit_test/ — clean
  • uv run ruff format --check on touched files — clean
  • manual: click "重新生成摘要" on the dispatched collection in the deploy and confirm the toast no longer fires

🤖 Generated with Claude Code

…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>
@earayu earayu merged commit a3f508e into main Apr 28, 2026
10 checks passed
@earayu earayu deleted the bryce/wave10-regen-summary-bot-bypass branch April 28, 2026 18:40
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant