fix(kg): enforce the object and range contracts the params declare - #2632
Merged
Conversation
A parameter's declared type is rendered into the JSON schema a caller is handed and was never compared against the argument that arrived, so two documented contracts were promises with nothing behind them. properties is declared as an object and accepted a bare string, which persisted. Every later reader then found a string where the schema said map. The success return is the real harm: an agent that mis-serializes a nested argument gets ok back and proceeds believing the write landed in the shape it intended, with no signal to correct on. Absent and explicit null stay legal, since null is how the update path clears the field. min_score is documented as a 0.0 to 1.0 floor and neither end was enforced. A floor above the range was honoured and returned an empty result, which a caller cannot tell from no such record, and a negative floor was silently clamped to zero, so the value passed was not the value that ran. Both are now refused with the range and the value named. Tests carry the arms that make them load-bearing. The object test has a control in the same test, the identical call with a real object, so the refusal is about the shape rather than the field; it also asserts a batch refusal names which item. The range test creates the rows and finds them at a sane floor first, so the empty result at an out-of-range floor cannot be read as an empty corpus.
…param-contracts # Conflicts: # crates/khive-pack-kg/src/handlers/common.rs
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.
A parameter's declared type is rendered into the JSON schema a caller is handed, and nothing ever compared it against the argument that arrived. Two documented contracts were therefore promises with nothing behind them, and both were found by exercising the surface as an agent would rather than by reading it.
propertiesis declared an object and accepted a bare string. The string persisted, so every later reader found a string where the schema said map. The success return is the real harm: an agent that mis-serializes a nested argument getsokback and proceeds believing the write landed in the shape it intended. Compare the refusals on the same surface that do work: an unknown kind lists every valid kind, a negative limit saysexpected u32, an empty query says the query must not be empty. Those let a caller correct itself; this one did not.Absent and explicit null stay legal, since null is how the update path clears the field and absent means unchanged. The check runs on create (singleton and batch), update and the search filter, and a batch refusal names which item.
min_scoreis documented as a 0.0 to 1.0 floor and neither end was enforced. A floor above the range was honoured and returned an empty result, which a caller cannot tell from "no such record". A negative floor was silently clamped to zero, so the value passed was not the value that ran. Both are now refused with the range and the value named.Tests. Each carries the arm that makes it load-bearing rather than merely green. The object test runs the identical call with a real object in the same test, so the refusal is demonstrably about the shape and not about the field being present, and it asserts the batch refusal names the offending item. The range test creates the rows and finds them at a sane floor first, so the empty result at an out-of-range floor cannot be read as an empty corpus; that control is the whole reason the finding is trustworthy.
Scope. This enforces two contracts this pack already declares. It does not add general type checking at the dispatch boundary for every parameter in every pack, which would change behaviour for callers relying on today's coercion and is a wider decision than a defect fix.