Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/hypertrain/challenge/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,16 @@ def configure(self, run_id: str, config: dict[str, int]) -> dict[str, Any]:

def set_paused(self, run_id: str, paused: bool) -> dict[str, Any]:
with self._tx() as db:
row = db.execute(
"SELECT status, manifest FROM runs WHERE run_id=?", (run_id,)
).fetchone()
if row is not None and json.loads(row["manifest"]).get("manifest_version") == 2:
# v2 rounds own their state; only a running<->paused display flip is allowed.
want, have = ("paused", "running") if paused else ("running", "paused")
if row["status"] not in (want, have):
raise ChallengeError(409, f"v2 run is {row['status']}, not {have}")
db.execute("UPDATE runs SET status=? WHERE run_id=?", (want, run_id))
return {"run_id": run_id, "status": want}
row, manifest = self._run(db, run_id)
if paused:
db.execute("UPDATE runs SET status='paused' WHERE run_id=?", (run_id,))
Expand Down
22 changes: 22 additions & 0 deletions tests/challenge/test_service_network_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4446,3 +4446,25 @@ def grants():
assert grants() == 2
retry = request(manifest(payload), expiry=584)
assert retry.status_code == 200 and retry.json() == honest.json() and grants() == 2


def test_admin_pause_flips_only_an_opened_v2_run_without_touching_its_state(network):
pause = "/v1/admin/runs/" + network.manifest.run_id() + "/paused"
# Given a created run: unpausing must never start a run that never opened a round.
refused = network.client.put(pause, json={"paused": False}, headers=admin())
assert refused.status_code == 409
assert network.client.get(network.url).json()["status"] == "created"
# Given a running v2 run (status set as open_round_v2 does).
with network.store._tx():
network.store._db.execute("UPDATE runs SET status='running'")
before = network.store._db.execute("SELECT manifest, envelope FROM runs").fetchone()
# When / Then: pause and unpause are status-only flips.
paused = network.client.put(pause, json={"paused": True}, headers=admin())
assert paused.status_code == 200, paused.text
assert network.client.get(network.url).json()["status"] == "paused"
resumed = network.client.put(pause, json={"paused": False}, headers=admin())
assert resumed.status_code == 200, resumed.text
assert network.client.get(network.url).json()["status"] == "running"
assert tuple(network.store._db.execute("SELECT manifest, envelope FROM runs").fetchone()) == (
tuple(before)
)
Loading