Skip to content

[Java] Embed Rust CLI runtime 4.4: JNA binding interface and implementation - #2230

Merged
edburns merged 3 commits into
edburns/1917-java-embed-rust-cli-runtime-dd-3039924-agentic-run-02from
copilot/edburns1917-java-embed-rust-cli-runtime-dd-3039924
Aug 3, 2026
Merged

[Java] Embed Rust CLI runtime 4.4: JNA binding interface and implementation#2230
edburns merged 3 commits into
edburns/1917-java-embed-rust-cli-runtime-dd-3039924-agentic-run-02from
copilot/edburns1917-java-embed-rust-cli-runtime-dd-3039924

Conversation

Copilot AI commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Implements the NativeBinding interface, JnaNativeBinding JNA-backed implementation, and OutboundCallback JNA callback — the Java bridge to the five copilot_runtime_* C ABI entry points exposed by runtime.node.

New files

  • OutboundCallback — JNA @FunctionalInterface Callback; invoked by the native runtime on native threads. Documents that data pointer is only valid during invocation and must be copied with Pointer.getByteArray(0, len).

  • NativeBinding — Internal interface abstracting the five ABI entry points. interface (not abstract class) for future FFM swappability via MR-JAR; direct instantiation, no ServiceLoader.

  • JnaNativeBinding — JNA implementation:

    • Inner CopilotRuntimeLibrary extends Library mapping copilot_runtime_* exports
    • Library-never-unloads: static volatile loadedLib/loadedPath fields; once set, never cleared in production
    • Duplicate-path guard: loading a different library path throws IllegalStateException with a diagnostic message naming both paths
    • Active-callback tracking: AtomicInteger activeCallbacks incremented on callback entry, decremented on exit — callers must drain to zero before connection_close/host_shutdown
    • Package-private testing constructor (accepts a stub CopilotRuntimeLibrary) and resetForTesting() for unit test isolation
  • JnaNativeBindingTest — 24 unit tests: delegation via StubRuntimeLibrary, library load/guard, and callback invocation/tracking against the spike-3-4 libcallback_test native library.

Modified files

  • pom.xml — adds net.java.dev.jna:jna:${jna.version} (5.19.1, <optional>true</optional>); version is a Maven property for deliberate upgrades.

  • module-info.java — adds requires static com.sun.jna and opens com.github.copilot.ffi to com.sun.jna (required for JNA reflection access to callback interface methods under JPMS).

Usage sketch

// Production path (called by FfiRuntimeHost, task 4.5)
NativeBinding binding = new JnaNativeBinding(NativeRuntimeLoader.resolve());

OutboundCallback cb = (userData, data, len) -> {
    byte[] bytes = data.getByteArray(0, len); // copy before returning
    queueInputStream.enqueue(bytes);
};

int serverId = binding.hostStart(argvJson, argvJson.length, null, 0);
int connId   = binding.connectionOpen(serverId, cb, Pointer.NULL,
                   null, 0, null, 0, null, 0);

- Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml
  with jna.version property for deliberate upgrades
- Create OutboundCallback.java: JNA Callback interface for
  native-to-Java outbound data delivery
- Create NativeBinding.java: interface abstraction for the 5
  copilot_runtime_* C ABI entry points
- Create JnaNativeBinding.java: JNA implementation with
  static singleton (library-never-unloads pattern), duplicate
  path guard, and active-callback AtomicInteger tracking
- Create JnaNativeBindingTest.java: 24 unit tests covering
  delegation, loading, duplicate guard, and callback behavior
  using the spike-3-4 test native library
- Update module-info.java: requires static com.sun.jna,
  opens com.github.copilot.ffi to com.sun.jna

Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement NativeBinding interface and JnaNativeBinding implementation [Java] Embed Rust CLI runtime 4.4: JNA binding interface and implementation Aug 3, 2026
Copilot AI requested a review from edburns August 3, 2026 16:31
@github-actions

