Skip to content

Fix stale scale notification recovery - #351

Open
ODevStudio wants to merge 3 commits into
decentespresso:mainfrom
ODevStudio:agent/fix-stale-scale-notification-recovery
Open

ODevStudio wants to merge 3 commits into
decentespresso:mainfrom
ODevStudio:agent/fix-stale-scale-notification-recovery

Conversation

@ODevStudio

@ODevStudio ODevStudio commented Jul 27, 2026

Copy link
Copy Markdown

Failure sequence

DE1app retained an HDS BLE handle whose control writes still succeeded, including heartbeats, tare, and timer commands, but no FFF4 0xCE weight notifications arrived. The first-update watchdog retried notification enable ten times, abandoned recovery, and left the stale handle connected. Power cycling and reconnecting restored weight updates, while the UI could continue to show WEIGHT WAIT.

Root cause

The first-update watchdog was not tied to the handle it watched and only cancelled itself after retry exhaustion. Disconnect cleanup was also not idempotent or handle-aware, so a delayed disconnect callback for the stale handle could clear or close a replacement connection. Weight packets were likewise processed without verifying that they belonged to the active handle. Scale-dependent controls and the weight UI used the BLE connection handle rather than confirmed live weight reporting.

Behavior change

  • Capture and verify the active scale handle in the first-update watchdog.
  • On retry exhaustion, route the same stale handle through the existing scale disconnect cleanup and automatic reconnect path.
  • Ignore duplicate disconnects and callbacks for stale handles while a replacement is connecting or active.
  • Reject stale-handle weight packets before history, timestamps, displayed weight, or stop-at-weight processing.
  • Mark a Decent Scale operational only after a live FFF4 0xCE weight packet from the active handle.
  • Keep connection acknowledgements, LED/status packets, command acknowledgements, and cached 0xCA weights from clearing the wait state.
  • Use operational state for hot-water volume fallback, SAV/SAW readiness, optional scale-required espresso starts, and the Streamline tare/reconnect action.
  • Resend the existing hot-water settings when live reporting is first confirmed.
  • Keep the text-mode harness compatible with the new scale state API.

Tests

  • C:\Program Files\Git\mingw64�in clsh.exe tests\scale_watchdog.test.tcl (9 passed)
  • git diff --check
  • de1app-textmode.tcl startup reached the REPL and exited cleanly; the local environment still reports its pre-existing missing lambda and ble packages.

Coverage includes retry exhaustion, stale watchdog handles, duplicate disconnect callbacks, stale disconnects while a replacement is connecting or connected, cached 0xCA processing without operational state, active-handle 0xCE processing, and stale-handle 0xCE rejection before process_weight_update. The disconnect cases exercise the real scale_disconnect_handler; packet tests record weight-processing calls.

@ODevStudio
ODevStudio marked this pull request as ready for review July 27, 2026 15:09
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