Skip to content

test: hold every driver to the rule the outage was about - #35

Merged
frahlg merged 4 commits into
mainfrom
catch-the-flap-class-at-the-source
Jul 28, 2026
Merged

frahlg merged 4 commits into
mainfrom
catch-the-flap-class-at-the-source

Conversation

@frahlg

@frahlg frahlg commented Jul 28, 2026

Copy link
Copy Markdown
Member

You asked for one place. This is what it takes to make device-drivers that place for this class of bug — and what it found.

The rule

A driver that keeps reporting telemetry must not keep failing reads.

The host counts every failed host.modbus_read against the poll whether or not Lua caught it with pcall — driver_poll: %d of %d modbus reads failed in FTW's go/internal/drivers/lua.go. A driver that decided it can live without a register, and then goes on reading it every five seconds anyway, gets marked offline by the stale-telemetry watchdog. The site reports nothing instead of one field less.

Emitting nothing while failing is not a violation. A device that cannot answer its identity block or its main data block really is unreadable, and failing the poll is the honest outcome. The violation is doing both.

tests/test_blueprint.py has held the blueprint to exactly this property since it was written. It applied to an imaginary driver and to none of the ones that ship.

What it found

Modbus drivers measured 50
violating on at least one register 49
probed addresses violating 497 of 543

Pixii and SolarEdge legacy were not unlucky. They were the two that met firmware omitting a register they happened to read. Every other Modbus driver has the same shape waiting for the right hardware.

The fix in #33 is visible in the numbers: unpatched baselines/ftw/drivers/pixii.lua scores 37, the fixed catalog driver scores 23. It removed the fourteen scale-factor reads. The value reads — AC power, frequency, temperature, SoC — are still there.

Why a baseline instead of a plain assertion

Failing 49 drivers would gate every unrelated change until the whole fleet is fixed. The counts go in drivers/tests/absent-register-baseline.json and the test ratchets:

  • a count that rises fails — new debt is blocked at the door;
  • a driver not listed must be clean — new drivers get the rule in full;
  • a count that falls also fails, asking for the file to be updated, so the debt cannot quietly be re-borrowed.

Shrink it, never grow it. make absent-register-report ID=<id> prints the registers for one driver.

The exemption was hiding the outage it caused

drivers/tests/conftest.py skips catalog-convention checks for every driver promoted from FTW. That is right for conventions this repository grew and FTW never spoke — spelling, key names, structure. It was applied to every parametrised check without distinction.

So a rule about what a driver does on hardware was being skipped for exactly the 34 drivers the outage happened in. The first run of this suite reported 46 passed, 34 skipped and looked green.

Checks marked holds_for_ftw_drivers now apply to every driver. That mark is the difference between "a convention we invented" and "a description of an outage".

Verification

  • The ratchet catches growth: setting pixii's baseline to 5 fails with pixii went from 5 to 23 registers it fails forever while still reporting, listing all 23.
  • With the exemption lifted, all 80 drivers are measured and none are skipped.
  • Full suite: 2111 passed, 2251 skipped — up 80 from main, no failures.

Nothing here changes a driver. It measures them.

Not in this PR

tools/check_public_boundary.py walks the filesystem with rglob and does not respect gitignore, so any git worktree under .claude/worktrees/ fails make boundary locally. CI is unaffected — no worktree exists there — but it makes the local gate unusable for anyone using worktrees, which CLAUDE.md tells contributors to run first.

🤖 Generated with Claude Code

frahlg and others added 2 commits July 28, 2026 18:24
The package target carried the narrow fix from #16, which guarded
register 40288 alone. Every other scale factor it reads would flap the
poll counter the same way on firmware that omits it: measured 3 reads
of an absent 40256 over 3 polls before this change, 1 after. It now
uses the same per-address probe as the catalog driver.

One parametrised test holds both files to the rule. The package target
having its own green test, run against a copy that kept the fix, is
what let the catalog regression reach customer hardware unseen.

Also records what the audit turned up. FTW's drivers/ is generated from
this repository at the commit pinned in FTW's drivers/BUNDLED_SOURCE.json,
and merging here does not move that pin — a gateway booting offline
keeps the old driver until someone runs FTW's sync script. Neither
repository's docs said so. AGENTS.md now states where a driver change
has to land, and that a promoted driver drops its baselines/ftw
exemption the moment it is edited.

README.md claimed all 37 promoted drivers stay byte-identical to their
baseline; three no longer are, which is what fixing a driver means.
SOURCE_IMPORT.md still weighed an import decision that #27 settled.
CLAUDE.md was missing and now points at AGENTS.md.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
A driver that keeps reporting telemetry must not keep failing reads. The
host counts every failed host.modbus_read against the poll whether or not
Lua caught it, so a driver that decided it can live without a register and
then goes on paying for it every five seconds is marked offline by the
watchdog. The site then reports nothing, which is worse than reporting one
field less.

