Make aggregate ONNX gates execute for real
Reference-count the process-global ONNX Runtime across embedder and routing-head sessions, make close idempotent, and require named proof that both aggregate routing gates executed rather than self-skipped (V-716). Owner explicitly requested direct commits to master.
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
# ONNX aggregate gate lifecycle — 2026-08-13
|
||||
|
||||
Vikunja: V-716.
|
||||
|
||||
## Finding
|
||||
|
||||
`router.NewONNXEmbedder` initialized `onnxruntime_go` unconditionally. Its
|
||||
`Close` method destroyed the model session but left the package-global runtime
|
||||
environment alive. In one Go process the first `TestONNX*` therefore ran and
|
||||
every later constructor returned `The onnxruntime has already been initialized`.
|
||||
Those tests converted the constructor error into `t.Skip`, so the aggregate
|
||||
package still reported `PASS`.
|
||||
|
||||
Reproduction before the fix:
|
||||
|
||||
```text
|
||||
TestONNXBaseline PASS classifier+onnx 72/96
|
||||
TestONNXRoutingHeads SKIP onnx: init environment: already initialized
|
||||
package PASS
|
||||
```
|
||||
|
||||
## Contract
|
||||
|
||||
The router now owns ONNX Runtime through reference-counted leases. Every model
|
||||
session holds one lease; routing heads hold their own, so daemon shutdown order
|
||||
cannot unload the library underneath a live graph. The last lease destroys an
|
||||
environment Maven initialized. Package `TestMain` holds one extra lease across
|
||||
all model-aware tests in `internal/router/eval` and `cmd/mavend`.
|
||||
|
||||
The aggregate router command additionally requires two named gates to record
|
||||
execution only after all of their model dependencies loaded. A second-test
|
||||
skip can no longer satisfy the command.
|
||||
|
||||
## Measurement
|
||||
|
||||
Runtime and model:
|
||||
|
||||
```text
|
||||
deps/onnxruntime-linux-x64-1.26.0/lib/libonnxruntime.so.1.26.0
|
||||
models/embedder/multilingual-e5-small/model_quantized.onnx
|
||||
models/embedder/router-heads/router_heads.onnx
|
||||
```
|
||||
|
||||
Focused aggregate, one process:
|
||||
|
||||
```text
|
||||
TestONNXBaseline PASS 72/96 full (75.0%), destination 11/33
|
||||
TestONNXRoutingHeads PASS 93/96 full (96.9%), destination 25/33
|
||||
ONNX aggregate proof: verified 2 required model gates:
|
||||
[TestONNXBaseline TestONNXRoutingHeads]
|
||||
```
|
||||
|
||||
The separate lifecycle test released the last lease and successfully acquired
|
||||
the runtime again. A second same-process package run also executed all three
|
||||
selected mavend gates without a skip:
|
||||
|
||||
```text
|
||||
TestONNXPersonalBoundary PASS 29/29
|
||||
TestONNXPersonalBoundaryFourFold PASS 99/104
|
||||
TestONNXTopics PASS 43/43
|
||||
```
|
||||
|
||||
Finally, `make eval-router` completed the full package. In addition to the two
|
||||
required proof gates, `TestONNXClaimConfidenceDistribution` and
|
||||
`TestReachBaselineONNX` executed; ecosystem reach remained 28/30.
|
||||
@@ -110,6 +110,7 @@ A pair in `docs/routing.md` went stale unnoticed. Its source predated the
|
||||
|
||||
| measurement | state |
|
||||
| --- | --- |
|
||||
| [Both ONNX routing gates execute in one process](2026-08-13-onnx-runtime-lifecycle.md) | live |
|
||||
| [Where the resident model's 7.9GB of RSS goes](2026-08-03-llama-prompt-cache.md) | live |
|
||||
| [Does one sqlite connection make reads queue? No](2026-08-07-store-connection-cap.md) | live |
|
||||
|
||||
|
||||
+17
@@ -301,6 +301,23 @@ make eval-recall
|
||||
|
||||
A large miss against 72.7% means the deploy differs from the bench harness.
|
||||
|
||||
`make eval-router` is also the aggregate ONNX lifecycle gate. When the default
|
||||
runtime path is non-empty it requires both `TestONNXBaseline` and
|
||||
`TestONNXRoutingHeads` to load their models and execute in the same Go process.
|
||||
The final line names both verified gates. A later test that skips because the
|
||||
first one consumed the process-global runtime now makes the command fail rather
|
||||
than leaving a green package result. To exercise the proof directly:
|
||||
|
||||
```sh
|
||||
MAVEN_ONNX_LIB="$PWD/deps/onnxruntime-linux-x64-1.26.0/lib/libonnxruntime.so" \
|
||||
MAVEN_ONNX_REQUIRED_GATES=2 \
|
||||
go test -v -count=1 \
|
||||
-run '^(TestONNXBaseline|TestONNXRoutingHeads)$' ./internal/router/eval/
|
||||
```
|
||||
|
||||
Set `MAVEN_ONNX_LIB=` explicitly when the intended measurement is the portable
|
||||
hash floor; that also disables the aggregate ONNX requirement.
|
||||
|
||||
**Run on 02-08-2026 @ af9d213. The deploy matches the bench.** `eval-models`
|
||||
scored 56 of 77: 72.7% full, 77.9% intent-only, 2 false clarifies and 1 missed.
|
||||
That is the recorded figure to the decimal, and calendar sat at 2 of 2, so the
|
||||
|
||||
Reference in New Issue
Block a user