Repository navigation
feat(agent): opt-in reliability layer for Runner — timeouts, retries, checkpoints and resume - #515
Open
Cookie0103 wants to merge 1 commit into
Open
Cookie0103 wants to merge 1 commit into
Cookie0103 wants to merge 1 commit into
Conversation
…s, checkpoints, resume) Runner.call/acall/astream had no timeouts, classified errors by substring matching (a 429 ended the run; any text containing "400" was fatal), broke the whole run on a tool exception, and kept step history only in memory. Adds adalflow.components.agent.reliability: - structured ErrorClassifier (status codes, Retry-After, cause chains) - RetryPolicy / TimeoutPolicy / per-tool ToolPolicy (non-idempotent by default) - ReliableExecutor applying them to planner and tool calls (sync and async) - versioned, sha256-checked RunCheckpoint with a write-ahead tool ledger - InMemoryCheckpointStore and FileCheckpointStore (atomic writes) - Runner.resume/aresume that replays completed tool calls instead of re-executing them and refuses to blindly re-run a crashed non-idempotent tool - runner.reliability stream events and ToolOutput status "timeout" All of it is opt-in: without a ReliabilityConfig the Runner behaves as before. Refs SylphAI-Inc#514 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #514
Runner(adalflow/components/agent/runner.py) runscall,acallandastreamwithout any reliability handling. Today:_is_unrecoverable_errorchecks"400" in error/"429" in error, so any error text that happens to contain those digits is fatal. An HTTP 429, which should back off and retry, ends the run instead.acallit reaches the outerexcept Exceptionand breaks the loop.This PR adds an opt-in reliability layer,
adalflow.components.agent.reliability, and wires it into all three Runner loops. With noReliabilityConfigpassed, the default code path is unchanged; the 44 existing runner and tracing tests pass without modification.Usage
Design
classification.pyErrorClassifierreadsstatus_code/response.status_code,Retry-After(seconds or HTTP date) and the__cause__/__context__chain, with no provider SDK imports. ForGeneratorOutput.errorstrings it uses anchored regexes instead of bare digit matching. NetworkOSErrors are told apart from e.g.FileNotFoundError. Users can register their own rules.policy.pyBackoffPolicy(exponential with full/equal jitter, honoursRetry-After, capped),RetryPolicy,TimeoutPolicy(per-op timeout bounded by the remaining run budget), and per-toolToolPolicy.executor.pyReliableExecutorapplies the policies to planner and tool calls, in both async and sync paths (sync timeouts use an owned single-worker pool, released byRunner.close()).CancelledErroris never retried, and cancelling during a backoff sleep propagates immediately. Clock, sleep and RNG are injectable so tests run instantly.checkpoint.pyRunCheckpointwith a sha256 integrity check and a migration hook. Holds the step history, token usage, aRunFingerprint(agent, model, tool signatures, input), the in-flightpending_function, and a write-ahead tool ledger.store.pyInMemoryCheckpointStore(deep copies, locked) andFileCheckpointStore(temp file + fsync +os.replace; run IDs restricted to a safe charset or hashed to prevent path traversal; optional history rotation; falls back to the newest valid history file if the primary is corrupted;prune()).runner.py_planner_call/_planner_acall,_execute_tool_reliably[_async],_checkpoint) used bycall,acallandastream, includingstream_tool_execution. Addsrun_id/resume/on_incomplete_tool/allow_fingerprint_mismatchkeywords andresume()/aresume().Engineering trade-offs
ToolPolicy(idempotent=True). A tool timeout becomes aToolOutput(status="timeout")observation that the agent can react to; it does not crash the run.startedentry is saved before the tool runs, and markedcompletedwith the resolved output afterwards (after coroutine and generator results have been consumed).startedentry for a non-idempotent tool raisesToolReplayRefusedErrorunless the caller passeson_incomplete_tool="rerun"or"skip".ResumeMismatchError, unlessallow_fingerprint_mismatch=True.require_approval=Trueexecutes with no approval when no callback is set #501 / fix(permission): deny require_approval tools when no callback is set #503).Verification
pytest tests/test_runner.py tests/test_runner_tracing.py tests/test_runner_reliability.py tests/test_runner_reliability_integration.py: 118 passed, on both Python 3.12 and Python 3.9 (the package's minimum)."Processed 1400 rows"false positive,Retry-Afterhandling and cause chains;cancelledcheckpoint;callpath;astreamreliability events;tests/directory: the failures and errors (40 failed, 3 errors in modules such astest_openai_client.pyand_test_optimizer.py, plus collection errors for missing optional dependencies) are identical on a clean checkout ofmain. This PR introduces no new failures.ruff(v0.4.2, repo config) andblack(24.4.2) are clean on all new and changed files.Breaking changes
None. Additive keyword-only parameters, a new
"timeout"value inToolOutput.status, and a newReliabilityRunItemevent type.Limitations
FileCheckpointStoreusesfcntladvisory locks for cross-process safety. On Windows that lock is skipped, though in-process locking still applies.Before submitting
AI disclosure: implemented with AI coding assistance (Claude, Cursor). I reviewed and tested every change.
🤖 Generated with Claude Code