Skip to content

fix(kg): enforce the object and range contracts the params declare - #2632

Merged
ohdearquant merged 3 commits into
mainfrom
fix/enforce-declared-param-contracts
Sep 12, 2026
Merged

fix(kg): enforce the object and range contracts the params declare#2632
ohdearquant merged 3 commits into
mainfrom
fix/enforce-declared-param-contracts

Conversation

@ohdearquant

Copy link
Copy Markdown
Owner

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.

properties is 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 gets ok back 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 says expected 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_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". 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.

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
@ohdearquant
ohdearquant merged commit 96bb26c into main Sep 12, 2026
47 of 49 checks passed
@ohdearquant
ohdearquant deleted the fix/enforce-declared-param-contracts branch September 12, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant