A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Tools: an itch 429 slows the save test's page polling instead of ending the test (#1919)
Eyal Golan3ac73a3c7eec
diff --git a/tools/nightly.py b/tools/nightly.pyindex 4c3af7e53..a3d972c87 100644--- a/tools/nightly.py+++ b/tools/nightly.py@@ -19,6 +19,7 @@ import signalimport subprocessimport sysimport time+import urllib.errorimport urllib.parseimport urllib.requestimport zipfile@@ -785,8 +786,12 @@ PERSIST_SAVED = re.compile(r"^PERSISTENCE saved (\d{4}-\d{2}-\d{2}) turn (\d+) h# The page names a new upload's frame only after itch has unpacked it; until then it carries just a JSON load_url# ({"status":"extracting"}). Unpacking the web build took about 17 minutes on 28 October 2026, longer than the old# 10-minute wait, so the save test now waits up to 40 minutes.+# While it waited for the second upload that day, itch answered 429 Too Many Requests; a 429 now slows the polling+# down (Retry-After, bounded) instead of ending the test, within the same 40 minutes.SAVETEST_FRAME_TRIES = 80SAVETEST_FRAME_SLEEP = 30+SAVETEST_RATE_LIMIT_SLEEP = 120 # after an HTTP 429 without a usable Retry-After+SAVETEST_RATE_LIMIT_MAX = 300 # a longer Retry-After is capped; the total wait stays within the frame budgetSAVETEST_RUN_MINUTES = 10TOOLS = Path(__file__).resolve().parent@@ -799,17 +804,43 @@ def _page_text(fetch, url: str) -> str:raise Refused("savetest", f"cannot read {url}: {type(e).__name__}: {e}") from e+def _rate_limit_pause(e: Refused) -> int | None:+ """Seconds to wait after itch answered HTTP 429 (its Retry-After, kept within bounds), or None for any other error."""+ cause = e.__cause__+ if not isinstance(cause, urllib.error.HTTPError) or cause.code != 429:+ return None+ try:+ asked = int((cause.headers or {}).get("Retry-After", ""))+ except ValueError:+ asked = SAVETEST_RATE_LIMIT_SLEEP+ return min(max(asked, SAVETEST_FRAME_SLEEP), SAVETEST_RATE_LIMIT_MAX)++def _frame_url(fetch, sleep, page_url: str, other: str | None = None) -> str | None:"""The game-frame URL the itch page embeds. With `other` it waits for a frame that is not that one; the last- frame seen (or None) comes back when the tries run out."""- found = None- for attempt in range(SAVETEST_FRAME_TRIES):- found = itch_frame_url(_page_text(fetch, page_url))- if found is not None and found != other:+ frame seen (or None) comes back when the wait budget runs out. A 429 from itch only slows the polling down; if+ itch still refuses when the budget runs out, that refusal is raised."""+ found, limited = None, None+ waited, budget = 0, SAVETEST_FRAME_TRIES * SAVETEST_FRAME_SLEEP+ while True:+ try:+ found, limited = itch_frame_url(_page_text(fetch, page_url)), None+ pause = SAVETEST_FRAME_SLEEP+ except Refused as e:+ pause = _rate_limit_pause(e)+ if pause is None:+ raise+ limited = e+ print(f"savetest: itch answered 429, waiting {pause} s", file=sys.stderr)+ else:+ if found is not None and found != other:+ return found+ if waited + pause > budget:+ if limited is not None:+ raise limitedreturn found- if attempt + 1 < SAVETEST_FRAME_TRIES:- sleep(SAVETEST_FRAME_SLEEP)- return found+ sleep(pause)+ waited += pausedef _frame_parts(url: str) -> tuple[str, str, str]:diff --git a/tools/tests/test_nightly.py b/tools/tests/test_nightly.pyindex 8a54dc67b..3392efc3e 100644--- a/tools/tests/test_nightly.py+++ b/tools/tests/test_nightly.py@@ -1865,9 +1865,9 @@ class Saved:self.runner = SaveRunner(**runner_kw)monkeypatch.setattr(nightly, "find_chrome", lambda: Path("/fake/chrome"))- def run(self, fetch=None, tag=TAG):+ def run(self, fetch=None, tag=TAG, sleep=lambda s: None):return nightly.savetest(self.cfg, self.config, self.job, self.runner, self.gh, self.itch, tag=tag,- fetch=fetch or page_for(self.itch), sleep=lambda s: None)+ fetch=fetch or page_for(self.itch), sleep=sleep)def evidence(self):return json.loads(next((self.job / "savetest").glob("*/evidence.json")).read_text())@@ -1965,6 +1965,41 @@ def test_savetest_waits_while_itch_is_still_unpacking_the_upload(saved):assert t.run(fetch) == "PASS" and t.enabled()+def too_many_requests(retry_after=None):+ import email.message+ import urllib.error+ headers = email.message.Message()+ if retry_after is not None:+ headers["Retry-After"] = retry_after+ return urllib.error.HTTPError(PAGE_URL, 429, "Too Many Requests", headers, None)++[email protected]("retry_after,pause", [("90", 90), (None, nightly.SAVETEST_RATE_LIMIT_SLEEP), ("soon",+ nightly.SAVETEST_RATE_LIMIT_SLEEP), ("5", nightly.SAVETEST_FRAME_SLEEP)])+def test_savetest_backs_off_and_keeps_waiting_when_itch_rate_limits_the_page(saved, retry_after, pause):+ t = saved() # 28 Oct 2026: itch answered 429 Too Many Requests while the test waited for upload B's frame+ framed, calls, sleeps = page_for(t.itch), {"n": 0}, []++ def fetch(url, timeout=30):+ calls["n"] += 1+ if t.itch.pushes == 2 and calls["n"] <= 6:+ raise too_many_requests(retry_after)+ return framed(url, timeout)+ assert t.run(fetch, sleep=sleeps.append) == "PASS" and t.enabled()+ assert pause in sleeps+++def test_savetest_a_rate_limit_that_never_lifts_ends_inconclusive_within_the_wait_budget(saved):+ t = saved()+ sleeps = []++ def fetch(url, timeout=30):+ raise too_many_requests("99999")+ assert t.run(fetch, sleep=sleeps.append) == "INCONCLUSIVE" and not t.enabled() and t.runner.runs == []+ assert sum(sleeps) <= nightly.SAVETEST_FRAME_TRIES * nightly.SAVETEST_FRAME_SLEEP+ assert sleeps and max(sleeps) == nightly.SAVETEST_RATE_LIMIT_MAX and "429" in t.log()++def test_savetest_a_page_without_a_frame_is_inconclusive(saved):t = saved()assert t.run(page_for(t.itch, frame=False)) == "INCONCLUSIVE" and t.runner.runs == [] and not t.enabled()