Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(ci): give a file that ran out of its budget one longer attempt (#589)

Ruben Lütke94e9a12bbff0
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 022c6b72c2..395e1b0b3e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -658,10 +658,18 @@ jobs:
pattern: tests-windows-*
path: reports/windows
merge-multiple: true
+ - name: Download the duration history this run started from
+ uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
+ with:
+ name: ${{ needs.detect.outputs.duration_snapshot }}
+ # On top of the history the run started from. A file that was flaky in
+ # this run reports no timing, and a history rebuilt from one run alone
+ # forgot it: the file fell back to the generic budget, timed out on a
+ # loaded runner, and could never report a timing again.
- name: Merge the shard timings
run: |
- python scripts/ci/ratchet_tests.py durations --out test_durations.json reports/linux
- python scripts/ci/ratchet_tests.py durations --out test_durations_windows.json reports/windows
+ python scripts/ci/ratchet_tests.py durations --base test_durations.json --out test_durations.json reports/linux
+ python scripts/ci/ratchet_tests.py durations --base test_durations_windows.json --out test_durations_windows.json reports/windows
- name: Save the Linux duration cache
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
diff --git a/docs/ci-pipeline.md b/docs/ci-pipeline.md
index ca35e59b6b..e8d7b63c1d 100644
--- a/docs/ci-pipeline.md
+++ b/docs/ci-pipeline.md
@@ -65,11 +65,11 @@ request, merge queue, and again on the push of the same commit).
| `zizmor` / `dependency review` | Workflow security audit on every event (merge queue included, exceptions in `.github/zizmor.yml`); dependency review on pull requests only, failing on an added dependency with a high or critical advisory. `security.yml` keeps the Security-tab uploads. | — |
| `live third-party sites` | Nightly only and non-blocking: the opt-in live checks of pages the app parses (`JARVIS_LIVE_NETWORK_TESTS=1`, ollama.com's library). A site redesign shows as a failed step and a run warning, never as a red gate. | — |
| `python contracts (fast)` | Import cleanliness on the bare install, the named contract guards, skill-routing precision and recall, plugin auth. Blocking, no baseline. | — |
-| `tests linux 1..6` | The whole suite in six shards. Batches of files run in fresh processes with a wall-clock budget; a failed batch is re-run file by file, a failed file once more (a pass there is reported as flaky). | `scripts/ci/run_tests_parallel.py` |
+| `tests linux 1..6` | The whole suite in six shards. Batches of files run in fresh processes with a wall-clock budget; a failed batch is re-run file by file, a failed file once more (a pass there is reported as flaky). A file that runs out of its budget alone gets one more attempt with twice that budget, capped at the file ceiling: a file without history starts on the generic floor, and a pass there is reported as flaky and enters the history with its real duration. | `scripts/ci/run_tests_parallel.py` |
| `tests windows 1..6` | The whole suite in six shards on every tier, pull requests included, so a Windows-only failure blocks the pull request instead of ejecting it from the merge queue. | `scripts/ci/run_tests_parallel.py` |
| `tests macos 1..3` | Nightly, release and manual runs with macOS only. | — |
| `test report + floor` | Proves the six Linux shards cover every discovered file exactly once, enforces the min-passed floor. Detection freezes one shared duration snapshot for all shards, including partial reruns. | `scripts/ci/ratchet_tests.py` |
-| `duration cache` | Runs on main only (nightly, a manual run, a push that bypassed the queue) and only after every Linux and Windows shard succeeded: merges the shard timings into one history per OS. Windows shards by its own history; until one exists it uses the Linux one. | `scripts/ci/ratchet_tests.py durations` |
+| `duration cache` | Runs on main only (nightly, a manual run, a push that bypassed the queue) and only after every Linux and Windows shard succeeded: merges the shard timings into one history per OS, on top of the history the run started from, so a file that was flaky in one run keeps its timing. Windows shards by its own history; until one exists it uses the Linux one. | `scripts/ci/ratchet_tests.py durations` |
| Lanes | `frontend` (three test shards and the build, side by side), `jarvisctl`, `deps`, `realtime` (+ slim container), `updater` (in-app update, native handover, restart helper), `agent runtimes` (+ slim container + the real Hermes and OpenClaw at their pinned version; see [agent-runtimes.md](agent-runtimes.md#ci-and-release-gates)), `dragdrop`, `browser`, `macOS desktop`, `installer smoke` — each only when its paths change, each as wide as the tier: Linux + Windows on a pull request, + macOS in the merge queue, + Intel and ARM in the wide matrix. | `scripts/ci/plan_run.py` |
| `release qualification` | Tag CI requires a full run with macOS and the browser-auth E2E evidence gate: a plugin labeled verified needs a completed journey, every completed journey ships as verified, and every other plugin ships labeled preview. The step summary counts both. Ordinary branch/PR/nightly CI skips this release-only job. | `scripts/ci/check_plugin_auth_contract.py --require-e2e-pass` |
| `CI gate` | Aggregates every job. **The only required check**, on the pull request and again on its merge-queue group. A missing or skipped selected lane fails. Unselected lanes may skip; nightly is strict except event-specific jobs. | `scripts/ci/required_results.py` |
diff --git a/scripts/ci/run_tests_parallel.py b/scripts/ci/run_tests_parallel.py
index 183ccba226..03fe17904d 100644
--- a/scripts/ci/run_tests_parallel.py
+++ b/scripts/ci/run_tests_parallel.py
@@ -17,11 +17,15 @@ How it works (a per-file runner):
in fresh processes, and a failed file gets one more fresh attempt. A pass
on that attempt is reported as FLAKY, not as a failure.
5. **Bound**: every process has a wall-clock budget and is killed with its
- whole process tree, so a hang costs one file, never the job.
+ whole process tree, so a hang costs one file, never the job. A file that
+ runs out of its budget alone gets one more attempt with a longer one: a
+ file the history has never timed starts on the generic floor, and a slow
+ file on a loaded runner is not a hang.
Outputs: ``--report`` (JSON: failed test ids, flaky files, counts) and
``--junit-out`` (merged JUnit XML), plus ``--durations-out`` (timings of files
-that passed on the first attempt — a hang can never ratchet its own budget).
+that passed on the first attempt or alone after a timeout — a killed run has no
+timing, so a hang can never ratchet its own budget).
The runner exits 1 when any test failed for real; whether that blocks the
build is ``test_ratchet.py``'s decision (known failures are baselined).
@@ -57,6 +61,12 @@ BATCH_TARGET_SECONDS = 45.0
BATCH_MAX_FILES = 12
MAX_BATCH_TIMEOUT = 1800.0
BATCH_TIMEOUT_FACTOR = 6.0 # times the batch's own history
+# A file that timed out alone runs once more with this multiple of its budget.
+# The floor is a guess for a file without history: on Windows a file whose
+# tests each start a contained command took 160 s on a quiet runner and more
+# than the 300 s floor on a loaded one, and every such timeout ejected a pull
+# request from the merge queue. A real hang now costs the floor three times.
+TIMEOUT_RETRY_FACTOR = 2.0
_OK_EXIT_CODES = {0, 5} # 5 = every test deselected / none collected
# A new batch waits while less than this much memory is left to commit. A local
# run shares the machine with the user's apps: eight batches on a box already
@@ -143,6 +153,11 @@ def file_timeout(file: str, durations: dict[str, float]) -> float:
return min(MAX_FILE_TIMEOUT, max(MIN_FILE_TIMEOUT, 3 * durations.get(file, 0.0)))
+def retry_timeout(file: str, durations: dict[str, float]) -> float:
+ """Wall clock for the one attempt a timed-out file gets on its own."""
+ return min(MAX_FILE_TIMEOUT, TIMEOUT_RETRY_FACTOR * file_timeout(file, durations))
+
+
def batch_timeout(batch: list[str], durations: dict[str, float]) -> float:
"""Wall clock for one batch: its slowest file's budget, or a multiple of its load.
@@ -405,23 +420,35 @@ class Runner:
"""Run one batch with isolation-on-failure and a flaky retry."""
budget = batch_timeout(batch, self.durations)
first = self.run(batch, budget)
- outcome: dict[str, object] = {"runs": [first], "flaky": [], "first_pass": []}
+ outcome: dict[str, object] = {"runs": [first], "flaky": [], "first_pass": [], "slow": []}
if first.ok:
outcome["first_pass"] = list(batch)
return outcome
runs: list[RunResult] = []
flaky: list[str] = []
+ slow: list[str] = []
for file in batch:
budget_one = file_timeout(file, self.durations)
single = first if len(batch) == 1 else self.run([file], budget_one)
- if not single.ok and not single.timed_out:
- retry = self.run([file], budget_one)
+ if not single.ok:
+ timed_out = single.timed_out
+ again = retry_timeout(file, self.durations) if timed_out else budget_one
+ retry = self.run([file], again)
if retry.ok:
flaky.append(file)
+ if timed_out:
+ # Its real duration, so the next history gives it room.
+ slow.append(file)
+ print(
+ f"[runner] SLOW: {file} passed in {retry.duration:.0f}s "
+ f"after running out of {int(budget_one)}s",
+ flush=True,
+ )
single = retry
runs.append(single)
outcome["runs"] = runs
outcome["flaky"] = flaky
+ outcome["slow"] = slow
return outcome
@@ -488,6 +515,7 @@ def main(argv: list[str] | None = None) -> int:
all_runs: list[RunResult] = []
flaky: list[str] = []
first_pass: list[str] = []
+ slow: list[str] = []
done = 0
with ThreadPoolExecutor(max_workers=max(1, args.workers)) as pool:
futures = [pool.submit(runner.run_unit, batch) for batch in batches]
@@ -497,6 +525,7 @@ def main(argv: list[str] | None = None) -> int:
all_runs.extend(runs) # type: ignore[arg-type]
flaky.extend(outcome["flaky"]) # type: ignore[arg-type]
first_pass.extend(outcome["first_pass"]) # type: ignore[arg-type]
+ slow.extend(outcome["slow"]) # type: ignore[arg-type]
done += 1
for run in runs: # type: ignore[attr-defined]
if not run.ok:
@@ -531,9 +560,10 @@ def main(argv: list[str] | None = None) -> int:
if args.durations_out:
fresh: dict[str, float] = {}
+ timed = {*first_pass, *slow}
for run in all_runs:
for file, secs in run.file_seconds.items():
- if file in first_pass:
+ if file in timed:
fresh[file] = round(secs + 1.0, 2) # + interpreter start-up share
payload = json.dumps(fresh, indent=1, sort_keys=True) + "\n"
args.durations_out.write_text(payload, encoding="utf-8")
diff --git a/tests/unit/ci/test_pipeline_audit.py b/tests/unit/ci/test_pipeline_audit.py
index eaafca8f4c..86f2faa56c 100644
--- a/tests/unit/ci/test_pipeline_audit.py
+++ b/tests/unit/ci/test_pipeline_audit.py
@@ -472,6 +472,18 @@ def test_only_a_complete_green_run_on_main_writes_the_duration_caches():
}
assert not any("cache/save@" in s.get("uses", "") for s in ci["test-report"]["steps"])
assert "duration-cache" in ci["gate"]["needs"]
+ # Each history is merged onto the one the run started from: a file that
+ # was flaky in this run reports no timing and must keep the one it had.
+ names = [s.get("name", "") for s in job["steps"]]
+ assert names.index("Download the duration history this run started from") < names.index(
+ "Merge the shard timings"
+ )
+ merge = next(s["run"] for s in job["steps"] if s.get("name") == "Merge the shard timings")
+ assert "--base test_durations.json --out test_durations.json reports/linux" in merge
+ assert (
+ "--base test_durations_windows.json --out test_durations_windows.json reports/windows"
+ in merge
+ )
def test_windows_shards_by_its_own_history_and_falls_back_to_the_linux_one():
diff --git a/tests/unit/ci/test_pipeline_scripts.py b/tests/unit/ci/test_pipeline_scripts.py
index aefb198496..5f4f8028aa 100644
--- a/tests/unit/ci/test_pipeline_scripts.py
+++ b/tests/unit/ci/test_pipeline_scripts.py
@@ -270,6 +270,120 @@ def test_runner_reports_failures_and_passes(tmp_path):
assert any(fid.endswith("::test_bad") for fid in report["failed_ids"])
+class _ScriptedRunner(run_tests_parallel.Runner):
+ """A runner whose pytest processes are scripted: no process is started."""
+
+ script: dict[str, list[str]] = {}
+
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.calls: list[tuple[tuple[str, ...], float]] = []
+ self.left = {file: list(steps) for file, steps in self.script.items()}
+
+ def run(self, files, timeout):
+ self.calls.append((tuple(files), timeout))
+ step = self.left[files[0]].pop(0) if len(files) == 1 else "pass"
+ return run_tests_parallel.RunResult(
+ files=list(files),
+ exit_code=0 if step == "pass" else 1,
+ duration=12.0,
+ timed_out=step == "timeout",
+ failed_ids=[] if step == "pass" else [f"{files[0]}::<{step}>"],
+ file_seconds={file: 7.0 for file in files} if step == "pass" else {},
+ counts={"tests": 1, "passed": int(step == "pass"), "failed": 0, "skipped": 0},
+ )
+
+
+def _scripted(tmp_path, script, durations=None):
+ runner_type = type("_Runner", (_ScriptedRunner,), {"script": script})
+ return runner_type(None, durations or {}, tmp_path)
+
+
+def test_a_file_that_runs_out_of_its_budget_gets_one_longer_attempt(tmp_path):
+ # GitHub issue #574 follow-up: a Windows file without history started on
+ # the 300 s floor, needed more on a loaded runner, and each timeout ejected
+ # a pull request from the merge queue.
+ runner = _scripted(tmp_path, {"t/test_slow.py": ["timeout", "pass"]})
+
+ outcome = runner.run_unit(["t/test_slow.py"])
+
+ floor = run_tests_parallel.MIN_FILE_TIMEOUT
+ assert [timeout for _files, timeout in runner.calls] == [floor, 2 * floor]
+ assert outcome["flaky"] == ["t/test_slow.py"]
+ assert outcome["slow"] == ["t/test_slow.py"]
+ assert [run.ok for run in outcome["runs"]] == [True]
+
+
+def test_a_file_that_hangs_twice_still_fails_as_a_timeout(tmp_path):
+ runner = _scripted(tmp_path, {"t/test_hang.py": ["timeout", "timeout"]})
+
+ outcome = runner.run_unit(["t/test_hang.py"])
+
+ assert len(runner.calls) == 2
+ assert outcome["flaky"] == [] and outcome["slow"] == []
+ (run,) = outcome["runs"]
+ assert run.timed_out and not run.ok
+
+
+def test_a_failed_file_is_retried_on_the_same_budget_and_is_not_slow(tmp_path):
+ runner = _scripted(tmp_path, {"t/test_flaky.py": ["fail", "pass"]})
+
+ outcome = runner.run_unit(["t/test_flaky.py"])
+
+ floor = run_tests_parallel.MIN_FILE_TIMEOUT
+ assert [timeout for _files, timeout in runner.calls] == [floor, floor]
+ assert outcome["flaky"] == ["t/test_flaky.py"] and outcome["slow"] == []
+
+
+def test_the_longer_attempt_never_exceeds_the_file_ceiling():
+ ceiling = run_tests_parallel.MAX_FILE_TIMEOUT
+ assert run_tests_parallel.retry_timeout("x", {"x": 10_000}) == ceiling
+ assert run_tests_parallel.retry_timeout("x", {"x": 250.0}) == ceiling
+ assert run_tests_parallel.retry_timeout("x", {}) < ceiling
+
+
+def test_a_slow_file_enters_the_duration_history_and_the_run_stays_green(
+ tmp_path, monkeypatch
+):
+ repo = run_tests_parallel.REPO_ROOT
+ rel = f"tests/unit/ci/_runner_probe_{tmp_path.name}"
+ probe = repo / rel
+ probe.mkdir()
+ slow, quick = f"{rel}/test_probe_slow.py", f"{rel}/test_probe_quick.py"
+ script = {slow: ["timeout", "pass"], quick: ["pass"]}
+ monkeypatch.setattr(
+ run_tests_parallel, "Runner", type("_Runner", (_ScriptedRunner,), {"script": script})
+ )
+ # One file per batch, as a file with a long history runs.
+ monkeypatch.setattr(run_tests_parallel, "BATCH_MAX_FILES", 1)
+ try:
+ for name in (slow, quick):
+ (repo / name).write_text("def test_ok():\n assert True\n")
+ code = run_tests_parallel.main(
+ [
+ rel,
+ "--workers",
+ "1",
+ "--durations",
+ str(tmp_path / "none.json"),
+ "--report",
+ str(tmp_path / "r.json"),
+ "--junit-out",
+ str(tmp_path / "r.xml"),
+ "--durations-out",
+ str(tmp_path / "d.json"),
+ ]
+ )
+ finally:
+ shutil.rmtree(probe, ignore_errors=True)
+ report = json.loads((tmp_path / "r.json").read_text(encoding="utf-8"))
+ timings = json.loads((tmp_path / "d.json").read_text(encoding="utf-8"))
+ assert code == 0
+ assert report["failed_ids"] == [] and report["timeouts"] == []
+ assert report["flaky_files"] == [slow]
+ assert timings == {slow: 8.0, quick: 8.0}
+
+
def test_memory_probe_reads_this_machine():
free = run_tests_parallel.available_memory()
assert free is None or free > 0