Skip to content

feat: add range validation for fractional fields and WarnAt/CutoverAt ordering to validate command #28

@fuseraft

Description

@fuseraft

fuseraft validate catches many config mistakes but misses two categories:

A — Out-of-range fractional fields. Three config properties are ratios that must be in [0, 1], but no range check exists:

Property Config type File
ContextCapFraction ContextWindowConfig src/Core/Models/ContextWindowConfig.cs:73
TrustScore AgentConfig src/Core/Models/AgentConfig.cs:66
AntiThrashMinSavingsRatio CompactionConfig src/Core/Models/CompactionConfig.cs:109

A value like TrustScore: 1.5 or ContextCapFraction: -0.2 is silently accepted and produces undefined behavior at runtime.

B — ContextBudgetConfig.WarnAtCutoverAt. If both values are non-zero and WarnAt ≥ CutoverAt, compaction fires before the warning ever triggers, making the warning permanently unreachable. The validator should flag this.

Suggested fix: Add checks in ValidateConfigCommand (src/Cli/Commands/ValidateConfigCommand.cs) alongside the existing MaxRetries > 0 and MaxIterations > 0 checks:

// Per-agent checks
if (agent.TrustScore is < 0.0 or > 1.0)
    issues.Add(("error", $"Agent '{agent.Name}': TrustScore must be 0.0–1.0 (got {agent.TrustScore})."));
if (agent.ContextWindow?.ContextCapFraction is < 0.0 or > 1.0)
    issues.Add(("error", $"Agent '{agent.Name}': ContextCapFraction must be 0.0–1.0."));

// Compaction checks
if (config.Compaction?.AntiThrashMinSavingsRatio is < 0.0 or > 1.0)
    issues.Add(("error", "Compaction.AntiThrashMinSavingsRatio must be 0.0–1.0."));

// ContextBudget cross-check
if (config.ContextBudget is { WarnAt: > 0, CutoverAt: > 0 } b && b.WarnAt >= b.CutoverAt)
    issues.Add(("warning", $"ContextBudget.WarnAt ({b.WarnAt}) >= CutoverAt ({b.CutoverAt}): warning will never fire."));

Also add corresponding test cases to tests/FuseraftCli.Tests/ValidateConfigCommandTests.cs.

Files to touch:

  • src/Cli/Commands/ValidateConfigCommand.cs
  • tests/FuseraftCli.Tests/ValidateConfigCommandTests.cs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions