Skip to content

fix(runtime): judge a written quantity by classification and by the quantity value type it is held as - #2287

Merged
HuiJun merged 19 commits into
developfrom
fix/written-value-quantity-and-scalar-kinds
Nov 16, 2026
Merged

HuiJun merged 19 commits into
developfrom
fix/written-value-quantity-and-scalar-kinds

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What and why

The compliance row "A value written to a feature conforms to that feature's declared type" (Action map) was ⚠️ because a written quantity was not judged by the relation every other value is. Two defects on develop:

  1. A quantity bypassed classifyValue on a write. quantityConforms judged a scalar target as if the quantity were a bare Rational, and held the quantity unjudged wherever the target fixed no dimension. So Real, Number, a subtype of Real and an unrelated attribute def Count; all held 5.0 [m], although 5.0 [m] istype Real is false.
  2. A quantity carried its unit but not the quantity value type it was held as, so two quantity value types of one dimension were not told apart: an EnergyValue feature's value was held by a TorqueValue feature, and energy istype TorqueValue was true.

Changes in internal/exec/runtime:

  • write_conformance.go quantityConforms asks classifyValue; dimensionRefusal keeps the two-dimension wording for a refusal by dimension (also used for vector and tensor components, whose type structuredConforms already judges).
  • value.go measured / Value.ofQuantityKind / Value.QuantityKind and write_conformance.go holdAsMeasured: a feature declared by a specialization of ScalarQuantityValue marks the quantity it holds as of that type. A quantity [ constructs or an operator computes carries none (the operators return ScalarQuantityValue).
  • classification.go classifyValue: the held type is one of the quantity's types, so a supertype or subtype holds it afterwards and an unrelated quantity value type refuses it, also when it is read through a wider feature (general : ScalarQuantityValue = work). hastype still answers by the quantity's own type, ScalarQuantityValue.
  • dependents.go heldSame: a derivation is evaluated again when a feature comes to hold an equal quantity as another quantity value type.
  • expr_tree.go valueArgument: overload selection types a quantity argument by the type it is held as.
  • adopt.go: a carry-over into a re-analysis rebinds the held type, and refuses the object where that type resolves differently now.

Across the wire (api/proto, internal/frontend/protoconv, internal/frontend/engine, the clients):

  • A quantity left the service without the type it was held as, so one read off an EnergyValue feature and sent back as a calculation argument was taken by a TorqueValue parameter. Quantity.value_type (field 7; valueType in JSON) now names the held quantity value type by qualified name, empty for none. protoconv.ProtoToQuantity and the engine's protoToQuantity resolve a name in the receiving model and hold the quantity through runtime.QuantityHeldAs, which refuses a name that is no proper specialization of ScalarQuantityValue (semantics.Model.IsQuantityValueType) or that fixes another dimension than the unit.
  • The Go, Python, Node, Rust, Java, Julia and MATLAB clients keep the field on their quantity and send it back; a quantity a client builds or computes carries none and is judged by dimension as before. docs/reference/wire-contract.md documents it. The field is additive (make proto-breaking passes) and no capability governs it.

One change in internal/check/passes, found by the corpus guard over the new fixture:

  • typecheck_value.go checkElementConformance: a literal bound to a supertype of its scalar type that is not itself in the scalar lattice (n : ScalarValues::NumericalValue = 0.5, or ScalarValue) was reported as cannot bind Rational value to a feature typed by NumericalValue. It is now accepted where the type generalizes the literal's scalar type; an unrelated literal ("hello") is reported as before. The run time already held these values.

Specification basis

  • KerML 1.1 §8.3.3.3.4 (Feature::type): "the values must be instances of all the types" — a write is held exactly where classification affirms the type.
  • SysML v2.1 §9.8.2 / §9.8.9.1: [ constructs a ScalarQuantityValue, which specializes TensorQuantityValue and NumericalValue, not Real; "all direct specializations of (abstract) ScalarQuantityValue … must be disjoint … all lower level specializations … must be disjoint at each sibling level"; "EnergyValue and TorqueValue have the same quantity dimension … but it is not valid to add an energy quantity to a torque quantity".
  • Grammar: no grammar rule is involved (AssignmentNode / FeatureValue parse as before).
  • Pilot (2026-09.1): executes no action or state machine, so it referees no write. Its validator warns "Bound features should have conforming types" for tq : TorqueValue = e and r : Real = e (with e : EnergyValue) and is silent on Real = 5 [s]; this change is stricter than the pilot and follows the clause text.

Row restated, still ⚠️ (every write is judged by classification except a quantity written to a measurement-reference-typed feature, pending the maintainer ruling below): docs/project/spec-compliance/02-detailed-semantic-compliance-map/13-action.md, the written-value row.

Stated limits

  • A computed quantity carries no held type, so a sibling quantity value type accepts it. With e : EnergyValue, both tq : TorqueValue = ConvertQuantity(e, N*m) and tq : TorqueValue = e + 0 [J] are held, while tq : TorqueValue = e is refused. Basis: the QuantityCalculations library model (SysML v2.1 §9.8, Quantities and Units Domain Library) declares the result of every operator and of ConvertQuantity as ScalarQuantityValue (calc def '+' … return : ScalarQuantityValue;, calc def ConvertQuantity { in x: ScalarQuantityValue[1]; in targetMRef: ScalarMeasurementReference[1]; return : ScalarQuantityValue[1]; }), not as the type of an operand, and KerML 1.1 §8.3.3.3.4 asks only that the value be an instance of the feature's types. A result is therefore a quantity of its dimension and of no particular quantity value type until a typed feature holds it; refusing it would be stricter than the clause text. The same holds for a value converted onto or off a measurement scale.
  • Unchanged, and an open question for the maintainers: a quantity written to a measurement-reference-typed feature is held unjudged — the one gap that keeps the row ⚠️. attribute hp : PowerUnit = 745.7 [SI::W]; (examples/pilot-corpora/sysml-examples/Individuals Examples/AnalysisIndividualExample.sysml, line 23) evaluates to 745.7 [SI::W], as on develop: quantityConforms does not judge a quantity written to a feature whose type specializes MeasurementReferences::TensorMeasurementReference — units, scales, coordinate frames and the vector and tensor references above them — (decided by specialization, not by name), which keeps the contract the measurement-reference row of 18-kerml-function-library.md and passes.TestBoundMeasurementUnit record. value_conformance_test.go:TestQuantityIsHeldUnjudgedByAUnitTypedFeature pins it, with a VectorMeasurementReference, a TensorMeasurementReference and a CoordinateFrame holding it both bound and written, and Real, an unrelated definition, a UnitConversion and a quantity value type of another dimension still refusing the same quantity. develop judged a quantity only against a primitive scalar type or a type with a dimension, so it also held one in every other definition, among them the MeasurementReferences types outside that family (UnitConversion, UnitPrefix, QuantityValueMapping); those are not measurement references and are refused here like any unrelated definition. That row's wording "as the pilot implementation accepts it" is corrected to what the pilot (2026-09.1) does: the validator reports nothing on the line, and the expression evaluator returns the [ operator expression unreduced, so neither judges the type. The question: by KerML 1.1 §8.3.3.3.4 this write should be refused, since a ScalarQuantityValue is not an instance of PowerUnit, a MeasurementUnit (SysML v2.1 §9.8.3.2.19, "a ScalarMeasurementReference that represents a measurement unit"). The conforming declaration of such a unit is the one §9.8.3.2.19 (unitConversion : UnitConversion [0..1], "a linear conversion relationship with respect to another MeasurementUnit") and §9.8.3.2.3 (ConversionByConvention, with referenceUnit and conversionFactor) give, and the one USCustomaryUnits uses for horsepower itself: attribute <hp> 'horsepower (550 ft*lbf/s)' : PowerUnit { :>> unitConversion: ConversionByConvention { :>> referenceUnit = W; :>> conversionFactor = 7.456999E+02; :>> isExact = false; } }. Against refusing: besides the OMG example, the standard library binds a quantity to a unit-typed feature in eight places in ISQSpaceTime (azimuth : AngularMeasureUnit = num#(2) [mRef.mRefs#(2)] and its like in the cylindrical, spherical and planetary position vectors), possibly an erratum for AngularMeasureValue. Those eight do not evaluate on develop or here for another reason (not a measurement unit expression, the unit operand being mRef.mRefs#(i); the LengthValue components beside them fail the same way), so this change does not touch them either way. No other file in examples/ or the training, pilot and specification-example corpora binds a quantity to a unit-typed feature (text search). Whether to refuse the write, and with it report the binding statically, is left for a maintainer ruling.
  • The static checker does not report a quantity bound to a scalar-typed feature (checked with speed : Real = 10.0 [m] / 2.0 [s], which validates clean); the refusal is raised when the value is evaluated.

How it was verified

New tests, failing on develop:

  • value_conformance_test.go: TestQuantityIsHeldByTheTypesItIsOf, TestQuantityHeldAsAKindIsRefusedByASiblingKind, TestQuantityKindIsReadThroughAWiderFeatureAndByDerivations, TestAdoptCarriesTheQuantityKindAWrittenQuantityIsHeldAs, TestAdoptRefusesAQuantityHeldAsAChangedQuantityKind, TestCalcCallSelectsByTheQuantityKindAnArgumentIsHeldAs

  • robustness_quantities_test.go: quantity_write_to_a_type_no_quantity_is_of

  • conformance assign_quantity_write_violates_scalar_type, assign_quantity_write_conforms_to_supertype

  • internal/check/passes/typecheck_expr_test.go: TestExprBindLiteralToAScalarSupertype

  • internal/frontend/grpc/convert_quantity_value_type_test.go: TestQuantityValueTypeRoundTrip (an energy read and sent back is refused by a torque parameter, taken by an energy one; the same quantity without a type is taken by both), TestQuantityValueTypeIsChecked (undeclared names, a calculation, a feature, a scalar type, ScalarQuantityValue, a unit, another dimension)

  • client/opensysml/quantity_value_type_test.go over the in-process, Connect protobuf and Connect JSON transports, and a round-trip test in each of the Python, Node, Rust, Java, Julia and MATLAB clients

Existing expectations that moved, each adjudicated:

  • conformance/action_quantity_assign.sysml wrote 10.0 [m] / 2.0 [s] to speed : Real. A quantity is not a Real; the fixture now declares speed : ISQ::SpeedValue, its expected output unchanged.

  • tests/wasm/testdata/engine.sysml declared speed : Real = 10.0 [SI::m] / 2.0 [SI::s]; it now declares ISQ::SpeedValue. TestEngineWireParity and TestCombinedWireParity only compared the two transports, which agreed on the type mismatch, so they now assert through wantSpeedAnswer that enginedemo::speed evaluates to the quantity 5 m/s (they fail with the old declaration). client/node/test/wasm.test.ts reads the same fixture and asserts a quantity.

  • robustness_quantities_test.go "scale whose mapping maps a quantity, not a definitional value": still ErrTypeMismatch, now raised when the QuantityValueMapping binds the quantity to mappedQuantityValue : DefinitionalQuantityValue, ahead of the scale reading it.

  • editors/vscode/src/landing/mass.json and mission.json are regenerated (-update-landing): the only movement is valueType on the quantities typed features hold.

  • tests/wasm wantSpeedAnswer also requires enginedemo::speed to be held as ISQSpaceTime::SpeedValue.

No corpus baseline moved.

Gates run locally on the head (current develop merged): gofmt -l . (empty), go build ./..., go vet ./..., make lint, make proto-lint proto-breaking, python3 scripts/spec_compliance.py check, python3 scripts/changelog.py check, and go test -count=1 -timeout 40m ./... with the training, pilot and specification-example corpora required (without -race). Every package passes except one subtest of tests/wasm, the engine size budget: gzipped sysml-engine.wasm is 11,105,256 bytes against 11,100,000. develop alone measures 11,094,557 and this branch merged with it before the wire change 11,102,533; the budget is not touched here (#2319 raises it). Client suites against a locally built sysml-grpc: Go, Python (1822 passed), Node (493 passed, 1 skipped), Rust, Java and Julia pass; the MATLAB tests were not run (no Octave on the machine).

Checklist

  • make test and make lint pass locally (make lint passes; the suite was run as go test ./..., without the race detector)
  • Tests added or updated for the change
  • Documentation extended where it already covers the surface (see CONTRIBUTING.md)
  • Changelog entry added as changes/unreleased/<slug>.<section>.md, not as an edit to CHANGELOG.md
  • baselines regenerated and make docs-counts run if a gate count moved (none moved)
  • No internal work-item labels (waves, slices, F4, K5) in the body, docs, or changelog

Link to Devin session: https://nasa-jpl-demo.devinenterprise.com/sessions/d78af7b1ace947d8b56c3a65eb35a256
Open in Devin Desktop: https://nasa-jpl-demo.devinenterprise.com/desktop/session/d78af7b1ace947d8b56c3a65eb35a256?variant=devin
Requested by: @HuiJun


🟢 Devin Review found nothing to fix · View findings · Follow Devin's work

Devin Review

devin-ai-integration Bot and others added 2 commits November 15, 2026 18:18
…ms its type

A quantity bypassed the shared classification on a write: a target fixing no
dimension held it unjudged and a scalar target judged it as a bare Rational,
so a Real, Number or unrelated attribute definition held a quantity that
istype denies. The write now asks classifyValue, keeping the dimension wording
for a refusal by dimension.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
A feature declared by a quantity value type marks the quantity it holds as of
that type, so istype, hastype, as and a later write read it: a sibling type of
the same dimension refuses it, a supertype or subtype holds it, and a quantity
an operator computes or `[` constructs carries no kind.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

devin-ai-integration Bot and others added 8 commits November 15, 2026 18:45
…nrelated to the one it is held as

Co-Authored-By: jason.han <hanhuijun@gmail.com>
…alue type

Co-Authored-By: jason.han <hanhuijun@gmail.com>
…d as

Co-Authored-By: jason.han <hanhuijun@gmail.com>
…it is held as

Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
…nt is held as

Co-Authored-By: jason.han <hanhuijun@gmail.com>
…e that resolves differently

Co-Authored-By: jason.han <hanhuijun@gmail.com>
…the scalar lattice

Co-Authored-By: jason.han <hanhuijun@gmail.com>

@devin-ai-integration devin-ai-integration 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.

Devin Review found 2 findings. Devin automatically fixed all 2 findings.

Fixed by Devin (2)
  • Quantity kind is lost over gRPC — The wire quantity now carries the quantity value type it is held as (Quantity.value_type), the service validates and restores it on the way back in, and every client keeps it; a round-trip test pins the sibling refusal.
  • Document queries drop quantity value types — A quantity a document query reads off a feature now keeps the quantity value type it is held as, on both the folded and the evaluated path, and the gRPC and JSON document encoders send it; a test pins that the sibling type refuses it sent back.

View findings in Devin Review · Follow Devin's work

Devin Review

devin-ai-integration Bot and others added 9 commits November 15, 2026 22:51
…t the value it evaluates to

The fixture bound a quantity to a Real feature, which a quantity is not (SysML v2.1 9.8.2), so
enginedemo::speed evaluated to a type mismatch and the parity tests compared two equal errors.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
…ents

Co-Authored-By: jason.han <hanhuijun@gmail.com>
…d, as before

A feature typed by a ScalarMeasurementReference keeps holding a quantity
written to it (hp : PowerUnit = 745.7 [W] in the OMG individuals example),
the contract the function-library map and TestBoundMeasurementUnit record.
The row's claim about the pilot is corrected to what it does.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
…ce family

A feature typed by any TensorMeasurementReference (a unit, scale, vector
reference or coordinate frame) holds a quantity written to it, as before
this branch. The written-value row states that one unjudged write and
stays approximate until it is ruled on.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
… the wire

A quantity left the service without the quantity value type it was held as, so
one read off an EnergyValue feature and sent back was taken by a TorqueValue
parameter. Quantity.value_type (valueType in JSON) names that type; the service
resolves it in the receiving model and refuses a name that is no quantity value
type or fixes another dimension. Every client keeps the field and sends it back.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
…t query answers

Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
…quantity-and-scalar-kinds

Co-Authored-By: jason.han <hanhuijun@gmail.com>

# Conflicts:
#	client/node/src/generated/sysml_pb.ts
#	client/python/opensysml/proto/sysml_pb2.py
#	client/rust/conformance/sysml.descriptor.binpb
@HuiJun
HuiJun added this pull request to the merge queue Nov 16, 2026
Merged via the queue into develop with commit 9e4c477 Nov 16, 2026
33 checks passed
@HuiJun
HuiJun deleted the fix/written-value-quantity-and-scalar-kinds branch November 16, 2026 23:36
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