You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement the in-process (FFI) transport for the Python SDK at parity with
the .NET/Rust/TypeScript implementations. Instead of spawning the runtime as
a child process, the SDK loads the runtime's native shared library into the
host process (via stdlib ctypes) and drives JSON-RPC over its C ABI; the
native host spawns the residual worker itself.
- api: RuntimeConnection.for_inprocess() + InProcessRuntimeConnection; add a
per-connection env field to ChildProcessRuntimeConnection (stdio/tcp).
- default transport: honor COPILOT_SDK_DEFAULT_CONNECTION=inprocess.
- ffi host: new copilot/_ffi_runtime_host.py (ctypes bindings, outbound
callback with drain/lifetime guarding, RTLD_NOW load, process-like adapter
so JsonRpcClient works unchanged).
- client wiring: start/stop/force_stop route through the FFI host.
- env guards: reject env/telemetry/working_directory with in-process, and
reject env set on both client and connection for child-process transports.
- bundling: fetch the native runtime library only opt-in — via
`download-runtime --in-process` or lazily on first in-process use; never for
stdio/tcp users.
- tests: in-process E2E smoke test; harness honors the inprocess default with
env mirroring + cwd redirect; conftest neutralizes ambient HMAC for
in-process; CI transport matrix cell.
- docs: python/README.md in-process section; APIs flagged experimental.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a96d1a82-c80e-40f1-a3df-a9708429b68b
`RuntimeConnection.for_uri(...)`, or `RuntimeConnection.for_inprocess(...)`.
200
+
Defaults to a stdio connection with the bundled binary.
189
201
-`working_directory` (str | None): Working directory for the CLI process (default: current dir).
190
202
-`log_level` (str): Log level (default: "info").
191
203
-`env` (dict | None): Environment variables for the CLI process.
@@ -204,6 +216,49 @@ All options are kw-only parameters:
204
216
-`RuntimeConnection.for_stdio(path=None, args=None)` — spawn a local CLI process and talk over stdio.
205
217
-`RuntimeConnection.for_tcp(port=0, connection_token=None, path=None, args=None)` — spawn a local CLI in TCP mode.
206
218
-`RuntimeConnection.for_uri(url, connection_token=None)` — connect to an existing CLI server (e.g. `"localhost:8080"`).
219
+
-`RuntimeConnection.for_inprocess(path=None, args=None)` — host the runtime in-process via its native C ABI (FFI). See [In-process (FFI) transport](#in-process-ffi-transport).
220
+
221
+
Child-process connections (`for_stdio`/`for_tcp`) also expose a per-connection
222
+
`env` field for the spawned process. Set it on the returned connection instead of
223
+
the client-level `env` — setting both raises:
224
+
225
+
```python
226
+
conn = RuntimeConnection.for_stdio()
227
+
conn.env = {"MY_VAR": "value"}
228
+
client = CopilotClient(connection=conn) # do NOT also pass env=... here
229
+
```
230
+
231
+
### In-process (FFI) transport
232
+
233
+
> ⚠️ **Experimental.** The in-process transport loads the runtime's native shared
234
+
> library into your process and drives JSON-RPC over its C ABI (via stdlib
235
+
> `ctypes`), instead of spawning a child process. The native host spawns the
236
+
> residual worker itself.
237
+
238
+
```python
239
+
from copilot import CopilotClient, RuntimeConnection
0 commit comments