---
phase: 05.1-post-audit-polish
plan: 01
subsystem: sidecar
tags: [http-health, ws-mode, test-fix, observability]

# Dependency graph
requires:
  - phase: 04-combined-ws
    provides: WsMode config and StreamManager ws_mode parameter
provides:
  - "/health endpoint ws_mode and expected_ws_connections fields (MISS-01)"
  - "Corrected test helper _make_bar() dict keys matching production Rust output"
affects: [heartbeat, monit, deploy]

# Tech tracking
tech-stack:
  added: []
  patterns: []

key-files:
  created:
    - tests/test_health_ws_mode.py
  modified:
    - python/opendeviationbar/sidecar/http_server.py
    - python/opendeviationbar/sidecar/__init__.py
    - tests/test_sync_flush_atomic_replace.py

key-decisions:
  - "ws_mode defaults to 'unknown' when not set in _health_state (graceful degradation)"
  - "expected_ws_connections is 2 for combined mode (2x9 hybrid streams per connection)"

patterns-established: []

requirements-completed: []

# Metrics
duration: 4min
completed: 2026-03-24
---

# Phase 05.1 Plan 01: Post-Audit Polish Summary

**/health endpoint now exposes ws_mode and expected_ws_connections; test helper \_make_bar() keys corrected from open_time_us to open_time_ms matching production Rust output**

## Performance

- **Duration:** 4 min
- **Started:** 2026-03-24T22:23:14Z
- **Completed:** 2026-03-24T22:27:30Z
- **Tasks:** 2
- **Files modified:** 4

## Accomplishments

- /health JSON response includes ws_mode (combined|per_symbol|unknown) and expected_ws_connections (int) for monit/heartbeat observability (MISS-01 closed)
- \_make_bar() test helper dict keys corrected from open_time_us/close_time_us to open_time_ms/close_time_ms, matching src/helpers.rs production output
- Cross-midnight filter test now genuinely exercises the L1 filter (previously passed vacuously because bar.get("open_time_ms", 0) returned 0)

## Task Commits

Each task was committed atomically:

1. **Task 1: Add ws_mode and expected_ws_connections to /health endpoint (TDD)** - `7e35870` (test: failing), `d707542` (feat: implementation)
2. **Task 2: Fix \_make_bar() key mismatch** - `9b726bf` (fix)

## Files Created/Modified

- `python/opendeviationbar/sidecar/http_server.py` - Added ws_mode and expected_ws_connections to /health response dict
- `python/opendeviationbar/sidecar/__init__.py` - Populate \_health_state with ws_mode and ws_symbols_count at sidecar startup
- `tests/test_health_ws_mode.py` - New: 3 tests for /health ws_mode field (combined, per_symbol, default)
- `tests/test_sync_flush_atomic_replace.py` - Fixed \_make_bar() dict keys from open_time_us to open_time_ms

## Decisions Made

- ws_mode defaults to "unknown" when not set in_health_state (graceful degradation for pre-Phase-4 health checks)
- expected_ws_connections returns 2 for combined mode (2x9 hybrid streams), len(symbols) for per_symbol mode

## Deviations from Plan

None - plan executed exactly as written.

## Issues Encountered

- /health endpoint returns 503 (unhealthy) in test environment due to no local ClickHouse -- tests handle this by reading JSON body from HTTPError responses

## Known Stubs

None.

## User Setup Required

None - no external service configuration required.

## Next Phase Readiness

- MISS-01 closed: monit/heartbeat can now verify WS mode via /health
- All test helpers produce dict keys matching production Rust output
- Pre-existing test failures in test_adaptive_sleep.py, test_data_contracts.py, and test_day_mode_invariant.py are unrelated to this plan

---

_Phase: 05.1-post-audit-polish_
_Completed: 2026-03-24_
