Skip to content

fix(zaptec_cloud): start one-phase cars, hand the charger back, give the cloud time (0.3.0) - #279

Merged
frahlg merged 2 commits into
mainfrom
fix/zaptec-field-robustness
Nov 25, 2026
Merged

frahlg merged 2 commits into
mainfrom
fix/zaptec-field-robustness

Conversation

@frahlg

@frahlg frahlg commented Nov 25, 2026

Copy link
Copy Markdown
Member

Problem

The first field test of Zaptec control (Zaptec Go, 3-phase site, 20 A main fuse, Pixii battery, two one-phase cars) never got the car charging under FTW. The help report from v0.167.0-beta.1 showed three faults:

  1. One-phase orders became 0 A. With the charger idle, amps_for divides by three phases. Core asked for 6–17 A on one phase (1 380–3 910 W), which came out as 2–5.7 A and was written as maxChargeCurrent = 0. The resume path wrote 6 A, the car drew 1.3 kW, and the next order wrote 0 A again. Core then reported offered_current_lower, blaming the charger for FTW's own 0 A.
  2. 0 A stayed on the charger. driver_default_mode writes 0 A and sends 506 at every Core stop and when the owner removes the driver. maxChargeCurrent is stored on the charger. The owner found "Max Current lower than Min Current" in the Zaptec portal; the Zaptec app and the owner's other load balancer could not start the charger until the owner fixed it by hand.
  3. Zaptec Cloud is slower than the host allows. Commands hit "context deadline exceeded", and 507 sometimes returned HTTP 500.

Change (zaptec_cloud 0.3.0)

  • One-phase start. When Core asks for one phase, the charger draws on no phase, its state is fresh and the order is at least the minimum on one phase, the driver offers the charger's minimum, the same exposure a resume already has. Once the car draws on one phase, the next order gets its full one-phase current. A car seen on three phases never gets this start; a failed poll never gets it.
  • Charger minimum. Read observation 511 (ChargerMinCurrent) and never write a positive current below it. Start and resume use it.
  • driver_release(). Puts back the maximum found before FTW's first write in this run, or 32 A (no charger cap; the installation's own limits still apply) when that is unknown or below the minimum. It resumes a charger FTW paused, or one left at 0 A with a final stop by an earlier run. It leaves a charger FTW never touched alone. Core calls it only when the owner removes or disables the driver (paired PR in srcfl/ftw); restarts still stand down at 0 A.
  • Slow cloud. Ask the host for 20 s per call with host.set_command_timeout_s (guarded; older hosts keep 5 s). Retry a request once, after 1 s, on a 5xx or a lost connection. Both writes are safe to repeat; a repeated command that changes nothing gets 528.
  • Docs: driver_release and set_command_timeout_s in docs/WRITING-A-DRIVER.md, spec/driver-contract.md, spec/host-api.md and the host API profile. Zaptec's public constants added to upstream_docs.

Tests

make test-driver ID=zaptec_cloud and make check (5 433 passed, 928 skipped) on this machine. New harness cases cover the field case (6, 12 and 17 A one-phase orders while idle → 6 A; the ramp; full 17 A once drawing on one phase; no start for a car seen on three phases or before a fresh poll), a 10 A charger minimum, retry on 503 and on a lost connection, no retry on 400, the 20 s request, and every release path (after a pause, after a stand-down, owner value captured before FTW's first write, left at 0 A by an earlier run, untouched charger, 528, refused write).

The control path stays experimental until a field report confirms it.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T06:04:56.492755Z 710d797 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…the cloud time (0.3.0)

First field test (Zaptec Go, 20 A fuse, two one-phase cars) could not charge.

- A one-phase order on an idle three-phase charger was divided over three
  phases, so up to 18 A came out under 6 A and was written as 0 A. The
  driver now offers the charger's minimum when Core asks for one phase and
  the charger draws on none, as a resume does.
- Every stop left 0 A stored on the charger ("Max Current lower than Min
  Current"). driver_release puts back the owner's maximum, or 32 A, and
  resumes a charger FTW paused, when the owner removes the driver.
- Zaptec Cloud is slow: ask for 20 s per call and retry once after a
  server error or a lost connection.
- Read the charger's minimum (511) and never write a positive current
  below it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
@frahlg
frahlg force-pushed the fix/zaptec-field-robustness branch from 710d797 to 6a9533e Compare November 25, 2026 06:03

@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: 710d797716

ℹ️ 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 +457 to +459
if phases == 3 and mode == "1p" and live == 0 and state_fresh
and w / voltage >= floor and (cap == nil or cap >= floor) then
return floor

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 Exclude known three-phase cars from the one-phase start exception

When a car previously measured on three phases stops drawing, the next successful idle poll makes this exception eligible again: no phase history is retained. Reproducing a three-phase charging poll, a zero-current order, an idle poll and then a 1,380 W 1p order offers 6 A on all three phases, allowing 4,140 W instead of the requested 1,380 W. This contradicts the stated exclusion of cars seen on three phases and AGENTS.md's requirement for limits that never exceed what Core asked for. Retain the observed multi-phase capability for the connected session and exclude those cars from this start path.

AGENTS.md reference: AGENTS.md:L39-L42

Useful? React with 👍 / 👎.

Comment thread drivers/lua/zaptec_cloud.lua Outdated
Comment on lines +517 to +518
local sent, applied = send_command(CMD_PAUSE)
if applied then paused = true end
if applied then paused = true; ftw_paused = true 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 Preserve pause ownership when a retry returns 528

If Zaptec applies command 506 but its response is lost, the new retry can receive 528 because the charger is already paused. send_command then returns true, false, so this assignment never records that FTW paused the charger. If the owner removes the driver before another state poll, driver_release() restores the current but skips 507 and returns success, leaving the charger paused. The same assignment pattern exists in driver_default_mode(). Preserve the uncertain pause ownership across retries or confirm the resulting state before deciding that release needs no resume.

Useful? React with 👍 / 👎.

…dd replies

Review findings on 0.3.0:
- A pause whose first reply was lost and whose retry got 528 did not
  count as FTW's, so a removal left the charger paused. Any pause that
  held now counts.
- A poll that still showed charging just after FTW's pause cleared it.
  Only a resume clears FTW's pause now.
- A state document without 511 reset the minimum to 6 A, letting a write
  fall below a higher minimum. The last known value stays.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
@frahlg
frahlg merged commit 28c771f into main Nov 25, 2026
5 checks passed
@frahlg
frahlg deleted the fix/zaptec-field-robustness branch November 25, 2026 06:07
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