---
phase: 33-dead-code-removal
plan: 01
type: execute
wave: 1
depends_on: []
files_modified:
  - python/opendeviationbar/sidecar/__init__.py
  - python/opendeviationbar/sidecar/config_helpers.py
autonomous: true
requirements: [CLEANUP-02, CLEANUP-03, CLEANUP-04]

must_haves:
  truths:
    - "Midnight preflight path only executes when day_symbols is non-empty"
    - "No dead day-mode fallback paths remain in sidecar or scripts"
    - "_seed_trade_ids_from_clickhouse has no unused symbol_modes parameter"
    - "All tests pass after changes"
  artifacts:
    - path: "python/opendeviationbar/sidecar/__init__.py"
      provides: "Log message when day_symbols is empty, skipping midnight preflight"
    - path: "python/opendeviationbar/sidecar/config_helpers.py"
      provides: "Cleaned _seed_trade_ids_from_clickhouse without symbol_modes param"
  key_links:
    - from: "python/opendeviationbar/sidecar/__init__.py"
      to: "python/opendeviationbar/sidecar/midnight.py"
      via: "day_symbols guard before _run_midnight_preflight call"
      pattern: "if day_symbols:"
---

<objective>
Audit and clean up day-mode dead code paths in the sidecar, removing unused parameters and adding skip-logging for the day-mode branch.

Purpose: Reduce maintenance surface and eliminate footgun risk now that all crypto symbols are Aion-only. Day-mode code is kept guarded (not deleted) for potential forex re-enablement.
Output: Cleaned sidecar code with verified guards, removed unused params, and explicit skip-logging.
</objective>

<execution_context>
@$HOME/.claude/get-shit-done/workflows/execute-plan.md
@$HOME/.claude/get-shit-done/templates/summary.md
</execution_context>

<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
@.planning/phases/33-dead-code-removal/33-CONTEXT.md
@python/opendeviationbar/sidecar/__init__.py
@python/opendeviationbar/sidecar/config_helpers.py
@python/opendeviationbar/sidecar/midnight.py
</context>

<tasks>

