Skip to content

chore(config): tighten download thread limits#161

Open
Craun718 wants to merge 2 commits into
HydroRoll-Team:mainfrom
Craun718:chore/settings
Open

chore(config): tighten download thread limits#161
Craun718 wants to merge 2 commits into
HydroRoll-Team:mainfrom
Craun718:chore/settings

Conversation

@Craun718

@Craun718 Craun718 commented Jun 10, 2026

Copy link
Copy Markdown

Summary by Sourcery

Tighten and enforce limits on the launcher download thread configuration and ensure configs are sanitized on load and save.

Enhancements:

  • Constrain launcher download thread configuration to a 1–64 range with a lower default value.
  • Introduce a sanitize method on the launcher configuration and apply it when loading and saving configs to normalize values.
  • Update the UI config editor schema to validate downloadThreads within the new bounds.

@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

@Craun718 is attempting to deploy a commit to the retrofor Team on Vercel.

A member of the Team first needs to authorize it.

@sourcery-ai

sourcery-ai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Tightens and enforces bounds on the launcher’s download thread configuration across backend config loading/saving and the UI schema, while lowering the default value and normalizing saved configs.

Sequence diagram for saving config with sanitization and normalization

sequenceDiagram
    participant UiConfigEditor
    participant TauriMain as save_raw_config
    participant LauncherConfig
    participant SerdeJson as serde_json
    participant TokioFs as tokio_fs

    UiConfigEditor->>TauriMain: save_raw_config(state, content)
    TauriMain->>SerdeJson: from_str(content)
    SerdeJson-->>TauriMain: LauncherConfig
    TauriMain->>LauncherConfig: sanitize()
    TauriMain->>SerdeJson: to_string_pretty(LauncherConfig)
    SerdeJson-->>TauriMain: normalized_content
    TauriMain->>TokioFs: write(state.file_path, normalized_content)
    TokioFs-->>TauriMain: Result
    TauriMain-->>UiConfigEditor: Result
Loading

File-Level Changes

Change Details Files
Constrain download thread count at the config model level and during config load/save.
  • Updated the documented valid range for the download thread count from 1–128 to 1–64 and lowered the default from 32 to 8.
  • Added a sanitize method on the launcher config that clamps the download thread count into the 1–64 range.
  • Applied sanitize during config file load so deserialized configs are normalized in memory.
  • Applied sanitize when saving raw configs, then re-serialized the sanitized config in pretty JSON before writing to disk, replacing the raw content.
src-tauri/src/core/config.rs
src-tauri/src/main.rs
Validate the download thread range on the frontend.
  • Tightened the Zod schema for the config editor to require the download thread count to be between 1 and 64 inclusive.
packages/ui/src/components/config-editor.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot 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.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src-tauri/src/core/config.rs" line_range="130" />
<code_context>

+impl LauncherConfig {
+    pub fn sanitize(&mut self) {
+        self.download_threads = self.download_threads.clamp(1, 64);
+    }
+}
</code_context>
<issue_to_address>
**suggestion:** Avoid hardcoding the download thread bounds directly in sanitize to keep limits consistent across the codebase.

The 1 and 64 bounds are duplicated here, in the doc comment, and in the UI schema. Consider defining shared constants (e.g., `MIN_DOWNLOAD_THREADS` / `MAX_DOWNLOAD_THREADS`) and reusing them in `sanitize()` and any related logic to keep these limits consistent and easier to update.

Suggested implementation:

```rust
pub const MIN_DOWNLOAD_THREADS: usize = 1;
pub const MAX_DOWNLOAD_THREADS: usize = 64;

impl LauncherConfig {
    pub fn sanitize(&mut self) {
        self.download_threads = self
            .download_threads
            .clamp(MIN_DOWNLOAD_THREADS, MAX_DOWNLOAD_THREADS);
    }
}

```

```rust

```

To fully apply the suggestion across the codebase, also:
1. Update the doc comment that describes the valid range for `download_threads` to reference `MIN_DOWNLOAD_THREADS` and `MAX_DOWNLOAD_THREADS` (or ensure the text stays in sync with these values).
2. Update any UI schema or validation logic that currently hardcodes `1` and `64` for download thread bounds to instead use these shared constants, or otherwise centralize those limits so they derive from `MIN_DOWNLOAD_THREADS` and `MAX_DOWNLOAD_THREADS`.
</issue_to_address>

### Comment 2
<location path="src-tauri/src/main.rs" line_range="1653-1654" />
<code_context>
         serde_json::from_str(&content).map_err(|e| format!("Invalid JSON: {}", e))?;
+    new_config.sanitize();
+
+    let normalized_content =
+        serde_json::to_string_pretty(&new_config).map_err(|e| format!("Invalid JSON: {}", e))?;

     // Save to file
</code_context>
<issue_to_address>
**suggestion:** Use a more accurate error message when serialization of the config fails.

`map_err(|e| format!("Invalid JSON: {}", e))` is appropriate for `from_str`, but misleading for `to_string_pretty` since the JSON is already valid at that point. Use a different message (e.g. `"Failed to serialize config"`) so callers can distinguish parse errors from serialization failures.

```suggestion
    let normalized_content = serde_json::to_string_pretty(&new_config)
        .map_err(|e| format!("Failed to serialize config: {}", e))?;
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src-tauri/src/core/config.rs Outdated
Comment thread src-tauri/src/main.rs Outdated
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.

1 participant