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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ Condensed release history, newest first.

## Unreleased

**Curatarr steps aside for training and tagging runs, not only for games.** A PyTorch run is
`python.exe`, and `python.exe` counted as a system process: the card check never saw it. A training
run that drew 82-92 % of the card with under 1 GB of VRAM also slipped past the full-card gate (memory
free, overall load swinging), so the curator loaded beside it and the run took 20 minutes instead
of 7. Now an interpreter that is not Curatarr's own process (the PC agent reports its pid) and
draws 30 % or more of the card on two readings in a row makes the PC busy, on a NAS-plus-PC install
and on a desktop install alike. It is never put to the "is this a game?" question: one name, every
script. Measured on a 4090: tagging 80-88 %, an image embedding 71-74 %, training 82-92 %.

**One song played is one play.** Plex gives every copy of a track in the library (the album, the
remaster, a compilation) the same "last played" second while its history holds one play, and a song
stored from the library listing and from the history landed twice when the two stamps lay more than
Expand Down
9 changes: 6 additions & 3 deletions src/gpu_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,23 @@ def parse_instance(name: str) -> "tuple | None":


def per_process(values, names_by_pid) -> list[dict]:
"""[{"name", "pct"}] for the 3D engine, one line per program (its
processes summed, capped at 100), largest first."""
"""[{"name", "pct", "pids"}] for the 3D engine, one line per program (its
processes summed, capped at 100), largest first. ``pids`` lets Curatarr
tell its own interpreter from someone's training script of the same name."""
by_pid: dict = {}
for inst, pct in values:
parsed = parse_instance(inst)
if not parsed or parsed[1].lower() != "3d" or pct is None:
continue
by_pid[parsed[0]] = by_pid.get(parsed[0], 0.0) + float(pct)
by_name: dict = {}
pids_by_name: dict = {}
for pid, pct in by_pid.items():
name = names_by_pid(pid)
if name:
by_name[name] = min(100.0, by_name.get(name, 0.0) + pct)
return [{"name": n, "pct": round(p, 1)}
pids_by_name.setdefault(name, set()).add(pid)
return [{"name": n, "pct": round(p, 1), "pids": sorted(pids_by_name[n])}
for n, p in sorted(by_name.items(), key=lambda kv: -kv[1]) if p >= MIN_PCT]


Expand Down
4 changes: 4 additions & 0 deletions src/pc_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import hmac
import json
import logging
import os
import socket
import subprocess
import threading
Expand Down Expand Up @@ -183,6 +184,9 @@ def snapshot(self) -> dict:
logger.warning("[agent] update state unreadable: %s", e)
return {"v": AGENT_VERSION, "time": time.time(), "processes": procs,
"gpu": gpu, "gpu_procs": gpu_procs, "build": build,
# this process (the tray it runs in): a python.exe on the card
# that is not one of these is someone's GPU work
"own_pids": [os.getpid()],
"node": {"name": self.name}, "shutting_down": self.shutting_down}

def update(self) -> "tuple[int, dict]":
Expand Down
75 changes: 74 additions & 1 deletion src/services/process_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,72 @@ def unknown_gpu_user(report: "dict | None") -> "str | None":
return max(hits)[1] if hits else None


# Interpreters that run GPU compute: training, tagging, embeddings - PyTorch
# is python.exe. SYSTEM_PROCESSES keeps them out of the "is this a game?"
# question (a name cannot tell one script from the next, and a "not a game"
# would hide every later run), so the card check counts them on their own:
# not by name, by what they draw, minus Curatarr's own processes (the agent
# reports their pids). Measured on the owner's 4090 (2026-11-15): tagging
# 80-88 %, SigLIP embedding 71-74 %, a training run 82-92 % of the 3D engine
# with 0.8 GB of VRAM - the full-card gate never saw that one (memory free,
# overall load swinging), and it ran 20 minutes instead of 7 beside the curator.
COMPUTE_HOSTS = frozenset({"python.exe", "pythonw.exe", "python3.exe"})
_compute_streak: dict = {}


def foreign_compute(report: "dict | None", streak: "dict | None" = None) -> "str | None":
"""The interpreter (python.exe) that is not one of the report's
``own_pids`` and has drawn GPU_PROC_BUSY_PCT or more on the card for
GPU_PROC_POLLS readings in a row, if any. Call once per reading."""
streak = _compute_streak if streak is None else streak
report = report or {}
own = {int(p) for p in report.get("own_pids") or [] if str(p).isdigit()}
drawing: dict = {}
for p in report.get("gpu_procs") or []:
name = p.get("name") or ""
nl = name.lower()
if nl not in COMPUTE_HOSTS:
continue
pids = {int(x) for x in p.get("pids") or [] if str(x).isdigit()}
if pids and pids <= own:
continue # Curatarr's own process
try:
pct = float(p.get("pct") or 0)
except (TypeError, ValueError):
continue
if pct >= GPU_PROC_BUSY_PCT:
drawing[nl] = (name, pct)
for nl in list(streak):
if nl not in drawing:
del streak[nl]
hits = []
for nl, (name, pct) in drawing.items():
streak[nl] = streak.get(nl, 0) + 1
if streak[nl] >= GPU_PROC_POLLS:
hits.append((pct, name))
return max(hits)[1] if hits else None


_local_sampler: dict = {"s": None}
_local_compute_said: dict = {"name": None}
_local_compute_streak: dict = {}


def local_foreign_compute() -> "str | None":
"""foreign_compute for the card of THIS machine (a desktop install with its
own Ollama), read through the same engine counters the PC agent uses;
None where they do not exist (not Windows). On the event loop: the last
verdict, never a reading (see _on_loop)."""
import os
if _on_loop():
return _local_compute_said["name"]
if _local_sampler["s"] is None:
from src.gpu_engine import Sampler
_local_sampler["s"] = Sampler()
report = {"gpu_procs": _local_sampler["s"].sample(), "own_pids": [os.getpid()]}
return foreign_compute(report, _local_compute_streak)


def drew_on_gpu(name: str) -> bool:
"""The program drew on the PC's card within the last hour."""
return (name or "").lower() in _gpu_drawing_seen
Expand All @@ -413,6 +479,7 @@ def pc_busy(report: "dict | None") -> "tuple[bool, str]":
game = next((p.get("name") for p in report.get("processes") or []
if (p.get("name") or "").lower() in targets), None)
drawing = unknown_gpu_user(report)
computing = foreign_compute(report)
pc = pc_host()
pressed = gpu_pressure(smi=lambda: _smi_from_report(report.get("gpu")),
ps=lambda: _ollama_loaded_models(pc.url if pc else None),
Expand All @@ -421,6 +488,8 @@ def pc_busy(report: "dict | None") -> "tuple[bool, str]":
return True, f"{game} running"
if drawing:
return True, f"{drawing} draws on the card (not classified yet)"
if computing:
return True, f"{computing} computes on the card (GPU work, not Curatarr's)"
if pressed:
return True, f"card held: {_pc_gpu_cache.get('reason') or 'busy'}"
return False, ""
Expand Down Expand Up @@ -555,7 +624,11 @@ def is_game_running() -> bool:
return pressed or game
pressed = gpu_pressure()
game = game_process_running()
return pressed or game
computing = local_foreign_compute()
if computing and not _local_compute_said["name"]:
logger.info("[gpu] %s computes on the card (GPU work, not Curatarr's) - LLM work yields", computing)
_local_compute_said["name"] = computing
return pressed or game or bool(computing)


async def _our_models() -> list[str]:
Expand Down
59 changes: 58 additions & 1 deletion tests/test_gpu_game_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""
from _harness import check # noqa: I001 - first: temp stores

import os
import sys
from pathlib import Path

Expand Down Expand Up @@ -43,7 +44,8 @@
("pid_31337_luid_a_phys_0_eng_0_engtype_3D", 50.0)] # gone meanwhile
out = ge.per_process(rows, names.get)
check("3D only, summed per program and capped at 100, idle and vanished ones left out",
out == [{"name": "NewGame.exe", "pct": 100.0}, {"name": "llama-server.exe", "pct": 97.0}])
out == [{"name": "NewGame.exe", "pct": 100.0, "pids": [4242, 4243]},
{"name": "llama-server.exe", "pct": 97.0, "pids": [99]}])

