Skip to content

internal/config,server: add setParamsByMatch request filter - #934

Open
asf0 wants to merge 2 commits into
mostlygeek:mainfrom
asf0:reasoning-effort-filter
Open

internal/config,server: add setParamsByMatch request filter#934
asf0 wants to merge 2 commits into
mostlygeek:mainfrom
asf0:reasoning-effort-filter

Conversation

@asf0

@asf0 asf0 commented Jul 19, 2026

Copy link
Copy Markdown

Set request parameters when a request field matches a value. Rules match on the request body rather than the model ID, so clients that send a fixed model and vary a separate field can change behaviour between requests without triggering a model swap.

macros:
  reasoning_rules:
    - key: reasoning_effort
      match: none
      set:
        chat_template_kwargs:
          enable_thinking: false
    - key: reasoning_effort
      match: high
      set:
        chat_template_kwargs:
          enable_thinking: true
        thinking_budget_tokens: 8192

models:
  my-model:
    filters:
      setParamsByMatch: ${reasoning_rules}
  • rules run in order after stripParams and before setParams/setParamsByID, which keep the final say
  • every matching rule applies, so a later rule overrides an earlier one
  • object values merge into an existing request object, so chat_template_kwargs the client already sent are preserved rather than replaced
  • match compares against the field's string form, so JSON booleans and numbers must be quoted
  • protected params like model cannot be matched on or set
  • supported in both model and peer filters, validated at config load

Macros can now hold maps and lists so several models can share one rule set. Without this a shared rule list needs a stray top-level YAML anchor key. Structured macros are only valid as a whole value; interpolating one into a string is a load-time error. This changes two existing tests that asserted macros were scalar-only.

Replaces the earlier reasoning-specific filter in this PR per the discussion in #958.

Fixes #958

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 8ea41d4c-8724-4a46-a3db-fe7a6ded64fa

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 19, 2026

Copy link
Copy Markdown

Greptile Summary

Adds setParamsByMatch, a new request filter that applies parameter overrides when a top-level request field equals a configured string value. This allows clients that send a fixed model field and vary another field (e.g. reasoning_effort) to change model behaviour without triggering a model swap. Macros are extended to support map and list values so a shared rule set can be referenced by multiple models.

  • MatchRule struct with config-load validation (key regex, protected-param guard, non-empty set) is wired into both model and peer filter pipelines; it runs after stripParams and before setParams/setParamsByID.
  • setMergedParam performs a one-level-deep merge: when both the configured value and the existing request field are objects, sub-keys are written individually via sjson dotted paths so client-sent sibling keys are preserved.
  • Macro handling is refactored to propagate errors from substituteMacroList and block non-scalar macros from being interpolated into strings while still allowing whole-value substitution.

Confidence Score: 5/5

The change is safe to merge. All three findings are edge-case nits with no impact on the documented, tested use cases.

The core logic is well-tested, protected-param checks are in place at both config-load and runtime, and the match/merge paths are covered by targeted test cases. The three findings (missing | escape in sub-key paths, one-level-only merge for nested objects, and null-vs-empty-string ambiguity in match) are all off the happy path and do not affect the primary reasoning-effort use case.

Files Needing Attention: internal/server/filters.go — the three nits are concentrated here; the rest of the changed files are straightforward.

Important Files Changed

Filename Overview
internal/server/filters.go Core runtime implementation of setParamsByMatch; applySetParamsByMatch and setMergedParam are well-structured, but escapePathSegment omits `
internal/config/filters.go Adds MatchRule struct, Validate(), and SanitizedSet(); key regex, protected-param checks, and sorted output all look correct.
internal/config/macros.go Extends macros to support map/list values, adds isScalarMacroValue guard, and propagates errors from substituteMacroList; self-reference detection via yaml.Marshal is a reasonable heuristic.
internal/config/load.go Adds validateSetParamsByMatch hook that validates both model and peer rules at config load time; ordering and error wrapping look correct.
internal/config/config_test.go Updates two pre-existing tests that assumed array/map macros were invalid, and adds comprehensive TestConfig_SetParamsByMatchValidation and TestConfig_StructuredMacros suites.
internal/server/filters_test.go Adds TestServer_ApplySetParamsByMatch with 12 sub-tests covering the documented use case, merge behaviour, ordering, protected params, and ordering relative to stripParams/setParams.
config-schema.json Adds setParamsByMatch array schema for both model and peer filters; also extends the macro value schema to allow object and array types.
internal/config/filters_test.go Adds TestFilters_MatchRuleValidate and TestFilters_MatchRuleSanitizedSet covering edge cases for key validation and protected-param removal.

Reviews (2): Last reviewed commit: "internal/config,server: add setParamsByM..." | Re-trigger Greptile

Comment thread internal/server/filters.go Outdated
Set request parameters when a request field matches a value. Rules match
on the request body rather than the model ID, so clients that send a
fixed model and vary a separate field can change behaviour between
requests without triggering a model swap.

- rules run in order after stripParams and before setParams/setParamsByID
- object values merge into an existing request object so keys the client
  already sent are preserved
- protected params like model cannot be matched on or set
- macros can now hold maps and lists, letting several models share one
  rule set; structured macros are only valid as a whole value

fixes mostlygeek#958
@asf0
asf0 force-pushed the reasoning-effort-filter branch from a9b9538 to 600cc8b Compare July 28, 2026 17:57
@asf0 asf0 changed the title internal/config,server: add reasoning filter for effort translation internal/config,server: add setParamsByMatch request filter Jul 28, 2026
@asf0
asf0 marked this pull request as ready for review July 28, 2026 18:02
Add a reusable macroReference definition and let model and peer
setParamsByMatch validate as either the rule array or a whole-value
macro string, so editors no longer flag ${rules} as a type error.
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.

Translate reasoning-effort field for clients that can't vary the model ID (Open WebUI, OpenCode)

1 participant