Repository navigation
π fix(crux/lanes): per-field bounds errors and string durations in lane config - #16402
Conversation
β¦ne config Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hive status β updated in place; edits do not notify. Full history is in the Activity Monitor. hive/awaiting-ci: CI pending β sweep will merge when green. π Hive Agent: β hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 Hive filed review findings that do not block this PR as backlog items:
Cap: 10 backlog item(s) per PR per day. Review findings from Intent alignment (#16387): per-field bounds errors and string durations are both implemented and match the issue. One in-scope regression the string-duration path introduces:
Requested change: inside Review findings from docs-currency perspective (head 1. Custom
The existing guards Fix (verified): in dec := json.NewDecoder(bytes.NewReader(data))
dec.DisallowUnknownFields()
if err := dec.Decode(&aux); err != nil { return err }and add a test that an otherwise-valid config plus one unknown key is rejected at decode time. 2. (advisory) Duration parse errors never reach the operator via The new Review findings from Correctness review @ 82076e3 1.
The second case matters: the Fix: in 2.
Review findings from One real regression; otherwise the change does what #16387 asks. Adding Finding β
|
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of No conflicting open PRs or same-file overlaps were found. |
There was a problem hiding this comment.
style review (head 82076e3)
Config.UnmarshalJSON silently defeats DisallowUnknownFields in LoadConfig β src/crux/lanes/config.go:328-346
loadConfig (src/crux/lanes/load.go:32-33) builds a json.Decoder with DisallowUnknownFields() so typo'd operator keys are rejected. Once Config implements json.Unmarshaler, the decoder hands the raw object to Config.UnmarshalJSON, which decodes it with a plain json.Unmarshal(data, &aux) (config.go:339) β unknown-field checking does not propagate. Verified with a scratch program: {"url":"nats://x","lease":"30s","typo_field":1} now decodes with nil error under DisallowUnknownFields, whereas the pre-PR struct fails with json: unknown field "typo_field". So a misspelled credentials_env or max_pendng is now silently ignored and defaults apply.
The existing guard test (auth_test.go, LoadConfig("testdata/unknown-config.json") β expects ErrInvalid) still passes only because {"unknown": true} also has an empty url and fails Validate, so it does not catch this.
Requested fix: inside Config.UnmarshalJSON, decode via d := json.NewDecoder(bytes.NewReader(data)); d.DisallowUnknownFields(); d.Decode(&aux), and extend unknown-config.json (or add a case) to an otherwise-valid config plus one unknown key so the guard is no longer vacuous.
Advisory (non-blocking): validateBounds eagerly formats all 17 range strings on every call (config.go:277-295); fine for a once-per-load path, just noting it is not lazy.
β hive: agent=adjudicator-4 backend=copilot model=claude-fable-5.1 copilot=1.0.88
β¦e errors Config.UnmarshalJSON used a permissive json.Unmarshal, which bypassed the outer decoder's DisallowUnknownFields so typoed or unexpected keys (including nested ones such as principals[].token) were silently accepted. Decode with a strict json.Decoder inside UnmarshalJSON, and have loadConfig wrap the decode error so unknown-field and invalid-duration messages reach operators. Adds regression tests for unknown top-level/nested keys and for the duration error on the loadConfig path. Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Re-reviewed at bd50f66. The follow-up commit closes the gap from the previous round: Config.UnmarshalJSON (src/crux/lanes/config.go:330-350) now builds its own json.Decoder with DisallowUnknownFields(), so the strictness the outer decoder in loadConfig (src/crux/lanes/load.go:31-36) can no longer propagate into the Unmarshaler is restored inside it. TestConfigUnmarshalRejectsUnknownFields covers both a top-level typo and an unknown nested principals[].token key, and TestLoadConfigSurfacesDurationError checks the decode error text reaches the operator now that load.go:35 wraps %v instead of swallowing it.
Also verified:
Configis only decoded inloadConfiginto a zero value beforeDefaults()runs, so the fact that omitted duration keys leaveaux.*at 0 and overwrite the target is harmless.plainis a defined type with no methods, so the embedded*plaindoes not recurse intoConfig.UnmarshalJSON; the shadowedretention/lease/β¦ tags on the outer struct take precedence by depth, as intended.validateBoundspreserves every bound from the old aggregate condition (17 checks, same comparisons) and still wrapsErrInvalid, soerrors.Iscallers are unaffected.- Package builds and the new tests type-check locally; CI was still in progress with no failures when I looked.
Looks correct to me. Matches the scope of #16387 (its blocker #16373 has landed β config.go exists at merge-base).
β hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Thank you for your contribution! Your PR has been merged. We'd love to hear how your experience was: share feedback |
Closes #16387
Why: operators hitting
lane configuration boundscould not tell which of ~25 checks failed, and hand-writing nanosecond integers for durations is error-prone.Config.Validatenow reports the failing field and allowed range (e.g.lanes: max_pending must be at least 1, got -1), still wrappingErrInvalid."30s"-style strings as well as integer nanoseconds (backward compatible).β hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88