Skip to content

fix(pixii): give the package target the same probe as the catalog driver - #34

Merged
frahlg merged 1 commit into
mainfrom
align-pixii-package-target-with-catalog-driver
Jul 28, 2026
Merged

frahlg merged 1 commit into
mainfrom
align-pixii-package-target-with-catalog-driver

Conversation

@frahlg

@frahlg frahlg commented Jul 28, 2026

Copy link
Copy Markdown
Member

Follow-up to #33. Fixes the divergence that PR left behind, and records what auditing it turned up.

The package target had the narrow fix

packages/v1/pixii/targets/ftw.lua still carried the guard from #16, which probed register 40288 alone in driver_init. The catalog driver got the general per-address probe in #33. That left the two files disagreeing, and left the package target open to the same flap on any of the other eleven scale factors it reads — 40084, 40086, 40106, 40177, 40180, 40182, 40184, 40240, 40249, 40251, 40256.

Measured against an absent 40256 over three polls:

reads
package target before 3
package target after 1

Package version 1.2.3 → 1.2.4. It runs its own version line, so bump_driver.py deliberately leaves it alone; both the recipe and the Lua DRIVER block were moved by hand.

The regression test is now parametrised over both files. A package target with its own green test, run against a copy that happened to keep the fix, is exactly what hid the catalog regression for two weeks.

What the audit found

FTW's bundled snapshot does not follow a merge here. FTW generates drivers/ from this repository at the commit pinned in its drivers/BUNDLED_SOURCE.json, and its CI rejects drift — that side is well built. But the pin currently sits at 1f67078 (#29) and has not moved since, so it misses #31, #32 and #33. A gateway booting offline still runs the Pixii and SolarEdge drivers with the flap in them. Moving that pin is a change in the FTW repository, so it is not in this PR.

Neither repository's docs said the pin exists. FTW's BUNDLED_SOURCE.json tells you not to edit a driver there. Nothing here told you that merging is not the last step. AGENTS.md gains a section naming all three places a driver can exist — catalog driver, optional package target, FTW snapshot — and what each one needs.

The package target is not generated from the catalog driver. They are two hand-maintained files with separate version lines and no check comparing them. Worth knowing before the next fix.

A promoted driver silently drops its test exemption when edited. conftest.py decides byte-identity by content, so editing one makes the whole catalog suite apply at once. That is deliberate and documented in the code, but nothing warned a contributor it was about to happen — it is what surfaced the _extract_decode_calls bug in #33. Now in AGENTS.md.

Stale instructions, corrected. README.md claimed all 37 promoted drivers stay byte-identical to baselines/ftw/drivers/; three no longer are. SOURCE_IMPORT.md still weighed whether the bundled drivers could replace their catalog namesakes "one at a time" — #27 settled that by promoting all 37 at once. CLAUDE.md was missing, against the standard that every repo carries one; it points at AGENTS.md rather than copying it.

Verification

make check passes — 2031 passed, 2251 skipped.

Not verified on live hardware. The Pixii package target is channel: beta with control_enabled: false, so this changes a read path only.

🤖 Generated with Claude Code

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]>
@frahlg
frahlg merged commit 3f62a00 into main Jul 28, 2026
5 checks passed
@frahlg
frahlg deleted the align-pixii-package-target-with-catalog-driver branch July 28, 2026 16:26

@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: 9715d04a28

ℹ️ 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 transient scale-factor failures before caching absence

When a scale factor's first read fails because of a transient timeout or short response, pcall provides no evidence that the register is actually absent, yet these lines permanently cache it as absent. Every later poll then skips the register and applies sf=0, so a present factor such as -1 produces telemetry off by 10× until the driver restarts; previously the general scale-factor reads retried on the next poll. Distinguish Illegal Data Address from transient failures or require bounded confirmation before caching, and apply the correction to the identical catalog helper as well.

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

Useful? React with 👍 / 👎.

