Repository navigation
Conversation
…error A hook that asks the server who can reach an item fails when the server is throttled or briefly overloaded. The classifier then falls back to the worst case (EXTERNAL, destroys, irreversible), so the user is asked to confirm a write into a private folder, and an unattended scheduled run stops at that confirmation. _run_hook, which every classifier goes through, now tries a hook once more after HOOK_RETRY_DELAY_SECONDS (10s, the wait after a 429 elsewhere in the app) when it failed with a connection error, a timeout, HTTP 429 or HTTP 5xx. Any other failure, and a second one, is raised as before, so the worst-case fallback is unchanged. The DAV mount lookup in audience.py now raises NextcloudException with the HTTP status instead of ValueError, so a throttled PROPFIND counts as transient like a throttled OCS call. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Christian Fu Mueller <christian-fu.mueller@nextcloud.com>
29e4293 to
f2d7e88
Compare
| if not _is_transient(e): | ||
| raise | ||
| print(f"Hook {getattr(hook, '__name__', hook)!r} failed ({e!r}), trying once more in {HOOK_RETRY_DELAY_SECONDS}s") | ||
| await asyncio.sleep(HOOK_RETRY_DELAY_SECONDS) |
There was a problem hiding this comment.
On a 429 this always waits a fixed HOOK_RETRY_DELAY_SECONDS. It doesn't add jitter or read the server's Retry-After header, which is available through NextcloudException.response.
Because graph.py gathers several classifiers for each pending tool call, a burst of tool calls can have many hooks (around 20 with 5 calls × 4 classifiers) get a 429 together. They all sleep exactly 10s and then hit the throttled server again at the same moment, often several requests each. That makes a second 429 likely, so they all fall back to EXTERNAL anyway. If the server's Retry-After is longer than 10s, the retry fails for certain.
Suggestion: when there's a Retry-After header, use it (capped at something sensible), and add some random jitter to the delay, e.g. delay * random.uniform(0.5, 1.5).
|
I think the retry belongs at the HTTP layer, not in the classifier. niquests already has a proper retry mechanism: Retry(
total=2,
status_forcelist={429, 502, 503, 504},
allowed_methods={"GET", "HEAD", "OPTIONS", "PROPFIND"},
backoff_factor=2,
backoff_jitter=1.0,
respect_retry_after_header=True,
retry_after_max=60,
raise_on_status=False, # so nc_py_api's check_error still raises NextcloudException on the last response
)Compared to retrying in
The blocker is nc_py_api: So I'd suggest fixing this in nc_py_api first: add a |
|
@marcelklehr |
Before each tool call, context_agent asks the server who can reach the item, whether the call overwrites something and how far it can be undone. When the server is throttled or briefly overloaded, such a lookup fails and the call falls back to the worst case: External, destroys, irreversible. The user is then asked to confirm a write into their own private folder. In a scheduled task, the run stops at that confirmation.
Seen on cloud.nextcloud.com: a scheduled run writing a note into the user's private Memories folder with
upload_filewas shown as "External".Change
_run_hook, which every classifier uses, now tries a hook once more afterHOOK_RETRY_DELAY_SECONDS(10s, the same wait the app uses after a 429 when polling tasks) when it failed with a connection error, a timeout, HTTP 429 or HTTP 5xx.audience.py: the DAV mount lookup raisedValueErroron a non-207 response. It now raisesNextcloudExceptionwith the HTTP status, so a throttled PROPFIND counts as transient like a throttled OCS call. This is the lookupupload_filegoes through.Hooks of other tools that wrap HTTP errors in plain exceptions (Deck, Calendar, Contacts) are not retried by this change.
Tests
ValueError) is asked once, not retried._is_transient: connection error, timeout, 429 and 5xx count; 403, 404, status 0 and a plainValueErrormentioning 429 do not.monkeypatchinside these tests only.+140/-5 in 3 files, 4 new tests; 427 tests pass.
Also tested on a sandbox Nextcloud 35.0.1 with Apache answering the Context Agent's PROPFIND with 429: after one 429,
upload_filewas retried 10s later, classified as the user's own folder and ran without a confirmation; with 429 on the retry too, it fell back to External and asked, as before.Base:
main.🤖 AI (if applicable)
Code, tests and this description were drafted with Claude Code (claude-opus-5-5) under my direction.