---
phase: 19-fleet-recompute-telemetry
plan: 01
type: execute
wave: 1
depends_on: []
files_modified:
  - scripts/detect_gaps.py
  - scripts/populate_full_cache.py
  - scripts/populate_range.py
  - deploy/opendeviationbar.env
  - deploy/CLAUDE.md
  - python/opendeviationbar/clickhouse/schema.sql
  - scripts/heartbeat/config.py
autonomous: true
requirements: [RECOMP-04, RECOMP-05]

must_haves:
  truths:
    - "detect_gaps.py accepts --ouroboros aion and resolves mode per-symbol from registry when not specified"
    - "populate_full_cache.py and populate_range.py accept --ouroboros aion and auto-detect from per-symbol registry"
    - "deploy/opendeviationbar.env documents OPENDEVIATIONBAR_OUROBOROS_MODE as forex-only fallback"
    - "schema.sql comments reflect Aion as a supported mode alongside Day"
    - "KNOWN_GAP_FINGERPRINTS dict is cleared (stale after recompute)"
  artifacts:
    - path: "scripts/detect_gaps.py"
      provides: "Per-symbol ouroboros mode resolution from registry"
      contains: "get_symbol_entry"
    - path: "scripts/populate_full_cache.py"
      provides: "Aion choice in --ouroboros CLI"
      contains: "aion"
    - path: "scripts/populate_range.py"
      provides: "Aion choice in --ouroboros CLI"
      contains: "aion"
    - path: "deploy/opendeviationbar.env"
      provides: "Updated comment for OUROBOROS_MODE"
      contains: "forex-only"
    - path: "python/opendeviationbar/clickhouse/schema.sql"
      provides: "Updated comment for ouroboros_mode column"
      contains: "Aion"
  key_links:
    - from: "scripts/detect_gaps.py"
      to: "python/opendeviationbar/symbol_registry.py"
      via: "get_symbol_entry() for per-symbol mode resolution"
      pattern: "get_symbol_entry"
---

<objective>
Update all diagnostic scripts, deploy config, and schema comments to support Aion mode for crypto symbols.

Purpose: Before the fleet recompute (Plan 02), all scripts and operational artifacts must accept and correctly resolve Aion mode so that post-recompute verification and ongoing operations work correctly.

Output: Updated scripts with Aion-aware CLI args and per-symbol registry resolution, updated deploy env comment, updated schema comments, cleared stale gap fingerprints.
</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
@python/opendeviationbar/ouroboros.py
@python/opendeviationbar/symbol_registry.py
</context>

<interfaces>
<!-- Key types and contracts the executor needs. -->

From python/opendeviationbar/ouroboros.py:

```python
class OuroborosMode(str, Enum):
    DAY = "day"
    AION = "aion"

def get_operational_ouroboros_mode() -> Literal["day", "aion"]:
    """Resolve from OPENDEVIATIONBAR_OUROBOROS_MODE env var via Settings."""
```

From python/opendeviationbar/symbol_registry.py:

```python
def get_symbol_entry(symbol: str) -> SymbolEntry:
    """Get a single symbol's entry. Has .ouroboros_mode attribute."""

def get_symbol_entries() -> MappingProxyType[str, SymbolEntry]:
    """All registered symbols as frozen dataclasses."""

def get_registered_symbols(*, asset_class=None, ouroboros_mode=None, enabled_only=True) -> list[str]:
    """Filter symbols by criteria."""
```

</interfaces>

<tasks>

<task type="auto">
  <name>Task 1: Update diagnostic scripts for Aion mode resolution</name>
  <files>scripts/detect_gaps.py, scripts/populate_full_cache.py, scripts/populate_range.py</files>
  <read_first>scripts/detect_gaps.py, scripts/populate_full_cache.py, scripts/populate_range.py, python/opendeviationbar/symbol_registry.py</read_first>
  <action>
Three scripts need updates for RECOMP-05:

**detect_gaps.py:**

1. Update `_resolve_ouroboros_mode()` (line ~102) to accept an optional `symbol` parameter. When symbol is provided, look up `get_symbol_entry(symbol).ouroboros_mode` from the registry FIRST, falling back to `get_operational_ouroboros_mode()` only if registry lookup fails. When no symbol, keep current behavior (global env var).
2. Update `stathera_audit_single()` (line ~448) to call `_resolve_ouroboros_mode(symbol=symbol)` instead of `_resolve_ouroboros_mode()` so each symbol gets its own mode from registry.
3. Update the `--ouroboros-mode` argparse choice from `choices=["day"]` (line ~987) to `choices=["day", "aion"]`.
4. Update help text from "Only 'day' mode is supported" to "Ouroboros mode filter (default: auto-detect from per-symbol registry)."

**populate_full_cache.py:**

1. Update `--ouroboros` argparse choice from `choices=["day"]` (line ~240) to `choices=["day", "aion"]`.
2. Update help text to mention per-symbol auto-detection from registry.
3. When `--ouroboros` is not specified (None), resolve from per-symbol registry: import `get_symbol_entry` and use `get_symbol_entry(symbol).ouroboros_mode`. Apply in `_populate_single()` where `ouroboros_mode` is passed to `populate_cache_resumable()`.

**populate_range.py:**

1. Update `--ouroboros` argparse choice from `choices=["day"]` (line ~227) to `choices=["day", "aion"]`.
2. Update help text similarly.
3. When `--ouroboros` is not specified, resolve from per-symbol registry in the same pattern.
   </action>

  <verify>
    <automated>cd /Users/terryli/eon/opendeviationbar-py && python -c "