agent = pc_agent.Agent("t" * 24, processes=lambda: [], gpu=lambda: [1.0, 2.0, 3.0],
gpu_procs=lambda: [{"name": "NewGame.exe", "pct": 88.0}])
Expand Down Expand Up @@ -100,6 +102,61 @@ def report(*procs, gpu=(2000.0, 24564.0, 20.0), processes=()):
check("no report: busy, and the streak is dropped",
pm.pc_busy(None)[0] and pm._gpu_proc_streak == {})

# ── someone's python on the card (2026-11-15) ───────────────────────────
# Measured on the owner's 4090 while Curatarr's curator sat beside them:
# tagging 80-88 %, a SigLIP embedding 71-74 %, a training run 82-92 % of
# the 3D engine with 0.8 GB of VRAM - python.exe was "a system process"
# and the full-card gate saw free memory and a swinging load.
def py(pct, pid, own=(), gpu=(2850.0, 24564.0, 45.0)):
r = report(gpu=gpu)
r["gpu_procs"] = [{"name": "python.exe", "pct": pct, "pids": [pid]}]
r["own_pids"] = list(own)
return r

for label, pct in (("training", 86.9), ("tagging", 84.1), ("SigLIP embedding", 73.3)):
pm._compute_streak.clear()
first = pm.pc_busy(py(pct, 3204))
second = pm.pc_busy(py(pct, 3204))
check(f"{label} in python.exe ({pct} %): busy on the second reading, and says why",
first == (False, "") and second[0] and "python.exe computes on the card" in second[1], second)
pm._compute_streak.clear()
for _ in range(3):
r = pm.pc_busy(py(90.0, 4321, own=[4321]))
check("Curatarr's own python process (the agent's pid) never counts", r == (False, ""))
pm._compute_streak.clear()
for _ in range(3):
r = pm.pc_busy(py(12.0, 3204))
check("a python script barely touching the card does not take the PC", r == (False, ""))
pm._compute_streak.clear()
pm.pc_busy(py(86.0, 3204))
pm.pc_busy(py(86.0, 3204))
check("...the run ends: free on the next reading", pm.pc_busy(report()) == (False, ""))
pm._gpu_drawing_seen.clear()
pm.unknown_gpu_user(py(86.0, 3204))
pm.unknown_gpu_user(py(86.0, 3204))
check("python.exe is never put to the 'is this a game?' question (one name, every script)",
not pm.drew_on_gpu("python.exe"))
# A desktop install reads its own card through the same counters.
class _FakeSampler:
def __init__(self, rows):
self.rows = rows

def sample(self):
return self.rows

pm._local_compute_streak.clear()
pm._local_sampler["s"] = _FakeSampler([{"name": "python.exe", "pct": 86.0, "pids": [3204]}])
pm.local_foreign_compute()
check("a desktop install sees someone's training on its own card too",
pm.local_foreign_compute() == "python.exe")
pm._local_compute_streak.clear()
pm._local_sampler["s"] = _FakeSampler([{"name": "python.exe", "pct": 86.0, "pids": [os.getpid()]}])
pm.local_foreign_compute()
check("...but never its own server process", pm.local_foreign_compute() is None)
pm._local_sampler["s"] = None
check("the agent reports its own pid", pc_agent.Agent("t" * 24, processes=lambda: [], gpu=lambda: [1.0, 2.0, 3.0],
gpu_procs=lambda: []).snapshot()["own_pids"] == [os.getpid()])

# ── whose programs are asked about ──────────────────────────────────────
pc_host.configured = lambda: True
pc_host.snapshot = lambda: report(("NewGame.exe", 85.0),
Expand Down
5 changes: 3 additions & 2 deletions tests/test_llm_lane.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ def test_the_wiring():

pm = (_ROOT / "src/services/process_monitor.py").read_text(encoding="utf-8")
assert "def game_process_running() -> bool:" in pm and "def gpu_pressure_reason() -> str:" in pm
# both causes, no short circuit, so the loop's cached verdicts stay fresh
assert "pressed = gpu_pressure()\n game = game_process_running()\n return pressed or game" in pm
# every cause read, no short circuit, so the loop's cached verdicts stay fresh
# (someone's GPU compute joined the game and the full card, 2026-11-15)
assert "pressed = gpu_pressure()\n game = game_process_running()\n computing = local_foreign_compute()" in pm

cust = (_ROOT / "src/services/data_custodian.py").read_text(encoding="utf-8")
assert 'llm_role: str = "curator"' in cust, "curator is the safe default"
Expand Down
Loading