Skip to content

Phase 5c-2b: receiver-side JOB_* fan-out to peer-link frames - #533

Merged
J. Nick Koston (bdraco) merged 6 commits into
mainfrom
phase-5c-2b-job-fanout
May 10, 2026
Merged

J. Nick Koston (bdraco) merged 6 commits into
mainfrom
phase-5c-2b-job-fanout

Conversation

@bdraco

Copy link
Copy Markdown
Member

What does this implement/fix?

Phase 5c-2b of #106 — receiver-side fan-out from firmware JOB_* events to peer-link frames. Pairs with the just-merged 5c-2a accept path (#528): once a remote-peer FirmwareJob is queued (carrying remote_peer + remote_job_id), the firmware controller's existing lifecycle and output events drive job_state_changed / job_output frames back to the submitting offloader.

What this PR adds:

  • controllers/remote_build_job_fanout.py — JobFanout class subscribes to firmware JOB_* events, filters to remote-peer jobs, and forwards typed wire frames over the matching peer-link session. JOB_STARTED / JOB_COMPLETED / JOB_FAILED / JOB_CANCELLED map 1:1 to job_state_changed{status: running|completed|failed|cancelled}. JOB_OUTPUT maps to job_output{stream: "stdout", line}. Wired into RemoteBuildController.start() (gated on _db.firmware) and detached in stop().

  • FirmwareJob.remote_job_id — new optional string field carrying the offloader's submit-tagged job_id from the submit_job header. The receiver-side FirmwareJob.job_id is generated independently (uuid4 hex), so the two id-spaces don't collide; this field threads the offloader's tag through so the fan-out can echo it back on every frame. The offloader matches against its own submit-tagged id, not the receiver's local one. _create_job accepts remote_job_id alongside remote_peer, and SubmitJobReceiver._extract_and_queue passes pending.job_id.

  • JOB_QUEUED deliberately doesn't fan out — the submit_job_ack response from 5c-2a already tells the offloader the job is queued, so a redundant job_state_changed{queued} frame would race the ack and add wire noise without adding signal. The Literal["queued", ...] slot stays in the wire schema for future use; today only the four post-queue transitions fan out.

  • Best-effort fan-out — a session that's unregistered between the JOB_* fire and the lookup, or a send_app_frame that itself raises, is logged at debug and skipped. The job runs to completion either way; the offloader's missing-output is on the next session bring-up's problem to surface (or 5d's cancel path to mop up).

16 unit tests in tests/test_remote_build_job_fanout.py covering: each lifecycle transition's status mapping, error_message carry-through on failed, the local-job-no-fan-out filter, the session-gone graceful skip, the JOB_QUEUED not-fanned-out contract, the JOB_OUTPUT happy path + skip-paths (local job / unknown job_id / firmware unavailable / session gone), stop() listener detachment, and the swallow-on-send-failure path. 100% coverage on the new module.

Related issue or feature (if applicable):

Types of changes

  • Bugfix (non-breaking change which fixes an issue) — bugfix
  • New feature (non-breaking change which adds functionality) — new-feature
  • Enhancement to an existing feature — enhancement
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) — breaking-change
  • Refactor (no behaviour change) — refactor
  • Documentation only — docs
  • Maintenance / chore — maintenance
  • CI / workflow change — ci
  • Dependencies bump — dependencies

Frontend coordination

  • No frontend change needed
  • Companion frontend PR: esphome/device-builder-dashboard-frontend#

(FirmwareJob.remote_job_id defaults to "", so existing frontend renderers ignoring unknown fields keep working unchanged. The job_state_changed / job_output frames go to the offloader-side PeerLinkClient (which 5c-3 will surface as local bus events the frontend re-broadcasts via subscribe_events); receiver-side frontend isn't affected.)

Checklist

  • The code change is tested and works locally.
  • Pre-commit hooks pass (ruff, codespell, yaml/json/python checks).
  • Tests have been added or updated under tests/ where applicable.
  • components.json has not been hand-edited (regenerate via script/sync_components.py if a sync is needed).
  • Architecture-level changes are reflected in docs/ARCHITECTURE.md and/or docs/API.md.

(Architecture mention deferred — the receive-side flow is half-described already in docs/ARCHITECTURE.md's "Long-lived peer-link sessions" section; the proper end-to-end write-up belongs in 5c-3 alongside the offloader-side submit caller, when the round-trip is fully observable.)

Copilot AI review requested due to automatic review settings May 10, 2026 14:42
@github-actions github-actions Bot added the new-feature New feature label May 10, 2026
@codecov-commenter

Codecov Comments Bot (codecov-commenter) commented May 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.17%. Comparing base (74163de) to head (8ec3660).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #533   +/-   ##
=======================================
  Coverage   99.16%   99.17%           
=======================================
  Files          70       71    +1     
  Lines        9020     9095   +75     
=======================================
+ Hits         8945     9020   +75     
  Misses         75       75           
Flag Coverage Δ
py3.12 99.14% <100.00%> (+<0.01%) ⬆️
py3.14 99.17% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
..._device_builder/controllers/firmware/controller.py 100.00% <ø> (ø)
esphome_device_builder/controllers/remote_build.py 99.56% <100.00%> (+<0.01%) ⬆️
...ice_builder/controllers/remote_build_job_fanout.py 100.00% <100.00%> (ø)
...ice_builder/controllers/remote_build_submit_job.py 100.00% <ø> (ø)
esphome_device_builder/models/firmware.py 100.00% <100.00%> (ø)
esphome_device_builder/models/remote_build.py 98.69% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed

codspeed Bot commented May 10, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 12 untouched benchmarks


Comparing phase-5c-2b-job-fanout (8ec3660) with main (74163de)

Open in CodSpeed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements receiver-side fan-out of firmware JOB_* events into peer-link application frames for remote-submitted firmware jobs (issue #106 phase 5c-2b), so offloaders can receive lifecycle transitions and streaming build output over the existing peer-link session.

Changes:

  • Added JobFanout helper that listens to firmware job lifecycle/output bus events and forwards them as job_state_changed / job_output peer-link frames for jobs tagged with remote_peer + remote_job_id.
  • Threaded a new FirmwareJob.remote_job_id field from the submit_job header through job creation so the receiver can echo the offloader’s job id back on all frames.
  • Added a focused unit test suite for the fan-out behavior and updated existing peer-link tests/stubs for the new job-creation signature.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
esphome_device_builder/controllers/remote_build_job_fanout.py New receiver-side fan-out module that converts JOB_* bus events into peer-link job_state_changed / job_output frames.
esphome_device_builder/controllers/remote_build.py Wires JobFanout into controller start()/stop() lifecycle.
esphome_device_builder/controllers/remote_build_submit_job.py Passes remote_job_id when creating firmware jobs from peer-link submissions.
esphome_device_builder/controllers/firmware/controller.py Extends _create_job() to accept/store remote_job_id.
esphome_device_builder/models/firmware.py Adds FirmwareJob.remote_job_id field for tracking the offloader’s job id.
tests/test_remote_build_job_fanout.py New tests covering lifecycle/output fan-out, skip paths, detachment, and send failure swallow behavior.
tests/test_remote_build_peer_link.py Updates test stub firmware _create_job signature to include remote_job_id.

Comment thread tests/test_remote_build_job_fanout.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread tests/test_remote_build_job_fanout.py Resolved
@bdraco
J. Nick Koston (bdraco) merged commit f267d6b into main May 10, 2026
13 checks passed
@bdraco
J. Nick Koston (bdraco) deleted the phase-5c-2b-job-fanout branch May 10, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants