Repository navigation
feat(api): clear and resync the MQTT brokers on request - #67
Merged
Merged
Conversation
POST /api/source/v1/resync publishes every module's state and every model's metadata to the brokers again. With `clear=true`, everything source publishes (all `state` and `metadata` topics) is removed from the brokers first, for when what they hold has drifted. It runs in the background, one at a time (409 while running), and GET reports progress. Clearing holds event processing back so nothing is published again while it runs, and works in rounds: take up to 5,000 retained topics, remove them, wait for the removals to reach the broker, repeat until a round finds nothing. A broker that drops part of what it sends a subscriber (past `max_queued_messages`) therefore cannot leave anything behind. Metadata is republished page by page, with scope read from the mappings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 14, 2026
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.
Why
When a broker's retained state has drifted, there was no way to put it right short of restarting source, and even a restart can't remove what nothing maps to on a large broker. The startup sweep sees only part of a large broker because mosquitto drops what a subscriber's queue can't hold (
max_queued_messages). At 3,000 systems and 15,000 modules with 2,500 deleted while source was down (about 27,500 stale topics), the sweep removed 385 with the default queue and 2,090 at 10,000.What
POST /api/source/v1/resync?clear=publishes every module's state and every model's metadata to the brokers again. Withclear=true, everything source publishes (allplaceos/+/state/#andplaceos/+/metadata/#) is removed first. It runs in the background, one at a time: 202 once started, 409 while one is running.GET /api/source/v1/resyncreports where the last one got to:state(idle, clearing, resyncing, complete or failed),started_at,finished_at,cleared,metadataanderror.Source's API is internal and unauthenticated. PlaceOS/rest-api exposes these to system admins as
POST/GET /api/engine/v2/source/resync(that PR is linked below).How clearing works:
Metadata (zones, systems, drivers) is republished page by page, by key. Scope for systems and drivers comes from the mappings, so there are no per-row queries.
Results
At 3,000 systems, 15,000 modules and about 166,000 retained topics, including about 25,000 stale ones the sweep had missed:
Testing
./test: 71 examples, 0 failures. Newspec/clear_spec.crclears 50 topics in rounds of 20 against the test broker and leaves a topic outsideplaceos/alone. A manager spec checks one resync runs at a time.localsuite): 15/15 on an image of this branch, and again after a clear and resync of the stack.🤖 Generated with Claude Code