Skip to content

fix(daemon): keep running when detaching from the console fails - #304

Merged
sergej-koscejev merged 6 commits into
mainfrom
fix/299-detach-failure
Nov 19, 2026
Merged

sergej-koscejev merged 6 commits into
mainfrom
fix/299-detach-failure

Conversation

@sergej-koscejev

@sergej-koscejev sergej-koscejev commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Refs #299

Summary

When the native call that detaches the daemon cannot be set up, the daemon now writes a warning to stderr (daemon.log) and keeps running without detaching, as it did before #13. Other detach failures still stop the daemon.

 MopsDaemonCommand.run
   DaemonProcess.detach()
-    JnaDetach.detach / ForeignFunctionDetach.detach      # any throwable ends the daemon
+    DaemonProcess.detach(System.err, apiDescription) { JnaDetach.detach / ForeignFunctionDetach.detach }
+      LinkageError                    -> warn, keep running   # JNA: UnsatisfiedLinkError, NoClassDefFoundError
+      IllegalCallerException          -> warn, keep running   # FFM: native access not enabled
+      UnsupportedOperationException   -> warn, keep running   # FFM: no native linker for the platform
+      anything else                   -> propagates
   DaemonRunner(...)

The warning, for the failure in #299:

Warning: the daemon did not detach from the console or process group that started it, so closing that console or ending that process group may stop the daemon. Detaching through JNA (jna.boot.library.path=C:\...\lib\jna) failed: java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/win32-x86-64/jnidispatch.dll) not found in resource path (...)

Refs, not Fixes: the reporter's daemon should now start, but why JNA does not load jnidispatch.dll on their machine is still unknown.

skills/mops-daemon/SKILL.md now says that such a daemon keeps running attached and where the warning goes.

Sibling paths: only the daemon detaches (DaemonProcess.detach is called only from MopsDaemonCommand.run and from DaemonControlIntegrationTest).

Evidence

  • Before: DaemonProcessTest (commit test(daemon): …): 2 of 3 tests fail. A detacher that throws UnsatisfiedLinkError or IllegalCallerException ends detach with that error.

    After: all 3 pass. Those two write a warning naming the API and the error, and detach returns. A detacher that throws IllegalStateException (Could not detach daemon session: errno 1) still fails and writes nothing.

  • :daemon:test, and DaemonStartupIntegrationTest + DaemonControlIntegrationTest on MPS 2024.1.6 (JBR 17, JNA path) and 2026.1.1 (FFM path): all pass (:daemon:test 489 tests; 5 integration tests per version).

Where to look

  • DaemonProcess.detach(warnings, apiDescription, detachNatively): which exceptions count as "cannot be set up". For the Foreign Function API I left out IllegalArgumentException (SymbolLookup.libraryLookup cannot load kernel32) and NoSuchElementException (symbol not found), because catching them around the whole call could also hide bugs, and kernel32/libc always exist.
  • Commit refactor(daemon): … adds the seam with warnings and api (later apiDescription) unused, so the test commit compiles and fails on behavior.

Merge Danger

Blast Radius: daemon startup. Where JNA cannot load, the daemon now stays attached to its launching console or process group instead of exiting, so it can be stopped together with them.

@sergej-koscejev
sergej-koscejev marked this pull request as ready for review November 19, 2026 20:27
@sergej-koscejev
sergej-koscejev added this pull request to the merge queue Nov 19, 2026
Merged via the queue into main with commit 262b48b Nov 19, 2026
27 of 30 checks passed
@sergej-koscejev
sergej-koscejev deleted the fix/299-detach-failure branch November 19, 2026 21:48
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.

1 participant