Skip to content

fix(drivers): a slow success is a success - #1889

Merged
frahlg merged 2 commits into
masterfrom
b1-slow-success-is-success
Oct 27, 2026
Merged

frahlg merged 2 commits into
masterfrom
b1-slow-success-is-success

Conversation

@frahlg

@frahlg frahlg commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Item B1 of the stable plan.

Problem

At the default 2 s control interval, every dispatch send waits 1 s (driverCommandTimeout, driver_command_deadline.go:43-52). beginCommand tied the command's context to that wait, and after driver_command returned success, commandContextError (registry.go:1092) turned it into DeadlineExceeded once the wait had ended. restoreAfterCommand then ran driver_default_mode.

So a driver that needs more than 1 s to answer is put back in its default after every command the device accepted. The default succeeds and clears the block, so the next tick sends again and the cycle repeats: forced, autonomous, forced. Sungrow through a WiNet dongle (four Modbus round trips per command) and Easee Cloud (whose default pauses the car at 0 A) are both exposed. The repro: a device that accepts at 40 ms with a 20 ms caller wait gave 3 commands and 3 defaults in 3 ticks.

Change

In internal/drivers/registry.go only:

  • commandRunContext: once a command has started, a caller deadline shorter than 5 s (defaultRecoveryTimeout) no longer cuts it short. The command runs for at least 5 s. Longer caller deadlines (vehicle wake, 15-30 s) and callers with no deadline are unchanged.
  • Wallbox-cycle steps (SendEVContinuation, cycleID != 0) keep the caller's deadline. The cycle owner gives up at that deadline and sends no resume, so a pause that lands late fails and restores the default, as on master, instead of latching evPausePending and blocking every later cycle pause.
  • commandContextError ignores the caller's deadline. A success that arrives late is a success. An explicit caller cancel, the driver lifecycle and SendDefault still stop the command, and a failure or run timeout still restores the default.

The caller still gets ErrCommandMayHaveRun at its own deadline. SendWithOutcome now reports the real result (nil) to the actor-owned outcome callback, and telemetry records "accepted", not "unconfirmed". The loadpoint saves its offer before the send, so a raise that lands late is already counted for the fuse.

A command queued behind a slow one still expires in the queue at its caller's deadline, as before, so the lag does not grow.

Tests

  • New go/internal/drivers/registry_slow_command_test.go (repro from the audit, renamed). Both tests fail on master and pass here. TestLateWallboxCyclePauseRestoresDefaultAndDoesNotLatch covers the cycle-step case: it fails without the cycle-step exception and passes here.
  • TestSendReturnsAtDeadlineWhileDriverIsWedged and TestRegistryCancelAfterCommandStartedRestoresDefault stay green.
  • go test -race -count=1 ./internal/drivers/... ./internal/loadpoint/... ./internal/api/... ./cmd/ftw/...: ok.
  • go test -count=1 ./...: ok.
  • go build ./... and go vet ./...: ok.

Risk

Medium. The actor can now spend up to 5 s on a stuck, context-aware command before the default, where before it gave up at 1 s and then spent up to 5 s on the default. SendDefault and the staleness watchdog still cancel a running command at once. Rig scenario R10 (charger that answers in 2.5 s) covers this; OCPP uses its own path and is a separate item (W2-11).

The comment at loadpoint/controller.go:1696-1698 says a timeout restores the default; it is now true only when the command fails. Three open PRs touch that file, so I left it.

🤖 Generated with Claude Code

A command that the device accepted after the caller's deadline was turned
into DeadlineExceeded, and the actor then sent driver_default_mode. A
driver slower than half the control interval flipped between forced and
autonomous mode on every tick.

The caller's deadline now bounds only its wait. A started command runs for
at least 5 s; an explicit cancel, the lifecycle and SendDefault still stop
it, and a failure or timeout still restores the default.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-27T13:22:34.404191Z 14db16f 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.

A wallbox-cycle ev_pause that succeeded after the caller's deadline set
evPausePending, but the cycle owner had already given up and never sent
the resume. Every later cycle pause was then refused as superseded until
a default or an operator command cleared the latch.

Cycle steps (cycleID != 0) now run under the caller's deadline, as
before the slow-success change. A late cycle step fails, restores the
default and leaves no pending pause. Other commands keep the 5 s run
bound.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@frahlg
frahlg merged commit 61a0804 into master Oct 27, 2026
22 checks passed
@frahlg
frahlg deleted the b1-slow-success-is-success branch November 11, 2026 09:12
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