Skip to content

fix(chat_shell): use INTERNAL_SERVICE_TOKEN for internal RAG HTTP auth - #42

Closed
cocowh wants to merge 3 commits into
mainfrom
weagent/fix-kb-info-auth-header
Closed

cocowh wants to merge 3 commits into
mainfrom
weagent/fix-kb-info-auth-header

Conversation

@cocowh

@cocowh cocowh commented May 6, 2026 •

Copy link
Copy Markdown
Owner

Background

The /internal/rag/* endpoints on the backend use verify_internal_service_token which checks against settings.INTERNAL_SERVICE_TOKEN, a shared secret for service-to-service authentication. The original code was sending auth_token (a task token JWT from ExecutionRequest), which does NOT match INTERNAL_SERVICE_TOKEN, resulting in persistent HTTP 401 errors.

Bug Timeline

Fix

Changed all 5 internal RAG HTTP call sites to use a priority chain:

  1. settings.INTERNAL_SERVICE_TOKEN (primary — shared secret for service-to-service)
  2. Fall back to self.auth_token (task token JWT — for dev backward compat)

Changes

chat_shell/chat_shell/tools/builtin/knowledge_base.py

  • _get_kb_info_via_http: settings.INTERNAL_SERVICE_TOKEN or self.auth_token
  • _retrieve_with_strategy_via_http: settings.INTERNAL_SERVICE_TOKEN or self.auth_token

chat_shell/chat_shell/tools/builtin/knowledge_listing.py

  • KbLsTool._list_docs_http_mode: added settings import, INTERNAL_SERVICE_TOKEN or self.auth_token
  • KbHeadTool._arun: added settings import, INTERNAL_SERVICE_TOKEN or self.auth_token

chat_shell/chat_shell/tools/knowledge_factory.py

  • _check_any_kb_has_rag_enabled: settings.INTERNAL_SERVICE_TOKEN or auth_token parameter

cocowh added 2 commits May 6, 2026 18:18
…uest

The _get_kb_info_via_http method was making HTTP POST requests to the
backend's /internal/rag/kb-size endpoint without an Authorization header.
After the backend added verify_internal_service_token dependency to all
internal RAG endpoints, these requests started returning 401, causing
the knowledge base info to be empty and triggering rag_not_configured.

The auth_token was already available in the KnowledgeBaseTool instance
but was never passed to the HTTP request. This fix adds the
Authorization: Bearer header when auth_token is present, consistent
with the fix already applied to _check_any_kb_has_rag_enabled.
Three endpoints were making requests to backend /internal/rag/* without
Authorization headers, causing 401 errors after the backend enforced
internal service token verification:

1. KnowledgeBaseTool._retrieve_with_strategy_via_http (POST /retrieve)
2. KbLsTool._list_docs_http_mode (POST /list-docs)
3. KbHeadTool._arun (POST /read-docs)

For KnowledgeBaseTool, self.auth_token already existed and just needed
to be passed as a header. For KbLsTool and KbHeadTool, the auth_token
field was added and wired through in knowledge_factory.py.

This completes the fix started in the previous commit for
_get_kb_info_via_http, covering all remaining chat_shell → backend
internal RAG HTTP calls.
@cocowh cocowh changed the title fix(chat_shell): add missing auth header to _get_kb_info_via_http request fix(chat_shell): add missing auth headers to all internal RAG HTTP calls May 6, 2026
The /internal/rag/* endpoints on the backend use verify_internal_service_token
which checks against settings.INTERNAL_SERVICE_TOKEN, not the task token JWT
(auth_token). Sending the task token JWT resulted in persistent 401 errors.

This fix changes all 5 internal RAG HTTP call sites to prefer
settings.INTERNAL_SERVICE_TOKEN from chat_shell config, with fallback to
auth_token for backward compatibility in dev environments.

Affected methods:
- KnowledgeBaseTool._get_kb_info_via_http (POST /kb-size)
- KnowledgeBaseTool._retrieve_with_strategy_via_http (POST /retrieve)
- KbLsTool._list_docs_http_mode (POST /list-docs)
- KbHeadTool._arun (POST /read-docs)
- knowledge_factory._check_any_kb_has_rag_enabled (POST /kb-size)
@cocowh cocowh changed the title fix(chat_shell): add missing auth headers to all internal RAG HTTP calls fix(chat_shell): use INTERNAL_SERVICE_TOKEN for internal RAG HTTP auth May 6, 2026
@cocowh cocowh closed this May 11, 2026
@cocowh
cocowh deleted the weagent/fix-kb-info-auth-header branch May 11, 2026 21:30
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