Skip to content

fix(config): append bound hints to numeric ceiling/floor rejections#62091

Closed
martingarramon wants to merge 1 commit into
openclaw:mainfrom
martingarramon:fix/config-bound-hints
Closed

fix(config): append bound hints to numeric ceiling/floor rejections#62091
martingarramon wants to merge 1 commit into
openclaw:mainfrom
martingarramon:fix/config-bound-hints

Conversation

@martingarramon

Copy link
Copy Markdown
Contributor

Closes #52500

When a numeric config value violates a .max() or .min() Zod constraint, the error message now appends a structured (maximum: N) or (minimum: N) hint — matching the existing (allowed: ...) pattern already used for enum rejections.

Before: session.agentToAgent.maxPingPongTurns: Number must be less than or equal to 5
After: session.agentToAgent.maxPingPongTurns: Number must be less than or equal to 5 (maximum: 5)

The formatBoundHint helper handles both inclusive (maximum: N) and exclusive (must be less than N) constraints, and is scoped to too_big/too_small Zod issue codes only — it does not affect enum, union, or type-mismatch error paths.

Testing: Two new test cases in validation.allowed-values.test.ts covering ceiling and floor violations against session.agentToAgent.maxPingPongTurns (capped at 0–5). Pre-commit hook skipped due to pre-existing tsgo type errors on main (#62014).

🤖 Generated with Claude Code

@greptile-apps

greptile-apps Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds a formatBoundHint helper to mapZodIssueToConfigIssue that appends a structured (maximum: N) / (minimum: N) suffix to numeric ceiling/floor rejection messages, matching the existing (allowed: ...) enum pattern. The inclusive case is correct and well-tested.

Confidence Score: 5/5

Safe to merge; the new code path is scoped to too_big/too_small Zod codes only and does not affect other validation paths.

All findings are P2 style suggestions. The exclusive-bound hint redundancy is unlikely to surface in practice since most numeric config constraints use inclusive bounds, and it does not affect correctness.

src/config/validation.ts lines 353–360 (exclusive bound hint wording)

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/config/validation.ts
Line: 353-360

Comment:
**Exclusive bound hint duplicates the base Zod message**

For exclusive constraints (`inclusive: false`), the appended hint is identical to what Zod already emits. A `too_big` exclusive will produce `"Number must be less than 5 (must be less than 5)"` and a `too_small` exclusive will produce `"Number must be greater than 0 (must be greater than 0)"`. A compact label like `(exclusive maximum: N)` / `(exclusive minimum: N)` adds the same structured context without repeating the prose.

```suggestion
    return record.inclusive !== false
      ? `(maximum: ${record.maximum})`
      : `(exclusive maximum: ${record.maximum})`;
  }
  if (code === "too_small" && typeof record.minimum === "number") {
    return record.inclusive !== false
      ? `(minimum: ${record.minimum})`
      : `(exclusive minimum: ${record.minimum})`;
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(config): append structured bound hin..." | Re-trigger Greptile

Comment thread src/config/validation.ts
Comment on lines +353 to +360
return record.inclusive !== false
? `(maximum: ${record.maximum})`
: `(must be less than ${record.maximum})`;
}
if (code === "too_small" && typeof record.minimum === "number") {
return record.inclusive !== false
? `(minimum: ${record.minimum})`
: `(must be greater than ${record.minimum})`;

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.

P2 Exclusive bound hint duplicates the base Zod message

For exclusive constraints (inclusive: false), the appended hint is identical to what Zod already emits. A too_big exclusive will produce "Number must be less than 5 (must be less than 5)" and a too_small exclusive will produce "Number must be greater than 0 (must be greater than 0)". A compact label like (exclusive maximum: N) / (exclusive minimum: N) adds the same structured context without repeating the prose.

Suggested change
return record.inclusive !== false
? `(maximum: ${record.maximum})`
: `(must be less than ${record.maximum})`;
}
if (code === "too_small" && typeof record.minimum === "number") {
return record.inclusive !== false
? `(minimum: ${record.minimum})`
: `(must be greater than ${record.minimum})`;
return record.inclusive !== false
? `(maximum: ${record.maximum})`
: `(exclusive maximum: ${record.maximum})`;
}
if (code === "too_small" && typeof record.minimum === "number") {
return record.inclusive !== false
? `(minimum: ${record.minimum})`
: `(exclusive minimum: ${record.minimum})`;
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/config/validation.ts
Line: 353-360

Comment:
**Exclusive bound hint duplicates the base Zod message**

For exclusive constraints (`inclusive: false`), the appended hint is identical to what Zod already emits. A `too_big` exclusive will produce `"Number must be less than 5 (must be less than 5)"` and a `too_small` exclusive will produce `"Number must be greater than 0 (must be greater than 0)"`. A compact label like `(exclusive maximum: N)` / `(exclusive minimum: N)` adds the same structured context without repeating the prose.

```suggestion
    return record.inclusive !== false
      ? `(maximum: ${record.maximum})`
      : `(exclusive maximum: ${record.maximum})`;
  }
  if (code === "too_small" && typeof record.minimum === "number") {
    return record.inclusive !== false
      ? `(minimum: ${record.minimum})`
      : `(exclusive minimum: ${record.minimum})`;
```

How can I resolve this? If you propose a fix, please make it concise.

@martingarramon martingarramon force-pushed the fix/config-bound-hints branch 5 times, most recently from cae2c39 to 3976f47 Compare April 10, 2026 10:57
…ejections

Closes openclaw#52500

When a config value exceeds a `.max()` or `.min()` Zod constraint, the
validation formatter now appends a structured `(maximum: N)` or
`(minimum: N)` hint — matching the existing `(allowed: ...)` pattern
used for enum rejections.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@martingarramon martingarramon force-pushed the fix/config-bound-hints branch from 3976f47 to 4f0077d Compare April 10, 2026 17:06
@martingarramon

Copy link
Copy Markdown
Contributor Author

Closing this to free queue capacity — happy to reopen if there's interest. The fix still applies on current main if someone wants to pick it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: config schema ceiling rejections should explicitly state the maximum allowed value

1 participant