Skip to content

Add reportedClientSessionId to Rust session create/resume wire - #2366

Draft
em-gong wants to merge 1 commit into
mainfrom
em-gong-reported-client-session-id
Draft

Add reportedClientSessionId to Rust session create/resume wire#2366
em-gong wants to merge 1 commit into
mainfrom
em-gong-reported-client-session-id

Conversation

@em-gong

@em-gong em-gong commented Aug 20, 2026

Copy link
Copy Markdown

What

Threads a new optional reported_client_session_id through the Rust SDK's SessionConfig and ResumeSessionConfig, serialized as a flat top-level reportedClientSessionId on both the session.create and session.resume JSON-RPC wire.

Part of a 4-repo fix for CCA (Cloud Copilot Coding Agent) per-session AI-credit attribution. On steering/resume runs the wrong session id lands on X-Client-Session-Id, so AI-credit spend bills to the task session instead of the steering session. This field lets callers seed the runtime's client-session scalar (→ X-Client-Session-Id + telemetry) without touching the logical/registry session_id, which keys resume-reattach, permission hooks, and the workspace filesystem.

Semantics

  • Wire key (camelCase JSON): reportedClientSessionIdflat top-level, sibling of sessionId (not nested), on both create and resume.
  • Rust field: reported_client_session_id: Option<String>; builder: with_reported_client_session_id(impl Into<String>).
  • #[serde(skip_serializing_if = "Option::is_none")]absent/None emits nothing and the wire is byte-for-byte identical to today; the engine then falls back to session_id. Non-empty wins.

Flat top-level is required because the runtime consumer (copilot-agent-runtime#16469) forwards this via its standalone-jsonrpc UPDATE_OPTIONS_FORWARDED_KEYS allowlist, which reads a flat top-level param on both create_session and resume_session. Nesting it under a sub-object would break pickup.

Changes (Rust only)

  • SessionConfig + ResumeSessionConfig: new reported_client_session_id field (docs; Default/new initialize to None; included in the custom Debug impls).
  • with_reported_client_session_id(..) builder on each (mirrors with_client_name).
  • SessionCreateWire + SessionResumeWire: new field, skip_serializing_if = Option::is_none, camelCase, flat top-level sibling of sessionId.
  • Mapped through both into_wire().
  • Tests: absent ⇒ reportedClientSessionId omitted; present ⇒ appears top-level on create and resume (with sessionId unchanged).

Scope: Rust-only (TS intentionally out of scope)

CCA drives copilotd via copilotd bootstrap env vars → copilot-host (Rust) → this Rust SDK builder → closed wire. It does not convey this identity through the TS CopilotClient.createSession/resumeSession JSON-RPC param path, so a TS reportedClientSessionId option would be permanent dead surface for this use case. Any non-CCA TS parity is a separate future PR.

Consumer / release ordering

  • Runtime consumer: copilot-agent-runtime#16469.
  • This SDK must release before copilot-host can bump its pin and call .with_reported_client_session_id(..).

Validation

  • cargo test --all-features — new tests pass.
  • cargo +nightly-2026-04-14 fmt --check — clean.
  • cargo clippy --all-features --all-targets -- -D warnings — clean.

Thread a new optional `reported_client_session_id` through `SessionConfig`
and `ResumeSessionConfig` so callers can seed the runtime's client-session
scalar (X-Client-Session-Id + telemetry) without changing the logical
`session_id` used for resume-reattach, permission hooks, and the workspace
filesystem.

The field serializes as a flat top-level `reportedClientSessionId` sibling of
`sessionId` on both `session.create` and `session.resume`, matching the
runtime's UPDATE_OPTIONS_FORWARDED_KEYS allowlist. When absent it is omitted
via skip_serializing_if, so the wire is byte-for-byte unchanged; the engine
then falls back to `session_id`.

Co-authored-by: Copilot App <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.

2 participants