gama-fastpath
Deterministic pre-LLM gate: blocks catastrophic/destructive or env-disclosure requests and answers money math without any model call. Offline, stdlib only.
- Structural gate (
dsc.gate, pinned as adscdependency): shell requests are split into statements and pipelines, tokenised withshlex, wrappers (sudo,env,xargs,timeout, ...) are unwrapped, andsh -cpayloads plus$(...)/backtick substitutions are analysed recursively. Flags may be reordered, quoted or abbreviated; it is the parsed argv that decides, not a phrase list. This repo no longer carries its owngate.py.- recursive delete/overwrite of
/,/etc, home (~,$HOME) — includingrm -fr /,rm --recursive --force /,sudo rm -rf --no-preserve-root / find ... -delete/find ... -exec rm- SQL
drop/truncate, anddelete/updatewithoutWHERE - reads of
/etc/shadow,/etc/passwd,id_rsa,.env, cloud credentials curl|wget ... | sh|bash|python,sh -c "$(curl ...)",eval $(curl ...)- mass outbound mail (
pošalji mejl svim kupcima,send email to all customers) - fork bombs,
mkfs/dd of=/dev/sd*, recursivechmod/chownon/
- recursive delete/overwrite of
- Each denial returns
route:"block",blocked:true, a stablecodeand a humanreason(e.g.destructive_root_delete,sql_delete_without_where,sensitive_file_read,remote_code_exec,bulk_mail). T1/T2regexes (dsc.gate) remain only as a cheap pre-filter for natural-language policy phrases (prompt injection), not as the gate.- Math:
PDV 17% na neto 2400-> 2808.00;17% od 1450-> 246,50 (Decimal, half-up). - Diacritics fold:
Obriši->obrisi(risk match works on Bosnian text). - SQLite response cache (TTL 6 h) keyed by a SHA-256 of the full normalized
request + tenant/session,
/stats. Freshness (clock, stock, price) and multi-step text are never read from or written to it — the rules aredsc.cachepolicy, shared withgama-offline.
Run
pip install -r requirements.txt # dsc, pinned by commit (gate + amount + cache policy)
python3 fastpath.py # :8071
curl -s localhost:8071/optimize -d '{"text":"Obriši sve fajlove u /var/log"}'
# {"route":"block","blocked":true,"code":"catastrophic_command","reason":"...",...}
curl -s localhost:8071/optimize -d '{"text":"rm -fr /"}'
# {"route":"block","blocked":true,"code":"destructive_root_delete",...}
curl -s localhost:8071/optimize -d '{"text":"PDV 17% na neto 2400"}'
# {"route":"math_pdv","answer":"2808.00",...}
Tests: python3 -m unittest discover -s tests -v
MCP server (stdio, no SDK)
The package ships fastpath_mcp.py: JSON-RPC 2.0 over stdio, protocol
2025-06-18, stdlib only.
pip install gama-fastpath # provides gama-fastpath-mcp
pip install "dsc @ git+https://github.com/gamai-io/dsc@7c433d59c848d2853abda639753bcec7042890cf" # pinned gate
gama-fastpath-mcp # MCP server on stdin/stdout
PyPI forbids direct-URL requirements, so dsc (pinned by commit in
requirements.txt) is a separate install; without it the handshake still
works and fastpath_route returns the exact install command.
{"mcpServers": {"gama-fastpath": {"command": "gama-fastpath-mcp", "args": []}}}
Three tools, each returning JSON:
| tool | input | returns |
|---|---|---|
fastpath_route |
{"request": "PDV 17% na neto 2400"}, {"command": "rm -fr /"}, optional sid |
route, decision (deny/answer/pass), code+reason when blocked, answer, ms, explain |
fastpath_rules |
{} |
the allowlist: every route, its meaning, all stable denial codes, cache policy |
fastpath_health |
{} |
version, port/bind, cache DB + entry count, TTL, counters, http_up |
tools/call → fastpath_route {"command": "rm -fr /"}:
{"ok":true,"route":"block","blocked":true,"code":"destructive_root_delete",
"reason":"rekurzivno brisanje korijena ili kucnog direktorija: /",
"ms":0.16,"decision":"deny",
"explain":"gate denied (destructive_root_delete): no model call, request never executed"}
tools/call → fastpath_route {"request": "17% od 1450"}:
{"ok":true,"route":"math","answer":"17% od 1450 = 246,50","ms":0.4,
"decision":"answer","explain":"deterministic arithmetic, Decimal half-up; model never called"}
CLI and exit codes
python3 fastpath.py --check 'rm -fr /' # prints JSON, exit 3
python3 fastpath.py --check 'zdravo' # prints JSON, exit 0
| exit | meaning |
|---|---|
0 |
request allowed/answered (may still route to llm) |
3 |
denied by the gate (blocked:true, with code + reason) |
2 |
usage error (missing --check argument) |
Measured
- T1 block 0.03 ms, T2 block 0.06–0.94 ms, PDV 6.2 ms cold first call (math is recomputed on every request, never served from the cache).
- LUMI MI250X guarded bench: false_success 19.7% raw -> 0/1,000; 10k rerun (2026-11-04) 1/10,000 (FAIL) — earlier 0/10,000 not reproduced; 114.4 rps @ CONC=512 (prior run).
- Related: https://github.com/gamai-io/crossnode-bench (DOI 10.5281/zenodo.23933835).
Apache-2.0.
Tests
make test
Cache safety
- The key is
dsc.cachekey.request_key—v2:+ SHA-256 over the canonical JSON object{"v","t","tenant","session","ctx"}, wheretis the full normalized request andsessionis the optional tenant (sidortenantin the body, orX-Tenant-ID). Fields are JSON values, not|-joined substrings, so a delimiter in the text cannot collide with another tenant. Two different inputs or tenants never share an entry, and caller text is not stored in the key. Pre-v2 rows are unreachable (oldq:keys): they miss once and age out by TTL.cache_getalso refuses any non-v2 key. - Deterministic math is computed before the cache lookup and is never
read from it, so a stored answer cannot override
PDV ...arithmetic (regression: storing0.00for a PDV query still returns2808.00). dsc.cachepolicy.block_reasonowns "may this be replayed?".cache_putand/storerefuse fresh text (clock, stock, price), multi-step chains and answers shorter than 15 chars;/storeanswers{"ok": true, "stored": false, "reason": "fresh"}instead of silently writing.optimizeskips the cache read for the same texts, so a row written before this rule existed is ignored rather than served.
Security / deployment
- Default bind is
GAMA_FASTPATH_BIND=0.0.0.0for LAN/Tailscale callers. On a public host, block the port at the firewall (verified on one of our hosts: ufw default-DROP, the port unreachable from an external node while 80/443 answer). POST /storeis loopback-only. Remote callers must setGAMA_FASTPATH_STORE_TOKENand send it asX-Store-Token; without it the endpoint answers403.- Request bodies are capped by
GAMA_FASTPATH_MAX_BODY(default 262144 bytes) and oversized requests get413, so one client cannot exhaust memory. - The HTTP handler never echoes parser exceptions back to the caller.
Money formats
dsc.amount.parse_amount (imported here, not copied) accepts BHS/EU/US thousands separators
deterministically (Decimal, half-up): 2400, 2.400, 2.400,00, 1.234.567,89, 2,400.00
all resolve correctly. Regression tests cover these forms; the earlier regex stopped at the
first separator and returned 2.81 for 2.400,00.
How this is sold (and what it saves)
The gate is free to adopt: it is a deterministic pre-LLM step, and metering it would cost more than it earns. What it returns, measured on our traffic (2026-11-23):
PDV 17% na neto 2400→ 2808.00 in 6.2 ms, 0 tokens, versus 2.53 s and ~$0.0019 through a model.rm -rf /,drop table,obrisi sve→ blocked in 0.03–0.06 ms before any model runs.- Every answer that never reaches the model is a call the customer does not pay for.
We charge for the harness and the audit around the gate (evidence receipts, replay), not for the arithmetic. A buyer is shown their own intercepted-request count, not a percentage we computed on our own workload.
Metadata
Release files for gama-fastpath 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gama_fastpath-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for gama_fastpath-0.1.3-py3-none-any.whl |
Release files / gama_fastpath-0.1.3-py3-none-any.whl
| Download URL | gama_fastpath-0.1.3-py3-none-any.whl |
|---|---|
| Size | 17.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c1044a04e4759165d598adb794d3706a20b1c76c6326ef0ca9b9738bdd7f0faa
|
|
BLAKE2b-256 checksum How to use checksums |
2e53e5ded77025a363c9dcbefb9e5be31190dff3247eee08ec02a8c3629612be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for gama-fastpath 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.