Skip to content

Keep MCP services alive in Prime runtimes - #2261

Merged
mikasenghaas merged 2 commits into
mainfrom
codex/prime-runtime-background
Aug 6, 2026
Merged

Keep MCP services alive in Prime runtimes#2261
mikasenghaas merged 2 commits into
mainfrom
codex/prime-runtime-background

Conversation

@eligotts

@eligotts eligotts commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • launch Prime background services through start_background_job() without an additional detached shell
  • use exec so the service occupies the SDK-managed job process
  • require a live sandbox and translate SDK submission failures to SandboxError

Root cause

PrimeRuntime.run_background() previously ran a nested sh -c "nohup ... &" through the normal command path. That inner shell exited immediately after spawning the service. Verifiers MCP servers enable PR_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>&1 as 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 — passed
  • uv run pre-commit run --all-files — passed
  • pre-push Ruff, formatting, and ty hooks — passed

Note

Keep MCP services alive in Prime runtimes using SDK background jobs

  • Rewrites PrimeRuntime.run_background in prime.py to call self._client.start_background_job instead of spawning a detached shell via sh -c 'nohup ... &'.
  • The new implementation constructs an exec <argv> command with stdout/stderr redirected to the provided log file, passing working_dir and env to the SDK call.
  • Behavioral Change: run_background now raises SandboxError immediately if the client or sandbox ID is missing, or if the SDK call fails.

Changes since #2261 opened

  • Replaced pre-validation guards with exception-based error handling in PrimeRuntime.run_background method [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_background no longer spawns a detached nohup shell that exits right after starting colocated tool/MCP servers.

It now submits exec <argv> with stdout/stderr redirected to the log path through start_background_job, with working_dir and env passed 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 using PR_SET_PDEATHSIG) tearing down the child while the sandbox stays up.

SDK submission failures are wrapped as SandboxError with a prime background launch failed message instead of checking exit code from a nested sh -c run.

Reviewed by Cursor Bugbot for commit abad82c. Bugbot is set up for automated code reviews on this repo. Configure here.

@eligotts
eligotts force-pushed the codex/prime-runtime-background branch from c357ba1 to bd90b69 Compare August 5, 2026 22:43
@eligotts
eligotts marked this pull request as ready for review August 5, 2026 22:45
Comment thread verifiers/v1/runtimes/prime.py Outdated
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment

Comment thread verifiers/v1/runtimes/prime.py Outdated
# 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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this conditional

Co-authored-by: Cursor <cursoragent@cursor.com>
@mikasenghaas
mikasenghaas merged commit 4d97861 into main Aug 6, 2026
11 of 12 checks passed
@mikasenghaas
mikasenghaas deleted the codex/prime-runtime-background branch August 6, 2026 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants