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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
perf(git): ask for named checks only where the Git tab shows them (#663)
Ruben Lütkee16b44ec1aea
diff --git a/jarvis/agentic_ide/git_overview.py b/jarvis/agentic_ide/git_overview.pyindex 7c716e1264..d5ecdb99b3 100644--- a/jarvis/agentic_ide/git_overview.py+++ b/jarvis/agentic_ide/git_overview.py@@ -34,7 +34,7 @@ import shutilimport subprocessimport threadingimport time-from collections.abc import Callable+from collections.abc import Callable, Iterablefrom dataclasses import asdict, dataclass, fieldfrom datetime import datetimefrom pathlib import Path@@ -75,9 +75,10 @@ SLOW_READ_S = 2.0# part alone is well inside it.## The checks behind each pull request's verdict are the slow part by far, so-# the pull requests are asked twice: once with the verdict and GitHub's own-# tally of the checks, which is on screen in about two seconds, and once with-# the checks themselves (their names and runs), which follow.+# the pull requests come with the verdict and GitHub's own tally of the+# checks, which is on screen in about two seconds. The checks themselves+# (their names and runs) are asked only for the pull requests whose checks+# the tab names — the failed and the running ones.#: Every open pull request with the CI verdict of its newest commit and how#: many checks passed, failed and run — no single check.@@ -95,7 +96,8 @@ query($owner: String!, $name: String!) {}"""-#: The same pull requests with the checks behind each verdict.+#: The same pull requests with every check behind each verdict: one more try+#: when the quick read fails._OPEN_QUERY = """query($owner: String!, $name: String!) {repository(owner: $owner, name: $name) {@@ -570,7 +572,10 @@ def _repository(payload: dict[str, Any]) -> dict[str, Any]:def _fetch_github(- repo: str, token: str, early: Callable[[_GitHubSnapshot], None] | None = None+ repo: str,+ token: str,+ early: Callable[[_GitHubSnapshot], None] | None = None,+ known_busy: Iterable[int] = (),) -> _GitHubSnapshot:"""GitHub's answer for ``repo``.@@ -578,6 +583,10 @@ def _fetch_github(pull request with its CI verdict and check counts and every branch, withoutthe names and runs of the checks and without CI for a branch that has nopull request.++ ``known_busy`` are the pull requests that failed or ran at the last read:+ their checks are asked for at once, side by side with the quick parts, so a+ refresh does not wait for the quick answer before asking."""now = time.time()owner, _, name = repo.partition("/")@@ -589,8 +598,9 @@ def _fetch_github(except github_link.GitHubError as exc: # handed back to the caller belowreturn exc+ known = sorted({int(number) for number in known_busy})quick_job = git_local.Job(ask, _OPEN_QUICK_QUERY + _PR_FRAGMENT + _TALLY_FRAGMENT)- open_job = git_local.Job(ask, _OPEN_QUERY + _PR_FRAGMENT + _ROLLUP_FRAGMENT)+ known_job = git_local.Job(ask, _details_query(known)) if known else Nonerecent_job = git_local.Job(ask, _RECENT_QUERY + _PR_FRAGMENT)refs_job = git_local.Job(ask, _REFS_CI_QUERY + _ROLLUP_FRAGMENT)names_job = git_local.Job(_all_refs, token, owner, name)@@ -599,21 +609,79 @@ def _fetch_github(# Open pull requests and CI landed; only "merged" marks are missing this round.logger.debug("Git overview: recent pull requests failed: {}", recent.code)recent = {}- if early is not None and not isinstance(quick, github_link.GitHubError):- first = _snapshot(quick, recent, {}, names, now)- if first.ok:- early(first)- opened, refs = open_job.result(), refs_job.result()- if isinstance(opened, github_link.GitHubError) and not isinstance(- quick, github_link.GitHubError- ):- # The checks behind each verdict are missing this round; the verdicts are not.- logger.debug("Git overview: pull request checks failed: {}", opened.code)- opened = quick- for answer in (opened, refs):- if isinstance(answer, github_link.GitHubError): # shown in the tab as github.reason/code- return _GitHubSnapshot(ok=False, reason=str(answer), code=answer.code, fetched_at=now)- return _snapshot(opened, recent, refs, names, now)+ if isinstance(quick, github_link.GitHubError):+ # One more try in the shape that carries the checks too, before giving up.+ logger.debug("Git overview: quick pull request read failed: {}", quick.code)+ quick = ask(_OPEN_QUERY + _PR_FRAGMENT + _ROLLUP_FRAGMENT)+ if isinstance(quick, github_link.GitHubError): # shown in the tab as github.reason/code+ return _GitHubSnapshot(ok=False, reason=str(quick), code=quick.code, fetched_at=now)+ first = _snapshot(quick, recent, {}, names, now)+ # Which checks to name is decided before ``early`` dresses the answer up.+ wanted = {pr.number: pr.ci.commit for pr in first.prs if _needs_details(pr)}+ missing = [number for number in wanted if number not in known]+ missing_job = git_local.Job(ask, _details_query(missing)) if missing else None+ if early is not None and first.ok:+ early(first)+ details: dict[int, CiStatus] = {}+ for job in (known_job, missing_job):+ if job is not None:+ details.update(_details(job.result()))+ # A pull request that got a new commit since the last read is asked again.+ moved = [n for n, commit in wanted.items() if n in details and details[n].commit != commit]+ if moved:+ details.update(_details(ask(_details_query(moved))))+ refs = refs_job.result()+ if isinstance(refs, github_link.GitHubError): # shown in the tab as github.reason/code+ return _GitHubSnapshot(ok=False, reason=str(refs), code=refs.code, fetched_at=now)+ snap = _snapshot(quick, recent, refs, names, now)+ _apply_details(snap, details)+ return snap+++def _needs_details(pr: PullRequest) -> bool:+ """The tab names the checks of a pull request that failed or still runs."""+ return pr.ci.state in {"failure", "running", "pending"}+++def _details_query(numbers: Iterable[int]) -> str:+ """The checks behind the verdicts of these pull requests, one alias each."""+ rows = " ".join(+ f"p{number}: pullRequest(number: {number}) {{ number commits(last: 1) "+ "{ nodes { commit { oid statusCheckRollup { ...Rollup } } } } }"+ for number in sorted({int(n) for n in numbers})+ )+ return (+ "query($owner: String!, $name: String!) { "+ f"repository(owner: $owner, name: $name) {{ {rows} }} }}" + _ROLLUP_FRAGMENT+ )+++def _details(answer: dict[str, Any] | github_link.GitHubError) -> dict[int, CiStatus]:+ """Pull request number → the CI of its newest commit, checks named."""+ if isinstance(answer, github_link.GitHubError):+ # The verdicts and counts stay; only the names of the checks are missing.+ logger.debug("Git overview: pull request checks failed: {}", answer.code)+ return {}+ found: dict[int, CiStatus] = {}+ for node in _repository(answer).values():+ if not isinstance(node, dict) or not node.get("number"):+ continue+ commits = (node.get("commits") or {}).get("nodes") or []+ commit = (commits[0] or {}).get("commit") if commits else None+ if isinstance(commit, dict):+ found[int(node["number"])] = ci_from_rollup(+ commit.get("statusCheckRollup"), str(commit.get("oid") or "")+ )+ return found+++def _apply_details(snap: _GitHubSnapshot, details: dict[int, CiStatus]) -> None:+ """Name the checks of each pull request whose commit the details describe."""+ for pr in snap.prs:+ known = details.get(pr.number)+ if known is not None and known.commit == pr.ci.commit:+ pr.ci.names = known.names+ pr.ci.url = known.url or pr.ci.urldef _snapshot(@@ -751,7 +819,12 @@ class _GitHubCache:with self._guard:self._entries[key] = first- fetched = _fetch_github(key, token, early)+ busy = (+ [pr.number for pr in snap.prs if _needs_details(pr)]+ if (snap is not None and snap.ok)+ else []+ )+ fetched = _fetch_github(key, token, early, busy)with self._guard:shown = self._entries.get(key)if fetched.ok or shown is None or not shown.ok:diff --git a/tests/unit/agentic_ide/test_git_control_center.py b/tests/unit/agentic_ide/test_git_control_center.pyindex a325b71691..44c457d7f0 100644--- a/tests/unit/agentic_ide/test_git_control_center.py+++ b/tests/unit/agentic_ide/test_git_control_center.py@@ -2,6 +2,7 @@from __future__ import annotations+import reimport shutilimport subprocessfrom pathlib import Path@@ -155,7 +156,9 @@ def test_unfetched_commits_on_github_are_flagged(theirs = _commit(other, "theirs.txt")_git(other, "push", "-q")- def snapshot(repo_name: str, token: str, early: object = None) -> git_overview._GitHubSnapshot:+ def snapshot(+ repo_name: str, token: str, early: object = None, known_busy: object = ()+ ) -> git_overview._GitHubSnapshot:snap = git_overview._GitHubSnapshot(ok=True, fetched_at=git_overview.time.time())snap.refs["main"] = (theirs[:12], CiStatus())return snap@@ -466,8 +469,8 @@ def test_github_is_asked_in_parts_and_a_missing_part_only_costs_its_own_data(monkeypatch.setattr(github_link, "graphql", fake_graphql)snap = git_overview._fetch_github("o/r", "t")- # The open pull requests are asked twice: the verdicts first, the checks after.- assert sorted(asked) == ["open", "open", "recent", "refs"]+ # No pull request failed or runs: nobody asks for the checks behind the verdicts.+ assert sorted(asked) == ["open", "recent", "refs"]# Recently merged pull requests are missing this round; everything else landed.assert snap.ok and [pr.number for pr in snap.prs] == [1, 2]assert (snap.prs[1].conflicting, snap.prs[1].review, snap.prs[1].author) == (@@ -487,7 +490,7 @@ def test_a_refresh_never_makes_the_tab_wait_for_github(reads: list[float] = []def slow_fetch(- repo_name: str, token: str, early: object = None+ repo_name: str, token: str, early: object = None, known_busy: object = ()) -> git_overview._GitHubSnapshot:reads.append(git_overview.time.time())if len(reads) > 1:@@ -571,7 +574,9 @@ def test_a_failed_github_read_keeps_the_last_good_answer(monkeypatch: pytest.Mon]reads: list[str] = []- def fetch(repo_name: str, token: str, early: object = None) -> git_overview._GitHubSnapshot:+ def fetch(+ repo_name: str, token: str, early: object = None, known_busy: object = ()+ ) -> git_overview._GitHubSnapshot:reads.append(repo_name)return answers[min(len(reads), len(answers)) - 1]@@ -674,17 +679,47 @@ def _with_ci(node: dict, rollup: dict, oid: str = "a" * 40) -> dict:return {**node, "commits": {"nodes": [{"commit": {"oid": oid, "statusCheckRollup": rollup}}]}}-def _github_in_two_steps(monkeypatch: pytest.MonkeyPatch, checks, oid: str = "a" * 40):- """A fake GitHub whose checks-bearing answer comes from ``checks()``."""+def _github_in_two_steps(+ monkeypatch: pytest.MonkeyPatch, checks, oid: str = "a" * 40, asked: list | None = None+):+ """A fake GitHub: pull request 1 failed, pull request 2 passed; the checks+ behind a verdict come from ``checks()`` (a rollup, or it raises)."""+ tally = {+ "state": "FAILURE",+ "contexts": {+ "totalCount": 2,+ "checkRunCountsByState": [+ {"state": "SUCCESS", "count": 1},+ {"state": "FAILURE", "count": 1},+ ],+ },+ }def fake_graphql(token: str, query: str, variables: dict | None = None) -> dict:if "pageInfo" in query:return _repo_payload(refs={"pageInfo": {"hasNextPage": False}, "nodes": []})if "states: OPEN" in query and "...Tally" in query:- node = _with_ci(_pr_node(1, "a"), {"state": "SUCCESS"}, oid)- return _repo_payload(pullRequests={"nodes": [node]})- if "states: OPEN" in query:- return checks()+ nodes = [+ _with_ci(_pr_node(1, "a"), tally, oid),+ _with_ci(_pr_node(3, "c"), {"state": "SUCCESS"}, oid),+ ]+ return _repo_payload(pullRequests={"nodes": nodes})+ if "pullRequest(number:" in query:+ numbers = [int(n) for n in re.findall(r"pullRequest\(number: (\d+)\)", query)]+ if asked is not None:+ asked.append(numbers)+ rollup = checks()+ return _repo_payload(+ **{+ f"p{n}": {+ "number": n,+ "commits": {+ "nodes": [{"commit": {"oid": oid, "statusCheckRollup": rollup}}]+ },+ }+ for n in numbers+ }+ )if "MERGED" in query:return _repo_payload(pullRequests={"nodes": []})return _repo_payload(refs={"nodes": [{"name": "main", "target": {"oid": "0" * 40}}]})@@ -705,35 +740,78 @@ def test_pull_requests_and_verdicts_show_before_their_checks_arrive(import threadingrelease = threading.Event()+ asked: list = []def checks() -> dict:release.wait(5)- node = _with_ci(_pr_node(1, "a"), _checks("SUCCESS"))- return _repo_payload(pullRequests={"nodes": [node]})+ return _checks("FAILURE")- _github_in_two_steps(monkeypatch, checks)+ _github_in_two_steps(monkeypatch, checks, asked=asked)cache = git_overview._GitHubCache()assert cache.get("o/r", "t", wait=False) is None_until(lambda: cache.peek("o/r") is not None)first = cache.peek("o/r")- # The verdict is there and leads to the checks page; the checks are still loading.+ # Verdicts and counts are there and lead to the checks page; the names still load.assert first.ok and cache.loading("o/r")- assert (first.prs[0].ci.state, first.prs[0].ci.total) == ("success", 0)- assert first.prs[0].ci.url == "https://github.com/o/r/pull/1/checks"+ failed = first.prs[0]+ assert (failed.ci.state, failed.ci.failed, failed.ci.total, failed.ci.names) == (+ "failure",+ 1,+ 2,+ [],+ )+ assert failed.ci.url == "https://github.com/o/r/pull/1/checks"release.set()_until(lambda: not cache.loading("o/r"))full = cache.peek("o/r")- assert (full.prs[0].ci.total, full.prs[0].ci.passed) == (1, 1)+ assert full.prs[0].ci.names == ["CI gate"]+ assert full.prs[0].ci.url == "https://github.com/o/r/runs/1"+ # Only the failed pull request was asked for its checks, never the passed one.+ assert asked == [[1]]assert "main" in full.refs+def test_a_refresh_asks_for_the_checks_it_already_expects_at_once(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ import threading++ quick_answered = threading.Event()+ order: list[str] = []+ asked: list = []++ def checks() -> dict:+ order.append("checks asked" if not quick_answered.is_set() else "checks after quick")+ return _checks("FAILURE")++ _github_in_two_steps(monkeypatch, checks, asked=asked)+ real = github_link.graphql++ def slow_quick(token: str, query: str, variables: dict | None = None) -> dict:+ if "...Tally" in query:+ git_overview.time.sleep(0.3)+ quick_answered.set()+ return real(token, query, variables)++ monkeypatch.setattr(github_link, "graphql", slow_quick)+ snap = git_overview._fetch_github("o/r", "t", known_busy=[1])+ # Pull request 1 failed last time: its checks were asked side by side with+ # the quick read, and nothing had to be asked again afterwards.+ assert order == ["checks asked"] and asked == [[1]]+ assert snap.prs[0].ci.names == ["CI gate"]++def test_verdicts_stay_when_the_checks_cannot_be_read(monkeypatch: pytest.MonkeyPatch) -> None:def checks() -> dict:raise github_link.GitHubError("GitHub took too long.", code="unreachable")_github_in_two_steps(monkeypatch, checks)snap = git_overview._fetch_github("o/r", "t")- assert snap.ok and [(pr.number, pr.ci.state) for pr in snap.prs] == [(1, "success")]+ assert snap.ok+ assert [(pr.number, pr.ci.state, pr.ci.failed) for pr in snap.prs] == [+ (1, "failure", 1),+ (3, "success", 0),+ ]def test_a_refresh_keeps_the_checks_of_commits_that_did_not_move(diff --git a/tests/unit/agentic_ide/test_git_overview.py b/tests/unit/agentic_ide/test_git_overview.pyindex 825c944f56..6df84ec023 100644--- a/tests/unit/agentic_ide/test_git_overview.py+++ b/tests/unit/agentic_ide/test_git_overview.py@@ -286,7 +286,7 @@ def test_overview_joins_pull_requests_ci_and_squash_merges(calls: list[str] = []def fake_fetch(- repo_name: str, token: str, early: object = None+ repo_name: str, token: str, early: object = None, known_busy: object = ()) -> git_overview._GitHubSnapshot:calls.append(repo_name)snap = parse_github(@@ -363,7 +363,7 @@ def test_a_first_read_lists_local_branches_without_waiting_for_github(release = threading.Event()def slow_fetch(- repo_name: str, token: str, early: object = None+ repo_name: str, token: str, early: object = None, known_busy: object = ()) -> git_overview._GitHubSnapshot:release.wait(5)return parse_github(_payload([]), fetched_at=git_overview.time.time())