# Phase 37: Python Integration + Staging Validation - Context

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

<domain>
## Phase Boundary

The sidecar runs in shadow mode on bigblack for 24+ hours, dual-writing via both Rust and Python, with zero diff between the two and zero dead-letter files.

Requirements: INTEG-03, VALID-01, VALID-02, VALID-03, VALID-04, VALID-05

</domain>

<decisions>
## Implementation Decisions

### Claude's Discretion

All implementation choices are at Claude's discretion.

Key constraints:

- Feature flag `OPENDEVIATIONBAR_USE_RUST_CH_WRITER` with 3 modes: off/shadow/live
- Flag evaluated once at `_create_engine()` startup — no mid-session switching
- Shadow mode: both Rust and Python write, Python compares results
- Live mode: Python skips `_write_batch_with_retry()` entirely
- 24h staging on bigblack is a human-action checkpoint (cannot be automated)
- Heartbeat must report ch_dead_letters and trigger LOUD alert if > 0
- Stathera audit verifies zero new gaps/overlaps after cutover
- Dedup token parity test (VALID-02) is a Rust unit test (already covered by Phase 34)
- Dead-letter round-trip test (VALID-05) is already covered by Phase 35

</decisions>

<code_context>

## Existing Code Insights

### Reusable Assets

- `python/opendeviationbar/sidecar/__init__.py` — sidecar orchestrator with `_create_engine()` and main loop
- `python/opendeviationbar/sidecar/clickhouse_write.py` — Python write path (`_write_batch_with_retry`)
- `python/opendeviationbar/sidecar/arrow_flush.py` — Arrow drain path (`_sync_flush_rest_bars_arrow`)
- `scripts/heartbeat/checks/stathera.py` — Stathera continuity check
- StreamManager.get*metrics() — already exposes ch_writer*\* metrics from Phase 36

### Integration Points

- `_create_engine()` in sidecar/**init**.py — read env var, pass to StreamManager
- Main loop bar write calls — skip when live mode
- Heartbeat formatter — display ch*writer*\* metrics
- deploy/opendeviationbar.env — add OPENDEVIATIONBAR_USE_RUST_CH_WRITER

</code_context>

<specifics>
## Specific Ideas

No specific requirements — refer to ROADMAP success criteria.

</specifics>

<deferred>
## Deferred Ideas

None.

</deferred>