Emitting nothing while failing is not a violation. A device that cannot
answer its identity block really is unreadable, and failing the poll is the
honest outcome. The violation is doing both.

tests/test_blueprint.py has held the blueprint to this property since it
was written. It applied to an imaginary driver and to none that ship.

Running it against the catalog found 49 of 50 Modbus drivers violating it
on at least one register, 497 of 543 probed addresses. Pixii and SolarEdge
legacy were not unlucky; they were the two that met firmware omitting a
register they read. Unpatched pixii scores 37 and the fix in #33 took it
to 23 -- the scale factors -- so the value reads are still there.

Failing 49 drivers would gate every unrelated change, so the counts go in
absent-register-baseline.json and the test ratchets: a count that rises
fails, a driver not listed must be clean, and a count that falls fails
until the file is updated so the debt cannot be re-borrowed.

conftest.py needed fixing first. It skips catalog-convention checks for
drivers promoted from FTW, which is right for conventions this repository
grew -- spelling, key names, structure. It was applied to every
parametrised check without distinction, so a rule about behaviour on
hardware was skipped for exactly the 34 drivers the outage happened in.
The first run of this suite reported 46 passed, 34 skipped, and looked
green. Checks marked holds_for_ftw_drivers now apply to everything.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
@frahlg
frahlg force-pushed the catch-the-flap-class-at-the-source branch from 59e3ff6 to 9efe544 Compare July 28, 2026 17:14

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9efe54447b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +65 to +66
if sf_present[address] == nil then
sf_present[address] = false

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Retry scale factors after transient read failures

When any scale-factor read fails because of a transient timeout or busy bus rather than an illegal-address response, this permanently records the register as absent and uses factor 0 until the driver restarts. For example, a single failed read of a present 40256 whose actual factor is -1 makes all subsequent meter power values 10× too large, because the register is never queried again; distinguish confirmed absence from transient errors or require bounded repeated failures before caching it.

Useful? React with 👍 / 👎.


local function fill_registers()
local regs = {}
for addr = 0, 65535 do regs[addr] = 100 end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exercise every supported Modbus variant

Filling every register with 100 exercises only one branch of drivers whose register maps depend on device identity. In drivers/lua/sungrow.lua, register 4999 equal to 100 classifies the device as a string inverter, so the probe never discovers hybrid-only reads such as 12999, 13000, 13002, 13019, 13040, and 13026; an absent-register regression in the supported SH hybrid path can therefore pass this catalog-wide ratchet. Run discovery with representative profiles for each supported variant rather than one synthetic register image.

Useful? React with 👍 / 👎.

ROOT = Path(__file__).resolve().parents[2]
LUA = ROOT / "lua55"
PROBE = ROOT / "drivers" / "tests" / "lua_harness" / "absent_register_probe.lua"
DRIVERS = ROOT / "drivers" / "lua"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include package targets in the absent-register ratchet

The new ratchet parametrizes only drivers/lua, so independently shipping targets such as packages/v1/sungrow/targets/ftw.lua and ftw-observe.lua are not checked; only Pixii receives a separate hand-written target test. An absent-register regression introduced directly into another package target will therefore pass make check, despite package targets being separate copies that can drift from the catalog driver. Include applicable package targets in this parametrization or add an equivalent generic target suite.

AGENTS.md reference: AGENTS.md:L27-L30

Useful? React with 👍 / 👎.

@frahlg
frahlg force-pushed the catch-the-flap-class-at-the-source branch from 295e8b6 to 2a55cb8 Compare July 28, 2026 17:25
claude added 2 commits July 28, 2026 17:25
Signed-off-by: Fredrik Ahlgren <[email protected]>
Co-authored-by: Claude Sonnet 5 <[email protected]>
Merging main pulled in #34's pixii-package and AGENTS.md/README.md/
SOURCE_IMPORT.md/CLAUDE.md changelog entries a second time, since this
branch had authored the same entries in parallel before #34 merged.
Drop the duplicate copy.

Signed-off-by: Fredrik Ahlgren <[email protected]>
Co-authored-by: Claude Sonnet 5 <[email protected]>
@frahlg
frahlg force-pushed the catch-the-flap-class-at-the-source branch from 2a55cb8 to 3569729 Compare July 28, 2026 17:26
@frahlg
frahlg merged commit 6291cf9 into main Jul 28, 2026
5 checks passed
@frahlg
frahlg deleted the catch-the-flap-class-at-the-source branch July 28, 2026 17:28
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