sofhiaazzhr Claude Opus 4.8 commited on
Commit
6977394
·
1 Parent(s): c5e2e1b

[NOTICKET] check: read documents from analysis-scope catalog

Browse files

Documents live ONLY in the analysis-scope catalog row (verified via the
`data_catalog` table: `scope_type='analysis'` rows carry `unstructured`
sources; user-scope rows have none). So the first cut — scoping only
`structured` reads to analysis and leaving documents on the user-scope reader —
made `check_knowledge` always return empty ("not listed"), because user-scope
has zero documents.

Fix: `AnalysisScopedCatalogReader` now reads analysis-scope for BOTH structured
and unstructured, falling back to the user-scope reader only when the analysis
has no catalog row. No regression risk: user-scope carried no documents anyway.

A document not bound to the current analysis still won't appear in that room —
there is no user-level document inventory in `data_catalog`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Files changed (1) hide show
  1. src/catalog/reader.py +15 -11
src/catalog/reader.py CHANGED
@@ -77,10 +77,12 @@ class AnalysisScopedCatalogReader(CatalogReader):
77
  """Reads the analysis-scope catalog, falling back to the user-scope reader.
78
 
79
  Used by the `check` skill so "what data do I have" inside a room reflects
80
- that analysis's bound sources AND their real namesa database shows as
81
- "xl test" (analysis-scope) instead of the auto-generated `postgres_<hash>`
82
- placeholder stored in the user-scope row. When the analysis has no catalog
83
- row (legacy / not yet bound) or the read fails, it degrades to the wrapped
 
 
84
  user-scope reader, so unbound rooms behave exactly as before.
85
  """
86
 
@@ -92,13 +94,15 @@ class AnalysisScopedCatalogReader(CatalogReader):
92
  self._analysis_id = analysis_id
93
 
94
  async def read(self, user_id: str, source_hint: SourceHint) -> Catalog:
95
- # Only STRUCTURED reads get analysis scope that's where the naming/scope
96
- # problem lives (databases named `postgres_<hash>` in user-scope vs their
97
- # real name in analysis-scope). Documents pass through to the user-scope
98
- # reader: they carry no scope-name gap, and we don't assume Go populates
99
- # the analysis-scope catalog with unstructured sources (scoping them could
100
- # wrongly hide a user's documents in a room).
101
- if source_hint == "structured" and self._analysis_id:
 
 
102
  try:
103
  catalog = await self._store.get_by_analysis(self._analysis_id)
104
  except Exception: # noqa: BLE001 — never block check on the analysis read
 
77
  """Reads the analysis-scope catalog, falling back to the user-scope reader.
78
 
79
  Used by the `check` skill so "what data do I have" inside a room reflects
80
+ that analysis's bound sources structured AND documentswith their real
81
+ names. A database shows as "xl test" (analysis-scope) instead of the
82
+ auto-generated `postgres_<hash>` placeholder, and documents show at all
83
+ (the user-scope catalog holds no `unstructured` sources, so reading them from
84
+ user-scope always came back empty). When the analysis has no catalog row
85
+ (legacy / not yet bound) or the read fails, it degrades to the wrapped
86
  user-scope reader, so unbound rooms behave exactly as before.
87
  """
88
 
 
94
  self._analysis_id = analysis_id
95
 
96
  async def read(self, user_id: str, source_hint: SourceHint) -> Catalog:
97
+ # Read analysis-scope for BOTH structured and unstructured. Verified via
98
+ # the dedorch `data_catalog` table: the analysis-scope rows carry the real
99
+ # DB names AND the room's documents (`source_type='unstructured'`), whereas
100
+ # the user-scope rows hold only structured sources with `postgres_<hash>`
101
+ # placeholder names and NO documents at all so reading documents from
102
+ # user-scope always returned empty ("not listed"). Fall back to the
103
+ # user-scope reader only when the analysis has no catalog row (legacy /
104
+ # unbound room).
105
+ if self._analysis_id:
106
  try:
107
  catalog = await self._store.get_by_analysis(self._analysis_id)
108
  except Exception: # noqa: BLE001 — never block check on the analysis read