Skip to content

M8 Local Powerwall, part B: merge classes, gateway healing, read-only check - #40

Merged
Bre77 merged 16 commits into
milestone/m8a-powerwallfrom
milestone/m8b-powerwall
Nov 2, 2026
Merged

Bre77 merged 16 commits into
milestone/m8a-powerwallfrom
milestone/m8b-powerwall

Conversation

@Bre77

@Bre77 Bre77 commented Nov 2, 2026

Copy link
Copy Markdown
Member

Second half of M8. Stacked on milestone/integration. ./powerwall stays out of tsdown.config.ts and package.json exports, so nothing here reaches npm consumers, and this PR has no changeset, like the earlier PW issues.

Issues

ENG-73 (PW-10): finished. test/powerwall-router.types.ts puts the real PowerwallEnergySite in the real EnergySiteRouter in front of the real TeslemetryEnergySite, replacing the stand-in. tsconfig.test.json checks it in CI. Removing a case fails the check, as does removing a local method or changing a signature: each was tried and failed tsc.

ENG-79 (PW-12): done.

  • All of test_energysite_merge_contract.py (pure helpers, already in test/energysite-router.test.ts)
  • Zero overlays, null does not
  • A cloud update keeps local keys
  • Backoff goes 1, 2, 4, 8, 12 ticks and resets
  • A command mid-read discards the poll
  • A held value survives a failed poll
  • owned_keys without island_status leaves that key at the cloud value
  • healthy is null, then true or false
  • A test asserts the module starts no timer

ENG-80 (PW-13): done.

  • Each failover row in document 02 section 3, with a real site on the fake gateway behind EnergySiteRouter
  • A local-absent method goes straight to the cloud
  • All five connect_gateway outcomes, and a cloud lookup failure counts as null
  • moved persists nothing
  • verify_local_gateway tells a wrong password from a rejected key

ENG-81 (PW-14): done, with R13 and R14 outside the script.

  • No path to a write method
  • Prints no value from a fake-gateway run holding marker strings
  • Docs state the writes are not yet verified from Node on hardware, on each one (DEC-P option A)

Proof the script cannot write

test/powerwall/readonly-check.test.ts checks three ways, all from allowlists, so a new client method counts as a write until someone says otherwise:

  1. Source. A TypeScript AST walk rejects any forbidden name, computed member access, dynamic import, prototype walk or unlisted import. The test adds each bypass to the script's text and confirms it is caught.
  2. Run time. Every write method on PowerwallClient and PowerwallEnergySite is replaced by a trap for a full run.
  3. Wire. The fake gateway records only read requests, and config.json is byte-identical afterwards.

The script's client and site are also Pick types of read methods, and CI compiles scripts/*.ts. Adding a real write call to the script (three variants, one obfuscated) failed all three layers.

The script has run only against the fake gateway, including once as a real process with real waits.

For review

  • R13 and R14 are not in the script. R13 is a Python comparison. R14 needs a cloud lookup, and you specified host, password path and key path as its only inputs. ENG-86 says R1 to R14 run "with the PW-14 script", so R14 needs a separate run or a follow-up.
  • tsx is a new dev dependency, for pnpm powerwall:check. The script imports src/, whose .js specifiers Node's type stripping cannot resolve. pnpm-workspace.yaml sets allowBuilds: esbuild: false; the script ran fine that way.
  • SiteInfoMerge has last_error. ENG-79 asks for it and document 02's sketch omits it.
  • A discarded SiteInfoMerge read still updates healthy. Document 02 doesn't cover this case. healthy says whether the gateway answered, so I kept that separate from whether the snapshot was used.
  • POWERWALL_SOAK_TICKS is an addition: an optional variable to shorten R12, default 120 ticks (10 minutes).
  • R3 requires site, battery, load and solar meters, not generator. Document 07 lists generator, but live_status already treats a missing meter as null, so a site without one should not stop the run.
  • connect_gateway rejects a bad PEM instead of returning an outcome, because it cannot build a client and no address repairs that.
  • verify_local_gateway raises PowerwallKeyRejectedError only for PowerwallAuthenticationError on the signed read, as document 07 says. Other faults pass through unchanged.

No hardware was used.

🤖 Generated with Claude Code

Bre77 and others added 6 commits November 2, 2026 13:55
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves export and doc conflicts between the sibling milestones, and updates
the log test to trigger_homelink's Python argument order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eRouter (ENG-73 / PW-10)

