Skip to content

Rust bug fixes & changes#560

Open
nenad1002 wants to merge 5 commits intomainfrom
nebanfic/rust-stuff
Open

Rust bug fixes & changes#560
nenad1002 wants to merge 5 commits intomainfrom
nebanfic/rust-stuff

Conversation

@nenad1002
Copy link
Copy Markdown

@nenad1002 nenad1002 commented Mar 27, 2026

Part 1 of Rust changes (have part 2 but don't have time to test it now).

This is mostly improving perf by reducing cloning and fixing some bugs + making code more readable (avoiding early returns).

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
foundry-local Ready Ready Preview, Comment Mar 27, 2026 10:39pm

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors parts of the Rust SDK to reduce unnecessary cloning (notably around model IDs and model variants), improves error message ergonomics, and hardens streaming UTF-8 decoding behavior.

Changes:

  • Switch ChatClient::new / AudioClient::new to take &str and clone internally only once.
  • Store Model variants as Arc<ModelVariant> to avoid cloning full ModelVariant values, and adjust catalog construction accordingly.
  • Improve ModelLoadManager branching for external service vs core commands, and make streaming callback decoding resilient to invalid UTF-8.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
sdk/rust/src/openai/chat_client.rs Constructor now accepts &str and owns via to_owned()
sdk/rust/src/openai/audio_client.rs Constructor now accepts &str and owns via to_owned()
sdk/rust/src/model_variant.rs Client creation avoids cloning model id String
sdk/rust/src/model.rs Variants stored as Vec<Arc<ModelVariant>>; selection and client creation updated
sdk/rust/src/detail/model_load_manager.rs Fix control flow to avoid always calling core load/unload when external URL is set; simplify parsing
sdk/rust/src/detail/core_interop.rs Streaming UTF-8 decode now skips invalid sequences to prevent buffer growth
sdk/rust/src/configuration.rs Refactor optional param insertion logic (currently introduces a compile-time partial-move issue)
sdk/rust/src/catalog.rs Avoid cloning ModelVariant; improve “available” lists in errors; adjust model build logic
Comments suppressed due to low confidence (1)

sdk/rust/src/configuration.rs:207

  • Configuration::new moves fields out of config into optional_fields and then later accesses config.additional_settings / config.logger. This is a partial-move and will not compile. Consider destructuring config into local variables up front (including additional_settings and logger) or using take() on those fields before moving the others, then build optional_fields from the locals.
        let optional_fields = [
            ("AppDataDir", config.app_data_dir),
            ("ModelCacheDir", config.model_cache_dir),
            ("LogsDir", config.logs_dir),
            ("LogLevel", config.log_level.map(|l| l.as_core_str().into())),
            ("WebServiceUrls", config.web_service_urls),
            ("WebServiceExternalUrl", config.service_endpoint),
            ("FoundryLocalCorePath", config.library_path),
        ];

        for (key, value) in optional_fields {
            if let Some(v) = value {
                params.insert(key.into(), v);
            }
        }

        if let Some(extra) = config.additional_settings {
            params.extend(extra);
        }

        Ok((Self { params }, config.logger))
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nenad1002 nenad1002 marked this pull request as ready for review March 27, 2026 23:18
@nenad1002 nenad1002 requested a review from samuel100 March 27, 2026 23:18
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