---
phase: 02-legacy-pruning
plan: 01
type: execute
wave: 1
depends_on: []
files_modified:
  - python/opendeviationbar/sidecar.py
autonomous: true
requirements:
  - PRUNE-01
  - PRUNE-02
  - PRUNE-03

must_haves:
  truths:
    - "_inline_startup_backfill function does not exist in sidecar.py"
    - "_startup_tid_reconciliation function does not exist in sidecar.py"
    - "_gap_fill() is not called from _restart_engine_with_recovery()"
    - "_create_engine receives gap_fill_results=None in watchdog restart path"
  artifacts:
    - path: "python/opendeviationbar/sidecar.py"
      provides: "Sidecar orchestrator with dead restart-gap code removed"
      contains: "def _restart_engine_with_recovery"
  key_links:
    - from: "python/opendeviationbar/sidecar.py (_restart_engine_with_recovery)"
      to: "python/opendeviationbar/sidecar.py (_create_engine)"
      via: "_create_engine(config, trace_id, None, valid_pairs=valid_pairs)"
      pattern: "_create_engine.*None.*valid_pairs"
---

<objective>
Delete three dead restart-gap code paths from sidecar.py: `_inline_startup_backfill()` (never called), `_startup_tid_reconciliation()` (redundant with fill_from_rest), and `_gap_fill()` call from watchdog restart (let fill_from_rest handle via _create_engine).

Purpose: Reduce sidecar.py complexity by removing ~150 lines of dead code that confuses readers about which restart mechanism is active.
Output: Smaller sidecar.py with only the fill_from_rest restart path.
</objective>

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

<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
@.planning/phases/02-legacy-pruning/02-CONTEXT.md
</context>

<tasks>

<task type="auto">
  <name>Task 1: Delete dead functions and remove call sites from sidecar.py</name>
  <files>python/opendeviationbar/sidecar.py</files>
  <read_first>python/opendeviationbar/sidecar.py (lines 525-620 for _inline_startup_backfill, lines 705-760 for _startup_tid_reconciliation, lines 1100-1170 for _restart_engine_with_recovery, lines 2260-2270 for run_sidecar call site, lines 25-35 for module docstring)</read_first>
  <action>
Four deletions in sidecar.py, each verified independently:

1. **Delete `_inline_startup_backfill()` function** (~line 528-615): Remove the entire function definition. It is never called anywhere (confirmed by grep). Remove any imports that become unused after this deletion.

2. **Delete `_startup_tid_reconciliation()` function** (~line 709-759): Remove the entire function definition AND its call site at ~line 2266 in `run_sidecar()`. The call site looks like:

   ```python
   if hasattr(engine, "fill_gap"):
       _startup_tid_reconciliation(engine, config.symbols, config.thresholds)
   ```

   Delete both the `if` check and the function call (2 lines).

3. **Remove `_gap_fill()` call from `_restart_engine_with_recovery()`** (~lines 1141-1153): Delete the "Step 4" block that calls `_gap_fill()`. Replace the `fresh_gap_fill` variable passed to `_create_engine()` with `None`. The result should look like:

   ```python
   # Step 3: Force shutdown
   ...

   # Step 4: Create new engine (fill_from_rest handles gaps via _create_engine)
   new_engine, _, new_min_tid_guard = _create_engine(
       config,
       trace_id,
       None,
       valid_pairs=valid_pairs,
   )
   ```

   Renumber the step comment from "Step 5" to "Step 4". Remove the logger.info about "running fresh gap-fill".

4. **Clean module docstring** (~line 29-34): Remove the "Start with gap-fill on startup" example block that references `gap_fill_on_startup=True`. Also remove the comment at ~line 927 referencing `_inline_startup_backfill()` if it exists ("This replaces the Python \_inline_startup_backfill()...").

Do NOT delete the `_gap_fill()` function itself -- it is still used by the HTTP API handler `_handle_gap_fill()` (~line 1605).

After all deletions, verify no dangling references remain by grepping for each deleted symbol.
</action>
<verify>
<automated>cd /Users/terryli/eon/opendeviationbar-py && grep -n "\_inline_startup_backfill\|\_startup_tid_reconciliation" python/opendeviationbar/sidecar.py | grep -v "^#" | grep -v "comment" ; echo "EXIT:$?"</automated>
</verify>
<acceptance_criteria>

- `grep -c "_inline_startup_backfill" python/opendeviationbar/sidecar.py` returns 0
- `grep -c "_startup_tid_reconciliation" python/opendeviationbar/sidecar.py` returns 0
- `_restart_engine_with_recovery()` passes `None` as gap_fill_results to `_create_engine()`
- `grep "_gap_fill" python/opendeviationbar/sidecar.py` shows only `def _gap_fill`, `_gap_fill_bucket`, and `_handle_gap_fill` references (no call in watchdog path)
- `uv run --python 3.13 pytest tests/test_sidecar.py tests/test_sidecar_watchdog.py -x -q` passes
  </acceptance_criteria>
  <done>All three dead functions/call sites removed from sidecar.py. No references to deleted symbols remain. Existing tests pass.</done>
  </task>

</tasks>

<verification>
```bash
# Verify deleted symbols are gone
grep -c "_inline_startup_backfill" python/opendeviationbar/sidecar.py  # expect 0
grep -c "_startup_tid_reconciliation" python/opendeviationbar/sidecar.py  # expect 0

# Verify \_gap_fill NOT called from watchdog (only def, bucket, and HTTP handler remain)

grep "\_gap_fill" python/opendeviationbar/sidecar.py

# Verify \_create_engine gets None in watchdog path

grep -A5 "Step 4.\*Create new engine" python/opendeviationbar/sidecar.py

# Run tests

uv run --python 3.13 pytest tests/test_sidecar.py tests/test_sidecar_watchdog.py -x -q

```
</verification>

<success_criteria>
- _inline_startup_backfill() function deleted from sidecar.py (PRUNE-01)
- _startup_tid_reconciliation() function and its call site deleted from sidecar.py (PRUNE-02)
- _gap_fill() call removed from _restart_engine_with_recovery(), replaced with None (PRUNE-03)
- All sidecar tests pass
</success_criteria>

<output>
After completion, create `.planning/phases/02-legacy-pruning/02-01-SUMMARY.md`
</output>
```
