Skip to content

Commit 80c473d

Browse files
aldro61claude
andcommitted
Add mechanism to force package version upgrades on demand
Add error-checking in fetch_instances() that allows the instance pool to signal errors to users. When an entry in the pool contains an "error" field, a RuntimeError is raised with the associated message. This enables maintainers to push upgrade notices to the instance pool that will interrupt users running outdated package versions, prompting them to upgrade to continue using the service. Also adds an optional filename parameter to fetch_instances() for flexibility in fetching different files from the HF dataset. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e299773 commit 80c473d

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/browsergym/workarena/instance.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,18 @@ def encrypt_instance_password(password: str) -> str:
4545
return base64.b64encode(cipher_bytes).decode("utf-8")
4646

4747

48-
def fetch_instances():
48+
def fetch_instances(filename: str = None):
4949
"""
5050
Load the latest instances from either a custom pool (SNOW_INSTANCE_POOL env var) or the gated HF dataset.
51+
52+
Parameters:
53+
-----------
54+
filename: str
55+
Optional filename to fetch from the HF dataset. Defaults to INSTANCE_REPO_FILENAME.
5156
"""
57+
if filename is None:
58+
filename = INSTANCE_REPO_FILENAME
59+
5260
pool_path = os.getenv("SNOW_INSTANCE_POOL")
5361
if pool_path:
5462
path = os.path.expanduser(pool_path)
@@ -62,13 +70,13 @@ def fetch_instances():
6270
disable_progress_bars()
6371
path = hf_hub_download(
6472
repo_id=INSTANCE_REPO_ID,
65-
filename=INSTANCE_REPO_FILENAME,
73+
filename=filename,
6674
repo_type=INSTANCE_REPO_TYPE,
6775
)
6876
logging.info("Loaded ServiceNow instances from the default instance pool.")
6977
except Exception as e:
7078
raise RuntimeError(
71-
f"Could not access {INSTANCE_REPO_ID}/{INSTANCE_REPO_FILENAME}. "
79+
f"Could not access {INSTANCE_REPO_ID}/{filename}. "
7280
"Make sure you have been granted access to the gated repo and that you are "
7381
"authenticated (run `huggingface-cli login` or set HUGGING_FACE_HUB_TOKEN)."
7482
) from e
@@ -77,6 +85,8 @@ def fetch_instances():
7785
entries = json.load(f)
7886

7987
for entry in entries:
88+
if entry.get("error"):
89+
raise RuntimeError(entry.get("message", "Unknown error from instance pool"))
8090
entry["url"] = entry["u"]
8191
entry["password"] = decrypt_instance_password(entry["p"])
8292
del entry["u"]

0 commit comments

Comments
 (0)