Repository navigation
Phase 5c-2a: receiver-side submit_job accept path - #528
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #528 +/- ##
==========================================
+ Coverage 99.18% 99.19% +0.01%
==========================================
Files 69 70 +1
Lines 8806 8997 +191
==========================================
+ Hits 8734 8925 +191
Misses 72 72
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Implements issue #106 phase 5c-2a on the receiver side: accepting submit_job / submit_job_chunk frames over peer-link, assembling + extracting the submitted bundle into a stable per-peer/per-device subtree, enqueueing a FirmwareJob tagged with the offloader identity, and replying with a structured submit_job_ack.
Changes:
- Added
SubmitJobReceiverto manage per-session in-flight bundle assembly, extraction viaprepare_bundle_for_compile(), and firmware job queueing +submit_job_ack. - Wired peer-link receive-loop dispatch for
submit_job+submit_job_chunkand integrated receiver lifecycle cleanup on session unregister. - Extended
FirmwareJob/FirmwareController._create_job()withremote_peerto tag remotely-submitted jobs; added unit tests for receiver-side submit/ack behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
esphome_device_builder/controllers/remote_build_submit_job.py |
New receiver-side submit/ack state machine: assemble → write → extract → queue → ack. |
esphome_device_builder/controllers/remote_build_peer_link.py |
Dispatch submit_job and submit_job_chunk frames from the peer-link receive loop. |
esphome_device_builder/controllers/remote_build.py |
Instantiate SubmitJobReceiver on start; discard in-flight state when a session unregisters; expose accessor for receive-loop dispatch. |
esphome_device_builder/controllers/firmware/controller.py |
Thread remote_peer into job creation for remote submissions. |
esphome_device_builder/models/firmware.py |
Add FirmwareJob.remote_peer field to carry the offloader’s dashboard_id. |
tests/test_remote_build_submit_job.py |
New unit tests covering header validation, chunk handling, rejection reasons, happy path, and session discard behavior. |
tests/test_remote_build_peer_link.py |
Update unit tests for new _receive_loop(session, controller) signature. |
J. Nick Koston (bdraco)
marked this pull request as draft
May 10, 2026 05:52
J. Nick Koston (bdraco)
marked this pull request as ready for review
May 10, 2026 14:28
This was referenced May 10, 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.
What does this implement/fix?
Phase 5c-2a of #106 — receiver-side bundle reception + queue + ack, the half of 5c-2 that drives a submitted bundle from the wire into a queued :class:
FirmwareJob. Splits the table row's 5c-2 into:JOB_*events filtered toremote_peer == session.dashboard_idand pushjob_state_changed/job_outputframes over the submitting session.Splitting was a sizing call — even just the receive path is ~560 lines of production + ~17 unit tests; landing it cleanly before the fan-out keeps each PR focused.
What this PR adds:
controllers/remote_build_submit_job.py—SubmitJobReceiverclass plus_PendingSubmitper-session dataclass. Owns the receive-loop dispatch forAppMessageType.SUBMIT_JOB/SUBMIT_JOB_CHUNK, drivesBundleAssemblerfrom 5c-1, writes the assembled tarball + extracts viaesphome.bundle.prepare_bundle_for_compile()(preserves.esphome//.pioenvs/for incremental compiles — load-bearing for the per-peer per-device subtree), and queues aFirmwareJobwithremote_peer=session.dashboard_id.Per-peer per-device subtree at
<config>/.esphome/.remote_builds/<dashboard_id>/<device_name>/. Two-segment key dedupes correctly across multi-offloader fleets (two HA Greens both shipping a "kitchen" device land in distinct subtrees) without colliding within one offloader's pool. PlatformIO's.pio/buildcache then sees stable source paths and skips the cold-rebuild hit.FirmwareJob.remote_peer— new optional string field (default"") carrying the offloader'sdashboard_idwhen the job came in via peer-link. Empty for locally-submitted jobs. Threads throughFirmwareController._create_job(... remote_peer=...). Surfaced as a "from <peer>" badge in the Firmware tasks UI later.Receive-loop wiring in
controllers/remote_build_peer_link._receive_loop— two new branches dispatch the new frame types tocontroller.get_submit_job_receiver().controlleris now threaded into the loop; existing tests passMagicMock()for the controller arg since their inputs don't include the new types.Lifecycle integration —
RemoteBuildController.start()constructs theSubmitJobReceiver(gated onself._db.firmware is not None);unregister_peer_link_session()callsdiscard_session(dashboard_id)so a bundle reception that was mid-stream when the session ended doesn't outlive its session.Reject reason taxonomy. Eight distinct
submit_job_ack.reasoncodes — six from the 5c-1BundleAssemblerErrorCode(mapped through 1:1) plus two receiver-side codes for paths after assembly (extract_failed/queue_rejected) and four for header / chunk dispatch (duplicate_submit/invalid_header/no_inflight_submit/job_id_mismatch/chunk_decode_failed). Wire-level misbehaviour codes (out-of-order chunks, decode failures, post-completion frames) triggerterminate{malformed_frame}after the ack; recoverable errors (oversized / undersized / hash mismatch / extract / queue) ack-and-stay so the offloader can retry on a fresh submit.17 unit tests in
tests/test_remote_build_submit_job.pycovering header validation (duplicate / invalid target / oversized), chunk dispatch (no-inflight, job_id mismatch, decode failure, out-of-order, hash mismatch), the happy path through a stubbedprepare_bundle_for_compile, extraction failure, and the session-discard contract. End-to-end against the realFirmwareController+ a real bundle goes in 5c-2b once the firmware-event fan-out lands.Related issue or feature (if applicable):
Types of changes
bugfixnew-featureenhancementbreaking-changerefactordocsmaintenancecidependenciesFrontend coordination
(
FirmwareJob.remote_peeris a new field but it defaults to"", so existing frontend renderers ignoring unknown fields keep working unchanged. The "from <peer>" badge UI lands in a later phase alongside the offloader Settings UI.)Checklist
ruff,codespell, yaml/json/python checks).tests/where applicable.components.jsonhas not been hand-edited (regenerate viascript/sync_components.pyif a sync is needed).docs/ARCHITECTURE.mdand/ordocs/API.md.(Architecture mention deferred to 5c-2b — the receive-then-fan-out shape is what
docs/ARCHITECTURE.md's "Long-lived peer-link sessions" section will want to describe end-to-end, not the half landed here.)