Skip to content

fix(spider2_lite): run SQL in a thread with a SQLite progress-handler timeout, not Ray - #6392

Merged
ananthsub merged 3 commits into
mainfrom
iguehring/spider2-lite-drop-ray
Nov 19, 2026
Merged

ananthsub merged 3 commits into
mainfrom
iguehring/spider2-lite-drop-ray

Conversation

@iguehring-nvidia

@iguehring-nvidia iguehring-nvidia commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What

spider2_lite runs its SQLite queries in a worker thread with a SQLite progress-handler timeout, the way bird_sql does, instead of as Ray remote tasks:

  • resources_servers/spider2_lite/eval_utils.py: execute_sqlite takes an optional timeout_s; a progress handler aborts the query from inside SQLite once the call has run that long and TimeoutError is raised. execute_sqlite_async runs it in a dedicated ThreadPoolExecutor under the semaphore, with an outer wait_for backstop, and still returns None on timeout or query error. import ray, the @ray.remote wrapper and ray.cancel are gone.
  • resources_servers/spider2_lite/app.py: no ray_enabled = True; the server owns a thread pool as large as its semaphore (max_concurrency), so an admitted query never waits in the pool shared with the rest of the server.
  • resources_servers/spider2_lite/pyproject.toml and uv.lock: the server no longer requests the ray extra (nemo-gym[dev], not nemo-gym[dev,ray]; relocked with uv 0.13.5, Ray and its dependencies drop out).
  • Tests for the timeout, and the docs no longer say that spider2_lite uses Ray.

Part of #3669; meets the done criterion of #6430.

Why

Ray was used for one thing: running a single SQLite query in a separate process and cancelling it after 30 seconds. ray_enabled = True makes the server supervisor require Ray in the environment where gym runs, so a run in an environment installed without the ray extra stops before the servers start with "These servers use Ray, but Ray isn't installed where gym runs: spider2_lite_benchmark_resources_server".

bird_sql made the same change for the same job; its docstring explains that Ray tasks can sit in the scheduler queue past the per-query timeout when the cluster is shared.

Raised in review (not reproduced here): on main, ray.cancel does not stop a query that is already running. Its default cancel raises KeyboardInterrupt in the worker, which sqlite3 delivers only after the C call returns, so a runaway query held its Ray CPU slot until it finished.

Each query still copies its whole database into memory, now in the server process instead of a Ray worker (the largest database is 313 MB). An out-of-memory kill now takes down the whole server. Opening the database read-only and querying it directly, as bird_sql does, removes the copy; that is tracked in #6430.

Validation

  • pytest resources_servers/spider2_lite/tests (with uv run --project resources_servers/spider2_lite): 51 passed. With the progress handler removed, the three timeout tests fail within 10 s instead of hanging.

  • uv lock --check in the server directory and the repo's pre-commit hooks on the changed files: passed.

  • Real Spider2-Lite databases (31 SQLite files, 1.6 GB), the 24 tasks with public gold SQL. The same predictions through the old implementation (loaded from main with a stub ray) and through the server's verify():

    prediction mode mean reward old / new same reward per task
    gold SQL gold_sql 1.000 / 1.000 24/24
    gold SQL gold_result 0.667 / 0.667 24/24
    SELECT 1 gold_sql 0.000 / 0.000 24/24
    SELECT 1 gold_result 0.000 / 0.000 24/24
    invalid SQL gold_sql 0.000 / 0.000 24/24
    invalid SQL gold_result 0.000 / 0.000 24/24

    The 8 of 24 gold SQLs that do not match their pre-computed CSV in gold_result mode are the same with both. Running the 24 gold queries 8 at a time takes 15 s with the new code against 27 s one after another. A never-ending prediction with a 2 s limit, 8 tasks at once, scores 0.0 with execution_error in 3.5 s.

  • A rollout of the 24 tasks with a model (Nemotron-3-Nano served by vLLM, vllm_model), one sample each, in an environment without Ray: all 24 scored, pass@1 0.25, no execution failures.

Compatibility

execute_sqlite_async and execute_and_compare take the executor as an argument (after the semaphore); results are unchanged (rows, or None on query error or timeout). execute_sqlite gains an optional argument. The timeout still covers the in-memory copy of the database as well as the query, but its clock now starts when the query starts running in its thread; Ray's started when the task was submitted, so it also counted time spent waiting for a Ray worker. The copy cannot be interrupted, so a very slow copy is limited only by the outer wait (timeout_s + 10 s).

… timeout, not Ray

The server used Ray only to run one SQLite query as a remote task and cancel it
after the timeout, but declaring ray_enabled made the supervisor require Ray in
the environment where gym runs, and a query queued behind other Ray work could
time out before it started. Same approach as bird_sql: run the query in a worker
thread and abort it from inside SQLite once the deadline passes. The server no
longer declares ray_enabled, and its dependency drops the ray extra.

Signed-off-by: Ingo Guehring <[email protected]>
@iguehring-nvidia iguehring-nvidia self-assigned this Nov 18, 2026
@copy-pr-bot