Replaces the stand-in for document 02's Routed types with the real router in
a test/*.types.ts file, so tsconfig.test.json checks it in CI. One case per
local method, through a mapped type: dropping a case fails the compile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Document 02 section 4. Neither owns a timer: the caller calls poll() on its
own schedule. test_energysite_merge_contract.py's cases are the pure helpers,
already ported to test/energysite-router.test.ts.

SiteInfoMerge also exposes last_error, as the issue asks and document 02's
sketch omits. A discarded read still updates healthy, because that says
whether the gateway answered, not whether the snapshot was used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… / PW-13)

Document 07 sections 14 and 15. Failover tests put a real PowerwallEnergySite
on the fake gateway behind EnergySiteRouter, one row per error in document 02
section 3. The router needed no per-method list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scripts/powerwall-readonly-check.ts covers R1 to R12 of document 09 section
4.1, and prints only key names, types and pass or fail. R13 is a Python
comparison, and R14 needs cloud credentials the script does not take.

Its tests prove it cannot write on the source, at run time and on the wire,
from allowlists, so a new client method counts as a write. tsx joins the dev
dependencies to run it: the script imports src/, whose .js specifiers Node's
own type stripping cannot resolve.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 51 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 90 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML; Path: .coderabbit.yaml
  • Review profile: CHILL
  • Plan: Team
  • Run ID: efb45c34-c002-429a-a4ac-f717db7ecf72
Commits

Reviewing files that changed from the base of the PR and between 1156684 and d95f43e.

Files ignored due to path filters: 1
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing: 36
  • .changeset/energy-island-modes.md
  • .changeset/energy-island-rejection.md
  • .changeset/log-routable-message.md
  • AGENTS.md
  • README.md
  • docs/powerwall.md
  • package.json
  • pnpm-workspace.yaml
  • scripts/powerwall-readonly-check.ts
  • src/energyisland.ts
  • src/energyparsers.ts
  • src/energyspecific.ts
  • src/log.ts
  • src/powerwall/client.ts
  • src/powerwall/energysite.ts
  • src/powerwall/gateway.ts
  • src/powerwall/index.ts
  • src/powerwall/merge.ts
  • src/powerwall/transport.ts
  • src/signing/energy.ts
  • src/teslemetryenergy.ts
  • test/energy-dispatch-island.test.ts
  • test/energy-signing.test.ts
  • test/helpers/fakegateway.ts
  • test/log.test.ts
  • test/powerwall-router.types.ts
  • test/powerwall/client-commands.test.ts
  • test/powerwall/client-config.test.ts
  • test/powerwall/client-island.test.ts
  • test/powerwall/energysite.test.ts
  • test/powerwall/gateway.test.ts
  • test/powerwall/merge.test.ts
  • test/powerwall/readonly-check.test.ts
  • test/powerwall/router-types.test.ts
  • test/teslemetry-energy.test.ts
  • tsconfig.test.json
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Bre77
Bre77 changed the base branch from milestone/integration to milestone/m8a-powerwall November 2, 2026 04:28
@Bre77
Bre77 added this pull request to stack #43 November 2, 2026 04:29
Bre77 and others added 9 commits November 2, 2026 16:09
… / PW-8)

A BUSY fault, HTTP 500 or common.error_response while revoking a compromised
key returned success with the key still paired. Tolerate only an empty reply,
plus code 5 on a cancel. This overrides document 07 section 8 and differs from
Python. Changes the tests that pinned the swallowing in client-commands.test.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…G-67 / PW-9)

Cloud set_island_mode checked only error_response, so REJECTED_LOW_ENERGY came
back as a normal reply while LAN raised. Both now share island_mode_rejection.
The signed path reads the envelope, and Teslemetry's keyless route answers the
decoded leaf, { response: { result } }, per its source and tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-67 / PW-9)

Modes 0, 3, 5, 99 and -1 were signed and sent, a missing mode sent 1 and closed
the contactor, and "6" sent 6 with force false. EnergyIslandMode names only
ON_GRID and OFF_GRID, and they are all Python's go_off_grid and reconnect_grid
use, so nothing else passes. The check also sits in EnergyDeviceSigner.envelope,
which covers a raw _signed_command. client-island's mode_override 7 test changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… / PW-9)

An undecodable reply returned success. Document 07 section 8 says it is a
PowerwallProtocolError, which is not failover-safe, so nothing replays. Covers
trigger_islanding too, which shares the path; both client-island tests that
pinned Python's tolerance change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-61 / PW-7)

A second curtail saved the curtailed values, so restore left backup at the
curtailed reserve. Save only when not already curtailed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…PW-7)

Infinity passed the limit checks and JSON.stringify wrote it as null. Limits
now require a finite number, and write_config rejects one at any depth, since
it takes arbitrary values. Reserve, curtail, backup, delay and dispatch inputs
already refused it: the new cases pin that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-13)

connect_gateway logged in at any IPv4 the cloud reported, with certificate
checks off, even after a rejected login. Now only private and link-local
addresses get a request, and a client with a known DIN refuses any other
gateway, failing over rather than talking to it. Existing healing tests use
allow_address, because the fake gateway can only be on loopback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ENG-81 / PW-14)

routable_message is replayable for 30 s, so it joins the log redaction keys.
write_config runs one at a time per client, so two writes cannot interleave a
read-modify-write. AGENTS.md records the rules that differ from Python on
purpose, and that set_island_mode(6) forces on LAN and omits force on cloud.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Bre77
Bre77 merged commit 1e92de1 into main Nov 2, 2026
4 checks passed
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