Skip to content

fix(model): remove conflicting default on CommodityTariff RandomizationType - #4375

Closed
lboue wants to merge 1 commit into
matter-js:mainfrom
lboue:fix/commodity-tariff-randomization-type-default
Closed

fix(model): remove conflicting default on CommodityTariff RandomizationType#4375
lboue wants to merge 1 commit into
matter-js:mainfrom
lboue:fix/commodity-tariff-randomization-type-default

Conversation

@lboue

@lboue lboue commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Type of change

  • 🐛 Fix — corrects a defect or wrong behavior
  • Feature — adds new functionality or capability

Description

CommodityTariff.DayEntryStruct.RandomizationType declared both conformance "[RNDM]" (only allowed
when the Randomization feature is supported) and default: 0. Writing a dayEntries list entry that
omits RandomizationType auto-filled it with that default before validating conformance, then rejected
the very same fill:

Conformance "[RNDM]": Matter does not allow you to set this attribute

This only happens along the list-of-struct write path (Endpoint.setStateOfsupervisor.patch
StructManager) — a plain state property assignment (agent.get(...).state.dayEntries = [...]) or a
bare, non-list struct attribute with the identical field shape (e.g. CurrentDayEntry) don't trip it.

Per the spec text for both RandomizationOffset and RandomizationType (Application Cluster
Specification § 9.12.5.10.4–5, as transcribed in commodity-tariff.resource.ts): "If this field is not
indicated, randomization shall use the value in the Default* attribute."
Absence is spec-meaningful
(fall back to the cluster's own DefaultRandomizationType), not "value is None". RandomizationOffset
already has no default in the model, matching that — RandomizationType's default: 0 was
inconsistent with its sibling field, and collapsed that fallback semantic even when Randomization was
enabled, on top of causing the conformance crash when it wasn't.

Fix: remove the conflicting default: 0.

Backing evidence

(Log attached on #4374, from the real-world crash in a Matterbridge plugin. This PR also adds a
self-contained regression test — CommodityTariffServerTest.ts — that reproduces the exact same error
via MockServerNode + Endpoint.setStateOf(), with and without the fix.)

Checklist

  • I understand the code I am submitting and can explain how it works (AI policy)
  • Tests added or updated to cover the change
  • npm test passes — ran @matter/model's build, @matter/node's full test/behaviors/** suite (390/390, including the new regression test) and @matter/general's suite (1330/1330). Could not complete a full root npm test in this sandbox: the browser/web test step fails on a missing Playwright browser binary, unrelated to this change.
  • npm run format-verify and npm run lint pass (both run at the repo root, not just on the touched files)
  • CHANGELOG updated

…onType

DayEntryStruct.RandomizationType declared both conformance "[RNDM]" (only
allowed when the Randomization feature is supported) and default: 0. Writing
a dayEntries list entry that omits RandomizationType auto-filled it with that
default before validating conformance, then rejected the very same fill:

  Conformance "[RNDM]": Matter does not allow you to set this attribute

A bare (non-list) struct attribute with the identical field shape (e.g.
CurrentDayEntry) did not trip this — the auto-fill-then-reject only happens
along the list-of-struct write path (Endpoint.setStateOf -> supervisor.patch
-> StructManager), not a plain state property assignment.

Per the spec text for both RandomizationOffset and RandomizationType (Matter
1.6 Application Cluster Spec, cluster section 9.12.5.10.4-5, as transcribed
in commodity-tariff.resource.ts): "If this field is not indicated,
randomization shall use the value in the Default* attribute." Absence is
spec-meaningful (fall back to the cluster's own DefaultRandomizationType),
not "value is None" — RandomizationOffset already has no default in the
model, matching that; RandomizationType's default: 0 was inconsistent with
its sibling field and collapsed that fallback semantic even when
Randomization was enabled, on top of causing the conformance crash when it
wasn't.

Root-caused and reported against Luligu/matterbridge#625 (their
ElectricalUtilityMeter.addElectricalMeter()'s energyTariff option hits this
exact path). Full crash log and analysis in the linked issue.

Related issue: matter-js#4374

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@mergify

mergify Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@Apollon77

Copy link
Copy Markdown
Collaborator

nooo, we never change the model files directly!

And in fact the default: "None" is basically defined by spec ... so have you more details like exact code to check that and verify? But the fix - if we change the default at all is a model override but this more looks like some other root cause. I close this PR and will check the issue later

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.

2 participants