copy-pr-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added risk:mid Autobot PR risk: mid bug Something isn't working area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers labels Nov 18, 2026
@iguehring-nvidia
iguehring-nvidia marked this pull request as ready for review November 18, 2026 17:51
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 18, 2026 17:51

@ananthsub ananthsub left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is it possible instead to directly migrate to using the sandbox api/infrastructure as with #3216
also tagging this as part of #3669

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SHIP WITH CARE

RISK: Supply the required validation for the execution change

The supplied validation has no representative real-model rollout or before/after reward profile for this commit. The description also says pre-commit run --all-files was not run. AGENTS.md requires real smoke rollouts for behavior-changing environment work and the repository checks. The review rubric additionally requires before/after reward evidence for fixed-benchmark verifier changes.

This is a fixed evaluation benchmark, and both verification branches turn execution outcomes into rewards. The tiny-database tests do not show that the changed backend and timeout behavior preserve scores on real databases. This is missing validation, not a demonstrated reward regression.

Could you add a representative model smoke run against the downloaded databases, record the command, model/configuration and inspected task outcomes, and provide before/after aggregate reward and timeout/error counts? Replay identical SQL responses on identical prepared tasks for the scoring comparison. Cover both gold_sql and gold_result: matching results should still score 1.0, mismatches and invalid SQL should score 0.0, and timeouts should remain controlled failures. Explain any changed scores. Also confirm startup without Ray installed and record the repository-pinned pre-commit results. These checks should validate the execution change without changing the existing result-comparison rules.

I reviewed all five changed files and their directly affected paths. I did not execute tests, hooks or rollouts in this read-only review.


Inline comments (escaped v1):

  • tests/unit_tests/server_runtime/test_ray_opt_out.py line 33: RISK: Remove Spider2-Lite from the Ray test inventory

    This entry still declares Spider2-Lite Ray-backed after the PR removes its last production Ray import, class flag and dependency extra. By source inspection, it breaks four core tests: the import inventory assertion discovers no Spider2-Lite import, while the declaration, entrypoint and dependency tests still require Ray because they consume this set. The server-only test run reported in the PR does not cover this core suite.

    Could you remove only this entry from DIRECT_RAY_COMPONENTS["resources_servers"]?

    -        "spider2_lite",

    Keep the production Ray removal and every other inventory entry. Restoring the flag or extra would undo the startup fix rather than repair the stale expectation.

    Proposed acceptance checks, not executed here: run pytest tests/unit_tests/server_runtime/test_ray_opt_out.py. The import inventory, class-declaration, entrypoint-detection and required-extra assertions should pass with Spider2-Lite excluded. Retain test_joins_the_configured_cluster requiring initialization for a Ray server and test_non_ray_server_never_connects requiring no initialization for a non-Ray server. The invariant is that this inventory names exactly the components that still import Ray in production.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Nov 18, 2026
@iguehring-nvidia

Copy link
Copy Markdown
Contributor Author

@ananthsub Thanks for keeping an eye on all the moving pieces! I really appreciate that! Re your suggestion: For me it is a human-bandwidth problem. I would like to get rid of ray here for MFN+Gym, but I don't have the capacity to deep dive into a more fundamental change. Selfishly asking: Do you think we can transfer it to #3669 lane, I cancel this one, and folks working on 3669 would pick it up?

@ananthsub

Copy link
Copy Markdown
Contributor

Selfishly asking: Do you think we can transfer it to #3669 lane, I cancel this one, and folks working on 3669 would pick it up?

completely understood. i agree, unblocking the ray dependency can come first without the wholesale move to the sandbox API.

@yaoyu-33
yaoyu-33 requested a review from wprazuch November 18, 2026 22:07
Comment thread resources_servers/spider2_lite/app.py Resolved
…eout tests

SQL queries ran in the event loop's shared default pool, which can be smaller than
the semaphore: an admitted query could queue there behind slow ones and time out,
and slow queries could hold up the server's own to_thread calls. The server now has
a pool as large as its semaphore, passed to execute_sqlite_async and
execute_and_compare.

The timeout tests use a query that ends on its own after a few seconds, so a missing
progress handler fails them instead of hanging the run, and one test checks that the
worker thread has finished. The docs no longer say that the server uses Ray.

Signed-off-by: Ingo Guehring <[email protected]>
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 19, 2026 07:49
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

The server no longer imports Ray, declares ray_enabled or requests the ray extra, so
the inventory of direct Ray components must not list it.

Signed-off-by: Ingo Guehring <[email protected]>
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 19, 2026 14:35
@ananthsub ananthsub linked an issue Nov 19, 2026 that may be closed by this pull request
@ananthsub
ananthsub added this pull request to the merge queue Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/44557104089

Merged via the queue into main with commit 4e920d1 Nov 19, 2026
71 checks passed
@ananthsub
ananthsub deleted the iguehring/spider2-lite-drop-ray branch November 19, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer risk:mid Autobot PR risk: mid

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate spider2_lite off Ray

3 participants