Skip to content

Conversation

@mostlygeek
Copy link
Owner

@mostlygeek mostlygeek commented Jun 15, 2025

move all default values for global, model and group configurations so it is all in one place. No functional changes for users but cleaned and made testing more rigid.

Summary by CodeRabbit

  • New Features

    • Default configuration values are now automatically applied when loading configs, including platform-specific defaults for certain fields.
  • Bug Fixes

    • Improved consistency and validation for configuration options, especially for port and health check settings.
    • Enforced stricter rules ensuring that if a proxy uses ${PORT}, the command must also include ${PORT}.
  • Tests

    • Added new tests to verify default configuration values and platform-specific behaviors on Windows and POSIX systems.
  • Refactor

    • Simplified the handling of default values and validation logic for configuration loading.
    • Removed implicit platform-specific stop commands and default health check endpoint fallbacks.

move all default values for global, model and group configurations
so it is all in one place.
@coderabbitai
Copy link

coderabbitai bot commented Jun 15, 2025

Warning

Rate limit exceeded

@mostlygeek has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 9 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between d9c0b5d and b9f0d33.

📒 Files selected for processing (6)
  • proxy/config.go (4 hunks)
  • proxy/config_posix_test.go (2 hunks)
  • proxy/config_test.go (1 hunks)
  • proxy/config_windows_test.go (2 hunks)
  • proxy/helpers_test.go (2 hunks)
  • proxy/process_test.go (1 hunks)

Walkthrough

This change introduces explicit default value handling for configuration structs, including platform-specific defaults during YAML unmarshaling. It centralizes and simplifies default assignments, enforces stricter validation for certain fields, and adds consistency checks for macro usage in model configurations. Associated tests are updated and expanded to verify these behaviors across platforms.

Changes

Files/Groups Change Summary
proxy/config.go Added UnmarshalYAML to ModelConfig for explicit defaults; centralized and simplified default assignments in LoadConfigFromReader; added stricter validation and macro consistency checks; removed some implicit fallback logic.
proxy/process.go Removed implicit Windows stop command fallback and default health endpoint assignment; simplified health check and stop command logic.
proxy/config_posix_test.go, proxy/config_windows_test.go Added new tests to verify default values and config loading behavior on POSIX and Windows platforms, including macro substitution and default group creation.
proxy/config_test.go Updated existing tests to explicitly check for default and empty values in config structs, reflecting new defaulting behavior.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ConfigLoader
    participant ModelConfig

    User->>ConfigLoader: LoadConfigFromReader(reader)
    ConfigLoader->>ConfigLoader: Set global defaults (HealthCheckTimeout, StartPort, LogLevel)
    ConfigLoader->>ModelConfig: UnmarshalYAML (with explicit defaults)
    ModelConfig-->>ConfigLoader: Model config with defaults
    ConfigLoader->>ConfigLoader: Validate fields (HealthCheckTimeout, StartPort)
    ConfigLoader->>ConfigLoader: Check macro consistency (Cmd/Proxy with ${PORT})
    ConfigLoader-->>User: Loaded & validated Config struct
Loading

Possibly related PRs

  • Automatic Port Numbers  #117: Refactors and centralizes default value handling for model and global config fields, including stricter validation and macro usage checks, which are directly modified in this PR.
  • Add macros to Configuration schema #149: Introduces a generalized macro substitution mechanism and validation, related to this PR's changes in macro handling and validation logic.
  • Add stopCmd to model configuration  #136: Originally introduced the CmdStop field and platform-specific default stop command logic, which this PR extends and refines.

Suggested labels

enhancement, configuration

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@mostlygeek mostlygeek added the configuration related to configuration of llama-swap label Jun 15, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2dc0ca0 and 407231c.

📒 Files selected for processing (5)
  • proxy/config.go (3 hunks)
  • proxy/config_posix_test.go (2 hunks)
  • proxy/config_test.go (2 hunks)
  • proxy/config_windows_test.go (2 hunks)
  • proxy/process.go (0 hunks)
💤 Files with no reviewable changes (1)
  • proxy/process.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: run-tests
🔇 Additional comments (4)
proxy/config.go (2)

34-60: LGTM! Clean implementation of explicit defaults.

The UnmarshalYAML method properly sets explicit defaults for all ModelConfig fields, including the platform-specific CmdStop for Windows. The use of a type alias to avoid recursion is the correct pattern.


142-160: Good refactoring of default value handling.

Setting defaults before unmarshaling and simplifying the validation logic makes the code cleaner and more maintainable. The minimum constraints (15s for health check timeout, >=1 for start port) are reasonable.

proxy/config_test.go (1)

80-113: Test updates correctly reflect the new default values.

The expected values now properly include the explicit defaults set during configuration loading, including LogLevel: "info" and empty slices for Env and Aliases fields.

proxy/config_posix_test.go (1)

45-84: Well-structured test for POSIX default values.

The test comprehensively validates all default configuration values on POSIX systems, including global defaults, model defaults, and the automatic ${PORT} replacement. The expectation of empty CmdStop is correct for non-Windows platforms.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
proxy/config.go (2)

34-60: Provide a POSIX fallback for CmdStop & revisit the unconditional proxy default

defaults.CmdStop is only initialised for Windows. On POSIX the field remains the empty string, which forces every model author to specify a stop command explicitly or rely on process.Kill later on. For symmetry with Windows (and to keep boilerplate low) consider a sane default such as kill -TERM ${PID}.

Likewise, setting Proxy to "http://localhost:${PORT}" unconditionally means every model inherits a proxy even when it does not expose an HTTP interface. This may surprise existing configurations that deliberately omitted the field. A safer pattern is to leave Proxy empty by default and selectively inject the placeholder only when ${PORT} appears in Cmd (the behaviour you previously had).

-       Proxy:            "http://localhost:${PORT}",
+       Proxy:            "",

and after unmarshalling, if Cmd contains ${PORT} and Proxy is still empty, populate it with the localhost template.


142-147: Minor: expose default values via constants

120, 5800, and "info" appear as magic literals. Defining them as typed constants (e.g. const DefaultHealthCheckTimeout = 120) improves discoverability, centralises future changes, and keeps the intent explicit throughout the codebase.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 407231c and d9c0b5d.

📒 Files selected for processing (3)
  • proxy/config.go (3 hunks)
  • proxy/config_posix_test.go (2 hunks)
  • proxy/config_test.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • proxy/config_test.go
  • proxy/config_posix_test.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: run-tests
🔇 Additional comments (2)
proxy/config.go (2)

208-211: Improved error message looks good

The new wording clearly communicates the ${PORT} mismatch between cmd and proxy. Nice catch.


153-160: ⚠️ Potential issue

startPort rejects the perfectly valid value 1

The validation enforces startPort > 1 (< 1 is rejected), so 1 is treated as invalid even though it is a non-privileged port on all platforms. If the intention is to forbid zero, change the check to:

- if config.StartPort < 1 {
+ if config.StartPort == 0 {

Otherwise update the error message to clarify that values below 2 are disallowed.

Likely an incorrect or invalid review comment.

@mostlygeek mostlygeek merged commit 4fa12a4 into main Jun 15, 2025
3 checks passed
@mostlygeek mostlygeek deleted the config-improvements branch June 15, 2025 19:32
mostlygeek added a commit that referenced this pull request Jun 18, 2025
PR #162 refactored the default configuration code. This
introduced a subtle bug where `env` became `[]string{}` instead of the
default of `nil`.

In golang, `exec.Cmd.Env == nil` means to use the "current process's
environment". By setting it to `[]string{}` as a default the Process's
environment was emptied out which caused an array of strange and
difficult to troubleshoot behaviour. See issues #168 and #169

This commit changes the behaviour to append model configured environment
variables to the default list rather than replace them.
mostlygeek added a commit that referenced this pull request Jun 18, 2025
Append custom env vars instead of replace in Process (#168, #169)

PR #162 refactored the default configuration code. This
introduced a subtle bug where `env` became `[]string{}` instead of the
default of `nil`.

In golang, `exec.Cmd.Env == nil` means to use the "current process's
environment". By setting it to `[]string{}` as a default the Process's
environment was emptied out which caused an array of strange and
difficult to troubleshoot behaviour. See issues #168 and #169

This commit changes the behaviour to append model configured environment
variables to the default list rather than replace them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

configuration related to configuration of llama-swap

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants