Skip to content

Fix server cleanup leaks and Metal build warnings - #513

Merged
ashhart merged 1 commit into
ashhart:mainfrom
CerebralCoding:fix/server-cleanup-leaks
Oct 10, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
CerebralCoding:fix/server-cleanup-leaks

Conversation

@CerebralCoding

Copy link
Copy Markdown
Contributor

What this changes

Release authentication keys, key-file storage, and metrics request counters when their owners shut down, and clean up partial authentication initialization on errors. Fix the remaining golden-harness allocations and remove nine unused declarations from the Nemotron split-K Metal kernels.

Receipt

  • Environment: base f8fe17d, candidate 71aec49; Zig 0.17.0, macOS 27.0.1, Apple M5 Max with 128 GiB unified memory, target apple_m1.
  • Checkpoint: downloaded with hf download: TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit@d9d758fb83953437f7263256b0d96157e2a348b8, including mtp-4bit.safetensors.
  • Native Metal inference: served with --parallel 4 --context 32768 --keep-warm 0. A readable response was checked, and runtime counters confirmed MTP drafts were accepted.
  • Token parity: the existing tools/zig/reuse_served.py replay client retained the token hashes and counts for 58 completed replies. All replies had valid token hashes and exactly 256 generated tokens. Fourteen drafted/serial pairs matched, including greedy and seeded sampling, prose/code prompts, and prompts of 2,130 and 8,370 tokens crossing the 8,192-token prefill boundary. All 28 concurrent replies at 1/2/4 streams matched their solo and serial references.
  • Cancellation: disconnected a live stream after one second; the server recorded client-left. Both subsequent replies matched their original reference hashes. The test server then shut down with exit 0.
  • Regression: authentication-initialization and server-cleanup tests reproduced allocator leaks before the fix and pass afterward. An additional test fails each authentication allocation in turn and verifies cleanup.
  • Build/tests: zig build install native tf-row-check tf-tp2-bench test test-native test-golden -Dcpu=apple_m1 --summary all succeeded: 179/179 steps and 207/207 executed tests passed; remaining test steps were cached.
  • Golden checks: 312/319 equal, seven inherited known differences, zero unexpected differences, and no allocator-leak diagnostics.
  • The nine affected Metal kernels recompiled without unused-variable warnings. Expected negative-test warnings remain.
  • Lean checker: 512 inherited findings before and after, with zero new findings; its nonzero exit is inherited. zig fmt --check on changed Zig files and git diff --check pass.
  • Limits: CUDA, other devices/checkpoints, and performance comparisons were not run. Native Nemotron prompt reuse is pending upstream #497. At the tested revision, each request processes its full prompt and all observed cached-token counts were zero, so resumed-prefix parity is not claimed. Incidental timings are not performance measurements.

@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thank you @CerebralCoding. Merged into main (490a9c6): the key store and the metrics counters free what they hold at shutdown, the allocation-failure tests walk every path, and the unused sg declarations are gone from the nine Nemotron kernels. One merge resolution on our side: #531 changed Metrics.note right beside your new deinit, and both are kept. It ships in the next release.

@ashhart ashhart mentioned this pull request Oct 10, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…clarations go

Thanks @CerebralCoding.

# Conflicts:
#	zig/src/server/metrics.zig
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.

2 participants