<task type="auto">
  <name>Task 1: Audit guards, remove dead params, add skip-logging</name>
  <files>python/opendeviationbar/sidecar/__init__.py, python/opendeviationbar/sidecar/config_helpers.py</files>
  <read_first>
    - python/opendeviationbar/sidecar/__init__.py (full file -- understand _create_engine and run_sidecar)
    - python/opendeviationbar/sidecar/config_helpers.py (full file -- see _seed_trade_ids_from_clickhouse signature)
    - python/opendeviationbar/sidecar/midnight.py (grep for symbol_modes usage)
    - python/opendeviationbar/sidecar/recovery.py (grep for _seed_trade_ids_from_clickhouse calls)
  </read_first>
  <action>
    This is a 4-part audit-and-clean task:

    **Part 1: Grep audit** -- Verify all day-mode guards are in place.
    Run these greps and confirm results match expectations:
    - `grep -rn "if day_symbols:" python/opendeviationbar/sidecar/` -- confirm _run_midnight_preflight and _check_yesterday_integrity are guarded
    - `grep -rn "_run_midnight_preflight\|_check_yesterday_integrity\|_heal_day_boundary_gaps" python/opendeviationbar/sidecar/__init__.py` -- confirm all day-mode calls are inside `if day_symbols:` block
    - `grep -rn "OuroborosMode.DAY\|ouroboros_mode.*day\|\"day\"" python/ scripts/` -- identify any remaining dead fallback paths (expect: symbols.toml entries, enum definition, guard conditions, tests only)

    **Part 2: Add skip-logging for empty day_symbols** (CLEANUP-02).
    In `_create_engine()` in `__init__.py`, add an `else` branch after `if day_symbols:` (around line 404):
    ```python
    else:
        logger.info("day: no day-mode symbols -- skipping midnight preflight path")
    ```
    This makes it explicit in logs when the day path is skipped.

    **Part 3: Remove unused symbol_modes param from _seed_trade_ids_from_clickhouse** (CLEANUP-03).
    In `config_helpers.py`, remove the `symbol_modes: dict[str, str] | None = None` parameter from `_seed_trade_ids_from_clickhouse()`. Update the docstring if needed. Check all callers of this function (grep for `_seed_trade_ids_from_clickhouse`) and remove any `symbol_modes=` keyword argument passed to it.

    **Part 4: Remove any remaining dead day-mode code paths** (CLEANUP-04).
    Based on the grep audit from Part 1, if any unguarded day-mode fallback paths exist outside the `if day_symbols:` block, either guard them or remove them. Specifically check:
    - The `symbol_modes` dict construction in `_create_engine()` -- the `else: symbol_modes[sym] = "aion"` branch (line ~224) already forces aion for non-registry symbols, which is correct
    - Any `.get(symbol, "day")` fallbacks that should be `.get(symbol, "aion")` -- these should have been changed in Phase 31 but verify
    - The `_seed_trade_ids_from_clickhouse` call in the `else` branch of `needs_fill` (line ~590) -- this is the non-fill_from_rest path for OdbEngine, keep it but without the removed param

    Do NOT delete the `if day_symbols:` block itself or the midnight.py functions -- they are guarded and may be needed for forex re-enablement.

  </action>
  <verify>
    <automated>cd /Users/terryli/eon/opendeviationbar-py && grep -n "no day-mode symbols" python/opendeviationbar/sidecar/__init__.py && grep -c "symbol_modes" python/opendeviationbar/sidecar/config_helpers.py | grep "^0$" && uv run --python 3.13 python -c "from opendeviationbar.sidecar.config_helpers import _seed_trade_ids_from_clickhouse; import inspect; sig = inspect.signature(_seed_trade_ids_from_clickhouse); assert 'symbol_modes' not in sig.parameters, 'symbol_modes still present'; print('OK: symbol_modes removed')"</automated>
  </verify>
  <acceptance_criteria>
    - grep audit confirms all day-mode calls (_run_midnight_preflight, _check_yesterday_integrity, DELETE today loop) are inside `if day_symbols:` guard
    - `else` branch after `if day_symbols:` logs "day: no day-mode symbols -- skipping midnight preflight path"
    - `_seed_trade_ids_from_clickhouse()` has no `symbol_modes` parameter
    - No callers pass `symbol_modes=` to `_seed_trade_ids_from_clickhouse()`
    - `grep -rn 'get.*"day"' python/opendeviationbar/sidecar/` shows only: (a) the `if m == "day"` guard in symbol_modes construction, (b) the L1 cross-midnight filter `symbol_modes.get(symbol, "aion") == "day"` -- no unguarded "day" fallbacks
    - `uv run --python 3.13 python -c "from opendeviationbar.sidecar import run_sidecar"` imports without error
  </acceptance_criteria>
  <done>Day-mode code paths verified guarded, unused symbol_modes param removed, skip-logging added, all imports clean</done>
</task>

</tasks>

<verification>
- All day-mode sidecar calls are behind `if day_symbols:` guard
- _seed_trade_ids_from_clickhouse signature has exactly 3 params (engine, symbols, thresholds)
- `python -c "from opendeviationbar.sidecar import run_sidecar"` succeeds
- grep for `"day"` fallback defaults in sidecar shows zero unguarded paths
</verification>

<success_criteria>
Requirements CLEANUP-02, CLEANUP-03, CLEANUP-04 are satisfied:

- Midnight preflight guarded behind day-mode check with explicit skip-log (CLEANUP-02)
- Unused symbol_modes parameter removed from_seed_trade_ids_from_clickhouse (CLEANUP-03)
- Grep audit confirms no dead day-mode code paths remain (CLEANUP-04)
  </success_criteria>

<output>
After completion, create `.planning/phases/33-dead-code-removal/33-01-SUMMARY.md`
</output>
