Skip to content

Studio tests: drain the background sandbox mover between tests - #15830

Merged
danielhanchen merged 1 commit into
mainfrom
tests-sandbox-migrate-thread-isolation
Oct 28, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
tests-sandbox-migrate-thread-isolation

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

(Python 3.13, rest) on #15810 failed test_legacy_sandbox_is_migrated with a log line that gives the cause away:

Moved 1 chat sandbox folder(s) from .../test_legacy_sandbox_is_migrate0/userprofile/studio_sandbox
  to .../test_sandbox_lives_under_the_s0/custom_studio_home/sandbox

The legacy folder of one test was moved into the sandbox root of the test that ran before it on the same xdist worker.

Cause

Since #15628, get_sandbox_workdir starts a background sandbox-migrate thread. That thread captures sandbox_root() when it starts, but reads the legacy root (HOME/studio_sandbox) only once it gets scheduled. test_sandbox_lives_under_the_studio_home never waits for its mover. On a busy worker the mover was still pending when test_legacy_sandbox_is_migrated switched HOME and reset _legacy_sandbox_migrated. It then moved the new test's folder into the old root. The new test's own get_sandbox_workdir found that mover still alive and reused it, so nothing ever moved the folder to where the test looks.

The product is fine: in a real process HOME never changes under the mover. This is test isolation.

There is a second hazard with the same root. The conftest does not isolate HOME, so a mover that outlives a test's monkeypatch reads the real ~/studio_sandbox.

Fix

A conftest autouse fixture joins any live sandbox-migrate thread before and after every backend test. It raises if a mover does not finish in 30s instead of letting it leak. The fixture requests monkeypatch, so the drain runs before the test's HOME is restored and a late mover can never read the real home directory.

Verification

  • Repro: a tiny plugin delays the mover by 1s, the way a loaded worker deschedules it. Running test_sandbox_lives_under_the_studio_home and then test_legacy_sandbox_is_migrated:
    • main 3db711acb5: 1 failed, 1 passed, with the same misplaced move as CI
    • this branch: 2 passed
  • test_sandbox_files_and_storage_roots.py on its own: 321 passed.
  • The 10 backend test files that start a mover, under -n 8: 887 passed, 3 skipped.
  • Only conftest.py and test_sandbox_files_and_storage_roots.py drive the mover directly, and nothing holds one open across tests, so the drain cannot stall an unrelated test.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T17:31:21.196190Z 3ab06f5 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 3ab06f57a4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 36d3c10 into main Oct 28, 2026
0 of 36 checks passed
@danielhanchen
danielhanchen deleted the tests-sandbox-migrate-thread-isolation branch October 28, 2026 17:45
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.

1 participant