Skip to content

[core][sandbox] Pull from a local fake registry in test_image_utils - #66786

Merged
pcmoritz merged 1 commit into
ray-project:masterfrom
xyuzh:sandbox-image-utils-hermetic
Oct 15, 2026
Merged

pcmoritz merged 1 commit into
ray-project:masterfrom
xyuzh:sandbox-image-utils-hermetic

Conversation

@xyuzh

@xyuzh xyuzh commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Description

test_image_utils is flaky in CI because three of its tests pull from the real Docker Hub. The two busybox pull tests fail whenever Docker Hub rate-limits the runner (100 anonymous pulls per 6 hours per IP) or the network blips. test_pull_nonexistent_image also goes to Docker Hub, but passes either way.

This PR adds a fake_docker_hub fixture: a small registry on 127.0.0.1 that RAY_SANDBOX_REGISTRY_MIRROR points Docker Hub references at. It serves library/busybox through each step of a real pull: the bearer-token challenge, a multi-arch index that lists another platform first, the manifest and config, and blobs behind a redirect that rejects the registry token, as presigned object storage does. The tests still cover busybox:latest and docker.io/library/busybox:latest, and the nonexistent image now fails on the fake's 404.

Only the test file changes. The gVisor backend tests still pull real images.

Related issues

Related to #65352. Follows #66675, which fixed the other test_image_utils failure in CI.

Additional information

  • Not a duplicate: searches of open PRs and issues for test_image_utils, sandbox flaky and sandbox docker hub found nothing.
  • Tested on macOS with the Ray 2.58 wheel and this branch's sandbox package: TEST_SANDBOX=1 pytest python/ray/experimental/sandbox/tests/test_image_utils.py passed (26 tests) on Python 3.10 with pytest 7.4.4, CI's versions, and on Python 3.11 with pytest 8.0.2. With every non-loopback socket blocked, it passed 25 runs out of 25; master's file fails its two busybox tests that way. Making image_utils.py forward the token on the redirect, take the first index entry, or drop the token makes the pull tests fail. CI's sandbox job covers Linux.
  • I used Claude Code to help write and test this change.

test_pull_and_extract_remote_image and
test_pull_and_extract_docker_io_prefixed_image pulled busybox from the
real Docker Hub, so a Docker Hub rate limit or network error failed
them, and with them the test_image_utils target. They were the only
tests in the file that reached outside the test process.
test_pull_nonexistent_image went to Docker Hub too, but passed either
way.

A fake_docker_hub fixture now serves library/busybox from 127.0.0.1,
and RAY_SANDBOX_REGISTRY_MIRROR sends Docker Hub references to it. It
answers each step of a pull: the bearer-token challenge, a multi-arch
index that lists another platform first, the manifest and config, and
blobs behind a redirect that rejects the registry token, as presigned
object storage does. The tests still cover busybox:latest and
docker.io/library/busybox:latest references, the token flow, platform
selection, and dropping the token at the blob redirect, without the
network. The nonexistent image now fails on the fake's 404.

The gVisor backend tests still pull real images from Docker Hub.

Signed-off-by: xyuzh <[email protected]>
@xyuzh
xyuzh requested a review from a team as a code owner October 6, 2026 17:35

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a local registry fixture, fake_docker_hub, using http.server.ThreadingHTTPServer to mock Docker Hub registry pulls in test_image_utils.py, allowing tests to run without network dependencies. The reviewer identified a critical issue where accessing server_port on the ThreadingHTTPServer instance will raise an AttributeError, and suggested using server_address[1] instead to correctly retrieve the dynamically bound port.

else:
self._reply(200, blob)
elif auth != f"Bearer {token}":
realm = f"http://127.0.0.1:{self.server.server_port}/token"

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.

high

The ThreadingHTTPServer class does not have a server_port attribute. Accessing self.server.server_port will raise an AttributeError. Use self.server.server_address[1] instead to retrieve the dynamically bound port.

