Skip to content

Add Rust SDK model allowlist support - #2512

Merged
jpbufe3 merged 10 commits into
github:mainfrom
jpbufe3:jobufe-microsoft-rust-model-allowlist
Sep 16, 2026
Merged

jpbufe3 merged 10 commits into
github:mainfrom
jpbufe3:jobufe-microsoft-rust-model-allowlist

Conversation

@jpbufe3

@jpbufe3 jpbufe3 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Users need a host-controlled subset of model IDs to apply consistently when creating, resuming, and updating sessions. This adds the Rust SDK contract needed to pass that restriction to the runtime without duplicating runtime validation or policy logic.

Summary

  • Add optional allowed_models fields and fluent builders to SessionConfig and ResumeSessionConfig, serialized as allowedModels and omitted when unrestricted.
  • Add the generated typed session.model.setAllowedModels RPC request/result surface for replacing or clearing a running session's restriction.
  • Cover defaults, Debug output, create/resume wire conversion, request serialization, method routing, and typed result deserialization.

The SDK preserves exact caller-provided IDs; the runtime remains responsible for validation, policy intersection, fallback selection, and enforcement across child, sub-agent, Auto, and remote execution paths.

Testing

  • COPILOT_SKIP_CLI_DOWNLOAD=1 cargo test --all-features allowed_models
  • COPILOT_SKIP_CLI_DOWNLOAD=1 cargo test --all-features wire_flags_off_without_handlers
  • cargo +nightly-2026-04-14 fmt --check

Expose create/resume allowlists and the generated live-session replacement RPC with focused contract tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 4, 2026 01:38
@jpbufe3
jpbufe3 requested a review from a team as a code owner September 4, 2026 01:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review tier: Lite
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity rust/​src/​types.rs — This builder will happily accept an empty iterator and serialize an explicit empty allowlist, but…
What changed in this PR

Adds Rust SDK support for a host-controlled allowlist of model IDs, enabling consistent restrictions during session create/resume and while updating a running session via a new RPC.

Changes:

  • Added allowed_models to SessionConfig and ResumeSessionConfig with wire serialization as allowedModels.
  • Introduced session.model.setAllowedModels RPC surface with typed request/result structs and routing constant.
  • Added/updated tests covering serialization, wire conversion, method routing, and result deserialization.
File Description
rust/​src/​types.rs Adds allowed_models to session configs, builders, Debug/Default, and wire conversion; adds unit tests.
rust/​src/​wire.rs Extends session create/resume wire structs to carry allowed_models.
rust/​src/​generated/​api_types.rs Adds RPC method constant and typed request/result DTOs for setAllowedModels.
rust/​src/​generated/​rpc.rs Adds typed SessionRpcModel::set_allowed_models method calling the new wire RPC.
rust/​tests/​session_test.rs Adds integration-style test verifying method name, params, and deserialization for replace/clear flows.
rust/​tests/​api_types_test.rs Adds contract/serialization tests for the new request/result types.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread rust/src/types.rs
jpbufe3 and others added 2 commits September 3, 2026 22:28
Preserve current main changes while resolving the generated API test conflict and clarify that empty model allowlists are rejected by the runtime.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Augment the Rust API schema until the pinned CLI release includes the paired runtime contract, while remaining a no-op once the method ships.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@SteveSandersonMS

Copy link
Copy Markdown
Contributor

Thanks for the contribution! I ran this against the real pinned CLI (v1.0.83-4) to validate the runtime side:

  • The real api.schema.json shipped in this CLI release has no allowedModels/setAllowedModels fields at all.
  • I started copilot --server --stdio and sent a live session.model.setAllowedModels JSON-RPC request — the runtime returns {"error":{"code":-32601,"message":"Unhandled method session.model.setAllowedModels"}}.
  • Setting allowedModels on session.create is silently ignored by the runtime, so SessionConfig::with_allowed_models(...) currently gives callers a false sense that a restriction is being enforced.

The addModelSetAllowedModelsRpc() function added to scripts/codegen/rust.ts hand-authors a schema fragment ahead of the real runtime contract, rather than generating from the shipped api.schema.json. That's not how this repo's codegen pipeline is meant to work, and it also means this capability is currently Rust-only rather than generated consistently for all 6 SDKs the way other schema-driven features are.

