Matter Behavioural-Parity Contract¶
Audience: every contributor and AI agent that touches code in this module. This is a standing contract, not an audit you run once. Read it before your first change here and treat it as binding.
go-fabric implements the Matter specification (currently 1.6.1) in Go. It
is not a port of matter.js's
TypeScript code, but it follows matter.js HEAD as its reference
implementation: matter.js is production-hardened against Apple Home, Google
Home and Alexa, and that hardening is what this module adopts. matter.js is our executable specification: where its production-hardened
behaviour departs from the spec text, we follow matter.js and record the
departure. The spec still defines what is mandatory. The
order of authority is fixed:
- matter.js HEAD decides wherever it models something — schema values
verbatim, implemented behaviour mirrored. Where the spec text and
matter.js's behaviour diverge, matter.js wins; a deliberate exception is
recorded in
notes/parity/by_design.md. - connectedhomeip decides where matter.js leaves a behaviour open, and for tool and controller behaviour matter.js does not model.
- The specification is the frame both are read against.
The scope is everything the specification makes mandatory — certifiability is a goal — plus what matter.js implements; going beyond matter.js is allowed when justified and registered. Three test sources hold it: matter.js's tests ported by meaning rather than line by line, the chip-tool suite with the CSA certification cases, and this module's own tests.
This page defines what "parity" means in practice and which standing guards keep it honest, so that a change which merely looks right but drifts from the reference cannot land unnoticed.
It complements the
matter.js is the gold standard section of this repository's
CLAUDE.md: that one tells you matter.js HEAD is the gold standard and how to
regenerate the schema; this one tells you what parity means, why
behaviour parity (not just schema parity) is the bar, and which standing
guards enforce it. What the ecosystems themselves do with the result is
collected in
Matter Ecosystem Observations.
1. The principle¶
Think for yourself, and always verify against matter.js / connectedhomeip. Mirror behaviour, not just shape.
Two halves, both mandatory:
- Reason about the change. Understand the cluster, the command, the state machine, the failure modes. Do not cargo-cult.
- Verify against the gold standard. Before you write a fix or feature, read the corresponding matter.js source (and connectedhomeip for wire-truth). Your implementation mirrors theirs — same defaults, same constraints, same status codes, same order, same wire shape — unless a divergence is deliberate and recorded.
A change that "looks right" but was never checked against matter.js is not acceptable, no matter how reasonable it seems. The protocol's edge cases were encoded into matter.js through real interop testing against Apple Home, Google Home, and Alexa; we mirror that hard-won behaviour rather than re-deriving it.
2. Why matter.js / chip, and why behaviour¶
matter.js HEAD is a production-tested, continuously-evolving Matter stack (it is not CSA-certified, and neither is this module). connectedhomeip (chip) is the CSA reference. Together they are the authority for:
- cluster IDs, revisions, attribute / command / event IDs (schema), and
- defaults, constraint enforcement on writes, command semantics, status codes, conformance gating, subscribe / report cadence, commissioning and CASE state machines (behaviour), and
- the byte-level wire shape (TLV, IM messages, sigma).
Schema parity is necessary but not sufficient. It is easy to advertise the right attribute IDs and revisions and still get the behaviour wrong — accept a write matter.js rejects, return the wrong status, skip a constraint, drop a session that must survive. Those defects pass every schema test and surface as silent Apple / Google pair-aborts or mis-behaving devices that take days to attribute back. Behaviour parity is the bar.
This is not hypothetical: a parity sweep found a whole class of write-constraint
and command-semantics defects (wrong setpoint limits, an unenforced
percent-max, a SupportedOperatingModes bitmap that marked a mandatory mode
unsupported, a MoveToColorTemperature that never moved, an UpdateNOC that
tore down its own response session) — every one of which a schema test would
have waved through.
3. The workflow for every change¶
- Read the matter.js source first. Likely paths:
- schema constant / revision / id →
../matter.js/packages/model/src/standard/elements/<name>.element.ts - cluster behaviour (defaults, mandatory attrs, conformance, write
constraints, command logic) →
../matter.js/packages/node/src/behaviors/<name>/<Name>Server.ts - device type →
../matter.js/packages/node/src/devices/<name>.ts - wire codec / IM / sigma →
../matter.js/packages/types/src/tlv/,../matter.js/packages/protocol/src/ - wire-truth cross-check →
../connectedhomeip/src/app/...,../connectedhomeip/src/messaging/... - Mirror the behaviour in Go idiom (struct-with-methods,
context.Context, goroutines for TS decorators / mixins /Promise<T>). Keep the same defaults, constraints, status codes, and order. - Cite the source in the Go code:
// Mirrors matter.js packages/node/src/behaviors/.../FooServer.ts:bar(or the chip path). Provenance must survive drift. - Add a parity test — behaviour, not just schema. A new constraint adds a row to the negative-write parity table (§4). A new cluster server adds a schema parity case. A wire change adds / updates a TLV fixture. PRs without parity coverage are rejected.
- Record deliberate divergences in
notes/parity/by_design.md(the living catalogue). A non-trivial divergence also gets an ADR underdocs/adr/. Valid divergences are TypeScript-only optimisations that fight Go's GC, or decorator patterns with no Go equivalent. Invalid divergences are hand-coding cluster revisions, attribute IDs, constraint defaults, status codes, or Apple-required tag patterns — those go verbatim from matter.js.
4. The standing guards (enforcement)¶
Parity is held by build- and test-time guards, not by periodically regenerated audit reports. These are the mechanism; keep them green and extend them with every change:
| Guard | Location | Locks |
|---|---|---|
| Schema parity | parity/ (the embedded matter.js HEAD extract) + schema/parity_test.go, schema/provenance_test.go, schema/staleness_test.go, and the schema and revision *parity_matterjs_test.go files across the tree (the behavioural ones have rows of their own below) |
cluster / device-type IDs, revisions, attribute / command / event IDs vs matter.js HEAD; that the generated Go maps match the snapshot they were generated from |
| Behavioural negative-write parity | cluster/matter_negative_write_parity_test.go |
a write/invoke matter.js rejects is rejected with the matching IM status (ConstraintError 0x87 / InvalidCommand 0x85), plus boundary positive controls against over-rejection. Add one row per new constraint. |
| Behavioural gate parity | endpoint/write_gates_parity_matterjs_test.go, endpoint/invoke_gates_parity_matterjs_test.go, bridge/imwrite_parity_matterjs_test.go, im/mandatory_field_parity_matterjs_test.go |
the per-path rules of a write and the per-path gates of a concrete and a wildcard invoke through the IM handlers and the TopologyDispatcher, in the order of the matter.js files each test names at the pin; the Write, Invoke and Timed interactions as they are answered on the wire through the bridge; an absent mandatory IM field answered InvalidAction |
| Wire-codec parity | tlv/parity_matterjs_test.go, im/wire_fixtures_parity_test.go, bridge/groups_parity_matterjs_test.go (GroupKeyManagement / Groups command payloads), bridge/groupcast_parity_matterjs_test.go (Groupcast commands, Membership / AuxiliaryAcl values and events) and groups/parity_matterjs_test.go (group key schedule and sealed group messages), each reading its own testdata/ copy of the fixtures; the generators live at notes/parity/matter/ |
byte-level TLV / IM / group-message shape |
| Reference-controller validation | conformance/ and internal/chiptool/ under the chiptool build tag, driven by .github/workflows/chiptool.yml |
end-to-end behaviour against the real chip-tool commissioner, plus borrowed CSA Test_TC_* cases |
| Go-TH certification leg | internal/chiptool/gocert_test.go and the gocert_*_test.go cases under the chiptool build tag, make chiptool-gocert (part of make chiptool-test locally; in CI the gocert job of .github/workflows/chiptool.yml, in three groups by family through GOFABRIC_GOCERT, while the chiptool job skips the leg), counts in internal/chiptool/testdata/chip-cases.golden.json → goCert |
the certification cases matter.js automates in support/chip-testing/test/cert/ at the snapshot's pin (db021da0, parity/schema.json → matter.sourceCommit; a case whose file moved on in a way the leg cannot follow yet stays the port of an earlier commit, goCertCase.readAt — none does today), each case of that list run or classified with its reason (matterJSCasesNotRun, controllerRoleCases), in both roles: read mirrored, the reference daemon answers the Go controller as the TS file's TH expects; in matter.js's own direction (role "dut" in the counts), the Go controller is the DUT against the daemon as the TS file's TH device, its PICS its own declarations. Step by step, each step citing its TS line and naming its evidence; a step whose PICS is false is recorded skipped, and a changed step count fails the case |
| Per-attribute timed-write parity | endpoint/timed_write_parity_matterjs_test.go, bridge/write_timed_stamp_test.go |
an attribute with the timed access quality answers NEEDS_TIMED_INTERACTION outside a timed interaction on a concrete path and is skipped on a wildcard one, after the access check, and is applied inside one (matter.js AttributeWriteResponse.ts:243-247, :343-345); the snapshot has no timed attribute yet, so the test marks one |
| chip-tool proof legs | groups and subscription-restart of TestChipToolSuite (internal/chiptool/groups_proof_test.go, internal/chiptool/subscription_proof_test.go), make chiptool-test and the chiptool job of .github/workflows/chiptool.yml, which fails when the groups leg skips for want of multicast |
chip-tool's own group configuration and Groupcast JoinGroup make the daemon act on a multicast OnOff Toggle; a subscription chip-tool holds survives a daemon restart, re-established by the daemon without a new SubscribeRequest |
| Surface snapshot | script/surfacecheck, make surface-check, the surface step of .github/workflows/ci.yml |
what a controller sees of the reference daemon (--dump-surface: the assembled topology — every endpoint's device types and every cluster's revision, FeatureMap and lists, the clusters the endpoint assembler mounts included); every change is a review diff |
| Specification levels | parity/levels/ (one file per Matter revision a matter.js release tag models, make generate-levels), script/levelgen (schema/levels_gen.go, docs/reference/spec-levels.md), the drift tests schema/levels_test.go and examples/reference-bridge/surface_level_test.go, and the chipdm level cross-check (internal/chipdm TestChipDataModelLevels, make chipdm-check) |
which device types, clusters, features, attributes, commands and events exist at each level the surface's level policy composes at; the daemon at every level serves nothing the level does not know without a keep decision |
| matterjs-server test-porting register | script/testparity/ (matterjsserver_register.json against the committed snapshot matterjsserver_tests.json, taken with -server-snapshot from MATTERJS_SERVER_DIR at matterjsServerCommit), rendered to notes/parity/matterjsserver_tests.md; the same make testparity-check |
every test file of the matterjs-server parts the module ports ahead of matter.js (its camera stream management, phase 37; its network topology, #380) at the matterjs-server pin — ported, partial, planned or excluded (class host-server for a test of its WebSocket server, which is go-fabric-server's), with the planned count on a ratchet |
| Controller profiles | notes/parity/controller_profiles.md (the evidence register), script/profilegen (surface/profiles_gen.go, make generate-profiles), its drift test TestRegisterIsCurrent and its register test TestCommittedRegister |
the generated profiles are exactly the register's rows; every row names a known profile, a parseable element of the pin's schema, a confidence and a source; a remove row (and a level row) needs the confidence Reproduced — any other fails the test — so only a measured row removes an element, and a Reported or Inherited row is a warning decision in the surface report |
| matter.js pin freshness | .github/workflows/matterjs-pin.yml + schema/staleness_test.go |
the embedded extract does not silently fall behind matter.js HEAD |
| matter.js citations | script/citecheck, make cite-check (needs a matter.js clone in MATTERJS_DIR), the cite-check job in .github/workflows/ci.yml |
every <file>.ts:<line> the Go code cites resolves at the pin (parity/schema.json → matter.sourceCommit, or the citation's own at <sha>) — a packages/… path exactly, a partial path as a unique suffix, a bare file name as a unique basename — and its lines exist (hard: fails); a citation whose sentence gives, nearer to it than to any other reference, names the cited file contains, none of them within ±15 lines of the cited range, is drift (soft), listed in the committed script/citecheck/drift.json and held by the exact ratchet citecheckDriftRatchet. Fails on a hard error and when regenerating moves drift.json or summary.md; make cite-report regenerates them, committed with the ratchet constant in the same commit. A citation whose sentence names matterjs-server resolves against a second clone, MATTERJS_SERVER_DIR (default ../matterjs-server), at the sentence's own at <sha> — it has no pin, so a sentence naming none is a hard error; without that clone the guard exits 2 as it does without matter.js. |
| Ahead-of-matter.js markers | script/aheadcheck, make ahead-check (needs a matter.js clone in MATTERJS_DIR; MATTERJS_REF, default HEAD), the weekly ahead-markers job in .github/workflows/matterjs-pin.yml against origin/main |
every row of the Ahead of matter.js register in notes/parity/by_design.md names a matter.js file and a text that holds while matter.js lacks the behaviour; the text is present at the pin (otherwise the row is wrong) and at the ref (otherwise the finding "caught up?" names the row, the trigger of the pin-lift reconciliation); a marker is a quoted text or class <Name> (the class's whole body at the pin); a row without a marker fails. Exit 1 on a finding, 2 when the check could not run. And the measured surface column with its completeness check: script/aheadcheck's surface test builds every cluster a server declares an ahead row for with and without the row's elements, every declared row must change FeatureMap or a list and read yes, and the column and the declarations (node.AheadRows) must match in both directions. |
| One time port | clock/noraw_test.go, part of make test |
no production .go file outside clock/, examples/, script/ and the nested modules (a directory with its own go.mod) calls or references time.Now, time.AfterFunc, time.NewTimer, time.NewTicker, time.Sleep, time.After, time.Tick, time.Since or time.Until; every interval runs on a clock.Clock, so a test drives matter.js's timings with clocktest.Fake (after matter.js MockTime) instead of the wall clock. Exceptions are listed in the test with a reason and an exact count (one: the two socket read deadlines of mdns/socket.go). |
| Divergence catalogue | notes/parity/by_design.md |
every intentional deviation, with rationale and what pins it |
| Open-gap register | notes/parity/matter_behaviour_findings.md |
known behaviour gaps that are not by design, as scoped fix packages |
| Test-porting register | script/testparity/ (register.json against the committed snapshot matterjs_tests.json), rendered to notes/parity/matterjs_tests.md; make testparity-check and the CI job testparity |
every *Test.ts under matter.js's packages/general/test, packages/model/test, packages/node/test, packages/nodejs/test, packages/protocol/test, packages/thread-br-client/test and packages/types/test at the pin (the roots since phase 33; packages/matter.js, nodejs-ble, nodejs-ws, testing and support/codegen stay out, each named with its reason on the rendered page) is ported, partial (naming the it cases not covered), a ported or partial entry's left naming each it case that will not be ported with its class (an exclusion class, by-design with the by_design.md entry, or skip with the Go subtest) and reason, never also missing, planned or excluded with one of five classes; every Go test an entry names exists; a ported, partial or excluded verdict fails once its matter.js file changes; the number of planned files, of ported files, of missing it cases summed over the partial entries and of left cases sit exactly on testparityPlannedRatchet, testparityPortedRatchet, testparityMissingRatchet and testparityLeftRatchet; every Go test whose body is a t.Skip("FixMe: …") is a row of the register's skips |
When a parity sweep is genuinely warranted, prefer extending these guards over producing a throw-away report: a guard catches the next regression, a report catches only today's.
Sweeping a pin bump¶
Moving parity/schema.json to a newer matter.js commit propagates the
schema mechanically; the behaviour that changed between the two pins does
not follow by itself. Every pin bump is therefore followed by a sweep of the
commits in between, the way
notes/parity/sweeps/2026-10-f07365a8-85cf6647.md
was made:
- List the commits, not just the files:
git -C ../matter.js log --oneline <old>..<new> -- packages/node/src packages/protocol/src packages/types/src. A commit message carries the reason a file diff hides. - Read each commit at its pin (
git -C ../matter.js show <commit>) and give it one verdict: (1) not applicable to the roles this module plays (device-side responder, commissioner/controller) or to a feature it does not have — say which; (2) already matches — cite the Go code; (3) go-fabric differs — fix it through the workflow above (read, mirror, cite, unit or parity test, CHANGELOG), or, if it is large, record a finding in the open-gap register. - Commit the table as
notes/parity/sweeps/<yyyy-mm>-<old>-<new>.md(commit, subject, verdict, Go reference / fix commit / finding), and re-run every certification family that covers a verdict-3 change. - Refresh the test snapshot (
make testparity-snapshot, against the same clone):make testparity-checkthen names every test file upstream added or removed and everyported,partialorexcludedentry whose file changed. Re-check those mappings and exclusions, update theirsnapshotSha, and movetestparityPlannedRatchetwith theplannedcount in the same commit.
5. Where the host's own parity obligation begins¶
This module owns the wire format. A bridge is this module plus a host that
projects its own devices onto clusters, and the host half has its own gold
standard — for OpenCCU-Loom, the reference consumer, that is aiohomematic on
the CCU side. The two reference layers do not overlap: CCU wire knowledge stays
in aiohomematic, Matter wire knowledge stays in matter.js.
The boundary is the contract/ package. Everything on this side
of it mirrors matter.js and is covered by §4. Everything on the far side —
which data point becomes which cluster, which device type a product maps to —
is the host's decision and the host's parity contract. A host that gets the
projection wrong produces a device that pairs and then misbehaves, which is
exactly the class of defect §2 is about; it is simply not caught by the guards
listed here.
One asymmetry worth stating: a port of a CCU stack converges, because the source stands still. The Matter mirror never "finishes" — matter.js HEAD bumps cluster and device-type revisions, and the wire shape is interop-critical. Parity here is a permanent discipline, re-verified on every change and whenever the matter.js pin is advanced.
6. The non-negotiable checklist¶
Before you open a PR:
- [ ] I read the matter.js (and, for wire-truth, chip) source for this cluster / behaviour / device-type.
- [ ] My implementation mirrors its defaults, constraints, status codes, and
order — or the divergence is recorded in
by_design.md(+ ADR if non-trivial). - [ ] I cited the matter.js / chip
path:linein the Go code. - [ ] I added or extended a behaviour parity test (a constraint row, a command-semantics case, a wire fixture) — not only a schema assertion.
- [ ] The standing guards in §4 are green.
If you cannot check every box, the change is not ready.