frahlg pushed a commit that referenced this pull request Jul 28, 2026
Updating this branch against 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.
frahlg pushed a commit that referenced this pull request Jul 28, 2026
Updating this branch against 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 pushed a commit that referenced this pull request Jul 28, 2026
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 added a commit that referenced this pull request Jul 28, 2026
Codex review on #39 found the guard incomplete, and it was right. When
register 4999 fails or returns the documented 0/0xFFFF sentinel,
detection settles on "unknown" and nothing ever classifies the device as
"string". A guard testing for "string" alone falls straight through, so
an SG inverter with an unreadable device-type register still got the
13049/13051 writes and still reported success.

The suggested fix -- gate on a positively identified "hybrid" -- trades
one outage for another. An SH inverter whose 4999 is unreadable settles
on "unknown" too, but its battery block answers, so the driver reads that
battery and reports its SoC every five seconds. Refusing to command a
battery the driver is actively reading is its own outage, and detection
giving up is common enough that DETECT_ATTEMPTS exists for it.

So the rule is evidence rather than labels: take a battery command when
the device named itself a hybrid, or when its battery registers have
answered. Refuse otherwise. The read path may probe its way out of
"unknown" because a failed read is bounded and self-correcting; a write
to a register the model does not implement is neither.

packages/v1/sungrow/targets/ftw.lua had the identical gap and gets the
identical fix, so both control paths still refuse on one rule with one
no_battery code.

The v2 target had no pytest at all -- only the Lua harness, which CI does
not run, which is the same way Pixii's 40288 came back. One parametrised
test now holds both files to the rule, as #34 learned to do. It pins the
refusal on a named string inverter and on an unidentified one that
answers no battery register, and pins both ways refusing could go too
far: a hybrid must still take a battery command, named or merely
observed, and a string inverter must still take a curtail.

Verified against the previous guard: the unidentified-string case fails
for the catalog driver and the v2 target alike.

Signed-off-by: Fredrik Ahlgren <[email protected]>
Co-authored-by: Claude Opus 5 <[email protected]>
frahlg added a commit that referenced this pull request Jul 29, 2026
1.5.3 required the model to have named itself a hybrid or a battery
register to have answered. That is right for a dispatch and wrong for
zero.

Zero is not a dispatch. It is the host handing the device back to
itself -- forced mode off, setpoint nought -- and it arrives from the
lifecycle rather than the planner, so it lands before the first poll,
which is exactly when nothing has been confirmed. Refusing to write
"stop" is a different risk from refusing to write "charge": a device
left in a forced state stays there. On a genuine string inverter the
write fails at the Modbus layer and costs nothing; the outage it
prevents is a battery with no way to be told to stop.

Non-zero setpoints still need evidence, so #40's hole stays shut.

Both control paths move together, as #34 taught. Five new pytest cases
pin the rule on a named string inverter, an unidentified one, a hybrid,
and -- the case FTW's suite exercises -- before any poll at all.

Also fixes the mock that made this hard to see. host_mock.lua answered
a failing modbus_read with error(), but FTW's binding pushes nil plus a
message and returns; it never raises. Every driver wraps the call in
pcall and works either way, which is why it went unnoticed for so long.
Code written correctly for the real host did not: the v2 target checks
the returned error, and under the mock it threw instead, taking the
whole command down rather than reporting a structured failure. The mock
now returns what the host returns, and nothing broke -- which is the
point. It had been lying for free.

test_pilot_safety_metadata_is_explicit pinned the sungrow package
version. That test is about what the package promises -- read-only, no
commands, no control permissions -- and a version is not one of those.
The pin made an unrelated safety test the thing that failed on every
legitimate bump. Fourth hand-maintained copy of a contract to drift
here.

Verified against FTW: the whole Go suite passes with this driver,
including TestSungrowZeroBatteryCommandForcesIdle, which was the last
thing blocking the pin move.

Signed-off-by: Fredrik Ahlgren <[email protected]>
Co-authored-by: Claude Opus 5 <[email protected]>
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