8000 fix(sensors): keep a retained MQTT message before acknowledging it by adeelahmad · Pull Request #299 · adeelahmad/lense · GitHub
[go: up one dir, main page]

Skip to content

fix(sensors): keep a retained MQTT message before acknowledging it - #299

Merged
adeelahmad merged 1 commit into
mainfrom
claude/project-thread-08vtp3
Oct 10, 2026
Merged

adeelahmad merged 1 commit into
mainfrom
claude/project-thread-08vtp3

Conversation

@adeelahmad
Copy link
Copy Markdown
Owner

Requested by Adeel · project thread

Description

Before: Lens's MQTT hub acknowledged a QoS 1/2 publish (PUBACK/PUBREC) before it stored the retained copy and passed the message on. A device that subscribed right after the publisher got its acknowledgement could miss the retained message and get it as a live one (retain flag off) instead.

After: the hub keeps and forwards the message first, then acknowledges it, then tells Lens about it. A subscriber that comes after the acknowledgement always gets the retained copy.

Motivation and Context

tests/api/test_sensors.py::test_broker_is_an_ordinary_local_broker failed now and then in CI because of this race (seen on #253's "FastAPI (SurrealDB server)" job: assert ('home/kitchen/temp', b'21.5', False) == (..., True)). Fixing the race fixes the red check rather than re-running it.

Steps to reproduce (if appropriate):

The new test test_a_retained_message_is_kept_before_its_sender_hears_it_arrived slows the hub's publish by 0.3 s: it fails on main and passes with this change.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change; ! in the title)

Checklist:

  • The title is a Conventional Commit.
  • My code follows the code style of this project (ruff check, ruff format, mypy clean).
  • I added or updated tests.
  • My change requires documentation updates: n/a, no behaviour a user configures changes.
  • CHANGELOG: n/a, the title says it.

Done questions (AGENTS.md)

  • Goal: removes a flaky CI failure at its cause; merged on green CI.
  • Agents: n/a, internal broker fix.
  • Zero setup: no new prerequisite.
  • Fewest clicks: n/a, no UI.
  • Configurable: n/a, no new setting.
  • Light: no new dependency.
  • Private and secure: no new surface; message order only.
  • Cost: n/a, no model calls.
  • User decides: defaults unchanged.
  • Upgrades: n/a, no stored-data change.
  • Honest: n/a.
  • Tests added (sensor tests 24/24 locally).
  • Open standards: follows MQTT 3.1.1 (the server owns the message before acknowledging it).
  • Reported in the project thread.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GbW6SC3MU2AmYQ9zFa5dk4


Generated by Claude Code

The hub sent PUBACK/PUBREC before it stored and forwarded the message, so a
client that subscribed right after the publisher's acknowledgement could miss
the retained copy and get it as a live message instead. This made
test_broker_is_an_ordinary_local_broker fail now and then in CI (seen on #253).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GbW6SC3MU2AmYQ9zFa5dk4
@adeelahmad adeelahmad self-assigned this Oct 10, 2026
@adeelahmad
adeelahmad merged commit a6c3893 into main Oct 10, 2026
5 checks passed
@adeelahmad
adeelahmad deleted the claude/project-thread-08vtp3 branch October 10, 2026 20:54
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.

2 participants

0