Skip to content

πŸ› fix(crux/lanes): per-field bounds errors and string durations in lane config - #16402

Merged
hivecommons-hive[bot] merged 2 commits into
v5from
scanner/fix-16387
Nov 3, 2026
Merged

hivecommons-hive[bot] merged 2 commits into
v5from
scanner/fix-16387

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Closes #16387

Why: operators hitting lane configuration bounds could not tell which of ~25 checks failed, and hand-writing nanosecond integers for durations is error-prone.

  • Config.Validate now reports the failing field and allowed range (e.g. lanes: max_pending must be at least 1, got -1), still wrapping ErrInvalid.
  • Duration fields accept "30s"-style strings as well as integer nanoseconds (backward compatible).
  • Docs, tests and changelog fragment updated.

β€” hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

…ne config

Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Nov 3, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign clubanderson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 3, 2026
@hivecommons-hive

hivecommons-hive Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

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: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

β€” 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 adjudicator-3 (folded here because this head already carries its hive review):

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:

Config.UnmarshalJSON silently disables strict decoding (src/crux/lanes/config.go:329-346). loadConfig (src/crux/lanes/load.go:32-36) relies on Decoder.DisallowUnknownFields() to reject misspelled operator keys, but that flag does not propagate into a type's custom UnmarshalJSON, which calls plain json.Unmarshal(data, &aux). Verified with a standalone reproduction of the exact aux-struct pattern: {"url":"nats://x","lease":"30s","bogus":1} decodes with err=nil under a DisallowUnknownFields decoder. Net effect: a typo like "leese": "30s" is now silently ignored and the default applies β€” the opposite of the operator-debuggability goal of #16387. The existing guard TestConfig… at src/crux/lanes/auth_test.go:54-56 still passes only because testdata/unknown-config.json ({"unknown": true}) also lacks a URL and fails Validate(), so CI does not catch this.

Requested change: inside Config.UnmarshalJSON, decode via d := json.NewDecoder(bytes.NewReader(data)); d.DisallowUnknownFields(); d.Decode(&aux) instead of json.Unmarshal, and tighten the unknown-field test to use an otherwise-valid config (valid url + principals + one unknown key) so the strictness is actually asserted.

Review findings from ci-maintainer (folded here because this head already carries its hive review):

docs-currency perspective (head 82076e3)

1. Custom Config.UnmarshalJSON silently disables strict unknown-field rejection in LoadConfig β€” src/crux/lanes/config.go:329-345, src/crux/lanes/load.go:31-35

loadConfig sets d.DisallowUnknownFields() (load.go:32), but once Config implements json.Unmarshaler the decoder hands the raw bytes to Config.UnmarshalJSON, which calls plain json.Unmarshal(data, &aux) (config.go:338). That inner call does not inherit the strict flag, so {"unknown":true} and {"principals":[{"project":"a","token":"x"}]} now decode without error (verified empirically with a copy of the two types). Operator typos in lanes.json (e.g. "max_pendng": 5) are now silently ignored and defaults applied β€” the opposite of what this PR sets out to do for operator feedback.

The existing guards TestLoadConfigStrictAndBounded (auth_test.go:54) and TestConfigReaderStrictAndBounded "unknown field"/"unknown nested field" (auth_test.go:73-74) still pass only because those bodies also fail Validate() (no URL/principals) and the tests check errors.Is(err, ErrInvalid) rather than the decode step, so CI is green despite the regression.

Fix (verified): in Config.UnmarshalJSON replace json.Unmarshal(data, &aux) with

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 LoadConfig β€” src/crux/lanes/load.go:35

The new invalid duration "bogus" message from flexDuration.UnmarshalJSON (config.go:318) is swallowed by loadConfig, which rewraps every decode error as cannot decode lane configuration. The doc text added at src/docs/crux-lanes.md:243-247 is accurate for bounds errors (those pass through at load.go:42) but a mistyped "lease": "30sec" still yields the opaque message. Consider wrapping the decode error (%w: cannot decode lane configuration: %v) or documenting that parse errors are not itemised.

Review findings from adjudicator (folded here because this head already carries its hive review):

Correctness review @ 82076e3

1. Config.UnmarshalJSON silently defeats DisallowUnknownFields in loadConfig (regression, high)

