Studio: fix RAG correctness bugs

Backend:
- Deterministic SQLite connection cleanup. The RAG code used bare
  `with get_connection() as conn:`, which commits but never closes, leaning
  on GC to release handles (the rest of studio_db closes explicitly). Add a
  closing_connection() context manager that commits/rolls back like sqlite3's
  own manager and always closes, and route all 30 RAG call sites through it.
- filter_by_min_score no longer drops BM25-only and figure-ref hits. min_score
  is a cosine floor, so it now gates only hits that carry a dense_score;
  lexical and figure-ref hits (dense_score is None) pass through instead of
  being silently discarded when the floor is raised.
- Fix two tests that could not pass against the production code: the RRF
  fusion test asserted the wrong winner (c edges out b: 0.032266 vs 0.032258),
  and two tool-handler scope tests stubbed retrieve_hybrid without accepting
  the embedder_model kwarg the handler now passes (TypeError was swallowed,
  leaving captured["scope"] unset).

Frontend:
- Removing an in-flight upload chip now routes through the teardown thunk
  already registered for the aggregate-progress toast (abort, unsubscribe,
  release the index slot, delete the backend doc with the correct kb/thread
  scope key it closed over) and clears the toast entry. Deleting directly
  leaked the concurrency slot and hardcoded the thread scope, mis-targeting
  KB-scoped docs. Applied in both the composer hook and the compare-view
  composer; drop the now-vestigial chip-scope-key tracking and unused
  activeThreadId selectors. Add index-progress-store.remove(id).
This commit is contained in:
Daniel Han 2026-05-31 09:56:23 +00:00
commit ab0828b976
13 changed files with 105 additions and 90 deletions

View file

@ -53,7 +53,7 @@ def test_kb_takes_precedence_over_thread():
captured = {}
def _stub_retrieve(scope, query, k):
def _stub_retrieve(scope, query, *args, **kwargs):
captured["scope"] = scope
return []
@ -78,7 +78,7 @@ def test_thread_scope_when_only_thread_set():
captured = {}
def _stub_retrieve(scope, query, k):
def _stub_retrieve(scope, query, *args, **kwargs):
captured["scope"] = scope
return []