Skip to content

feat: add MI_NO_PROCESS_DETACH (skip automatic mi_process_done at exit) - #284

Merged
zackees merged 4 commits into
mainfrom
bun-parity/p3-no-process-detach
Sep 2, 2026
Merged

zackees merged 4 commits into
mainfrom
bun-parity/p3-no-process-detach

Conversation

@zackees

@zackees zackees commented Sep 2, 2026

Copy link
Copy Markdown
Owner

Summary

Bun parity P3 (Closes #268, sub-issue of #264). Ports Bun's MI_NO_PROCESS_DETACH
(oven-sh/mimalloc@942b8342, MIT): a CMake option, an early return in
_mi_auto_process_done (src/init.c), and a #ifndef-guarded destructor
registration (src/prim/prim.c). All three ported hunks carry provenance comments.

  • Confirmed the Windows DllMain/TLS-callback and atexit exit paths
    (src/prim/windows/prim.c) all funnel through _mi_auto_process_done, so the
    init.c early return covers Windows too.
  • Documented in include/mimalloc/profile.h and the README that
    MIMALLOC_PROF_DUMP_AT_EXIT/DHAT dump-at-exit are consequently also skipped —
    an embedder using MI_NO_PROCESS_DETACH must call mi_prof_dump/mi_dhat_dump
    itself.
  • MIMALLOC_FORKS.md pass-3 row updated to IMPORTED (Bun parity P3: add MI_NO_PROCESS_DETACH #268).
  • Bun-consumer compile check passes: c++ -x c++ -std=c++17 -c src/static.c -Iinclude -DMI_STATIC_LIB -DMI_NO_PROCESS_DETACH=1 -DMI_SKIP_COLLECT_ON_EXIT=1
    compiles clean, and nm -C | grep mi_process_detach is empty.

Deviation from the issue's test plan (rule 7, evidence-first)

The issue's step 3 said "a CMake add_test with PASS_REGULAR_EXPRESSION/
FAIL_REGULAR_EXPRESSION is enough" — that doesn't survive the #277 bundle
gate, which is part of the required c-unit merge gates:

bundle_tests: cannot lower 2 test(s) into a bundle:
  - test-no-process-detach-runs: test properties ['PASS_REGULAR_EXPRESSION'] have no bundle equivalent; implement them or the bundle would silently change what is asserted
  - test-no-process-detach-skipped: test properties ['FAIL_REGULAR_EXPRESSION'] have no bundle equivalent; implement them or the bundle would silently change what is asserted

Fix: generalized the existing test/run-negative.cmake cmake -P harness
pattern (already lowered by the bundler) into a new test/run-text-check.cmake
(MODE=REQUIRE|FORBID, the zero-exit mirror of run-negative.cmake's
non-zero-exit contract), plus a matching forbid_text field through
ci/bundle_tests.py/ci/run_test_bundle.py with unit test coverage. Posted
as a comment on #268 with the same evidence.

test/test-no-process-detach.c is built twice — once against the normal
static lib, once against a dedicated mimalloc-static-no-detach target
compiled with MI_NO_PROCESS_DETACH=1 — and both are checked against opposite
expectations on the MIMALLOC_VERBOSE=1 "process done" line.

Test plan

  • uv run ci/verify_local.py --keep-going:
config result
release PASS
off PASS
debug-full PASS
guarded PASS
shared PASS
bundle PASS
memory-gate PASS
diag PASS
lint PASS
rust PASS (after the trailing amalgamation-regeneration commit)
asan FAIL — environmental only: MI_TRACK_ASAN did not survive configure (no ASan runtime installed in this dev container; unrelated to this change)
  • Manual proof of both variants:
    $ MIMALLOC_VERBOSE=1 ./mimalloc-test-no-process-detach       | grep "process done"
    mimalloc: process done
    $ MIMALLOC_VERBOSE=1 ./mimalloc-test-no-process-detach-skip  | grep "process done"
    (no output)
    
  • ctest -R test-no-process-detach: both test-no-process-detach-runs and
    test-no-process-detach-skipped PASS.
  • cargo run -p xtask -- check and cargo test -p mimalloc-pprof: pass.

Notes for reviewers

  • src/init.c/src/prim/prim.c/CMakeLists.txt/test/* are in one commit;
    the rust/mimalloc-pprof/vendor/* amalgamation regeneration is a separate
    trailing commit (rule 2).
  • Minor watch item, not verified locally: MSVC /WX is not set anywhere in
    CMakeLists.txt today, so the now-unreachable tail of
    _mi_auto_process_done under MI_NO_PROCESS_DETACH (C4702) should not fail
    a Windows build — but this wasn't testable on this Linux dev box, so flag if
    the win-msvc job surfaces it.

Co-Authored-By: Claude Fable 5.1 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S

🤖 Generated with Claude Code

https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S

zackees and others added 4 commits September 2, 2026 00:21
Bun parity P3 (issue #268). Ports Bun's MI_NO_PROCESS_DETACH: a CMake option, an
early return in _mi_auto_process_done (src/init.c) so nothing runs from the
automatic exit path, and a #ifndef-guarded destructor registration
(src/prim/prim.c) so the destructor is never installed at all. All three hunks
carry "imported from oven-sh/mimalloc @ 942b8342, MIT" provenance.

Confirmed the Windows DllMain/TLS-callback and atexit exit paths
(src/prim/windows/prim.c) all funnel through _mi_auto_process_done, so the
init.c early return covers them too. Documented in include/mimalloc/profile.h
and README that MIMALLOC_PROF_DUMP_AT_EXIT/DHAT dump-at-exit are consequently
skipped as well -- an embedder using MI_NO_PROCESS_DETACH must call
mi_prof_dump/mi_dhat_dump itself.

test/test-no-process-detach.c is built twice (with and without the define,
against a dedicated mimalloc-static-no-detach target) and checked for opposite
outcomes on the MIMALLOC_VERBOSE=1 "process done" line. The issue originally
scoped this via ctest's PASS_REGULAR_EXPRESSION/FAIL_REGULAR_EXPRESSION, but
those have no bundle equivalent and the #277 bundle-roundtrip c-unit gate
refuses them outright -- generalized the existing run-negative.cmake `cmake -P`
harness pattern into test/run-text-check.cmake (MODE=REQUIRE|FORBID, the
zero-exit mirror of run-negative.cmake's non-zero-exit contract) instead, with
a matching forbid_text field through ci/bundle_tests.py and
ci/run_test_bundle.py plus unit test coverage. See the evidence comment on
#268 for the bundle_tests.py error this fixes.

MIMALLOC_FORKS.md pass-3 row updated to IMPORTED (#268).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
…S_DETACH

Trailing rust-only commit (CLAUDE.md rule 2): src/init.c and src/prim/prim.c
changed in the previous commit, so amalgamate-c/amalgamate-h regenerate
rust/mimalloc-pprof/vendor/mimalloc-pprof-amalgamated.{c,h}. cargo run -p
xtask -- check confirms the vendor tree matches, and cargo test -p
mimalloc-pprof passes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
…ption

Opus review of PR #284 (blocking): with -DMI_NO_PROCESS_DETACH=ON, mi_defines
already carries MI_NO_PROCESS_DETACH=1 into mimalloc-static itself, so
mimalloc-test-no-process-detach (the REQUIRE/positive control) linked against
mimalloc-static never prints "process done" and fails by construction. No
c-unit job sets the option, which is why CI stayed green.

Guard the REQUIRE half with `NOT MI_NO_PROCESS_DETACH` so it is skipped
(mimalloc-static is not detach-enabled to test against) rather than failing
for the wrong reason; the FORBID half (its own always-detach-enabled
mimalloc-static-no-detach) keeps running unconditionally. Also switched
mimalloc-static-no-detach to build from src/static.c (single TU) instead of
the full source list -- the exact Bun-consumer compile shape this issue's
acceptance check already exercises.

Verified: Release without the option (both tests PASS), Release with
-DMI_NO_PROCESS_DETACH=ON (only test-no-process-detach-skipped registered,
PASS), and MI_PPROF=OFF with the option (same, PASS).

Nits: include/mimalloc/dhat.h now carries the MI_NO_PROCESS_DETACH /
MIMALLOC_DHAT_DUMP_AT_EXIT interaction note profile.h already referenced but
dhat.h itself lacked; README's DHAT section gets the same dump-at-exit warning
the PROF section already has.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
Trailing rust-only commit (CLAUDE.md rule 2): include/mimalloc/dhat.h changed
in the previous commit (MI_NO_PROCESS_DETACH interaction note), so
amalgamate-c/amalgamate-h regenerate rust/mimalloc-pprof/vendor/mimalloc-pprof-amalgamated.{c,h}
(dhat.h is inlined into both). cargo run -p xtask -- check confirms the
vendor tree matches, and cargo test -p mimalloc-pprof passes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
@zackees

zackees commented Sep 2, 2026

Copy link
Copy Markdown
Owner Author

Opus review: APPROVE after the CMake guard fix (8ec74c20): the REQUIRE positive control is now registered only when MI_NO_PROCESS_DETACH is not set globally, the FORBID control builds its own single-TU mimalloc-static-no-detach from src/static.c (the Bun-consumer shape), and dhat.h/README carry the dump-at-exit note. Verified: the three ported hunks match Bun @942b8342; Windows DllMain/atexit paths funnel through the early return; run-text-check.cmake negative controls all fail correctly; bundle round-trip lowers the new shape. CI 51/51.

@zackees
zackees merged commit 613aab8 into main Sep 2, 2026
51 checks passed
@zackees
zackees deleted the bun-parity/p3-no-process-detach branch September 2, 2026 07:48
zackees added a commit that referenced this pull request Sep 2, 2026
Issue #274 (Bun parity P9b). docs/bun-gap-analysis-2026-09-02.md re-runs
the 2026-09-01 analysis's four checks against Bun's current pin: the
scripts/build/deps/mimalloc.ts commit (942b8342) has not moved, and all
five consumer files (mimalloc_sys.rs, MimallocArena.rs,
MimallocWTFMalloc.h, BunJSCModule.h, heapStats-mimalloc.test.ts) are
byte-identical to what was cached in that session -- no new gap exists at
Bun's current pin, so no new sub-issue is filed. The rest of the doc is a
status table for every item and gap ID (B1-B20) from the 2026-09-01
analysis against what has actually merged since (#276, #281, #284, #286,
#289, #291, #297) versus what's still open (#299, #302, and the items tied
to them): 7/9 required-before-pitch items done, 11/20 B-numbered gaps done,
1 partial, 0 new.

docs/ci-gates.md gains a `bun-surface` row and a short section explaining
why that CI job is temporarily continue-on-error (mi_on_thread_idle isn't
on main yet) with a dated TODO for when to make it a hard gate.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
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.

Bun parity P3: add MI_NO_PROCESS_DETACH

1 participant