fix: batch Prime background job polling - #2462
Merged
Merged
Conversation
mikasenghaas
approved these changes
Aug 29, 2026
Contributor
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — This localized Prime runtime fix replaces manual one-second job polling with the existing SDK helper, preserving command execution and result handling while enabling shared-client batching. The only added bound is a 30-day safety deadline, leaving normal rollout timeouts and existing behavior effectively unchanged. You can add or adjust custom eligibility rules. Learn more. |
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.
Summary
Prime runtime command execution now delegates to the Prime SDK
run_background_jobhelper instead of manually polling each job withget_background_job. Because runtimes already share one SDK client per event loop, concurrent VM job checks can now coalesce into batches of up to 100 rather than producing one gateway/read-filerequest per job.The call preserves the previous one-second polling cadence and uses the existing effectively-unbounded 30-day safety deadline. Rollout cancellation remains the practical execution timeout, and result/error mapping is unchanged.
Verification
uv run --isolated pytest tests/: 915 passed, 76 credential-gated tests skippedtychecks: passedNote
Medium Risk
Changes how every Prime
run()waits on VM jobs; behavior is intended to match prior polling but relies on SDK batching and timeout semantics.Overview
Prime sandbox command execution now uses the shared SDK
run_background_jobhelper instead of starting a job and pollingget_background_jobin a loop. That lets concurrent polls on the per–event-loop client batch (up to ~100 jobs), cutting per-job gateway traffic while keeping 1spoll_intervaland the same long safety deadline.The idle-timeout sandbox lifetime fallback constant is renamed to
EFFECTIVELY_UNBOUNDED_SECONDSwith a clearer docstring; containertimeout_minutesstill uses that 30-day bound. Rollout cancellation remains the real timeout;ProgramResultmapping is unchanged.Reviewed by Cursor Bugbot for commit b2e7304. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Replace manual polling with SDK
run_background_jobinPrimeRuntime.runstart_background_job+get_background_jobwhile-loop with 1s sleeps inPrimeRuntime.runwith a single SDKrun_background_jobcall usingtimeout=EFFECTIVELY_UNBOUNDED_SECONDSandpoll_interval=1.IDLE_FALLBACK_LIFETIMEtoEFFECTIVELY_UNBOUNDED_SECONDSin prime.py and updates all references including the sandbox timeout calculation.run_background_jobimplementation rather than the previous manual loop.Macroscope summarized b2e7304.