Repository navigation
chore(release): span-panel-api 3.9.0 and schema-1 1.5.0 - #240
Merged
Merged
Conversation
SpanPanelSnapshot.publishes_shared_meters is true where any circuit declares meter/shared-with-device-ids, which the panel models that describe their multi-load breakers declare on every circuit, a standard breaker included, valued only where a meter is shared. MAIN 32 declares neither list. The declaration decides, as for publishes_solar_roles, so a list that has not arrived yet still marks the panel. Consumers that cannot tell a tandem from a single-pole circuit on MAIN 32 need this to know whether the panel describes its breakers at all.
span-panel-api 3.9.0b1 adds SpanCircuitSnapshot.breaker_rating_declared and SpanPanelSnapshot.publishes_shared_meters, which span-panel-api-schema-1 1.5.0b1 fills, so schema-1 floors on span-panel-api>=3.9.0b1. The changelogs carry the public versions, 3.9.0 and 1.5.0. schema-0 stays at 1.3.0, and the core schema-1 extra stays at 1.4.0, which 1.5.0b1 still satisfies. Replaces the 3.8.0b2 / 1.4.0b3 bump this branch carried before 3.8.0 and 1.4.0 were released without the field.
Every connection is a clean session, and the broker answers each SUBSCRIBE by replaying every retained message on the filter. The connection callback subscribed on the CONNACK and connect() subscribed again once the bridge returned, so the first connection asked for the panel's tree twice and received it twice. The bridge now owns subscription. SpanMqttClient hands it the topics of every parser it builds, and the bridge subscribes them once on each accepted CONNACK -- the initial connect, each reconnect, each rebuilt client -- before the connection is announced; neither connect() nor the connection callback subscribes any more. On a live session a new set is subscribed at once, which is how a parser swapped in for another schema generation receives the tree, and a filter that left the set is unsubscribed, where the old generation's filter stayed until the next reconnect and the broker delivered every message under the panel's own device once per overlapping filter. AsyncMqttBridge.subscribe(topic, qos) is replaced by set_subscriptions(topics).
connect() now creates its bridge before the parser, so a close() that landed while it was suspended dropped the client's only reference to that bridge, and connect() went on to connect it: before the parser was built the session carried no subscription, connect() timed out waiting for a tree that never came, and the bridge stayed connected with its reconnect loop armed and nothing left to close it. connect() now checks, before building the parser, before connecting the bridge, when that connect fails or returns, when the wait for the panel times out, and before returning, that the client still holds its bridge, and otherwise disconnects it and raises SpanPanelConnectionError. In 3.8.0 the same close() was undone instead, connect() carrying on to connect the client it had been asked to close. set_subscriptions refuses a bare string, which a Sequence[str] admits and which would subscribe one filter per character, and refuses any filter MQTT 3.1.1 does not accept, in the caller's frame and before anything is recorded, rather than at the next CONNACK, where paho's refusal escapes the read callback and the connect times out. The parser is installed only once the bridge has accepted its topics. A swap landing between a CONNECT and its CONNACK is now pinned as subscribed once, by the CONNACK.
subscribe(topic, qos=0) is kept from 3.8.0 and now held the way set_subscriptions holds its set: subscribed at once on a live session and on every later CONNACK, where in 3.8.0 it was one SUBSCRIBE on the current session, dropped when no paho client existed yet and gone after the next reconnect. The bridge keeps its subscription in two parts with one writer each: the set set_subscriptions replaces whole, the parser's, and the topics subscribe() adds, which nothing removes. A session holds both, each topic once, at the highest QoS either asks, so replacing the parser's set on a swap never drops a consumer's topic, including one both held. A topic already held at the QoS asked sends nothing; a higher one is subscribed again at that QoS, as 3.8.0 honoured qos. subscribe() refuses a malformed filter or a QoS other than 0, 1 or 2 where it is called.
…r does not say SpanPanelSnapshot.publishes_shared_meters, added in 3.9.0b1, defaulted to False, so a snapshot from an adapter that does not answer -- the flat schema's, or a span-panel-api-schema-1 older than the field, which the core 3.9.0 extra still admits -- read as "this panel does not describe its multi-load breakers". It is now bool | None and None by default, as breaker_rating_declared is. span-panel-api-schema-1 1.5.0b1 already sets it to True or False from the declarations and is unchanged; schema-0 now reads None.
…id-connect SpanMqttClient.connect() waited out MQTT_READY_TIMEOUT_S when close() landed during its wait for a ready tree. The wait now runs as a background task, as the label wait does, so close() -- which cancels every one -- ends it at once and connect() reports the close. AsyncMqttBridge.connect() did not notice a disconnect() made while it was suspended: during the unpinned CA fetch it went on to build a client and connect, during the executor connect its finally read the cleared self._client and raised AttributeError, and during the CONNACK wait it waited out its timeout. Each connect() now carries a token disconnect() clears, checked after each of its awaits. It raises SpanPanelConnectionError instead, closes the socket the executor opened, and disconnect() ends the CONNACK wait. The executor's finally uses the client connect() built. A CONNACK from a client the bridge has let go of is ignored, so the abandoned socket's late CONNACK cannot mark the bridge connected or subscribe it. With the bridge refusing to return from a connect that disconnect() interrupted, SpanMqttClient.connect() no longer checks after a successful bridge connect; a failed one that close() caused still reports the close.
…rebuild made AsyncMqttBridge._on_disconnect now ignores a disconnect reported by a client the bridge no longer holds, as _on_connect already ignores its CONNACK, so a replaced client reporting its end cannot mark the bridge disconnected under the new client's live session, tell consumers the panel was lost, and start a reconnect that replaces that session. The guard depends on self._client being the live client, and _rebuild_client broke that: cancelled during its executor connect, it restored the old client. disconnect() cancels it so, after letting every client go, and the restore put one back; a CONNACK from the new client cancels it so too, and the restore left the bridge acting through a client whose session was over, publishing and subscribing into nothing and, with these guards, deaf to the live session's own disconnect. A cancelled rebuild now leaves self._client as it is.
…g call returns paho runs here with its locks removed, so only one thread may be inside a client at a time, and three paths broke that. disconnect() called paho's disconnect() on the loop while an executor thread was inside the same client's connect() or reconnect(). And when disconnect() cancelled the reconnect task, the coroutine's finally switched the socket callbacks back to the loop-only ones at the cancel, while the thread was still inside paho and could call them from the wrong thread. On the rebuild path nothing closed the socket the new client's connect went on to open, so it stayed open. Every blocking call now goes through _run_blocking. The client is marked held and given the thread-safe socket callbacks. disconnect() never calls into a held client, only lets it go. The loop takes the client back in _executor_returned when the call returns, not when its caller resumes: loop callbacks again, and a client let go of meanwhile is disconnected there, closing whatever the call opened. The caller awaits a future that hand-back resolves, so a cancelled caller cancels only its wait, and a failure nobody awaits is retrieved without being reported; asyncio.shield would report it through the loop's exception handler.
The close() line names AttributeError among the outcomes a close during connect() could have. Adds AsyncMqttBridge.connect() raising on a concurrent disconnect() and AsyncMqttBridge.subscribe() holding its topic on every later connection, and says publishes_shared_meters is None where the adapter does not say.
test_close delivered the tree's messages after sleep(0.05), assuming connect() had built its parser by then, and a message delivered before it is dropped. connect() reaches the parser only after resolving the adapter in a thread, so a loaded machine made the test wait out its timeout. It now waits until the client has a parser. With that resolve slowed by 200 ms the old test fails every time and this one passes.
Eight more tests in the file delivered the tree's messages after sleep(0.05), with the same race test_close had: a message that arrives before connect() has built its parser is dropped, and resolving the adapter in a thread can outlast the sleep on a loaded machine. Each now waits until the client has a parser. With that resolve slowed by 200 ms all eight failed before and the whole file passes now.
The wait test_mqtt_connect_flow used moves to conftest as until_the_parser_exists, and the last two fixed sleeps standing in for it go: the one in test_factory_dispatch, and the one in test_mqtt_debounce's shared connect helper, which nine tests go through. A message delivered before connect() has built its parser is dropped, and connect() reaches the parser only after resolving the adapter in a thread. With that resolve slowed by 200 ms, those ten tests failed before and pass now, and the whole suite passes. No other test in tests/ waits on a fixed sleep for the parser: the readiness-gate tests wait on a condition, and the remaining fixed sleeps wait for the reconnect loop.
_run_blocking gave the executor thread thread-safe forms of only two of the four socket callbacks paho makes inside a blocking call. reconnect() replacing a socket still awaiting its CONNACK closes that socket on the thread, so the loop-only close and unregister-write handlers ran there. And the loop itself reached into the held client: the socket-open handler, scheduled from the thread, read the client while the thread was still inside paho's connect(); the misc timer called loop_misc() on a client reconnect() was inside; and the reader for the socket being replaced could fire. Every socket event paho makes inside the call is now recorded on the thread and replayed by the hand-back, in order, through the loop's handlers once the call has returned; close and unregister-write carry the descriptor, read while the socket is still open. While the call runs the loop stops watching the client's socket and the misc timer passes the client over. The client is marked held only once the executor has accepted the call, so a refused submission leaves it to the loop.
The socket-close handler acted for any client, unlike _on_connect and _on_disconnect. disconnect() during a blocking connect and then connect() again on the same bridge left the abandoned client's DISCONNECT to be written later, and its socket closing then set the new attempt's connect event -- "MQTT connection failed" while the broker was accepting -- and cancelled the misc timer the new socket had started. A client the bridge no longer holds now only stops being read when its socket closes.
In 3.8.0 a direct user of AsyncMqttBridge heard connected=False after its own disconnect(), from paho's report once the DISCONNECT was written. disconnect() now lets the client go before that report, which _on_disconnect then ignores, so the user heard nothing. disconnect() now tells the connection callback False itself, once, when the bridge was connected. SpanMqttClient.close() is no longer live by the time its bridge disconnects, so that False is no edge and its consumers are not told the panel was lost, as in 3.8.0, where paho's report arrived after close() had already marked the client not live.
subscribe() checked qos by value, so 1.0 and True passed as QoS 1 and reached paho that way. It now refuses anything but the integer 0, 1 or 2, before recording anything. Its CONNACK gate, which keeps a topic subscribed between a CONNECT and its CONNACK from being sent twice, gets the test set_subscriptions already has.
The wait for a ready tree runs as a task of its own, so close() can end it, and a connect() cancelled during it left that task pending until something closed the client. connect() now cancels it however the wait ends.
The rebuild's comment said the hand-back disconnected the new client when its connect failed. It did not: at hand-back the new client was still the bridge's, and only afterwards was the old one restored, so a connect that had opened its socket before failing left that socket open. The rebuild now disconnects the new client itself once it has restored the old one.
disconnect() sets the CONNACK event as it abandons an attempt, so an attempt abandoned while the executor held the client already returns at once from the CONNACK wait, and the check after that wait reports it with the same error. The check right after the executor added nothing a mutation could take away; that window now rests on the one check, which the blocking-connect tests pin.
Three cross-thread tests waited for a blocking call's hand-back with five sleep(0)s after the thread returned. They now wait until the bridge holds no client in an executor call, and then for the DISCONNECT the hand-back queued for a let-go client to be written.
…nger own A close paho made on the executor thread -- reconnect() replacing a socket still awaiting its CONNACK -- was replayed by the hand-back as remove_reader and remove_writer on the descriptor number recorded at the close. paho had closed that socket on the thread, so the number was free for the rest of the call, and anything else in the process could take it: the hand-back then stopped the loop reading the new owner. A second bridge kept is_connected and never heard from its broker again; an asyncio transport logged a RuntimeError. The loop now acts only on a socket object it knows to be open. _run_blocking stops watching the client's socket before the call is submitted, by the socket itself, and keeps what restores exactly those watchers. A close made inside the call records only the bridge's own bookkeeping, and a write-unregister records nothing, since no socket of the client is watched while the call runs. Socket closes paho makes on the loop unwatch by the socket while it is still open. If the call leaves the socket it was given open and still the client's -- the executor never ran it, or reconnect() refused its host before closing anything -- the hand-back watches it again as it was.
A misc tick that stopped -- no client to tick for, or paho answering that the client had no socket -- returned without clearing _misc_timer, and the next socket opened then saw a handle set and started no timer. A bridge reused more than a second after an abandoned connect, or an old client reconnecting more than a second after a failed rebuild, ran its session without keepalives until the broker dropped it. Each tick now clears the handle before anything else, so it is set exactly while a tick is scheduled. The socket-close handler also keeps a failing removal of the socket's watcher from paho: raised there, it ended paho's close before paho reported the disconnect, and the bridge never heard. The bridge's own bookkeeping already ran first.
…e timer's stop on close A reconnect that replaces a socket still awaiting its CONNACK closes one socket and opens another inside the same blocking call; taken back in reverse, the close would stop the timer the open had left running. An idle connected socket must not stay watched for writing, which only holds if the hand-back gives paho's unregister back to the loop. And the bridge's own close stops the misc timer, so nothing ticks into a client without a socket through an outage; that window is anchored on the first refused reconnect being handed back rather than on a fixed sleep.
It took `object` where the loop takes a descriptor number or anything with a fileno(). The failed-rebuild test's precondition now reads the fake broker's record, that the rebuild built a client and the live session is the old client's, rather than the bridge's private client attribute.
…urns The broker counts every packet it schedules where it schedules it, under a lock since a CONNACK is scheduled from the executor thread, so waiting for nothing pending leaves no CONNACK or SUBSCRIBE replay on its way. A close or disconnect made while a blocking call is held is followed by every task it cancelled running to its end, rather than five turns of the loop. A socket made readable is followed by a poll of the loop's selector, a keepalive expected by the tick it waits for, and the ready wait's end by that task. A late disconnect from a replaced client needs no wait at all: acting on it shows inside drop(). The windows left are timer deadlines, each commented.
… wait for tasks a call started A hand-back that raised after a reconnect had closed its real socket left the reconnect loop waiting on an answer that never came, and the tests on that path passed because none of them looked at the loop's exception handler; they do now, and a new one has two reconnects replace sockets before any CONNACK, so a loop left waiting never tries again, then drops the session a second time. The helper that waits out what a close or disconnect cancelled also takes the tasks still running after the call, so a task the call both started and cancelled is waited for too.
The hand-back answered its caller only if every step before the answer succeeded. A step that raised -- giving the loop back a socket the call had kept, say -- ended it there, and the reconnect loop waiting on that answer waited for ever; with the kept socket unwatched no CONNACK could reach it either, so the bridge never connected again. Each step is now taken whether or not one before it raised, and the caller is answered in a finally. A call that succeeded hands its caller the hand-back's first failure, so the reconnect loop counts and retries the attempt as it does any other failure, and connect() reports it as its connection error; a failure the caller is not given is logged with its traceback. A let-go client's failed disconnect is logged as a warning, where it was a debug line, and never given to its abandoned caller.
…t_subscriptions()
span-panel-api 3.9.0b2 subscribes each broker session once. schema-0 stays at 1.3.0 and schema-1 at 1.5.0b1, neither changed: schema-1 keeps its span-panel-api>=3.9.0b1 floor, which 3.9.0b2 satisfies, and the core extras keep their stable floors. The changelog carries the public version, 3.9.0.
Finals of 3.9.0b2 and 1.5.0b1, with the same code. The schema-1 extra floors on span-panel-api-schema-1 1.5.0, the adapter that fills breaker_rating_declared and publishes_shared_meters, and schema-1 floors on span-panel-api 3.9.0, a stable floor again in place of the beta's. schema-0 stays at 1.3.0, unchanged, and the schema-0 extra keeps its 1.3.0 floor. The 3.9.0 changelog entry gains its summary line and the schema-1 extra's floor, and the 1.5.0 entry says its floor carries both fields the parser fills.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Final releases of the 3.9 pre-release line: span-panel-api 3.9.0 and span-panel-api-schema-1 1.5.0, the finals of 3.9.0b2 and 1.5.0b1 with the same code. This brings the 32 commits of
prerelease/3.9tomain, which has nothing that branch lacks, plus the version bump.The last public releases are 3.8.0, schema-0 1.3.0 and schema-1 1.4.0.
Version changes:
pyproject.toml: version3.9.0; theschema-1extra requiresspan-panel-api-schema-1>=1.5.0, the adapter that fillsbreaker_rating_declaredandpublishes_shared_meters. Theschema-0extra keepsspan-panel-api-schema-0>=1.3.0.packages/schema-1/pyproject.toml: version1.5.0, requiringspan-panel-api>=3.9.0,<4.0, a stable floor in place of the beta's>=3.9.0b1.uv.lock: version lines only.schema-0 is unchanged: nothing under
packages/schema-0differs fromschema-0-v1.3.0, itsspan-panel-api>=3.8.0,<4.0floor admits 3.9.0, and it leaves both new fieldsNone, which is what they document for that adapter.Changelogs:
[3.9.0]entry gains its summary line and a Changed entry for theschema-1extra's floor.[1.5.0]entry says its floor carries the fields this parser fills, where it named one field.Checks:
pre-commit run --all-files: every hook passes.span-panel-api-schema-0>=1.3.0; extra == 'schema-0',span-panel-api-schema-1>=1.5.0; extra == 'schema-1', andspan-panel-api<4.0,>=3.9.0in schema-1, with no beta floor left;twine checkpasses for every build.Release order after merge:
v3.9.0, thenschema-1-v1.5.0.