# Task Log - Fix 400 Bad Request in Retrieval

## Actions
- Analyzed `lightrag_webui/src/api/lightrag.ts` and confirmed `queryTextStream` correctly reads tenant context from `localStorage`.
- Analyzed `lightrag_webui/src/features/RetrievalTesting.tsx` and discovered it was missing a check for `selectedKB`.
- Modified `RetrievalTesting.tsx` to import `useTenantState` and check for `selectedKB`.
- Added an early return in `RetrievalTesting.tsx` to display a friendly message ("Please select a Knowledge Base") if no KB is selected, preventing the API call that causes the 400 error.

## Decisions
- Decided to enforce KB selection at the UI level (in the component) rather than modifying the API client to handle missing headers silently, as the backend strictly requires the context.
- Decided to provide a clear instruction to the user ("Use the selector in the top header") to improve UX.

## Next Steps
- Verify that the "Retrieval" page now shows the prompt when no KB is selected.
- Verify that selecting a KB enables the chat interface.
- (Optional) Consider adding similar checks to `DocumentManager` and `GraphViewer` if they exhibit similar issues.

## Lessons
- The frontend API client was robust, but the UI component allowed users to trigger actions without the necessary state (KB selection).
- Strict multi-tenancy requires strict UI state management to ensure context is always present before API calls.