This comment has been minimized.

@edburns
edburns marked this pull request as ready for review August 3, 2026 16:48
@edburns
edburns requested a review from a team as a code owner August 3, 2026 16:48
Copilot AI review requested due to automatic review settings August 3, 2026 16:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Java’s JNA bridge to the embedded Rust runtime C ABI.

Changes:

  • Defines native binding and callback interfaces.
  • Implements guarded JNA library loading and ABI delegation.
  • Adds JNA configuration and unit tests.
Show a summary per file
File Description
java/sdk/pom.xml Adds optional JNA dependency.
java/sdk/src/main/java/module-info.java Configures JNA module access.
OutboundCallback.java Defines the native callback contract.
NativeBinding.java Defines the internal runtime ABI.
JnaNativeBinding.java Implements JNA loading, delegation, and callback tracking.
JnaNativeBindingTest.java Tests delegation, loading, guards, and callbacks.

Review details

Suppressed comments (2)

java/sdk/src/main/java/com/github/copilot/ffi/JnaNativeBinding.java:72

  • This export returns the runtime's one-byte Rust/C ABI bool (rust/src/ffi.rs:43), but JNA maps Java boolean to a 32-bit C int. That ABI mismatch can decode a native false as true. Use a one-byte native return (or explicit type mapper) and convert it in connectionClose.
        boolean copilot_runtime_connection_close(int connectionId);

java/sdk/src/main/java/com/github/copilot/ffi/JnaNativeBinding.java:69

  • This export also returns the runtime's one-byte Rust/C ABI bool (rust/src/ffi.rs:42), whereas JNA's Java boolean mapping expects a 32-bit C int. A native false can therefore be decoded incorrectly. Use a one-byte native return (or explicit type mapper) and convert it in connectionWrite.
        boolean copilot_runtime_connection_write(int connectionId, byte[] data, int dataLen);
  • Files reviewed: 6/6 changed files
  • Comments generated: 6
  • Review effort level: Balanced

Comment thread java/sdk/src/main/java/com/github/copilot/ffi/JnaNativeBinding.java Outdated
Comment thread java/sdk/src/main/java/com/github/copilot/ffi/JnaNativeBinding.java Outdated
Comment thread java/sdk/src/main/java/com/github/copilot/ffi/JnaNativeBinding.java Outdated
Comment thread java/sdk/src/test/java/com/github/copilot/ffi/JnaNativeBindingTest.java Outdated
- Fix callback GC: store tracked callbacks per connection in a
  ConcurrentHashMap, removed on connectionClose (comment #3706039757)
- Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean
  as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert
  to boolean in delegation methods (comment #3706039823)
- Wrap UnsatisfiedLinkError in IllegalStateException per error contract
  (comment #3706039855)
- Replace silent return with assumeTrue for native lib tests so skips
  are visible in CI reports (comment #3706039896)
- Rewrite activeCallbackCount test to exercise through JnaNativeBinding
  and assert binding.activeCallbacks (comment #3706039935)
- Add ABI name documentation to CallbackTestLib, fix byte return types
  in test interface (comment #3706039968)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Cross-SDK Consistency Review ✅

All 6 changed files in this PR are scoped entirely to Java (java/sdk/). The changes introduce:

  • NativeBinding interface and JnaNativeBinding JNA implementation — internal Java FFI bridge to the Rust CLI runtime's C ABI
  • OutboundCallback — JNA-specific callback type
  • Maven/JPMS plumbing (pom.xml, module-info.java)

No cross-SDK consistency issues. This is Java-specific native-bridge infrastructure using JNA (Java Native Access), which is a Java ecosystem mechanism with no equivalent in the other SDKs. Each SDK integrates the native runtime through its own platform-appropriate path (Node.js via native modules, Python via ctypes/cffi, Go via cgo, .NET via P/Invoke, Rust natively). No public API surface was added or modified, so no parallel changes are needed in Node.js, Python, Go, .NET, or Rust.

Generated by SDK Consistency Review Agent for #2230 · sonnet46 17.7 AIC · ⌖ 5.39 AIC · ⊞ 6.6K ·

@edburns
edburns merged commit 357f577 into edburns/1917-java-embed-rust-cli-runtime-dd-3039924-agentic-run-02 Aug 3, 2026
26 checks passed
@edburns
edburns deleted the copilot/edburns1917-java-embed-rust-cli-runtime-dd-3039924 branch August 3, 2026 17:38
edburns added a commit that referenced this pull request Aug 4, 2026
…tation (#2230)

* Initial plan

* feat(java): add JNA binding interface and implementation (task 4.4)

- Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml
  with jna.version property for deliberate upgrades
- Create OutboundCallback.java: JNA Callback interface for
  native-to-Java outbound data delivery
- Create NativeBinding.java: interface abstraction for the 5
  copilot_runtime_* C ABI entry points
- Create JnaNativeBinding.java: JNA implementation with
  static singleton (library-never-unloads pattern), duplicate
  path guard, and active-callback AtomicInteger tracking
- Create JnaNativeBindingTest.java: 24 unit tests covering
  delegation, loading, duplicate guard, and callback behavior
  using the spike-3-4 test native library
- Update module-info.java: requires static com.sun.jna,
  opens com.github.copilot.ffi to com.sun.jna

Co-authored-by: edburns <75821+edburns@users.noreply.github.com>

* fix: address Copilot code review findings for JNA binding

- Fix callback GC: store tracked callbacks per connection in a
  ConcurrentHashMap, removed on connectionClose (comment #3706039757)
- Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean
  as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert
  to boolean in delegation methods (comment #3706039823)
- Wrap UnsatisfiedLinkError in IllegalStateException per error contract
  (comment #3706039855)
- Replace silent return with assumeTrue for native lib tests so skips
  are visible in CI reports (comment #3706039896)
- Rewrite activeCallbackCount test to exercise through JnaNativeBinding
  and assert binding.activeCallbacks (comment #3706039935)
- Add ABI name documentation to CallbackTestLib, fix byte return types
  in test interface (comment #3706039968)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Co-authored-by: Ed Burns <edburns@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
edburns added a commit that referenced this pull request Aug 4, 2026
…tation (#2230)

* Initial plan

* feat(java): add JNA binding interface and implementation (task 4.4)

- Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml
  with jna.version property for deliberate upgrades
- Create OutboundCallback.java: JNA Callback interface for
  native-to-Java outbound data delivery
- Create NativeBinding.java: interface abstraction for the 5
  copilot_runtime_* C ABI entry points
- Create JnaNativeBinding.java: JNA implementation with
  static singleton (library-never-unloads pattern), duplicate
  path guard, and active-callback AtomicInteger tracking
- Create JnaNativeBindingTest.java: 24 unit tests covering
  delegation, loading, duplicate guard, and callback behavior
  using the spike-3-4 test native library
- Update module-info.java: requires static com.sun.jna,
  opens com.github.copilot.ffi to com.sun.jna

Co-authored-by: edburns <75821+edburns@users.noreply.github.com>

* fix: address Copilot code review findings for JNA binding

- Fix callback GC: store tracked callbacks per connection in a
  ConcurrentHashMap, removed on connectionClose (comment #3706039757)
- Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean
  as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert
  to boolean in delegation methods (comment #3706039823)
- Wrap UnsatisfiedLinkError in IllegalStateException per error contract
  (comment #3706039855)
- Replace silent return with assumeTrue for native lib tests so skips
  are visible in CI reports (comment #3706039896)
- Rewrite activeCallbackCount test to exercise through JnaNativeBinding
  and assert binding.activeCallbacks (comment #3706039935)
- Add ABI name documentation to CallbackTestLib, fix byte return types
  in test interface (comment #3706039968)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Co-authored-by: Ed Burns <edburns@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
edburns added a commit that referenced this pull request Aug 4, 2026
…tation (#2230)

* Initial plan

* feat(java): add JNA binding interface and implementation (task 4.4)

- Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml
  with jna.version property for deliberate upgrades
- Create OutboundCallback.java: JNA Callback interface for
  native-to-Java outbound data delivery
- Create NativeBinding.java: interface abstraction for the 5
  copilot_runtime_* C ABI entry points
- Create JnaNativeBinding.java: JNA implementation with
  static singleton (library-never-unloads pattern), duplicate
  path guard, and active-callback AtomicInteger tracking
- Create JnaNativeBindingTest.java: 24 unit tests covering
  delegation, loading, duplicate guard, and callback behavior
  using the spike-3-4 test native library
- Update module-info.java: requires static com.sun.jna,
  opens com.github.copilot.ffi to com.sun.jna

Co-authored-by: edburns <75821+edburns@users.noreply.github.com>

* fix: address Copilot code review findings for JNA binding

- Fix callback GC: store tracked callbacks per connection in a
  ConcurrentHashMap, removed on connectionClose (comment #3706039757)
- Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean
  as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert
  to boolean in delegation methods (comment #3706039823)
- Wrap UnsatisfiedLinkError in IllegalStateException per error contract
  (comment #3706039855)
- Replace silent return with assumeTrue for native lib tests so skips
  are visible in CI reports (comment #3706039896)
- Rewrite activeCallbackCount test to exercise through JnaNativeBinding
  and assert binding.activeCallbacks (comment #3706039935)
- Add ABI name documentation to CallbackTestLib, fix byte return types
  in test interface (comment #3706039968)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Co-authored-by: Ed Burns <edburns@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
edburns added a commit that referenced this pull request Aug 4, 2026
…tation (#2230)

* Initial plan

* feat(java): add JNA binding interface and implementation (task 4.4)

- Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml
  with jna.version property for deliberate upgrades
- Create OutboundCallback.java: JNA Callback interface for
  native-to-Java outbound data delivery
- Create NativeBinding.java: interface abstraction for the 5
  copilot_runtime_* C ABI entry points
- Create JnaNativeBinding.java: JNA implementation with
  static singleton (library-never-unloads pattern), duplicate
  path guard, and active-callback AtomicInteger tracking
- Create JnaNativeBindingTest.java: 24 unit tests covering
  delegation, loading, duplicate guard, and callback behavior
  using the spike-3-4 test native library
- Update module-info.java: requires static com.sun.jna,
  opens com.github.copilot.ffi to com.sun.jna

Co-authored-by: edburns <75821+edburns@users.noreply.github.com>

* fix: address Copilot code review findings for JNA binding

- Fix callback GC: store tracked callbacks per connection in a
  ConcurrentHashMap, removed on connectionClose (comment #3706039757)
- Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean
  as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert
  to boolean in delegation methods (comment #3706039823)
- Wrap UnsatisfiedLinkError in IllegalStateException per error contract
  (comment #3706039855)
- Replace silent return with assumeTrue for native lib tests so skips
  are visible in CI reports (comment #3706039896)
- Rewrite activeCallbackCount test to exercise through JnaNativeBinding
  and assert binding.activeCallbacks (comment #3706039935)
- Add ABI name documentation to CallbackTestLib, fix byte return types
  in test interface (comment #3706039968)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Co-authored-by: Ed Burns <edburns@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
edburns added a commit that referenced this pull request Aug 4, 2026
…tation (#2230)

* Initial plan

* feat(java): add JNA binding interface and implementation (task 4.4)

- Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml
  with jna.version property for deliberate upgrades
- Create OutboundCallback.java: JNA Callback interface for
  native-to-Java outbound data delivery
- Create NativeBinding.java: interface abstraction for the 5
  copilot_runtime_* C ABI entry points
- Create JnaNativeBinding.java: JNA implementation with
  static singleton (library-never-unloads pattern), duplicate
  path guard, and active-callback AtomicInteger tracking
- Create JnaNativeBindingTest.java: 24 unit tests covering
  delegation, loading, duplicate guard, and callback behavior
  using the spike-3-4 test native library
- Update module-info.java: requires static com.sun.jna,
  opens com.github.copilot.ffi to com.sun.jna

Co-authored-by: edburns <75821+edburns@users.noreply.github.com>

* fix: address Copilot code review findings for JNA binding

- Fix callback GC: store tracked callbacks per connection in a
  ConcurrentHashMap, removed on connectionClose (comment #3706039757)
- Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean
  as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert
  to boolean in delegation methods (comment #3706039823)
- Wrap UnsatisfiedLinkError in IllegalStateException per error contract
  (comment #3706039855)
- Replace silent return with assumeTrue for native lib tests so skips
  are visible in CI reports (comment #3706039896)
- Rewrite activeCallbackCount test to exercise through JnaNativeBinding
  and assert binding.activeCallbacks (comment #3706039935)
- Add ABI name documentation to CallbackTestLib, fix byte return types
  in test interface (comment #3706039968)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Co-authored-by: Ed Burns <edburns@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
edburns added a commit that referenced this pull request Aug 5, 2026
…tation (#2230)

* Initial plan

* feat(java): add JNA binding interface and implementation (task 4.4)

- Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml
  with jna.version property for deliberate upgrades
- Create OutboundCallback.java: JNA Callback interface for
  native-to-Java outbound data delivery
- Create NativeBinding.java: interface abstraction for the 5
  copilot_runtime_* C ABI entry points
- Create JnaNativeBinding.java: JNA implementation with
  static singleton (library-never-unloads pattern), duplicate
  path guard, and active-callback AtomicInteger tracking
- Create JnaNativeBindingTest.java: 24 unit tests covering
  delegation, loading, duplicate guard, and callback behavior
  using the spike-3-4 test native library
- Update module-info.java: requires static com.sun.jna,
  opens com.github.copilot.ffi to com.sun.jna

Co-authored-by: edburns <75821+edburns@users.noreply.github.com>

* fix: address Copilot code review findings for JNA binding

- Fix callback GC: store tracked callbacks per connection in a
  ConcurrentHashMap, removed on connectionClose (comment #3706039757)
- Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean
  as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert
  to boolean in delegation methods (comment #3706039823)
- Wrap UnsatisfiedLinkError in IllegalStateException per error contract
  (comment #3706039855)
- Replace silent return with assumeTrue for native lib tests so skips
  are visible in CI reports (comment #3706039896)
- Rewrite activeCallbackCount test to exercise through JnaNativeBinding
  and assert binding.activeCallbacks (comment #3706039935)
- Add ABI name documentation to CallbackTestLib, fix byte return types
  in test interface (comment #3706039968)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Co-authored-by: Ed Burns <edburns@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
edburns added a commit that referenced this pull request Aug 5, 2026
…tation (#2230)

* Initial plan

* feat(java): add JNA binding interface and implementation (task 4.4)

- Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml
  with jna.version property for deliberate upgrades
- Create OutboundCallback.java: JNA Callback interface for
  native-to-Java outbound data delivery
- Create NativeBinding.java: interface abstraction for the 5
  copilot_runtime_* C ABI entry points
- Create JnaNativeBinding.java: JNA implementation with
  static singleton (library-never-unloads pattern), duplicate
  path guard, and active-callback AtomicInteger tracking
- Create JnaNativeBindingTest.java: 24 unit tests covering
  delegation, loading, duplicate guard, and callback behavior
  using the spike-3-4 test native library
- Update module-info.java: requires static com.sun.jna,
  opens com.github.copilot.ffi to com.sun.jna

Co-authored-by: edburns <75821+edburns@users.noreply.github.com>

* fix: address Copilot code review findings for JNA binding

- Fix callback GC: store tracked callbacks per connection in a
  ConcurrentHashMap, removed on connectionClose (comment #3706039757)
- Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean
  as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert
  to boolean in delegation methods (comment #3706039823)
- Wrap UnsatisfiedLinkError in IllegalStateException per error contract
  (comment #3706039855)
- Replace silent return with assumeTrue for native lib tests so skips
  are visible in CI reports (comment #3706039896)
- Rewrite activeCallbackCount test to exercise through JnaNativeBinding
  and assert binding.activeCallbacks (comment #3706039935)
- Add ABI name documentation to CallbackTestLib, fix byte return types
  in test interface (comment #3706039968)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Co-authored-by: Ed Burns <edburns@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
edburns added a commit that referenced this pull request Aug 5, 2026
…tation (#2230)

* Initial plan

* feat(java): add JNA binding interface and implementation (task 4.4)

- Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml
  with jna.version property for deliberate upgrades
- Create OutboundCallback.java: JNA Callback interface for
  native-to-Java outbound data delivery
- Create NativeBinding.java: interface abstraction for the 5
  copilot_runtime_* C ABI entry points
- Create JnaNativeBinding.java: JNA implementation with
  static singleton (library-never-unloads pattern), duplicate
  path guard, and active-callback AtomicInteger tracking
- Create JnaNativeBindingTest.java: 24 unit tests covering
  delegation, loading, duplicate guard, and callback behavior
  using the spike-3-4 test native library
- Update module-info.java: requires static com.sun.jna,
  opens com.github.copilot.ffi to com.sun.jna

Co-authored-by: edburns <75821+edburns@users.noreply.github.com>

* fix: address Copilot code review findings for JNA binding

- Fix callback GC: store tracked callbacks per connection in a
  ConcurrentHashMap, removed on connectionClose (comment #3706039757)
- Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean
  as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert
  to boolean in delegation methods (comment #3706039823)
- Wrap UnsatisfiedLinkError in IllegalStateException per error contract
  (comment #3706039855)
- Replace silent return with assumeTrue for native lib tests so skips
  are visible in CI reports (comment #3706039896)
- Rewrite activeCallbackCount test to exercise through JnaNativeBinding
  and assert binding.activeCallbacks (comment #3706039935)
- Add ABI name documentation to CallbackTestLib, fix byte return types
  in test interface (comment #3706039968)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Co-authored-by: Ed Burns <edburns@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
edburns added a commit that referenced this pull request Aug 7, 2026
…tation (#2230)

* Initial plan

* feat(java): add JNA binding interface and implementation (task 4.4)

- Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml
  with jna.version property for deliberate upgrades
- Create OutboundCallback.java: JNA Callback interface for
  native-to-Java outbound data delivery
- Create NativeBinding.java: interface abstraction for the 5
  copilot_runtime_* C ABI entry points
- Create JnaNativeBinding.java: JNA implementation with
  static singleton (library-never-unloads pattern), duplicate
  path guard, and active-callback AtomicInteger tracking
- Create JnaNativeBindingTest.java: 24 unit tests covering
  delegation, loading, duplicate guard, and callback behavior
  using the spike-3-4 test native library
- Update module-info.java: requires static com.sun.jna,
  opens com.github.copilot.ffi to com.sun.jna

Co-authored-by: edburns <75821+edburns@users.noreply.github.com>

* fix: address Copilot code review findings for JNA binding

- Fix callback GC: store tracked callbacks per connection in a
  ConcurrentHashMap, removed on connectionClose (comment #3706039757)
- Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean
  as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert
  to boolean in delegation methods (comment #3706039823)
- Wrap UnsatisfiedLinkError in IllegalStateException per error contract
  (comment #3706039855)
- Replace silent return with assumeTrue for native lib tests so skips
  are visible in CI reports (comment #3706039896)
- Rewrite activeCallbackCount test to exercise through JnaNativeBinding
  and assert binding.activeCallbacks (comment #3706039935)
- Add ABI name documentation to CallbackTestLib, fix byte return types
  in test interface (comment #3706039968)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Co-authored-by: Ed Burns <edburns@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
edburns added a commit that referenced this pull request Aug 7, 2026
…tation (#2230)

* Initial plan

* feat(java): add JNA binding interface and implementation (task 4.4)

- Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml
  with jna.version property for deliberate upgrades
- Create OutboundCallback.java: JNA Callback interface for
  native-to-Java outbound data delivery
- Create NativeBinding.java: interface abstraction for the 5
  copilot_runtime_* C ABI entry points
- Create JnaNativeBinding.java: JNA implementation with
  static singleton (library-never-unloads pattern), duplicate
  path guard, and active-callback AtomicInteger tracking
- Create JnaNativeBindingTest.java: 24 unit tests covering
  delegation, loading, duplicate guard, and callback behavior
  using the spike-3-4 test native library
- Update module-info.java: requires static com.sun.jna,
  opens com.github.copilot.ffi to com.sun.jna

Co-authored-by: edburns <75821+edburns@users.noreply.github.com>

* fix: address Copilot code review findings for JNA binding

- Fix callback GC: store tracked callbacks per connection in a
  ConcurrentHashMap, removed on connectionClose (comment #3706039757)
- Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean
  as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert
  to boolean in delegation methods (comment #3706039823)
- Wrap UnsatisfiedLinkError in IllegalStateException per error contract
  (comment #3706039855)
- Replace silent return with assumeTrue for native lib tests so skips
  are visible in CI reports (comment #3706039896)
- Rewrite activeCallbackCount test to exercise through JnaNativeBinding
  and assert binding.activeCallbacks (comment #3706039935)
- Add ABI name documentation to CallbackTestLib, fix byte return types
  in test interface (comment #3706039968)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Co-authored-by: Ed Burns <edburns@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
edburns added a commit that referenced this pull request Aug 7, 2026
…tation (#2230)

* Initial plan

* feat(java): add JNA binding interface and implementation (task 4.4)

- Add JNA 5.19.1 as optional dependency to java/sdk/pom.xml
  with jna.version property for deliberate upgrades
- Create OutboundCallback.java: JNA Callback interface for
  native-to-Java outbound data delivery
- Create NativeBinding.java: interface abstraction for the 5
  copilot_runtime_* C ABI entry points
- Create JnaNativeBinding.java: JNA implementation with
  static singleton (library-never-unloads pattern), duplicate
  path guard, and active-callback AtomicInteger tracking
- Create JnaNativeBindingTest.java: 24 unit tests covering
  delegation, loading, duplicate guard, and callback behavior
  using the spike-3-4 test native library
- Update module-info.java: requires static com.sun.jna,
  opens com.github.copilot.ffi to com.sun.jna

Co-authored-by: edburns <75821+edburns@users.noreply.github.com>

* fix: address Copilot code review findings for JNA binding

- Fix callback GC: store tracked callbacks per connection in a
  ConcurrentHashMap, removed on connectionClose (comment #3706039757)
- Fix boolean ABI mismatch: Rust bool is 1 byte, JNA maps Java boolean
  as 32-bit int. Changed CopilotRuntimeLibrary to return byte, convert
  to boolean in delegation methods (comment #3706039823)
- Wrap UnsatisfiedLinkError in IllegalStateException per error contract
  (comment #3706039855)
- Replace silent return with assumeTrue for native lib tests so skips
  are visible in CI reports (comment #3706039896)
- Rewrite activeCallbackCount test to exercise through JnaNativeBinding
  and assert binding.activeCallbacks (comment #3706039935)
- Add ABI name documentation to CallbackTestLib, fix byte return types
  in test interface (comment #3706039968)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Co-authored-by: Ed Burns <edburns@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

[Java] Embed Rust CLI runtime 4.4: JNA binding interface and implementation

3 participants