---
phase: 22-monitor-hardening-schema
plan: 01
subsystem: monitoring
tags: [heartbeat, ouroboros, aion, clickhouse, schema-validation]

requires:
  - phase: 18-monitor-validation
    provides: Aion freshness check in yesterday.py
provides:
  - Aion freshness query filtered by ouroboros_mode='aion'
  - SCHEMA-01 ouroboros_mode mismatch warning on write paths
affects: [heartbeat, bulk-operations, sidecar-writes]

tech-stack:
  added: []
  patterns: [registry-based mode validation on write path]

key-files:
  created: []
  modified:
    - scripts/heartbeat/checks/yesterday.py
    - python/opendeviationbar/clickhouse/bulk_operations.py

key-decisions:
  - "Keep CH DEFAULT 'day' for backward compat; warn in Python instead of erroring"
  - "Use get_symbol_entries() lookup (not new function) for mode validation"

patterns-established:
  - "SCHEMA-01 pattern: warn on mode mismatch at write time, never block writes"

requirements-completed: [MON-04, SCHEMA-01]

duration: 2min
completed: 2026-03-27
---

# Phase 22 Plan 01: Aion Freshness + Write-Path Mode Validation Summary

**Aion freshness query filters by ouroboros_mode='aion' (MON-04) and both store methods warn on mode mismatch (SCHEMA-01)**

## Performance

- **Duration:** 2 min
- **Started:** 2026-03-27T19:57:33Z
- **Completed:** 2026-03-27T19:59:24Z
- **Tasks:** 2
- **Files modified:** 2

## Accomplishments

- Aion freshness heartbeat query now only considers bars with ouroboros_mode='aion', preventing false-positive freshness from leftover day-mode bars
- Both store_bars_bulk and store_bars_batch log SCHEMA-01 WARNING when a symbol's resolved ouroboros_mode doesn't match the registry entry
- No behavioral change to existing write paths (warnings only)

## Task Commits

1. **Task 1: Add ouroboros_mode='aion' filter to freshness query** - `279495e` (feat)
2. **Task 2: Add SCHEMA-01 ouroboros_mode validation warning on write** - `9309aaf` (feat)

## Files Created/Modified

- `scripts/heartbeat/checks/yesterday.py` - Added `AND ouroboros_mode = 'aion'` to \_check_aion_freshness SQL query
- `python/opendeviationbar/clickhouse/bulk_operations.py` - Added SCHEMA-01 mismatch warning in both store_bars_bulk (line ~585) and store_bars_batch (line ~932)

## Decisions Made

- Kept CH `DEFAULT 'day'` for backward compatibility — removing it would break existing INSERTs that don't specify the column
- Used `(ImportError, OSError)` catch instead of bare `Exception` for registry lookup failures

## Deviations from Plan

None - plan executed exactly as written.

## Issues Encountered

None

## User Setup Required

None - no external service configuration required.

## Next Phase Readiness

- MON-04 and SCHEMA-01 complete
- Ready for 22-02 (sidecar restart investigation)

## Self-Check: PASSED

---

_Phase: 22-monitor-hardening-schema_
_Completed: 2026-03-27_
