fix(cloud_api): restore legacy is_retrieval_ready swallow-on-error contract

For faithful 0.2.x cloud SDK drop-in compatibility, is_retrieval_ready
again swallows PageIndexAPIError and returns False (instead of raising),
so existing `while not is_retrieval_ready(...)` polling loops behave
exactly as before. Documented that this can loop forever on a permanent
error — that is the legacy contract; callers guard their own loops.

(The new SDK's own indexing path doesn't use this method — it polls
document status with a bounded 120-attempt cap — so the infinite-loop
risk is confined to legacy-SDK usage that already had it.)

Test updated to assert the swallow behavior.

Claude-Session: https://claude.ai/code/session_01Kx5DgKbhK1N8autqXH8SmS
This commit is contained in:
mountain 2026-07-07 15:48:49 +08:00
parent b2756c73d2
commit 154c483fb1
2 changed files with 14 additions and 11 deletions

View file

@ -93,13 +93,17 @@ class LegacyCloudAPI:
def is_retrieval_ready(self, doc_id: str) -> bool:
"""Return whether retrieval is ready for ``doc_id``.
API failures (revoked key, network down, unknown doc) propagate as
PageIndexAPIError instead of reading as "not ready" swallowing them
turned ``while not is_retrieval_ready(...)`` polling loops into
infinite loops.
Faithfully matches the 0.2.x cloud SDK: API errors are swallowed and
reported as "not ready" (False) so existing
``while not is_retrieval_ready(...)`` polling loops behave identically.
Note this can loop forever on a permanent error (revoked key, deleted
doc) that is the legacy contract; guard the loop yourself if needed.
"""
result = self.get_tree(doc_id)
return result.get("retrieval_ready", False)
try:
result = self.get_tree(doc_id)
return result.get("retrieval_ready", False)
except PageIndexAPIError:
return False
def submit_query(self, doc_id: str, query: str, thinking: bool = False) -> dict[str, Any]:
payload = {