argus-iris 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. argus_iris-0.1.0/.copier-answers.yml +21 -0
  2. argus_iris-0.1.0/.dockerignore +16 -0
  3. argus_iris-0.1.0/.github/workflows/ci.yml +19 -0
  4. argus_iris-0.1.0/.github/workflows/release.yml +163 -0
  5. argus_iris-0.1.0/.gitignore +18 -0
  6. argus_iris-0.1.0/CLAUDE.md +100 -0
  7. argus_iris-0.1.0/DESIGN.md +400 -0
  8. argus_iris-0.1.0/Dockerfile +23 -0
  9. argus_iris-0.1.0/LICENSE +21 -0
  10. argus_iris-0.1.0/Makefile +27 -0
  11. argus_iris-0.1.0/PKG-INFO +149 -0
  12. argus_iris-0.1.0/README.md +98 -0
  13. argus_iris-0.1.0/compose.yaml +18 -0
  14. argus_iris-0.1.0/deploy/.env.example +35 -0
  15. argus_iris-0.1.0/deploy/agent.compose.yaml +31 -0
  16. argus_iris-0.1.0/deploy/broker.compose.yaml +25 -0
  17. argus_iris-0.1.0/deploy/iris.example.yaml +77 -0
  18. argus_iris-0.1.0/deploy/policy.example.yaml +48 -0
  19. argus_iris-0.1.0/pyproject.toml +85 -0
  20. argus_iris-0.1.0/src/argus_iris/__init__.py +16 -0
  21. argus_iris-0.1.0/src/argus_iris/_version.py +24 -0
  22. argus_iris-0.1.0/src/argus_iris/agent/__init__.py +5 -0
  23. argus_iris-0.1.0/src/argus_iris/agent/app.py +307 -0
  24. argus_iris-0.1.0/src/argus_iris/agent/docker.py +88 -0
  25. argus_iris-0.1.0/src/argus_iris/agent/nvml.py +117 -0
  26. argus_iris-0.1.0/src/argus_iris/agent/procfs.py +82 -0
  27. argus_iris-0.1.0/src/argus_iris/agent/tracker.py +59 -0
  28. argus_iris-0.1.0/src/argus_iris/broker/__init__.py +1 -0
  29. argus_iris-0.1.0/src/argus_iris/broker/actions.py +333 -0
  30. argus_iris-0.1.0/src/argus_iris/broker/adapters/__init__.py +25 -0
  31. argus_iris-0.1.0/src/argus_iris/broker/adapters/base.py +41 -0
  32. argus_iris-0.1.0/src/argus_iris/broker/adapters/comfyui.py +52 -0
  33. argus_iris-0.1.0/src/argus_iris/broker/adapters/http.py +96 -0
  34. argus_iris-0.1.0/src/argus_iris/broker/adapters/ollama.py +53 -0
  35. argus_iris-0.1.0/src/argus_iris/broker/config.py +129 -0
  36. argus_iris-0.1.0/src/argus_iris/broker/leases.py +857 -0
  37. argus_iris-0.1.0/src/argus_iris/broker/policy.py +237 -0
  38. argus_iris-0.1.0/src/argus_iris/broker/residency.py +229 -0
  39. argus_iris-0.1.0/src/argus_iris/broker/state.py +354 -0
  40. argus_iris-0.1.0/src/argus_iris/cli.py +51 -0
  41. argus_iris-0.1.0/src/argus_iris/models.py +160 -0
  42. argus_iris-0.1.0/src/argus_iris/py.typed +0 -0
  43. argus_iris-0.1.0/src/argus_iris/server/__init__.py +1 -0
  44. argus_iris-0.1.0/src/argus_iris/server/app.py +348 -0
  45. argus_iris-0.1.0/src/argus_iris/ui/app.css +168 -0
  46. argus_iris-0.1.0/src/argus_iris/ui/app.js +441 -0
  47. argus_iris-0.1.0/src/argus_iris/ui/index.html +93 -0
  48. argus_iris-0.1.0/src/argus_iris/ui/vendor/dh/dh-theme.js +143 -0
  49. argus_iris-0.1.0/src/argus_iris/ui/vendor/dh/dh-tokens.css +196 -0
  50. argus_iris-0.1.0/tests/test_actions.py +221 -0
  51. argus_iris-0.1.0/tests/test_admission.py +437 -0
  52. argus_iris-0.1.0/tests/test_agent.py +182 -0
  53. argus_iris-0.1.0/tests/test_broker.py +298 -0
  54. argus_iris-0.1.0/tests/test_evict.py +238 -0
  55. argus_iris-0.1.0/tests/test_leases.py +436 -0
  56. argus_iris-0.1.0/tests/test_policy.py +383 -0
  57. argus_iris-0.1.0/tests/test_procfs.py +52 -0
  58. argus_iris-0.1.0/tests/test_smoke.py +8 -0
  59. argus_iris-0.1.0/tests/test_tracker.py +56 -0
  60. argus_iris-0.1.0/tests/test_ui.py +58 -0
