github/copilot-sdk · error

env is not supported with RuntimeConnection.forInProcess()…

Error message

env is not supported with RuntimeConnection.forInProcess(): the in-process transport loads the native runtime into the shared host process, whose single environment block cannot carry per-client values. Set the variables on the host process environment instead.

What it means

When the caller supplies a local_session_id to create_session, the client generates the session id client-side and asks the server to use it. _register_inline() raises this RuntimeError if the server's session.create response returns a different sessionId than requested, meaning the server ignored or overrode the caller-supplied id.

Solutions

  1. Omit local_session_id and use the server-assigned sessionId from the returned session.
  2. Use the non-cloud/local session path where client-supplied ids are honored.
  3. Align CLI/server versions so session.create supports caller-requested sessionIds.
  4. Ensure the requested id is unique/valid if the server replaces colliding ids.

Example fix

// before
session = await client.create_session(local_session_id="fixed-id")
// after
session = await client.create_session()  # use session.session_id from the server
Defensive patterns

Strategy: try-catch

Type guard

def returned_requested_id(response: dict, local_session_id) -> bool:
    return local_session_id is None or response.get("sessionId") == local_session_id

Try / catch

try:
    session = await client.create_session(local_session_id=my_id)
except RuntimeError as e:
    if "returned sessionId" in str(e):
        session = await client.create_session()  # accept server-assigned id
        my_id = session.session_id

Prevention

When it happens

Trigger: Calling create_session(..., local_session_id="my-id") while the connected server assigns its own session ids (e.g. a cloud session path where the server reserves id assignment, or a server build that doesn't honor client-supplied ids).

Common situations: Passing a local_session_id with a cloud session backend; server/client version mismatch where local id support differs; duplicate/conflicting ids causing the server to reissue one.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/95ebc5e9ae153587. Report an issue: GitHub.

Appendix: source

Thrown at nodejs/src/client.ts:621

        if (
            conn.kind === "uri" &&
            (options.gitHubToken !== undefined || options.useLoggedInUser !== undefined)
        ) {
            throw new Error(
                "gitHubToken and useLoggedInUser cannot be used with RuntimeConnection.forUri (external server manages its own auth)"
            );
        }
        if (conn.kind === "inprocess" && options.workingDirectory !== undefined) {
            throw new Error(
                "workingDirectory is not supported with RuntimeConnection.forInProcess(): the in-process " +
                    "transport hosts the runtime in this process, so honoring it would require mutating the " +
                    "shared process-global cwd. Change the host process's working directory before " +
                    "constructing the client instead."
            );
        }
        if (conn.kind === "inprocess" && options.env !== undefined) {
            throw new Error(
                "env is not supported with RuntimeConnection.forInProcess(): the in-process transport loads " +
                    "the native runtime into the shared host process, whose single environment block cannot " +
                    "carry per-client values. Set the variables on the host process environment instead."
            );
        }
        if (conn.kind === "inprocess" && options.telemetry !== undefined) {
            throw new Error(
                "telemetry is not supported with RuntimeConnection.forInProcess(): telemetry configuration " +
                    "is lowered to environment variables read by native runtime code running in the shared " +
                    "host process, so per-client telemetry cannot be honored in-process. Configure telemetry " +
                    "via the host process environment, or use a child-process transport."
            );
        }
        if (
            (conn.kind === "stdio" || conn.kind === "tcp") &&
            conn.env !== undefined &&
            options.env !== undefined
        ) {

View on GitHub (pinned to cd8cf15dc3)