- Extend migration 000056 with legacy-docs backfill (telegram/<chat>,
ws/<chat>, delegate/<chat>, and agent/bot/<chat> path shapes) so
scope=shared/personal docs created before team-scope refactor also
get stamped with chat_id and stop leaking across chats
- rescan: inferOwnerFromPath now returns chat_id extracted from team
path third segment; stamp onto VaultDocument so admin /vault/rescan
preserves chat isolation
- HTTP vault search: accept optional chat_id body param, set
TeamIsolated=true when TeamID + ChatID both present (admin UI can
view vault from a specific chat perspective)
Applied to staging DB via MCP: 91 legacy rows backfilled.
9 fixes for vault enrichment pipeline:
1. Queue key = tenant-only (was per-agent, caused multiple batches
blocking EventBus workers and progress bar flashing)
2. Classify chunks 5 candidates per LLM call (prevents response
truncation that caused parse_still_failed errors)
3. Classify prompt improved: explicit "EXACTLY one entry per
candidate", 5-entry example, ctx capped at 30 words
4. max_tokens kept at 1024 (sufficient for 5 candidates)
5. Progress AddDone removes !running guard (safe before Start)
6. Rescan defers event publishing via PendingEvents — Start()
called before workers receive events, eliminating race
7. Upload handler same deferred publish pattern
8. Frontend enrichment timer cancels stale "complete" timeout
when new enrichment starts (prevents bar disappearing)
9. Sidebar tree reloads after rescan completes
Classify now searches across entire tenant (empty agentID) to
build cross-agent links for future vault sharing. Access control
enforced at query time — agents only see their own docs.