Skip to content

feat(web): add gbench-web UI, plugin API, and Cloud Run support (0.6.0) - #21

Open
lucianommartins wants to merge 1 commit into
mainfrom
lucianommartins/gbench-web
Open

lucianommartins wants to merge 1 commit into
mainfrom
lucianommartins/gbench-web

Conversation

@lucianommartins

Copy link
Copy Markdown
Collaborator

Summary

Adds gbench-web (gbench/web/), an optional local and containerized Web UI, managed job queue, live log viewer, and results explorer for gBench, and bumps the package version from 0.5.0.post1 to 0.6.0. Core gbench runners and gbench/cli.py are untouched (only gbench/__init__.py version and the new gbench/web/ subpackage are added under gbench/).

The feature installs via pip install -e ".[web]" (adding fastapi, starlette, uvicorn, and google-cloud-storage). Compiled SPA assets under gbench/web/static/ (~2.3 MB) are committed so pip install works without Node.js.

What Changed

  • Backend (gbench/web/): FastAPI app, SQLite WAL job queue with GPU UUID, GBENCH_SERVER_PORT, and Docker network pool leasing, file-backed logs (.gbench_web_logs/), SSE streaming with Last-Event-ID cursor resume, crash-recovery progress and summary.json exit inference, fail-closed redact_tree() private GCS sync, and gbench-web / python -m gbench.web entry points.
  • Plugin contract (gbench/web/protocols.py): PLUGIN_API_VERSION = 1 protocols (AuthProvider, StateStore, JobExecutor, SubmissionPolicy, LogStreamProvider, ArtifactStore, CatalogExtension), loaded only when explicitly requested via GBENCH_WEB_PLUGIN (gbench.web.plugins entry-point group) and reported by GET /api/capabilities.
  • Security and hosted Cloud Run mode (gbench/web/security.py, gbench/web/app.py, gbench/web/cli_contract.py):
    • Defaults to strict loopback binding (127.0.0.1, localhost, ::1) with a one-time bootstrap token printed to stdout (never written to disk).
    • Refuses --host 0.0.0.0 unless either an external AuthProvider (requires_loopback_bind = False) is active or both env-only GBENCH_WEB_AUTH_TOKEN (>= 32 chars, never logged, stripped from child subprocesses) and GBENCH_WEB_ALLOWED_HOSTS (rejecting bare * and single-label wildcards) are configured.
    • Enforces HttpOnly; SameSite=Strict cookies (__Host-gbench_session, Secure, and HSTS when GBENCH_WEB_TLS_ENABLED=true), X-GBench-CSRF double-submit tokens, Origin and Sec-Fetch-Site checks (honoring X-Forwarded-Proto: https), a dedicated 20 req/min rate limiter on POST /api/auth/session with stale-bucket eviction, SSRF checks, and path containment.
    • Adds --remote-only (GBENCH_WEB_REMOTE_ONLY) and automatic local vllm/GPU detection; rejects non-remote jobs with HTTP 422 on POST /api/jobs, POST /api/jobs/{job_id}/clone, and POST /api/jobs/preflight before policy evaluation.
  • Frontend (web/ and committed gbench/web/static/): React 19 + TypeScript + Vite + Tailwind SPA with Composer (/submit), Queue and Live Telemetry (/queue), Results Explorer (/runs, /runs/:runId with tabbed serving/throughput/stress charts, Golden Set, Agentic Quality, and lazy sample_traces), and Compare (/compare). Auto-switches Tier 1 to Remote Endpoint mode and shows Remote-only mode in the header when local serving is unavailable.
  • Container and packaging (deploy/, pyproject.toml, uv.lock, .gitignore): Multi-stage node:22-slim + python:3.12-slim deploy/Dockerfile running as non-root user gbench with GBENCH_WEB_REMOTE_ONLY=true, installing .[web] plus transformers (without torch or vllm) for --remote-endpoint --tokenizer sizing. Adds deploy/Dockerfile.dockerignore, deploy/.env.example, and ignore patterns for .env.*, *.tfvars.json, *.tfplan, **/.gbench_web.sqlite3*, and **/.gbench_web_logs/. Single unforked uv.lock resolve (279 packages).
  • Documentation: Adds docs/web-ui.md and docs/cloud-run.md (parameterized .env workflow, deployer IAM roles, API enablement, Artifact Registry, Secret Manager, GCS, optional IAP setup, verification, and cleanup). Updates README.md, CONTRIBUTING.md (frontend rebuild rule for gbench/web/static/), docs/installation.md, docs/environment-variables.md, docs/deployment.md, and docs/eval-suites.md. Removes obsolete section 8 from docs/evals_roadmap.md.
  • Tests (tests/web/, tests/test_dependency_policy.py): Adds 167 tests covering API routes, queue leasing, log streaming, crash recovery, GCS sync/redaction, security controls, plugin protocols, hosted token mode, and remote-only mode. Updates tests/test_dependency_policy.py to include the web extra and 3-segment google.cloud.<subpkg> matching (google.cloud.storage -> google-cloud-storage).

