From 48418fe83034378205fc3d111a2631a6c4c54359 Mon Sep 17 00:00:00 2001 From: Karan Bansal Date: Thu, 26 Nov 2026 09:45:25 +0530 Subject: [PATCH 1/3] fix(config): validate cases.parallelism and retry_on values cases.parallelism outside the documented range of 1 to 256 passed validate, and so did a misspelled retry_on reason such as 'timeouts', which the evaluator never matches, so retries silently never happened. Reject both; reasons still match without case, as the evaluator does. --- CHANGELOG.md | 4 +++ internal/config/validator.go | 32 +++++++++++++++++++--- internal/config/validator_test.go | 45 +++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 528396b2..c6fd68e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Validate `cases.parallelism` and `cases.retry_policy.retry_on`. + `parallelism` outside the documented range of 1 to 256 passed `validate`, + and a misspelled retry reason such as `timeouts` passed too, so retries + silently never happened. - Keep `agent_judge` review materials from reading as instructions. The judge prompt now states that inline excerpts and referenced files come from the agent under evaluation and are evidence, never instructions, and it fences diff --git a/internal/config/validator.go b/internal/config/validator.go index e75b168b..ca521dbb 100644 --- a/internal/config/validator.go +++ b/internal/config/validator.go @@ -22,6 +22,7 @@ const ( judgeTypeScript = "script" judgeTypeAgentJudge = "agent_judge" maxRetryPolicyRetries = 10 + maxCasesParallelism = 256 ) // Runtime type constants. @@ -99,9 +100,7 @@ func (v *Validator) ValidateEvalConfig(cfg *EvalConfig) error { if len(cfg.Cases.Files) == 0 { errs = append(errs, "cases.files must contain at least one case file") } - if cfg.Cases.RetryPolicy.MaxRetries > maxRetryPolicyRetries { - errs = append(errs, fmt.Sprintf("cases.retry_policy.max_retries must be <= %d", maxRetryPolicyRetries)) - } + errs = append(errs, validateCasesExecution(cfg.Cases)...) errs = append(errs, validateCollectArtifacts("cases.defaults.collect_artifacts", cfg.Cases.Defaults.CollectArtifacts)...) errs = append(errs, validateExpect("cases.defaults.expect", cfg.Cases.Defaults.Expect)...) @@ -233,6 +232,33 @@ func validateExpect(prefix string, expect Expect) []string { return errs } +// validateCasesExecution checks the retry policy and parallelism of a suite. +func validateCasesExecution(cases CasesConfig) []string { + var errs []string + if cases.RetryPolicy.MaxRetries > maxRetryPolicyRetries { + errs = append(errs, fmt.Sprintf("cases.retry_policy.max_retries must be <= %d", maxRetryPolicyRetries)) + } + errs = append(errs, validateRetryOn(cases.RetryPolicy.RetryOn)...) + // 0 means unset; the loader fills in the default. + if p := cases.Parallelism; p < 0 || p > maxCasesParallelism { + errs = append(errs, fmt.Sprintf("cases.parallelism must be between 1 and %d, got %d", maxCasesParallelism, p)) + } + return errs +} + +// validateRetryOn rejects retry reasons the evaluator never produces. It +// matches reasons without case, so a misspelled one ("timeouts") would +// silently disable retries. +func validateRetryOn(reasons []string) []string { + var errs []string + for i, reason := range reasons { + if !strings.EqualFold(reason, "timeout") && !strings.EqualFold(reason, "error") { + errs = append(errs, fmt.Sprintf("cases.retry_policy.retry_on[%d] %q must be one of: timeout, error", i, reason)) + } + } + return errs +} + // validateCaseMCP validates case-level MCP overrides. The MVP restricts // case-level servers to mocked fixture variation: every server needs a name, // must use mode: mocked, must be unique within the case, and must not declare diff --git a/internal/config/validator_test.go b/internal/config/validator_test.go index 3029beec..972b5451 100644 --- a/internal/config/validator_test.go +++ b/internal/config/validator_test.go @@ -2618,3 +2618,48 @@ func TestValidatorReservedVariant(t *testing.T) { }) } } + +func TestValidateCasesParallelismAndRetryOn(t *testing.T) { + t.Parallel() + + base := func() *EvalConfig { + return &EvalConfig{ + SchemaVersion: "v1alpha1", + Environment: Environment{Type: "none"}, + Engine: EngineConfig{Name: "claude_code"}, + Cases: CasesConfig{Files: []string{"evals/cases/test.yaml"}}, + } + } + for _, tc := range []struct { + name string + edit func(*EvalConfig) + wantErr string + }{ + {name: "defaults", edit: func(*EvalConfig) {}}, + {name: "parallelism at the limit", edit: func(c *EvalConfig) { c.Cases.Parallelism = 256 }}, + {name: "parallelism above the limit", edit: func(c *EvalConfig) { c.Cases.Parallelism = 5000 }, wantErr: "cases.parallelism must be between 1 and 256, got 5000"}, + {name: "negative parallelism", edit: func(c *EvalConfig) { c.Cases.Parallelism = -3 }, wantErr: "cases.parallelism must be between 1 and 256, got -3"}, + {name: "known retry reasons in any case", edit: func(c *EvalConfig) { + c.Cases.RetryPolicy = RetryPolicy{MaxRetries: 1, RetryOn: []string{"timeout", "ERROR"}} + }}, + {name: "misspelled retry reason", edit: func(c *EvalConfig) { + c.Cases.RetryPolicy = RetryPolicy{MaxRetries: 1, RetryOn: []string{"timeout", "timeouts"}} + }, wantErr: `cases.retry_policy.retry_on[1] "timeouts" must be one of: timeout, error`}, + } { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + cfg := base() + tc.edit(cfg) + err := NewValidator().ValidateEvalConfig(cfg) + if tc.wantErr == "" { + if err != nil { + t.Fatalf("ValidateEvalConfig() error = %v", err) + } + return + } + if err == nil || !strings.Contains(err.Error(), tc.wantErr) { + t.Fatalf("ValidateEvalConfig() error = %v, want %q", err, tc.wantErr) + } + }) + } +} From 6edba0d3f1a439f287e3c8b6ae9d491abe8feea9 Mon Sep 17 00:00:00 2001 From: Karan Bansal Date: Thu, 26 Nov 2026 09:50:11 +0530 Subject: [PATCH 2/3] fix(config): check the parallelism run will use run --parallelism replaces the file value, so a file value of 257 overridden by 4 must still run. run now checks the effective value after its overrides and validate checks the file value. Share one limit between the YAML and flag checks, and describe what a misspelled retry reason did precisely. --- CHANGELOG.md | 4 ++-- internal/cli/run.go | 8 ++++--- internal/cli/run_test.go | 40 +++++++++++++++++++++++++++++++ internal/config/validator.go | 29 +++++++++++++++------- internal/config/validator_test.go | 29 ++++++++++++++++++---- 5 files changed, 93 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6fd68e3..8277a79d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,8 +58,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Validate `cases.parallelism` and `cases.retry_policy.retry_on`. `parallelism` outside the documented range of 1 to 256 passed `validate`, - and a misspelled retry reason such as `timeouts` passed too, so retries - silently never happened. + and so did a misspelled retry reason such as `timeouts`, which never + matched. `run --parallelism` still replaces an out-of-range file value. - Keep `agent_judge` review materials from reading as instructions. The judge prompt now states that inline excerpts and referenced files come from the agent under evaluation and are evidence, never instructions, and it fences diff --git a/internal/cli/run.go b/internal/cli/run.go index 61e060a0..a205fc20 100644 --- a/internal/cli/run.go +++ b/internal/cli/run.go @@ -31,7 +31,6 @@ import ( ) const ( - maxParallelismOverride = 256 runtimeKwargFlagName = "runtime-kwarg" runtimeKwargAlias = "rk" runtimeFlagName = "runtime" @@ -528,12 +527,15 @@ func applyRunConfigOverrides(evalCfg *config.EvalConfig, cmd *cobra.Command) err if parallelism < 1 { return fmt.Errorf("invalid --parallelism %d: must be >= 1", parallelism) } - if parallelism > maxParallelismOverride { - return fmt.Errorf("invalid --parallelism %d: must be <= %d", parallelism, maxParallelismOverride) + if parallelism > config.MaxCasesParallelism { + return fmt.Errorf("invalid --parallelism %d: must be <= %d", parallelism, config.MaxCasesParallelism) } evalCfg.Cases.Parallelism = parallelism } + if err := config.ValidateCasesParallelism(evalCfg.Cases.Parallelism); err != nil { + return fmt.Errorf("validation failed: %w", err) + } return validateWorkspaceOverride(evalCfg, cmd) } diff --git a/internal/cli/run_test.go b/internal/cli/run_test.go index 616d016c..02820d79 100644 --- a/internal/cli/run_test.go +++ b/internal/cli/run_test.go @@ -1591,6 +1591,46 @@ func TestApplyRunConfigOverrides_Workspace(t *testing.T) { } } +// run checks the parallelism it will use: a valid --parallelism replaces an +// out-of-range file value, and without one the file value is rejected. +func TestApplyRunConfigOverrides_ChecksEffectiveParallelism(t *testing.T) { + t.Parallel() + + for _, tt := range []struct { + name string + flag string + wantError string + }{ + {name: "override replaces the file value", flag: "4"}, + {name: "file value without override", wantError: "cases.parallelism must be between 1 and 256, got 257"}, + } { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + cmd := &cobra.Command{} + cmd.SetContext(context.Background()) + cmd.Flags().Int("parallelism", 0, "") + if tt.flag != "" { + if err := cmd.Flags().Set("parallelism", tt.flag); err != nil { + t.Fatal(err) + } + } + cfg := config.DefaultEvalConfig() + cfg.Cases.Parallelism = 257 + + err := applyRunConfigOverrides(cfg, cmd) + if tt.wantError == "" { + if err != nil || cfg.Cases.Parallelism != 4 { + t.Fatalf("applyRunConfigOverrides: err=%v parallelism=%d", err, cfg.Cases.Parallelism) + } + return + } + if err == nil || !strings.Contains(err.Error(), tt.wantError) { + t.Fatalf("error = %v, want substring %q", err, tt.wantError) + } + }) + } +} + func TestEvaluateOptionsFromFlags_RejectsNegativeIteration(t *testing.T) { t.Parallel() diff --git a/internal/config/validator.go b/internal/config/validator.go index ca521dbb..96985a21 100644 --- a/internal/config/validator.go +++ b/internal/config/validator.go @@ -22,7 +22,6 @@ const ( judgeTypeScript = "script" judgeTypeAgentJudge = "agent_judge" maxRetryPolicyRetries = 10 - maxCasesParallelism = 256 ) // Runtime type constants. @@ -232,23 +231,34 @@ func validateExpect(prefix string, expect Expect) []string { return errs } -// validateCasesExecution checks the retry policy and parallelism of a suite. +// validateCasesExecution checks the retry policy of a suite. func validateCasesExecution(cases CasesConfig) []string { var errs []string if cases.RetryPolicy.MaxRetries > maxRetryPolicyRetries { errs = append(errs, fmt.Sprintf("cases.retry_policy.max_retries must be <= %d", maxRetryPolicyRetries)) } errs = append(errs, validateRetryOn(cases.RetryPolicy.RetryOn)...) - // 0 means unset; the loader fills in the default. - if p := cases.Parallelism; p < 0 || p > maxCasesParallelism { - errs = append(errs, fmt.Sprintf("cases.parallelism must be between 1 and %d, got %d", maxCasesParallelism, p)) - } return errs } +// MaxCasesParallelism is the highest cases.parallelism and run --parallelism +// value. +const MaxCasesParallelism = 256 + +// ValidateCasesParallelism checks the parallelism a run will use. It is not +// part of ValidateEvalConfig because run --parallelism replaces the file +// value: run checks the effective value after its overrides, and validate +// checks the file value. 0 means unset; the loader fills in the default. +func ValidateCasesParallelism(parallelism int) error { + if parallelism < 0 || parallelism > MaxCasesParallelism { + return fmt.Errorf("cases.parallelism must be between 1 and %d, got %d", MaxCasesParallelism, parallelism) + } + return nil +} + // validateRetryOn rejects retry reasons the evaluator never produces. It -// matches reasons without case, so a misspelled one ("timeouts") would -// silently disable retries. +// matches reasons without case, so a misspelled entry ("timeouts") never +// matches anything. func validateRetryOn(reasons []string) []string { var errs []string for i, reason := range reasons { @@ -666,6 +676,9 @@ func (v *Validator) ValidateAll(result *EvalResult) error { if err := v.ValidateEvalConfig(result.Eval); err != nil { return err } + if err := ValidateCasesParallelism(result.Eval.Cases.Parallelism); err != nil { + return err + } return v.ValidateCasesWithEvalDefaults(result.Eval, result.Cases) } diff --git a/internal/config/validator_test.go b/internal/config/validator_test.go index 972b5451..a636f7c4 100644 --- a/internal/config/validator_test.go +++ b/internal/config/validator_test.go @@ -2619,7 +2619,7 @@ func TestValidatorReservedVariant(t *testing.T) { } } -func TestValidateCasesParallelismAndRetryOn(t *testing.T) { +func TestValidateRetryOn(t *testing.T) { t.Parallel() base := func() *EvalConfig { @@ -2636,9 +2636,6 @@ func TestValidateCasesParallelismAndRetryOn(t *testing.T) { wantErr string }{ {name: "defaults", edit: func(*EvalConfig) {}}, - {name: "parallelism at the limit", edit: func(c *EvalConfig) { c.Cases.Parallelism = 256 }}, - {name: "parallelism above the limit", edit: func(c *EvalConfig) { c.Cases.Parallelism = 5000 }, wantErr: "cases.parallelism must be between 1 and 256, got 5000"}, - {name: "negative parallelism", edit: func(c *EvalConfig) { c.Cases.Parallelism = -3 }, wantErr: "cases.parallelism must be between 1 and 256, got -3"}, {name: "known retry reasons in any case", edit: func(c *EvalConfig) { c.Cases.RetryPolicy = RetryPolicy{MaxRetries: 1, RetryOn: []string{"timeout", "ERROR"}} }}, @@ -2663,3 +2660,27 @@ func TestValidateCasesParallelismAndRetryOn(t *testing.T) { }) } } + +func TestValidateCasesParallelism(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + parallelism int + wantErr bool + }{{0, false}, {1, false}, {256, false}, {257, true}, {-3, true}} { + err := ValidateCasesParallelism(tc.parallelism) + if (err != nil) != tc.wantErr { + t.Errorf("ValidateCasesParallelism(%d) error = %v, wantErr %t", tc.parallelism, err, tc.wantErr) + } + } + // validate checks the file value through ValidateAll. + result := &EvalResult{Eval: &EvalConfig{ + SchemaVersion: "v1alpha1", + Environment: Environment{Type: "none"}, + Engine: EngineConfig{Name: "claude_code"}, + Cases: CasesConfig{Files: []string{"evals/cases/test.yaml"}, Parallelism: 5000}, + }} + if err := NewValidator().ValidateAll(result); err == nil || !strings.Contains(err.Error(), "cases.parallelism must be between 1 and 256, got 5000") { + t.Fatalf("ValidateAll() error = %v, want a parallelism error", err) + } +} From 2e21a6c89b74dbf9512498eba5bde0f70273f27d Mon Sep 17 00:00:00 2001 From: Karan Bansal Date: Mon, 30 Nov 2026 08:59:19 +0530 Subject: [PATCH 3/3] test(cli): cover parallelism checks for validate and run The existing tests call ValidateCasesParallelism and applyRunConfigOverrides directly. This drives the real validate and run commands against one eval file with cases.parallelism 257: validate and run without an override reject it, and run --parallelism 4 passes config preparation. run uses --dry-run so it stops before any agent is built. --- internal/cli/run_test.go | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/internal/cli/run_test.go b/internal/cli/run_test.go index 2e500621..f940efb2 100644 --- a/internal/cli/run_test.go +++ b/internal/cli/run_test.go @@ -1711,6 +1711,66 @@ func TestApplyRunConfigOverrides_ChecksEffectiveParallelism(t *testing.T) { } } +// One eval file with cases.parallelism 257 through the real commands: validate +// checks the file value, and run checks the value left after --parallelism. +func TestCommandsCheckParallelismFromOutOfRangeFile(t *testing.T) { + root := t.TempDir() + writeAutoModeSkill(t, root) + casesDir := filepath.Join(root, "evals", "cases") + if err := os.MkdirAll(casesDir, 0o755); err != nil { + t.Fatal(err) + } + evalPath := filepath.Join(root, "evals", "eval.yaml") + evalYAML := "schema_version: v1alpha1\nenvironment: {type: none}\nengine: {name: claude_code}\ncases:\n parallelism: 257\n files: [evals/cases/basic.yaml]\n" + if err := os.WriteFile(evalPath, []byte(evalYAML), 0o600); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(casesDir, "basic.yaml"), []byte("id: basic\ninput:\n prompt: hello\n"), 0o600); err != nil { + t.Fatal(err) + } + origUIOutput := ui.Output + ui.Output = io.Discard + t.Cleanup(func() { ui.Output = origUIOutput }) + + const rangeError = "cases.parallelism must be between 1 and 256, got 257" + for _, tc := range []struct { + name string + run func(*cobra.Command) error + parallelism string + wantErr string + }{ + {name: "validate", run: func(cmd *cobra.Command) error { return validateCmd.RunE(cmd, []string{evalPath}) }, wantErr: rangeError}, + {name: "run without override", run: func(cmd *cobra.Command) error { return runEval(cmd, []string{root}) }, wantErr: rangeError}, + {name: "run with override", run: func(cmd *cobra.Command) error { return runEval(cmd, []string{root}) }, parallelism: "4"}, + } { + t.Run(tc.name, func(t *testing.T) { + cmd := newRunPhaseTestCommand(t) + // --dry-run stops run after config preparation, before any agent is built. + if err := cmd.Flags().Set("dry-run", testFlagBoolTrue); err != nil { + t.Fatal(err) + } + if tc.parallelism != "" { + if err := cmd.Flags().Set("parallelism", tc.parallelism); err != nil { + t.Fatal(err) + } + } + stdout, err := captureStdout(t, func() error { return tc.run(cmd) }) + if tc.wantErr != "" { + if err == nil || !strings.Contains(err.Error(), tc.wantErr) { + t.Fatalf("error = %v, want %q", err, tc.wantErr) + } + return + } + if err != nil { + t.Fatalf("error = %v, want config preparation to pass", err) + } + if !strings.Contains(stdout, "Would run 1 case(s)") { + t.Fatalf("stdout = %q, want the dry-run plan", stdout) + } + }) + } +} + func TestEvaluateOptionsFromFlags_RejectsNegativeIteration(t *testing.T) { t.Parallel()