# Phase 36: Fan-Out + PyO3 Bridge - Context

**Gathered:** 2026-03-29
**Status:** Ready for planning
**Mode:** Auto-generated (infrastructure phase — discuss skipped)

<domain>
## Phase Boundary

LiveBarEngine dispatches every completed bar to both ChannelSink (for Python) and ClickHouseWriterSink (for CH), with writer metrics and config flowing through the PyO3 bridge.

Requirements: INTEG-01, INTEG-02, INTEG-04, INTEG-05, INTEG-07

</domain>

<decisions>
## Implementation Decisions

### Claude's Discretion

All implementation choices are at Claude's discretion — infrastructure phase.

Key constraints:

- Fan-out must NOT block either sink — if CH sink is slow, Python sink must still receive bars
- ChannelSink (Python) MUST stay active — Python needs bars for checkpoints, SSE, Argus, Lethe, min-TID guard
- Pre-write guards run BEFORE BarSink.on_bar() to prevent invalid bars from being serialized
- Config from env vars only (OPENDEVIATIONBAR_CH_HOSTS, OPENDEVIATIONBAR_MODE, etc.) — no PyO3 config bridge
- Ouroboros mode hardcoded to "aion" in ClickHouseBarRow (already done in row.rs)
- Metrics exposed via StreamManager.get_metrics() dict — Python heartbeat already reads this

</decisions>

<code_context>

## Existing Code Insights

### Reusable Assets

- `LiveBarEngine` in `live_engine/mod.rs` — currently dispatches to single ChannelSink
- `StreamManager` in `stream_manager.rs` — PyO3 class exposing next_bar(), drain_bars_arrow(), get_metrics()
- `BarSink` trait with on_bar(), flush(), name()
- `ClickHouseWriterSink` from Phase 34 — ready to be plugged in
- `ClickHouseWriterConfig::from_env()` — reads CH config from env vars

### Integration Points

- `LiveBarEngine::new()` or engine builder — add second sink
- `symbol_task()` in live_engine — where bars are dispatched to sinks
- `StreamManager` PyO3 bindings — expose CH writer metrics
- `src/streaming_bindings.rs` — PyO3 module registration

</code_context>

<specifics>
## Specific Ideas

No specific requirements — infrastructure phase.

</specifics>

<deferred>
## Deferred Ideas

None.

</deferred>
