Keep MCP services alive in Prime runtimes - #2261
Merged
Merged
Conversation
eligotts
force-pushed
the
codex/prime-runtime-background
branch
from
August 5, 2026 22:43
c357ba1 to
bd90b69
Compare
eligotts
marked this pull request as ready for review
August 5, 2026 22:45
mikasenghaas
reviewed
Aug 6, 2026
| if result.exit_code != 0: | ||
| raise SandboxError( | ||
| f"prime background launch failed: {result.stderr.strip()}" | ||
| # Do not add an inner `sh -c "... &"` layer: it exits after spawning, and |
| # Do not add an inner `sh -c "... &"` layer: it exits after spawning, and | ||
| # services using PR_SET_PDEATHSIG (including Verifiers' MCP servers) die with | ||
| # it. `exec` keeps the service in the SDK-managed background job instead. | ||
| if self._client is None or self.info.id is None: |
Co-authored-by: Cursor <cursoragent@cursor.com>
mikasenghaas
approved these changes
Aug 6, 2026
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
start_background_job()without an additional detached shellexecso the service occupies the SDK-managed job processSandboxErrorRoot cause
PrimeRuntime.run_background()previously ran a nestedsh -c "nohup ... &"through the normal command path. That inner shell exited immediately after spawning the service. Verifiers MCP servers enablePR_SET_PDEATHSIG, so the shell's exit could kill the colocated MCP service while leaving the Prime sandbox itself alive.Submitting
exec <service> > <log> 2>&1as the SDK background job removes that short-lived parent and keeps the service attached to the SDK-managed job for the sandbox lifetime.This is infrastructure lifecycle hardening only; it does not change evaluation logic, rewards, task behavior, or Worldsims pipelines.
Validation
uv run ruff check verifiers/v1/runtimes/prime.py— passeduv run pre-commit run --all-files— passedNote
Keep MCP services alive in Prime runtimes using SDK background jobs
PrimeRuntime.run_backgroundin prime.py to callself._client.start_background_jobinstead of spawning a detached shell viash -c 'nohup ... &'.exec <argv>command with stdout/stderr redirected to the provided log file, passingworking_dirandenvto the SDK call.run_backgroundnow raisesSandboxErrorimmediately if the client or sandbox ID is missing, or if the SDK call fails.Changes since #2261 opened
PrimeRuntime.run_backgroundmethod [abad82c]Macroscope summarized c357ba1.
Note
Medium Risk
Changes only Prime sandbox background service lifecycle, but mis-launch or job API behavior could break colocated MCP/tool servers during eval rollouts.
Overview
Prime
run_backgroundno longer spawns a detachednohupshell that exits right after starting colocated tool/MCP servers.It now submits
exec <argv>with stdout/stderr redirected to the log path throughstart_background_job, withworking_dirandenvpassed to the SDK, so the service runs as the SDK-managed job process for the sandbox lifetime. That avoids a short-lived parent shell exiting and (with MCP servers usingPR_SET_PDEATHSIG) tearing down the child while the sandbox stays up.SDK submission failures are wrapped as
SandboxErrorwith aprime background launch failedmessage instead of checking exit code from a nestedsh -crun.Reviewed by Cursor Bugbot for commit abad82c. Bugbot is set up for automated code reviews on this repo. Configure here.