Suggested change
realm = f"http://127.0.0.1:{self.server.server_port}/token"
realm = f"http://127.0.0.1:{self.server.server_address[1]}/token"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changing this: ThreadingHTTPServer inherits HTTPServer.server_bind, which sets server_port right after binding (CPython Lib/http/server.py), so self.server.server_port is the port the fake registry got. The three tests that use the fixture pass in CI with it.

server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Registry)
threading.Thread(target=server.serve_forever, daemon=True).start()
monkeypatch.setenv(
"RAY_SANDBOX_REGISTRY_MIRROR", f"http://127.0.0.1:{server.server_port}"

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.

high

The ThreadingHTTPServer class does not have a server_port attribute. Accessing server.server_port will raise an AttributeError. Use server.server_address[1] instead to retrieve the dynamically bound port.

Suggested change
"RAY_SANDBOX_REGISTRY_MIRROR", f"http://127.0.0.1:{server.server_port}"
"RAY_SANDBOX_REGISTRY_MIRROR", f"http://127.0.0.1:{server.server_address[1]}"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Same as above: HTTPServer.server_bind sets server_port, so this is the bound port.

@pcmoritz pcmoritz added the go add ONLY when ready to merge, run all tests label Oct 6, 2026

@pcmoritz pcmoritz 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.

The busybox image we serve through this is very fake right now :)

@xyuzh

xyuzh commented Oct 7, 2026

Copy link
Copy Markdown
Member Author

@pcmoritz good to merge?

@ray-gardener ray-gardener Bot added the core Issues that should be addressed in Ray Core label Oct 7, 2026
@pcmoritz
pcmoritz merged commit ad6b5bd into ray-project:master Oct 15, 2026
6 checks passed
pawelbeza pushed a commit to pawelbeza/ray that referenced this pull request Nov 2, 2026
…ay-project#66786)

## Description

`test_image_utils` is flaky in CI because three of its tests pull from
the real Docker Hub. The two `busybox` pull tests fail whenever Docker
Hub rate-limits the runner (100 anonymous pulls per 6 hours per IP) or
the network blips. `test_pull_nonexistent_image` also goes to Docker
Hub, but passes either way.

This PR adds a `fake_docker_hub` fixture: a small registry on
`127.0.0.1` that `RAY_SANDBOX_REGISTRY_MIRROR` points Docker Hub
references at. It serves `library/busybox` through each step of a real
pull: the bearer-token challenge, a multi-arch index that lists another
platform first, the manifest and config, and blobs behind a redirect
that rejects the registry token, as presigned object storage does. The
tests still cover `busybox:latest` and
`docker.io/library/busybox:latest`, and the nonexistent image now fails
on the fake's 404.

Only the test file changes. The gVisor backend tests still pull real
images.

## Related issues

Related to ray-project#65352. Follows ray-project#66675, which fixed the other
`test_image_utils` failure in CI.

## Additional information

- Not a duplicate: searches of open PRs and issues for
`test_image_utils`, `sandbox flaky` and `sandbox docker hub` found
nothing.
- Tested on macOS with the Ray 2.58 wheel and this branch's sandbox
package: `TEST_SANDBOX=1 pytest
python/ray/experimental/sandbox/tests/test_image_utils.py` passed (26
tests) on Python 3.10 with pytest 7.4.4, CI's versions, and on Python
3.11 with pytest 8.0.2. With every non-loopback socket blocked, it
passed 25 runs out of 25; master's file fails its two `busybox` tests
that way. Making `image_utils.py` forward the token on the redirect,
take the first index entry, or drop the token makes the pull tests fail.
CI's sandbox job covers Linux.
- I used Claude Code to help write and test this change.

Signed-off-by: xyuzh <[email protected]>
Signed-off-by: Pawel Beza <[email protected]>
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 4b9df5c4-6ec3-4e1f-ac3e-54f320ebd8c4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants