Skip to content

Allow regular model IDs in Matrix DSL#715

Open
spicyneuron wants to merge 3 commits into
mostlygeek:mainfrom
spicyneuron:matrix-ids
Open

Allow regular model IDs in Matrix DSL#715
spicyneuron wants to merge 3 commits into
mostlygeek:mainfrom
spicyneuron:matrix-ids

Conversation

@spicyneuron

Copy link
Copy Markdown

While short vars for matrix logic seemed convenient at first, I found that maintaining another set of model ID to be more cumbersome than expected in practice. Especially with long, frequently updated model lists.

This PR makes vars optional and lets matrix sets use either vars or normal model IDs. Using YAML's multiline syntax, I think this is just as readable as the var-based one-liners:

matrix:
  sets:
    default: >
      gemma4-4b
      & (gemma4-31 | qwen3.6-27 | qwen3.6-35)
      & (minimax2.7 | qwen3.5-397)

Also:

  • evict_costs works with either vars or model IDs.
  • Slightly relaxes matrix validation to support common model ID chars like / and :.

References

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c344177c-a303-4ed9-bf59-cfec675adcfc

📥 Commits

Reviewing files that changed from the base of the PR and between b56445c and b8e9487.

📒 Files selected for processing (1)
  • proxy/config/matrix.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • proxy/config/matrix.go

Walkthrough

Matrix vars were made optional in the schema and docs; matrix validation now accepts and resolves direct model IDs alongside var aliases, with deduplication and updated error messages. The DSL tokenizer permits : in identifiers and tests/docs/examples were updated accordingly.

Changes

Cohort / File(s) Summary
Configuration schema & examples
config-schema.json, config.example.yaml, docs/configuration.md
Removed vars from required fields and updated docs/comments to state sets and evict_costs may reference either optional vars aliases or direct model IDs.
Matrix validation & resolver
proxy/config/matrix.go
Refactored validation into helpers (validateMatrixVars, validateEvictCosts), added identifier resolution (resolveMatrixIdent, resolveMatrixCombo), changed error wording to "unknown model ID", and added dedup-and-sort behavior for resolved sets.
DSL tokenizer
proxy/config/matrix_dsl.go
Expanded identifier character set to accept colon (:) inside identifiers.
Tests: DSL tokenization
proxy/config/matrix_dsl_test.go
Added testcase ensuring identifiers with / and : are tokenized as single tokIdent.
Tests: matrix validation
proxy/config/matrix_test.go
Updated expectations to accept direct model IDs, adjusted error strings, added coverage for deduplication, resolution conflicts, and YAML loading behavior regarding model aliases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.79% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check ❓ Inconclusive Issue #699 requests relaxing matrix variable key constraints to allow longer, descriptive names with underscores. However, the PR makes vars entirely optional and allows direct model IDs instead, which is a different approach than just relaxing var constraints. Clarify whether making vars optional satisfies issue #699's intent. If the goal was to allow longer var names (e.g., 'large_llms'), verify this is supported; if not, additional var validation updates may be needed.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Allow regular model IDs in Matrix DSL' directly and accurately summarizes the main change: enabling model IDs to be used directly in matrix sets instead of requiring short variable aliases.
Description check ✅ Passed The description explains the motivation (maintenance burden of separate var IDs), demonstrates the new capability with a YAML example, and lists additional features like evict_costs support and relaxed validation.
Out of Scope Changes check ✅ Passed The changes focus on making vars optional, allowing direct model IDs in matrix DSL, updating evict_costs handling, and relaxing validation for model ID characters (/, :). All changes align with the stated objectives of supporting model IDs directly in matrix sets.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
config-schema.json (1)

335-344: ⚠️ Potential issue | 🟠 Major

Loosen the matrix.vars schema; it still enforces the old 1-8 alnum rule.

The description and propertyNames.pattern still reject keys like large_llms, so schema-backed validation in editors/CI will keep flagging the exact configs that issue #699 is trying to allow.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@config-schema.json` around lines 335 - 344, The schema for matrix.vars
currently enforces the old alphanumeric 1-8 rule via propertyNames.pattern;
update that pattern to allow underscores and a longer name length (e.g. change
propertyNames.pattern to "^[a-zA-Z0-9_]{1,64}$") and update the description to
reflect that keys may include underscores and be longer (e.g. "Keys must be
alphanumeric or underscore, 1-64 characters"). Keep the rest of the object
(type, minProperties, additionalProperties) unchanged so sets and evict_costs
continue to accept vars or real model IDs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@proxy/config/matrix.go`:
- Around line 168-175: The code currently allows matrix.Var keys to shadow real
model IDs causing ambiguous resolution in resolveMatrixIdent; instead add a
validation step that rejects collisions: in the matrix config validation routine
(the function that validates MatrixConfig against the models map) iterate over
each key in MatrixConfig.Var and if that key exists in the models map (the
models map of ModelConfig), return a clear validation error stating the
conflicting identifier so configs like vars.g and model id g are disallowed;
keep resolveMatrixIdent behavior unchanged once collision checks are in place.
- Around line 144-152: validateMatrixVars currently enforces the old short
alphanumeric-only rule via varKeyPattern and rejects names like "large_llms";
update the validator to accept longer, underscore-containing keys by loosening
varKeyPattern (e.g., allow underscores and increase max length) and adjust the
error message accordingly, ensuring you update uses of matrix.Var and any
related schema/tests/docs to reflect the new allowed pattern; keep the model
existence check (models map lookup) unchanged.

---

Outside diff comments:
In `@config-schema.json`:
- Around line 335-344: The schema for matrix.vars currently enforces the old
alphanumeric 1-8 rule via propertyNames.pattern; update that pattern to allow
underscores and a longer name length (e.g. change propertyNames.pattern to
"^[a-zA-Z0-9_]{1,64}$") and update the description to reflect that keys may
include underscores and be longer (e.g. "Keys must be alphanumeric or
underscore, 1-64 characters"). Keep the rest of the object (type, minProperties,
additionalProperties) unchanged so sets and evict_costs continue to accept vars
or real model IDs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0bc5caac-5f7b-443e-8589-f72339b24b2a

📥 Commits

Reviewing files that changed from the base of the PR and between 5bae33a and b56445c.

📒 Files selected for processing (7)
  • config-schema.json
  • config.example.yaml
  • docs/configuration.md
  • proxy/config/matrix.go
  • proxy/config/matrix_dsl.go
  • proxy/config/matrix_dsl_test.go
  • proxy/config/matrix_test.go

Comment thread proxy/config/matrix.go
Comment on lines +144 to +152
func validateMatrixVars(matrix MatrixConfig, models map[string]ModelConfig) error {
for id, modelName := range matrix.Var {
if !varKeyPattern.MatchString(id) {
return fmt.Errorf("var key %q must be alphanumeric and 1-8 characters", id)
}
if _, exists := models[modelName]; !exists {
return fmt.Errorf("var key %q references unknown model %q", id, modelName)
}
}

@coderabbitai coderabbitai Bot Apr 28, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

This still preserves the legacy vars restriction from issue #699.

validateMatrixVars continues to reject names like large_llms, so the linked objective of allowing longer descriptive keys with underscores is still unmet at runtime. Please loosen this validator and keep the schema/tests/docs in sync.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@proxy/config/matrix.go` around lines 144 - 152, validateMatrixVars currently
enforces the old short alphanumeric-only rule via varKeyPattern and rejects
names like "large_llms"; update the validator to accept longer,
underscore-containing keys by loosening varKeyPattern (e.g., allow underscores
and increase max length) and adjust the error message accordingly, ensuring you
update uses of matrix.Var and any related schema/tests/docs to reflect the new
allowed pattern; keep the model existence check (models map lookup) unchanged.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Goal of this PR is to add support for model IDs, not change existing restrictions on vars. These are two separate code paths. To clarify, the relaxed validation was referring to:

https://github.com/mostlygeek/llama-swap/pull/715/changes#diff-08fd4e5e329e389732ac7b0625fe7567b218b564ed54f075f0d097aae9cbe705

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@spicyneuron, thank you for the clarification! You're right — the "relaxed validation" in the PR description refers to the changes in matrix_dsl.go (allowing / and : in DSL identifiers so real model IDs can be used directly), not to the varKeyPattern governing vars keys. These are indeed separate code paths. My comment was incorrect, and I apologize for the noise.


✏️ Learnings added
Learnt from: spicyneuron
Repo: mostlygeek/llama-swap PR: 715
File: proxy/config/matrix.go:144-152
Timestamp: 2026-04-28T01:43:14.083Z
Learning: In the llama-swap project, PR `#715` relaxes matrix DSL tokenization (in `proxy/config/matrix_dsl.go`) to accept `/` and `:` in identifiers so real model IDs can be used directly in DSL expressions. The `varKeyPattern` in `proxy/config/matrix.go` (which enforces the 1–8 alphanumeric constraint on `vars` keys) is intentionally left unchanged by this PR — changing `vars` key restrictions is a separate concern tracked by issue `#699`.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: brettp
Repo: mostlygeek/llama-swap PR: 226
File: proxy/config.go:305-313
Timestamp: 2025-08-07T04:50:07.200Z
Learning: In the llama-swap project, model IDs are treated as trusted input from YAML configuration files. Additional validation for MODEL_ID macro expansion is not needed because if someone can control model IDs in the config, they can already inject malicious content in other fields like cmd. The configuration file is the trusted source.

Comment thread proxy/config/matrix.go
@mostlygeek

Copy link
Copy Markdown
Owner

Hi,

This isn't the design I want to maintain in llama-swap. I prefer the shorter var name design.

@spicyneuron

spicyneuron commented Apr 28, 2026

Copy link
Copy Markdown
Author

@mostlygeek Just in case something was lost in translation — the vars syntax is still supported. This PR merely allows model IDs, which need to resolved anyway, to be used directly.

Am I missing something about how this would create maintenance burden? Happy to adjust if so.

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.

matrix: var key must be alphanumeric and 1-8 characters

2 participants