Skip to content

Commit 0bda4f4

Browse files
krukowCopilot
andcommitted
fix: wrap stdio in non-closing streams for child process mode
Prevents proto/disconnect from closing the JVM's global System/in and System/out when tearing down a child-process connection. Uses FilterInputStream/FilterOutputStream proxies with no-op close(). Addresses review feedback on PR #48. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 7e4dd6e commit 0bda4f4

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/github/copilot_sdk/client.clj

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,29 @@
526526
(let [conn (proto/connect (:stdout process) (:stdin process) (:state client))]
527527
(swap! (:state client) assoc :connection-io conn))))
528528

529+
(defn- non-closing-input-stream
530+
"Wrap an InputStream so that .close is a no-op.
531+
Prevents proto/disconnect from closing System/in."
532+
^java.io.InputStream [^java.io.InputStream in]
533+
(proxy [java.io.FilterInputStream] [in]
534+
(close [] nil)))
535+
536+
(defn- non-closing-output-stream
537+
"Wrap an OutputStream so that .close is a no-op.
538+
Prevents proto/disconnect from closing System/out."
539+
^java.io.OutputStream [^java.io.OutputStream out]
540+
(proxy [java.io.FilterOutputStream] [out]
541+
(close [] nil)))
542+
529543
(defn- connect-parent-stdio!
530-
"Connect via own stdio to a parent Copilot CLI process (child process mode)."
544+
"Connect via own stdio to a parent Copilot CLI process (child process mode).
545+
Wraps System/in and System/out in non-closing wrappers so that
546+
proto/disconnect does not close the JVM's global stdio streams."
531547
[client]
532548
(swap! (:state client) assoc :connection (proto/initial-connection-state))
533-
(let [conn (proto/connect System/in System/out (:state client))]
549+
(let [in (non-closing-input-stream System/in)
550+
out (non-closing-output-stream System/out)
551+
conn (proto/connect in out (:state client))]
534552
(swap! (:state client) assoc :connection-io conn)))
535553

536554
(defn- connect-tcp!

0 commit comments

Comments
 (0)