fix: validate nudge numeric config fields - #100
Open
Beatrice0377 wants to merge 1 commit into
Open
Conversation
ranxianglei
approved these changes
Aug 21, 2026
ranxianglei
left a comment
Owner
There was a problem hiding this comment.
Review: ✅ Approve — 2 independent agent reviews, both approve. Nits below are optional follow-ups, none blocking.
Verified locally on the PR branch (claims all check out):
npm run typecheck✅npm test→ 400/400 ✅ (matches PR claim)npm run build✅- CI green (pr-validation, test 22/24); mergeable; single commit; scope confirmed:
src/config.ts(+29/−1),tests/sync-config.test.ts(+108)
Correctness
- Implements all six checks from #46, and adds finiteness (NaN/Infinity) checks beyond the issue's suggestion — good hardening, since NaN silently bypasses
</>comparisons. - The
Number.isFinite(growthFloor)guard at src/config.ts:92 avoids a confusing "growthCap must be >= growthFloor" cascade when the floor itself is non-finite. Probed:growthFloor: Infinity→ single clear error;growthFloor: NaN, growthCap: -1→ root-cause error only. growthCap >= 0isn't checked directly but holds transitively (cap ≥ floor ≥ 0). Negative cap with valid floor is caught via the cap-vs-floor relation.emergencyThresholdPctdomain(0, 1]is correct:usage >= emergencyThresholdPct(src/compress.ts:967) means 0 would fire every turn and >1 never fires — exactly the nonsense values #46 wanted flagged.- Semantics vs
resolveAdaptiveGrowth(src/compress.ts:922-928): with cap < floor,Math.min(cap, Math.max(floor, …))silently returns cap — the validator now surfaces that misconfiguration instead of masking it. - Defaults (growthFloor=50000, growthCap=50000, emergencyThresholdPct=0.95) validate clean; also probed
defaultConfig(2_000_000)to rule out limit-dependent breakage. - No consumer risk:
validateConfigoutput is onlyconsole.warn'd (src/compress.ts:327-329), never thrown; pure additive checks, no behavior change for valid configs.
Nits (optional)
- No explicit negative-
growthCaptest (growthCap: -1with a valid floor) — tests only cover cap=99/floor=100. growthCap: NaNuntested (onlyInfinity, same!Number.isFinitebranch — cosmetic).emergencyThresholdPct: -0.5untested (0 and 1.01 already hit both branches — cosmetic).- Follow-up candidate (explicitly out of scope here):
tier2GrowthMultiplier,frequency,iterationThreshold, and min/max pct ranges remain unvalidated.
The keyof Pick<NudgeConfig, …> typing (src/config.ts:75-80) is a nice touch — keeps the field list refactor-safe. Thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
validateConfig()does not sanity-check several numeric nudge configuration fields added over time.Invalid overrides such as a negative growth floor,
growthCap < growthFloor, or an out-of-range emergency threshold are currently accepted and can make nudge thresholds behave unexpectedly without any validation warning.Non-finite values such as
NaNorInfinitycan also bypass ordinary numeric comparisons and propagate into the adaptive-growth calculations.Root Cause
The newer nudge numeric fields were added without corresponding checks in
validateConfig().The existing validator covers model context limits, tier trigger ordering, truncation thresholds, and some nudge threshold relationships, but not:
growthRatiogrowthFloorgrowthCapminGrowthFloorminGrowthRatioemergencyThresholdPctFix
Add validation for the six fields above:
growthRatio,growthFloor,minGrowthFloor, andminGrowthRatioto be non-negative.growthCap >= growthFloor.emergencyThresholdPctto be in(0, 1].The validator keeps its existing behavior of returning validation errors; no runtime path is changed to throw.
Scope / Non-goals
tier2GrowthMultiplieror other fields outside the scope of validateConfig() does not sanity-check the newer nudge numeric fields #46.Tests
Added regression coverage for:
NaN/Infinityinputs.growthCap < growthFloor.growthCap == growthFloor.emergencyThresholdPctboundaries.1.Validation:
npm run typecheck: passed.npm run build: passed.git diff --check: passed.Compatibility
Valid existing configurations continue to pass validation.
The change only adds warnings for invalid configuration values; it does not alter nudge calculation behavior for valid inputs.
Fixes #46