Skip to content

Manual Environment - #610

Merged
decahedron1 merged 5 commits into
mainfrom
manual-env
Aug 23, 2026
Merged

decahedron1 merged 5 commits into
mainfrom
manual-env

Conversation

@decahedron1

Copy link
Copy Markdown
Member
-ort::init().commit();
+let env = ort::init().build()?;
 
-let mut session = Session::builder()?
+let mut session = Session::builder(&env)?
     .commit_from_file("model.onnx")?;

@decahedron1
decahedron1 merged commit 02b1313 into main Aug 23, 2026
37 checks passed
@decahedron1
decahedron1 deleted the manual-env branch August 23, 2026 20:46
dariofinardi added a commit to dariofinardi/gliner2-rs that referenced this pull request Aug 25, 2026
Runtimes below 1.23 run correctly and then segfault when the process
exits: exit 139, after main returns, with complete and byte-identical
output. Measured with one binary against three runtimes - 1.20.0 and
1.22.0 crash, 1.23.2 does not.

Not this crate, and not the CUDA EP: it reproduces on CPU in twenty
lines of ort with no GLiNER code, needs a session that is actually
dropped rather than leaked, and happens with one intra-op thread as
readily as four. The cause is ort's global Environment being released at
exit after the session state it refers to is gone.

Fixed upstream by pykeio/ort#610, which makes the environment manual;
verified that ort from git exits cleanly even against 1.20.0. That change
is not in rc.13, so until it ships the runtime version is what decides
it. Reported with the measurements as pykeio/ort#614.

Worth stating because nothing warns you: ORT_API_VERSION is 17 and old
runtimes satisfy it, so the library loads without complaint and the
crash carries no hint that the .so is the problem.
dariofinardi added a commit to dariofinardi/gliner25-rs that referenced this pull request Aug 25, 2026
Runtimes below 1.23 run correctly and then segfault when the process
exits: exit 139, after main returns, with complete and byte-identical
output. Measured with one binary against three runtimes - 1.20.0 and
1.22.0 crash, 1.23.2 does not.

Not this crate, and not the CUDA EP: it reproduces on CPU in twenty
lines of ort with no GLiNER code, needs a session that is actually
dropped rather than leaked, and happens with one intra-op thread as
readily as four. The cause is ort's global Environment being released at
exit after the session state it refers to is gone.

Fixed upstream by pykeio/ort#610, which makes the environment manual;
verified that ort from git exits cleanly even against 1.20.0. That change
is not in rc.13, so until it ships the runtime version is what decides
it. Reported with the measurements as pykeio/ort#614.

Worth stating because nothing warns you: ORT_API_VERSION is 17 and old
runtimes satisfy it, so the library loads without complaint and the
crash carries no hint that the .so is the problem.
ianshank pushed a commit to ianshank/FORGE that referenced this pull request Aug 28, 2026
…ndled)

A routine Dependabot bump (ort rc.12 -> rc.13, a7b078c) silently broke
this entire feature surface -- invisible because no CI job built it.
Confirmed the actual break first-hand (not the deep ABI/toolchain
conflict the existing docs described): 5 mechanical lines in
onnx_model.rs against ort 2.0.0-rc.13's actual API:

- try_extract_raw_tensor -> try_extract_tensor (renamed)
- ort::inputs![...] no longer returns a Result -- removed the stray `?`
  after each of the 3 call sites
- Session::run now needs &mut self -- the three session-holding locals
  are now `let mut session = ...`
- ort/std must be enabled explicitly for SessionBuilder::commit_from_file
  to exist at all (previously implicit; default-features = false on the
  base ort dependency turned it off as collateral)

Also fixed a genuinely pre-existing bug this surfaced: onnx_integration.rs
was missing `use std::process::Command`, uncaught for the same reason.

Verified end-to-end, not just compiled: bootstrapped a real MuZero bundle
via the Python export pipeline, loaded it through OnnxMuZeroModel, and
ran real MCTS inference via LatentMctsSearch -- all 124 forge-agent unit
tests plus the full integration test pass. Found and fixed a second,
separate issue in the process: ONNX Runtime <1.23.2 hits a known upstream
ort rc.13 teardown segfault on process exit under load-dynamic
(pykeio/ort#614, fixed in the runtime by pykeio/ort#610) -- reproduced
locally, confirmed 1.23.2 resolves it. Bumped
docker/mc-runner.Dockerfile's ONNXRUNTIME_VERSION accordingly (1.18.0 ->
1.23.2); the deployed trained-mode image was carrying this same
pre-existing crash risk.

onnx_integration.rs's real-inference test is marked #[ignore] (needs
torch+onnx+onnxscript; run with --ignored) matching the
forge-eval/tests/exporters_e2e.rs precedent for heavy-external-dep tests
-- everything else runs in the new CI job in the same commit.
peteonrails pushed a commit to reverb256/voxtype that referenced this pull request Nov 22, 2026
`voxtype transcribe <file>` on the ONNX variants prints its transcript and
then aborts during teardown: `corrupted double-linked list`, exit 134, and a
~360 MB core dump per run (peteonrails#772). The command finished; the crash is entirely
in the exit path.

`ort` 2.0.0-rc.12 registers `release_env_on_exit` in `.fini_array`, and that
cleanup releases memory ONNX Runtime has already released. glibc catches the
damage on its next free in that size class and aborts, so `_dl_fini` is where
the abort surfaces, not where the memory was corrupted. Skipping the hook
stops the abort but is not a fix, and the hook cannot be skipped from outside
the crate.

The daemon already stops unwinding for the same reason (525a0a6, "Exit the
daemon without running static destructors"). A one-shot command owns nothing
that a static destructor releases, so it now leaves the same way: flush
stdio, then `_exit`. Errors keep their exit code and their `Error: ...` line,
so a missing model or an empty WAV still returns 1 rather than 134.

The daemon's own error return now goes through this path too. Its success path
already left without unwinding, so the only change is which code the process
exits with after a failed startup, and how much of the hostile teardown it
runs on the way out.

The underlying defect stays upstream in `ort`/ONNX Runtime: pykeio/ort#610
replaces the exit hook with an explicitly managed environment, and it is
merged but unreleased as of 2.0.0-rc.13. `src/app/exit.rs` says when to
revisit this.

Refs peteonrails#772
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.

CUDA EP: release_env_on_exit reads freed memory, aborting at exit — reproduces without a second CUDA library (cf. #564, #392, #169)

1 participant