Skip to content

Fix EventBus context arguments and formalize event schemas - #1210

Merged
rickwierenga merged 8 commits into
PyLabRobot:mainfrom
j0nch:fix/event-context-positional-args
Aug 19, 2026
Merged

Fix EventBus context arguments and formalize event schemas#1210
rickwierenga merged 8 commits into
PyLabRobot:mainfrom
j0nch:fix/event-context-positional-args

Conversation

@j0nch

@j0nch j0nch commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix EventBus context factories that did not follow the positional calling semantics of their decorated public methods, and formalize the EventBus instrumentation and schema contracts so the same class of bug and metadata drift is less likely in future drivers.

evented_operation() invokes a context factory with the original call arguments:

context_factory(*args, **kwargs)

A decorated operation and its context factory therefore need compatible positional and keyword semantics. For operations with validated, normalized, derived, measured, or completion-only context, this PR documents explicit event_operation() construction inside the method as the preferred approach.

Problem

The audit found two failure modes that only appear when an EventBus subscriber is active:

  1. Silent metadata misbinding. TemperatureController.hold_temperature(120) passed 120 into a shared context factory's temperature parameter. Hardware behavior remained correct, but the event reported target_temperature=120 instead of the configured target and omitted the requested duration. Positional wait_for_temperature(timeout, tolerance) calls were similarly vulnerable.
  2. EventBus-only TypeErrors. Valid calls such as positional VSpin.spin(...) and LiquidHandler.move_picked_up_resource(to, ...) could fail in their context factories before the frontend operation ran.

The same positional-capacity issue affected later optional arguments on several LiquidHandler operations.

Implementation changes

  • Add operation-specific temperature-controller context factories for set, wait, hold, and deactivate semantics.
  • Make the VSpin spin context factory positionally compatible with VSpin.spin().
  • Align LiquidHandler context factories for:
    • tip pickup and drop;
    • aspirate and dispense;
    • 96-head tip pickup and drop;
    • resource pickup, move, and drop.
  • Emit the final controller reading as current_temperature on successful temperature_controller.wait_for_temperature.completed events.
  • Preserve existing public frontend signatures and hardware behavior.
  • Add focused positional and keyword invocation tests for affected decorated operations.

An audit of all current evented_operation() call sites found no remaining signature mismatches. Existing BenchCel, Access2, incubator, shaker, machine, and PreciseFlex factories were verified before being left unchanged.

Documentation and contributor contract

This PR also establishes a canonical EventBus documentation structure:

  • The user guide now lists every currently instrumented frontend by fully qualified class path and every semantic operation it emits.
  • A new Event Schema Registry defines canonical operation names, lifecycle-specific fields, units, and resource semantics for all current semantic, state-transition, firmware, and transport events.
  • Canonical cross-device vocabulary is explicit, including duration, timeout, target_temperature, current_temperature, relative_centrifugal_force, resources, source, destination, and volume.
  • Contributor guidance now reserves @evented_operation(...) for straightforward invocation-context projections whose factory matches the method's calling semantics.
  • Contributors are directed to use explicit event_operation() construction when context depends on validation, normalization, resolved resources, derived parameters, measured values, or completion state.
  • Adding a new operation family, changing a payload, or instrumenting a new frontend requires updating both the schema registry and user-facing coverage matrix. Maintainer review establishes the convention for future devices implementing that operation family.

This keeps EventBus consistency semantic rather than inheritance-based, which is important for PLR's independent vendor/device frontends.

Compatibility

  • No hardware-control behavior changes.
  • No public frontend signature changes.
  • Existing event names and established field meanings are preserved.
  • current_temperature is a backward-compatible completed-event addition for wait_for_temperature.

Verification

  • Focused EventBus, temperature-controller, LiquidHandler, VSpin, and Access2 tests: 94 passed, 20 subtests passed
  • Static documentation audit: all 55 currently emitted event names are represented in the schema registry
  • Coverage audit: all 9 currently instrumented frontend classes are listed in the user guide
  • git diff --check: clean

@j0nch
j0nch marked this pull request as draft August 18, 2026 00:57
@j0nch j0nch changed the title Fix EventBus context factories for positional arguments Fix EventBus context arguments and formalize event schemas Aug 18, 2026
@j0nch
j0nch marked this pull request as ready for review August 18, 2026 03:40
@rickwierenga
rickwierenga merged commit 4bdb5f0 into PyLabRobot:main Aug 19, 2026
21 checks passed
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