---
phase: 21-universal-write-path-ouroboros-mode
plan: 01
subsystem: api
tags: [ouroboros, symbol-registry, write-path, per-symbol-mode]

requires:
  - phase: 15-registry-ouroboros-mode
    provides: "OuroborosMode enum + per-symbol registry in symbols.toml"
provides:
  - "Per-symbol ouroboros_mode in all write paths (backfill, dead-letter, count-bounded)"
  - "_get_mode_for_symbol() helper pattern in backfill.py"
affects: [sidecar, kintsugi, orchestration]

tech-stack:
  added: []
  patterns:
    - "Per-symbol ouroboros_mode lookup via _get_mode_for_symbol() before store_bars_batch"

key-files:
  created: []
  modified:
    - python/opendeviationbar/backfill.py
    - python/opendeviationbar/kintsugi/dead_letter.py
    - python/opendeviationbar/orchestration/count_bounded.py

key-decisions:
  - "Thread ouroboros_mode through _fill_gap_and_cache and _fill_gap_exness rather than re-resolving per call"
  - "Keep get_operational_ouroboros_mode() in _get_cached_symbol_threshold_pairs() (read path, filters CH query by operational mode)"

patterns-established:
  - "_get_mode_for_symbol(symbol) pattern: registry lookup with 'day' default for unknown symbols"

requirements-completed: [WRITE-01, WRITE-02, WRITE-03, WRITE-04]

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

# Phase 21 Plan 01: Universal Write Path ouroboros_mode Summary

**Per-symbol ouroboros_mode wired into all 6 store_bars_batch call sites across backfill.py, dead_letter.py, and count_bounded.py -- eliminating global get_operational_ouroboros_mode() fallback for crypto write paths**

## Performance

- **Duration:** 4 min
- **Started:** 2026-03-27T19:57:28Z
- **Completed:** 2026-03-27T20:01:39Z
- **Tasks:** 2
- **Files modified:** 3

## Accomplishments

- All 3 store_bars_batch calls in backfill.py now pass ouroboros_mode from per-symbol registry lookup
- dead_letter.py store_bars_batch call passes per-symbol ouroboros_mode via \_get_mode_for_symbol from \_helpers
- Both store_bars_batch calls in count_bounded.py pass per-symbol ouroboros_mode (threaded through \_fill_gap_and_cache and \_fill_gap_exness)
- Zero remaining global-fallback call sites in write paths (only read-path \_get_cached_symbol_threshold_pairs retains global mode)

## Task Commits

Each task was committed atomically:

1. **Task 1: Wire per-symbol ouroboros_mode in backfill.py and dead_letter.py** - `fc4e764` (feat)
2. **Task 2: Wire per-symbol ouroboros_mode in count_bounded.py** - `2a477c8` (feat)

## Files Created/Modified

- `python/opendeviationbar/backfill.py` - Added \_get_mode_for_symbol() helper, replaced 3 global mode calls with per-symbol lookup, added ouroboros_mode to 3 store_bars_batch calls
- `python/opendeviationbar/kintsugi/dead_letter.py` - Imported \_get_mode_for_symbol from \_helpers, added ouroboros_mode to store_bars_batch call
- `python/opendeviationbar/orchestration/count_bounded.py` - Replaced global mode fallback with per-symbol registry lookup, threaded ouroboros_mode through_fill_gap_and_cache and_fill_gap_exness, added ouroboros_mode to both store_bars_batch calls

## Decisions Made

- Thread ouroboros_mode as a parameter through_fill_gap_and_cache and_fill_gap_exness rather than re-resolving per call (avoids redundant registry lookups)
- Keep get_operational_ouroboros_mode() in_get_cached_symbol_threshold_pairs() -- this is a read path that queries CH for all pairs in the operational mode, not a write path

## Deviations from Plan

### Auto-fixed Issues

**1. [Rule 3 - Blocking] Thread ouroboros_mode through \_fill_gap_and_cache and \_fill_gap_exness**

- **Found during:** Task 2 (count_bounded.py)
- **Issue:** The plan specified adding ouroboros_mode to store_bars_batch at line 522, but that call is inside_fill_gap_and_cache (a separate function), not inside get_n_open_deviation_bars(). The ouroboros_mode variable was not in scope.
- **Fix:** Added ouroboros_mode parameter to_fill_gap_and_cache() and_fill_gap_exness() signatures, threaded the value from get_n_open_deviation_bars() through the call chain
- **Files modified:** python/opendeviationbar/orchestration/count_bounded.py
- **Verification:** Type checker confirms no unresolved references
- **Committed in:** 2a477c8

---

**Total deviations:** 1 auto-fixed (1 blocking)
**Impact on plan:** Necessary to correctly wire ouroboros_mode to the nested function calls. No scope creep.

## Issues Encountered

None

## User Setup Required

None - no external service configuration required.

## Next Phase Readiness

- Phase 21 Plan 01 complete, ready for next plan or phase verification
- All write paths now use per-symbol ouroboros_mode from the registry

## Self-Check: PASSED

---

_Phase: 21-universal-write-path-ouroboros-mode_
_Completed: 2026-03-27_
