wf-agent3/north_bridge_plan.md

9.7 KiB

North Bridge Refactor Execution Plan

Summary

  • Move the active runtime path from director to north_bridge.
  • Keep adapters focused on canonical dataclasses and CommandResult.
  • Make north_bridge the single northbound ingress for protobuf events and command responses.
  • Keep command initiation out of acquisition and worker loops; explicit command completion is published to north_bridge as a canonical event.

Execution Order

1. Align Architecture Docs

2. Add Shared Ports and Protobuf Envelopes

3. Create app.north_bridge

  • Create src/app/north_bridge/ with:
    • protocol
    • runtime
    • events
    • session
    • subscriptions
    • command
    • websocket
    • config
    • observability
  • Start with in-process runtime, registries, and models.
  • No real WebSocket transport in this phase.
  • Commit target: chore: create north bridge package skeleton

4. Implement North Bridge Ingress

  • Implement NorthBridgeIngressPort as the single protobuf ingress for adapter output.
  • Add in-memory fanout for sessions, subscriptions, and future consumers.
  • Keep cache as a north_bridge consumer instead of broker-side storage.
  • Commit target: feat: implement north bridge ingress service for protobuf events

5. Redirect Adapter Export Flow

6. Implement North Bridge Command Handling

  • Add an explicit CLI subcommand wf-agent3 command ... as the control-plane entrypoint for all explicit commands.
  • Implement north_bridge command path:
    • receive CommandRequestEnvelope
    • validate
    • dispatch by adapter_id
    • return CommandResponseEnvelope
  • Keep concrete executors in:
  • Keep src/app/adapters/skeleton/commands/__init__.py as the shared router layer.
  • Command initiation belongs only to control plane sources: CLI, north_bridge, scheduler, derivator, and tests.
  • Command executors return CommandResult and immediately export the resulting canonical event to north_bridge without a separate follow-up request.
  • scan is an explicit command, not an automatic acquisition operation.
  • DBusConnectionDriver.receive() and the worker loop do not initiate commands.
  • Commit target: feat: implement north bridge command handling

7. Remove Director from Active Runtime Path

  • Remove director from composition root and active runtime wiring.
  • Update src/app/application/cli.py, README, examples, and tests.
  • src/app/application/cli.py must expose wf-agent3 command ... as the explicit command entrypoint.
  • Keep director only as non-target legacy code if needed during migration, not as active runtime infrastructure.
  • Commit target: refactor: remove director from active runtime path

Public API Changes

Test Plan

  • Adapter event path:
    • canonical messages from file/dbus/wpa runtimes reach north_bridge ingress
    • north_bridge fanout receives them
    • cache consumer receives them through north_bridge
  • North bridge event path:
    • protobuf event envelope passes ingress validation
    • subscription registry matches sessions correctly
    • fanout delivers to registered consumers
  • Command path:
    • wf-agent3 command ... sends CommandRequestEnvelope through north_bridge
    • north_bridge resolves target adapter by adapter_id
    • adapter runtime returns CommandResult
    • executor exports the canonical command result event to north_bridge immediately after completion
    • north_bridge emits CommandResponseEnvelope
  • D-Bus command path:
    • Capabilities, State, Country, CurrentBSS return expected CommandResult
    • executor publishes the canonical command result event to north_bridge without a separate follow-up request
  • WPA ctrl_iface command path:
    • CommandResult returns through runtime without bypassing router
  • Control-plane commands:
    • scan is not generated by acquisition
    • scan appears only after an explicit command request
    • acquisition loop remains passive
  • Regression:
    • UniversalAdapterRuntime.start, run_once, execute_command still work
    • no active runtime reference to app.director remains
  • Smoke:
    • app.north_bridge imports cleanly
    • updated shared contracts and protobuf helpers import cleanly
  • Failure cases:
    • malformed protobuf envelope
    • unsupported command
    • routing failure
    • subscription mismatch
    • ingress backpressure or runtime error handling

Assumptions and Defaults

  • North bridge is in-process for the first migration step.
  • Protobuf remains the mandatory inter-module boundary.
  • adapter_id is the required command routing key.
  • MessageExportPort stays as the adapter-facing ABI for minimal churn.
  • Command executors publish canonical command result events to north_bridge immediately after execution.
  • north_bridge does not require a second request to learn about a completed command.
  • wf-agent3 command ... is the explicit control-plane entrypoint for commands.
  • scan is a command, not an automatic acquisition operation.
  • Cache and future coordinator are north_bridge consumers.
  • stdout_proto and stdout_json are not part of the target runtime path.

Success Criteria

  • Adapter layer no longer depends on a director-centric sink.
  • North bridge becomes the single northbound delivery boundary.
  • Executors remain concrete adapter implementations only.
  • Tests and docs reflect the north_bridge-centric architecture.