import subprocess, sys
# Verify detect_gaps accepts aion
r = subprocess.run([sys.executable, 'scripts/detect_gaps.py', '--help'], capture_output=True, text=True)
assert 'aion' in r.stdout, 'detect_gaps.py missing aion choice'
# Verify populate_full_cache accepts aion
r = subprocess.run([sys.executable, 'scripts/populate_full_cache.py', '--help'], capture_output=True, text=True)
assert 'aion' in r.stdout, 'populate_full_cache.py missing aion choice'
# Verify populate_range accepts aion
r = subprocess.run([sys.executable, 'scripts/populate_range.py', '--help'], capture_output=True, text=True)
assert 'aion' in r.stdout, 'populate_range.py missing aion choice'
print('All scripts accept aion mode')
"</automated>
  </verify>
  <acceptance_criteria>
    - grep -q "aion" scripts/detect_gaps.py (choices include aion)
    - grep -q "get_symbol_entry" scripts/detect_gaps.py (per-symbol resolution)
    - grep -q "aion" scripts/populate_full_cache.py
    - grep -q "aion" scripts/populate_range.py
  </acceptance_criteria>
  <done>All three diagnostic scripts accept "aion" as --ouroboros choice and auto-detect mode per-symbol from registry when not explicitly specified</done>
</task>

<task type="auto">
  <name>Task 2: Update deploy config, schema comments, and clear stale fingerprints</name>
  <files>deploy/opendeviationbar.env, deploy/CLAUDE.md, python/opendeviationbar/clickhouse/schema.sql, scripts/heartbeat/config.py</files>
  <read_first>deploy/opendeviationbar.env, deploy/CLAUDE.md, python/opendeviationbar/clickhouse/schema.sql, scripts/heartbeat/config.py</read_first>
  <action>
Four files need updates for RECOMP-04 and RECOMP-05:

**deploy/opendeviationbar.env** (line ~11):

- Change comment from `# Issue #137: Day-mode ouroboros for atomic daily resets` to `# Issue #137: Global ouroboros fallback. Per-symbol registry (symbols.toml) takes precedence. This value is forex-only fallback for scripts lacking symbol context.`
- Keep the value `OPENDEVIATIONBAR_OUROBOROS_MODE=day` unchanged (forex symbols still use day mode; per-symbol registry overrides for crypto).

**deploy/CLAUDE.md:**

- In the "opendeviationbar.env -- Key Variables" section, update the `OPENDEVIATIONBAR_OUROBOROS_MODE` comment from `# Ouroboros (day-mode for atomic daily resets)` to `# Ouroboros (forex-only fallback; per-symbol registry takes precedence for crypto=aion)`.
- Add a note that crypto symbols use `ouroboros_mode = "aion"` from `symbols.toml` per-symbol registry (Phase 13 REG-01).

**python/opendeviationbar/clickhouse/schema.sql:**

- Line ~258: Change comment from `-- Day mode is the only supported mode.` to `-- Day (UTC midnight reset) or Aion (continuous, crypto-only). Per-symbol SSoT: symbols.toml.`
- Line ~443 (population_checkpoints table): Same comment update.

**scripts/heartbeat/config.py:**

- Clear the `KNOWN_GAP_FINGERPRINTS` dict (line ~119). Set it to an empty dict `{}` with a comment: `# Cleared for v7.0 Aion recompute. Re-add only if gaps reappear post-recompute.`
- This prevents stale fingerprints from masking real issues after the fleet recompute changes all trade-ID boundaries.
  </action>
  <verify>
  <automated>cd /Users/terryli/eon/opendeviationbar-py && python -c "
  import re

# Check env file

with open('deploy/opendeviationbar.env') as f:
content = f.read()
assert 'forex-only' in content, 'env file missing forex-only comment'

# Check schema.sql

with open('python/opendeviationbar/clickhouse/schema.sql') as f:
content = f.read()
assert 'Aion' in content, 'schema.sql missing Aion reference'
assert 'Day mode is the only supported mode' not in content, 'stale comment remains'

# Check fingerprints cleared

with open('scripts/heartbeat/config.py') as f:
content = f.read()
assert 'Cleared for v7.0' in content or 'KNOWN_GAP_FINGERPRINTS: dict[tuple, dict] = {}' in content, 'fingerprints not cleared'
print('All config updates verified')
"</automated>
</verify>
<acceptance_criteria> - grep -q "forex-only" deploy/opendeviationbar.env - grep -q "Aion" python/opendeviationbar/clickhouse/schema.sql - grep -v "Day mode is the only supported mode" python/opendeviationbar/clickhouse/schema.sql (stale comment removed) - grep -q "Cleared for v7.0" scripts/heartbeat/config.py
</acceptance_criteria>
<done>Deploy env has forex-only fallback comment, schema.sql reflects Aion support, stale gap fingerprints cleared for fleet recompute</done>
</task>

</tasks>

<verification>
1. `python scripts/detect_gaps.py --help` shows "aion" in --ouroboros-mode choices
2. `python scripts/populate_full_cache.py --help` shows "aion" in --ouroboros choices
3. `python scripts/populate_range.py --help` shows "aion" in --ouroboros choices
4. `grep "forex-only" deploy/opendeviationbar.env` returns a match
5. `grep "Aion" python/opendeviationbar/clickhouse/schema.sql` returns matches
6. `grep "Cleared for v7.0" scripts/heartbeat/config.py` returns a match
</verification>

<success_criteria>
All diagnostic scripts, deploy config, schema comments, and heartbeat config are Aion-aware. No stale Day-mode-only references remain for crypto symbol contexts. Ready for fleet recompute in Plan 02.
</success_criteria>

<output>
After completion, create `.planning/phases/19-fleet-recompute-telemetry/19-01-SUMMARY.md`
</output>
