Skip to content

Commit 0cee63f

Browse files
committed
fix(services): guard workspace discovery fallback
Signed-off-by: Drew Cain <groksrc@gmail.com>
1 parent bc36d3c commit 0cee63f

2 files changed

Lines changed: 52 additions & 3 deletions

File tree

src/basic_memory/services/link_resolver.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,22 @@ async def detect_project_from_workspace_identifier_prefix(
4747
if not _workspace_identifier_discovery_available(identifier, config):
4848
return None
4949

50-
workspace_resolution = await resolve_workspace_qualified_identifier(
51-
identifier,
52-
context=context,
50+
workspace_discovery_fallback_errors = (
51+
"not found",
52+
"no accessible workspaces",
53+
"unable to discover",
5354
)
55+
try:
56+
workspace_resolution = await resolve_workspace_qualified_identifier(
57+
identifier,
58+
context=context,
59+
)
60+
except ValueError as exc:
61+
message = str(exc).lower()
62+
if any(error in message for error in workspace_discovery_fallback_errors):
63+
return None
64+
raise
65+
5466
if workspace_resolution is None:
5567
return None
5668
return workspace_resolution.project_identifier

tests/services/test_link_resolver.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,43 @@ async def resolve_workspace_identifier(identifier, context=None):
205205
assert detected == "team-acme/research"
206206

207207

208+
@pytest.mark.asyncio
209+
@pytest.mark.parametrize(
210+
"message",
211+
[
212+
"Workspace 'team-acme' was not found.",
213+
"No accessible workspaces found for this account.",
214+
"Unable to discover projects in any accessible workspace. Failed workspaces: team-acme",
215+
],
216+
)
217+
async def test_workspace_identifier_project_detection_ignores_discovery_failures(
218+
monkeypatch,
219+
config_manager,
220+
message,
221+
):
222+
"""Workspace detection should fall back when cloud discovery is unavailable."""
223+
from basic_memory.services import link_resolver
224+
225+
async def fail_workspace_identifier(identifier, context=None):
226+
raise ValueError(message)
227+
228+
monkeypatch.setattr(
229+
"basic_memory.mcp.project_context._workspace_identifier_discovery_available",
230+
lambda identifier, config: True,
231+
)
232+
monkeypatch.setattr(
233+
"basic_memory.mcp.project_context.resolve_workspace_qualified_identifier",
234+
fail_workspace_identifier,
235+
)
236+
237+
detected = await link_resolver.detect_project_from_workspace_identifier_prefix(
238+
"team-acme/research/note",
239+
config_manager.config,
240+
)
241+
242+
assert detected is None
243+
244+
208245
@pytest.mark.asyncio
209246
async def test_workspace_identifier_project_detection_allows_mixed_local_cloud_config(
210247
monkeypatch,

0 commit comments

Comments
 (0)