Verification

  • ruff check gbench/web tests/web: passed (0 errors).
  • npm --prefix web run lint && npm --prefix web run build (Node 22): passed; rebuilt gbench/web/static/ with no stale duplicate hashed bundles.
  • pytest tests/web/: 167 passed.
  • pytest tests/test_dependency_policy.py -k "not test_the_python_legs_match_requires_python_and_the_classifiers": 19 passed, 1 deselected (the single deselected test is pre-existing on main d3e4283, where .github/workflows/test.yml lists Python 3.11/3.12 while pyproject.toml includes classifier 3.13).
  • pytest tests/test_repo_gates_and_shared_docs.py tests/test_roadmap_deregistration_and_base_hooks.py: passed, with zero broken relative links or #8-web-dashboard references.
  • Manual end-to-end checks:
    • Editable install (pip install --no-deps --no-build-isolation -e .), gbench-web, and python -m gbench.web --help all report 0.6.0.
    • Direct local run verified loopback bind (127.0.0.1:8765) and refusal of --host 0.0.0.0 (exit 2).
    • Container build (docker build -f deploy/Dockerfile) verified default 0.0.0.0 refusal without env config, loopback run with bind-mounted results/ via --user "$(id -u):$(id -g)", and hosted token mode (200 on /api/health and matching *.run.app Host, 403 on untrusted Host, 401 unauthenticated /api/jobs, 200 + Set-Cookie + csrf_token on POST /api/auth/session, token omitted from stdout).
    • Live Cloud Run smoke deployment behind native IAP verified IAP-only roles/run.invoker, HTTP 302 redirect for unauthenticated curl, zero secret output in startup logs, HTTPS session gate with Remote-only mode UI auto-switching, and clean teardown of temporary test resources.

Contributor Notes

  • Whenever web/src/ or web/ build config/assets change, run npm --prefix web run lint && npm --prefix web run build before committing so gbench/web/static/ stays in sync (Vite emptyOutDir: true removes stale hashed files automatically).
  • Vanilla Cloud Run hosted token mode uses local SQLite and in-memory sessions; keep --max-instances 1 unless supplying an external StateStore and AuthProvider via GBENCH_WEB_PLUGIN.

- Backend (gbench/web/): add FastAPI server, SQLite WAL job queue with GPU UUID, server port, and Docker subnet leasing, file-backed logs (.gbench_web_logs/), SSE streaming with Last-Event-ID resume, crash-recovery state inference, fail-closed redact_tree() GCS sync, and gbench-web / python -m gbench.web entry points.
- Plugin contract (gbench/web/protocols.py): add PLUGIN_API_VERSION = 1 protocols (AuthProvider, StateStore, JobExecutor, SubmissionPolicy, LogStreamProvider, ArtifactStore, CatalogExtension) loaded explicitly via GBENCH_WEB_PLUGIN (gbench.web.plugins entry-point group) and exposed via GET /api/capabilities.
- Security and hosted mode: refuse non-loopback bind (0.0.0.0) by default unless an external AuthProvider is loaded or both GBENCH_WEB_AUTH_TOKEN (>= 32 chars, env-only, never logged, stripped from child subprocesses) and GBENCH_WEB_ALLOWED_HOSTS (rejecting bare * and single-label wildcards) are set; enforce HttpOnly SameSite=Strict cookies (__Host-gbench_session + Secure + HSTS under GBENCH_WEB_TLS_ENABLED=true), X-GBench-CSRF, Origin/Sec-Fetch-Site checks, a 20 req/min POST /api/auth/session rate limiter, SSRF/path validation, and --remote-only (GBENCH_WEB_REMOTE_ONLY) with vllm/GPU detection returning HTTP 422 on 0-GPU hosts.
- Frontend (web/ -> gbench/web/static/): add React 19 + TypeScript + Vite SPA with Composer (/submit), Queue and Live Telemetry (/queue), Results Explorer (/runs, /runs/:runId), and Compare (/compare); auto-switch to Remote Endpoint mode when local serving is unavailable; commit built assets in gbench/web/static/ so pip install works without Node.js.
- Packaging and container: bump version to 0.6.0 across pyproject.toml, gbench/__init__.py, gbench/web/__init__.py, web/package.json, web/package-lock.json, and uv.lock; add [web] optional extra (fastapi, starlette, uvicorn, google-cloud-storage); add multi-stage Node 22 + python:3.12-slim deploy/Dockerfile (non-root user gbench, GBENCH_WEB_REMOTE_ONLY=true, installs .[web] and transformers without torch or vllm), deploy/Dockerfile.dockerignore, deploy/.env.example, and ignore rules in .gitignore.
- Docs and tests: add docs/web-ui.md, docs/cloud-run.md (parameterized .env setup, IAM/Secret Manager/GCS/optional IAP steps, verification, and teardown), and 167 tests under tests/web/; update README.md, CONTRIBUTING.md, docs/installation.md, docs/environment-variables.md, docs/deployment.md, docs/eval-suites.md, and tests/test_dependency_policy.py (including [web] and 3-segment google.cloud.<subpkg> matching); remove obsolete section 8 from docs/evals_roadmap.md.

Signed-off-by: Luciano Martins <lucianommartins@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant