9.7 KiB
9.7 KiB
North Bridge Refactor Execution Plan
Summary
- Move the active runtime path from
directortonorth_bridge. - Keep adapters focused on canonical dataclasses and
CommandResult. - Make
north_bridgethe 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
- Update
.codex/context/architecture.mdto makenorth_bridgethe target northbound boundary. - Update
.codex/context/repo-layout.mdto includesrc/app/north_bridge/. - Update north_bridge_implement_plan.md so it matches the current codebase and migration order.
- Commit target:
docs: align architecture with north bridge centric delivery
2. Add Shared Ports and Protobuf Envelopes
- Extend
src/app/shared/contracts/ports.pywith:NorthBridgeIngressPortNorthBridgeCommandPort
- Extend
src/app/shared/contracts/proto/v1/adapter_wire.protowith:ClientEnvelopeServerEnvelopeEventEnvelopeCommandRequestEnvelopeCommandResponseEnvelopeSubscribeRequestUnsubscribeRequestErrorResponsePingPong
- Add
adapter_idas the command routing key inCommandRequestEnvelope. - Update
src/app/shared/contracts/proto/v1/converters.pyfor event and command envelope conversion. - Regenerate
src/app/shared/contracts/proto/v1/adapter_wire_pb2.py. - Commit target:
feat: add north bridge shared ports and protobuf envelopes
3. Create app.north_bridge
- Create
src/app/north_bridge/with:protocolruntimeeventssessionsubscriptionscommandwebsocketconfigobservability
- 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
NorthBridgeIngressPortas 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
- Update
src/app/application/supervisor.pyandsrc/app/application/broker.pyto wire north_bridge ingress instead of director sink. - Keep
src/app/adapters/skeleton/export/__init__.pyas the dataclass-to-protobuf bridge. - Make adapter runtimes receive a
NorthBridgeIngressPort. - Remove
create_service_directorfrom the active serve path. - Commit target:
feat: wire adapter runtime export flow to north bridge ingress
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
- receive
- Keep concrete executors in:
- Keep
src/app/adapters/skeleton/commands/__init__.pyas the shared router layer. - Command initiation belongs only to control plane sources: CLI, north_bridge, scheduler, derivator, and tests.
- Command executors return
CommandResultand immediately export the resulting canonical event to north_bridge without a separate follow-up request. scanis 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
directorfrom composition root and active runtime wiring. - Update
src/app/application/cli.py, README, examples, and tests. src/app/application/cli.pymust exposewf-agent3 command ...as the explicit command entrypoint.- Keep
directoronly 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
src/app/shared/contracts/ports.py- add
NorthBridgeIngressPort - add
NorthBridgeCommandPort
- add
src/app/shared/contracts/proto/v1/adapter_wire.proto- add north bridge client/server envelopes
- add event, command request/response, subscribe/unsubscribe, error, ping, pong wrappers
src/app/shared/contracts/proto/v1/converters.py- add north_bridge converters
src/app/north_bridge/- new application subsystem
src/app/adapters/skeleton/runtime/__init__.py- API stays the same, but
export_portpoints to north_bridge ingress
- API stays the same, but
src/app/adapters/skeleton/commands/__init__.py- registry/router remain the adapter-level selection mechanism
src/app/adapters/dbus_adapter/commands/__init__.py- executor remains
CommandRequest -> CommandResultand publishes the canonical command result event to north_bridge
- executor remains
src/app/adapters/wpa_supplicant_adapter/commands/__init__.py- executor follows the same contract
src/app/application/cli.py- add
wf-agent3 command ...as the explicit control-plane entrypoint
- add
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 ...sendsCommandRequestEnvelopethrough 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,CurrentBSSreturn expectedCommandResult- executor publishes the canonical command result event to north_bridge without a separate follow-up request
- WPA ctrl_iface command path:
CommandResultreturns through runtime without bypassing router
- Control-plane commands:
scanis not generated by acquisitionscanappears only after an explicit command request- acquisition loop remains passive
- Regression:
UniversalAdapterRuntime.start,run_once,execute_commandstill work- no active runtime reference to
app.directorremains
- Smoke:
app.north_bridgeimports 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_idis the required command routing key.MessageExportPortstays 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.scanis a command, not an automatic acquisition operation.- Cache and future coordinator are north_bridge consumers.
stdout_protoandstdout_jsonare 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.