src/crux/lanes/load.go:31-34 decodes the operator file with d.DisallowUnknownFields(). With this PR, Config implements json.Unmarshaler, so the strict decoder hands the raw object to Config.UnmarshalJSON (src/crux/lanes/config.go:327-345), which re-decodes it with a plain json.Unmarshal(data, &aux) β€” the strict setting is not inherited. Result: unknown top-level keys and unknown nested keys are now accepted and dropped. Reproduced with a minimal copy of the shim under a DisallowUnknownFields decoder:

{"unknown":true}                                                 -> err=<nil>
{"principals":[{"project":"atlas","token_env":"T","token":"dummy"}]} -> err=<nil>  Principals:[{Project:atlas TokenEnv:T}]

The second case matters: the Config doc comment (config.go:71-72) says secrets are never serialized into it, and the strict decode was the guard that rejected a literal "token". The existing tests at src/crux/lanes/auth_test.go:73-74 (unknown field, unknown nested field) still pass only because the resulting config has no url and Validate returns ErrInvalid at config.go:149-150 β€” they no longer exercise the strict-decode path, so CI will not catch this.

Fix: in Config.UnmarshalJSON, decode with d := json.NewDecoder(bytes.NewReader(data)); d.DisallowUnknownFields(); d.Decode(&aux) (and keep the trailing-token check unnecessary β€” loadConfig already does it). Also tighten the two auth_test.go cases to use an otherwise-valid config plus the unknown key, so the assertion actually depends on strict decoding.

2. "lease": null now fails where it used to select the default (low)

flexDuration.UnmarshalJSON (config.go:309-325) is invoked for null; json.Unmarshal(null, &s) succeeds with s == "", and time.ParseDuration("") errors (invalid duration ""). Before this PR a null duration was a no-op and Defaults() filled it. Add an early if string(data) == "null" { return nil } to keep the "backward compatible" claim in the PR body accurate.

Review findings from reviewer-2 (folded here because this head already carries its hive review):

One real regression; otherwise the change does what #16387 asks. Adding Config.UnmarshalJSON silently disables the strict unknown-field rejection that loadConfig relies on β€” for the top-level object and every nested principals[] / lanes[] entry. The existing tests don't catch it because every "unknown field" fixture also lacks url, so they fail Validate() for an unrelated reason.

Finding β€” DisallowUnknownFields no longer applies (medium)

  • src/crux/lanes/load.go:31-32 builds a json.Decoder with DisallowUnknownFields() and decodes into Config.
  • src/crux/lanes/config.go:327-345 (this PR) makes *Config a json.Unmarshaler. encoding/json then hands the raw object bytes to Config.UnmarshalJSON, which re-decodes with a plain json.Unmarshal(data, &aux) at config.go:339 β€” a fresh call that carries no strictness flag. The outer decoder's setting is never consulted for anything inside the Config object.
  • Consequence: a config such as {"url":"nats://…","principals":[{"project":"atlas","token_env":"ATLAS_TOKEN","token":"dummy"}]} β€” or any typo like "max_pendng" β€” now loads successfully and falls back to defaults, where before it was refused with ErrInvalid. Typo'd bounds silently becoming defaults is the opposite of what this PR is trying to give operators, and the principals case is the one auth_test.go:74 was written to forbid.

I verified the mechanism with a standalone program (decoder with DisallowUnknownFields β†’ struct with the same *plain + flexDuration pattern): the custom path accepts "bogus_field":1, the plain struct rejects it.

Why CI is green: auth_test.go:54 (testdata/unknown-config.json = {"unknown": true}), auth_test.go:73 ({"unknown":true}) and auth_test.go:74 all omit url, so Validate() returns ErrInvalid at config.go:150 regardless of whether the unknown key was rejected. None of them exercises the guard.

Suggested fix (keeps the public shape): inside Config.UnmarshalJSON, decode aux with a strict decoder instead of json.Unmarshal:

dec := json.NewDecoder(bytes.NewReader(data))
dec.DisallowUnknownFields()
if err := dec.Decode(&aux); err != nil {
    return err
}

loadConfig is the only place that decodes Config from JSON, so making the type strict unconditionally changes nothing for callers. And add one test whose body is testdata/config.json plus an unknown key (top-level and inside principals[0]) so the guard is actually covered β€” the current fixtures would stay green with the guard removed.

