aws-samples / aws-samples/bedrock-chat
[BUG] Adding files to an existing shared-KB bot never ingests them: sync succeeds with an empty DataSources list
- Dominant language
- TypeScript
- Stars
- 1.3k
- Forks
- 535
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 10
Description
### Describe the bug
Adding (or replacing) files on an **existing bot that uses a shared knowledge base** never ingests them. The sync completes with `SyncStatus: SUCCEEDED`, the UI looks healthy, but the new documents are absent from the knowledge base, so retrieval keeps answering only from the files present at bot creation. There is no error anywhere.
### Root cause
On the update path (`SyncSharedKnowledgeBasesRequired: false` → `MapQueuedBots` flow), `backend/embedding_statemachine/bedrock_knowledge_base/finalize_custom_bot_build.py` builds the `DataSources` list for ingestion from exactly two sources:
1. `event["DataSources"]` — only present when coming through the SharedKnowledgeBases creation flow.
2. The `BrChatKbStack{botId}` CloudFormation outputs — a `KnowledgeBaseId` output only exists for **dedicated** knowledge bases.
For a shared-KB bot being updated, neither source exists, so the handler returns `DataSources: []`. The downstream ingestion Map state iterates over zero items and the state machine finishes successfully, dropping the file diff on the floor.
Confirmed from a live execution history: the `FinalizeCustomBotBuild` input contains the correct diff (`"FilesDiff": {"Added": ["fileA.pdf", "fileB.pdf"], ...}`) and no `DataSources` key; its output contains `"DataSources": []`; `MapIngestionJobsForCustomBot` schedules no tasks; `UpdateSyncStatusSuccess` then records `SUCCEEDED`.
Verified at v3.17.0 and on current `v3` HEAD.
### Steps to reproduce
1. Create a bot with a **shared** knowledge base and some files; wait for the sync to complete (works).
2. Edit the bot and add one more file; save. Sync completes successfully.
3. `aws bedrock-agent list-knowledge-base-documents` on the bot's KB/data source: the new file is not there (not even as FAILED), and retrieval never uses it.
### Expected behavior
Files added to an existing shared-KB bot are ingested, or the sync fails loudly.
### Fix
The bot record already stores everything needed: `update_knowledge_base_id()` persists `knowledge_base_id` and `data_source_ids` on the bot at creation time. When the event carries file diffs but no `DataSources`, and the stack outputs expose no `KnowledgeBaseId`, fall back to the bot record. PR to follow.
Related: #1126 (same observability gap: the sync status reports success while nothing was ingested).
Contributor guide
Research direction
Start in backend/embedding_statemachine/bedrock_knowledge_base/finalize_custom_bot_build.py and trace the FinalizeCustomBotBuild to MapIngestionJobsForCustomBot flow. Inspect how update_knowledge_base_id() stores the bot's knowledge_base_id and data_source_ids, then verify that an update with FilesDiff but no DataSources produces ingestion jobs and no longer reports success with an empty list.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- backend, cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100