Repository navigation
Studio: stop asking for OAuth consent again when reconnecting to an MCP server - #18171
Conversation
… with its output (rest-2 timeouts) (#18180) `tests/test_ddp_find_unused_default.py::test_trainable_embeddings_train_under_ddp_reentrant_checkpointing` hits pytest-timeout in the CPU `rest-2` shard on unrelated PRs (#18135, #18165, #18171 today): ``` tests/test_ddp_find_unused_default.py:285: in test_trainable_embeddings_train_under_ddp_reentrant_checkpointing proc = subprocess.run( E Failed: Timeout (>330.0s) from pytest-timeout. ``` The test takes about 11 s locally and hung only on some workers, with no child output in the log. ## Cause The test copies `os.environ` into both children: the single-process reference and the `torchrun` pair. The worker decides it is distributed from `WORLD_SIZE`. Several tests write rank variables (`RANK`, `WORLD_SIZE`, `MASTER_PORT`, ...) into the pytest process environment, so on a worker that ran one of them first, the single-process reference sees `WORLD_SIZE=2`, calls `init_process_group("gloo")` and waits for a second rank that never comes. It never returns, and the child's `timeout = 600` is longer than pytest-timeout's 330 s, so CI only showed a bare timeout. Reproduced on main by running the file with `WORLD_SIZE=2 RANK=0 MASTER_ADDR=127.0.0.1 MASTER_PORT=29555` in the environment: it hangs until killed. ## Fix - `_rank_env(tmp_path)` builds the child environment without `RANK`, `WORLD_SIZE`, `LOCAL_RANK`, `LOCAL_WORLD_SIZE`, `GROUP_RANK`, `ROLE_RANK`, `MASTER_ADDR`, `MASTER_PORT` (torchrun sets its own) and the `UNSLOTH_DDP_FIND_UNUSED_PARAMETERS_AUTO` override the test already dropped. - `_run_child` runs each child under a timeout below pytest-timeout (150 s each for the two-step test, 300 s for the single torchrun in the VLM test) and, if one still hangs, fails with the tail of its output instead of a bare timeout. - Both DDP tests in the file use them. ## Verification - `tests/test_ddp_find_unused_default.py`: 63 passed. - Same file with `WORLD_SIZE=2 RANK=0 MASTER_ADDR=127.0.0.1 MASTER_PORT=29555` exported: 63 passed (main: hangs).
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
|
@codex security review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a45e12f821
ℹ️ 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".
| _oauth_refresh_locks: dict[tuple[int, str], threading.Lock] = {} | ||
| _oauth_refresh_locks_guard = threading.Lock() |
There was a problem hiding this comment.
Reset the new OAuth locks after a fork
On POSIX, a child forked while another thread holds either of these locks inherits it in the locked state, but the existing _reset_after_fork() hook resets only the session and cleanup locks. The owning thread no longer exists in the child, so its next OAuth connection either blocks synchronously in _oauth() on the guard or repeatedly times out waiting for the per-URL refresh lock; releasing the parent's copy does not unblock the child. Recreate the guard and clear the refresh-lock table in the existing at-fork hook.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not reachable: every Studio worker uses spawn, and the only os.fork() callers (sandbox_landlock, sandbox_egress_relay) exec or _exit without touching MCP OAuth.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f7e8574b0d
ℹ️ 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".
| import time | ||
| import uuid | ||
| from contextlib import contextmanager | ||
| from contextlib import aclosing, contextmanager |
There was a problem hiding this comment.
Avoid the Python-3.10-only import
For Studio installs using the explicitly supported Python 3.9 backend (studio/backend/requirements/studio.txt keeps <3.10 dependency pins), this import raises ImportError because contextlib.aclosing is available only in Python 3.10 and later. routes/mcp_servers.py imports mcp_client at module load and main.py includes that router, so the backend fails to start even when OAuth is unused; use a Python 3.9-compatible async-generator close pattern or a guarded fallback.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not reachable: the backend floor is 3.10 (studio-backend-ci PYTHON_FLOOR, lint_backend_python_floor), fastmcp>=4.1.5 itself requires Python >=3.10, and main already imports contextlib.aclosing in managed_engine_chat.
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Related to #18164 (the reported bug is fixed in #18203). When several connections to Notion's MCP server refreshed an expired token at the same time, Studio could keep a refresh token Notion had already replaced. The next refresh failed with a 400 and Studio asked for consent again on every connection. Now one connection refreshes and the rest reuse the new token.
Tested against the real Notion MCP server in Studio: