From 79269da8025e896a3890e74ffa460d9bb9b27b43 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 30 Jun 2026 21:39:00 -0400 Subject: [PATCH] fix(agent): prompt stop + lazy curator polling + build marker; add agent to CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses operator reports: Stop never finishes, the agent polls curator constantly, and stale-cached pages get mistaken for a failed deploy. - Stop is prompt: flip _running BEFORE any lock so /status + worker loops see "stopped" immediately, and add a stop/shrink checkpoint in _process (after decode, before the expensive detect+embed) that releases the job and bails — so a Stop doesn't wait out heavy GPU work. - Lazy curator polling: the queue snapshot is fetched only while a browser is actually watching (a /status hit within UI_IDLE_GRACE) and on a 5s cadence, not a constant background loop. The work loop's own lease/submit is curator's only visitor otherwise — nothing polls just to poll. - Build marker: VERSION is embedded in the page and reported on /status; the UI shows a "reload" banner when they differ, so a browser-cached page can't be mistaken for "the new image didn't deploy" (complements the no-store header). CI: the lint lane now also `ruff check`s agent/ and compileall-parses it, so the GPU agent is linted + syntax-checked before its image builds (build.yml only `docker build`s it). Fixed the agent's pre-existing UP037/B905 so it passes. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Ttrj5P7upUTueSfoJcxEqa --- .forgejo/workflows/ci.yml | 9 ++++++- agent/fc_agent/app.py | 18 ++++++++++++-- agent/fc_agent/config.py | 2 +- agent/fc_agent/worker.py | 50 +++++++++++++++++++++++++++++---------- 4 files changed, 62 insertions(+), 17 deletions(-) diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index 9a31d7c..ec1dcbf 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -27,7 +27,14 @@ jobs: steps: - uses: actions/checkout@v4 - name: Ruff lint - run: ruff check backend/ tests/ alembic/ + # agent/ included so the GPU-agent is linted before its image is built + # (build.yml only `docker build`s it — this is where it gets checked). + run: ruff check backend/ tests/ alembic/ agent/ + - name: Agent syntax check + # The agent's runtime deps (torch/transformers/ultralytics) aren't in the + # CI image, so we can't import it — but compileall parses every module, + # catching syntax errors before the image build. + run: python -m compileall -q agent/fc_agent backend-lint-and-test: runs-on: python-ci diff --git a/agent/fc_agent/app.py b/agent/fc_agent/app.py index 87be87b..f52435a 100644 --- a/agent/fc_agent/app.py +++ b/agent/fc_agent/app.py @@ -12,6 +12,11 @@ from .config import Config from .gpu import read_gpu from .worker import Worker +# Bump on every agent change. The page embeds this and /status reports it; the UI +# warns to reload when they differ — so a stale browser-cached page can't be +# mistaken for "the new image didn't deploy". (Belt-and-braces with no-store.) +VERSION = "2026-06-30.5 · stop+poll+ci" + logbuf.install() cfg = Config.from_env() worker = Worker(cfg) @@ -41,7 +46,7 @@ def _maybe_autostart() -> None: @app.get("/", response_class=HTMLResponse) def index() -> str: - return _PAGE + return _PAGE.replace("__BUILD__", VERSION) @app.post("/start") @@ -92,10 +97,12 @@ def status(): # Pure in-memory read: worker.status() is lock-free and the queue snapshot is # kept fresh by a background poller — NO inline curator call, so this can't # stall the status view when curator is buried under a big backlog. + worker.note_ui() # a browser is watching → keep the queue snapshot warm s = worker.status() s["fc_url"] = cfg.fc_url s["configured"] = bool(cfg.token) s["queue"] = worker.latest_queue() + s["build"] = VERSION return JSONResponse(s) @@ -179,8 +186,11 @@ _PAGE = """
FabledCurator GPU agent
-

Server · token

+

Server · token · build __BUILD__

+ @@ -227,6 +237,7 @@ _PAGE = """