-
Notifications
You must be signed in to change notification settings - Fork 325
openenv/tbench2: orphan TTL + ownership labels for per-task sandboxes #1711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+150
−4
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a55f748
openenv/tbench2: per-task sandbox image recipe + Daytona materialization
nblintao 3e4317a
openenv/tbench2: split the provider-agnostic recipe from the Daytona …
nblintao 5d97c75
openenv: drop the patched-checkout framing from the recipe docs
nblintao 233e82e
openenv/tbench2: deterministic embed tar + provider-first module names
nblintao b99ecf0
openenv/tbench2: orphan TTL + ownership labels for per-task sandboxes
nblintao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
examples/experimental/openenv/tests/test_tb2_sandbox_daytona.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| """Tests for the Daytona sandbox half: ownership labels and the orphan-TTL | ||
| keepalive lifecycle. | ||
|
|
||
| Not collected by the repo-level pytest run (testpaths = ./tests); run manually | ||
| when touching the recipe: | ||
|
|
||
| pytest examples/experimental/openenv/tests/ -q | ||
| """ | ||
|
|
||
| import inspect | ||
| import sys | ||
| import threading | ||
| import time | ||
| from pathlib import Path | ||
|
|
||
| sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) | ||
| import tb2_sandbox_daytona as sandbox # noqa: E402 | ||
|
|
||
|
|
||
| def test_sandbox_labels_default_to_unix_user(monkeypatch): | ||
| monkeypatch.delenv("OPENENV_LAUNCHER", raising=False) | ||
| monkeypatch.delenv("OPENENV_RUN_ID", raising=False) | ||
| labels = sandbox.sandbox_labels(Path("/opt/tb2-tasks/regex-chess")) | ||
| assert labels["openenv-tbench2-task"] == "regex-chess" | ||
| assert labels["openenv-launcher"] # some non-empty identity, never absent | ||
| assert "openenv-run-id" not in labels # omitted when unset, not "" | ||
|
|
||
|
|
||
| def test_sandbox_labels_explicit_launcher_and_run_id(monkeypatch): | ||
| monkeypatch.setenv("OPENENV_LAUNCHER", "tao-lin") | ||
| monkeypatch.setenv("OPENENV_RUN_ID", "tb2-grpo-0717") | ||
| labels = sandbox.sandbox_labels(Path("/opt/tb2-tasks/regex-chess")) | ||
| assert labels["openenv-launcher"] == "tao-lin" | ||
| assert labels["openenv-run-id"] == "tb2-grpo-0717" | ||
|
|
||
|
|
||
| def test_create_arms_ttl_by_default(): | ||
| # The dead-man's-switch contract: creates must arm auto-stop/auto-delete, | ||
| # or a hard-killed caller's orphans run (and bill) forever. | ||
| sig = inspect.signature(sandbox.create_task_sandbox) | ||
| assert sig.parameters["auto_stop_minutes"].default > 0 | ||
| assert sig.parameters["auto_delete_minutes"].default > 0 | ||
|
|
||
|
|
||
| def test_keepalive_beats_then_exits_on_persistent_failure(monkeypatch): | ||
| monkeypatch.setattr(sandbox, "_KEEPALIVE_INTERVAL_S", 0.02) | ||
|
|
||
| class Stub: | ||
| def __init__(self): | ||
| self.beats = 0 | ||
| self.dead = False | ||
|
|
||
| def refresh_activity(self): | ||
| if self.dead: | ||
| raise RuntimeError("sandbox deleted") | ||
| self.beats += 1 | ||
|
|
||
| stub = Stub() | ||
| sandbox._start_keepalive(stub, "regex-chess") | ||
| deadline = time.time() + 2.0 | ||
| while stub.beats < 3 and time.time() < deadline: | ||
| time.sleep(0.01) | ||
| assert stub.beats >= 3 # beats while the sandbox is alive | ||
|
|
||
| stub.dead = True # episode over, sandbox deleted -> thread must exit | ||
| deadline = time.time() + 2.0 | ||
| while time.time() < deadline: | ||
| if not any("keepalive" in t.name for t in threading.enumerate()): | ||
| break | ||
| time.sleep(0.01) | ||
| assert not any("keepalive" in t.name for t in threading.enumerate()) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense for public users, but it seems that within our devbox,
getpass.getuser()always returnsroot. I'm worried that we'd still be unable to distinguish the sandbox owners after this PR.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. We'll use
OPENENV_LAUNCHERbelow to distinguish. But I know it's not very convenient, since there is no default for it. Need to figure out a better way (Claude Code suggested some ways. But I don't think it's good idea to implement them on Miles. It should be changed on devbox's setup).For now, it's not a blocker since we already have TTL, ownership label is no longer critical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kangyan just told me that we can use
RADIXARK_USER_EMAILto identify username within a devbox. Would you mind opening a new PR to update this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm I think this script is public facing and it'd be weird to have an internal env var hardcoded here.