GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [Bug] Bun NAPI crash on TUI exit: process.exit() in SIGINT handler conflicts with onnxruntime-node native cleanup · Issue #114 · tickernelz/opencode-mem

[Bug] Bun NAPI crash on TUI exit: process.exit() in SIGINT handler conflicts with onnxruntime-node native cleanup #114

New issue
Copy link
New issue
Copy link
Closed
#147
Closed
[Bug] Bun NAPI crash on TUI exit: process.exit() in SIGINT handler conflicts with onnxruntime-node native cleanup#114
#147
Copy link

Description

@keetyHuang
keetyHuang
opened on May 27, 2026
Issue body actions

Description

When using opencode-mem plugin with Bun runtime, exiting the TUI via Ctrl+C consistently crashes Bun with:

panic: NAPI FATAL ERROR: Error::New napi_create_error

Root Cause

The plugin registers a SIGINT/SIGTERM handler in dist/index.js that calls process.exit() after cleanup. When exiting opencode TUI:

  1. Plugin's SIGINT handler fires, calls memoryClient.close() then process.exit(0)
  2. onnxruntime-node (used via @xenova/transformers for local embeddings) has an InferenceSession loaded in a worker thread
  3. process.exit() triggers process termination — Bun starts tearing down the NAPI environment
  4. The ONNX Runtime GC finalizer (InferenceSessionWrap::FinalizeCallback) tries to destroy the session
  5. During destruction, Napi::Error::New(napi_env__*) is called, but the napi_env is already partially destroyed
  6. Bun panics with NAPI FATAL ERROR: Error::New napi_create_error

Crash Stack (from macOS crash report)

InferenceSessionWrap::FinalizeCallback()
  → InferenceSessionWrap::~InferenceSessionWrap()
    → Napi::ObjectWrap<InferenceSessionWrap>::~ObjectWrap()
      → Napi::Error::New(napi_env__*)
        → Napi::Error::Fatal() → Bun panic

Environment

  • Bun: 1.3.14
  • opencode-mem: 2.14.3
  • opencode: 1.15.10
  • macOS 15.5 (Apple Silicon arm64)
  • onnxruntime-node: 1.14.0

Suggested Fix

Remove process.exit() from the shutdownHandler — let the host process manage lifecycle:

const shutdownHandler = async () => {
    try {
        if (webServer) await webServer.stop();
        memoryClient.close();
        // DO NOT call process.exit()
    } catch (error) {
        log("Shutdown error", { error: String(error) });
    }
};

Related

See also #97, #88 for other NAPI/native addon issues on arm64.

Activity

  1. tickernelz
    closed this as completedin #147on Jul 7, 2026
  2. EyJunge1
    added a commit that references this issue on Oct 13, 2026

    fix: re-raise SIGINT/SIGTERM after plugin cleanup (#409)

    2dd1255
  3. dmr48rus
    added a commit that references this issue on Oct 16, 2026

    fix: re-raise SIGINT/SIGTERM after plugin cleanup (tickernelz#409)

    4643f12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.