Could you hold off until the corresponding runtime contract actually ships in a released CLI, then resubmit generated purely from the real schema (and ideally across all SDKs, since this isn't Rust-specific)? For tracking, I've moved this to draft - please mark as ready to review when appropriate.

@SteveSandersonMS
SteveSandersonMS marked this pull request as draft September 4, 2026 08:06
@jpbufe3

jpbufe3 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Could you hold off until the corresponding runtime contract actually ships in a released CLI, then resubmit generated purely from the real schema (and ideally across all SDKs, since this isn't Rust-specific)?

Thanks for validating this against the pinned CLI. Agreed: this should not merge while the shipped runtime ignores the create/resume field and does not implement the live RPC. I will keep the PR in draft and retain the branch only for coordination with the paired runtime/app work. Once the contract is in a released CLI, the SDK surface should be regenerated from that shipped schema and evaluated consistently across the SDKs.

jpbufe3 and others added 2 commits September 4, 2026 07:37
Resolve the generated API test import conflict while preserving both Auto-tier and allowlist coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preserve sandbox bypass, session detach, Auto-tier, and allowlist generated API test coverage while resolving the latest base conflict.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jpbufe3

jpbufe3 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

https://github.com/github/copilot-agent-runtime/pull/18943has merged and is being staged for prerelease! Reopening for review cc @SteveSandersonMS

@jpbufe3
jpbufe3 marked this pull request as ready for review September 8, 2026 12:48
@SteveSandersonMS

Copy link
Copy Markdown
Contributor

Thanks for flagging that the runtime PR merged — I re-checked before proceeding.

I re-validated against the latest shipped CLI release (v1.0.84-1, published after your comment) as well as the versions in between (v1.0.83-5, v1.0.83, v1.0.84-0): none of their api.schema.json files contain allowedModels or setAllowedModels. I also ran the actual v1.0.84-1 binary in --server --stdio mode and sent a live session.model.setAllowedModels request — it still returns:

{"error":{"code":-32601,"message":"Unhandled method session.model.setAllowedModels"}}

So github/copilot-agent-runtime#18943 merging is good progress, but per your own note it's only "staged for prerelease" — it hasn't reached a released CLI build yet, and this repo's pinned COPILOT_CLI_VERSION (nodejs/src/cliVersion.ts) is unchanged. Since this SDK PR still depends on a runtime contract that hasn't shipped, I'm moving it back to draft rather than asking you to do so. Please mark it ready for review once a released CLI (bumped in cliVersion.ts) actually carries the session.model.setAllowedModels contract in its schema, so the SDK surface can be regenerated from the real schema instead of the hand-authored one in scripts/codegen/rust.ts.

@SteveSandersonMS
SteveSandersonMS marked this pull request as draft September 8, 2026 13:22
jpbufe3 and others added 4 commits September 8, 2026 10:36
Pin CLI 1.0.84-2 and regenerate the shared and Java SDK contracts. Remove the temporary Rust schema augmentation, cover the generated Java live allowlist API, and adapt affected test constructors.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preserve CLI 1.0.84-2 while adopting the release-based Java schema loader and retaining both allowlist and upstream session coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Reconcile with SDK main and regenerate canonical release contracts while preserving typed Rust create/resume allowlists and live-session API coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Retain typed Rust create/resume allowlists and live-session API coverage while adopting canonical released contracts and current SDK main.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jpbufe3
jpbufe3 marked this pull request as ready for review September 15, 2026 16:13
@jpbufe3

jpbufe3 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

@SteveSandersonMS SDK main now pins the published CLI 1.0.84-8 prerelease, whose canonical schema includes session.model.setAllowedModels. This branch is reconciled with main, the temporary schema augmentation is gone, and the owned generated contracts reproduce from that release. The typed Rust create/resume allowlists and live-session replacement/clear API are ready for review; focused validation passed.

Covers replace, explicit-empty rejection, and clear against the real
bundled CLI (v1.0.84-8), which now ships the runtime contract. The
existing tests only exercised the RPC against a mock JSON-RPC server;
this closes the gap by validating actual runtime behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@SteveSandersonMS

Copy link
Copy Markdown
Contributor

Re-validated against the currently pinned CLI (v1.0.84-8), which now genuinely ships the runtime contract:

  • api.schema.json in v1.0.84-8 includes session.model.setAllowedModels, ModelSetAllowedModelsRequest/Result.
  • Live JSON-RPC against the real binary confirms correct behavior: replacing the allowlist returns the applied/effective policy, an explicit empty list is rejected ("Host allowedModels must contain at least one model id"), and omitting/null clears the restriction.
  • The temporary schema augmentation in scripts/codegen/rust.ts is gone, and the generated RPC surface (types, method routing) is now produced purely from the shipped schema — confirmed via git merge-tree, no conflicts with current main.
  • The remaining Rust-specific diff (allowed_models on SessionConfig/ResumeSessionConfig plus builders) is small and reasonable.

One gap: the existing tests (api_types_test.rs, session_test.rs) only exercise this against a mocked JSON-RPC server, not the real runtime. Since this repo's convention is to have real E2E coverage for runtime-backed behavior, I added should_replace_and_clear_the_host_model_allowlist_on_a_live_session in rust/tests/e2e/session.rs, which drives the actual bundled CLI through replace → reject-empty → clear. I ran it locally against the real v1.0.84-8 CLI and it passes. Pushed as a follow-up commit on this branch.

cargo +nightly-2026-04-14 fmt --check and the targeted test suite pass. Approving and enabling auto-merge.

@SteveSandersonMS SteveSandersonMS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving — runtime contract verified live against pinned CLI v1.0.84-8, codegen is clean, and I added a real E2E test for the setAllowedModels RPC (see comment above).

@jpbufe3
jpbufe3 added this pull request to the merge queue Sep 16, 2026
Merged via the queue into github:main with commit f60f9d4 Sep 16, 2026
88 of 90 checks passed
@jpbufe3
jpbufe3 deleted the jobufe-microsoft-rust-model-allowlist branch September 16, 2026 01:09
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.

3 participants