Add Rust SDK model allowlist support - #2512
Conversation
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>
There was a problem hiding this comment.
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
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
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_modelstoSessionConfigandResumeSessionConfigwith wire serialization asallowedModels. - Introduced
session.model.setAllowedModelsRPC 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.
| /// Restrict this session to the provided exact model IDs. | ||
| pub fn with_allowed_models<I, S>(mut self, models: I) -> Self | ||
| where | ||
| I: IntoIterator<Item = S>, | ||
| S: Into<String>, | ||
| { | ||
| self.allowed_models = Some(models.into_iter().map(Into::into).collect()); | ||
| self | ||
| } |
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>
|
Thanks for the contribution! I ran this against the real pinned CLI (v1.0.83-4) to validate the runtime side:
The 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. |
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. |

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
allowed_modelsfields and fluent builders toSessionConfigandResumeSessionConfig, serialized asallowedModelsand omitted when unrestricted.session.model.setAllowedModelsRPC request/result surface for replacing or clearing a running session's restriction.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_modelsCOPILOT_SKIP_CLI_DOWNLOAD=1 cargo test --all-features wire_flags_off_without_handlerscargo +nightly-2026-04-14 fmt --check