@@ -0,0 +1,21 @@
1
+ # Managed by Copier — do not edit by hand.
2
+ # Run `copier update` in this repo to pull template changes.
3
+ _commit: 939debb
4
+ _src_path: https://github.com/smk762/argus-pkg-template.git
5
+ author: smk762
6
+ cli_name: argus-iris
7
+ description: 'VRAM-aware GPU lease broker for the Argus suite: priorities, schedules,
8
+ keepalive and idle-kill across GPU nodes'
9
+ dockerfile: Dockerfile
10
+ github_owner: smk762
11
+ has_cli: true
12
+ has_server: true
13
+ image_name: argus-iris
14
+ package_name: argus_iris
15
+ post_test: ''
16
+ project_name: argus-iris
17
+ python_min: '3.11'
18
+ ruff_pin: 0.15.16
19
+ test_extras: dev
20
+ version_build_arg: false
21
+
@@ -0,0 +1,16 @@
1
+ # NOTE: .git is deliberately *not* ignored -- hatch-vcs reads the version from
2
+ # git history at build time. Set `version_build_arg` if you want it excluded.
3
+ .github
4
+ .venv
5
+ venv
6
+ dist
7
+ build
8
+ *.egg-info
9
+ **/__pycache__
10
+ **/*.py[cod]
11
+ .pytest_cache
12
+ .ruff_cache
13
+ .mypy_cache
14
+ .coverage
15
+ htmlcov
16
+ .env
@@ -0,0 +1,19 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [dev, main]
6
+ pull_request:
7
+ branches: [dev, main]
8
+
9
+ concurrency:
10
+ group: ci-${{ github.ref }}
11
+ cancel-in-progress: true
12
+
13
+ jobs:
14
+ ci:
15
+ uses: smk762/argus-ci/.github/workflows/python-ci.yml@v1
16
+ with:
17
+ ruff-version: "0.15.16"
18
+ test-extras: "dev"
19
+
@@ -0,0 +1,163 @@
1
+ name: Release to PyPI
2
+
3
+ # Top-level (non-reusable) on purpose: PyPI trusted publishing cannot run inside
4
+ # a reusable workflow. Keep this file in sync across the suite via `copier update`.
5
+
6
+ on:
7
+ push:
8
+ tags: ["v*"]
9
+ # Sent by argus-cortex's release workflow. The image installs argus-cortex
10
+ # from the pyproject range at build time, so rebuilding the newest release's
11
+ # image is how a new cortex reaches it. Only the image jobs run: PyPI and the
12
+ # GitHub Release for that tag already exist.
13
+ repository_dispatch:
14
+ types: [cortex-released]
15
+
16
+ permissions:
17
+ contents: read
18
+ id-token: write
19
+
20
+ jobs:
21
+ build:
22
+ # Not on a cortex dispatch, so the PyPI and Release jobs that chain off it
23
+ # skip too.
24
+ if: github.event_name == 'push'
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+ with:
29
+ fetch-depth: 0
30
+ - uses: astral-sh/setup-uv@v6
31
+ with:
32
+ enable-cache: true
33
+ - run: uv build
34
+ - uses: actions/upload-artifact@v4
35
+ with:
36
+ name: dist
37
+ path: dist/
38
+
39
+ test-install:
40
+ runs-on: ubuntu-latest
41
+ needs: build
42
+ strategy:
43
+ matrix:
44
+ python-version: ["3.11", "3.12"]
45
+ steps:
46
+ - uses: actions/download-artifact@v4
47
+ with:
48
+ name: dist
49
+ path: dist/
50
+ - uses: astral-sh/setup-uv@v6
51
+ with:
52
+ enable-cache: true
53
+ - name: Install wheel and smoke-test import
54
+ run: |
55
+ uv venv --python ${{ matrix.python-version }}
56
+ uv pip install dist/*.whl
57
+ uv run --no-sync python -c "import argus_iris; print(f'argus-iris {argus_iris.__version__} OK')"
58
+
59
+ publish-testpypi:
60
+ runs-on: ubuntu-latest
61
+ needs: test-install
62
+ environment: testpypi
63
+ steps:
64
+ - uses: actions/download-artifact@v4
65
+ with:
66
+ name: dist
67
+ path: dist/
68
+ - uses: pypa/gh-action-pypi-publish@release/v1
69
+ with:
70
+ repository-url: https://test.pypi.org/legacy/
71
+
72
+ publish-pypi:
73
+ runs-on: ubuntu-latest
74
+ # Ordered *after* the TestPyPI rehearsal so its outcome is visible first, but
75
+ # deliberately not gated on it. A TestPyPI-only fault — a missing trusted
76
+ # publisher, an index outage — must not silently withhold the real release:
77
+ # that failure mode shipped argus-proof images for two tags with no wheel on
78
+ # PyPI, and nothing surfaced it because publish-image is independent.
79
+ # Only the build + install gate is required; a TestPyPI failure still marks
80
+ # the whole run failed, so the problem stays loud.
81
+ needs: [test-install, publish-testpypi]
82
+ if: "!cancelled() && needs.test-install.result == 'success'"
83
+ environment: pypi
84
+ steps:
85
+ - uses: actions/download-artifact@v4
86
+ with:
87
+ name: dist
88
+ path: dist/
89
+ - uses: pypa/gh-action-pypi-publish@release/v1
90
+
91
+ release-tag:
92
+ # The tag the image jobs build: the pushed one, or on a cortex dispatch the
93
+ # newest final release. A pre-release never moved `latest`, so a dispatch
94
+ # does not rebuild one.
95
+ runs-on: ubuntu-latest
96
+ outputs:
97
+ tag: ${{ steps.tag.outputs.tag }}
98
+ sha: ${{ steps.tag.outputs.sha }}
99
+ steps:
100
+ - uses: actions/checkout@v4
101
+ if: github.event_name == 'repository_dispatch'
102
+ - id: tag
103
+ env:
104
+ CORTEX_VERSION: ${{ github.event.client_payload.version }}
105
+ run: |
106
+ if [ "$GITHUB_EVENT_NAME" != repository_dispatch ]; then
107
+ echo "tag=$GITHUB_REF_NAME" >> "$GITHUB_OUTPUT"
108
+ echo "sha=$GITHUB_SHA" >> "$GITHUB_OUTPUT"
109
+ exit 0
110
+ fi
111
+ refs=$(git ls-remote --tags origin 'refs/tags/v*')
112
+ tag=$(echo "$refs" | sed -n 's|.*refs/tags/\(v[0-9]*\.[0-9]*\.[0-9]*\)\(\^{}\)\{0,1\}$|\1|p' | sort -uV | tail -n1)
113
+ if [ -z "$tag" ]; then
114
+ echo "::notice::No release tag yet, so no image to rebuild for cortex $CORTEX_VERSION."
115
+ exit 0
116
+ fi
117
+ # An annotated tag lists its commit on the peeled ^{} line.
118
+ sha=$(echo "$refs" | awk -v t="refs/tags/$tag" '$2 == t {l = $1} $2 == t "^{}" {p = $1} END {print p ? p : l}')
119
+ echo "Rebuilding $tag ($sha) for cortex $CORTEX_VERSION."
120
+ echo "tag=$tag" >> "$GITHUB_OUTPUT"
121
+ echo "sha=$sha" >> "$GITHUB_OUTPUT"
122
+
123
+ publish-image:
124
+ runs-on: ubuntu-latest
125
+ needs: [release-tag, test-install]
126
+ # On a cortex dispatch test-install is skipped (nothing was built for PyPI),
127
+ # so the job runs on the tag alone.
128
+ if: "!cancelled() && needs.release-tag.outputs.tag != '' && (needs.test-install.result == 'success' || github.event_name == 'repository_dispatch')"
129
+ permissions:
130
+ contents: read
131
+ packages: write
132
+ steps:
133
+ - uses: actions/checkout@v4
134
+ with:
135
+ ref: ${{ needs.release-tag.outputs.tag }}
136
+ fetch-depth: 0 # hatch-vcs reads the tag from git history
137
+ - uses: docker/setup-buildx-action@v3
138
+ - uses: docker/login-action@v3
139
+ with:
140
+ registry: ghcr.io
141
+ username: ${{ github.actor }}
142
+ password: ${{ secrets.GITHUB_TOKEN }}
143
+ - id: meta
144
+ uses: docker/metadata-action@v5
145
+ with:
146
+ images: ghcr.io/${{ github.repository_owner }}/argus-iris
147
+ labels: org.opencontainers.image.revision=${{ needs.release-tag.outputs.sha }}
148
+ tags: |
149
+ type=semver,pattern={{version}},value=${{ needs.release-tag.outputs.tag }}
150
+ type=semver,pattern={{major}}.{{minor}},value=${{ needs.release-tag.outputs.tag }}
151
+ type=raw,value=latest
152
+ - uses: docker/build-push-action@v6
153
+ with:
154
+ context: .
155
+ file: ./Dockerfile
156
+ push: true
157
+ tags: ${{ steps.meta.outputs.tags }}
158
+ labels: ${{ steps.meta.outputs.labels }}
159
+ # A dispatch rebuilds an unchanged context, so a cached install layer
160
+ # would keep the old argus-cortex.
161
+ no-cache: ${{ github.event_name == 'repository_dispatch' }}
162
+ cache-from: type=gha
163
+ cache-to: type=gha,mode=max
@@ -0,0 +1,18 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+ # hatch-vcs writes this at build time (version derived from git tags)
10
+ src/argus_iris/_version.py
11
+
12
+ # Local secrets (see deploy/.env.example)
13
+ .env
14
+ deploy/iris.yaml
15
+ deploy/policy.yaml
16
+ .env.*
17
+ !.env.example
18
+ deploy/*.bak-*
@@ -0,0 +1,100 @@
1
+ # CLAUDE.md — argus-iris
2
+
3
+ Guidance for AI agents working in this repo. Human-facing usage lives in [README.md](README.md); this file is the orientation an agent needs to change code safely.
4
+
5
+ > Scaffolded from [`argus-pkg-template`](https://github.com/smk762/argus-pkg-template). Flesh out **Layout** and **Gotchas** below as the code grows — the suite conventions are already correct and shared.
6
+
7
+ ## What this is
8
+
9
+ VRAM-aware GPU lease broker for the Argus suite: priorities, schedules, keepalive and idle-kill across GPU nodes
10
+
11
+ It decides whether a GPU job may start now, on which node (morpheus, dragon, jarrah), and what must be unloaded first. It does not run the work. **[DESIGN.md](DESIGN.md) is the plan the first releases build to; read it before changing anything.** The client (`BrokerCoordinator`) and the lease and tenant-manifest wire models live in argus-cortex's `gpu` module, so callers and broker share one definition.
12
+
13
+ ## Argus suite
14
+ <!-- argus-suite: keep this block; argus-ci checks for it -->
15
+ This repo is part of the Argus suite. The suite map below lists every sibling and what it owns; check it before
16
+ building something a sibling may already do. **On every release, update this repo's row and capabilities in
17
+ argus-cortex's SUITE.md** (a PR to argus-cortex in the same release).
18
+
19
+ @../argus-core/SUITE.md
20
+
21
+ Not checked out? Read https://github.com/smk762/argus-cortex/blob/dev/SUITE.md
22
+
23
+ ## Layout
24
+
25
+ `src/argus_iris/` — the package. Rollout step 3: leases, placement and admission (`admission: observe` grants
26
+ everything and records `fits`; `enforce` queues, spills and evicts). Step 4's residency policy (`policy.py`, `residency.py`) is report-only per rule until `enforce: true`.
27
+
28
+ - `models.py` — agent snapshot (`NodeSnapshot`, `GpuProcess`, …) and the broker's read models (`NodeState`,
29
+ `Resident`, `NodeLedger`). Lease and tenant-manifest models are **not** here: import them from
30
+ `argus_cortex.gpu_wire`.
31
+ - `agent/` — `iris-agent` (`[agent]` extra, `argus-iris agent`, :9110). `nvml.py` samples, `tracker.py` keeps idle
32
+ time (VRAM unchanged **and** no utilisation), `procfs.py` maps PIDs to containers through cgroups and reads anon
33
+ memory, `docker.py` is a minimal Engine API client over the Unix socket, `app.py` serves `/snapshot`, `/metrics`,
34
+ `/health` and token- and allowlist-gated `POST /containers/{name}/{start|stop|restart}`.
35
+ - `broker/` — `config.py` (YAML, `IRIS_CONFIG`), `adapters/` (comfyui, ollama, argus-http; read-only),
36
+ argus-http validates `/health` as cortex's `ResidentHealth` and reads older shapes best-effort, logging
37
+ `resident_off_contract` (and `detail.off_contract` on the resident); a truthy non-bool `busy` counts as busy,
38
+ `state.py` (`Broker` polls agents and adapters, ticks the lease book every second; `compose_node` is the pure
39
+ accounting), `leases.py` (`LeaseBook`: tenants, `candidates()` (placement order), admission (`_serve_queue`: class order
40
+ with aging, head reservation, spill, `_plan` eviction plans run by the broker's `_evict_for`), request_id idempotency, `resume`,
41
+ heartbeat/TTL expiry (a beat also carries `progress`/`stage`, published to `/events` when they change), the 30 s first-beat reclaim, the stall watchdog (`_watch`: heartbeating with no GPU activity for `lease_stall_s` -> `stalled_at`, `yield_requested` while it blocks the queue, reclaimed as `refused` only with `lease_stall_reclaim`), unpolled-queue drop; synchronous with an injectable clock, so test
42
+ it by moving the clock and calling `tick()`), `policy.py` (the operator's YAML: cron, windows, resident rules; `IRIS_POLICY`), `residency.py` (`Residency`:
43
+ per-resident `ResidentPolicy` view on every poll, `step()` acts on enforced rules: pin/extend Ollama keep_alive,
44
+ idle-kill evict, `unload_after` (CPU stage -> unloaded; confirmed by the reply, since only RAM moves), restart
45
+ when unloaded (never merely on the CPU) but holding `restart_residual_mb`, or idle `restart_host_ram_idle` with
46
+ container anon memory (`Resident.host_ram_mb`) over `restart_host_ram_mb` (default: the manifest's
47
+ `host_ram_restart_mb`); `Broker.residuals` remembers what an
48
+ eviction left so it is not repeated), `actions.py` (warm: 409 unless `force` while the node cannot admit `warm_mb` or the most it was seen holding, `Broker.peaks`; agent starts the container, wait for health, call `warm_path`;
49
+ `evict_resident`: adapter route per source, 409 while busy, confirmed by the GPU's NVML free memory rising by half
50
+ the resident's VRAM, not by the service's word; reports `residual_mb`).
51
+ - `server/app.py` — the broker API (`[server]` extra, `argus-iris serve`, :8120): `/nodes`, `/residents`, `/events`
52
+ (SSE: `node` and `lease` events), `/metrics`, `/health`, `/ui/`, the lease routes (`POST /tenants`, `POST /leases`,
53
+ `GET /leases/{id}?wait_s=`, `.../heartbeat`, `.../release`, `GET /leases`, `/queue`, `/tenants`; bearer token
54
+ checked only when `ARGUS_GPU_BROKER_TOKEN` is set) `POST /services/{id}/warm` and `POST /residents/{id}/evict` (resident ids contain slashes; both need that token). Wrapped in
55
+ cortex's `WriteGuard`. Test the lease routes with cortex's own `BrokerCoordinator` over `httpx.ASGITransport`.
56
+ - `ui/` — the dashboard, served by the broker at `/ui/` (`/` redirects). Plain HTML and ES modules with no build
57
+ step, shipped in the wheel (the pattern argus-mask and argus-survey use). It is a thin client over `/health`,
58
+ `/config` and `/events`, and the warm POST, so it never computes what the broker decides. `vendor/dh/` holds
59
+ `dh-tokens.css` and `dh-theme.js`, copied unchanged from dh-shared 1.2.7 (via argus-mask): **never edit them**.
60
+ Re-copy them from a newer sync instead. Colours come from `--dh-*` tokens only.
61
+ - `cli.py` — Typer app; entry point `argus-iris` (`serve`, `agent`, `version`).
62
+ - `compose.yaml` includes `deploy/broker.compose.yaml` and `deploy/agent.compose.yaml` with `deploy/.env` (project
63
+ `argus-iris`); `deploy/` — example broker config, policy, and the compose files for the broker and the agents.
64
+
65
+ ## Commands
66
+
67
+ ```bash
68
+ make install # uv venv + editable install with the "dev" extras
69
+ make test # pytest --tb=short -q
70
+ make lint # ruff check + format --check (pinned ruff 0.15.16)
71
+ make format # ruff format + --fix
72
+ ```
73
+
74
+ Run one test: `uv run --no-sync pytest tests/test_x.py::test_name -q`.
75
+
76
+ ## Conventions & gotchas
77
+
78
+ - **Versioning is git-tag-derived** (`hatch-vcs`). Never hand-edit a version; `src/argus_iris/_version.py` is generated (gitignored). Tag `vX.Y.Z` to release.
79
+ - **`src/` layout, `py.typed`, Pydantic v2, `structlog`.** Ruff line-length 120; keep it clean (`make lint`) before committing.
80
+ - **Any endpoint that does something is a boundary.** There's no auth by default — treat reaching the port as host access. Gate state-changing routes behind the shared read-only / origin guards, and fence any caller-supplied path under a configured root.
81
+ - Wire schemas (if any) are checked in and verified in CI — regenerate and commit when the types change, don't let the committed copy drift.
82
+ - **Ports:** a2f holds :8110 on morpheus, so the broker is :8120; the agent is :9110 (gothmog's exporter used :9101).
83
+ - **The agent is root-equivalent** (Docker socket, `pid: host`). Container actions stay behind `IRIS_AGENT_TOKEN`
84
+ **and** the agent's own `IRIS_AGENT_CONTAINERS` allowlist; never let broker config or a POSTed manifest widen it.
85
+ - **Memory is MiB** everywhere (`*_mb`), times are aware UTC.
86
+ - **Don't 4xx for "busy"** on lease routes: cortex's client treats any 4xx other than 404 as a caller error. Busy is
87
+ `queued`.
88
+
89
+ ## Branches
90
+
91
+ `dev` is the default branch and the base for every PR, as in the rest of the suite. Cut feature branches from
92
+ `origin/dev` and bring them up to date by merging `origin/dev`, never `main`. Never push work to `main` or open a PR
93
+ against it, except the release PR from `dev`: `main` must never be ahead of `dev`. A release fast-forwards `main` to a
94
+ `dev` commit that passed CI (`git push origin origin/dev:main`), then tags `vX.Y.Z` on it. If `main` is protected, the
95
+ release is a reviewed PR from `dev` into `main`; its merge commit is the one thing `main` may have that `dev` lacks
96
+ (same tree). Leave it there and don't merge `main` back into `dev`.
97
+
98
+ ## CI / release
99
+
100
+ CI runs via the shared [`argus-ci`](https://github.com/smk762/argus-ci) reusable workflow. Release publishes to PyPI (OIDC trusted publishing) + GHCR on `v*` tags. Run `copier update` to pull template (CI/release/tooling) changes.