test(integration): address round-8 review — sampling wait-loop robustness
- Guard the status parse in test_sampling's wait_for_vector_sync with
try/except (AttributeError, IndexError, ValueError) -> {} and read status
fields via .get() with safe defaults (pending defaults to 1 = "not done"), so
a transient empty/error status response keeps polling instead of raising and
an empty dict never triggers a false break.
- Document the idle-signal else branch: idle + pending==0 is also the initial
empty state, so prefer passing search_term.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
ca313e7271
commit
a9e512d1dc
@@ -59,7 +59,12 @@ async def wait_for_vector_sync(
|
|||||||
sync_status = await nc_mcp_client.call_tool(
|
sync_status = await nc_mcp_client.call_tool(
|
||||||
"nc_get_vector_sync_status", arguments={}
|
"nc_get_vector_sync_status", arguments={}
|
||||||
)
|
)
|
||||||
status_data = json.loads(sync_status.content[0].text)
|
try:
|
||||||
|
status_data = json.loads(sync_status.content[0].text)
|
||||||
|
except (AttributeError, IndexError, ValueError):
|
||||||
|
# transient empty/error response — keep polling. .get() defaults
|
||||||
|
# below also keep an empty dict from triggering a false break.
|
||||||
|
status_data = {}
|
||||||
|
|
||||||
if search_term is not None:
|
if search_term is not None:
|
||||||
# Robust signal: wait for the specific document to be retrievable
|
# Robust signal: wait for the specific document to be retrievable
|
||||||
@@ -68,13 +73,18 @@ async def wait_for_vector_sync(
|
|||||||
elif initial_indexed_count is not None:
|
elif initial_indexed_count is not None:
|
||||||
# Legacy: wait for new document(s) to be indexed (gauge delta)
|
# Legacy: wait for new document(s) to be indexed (gauge delta)
|
||||||
if (
|
if (
|
||||||
status_data["indexed_count"] > initial_indexed_count
|
status_data.get("indexed_count", 0) > initial_indexed_count
|
||||||
and status_data["pending_count"] == 0
|
and status_data.get("pending_count", 1) == 0
|
||||||
):
|
):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# Wait for all pending work to complete
|
# NOTE: idle + pending==0 is also the *initial empty* state, so this
|
||||||
if status_data["status"] == "idle" and status_data["pending_count"] == 0:
|
# can break before a caller's work is even enqueued — prefer passing
|
||||||
|
# search_term. Kept only for callers that just need a settled corpus.
|
||||||
|
if (
|
||||||
|
status_data.get("status") == "idle"
|
||||||
|
and status_data.get("pending_count", 1) == 0
|
||||||
|
):
|
||||||
break
|
break
|
||||||
|
|
||||||
await anyio.sleep(wait_interval)
|
await anyio.sleep(wait_interval)
|
||||||
|
|||||||
Reference in New Issue
Block a user