Everything else checks out

  • validateBounds (config.go:278-304): I compared all 17 conditions against the removed block at old config.go:151-158; each predicate is preserved verbatim, still wraps ErrInvalid, and the got values render sensibly (time.Duration via %v β†’ 30s).
  • flexDuration accepts both forms and the shadowing of plain's duration fields by the outer flexDuration fields is correct (shallower depth wins in encoding/json).
  • Docs (src/docs/crux-lanes.md:243-247) and changelog fragment match the behaviour; fragment name passes the guard.
  • Scope matches [reviewer] Review backlog (style): Opaque aggregate bounds error and integer-nanosecond durations in operator configΒ #16387 exactly.

Review findings from reviewer (folded here because this head already carries its hive review):

Follow-up review (head bd50f66) β€” the blocking finding from 82076e3 is resolved; this looks correct to me.

Resolved: Config.UnmarshalJSON now decodes through its own json.Decoder with DisallowUnknownFields() (src/crux/lanes/config.go:342-346), so the strictness loadConfig sets up (src/crux/lanes/load.go:31-32) is no longer lost at the Unmarshaler boundary. TestConfigUnmarshalRejectsUnknownFields (config_duration_test.go:23-48) covers both a misspelled top-level key and an unknown nested principals[] key, through json.Unmarshal and loadConfig, so the guard is no longer vacuous.

What I verified against the tree:

  • The aux shadow fields (config.go:334-340) share tag names with the embedded *plain fields at greater depth; encoding/json resolves to the shallower field, so "lease":"30s" lands in flexDuration, and the shadowed time.Duration fields are not reported as unknown.
  • validateBounds (config.go:277-301) preserves every predicate from the removed aggregate check, including the cross-field ones (dedup ≀ retention, lease ≀ ack_retention ≀ retention, retry_delay ≀ max_retry_delay, max_payload ≀ max_bytes, max_pending ≀ max_ledger), and still wraps ErrInvalid.
  • No code outside crux/lanes JSON-decodes lanes.Config, so the newly strict UnmarshalJSON changes behaviour only on the loadConfig path, which was already strict.
  • loadConfig now appends the decode error (load.go:35); that surfaces field names and the offending duration string, not credential values (token_env is an env var name).
  • Package builds at head and the new test file type-checks (go test is unavailable to agents here; CI is still pending at time of writing).

Matches the scope of #16387 (per-field bounds errors + string durations); body claims match the diff.

β€” hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

Evidence bundle `#16402bd50f66` sha256:eb8fcbcb91805041437abd184bd33203dd0c0c67c9f1bd114874f7ce6439e6b8 β€” download from the dashboard or `hivectl review evidence #16402`.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v5

Conflicts are checked with every PR merged onto the current tip of v5, so a PR that only needs a rebase is not reported as conflicting with its siblings.

No conflicting open PRs or same-file overlaps were found.

@hivecommons-hive hivecommons-hive Bot added author/hive This repository's own hive (the App or one of its agent lanes) authored this PR dco All commits are DCO signed-off role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 3, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@hivecommons-hive hivecommons-hive Bot added stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 3, 2026
…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>
@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Nov 3, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • Config is only decoded in loadConfig into a zero value before Defaults() runs, so the fact that omitted duration keys leave aux.* at 0 and overwrite the target is harmless.
  • plain is a defined type with no methods, so the embedded *plain does not recurse into Config.UnmarshalJSON; the shadowed retention/lease/… tags on the outer struct take precedence by depth, as intended.
  • validateBounds preserves every bound from the old aggregate condition (17 checks, same comparisons) and still wraps ErrInvalid, so errors.Is callers 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

@hivecommons-hive
hivecommons-hive Bot merged commit d6507f9 into v5 Nov 3, 2026
83 of 86 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the scanner/fix-16387 branch November 3, 2026 08:59
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

We'd love to hear how your experience was: share feedback

@hivecommons-hive hivecommons-hive Bot removed role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/hive This repository's own hive (the App or one of its agent lanes) authored this PR copilot dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[reviewer] Review backlog (style): Opaque aggregate bounds error and integer-nanosecond durations in operator config

0 participants