fix: treat DSM 599 as task-not-ready in _poll_task, poll until 60s timeout

DirSize/MD5 return error 599 while the async task is still initialising on
the NAS, not only after the task is gone. Remove the 5-consecutive-599 abort
limit and the debug stderr logging; instead pass on 599 and keep polling
until the existing 60 s timeout fires. Rename the test that checked the old
limit to reflect the new timeout-based behaviour.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-14 13:19:32 +02:00
parent c0d4c347c5
commit 4bf655236d
5 changed files with 10 additions and 32 deletions
@@ -81,26 +81,16 @@ def register_filestation(
``(True, status_dict)`` on success, or ``(False, "Error: …")`` on
DSM error or timeout.
"""
import sys as _sys
from mcp_synology_filestation.client import SynologyError as _SynologyError
delay = 0.2
elapsed = initial_delay
timeout = 60.0
consecutive_599 = 0
attempt = 0
_sys.stderr.write(
f"[poll] START {api}/status v{version} taskid={taskid} initial_delay={initial_delay}\n"
)
_sys.stderr.flush()
if initial_delay > 0:
await asyncio.sleep(initial_delay)
while True:
attempt += 1
try:
status_data = await client.request(
api,
@@ -108,25 +98,12 @@ def register_filestation(
version=version,
params={"taskid": taskid},
)
consecutive_599 = 0
finished = status_data.get("finished")
_sys.stderr.write(
f"[poll] #{attempt} elapsed={elapsed:.2f}s finished={finished}"
f" data_keys={list(status_data.keys())}\n"
)
_sys.stderr.flush()
except _SynologyError as e:
_sys.stderr.write(
f"[poll] #{attempt} elapsed={elapsed:.2f}s"
f" SynologyError code={e.code} msg={e}\n"
)
_sys.stderr.flush()
if e.code == 599:
# 599 can be transient (task just started, not yet available).
# Retry up to 5 times before giving up.
consecutive_599 += 1
if consecutive_599 >= 5:
return False, f"Error: {e}"
# DSM returns 599 while the async task is still initialising
# or running (task-not-yet-available). Treat it the same as
# finished=False and keep polling until the 60 s timeout.
pass
else:
return False, f"Error: {e}"
else: