Skip to content

Rust example in "Connecting to an external CLI server" does not compile (missing connection_token) #2141

Description

@examon

Summary

The Rust example under Connecting to an external CLI server constructs Transport::External { host, port }, but that variant has a third required field, connection_token: Option<String>. Copying the documented example into a project fails to compile.

Reproduction

Set the crate up exactly as the guide instructs:

cargo new copilot-demo && cd copilot-demo
cargo add github-copilot-sdk --features derive
cargo add tokio --features rt-multi-thread,macros

Paste the guide's Rust example into src/main.rs, in the #[tokio::main] async main the guide's own complete examples use:

use std::sync::Arc;

use github_copilot_sdk::handler::ApproveAllHandler;
use github_copilot_sdk::{Client, ClientOptions, SessionConfig, Transport};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut options = ClientOptions::default();
    options.transport = Transport::External {
        host: "localhost".to_string(),
        port: 4321,
    };
    let client = Client::start(options).await?;

    let session = client
        .create_session(SessionConfig::default().with_permission_handler(Arc::new(ApproveAllHandler)))
        .await?;
    let _ = session;
    Ok(())
}

Expected

The example compiles, like the guide's other Rust examples.

Actual

$ cargo build
error[E0063]: missing field `connection_token` in initializer of `github_copilot_sdk::Transport`
 --> src/main.rs:9:25
  |
9 |     options.transport = Transport::External {
  |                         ^^^^^^^^^^^^^^^^^^^ missing `connection_token`

For more information about this error, try `rustc --explain E0063`.
error: could not compile `copilot-demo` (bin "copilot-demo") due to 1 previous error

This is the only error in the snippet. Every other line resolves against the current API.

Cause

Transport::External is declared with three fields:

External {
    host: String,
    port: u16,
    connection_token: Option<String>,
},

The example predates the field: it was written when the variant had only host and port, and it was not updated when connection_token was added. The other Rust example that constructs this variant, in docs/setup/multi-tenancy.md, already passes connection_token: None.

Nothing catches this. Rust fenced blocks under docs/ are never extracted by scripts/docs-validation, because its LANGUAGE_MAP has no rust entry and unmapped fences are skipped silently, so there is no Rust job in the documentation validation workflow.

Suggested fix

Add connection_token: None, to the example. None is what this section calls for: the server it tells you to start, copilot --headless --port 4321, has no token, and reports so on startup.

Environment

  • github-copilot-sdk 1.0.8 (published crate); also reproduced against main at 7f1f8478
  • rustc 1.97.1, Linux x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions