Repository navigation
Conversation
Fixes #798 Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Contributor
|
📁 PR Artifacts Notice This PR adds or changes temporary PR-specific documents under |
Contributor
|
Warning Your comment is too long (maximum is 65536 characters), so the coverage report was not added. See the job log for how to reduce it. |
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.
This PR was created by an AI agent (OpenHands) on behalf of @neubig.
Why
When the organization concurrency limit blocks a run, the run is deferred with exponential backoff. The deferral stops at
AUTOMATION_DEFER_MAX_AGE_SECONDSafter the run was created. When the next backoff would go past that deadline,_defer_or_skip_blocked_runsetsdeferred_untilto exactly the deadline. The intent is one last attempt at that time (seetest_backoff_bounded_by_remaining_age).That last attempt never happened:
dispatch_pending_runsrunsexpire_aged_deferred_runsbefore it claims runs.deferred_until <= now AND created_at <= now - max_age. For the capped row, both conditions become true at the same moment.SKIPPED/defer_expiredwithout a sandbox attempt, even when capacity had come back. For an event run, the event is lost.The sweep's docstring says the dispatch attempt should normally expire a deferred run, and that the sweep is for polls that are at the
AUTOMATION_MAX_CONCURRENT_RUNScap. The code did not do that.Summary of the change
expire_aged_deferred_runstakes a newclaim_grace_secondsargument (default 0). It reaps a run only after the run has been due for that long (deferred_until <= now - claim_grace_seconds). The age condition does not change.dispatch_pending_runspasses two dispatcher poll intervals (2 * AUTOMATION_DISPATCHER_INTERVAL_SECONDS)._defer_or_skip_blocked_runsees that the age has passed and marks itdefer_expired, as before.AUTOMATION_MAX_CONCURRENT_RUNScap still reaps aged deferred runs once the grace has passed.Fixes #798
Out of scope: issue #798 also proposes an upper limit on the deferral backoff, so runs are retried more often during their window. That change adds sandbox-API load when many runs are blocked, which #771 and #773 cared about. I left it for a separate discussion.
How to Test
uv sync --frozen uv run python -m pytest tests/test_dispatcher.py -k 'FinalAttempt or ClaimGrace or ExpireAged or expires_aged_deferred_run_even_at_capacity' -vResult on this branch:
11 passed.The new tests in
TestDeferredRunFinalAttemptrun the realdispatch_pending_runs,_execute_run,_defer_or_skip_blocked_run,expire_aged_deferred_runsandCloudSandboxBackendwith the default deferral settings. Only the sandbox API (anhttpx.MockTransport) and the key mint are stubbed.429 CONCURRENCY_LIMIT_REACHED, and the run is deferred to its deadline.test_run_starts_when_capacity_is_back_at_its_deadline: with capacity back, the run isRUNNINGwith a sandbox.test_still_blocked_final_attempt_expires_the_run: still blocked, the run makes one more sandbox attempt and is thenSKIPPED/defer_expired.TestExpireAgedDeferredRunsClaimGracechecks that the sweep keeps a run that came due 5 s ago and reaps one that came due 30 s ago, with a 20 s grace.I changed one existing test.
test_expires_aged_deferred_run_even_at_capacitynow seeds a run that came due 5 minutes ago instead of 1 s ago, because a run that just came due is now left to the claim first.I also ran every test file that calls
_execute_runordispatch_pending_runs, plustests/test_conversations.pyandtests/test_run_utils.py: all pass. Pre-commit (ruff, pycodestyle, pyright) is clean on the changed files.Video/Screenshots
Before: on
main, the run is skipped asdefer_expiredon the first poll after its deadline. No final sandbox attempt is made, even though capacity is back.After: on this branch, the final attempt happens. The run starts when capacity is back, and expires only if it is still blocked. The existing sweep tests still pass.