# Execution Engine — Alpaca/multistrat Loop (Sub-project C1) Implementation Plan

> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** Make `execute-multistrat` B2a-driven — deploy exactly `strategy_allocation[multistrat]` dollars into the multistrat book on Alpaca (flatten to cash on $0/absent), reconcile + place via the existing `ExecutionService`, and record the executed book's daily (envelope-basis, flow-excluded) return as an observed `forward_record` for a new `multistrat_exec` track via A's `run_track`.

**Architecture:** Pure helpers (`scaled_weights` bridge, `compute_exec_return`, `build_pos_state`) + `record_exec_track` (which reuses A's observed `run_track` to book the exec return + carries the position-state in A's book-state under `multistrat_exec_pos`). A registry `multistrat_exec` observed track. The CLI reads B2a's envelope, scales the book weights to it, flattens on zero, and on `--execute` records the exec track. No new execution engine — reuse `ExecutionService`/`AlpacaBroker`/A's machinery.

**Tech Stack:** Python 3.12, Typer CLI, SQLAlchemy 2.0 (sqlite tests / Postgres prod), pytest (`uv run pytest`), ruff (E,F,I,UP,B,SIM; 120).

## Global Constraints

- Spec: `docs/superpowers/specs/2026-07-09-execution-engine-alpaca-multistrat-c1-design.md` (authoritative).
- Builds on A (`run_track`, `get_book_state`/`set_book_state`/`append_record`, the observed machinery), B1 (gate), B2a (`ForwardNavRepo.current_allocation()` → `{strategy_id: target_dollars}`). All merged.
- REAL MONEY (paper for now): the engine reconciles, never authorizes capital. Deploy exactly B2a's `multistrat` envelope = `min(target_dollars, account_NLV)`; **$0 / absent row → flatten to cash** (deploy nothing). Real capital = the existing `--live` + `allow_live` gate (unchanged). Dry-run is the default (`--execute` places).
- LOAD-BEARING: the executed return is measured on B2a's **envelope** (not the full account NLV), and EXCLUDES re-allocation capital flows (time-weighted: the P&L of the HELD positions since the last rebalance). Tests pin both.
- Reuse `ExecutionService.rebalance_weights` + `AlpacaBroker` + A's `run_track`/book-state — do NOT build a new execution engine or a new return-accumulation store.
- Determinism: the return/bridge helpers are pure. Never save tests to the repo root. Commit after every task; messages end with the `Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>` trailer.

---

### Task 1: Pure helpers — the bridge, the exec return, the position-state

**Files:**
- Create: `src/fxhnt/application/multistrat_exec_record.py`
- Test: `tests/unit/test_multistrat_exec_helpers.py`

**Interfaces:**
- Produces:
  - `scaled_weights(within_weights: dict[str,float], envelope: float, nlv: float) -> dict[str,float]` — the bridge: `within_i · envelope/nlv` so `ExecutionService`'s `weight·NLV` sizing lands on `within_i·envelope`; all-zero when `envelope<=0` or `nlv<=0` (flatten).
  - `build_pos_state(positions: dict[str,float], prices: dict[str,float], envelope: float) -> dict` — the carried position-state for the next run's return.
  - `compute_exec_return(pos_prior: dict, today_prices: dict[str,float]) -> float | None` — the time-weighted, envelope-basis daily return of the PRIOR book at today's prices; `None` on the first run (no prior).

- [ ] **Step 1: Write the failing test**

```python
# tests/unit/test_multistrat_exec_helpers.py
from fxhnt.application.multistrat_exec_record import (
    build_pos_state, compute_exec_return, scaled_weights)


def test_scaled_weights_bridge_and_flatten():
    w = {"SPY": 0.6, "IEF": 0.4}
    # envelope 10k in a 100k account → scale 0.1 → weights sum to envelope/NLV
    s = scaled_weights(w, envelope=10_000.0, nlv=100_000.0)
    assert abs(s["SPY"] - 0.06) < 1e-12 and abs(s["IEF"] - 0.04) < 1e-12
    assert scaled_weights(w, 0.0, 100_000.0) == {"SPY": 0.0, "IEF": 0.0}      # $0 envelope → flatten
    assert scaled_weights(w, 10_000.0, 0.0) == {"SPY": 0.0, "IEF": 0.0}       # no NLV → flatten (safe)


def test_compute_exec_return_first_run_is_none():
    assert compute_exec_return({}, {"SPY": 500.0}) is None                    # no prior book → inception


def test_exec_return_is_envelope_basis_not_full_nlv():
    # prior book: $10k envelope fully deployed in 20 SPY @ 500 (=$10k), in a (hypothetical) large account.
    prior = build_pos_state({"SPY": 20.0}, {"SPY": 500.0}, envelope=10_000.0)
    # SPY +10% today → book +$1000 on the $10k envelope → 10% return (NOT diluted by any idle account cash)
    assert abs(compute_exec_return(prior, {"SPY": 550.0}) - 0.10) < 1e-9


def test_reallocation_capital_flow_is_not_return():
    # flat prices; the envelope will grow at the NEXT rebalance (a flow) — the RETURN of the prior book is ~0
    prior = build_pos_state({"SPY": 20.0}, {"SPY": 500.0}, envelope=10_000.0)
    assert abs(compute_exec_return(prior, {"SPY": 500.0})) < 1e-12            # flat prices → 0%, not a jump


def test_partial_deployment_reserve_earns_zero():
    # $10k envelope, only $6k deployed (12 SPY @ 500), $4k reserve. SPY +10% → +$600 on $10k = 6%.
    prior = build_pos_state({"SPY": 12.0}, {"SPY": 500.0}, envelope=10_000.0)
    assert abs(compute_exec_return(prior, {"SPY": 550.0}) - 0.06) < 1e-9
```

- [ ] **Step 2: Run test to verify it fails**

Run: `uv run pytest tests/unit/test_multistrat_exec_helpers.py -q`
Expected: FAIL with `ModuleNotFoundError: No module named 'fxhnt.application.multistrat_exec_record'`.

- [ ] **Step 3: Implement the helpers**

```python
# src/fxhnt/application/multistrat_exec_record.py
"""Sub-project C1 — record the EXECUTED multistrat track and bridge B2a's dollar allocation to the venue.

`scaled_weights` turns the multistrat book's within-book weights into weights that ExecutionService sizes to
B2a's envelope (not the full account). `compute_exec_return` measures the executed book's daily return on
B2a's ENVELOPE (not the full NLV) and as the P&L of the HELD positions since the last rebalance (a
re-allocation is a capital flow, not a gain). `record_exec_track` books that return as an observed
forward_record via A's run_track. No new execution engine, no new return store."""
from __future__ import annotations

from typing import Any


def scaled_weights(within_weights: dict[str, float], envelope: float, nlv: float) -> dict[str, float]:
    if envelope <= 0.0 or nlv <= 0.0:
        return {s: 0.0 for s in within_weights}          # flatten to cash (B2a $0 / no NLV)
    scale = envelope / nlv
    return {s: w * scale for s, w in within_weights.items()}


def build_pos_state(positions: dict[str, float], prices: dict[str, float], envelope: float) -> dict[str, Any]:
    return {"positions": {s: float(q) for s, q in positions.items()},
            "prices": {s: float(p) for s, p in prices.items()}, "envelope": float(envelope)}


def compute_exec_return(pos_prior: dict[str, Any], today_prices: dict[str, float]) -> float | None:
    envelope = float(pos_prior.get("envelope", 0.0))
    if not pos_prior or envelope <= 0.0:
        return None                                      # first run / no prior book → inception
    positions = pos_prior.get("positions", {})
    prior_prices = pos_prior.get("prices", {})
    val_prior = sum(q * prior_prices[s] for s, q in positions.items())
    val_today = sum(q * today_prices.get(s, prior_prices[s]) for s, q in positions.items())
    reserve = envelope - val_prior                       # un-deployed envelope earns 0
    exec_equity_today = val_today + reserve
    return exec_equity_today / envelope - 1.0
```

- [ ] **Step 4: Run tests → PASS + ruff, then commit**

Run: `uv run pytest tests/unit/test_multistrat_exec_helpers.py -q` → PASS (5 passed).
Run: `uv run ruff check src/fxhnt/application/multistrat_exec_record.py tests/unit/test_multistrat_exec_helpers.py`

```bash
git add src/fxhnt/application/multistrat_exec_record.py tests/unit/test_multistrat_exec_helpers.py
git commit -F - <<'EOF'
feat(exec): pure C1 helpers — B2a-envelope bridge + envelope-basis flow-excluded exec return

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
EOF
```

---

### Task 2: Registry — the `multistrat_exec` observed track

**Files:**
- Modify: `src/fxhnt/registry.py` (add `multistrat_exec`)
- Modify: `tests/unit/test_forward_definition.py` (the observed-set assertion)
- Test: `tests/unit/test_registry_multistrat_exec.py`

**Interfaces:**
- Produces: `STRATEGY_REGISTRY["multistrat_exec"]` with `record_mode == "observed"`, venue `alpaca-paper`, a reconciliation gate_spec, and a `definition`.

- [ ] **Step 1: Write the failing test**

```python
# tests/unit/test_registry_multistrat_exec.py
from fxhnt.application.forward_definition import track_definition
from fxhnt.registry import STRATEGY_REGISTRY


def test_multistrat_exec_is_observed_track():
    e = STRATEGY_REGISTRY["multistrat_exec"]
    assert e["venue"] == "alpaca-paper"
    _params, _version, mode = track_definition("multistrat_exec")
    assert mode == "observed"                       # executed fills are observed, not recomputable
    assert e["gate_spec"].get("gate_type") == "reconciliation"
```

- [ ] **Step 2: Run test to verify it fails**

Run: `uv run pytest tests/unit/test_registry_multistrat_exec.py -q`
Expected: FAIL with `KeyError: 'multistrat_exec'`.

- [ ] **Step 3: Add the registry entry**

In `src/fxhnt/registry.py`, add (after the `multistrat` entry):

```python
    # The EXECUTED multistrat book (sub-project C1): the real Alpaca-paper track — its daily return is the
    # executed book's envelope-basis P&L (fills + slippage + fees), recorded by `fxhnt execute-multistrat
    # --execute` (NOT a nightly nav asset). OBSERVED (fills are observed, not recomputable). Its gate
    # reconciles the executed track against the MODELED multistrat (execution decay shows as divergence).
    "multistrat_exec": {
        "display_name": "Multi-strat book (EXECUTED, Alpaca paper)", "sleeve": "tradfi-multistrat",
        "venue": "alpaca-paper", "state_file": "multistrat_exec_state",
        "tier": "research", "execution": "paper",
        "gate_spec": {"gate_type": "reconciliation", "min_forward_days": 20, "max_gap_days": 4},
        "definition": {"params": {"source": "alpaca-executed-fills", "models": "multistrat"},
                       "version": 1, "record_mode": "observed"},
    },
```

- [ ] **Step 4: Update the observed-set assertion**

In `tests/unit/test_forward_definition.py`, the test asserting the observed set (it was `{"xsfunding", "combined"}`) must now include `multistrat_exec`. Find that test and change the expected set to `{"xsfunding", "combined", "multistrat_exec"}` (keep the assertion, update the value).

- [ ] **Step 5: Run tests → PASS + ruff, then commit**

Run: `uv run pytest tests/unit/test_registry_multistrat_exec.py tests/unit/test_forward_definition.py -q` → PASS.
Run: `uv run ruff check src/fxhnt/registry.py tests/unit/test_registry_multistrat_exec.py`

```bash
git add src/fxhnt/registry.py tests/unit/test_registry_multistrat_exec.py tests/unit/test_forward_definition.py
git commit -F - <<'EOF'
feat(exec): register multistrat_exec as an observed Alpaca-paper track (C1)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
EOF
```

---

### Task 3: `record_exec_track` — book the exec return via A's `run_track` + carry the position-state

**Files:**
- Modify: `src/fxhnt/application/multistrat_exec_record.py` (add `record_exec_track` + `_ExecBookingStrategy`)
- Test: `tests/integration/test_record_exec_track.py`

**Interfaces:**
- Consumes: `run_track` (A, `fxhnt.application.forward_engine`), `ForwardNavRepo.get_book_state`/`set_book_state`/`record_series`/`nav_history` (A), the `multistrat_exec` registry track (Task 2), Task-1 helpers.
- Produces:
  - `record_exec_track(repo, exec_return, new_positions, today_prices, envelope, today, at) -> None` — books `exec_return` as an observed `forward_record` for `multistrat_exec` via `run_track`, and stores the next position-state under book-state key `"multistrat_exec_pos"`.
  - `_ExecBookingStrategy(exec_return)` — a `ForwardStrategy` whose `advance(None, extra)` returns `[(extra["_today"], exec_return)]` (or `[]` when `exec_return is None`).

- [ ] **Step 1: Write the failing test**

```python
# tests/integration/test_record_exec_track.py
import datetime as dt

from fxhnt.adapters.persistence.forward_nav import ForwardNavRepo
from fxhnt.application.multistrat_exec_record import record_exec_track


def _repo(tmp_path):
    repo = ForwardNavRepo(f"sqlite:///{tmp_path}/x.db"); repo.migrate()
    return repo


def test_first_run_inceptions_no_return_then_books_second_day(tmp_path):
    repo = _repo(tmp_path)
    at = dt.datetime(2026, 7, 9, 23, 30)
    # run 1: exec_return None (inception) — stores position-state, books no return
    record_exec_track(repo, exec_return=None, new_positions={"SPY": 20.0},
                      today_prices={"SPY": 500.0}, envelope=10_000.0, today="2026-07-09", at=at)
    assert repo.record_series("multistrat_exec") == []                # inception: nothing booked
    assert repo.get_book_state("multistrat_exec_pos")["envelope"] == 10_000.0
    # run 2: a +2% executed day
    record_exec_track(repo, exec_return=0.02, new_positions={"SPY": 20.4},
                      today_prices={"SPY": 510.0}, envelope=10_200.0, today="2026-07-10", at=at)
    assert repo.record_series("multistrat_exec") == [("2026-07-10", 0.02)]   # observed return booked
    assert [r.date for r in repo.nav_history("multistrat_exec")] == ["2026-07-10"]  # nav derived (via run_track)
    assert repo.get_book_state("multistrat_exec_pos")["positions"] == {"SPY": 20.4}  # state advanced
```

- [ ] **Step 2: Run test to verify it fails**

Run: `uv run pytest tests/integration/test_record_exec_track.py -q`
Expected: FAIL with `ImportError: cannot import name 'record_exec_track'`.

- [ ] **Step 3: Implement `record_exec_track`**

Append to `src/fxhnt/application/multistrat_exec_record.py`:

```python
import datetime as _dt


class _ExecBookingStrategy:
    """A trivial observed ForwardStrategy for run_track: books today's pre-computed executed return (or
    nothing on the inception run). The return is computed by the CLI (it has the live prices/positions); this
    just hands it to A's observed engine."""
    def __init__(self, exec_return: float | None) -> None:
        self._r = exec_return

    def advance(self, last_date: str | None, extra: dict[str, Any]) -> tuple[list[tuple[str, float]], dict[str, Any]]:
        if self._r is None:
            return [], extra
        return [(str(extra.get("_today")), float(self._r))], extra


def record_exec_track(repo: Any, exec_return: float | None, new_positions: dict[str, float],
                      today_prices: dict[str, float], envelope: float, today: str, at: _dt.datetime) -> None:
    """Book `exec_return` as an observed forward_record for `multistrat_exec` via A's run_track (anchor +
    record + nav/summary), then carry the next run's position-state under book-state key `multistrat_exec_pos`
    (kept SEPARATE from run_track's own book_state for multistrat_exec)."""
    from fxhnt.application.forward_engine import run_track
    run_track(repo, "multistrat_exec", _ExecBookingStrategy(exec_return), today=today, at=at)
    repo.set_book_state("multistrat_exec_pos", build_pos_state(new_positions, today_prices, envelope), at=at)
```

- [ ] **Step 4: Run tests → PASS + ruff, then commit**

Run: `uv run pytest tests/integration/test_record_exec_track.py -q` → PASS.
Run: `uv run ruff check src/fxhnt/application/multistrat_exec_record.py tests/integration/test_record_exec_track.py`

```bash
git add src/fxhnt/application/multistrat_exec_record.py tests/integration/test_record_exec_track.py
git commit -F - <<'EOF'
feat(exec): record_exec_track — book the executed multistrat return via A's observed run_track (C1)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
EOF
```

---

### Task 4: Wire `execute_multistrat` — B2a envelope driver + flatten + record on `--execute`

**Files:**
- Modify: `src/fxhnt/cli.py` (`execute_multistrat`)
- Test: `tests/integration/test_execute_multistrat_b2a.py`

**Interfaces:**
- Consumes: `ForwardNavRepo.current_allocation` (B2a), `scaled_weights`/`compute_exec_return`/`record_exec_track` (Tasks 1+3), `AccountState.nlv`/`positions` (from the broker), `ExecutionService.rebalance_weights`.
- Produces: `execute_multistrat` now sizes the book to B2a's `multistrat` envelope, flattens on $0/absent, and on `--execute` records the `multistrat_exec` observed track.

- [ ] **Step 1: Write the failing test (a fake broker + repo seam)**

Add a testable seam: extract the B2a-envelope + record logic into a pure-ish function the CLI calls, so the broker/Yahoo hot path stays thin. Add to `multistrat_exec_record.py`:

```python
def plan_and_record(*, repo: Any, exec_svc: Any, within_weights: dict[str, float], prices: dict[str, float],
                    nlv: float, positions_after: dict[str, float], today: str, at: _dt.datetime,
                    max_gross: float, execute: bool) -> tuple[Any, float]:
    """Compute the B2a envelope, size the book to it (flatten on $0), reconcile via exec_svc, and on
    `execute` record the observed multistrat_exec return. Returns (plan, envelope). `exec_svc` is an
    ExecutionService; `positions_after` are the multistrat positions the broker holds AFTER the rebalance
    (for the next run's return basis — pass the current broker positions when reading them post-execute, or
    the target positions in dry-run)."""
    envelope = min(float(repo.current_allocation().get("multistrat", 0.0)), float(nlv))
    weights = scaled_weights(within_weights, envelope, nlv)
    plan = exec_svc.rebalance_weights("multistrat", weights, prices, max_gross=max_gross, execute=execute)
    if execute:
        pos_prior = repo.get_book_state("multistrat_exec_pos")
        exec_return = compute_exec_return(pos_prior, prices)
        record_exec_track(repo, exec_return, positions_after, prices, envelope, today, at)
    return plan, envelope
```

Test (`tests/integration/test_execute_multistrat_b2a.py`):

```python
import datetime as dt

from fxhnt.adapters.persistence.cockpit_models import StrategyAllocationRow
from fxhnt.adapters.persistence.forward_nav import ForwardNavRepo
from fxhnt.application.multistrat_exec_record import plan_and_record


class _FakePlan:
    def __init__(self): self.orders = []; self.notes = []; self.nlv = 100_000.0; self.blocked = False

class _FakeExecSvc:
    def __init__(self): self.last = None
    def rebalance_weights(self, name, weights, prices, *, max_gross, execute):
        self.last = dict(weights); return _FakePlan()


def _seed_alloc(repo, dollars, at):
    repo.replace_allocations([StrategyAllocationRow(
        strategy_id="multistrat", target_weight=0.5, target_dollars=dollars, policy_version=1,
        policy_hash="h", as_of="2026-07-10", computed_at=at)], at)


def test_envelope_scales_weights_and_records_on_execute(tmp_path):
    repo = ForwardNavRepo(f"sqlite:///{tmp_path}/e.db"); repo.migrate()
    at = dt.datetime(2026, 7, 10, 23, 30)
    _seed_alloc(repo, 10_000.0, at)
    svc = _FakeExecSvc()
    plan, env = plan_and_record(repo=repo, exec_svc=svc, within_weights={"SPY": 0.6, "IEF": 0.4},
                                prices={"SPY": 500.0, "IEF": 100.0}, nlv=100_000.0,
                                positions_after={"SPY": 12.0, "IEF": 40.0}, today="2026-07-10", at=at,
                                max_gross=2.0, execute=True)
    assert env == 10_000.0
    assert abs(svc.last["SPY"] - 0.06) < 1e-12                       # 0.6 * 10k/100k
    assert repo.get_book_state("multistrat_exec_pos")["envelope"] == 10_000.0   # recorded


def test_zero_allocation_flattens(tmp_path):
    repo = ForwardNavRepo(f"sqlite:///{tmp_path}/z.db"); repo.migrate()
    at = dt.datetime(2026, 7, 10, 23, 30)                            # no allocation row for multistrat
    svc = _FakeExecSvc()
    plan, env = plan_and_record(repo=repo, exec_svc=svc, within_weights={"SPY": 0.6, "IEF": 0.4},
                                prices={"SPY": 500.0, "IEF": 100.0}, nlv=100_000.0,
                                positions_after={}, today="2026-07-10", at=at, max_gross=2.0, execute=False)
    assert env == 0.0 and svc.last == {"SPY": 0.0, "IEF": 0.0}       # $0/absent → flatten
```

(Use whichever allocation-write method exists — `replace_allocations` with a `StrategyAllocationRow` is the B2a API; simplify the test's seeding to that.)

- [ ] **Step 2: Run test to verify it fails**

Run: `uv run pytest tests/integration/test_execute_multistrat_b2a.py -q`
Expected: FAIL with `ImportError: cannot import name 'plan_and_record'`.

- [ ] **Step 3: Implement `plan_and_record` (Task 4 Step 1 block) + wire the CLI**

Add `plan_and_record` to `multistrat_exec_record.py` (the block above). Then in `src/fxhnt/cli.py` `execute_multistrat`, replace the direct `ExecutionService(...).rebalance_weights(...)` call with `plan_and_record`, reading the account for `nlv`/`positions_after`:

```python
    from fxhnt.adapters.persistence.forward_nav import ForwardNavRepo
    from fxhnt.application.multistrat_exec_record import plan_and_record
    import datetime as _dt
    repo = ForwardNavRepo(settings.operational_dsn); repo.migrate()
    today = _dt.datetime.now(_dt.UTC).strftime("%Y-%m-%d")
    at = _dt.datetime.now(_dt.UTC).replace(tzinfo=None)
    try:
        with broker as brk:
            svc = ExecutionService(data, brk, settings)
            acct = brk.account_state()
            positions_after = {s: acct.positions.get(s, 0.0) for s in multistrat.FUND_INSTRUMENTS} \
                if do_execute else {}   # post-execute the broker reflects the new book; dry-run has no fills
            plan, envelope = plan_and_record(
                repo=repo, exec_svc=svc, within_weights=bweights, prices=bprices, nlv=acct.nlv,
                positions_after=positions_after, today=today, at=at, max_gross=max_gross, execute=do_execute)
    except Exception as e:
        ...  # keep the existing broker-error handling
    typer.echo(f"NLV ${plan.nlv:,.0f}  | envelope ${envelope:,.0f} (B2a) | orders {len(plan.orders)}")
    ...  # keep the existing notes/orders echo
```
(Read the current `execute_multistrat` body first — preserve the weights computation, the broker construction, the error handling, and the echo of notes/orders; only swap the rebalance call for `plan_and_record` + add the envelope to the echo. NOTE: `positions_after` on `--execute` reads the broker's CURRENT positions after placement as the next return basis — for the first execute run this seeds the inception state; the exact fill-settled positions are the honest basis.)

- [ ] **Step 4: Run tests + full suite + ruff, then commit**

Run: `uv run pytest tests/integration/test_execute_multistrat_b2a.py -q` → PASS.
Run the FULL suite ONCE (touches the CLI + registry): `uv run pytest -q` → PASS. (Ensure no other pytest is running first — concurrent full-suite runs SIGTERM each other.)
Run: `uv run ruff check src/fxhnt/cli.py src/fxhnt/application/multistrat_exec_record.py tests/integration/test_execute_multistrat_b2a.py`

```bash
git add src/fxhnt/cli.py src/fxhnt/application/multistrat_exec_record.py tests/integration/test_execute_multistrat_b2a.py
git commit -F - <<'EOF'
feat(exec): execute-multistrat is B2a-driven — deploy the envelope, flatten on $0, record the exec track (C1)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
EOF
```

---

## Self-Review notes

- **Spec coverage:** bridge/envelope (§1)→T1 `scaled_weights` + T4 `plan_and_record`; reconcile reuse (§2)→T4 (existing ExecutionService); fills→observed record (§3)→T1 `compute_exec_return` + T3 `record_exec_track` (via A's run_track); registry track (§4)→T2; shape+safety (§5)→T4 (CLI + existing gates + dry-run default). Flatten-on-$0→T1/T4; envelope-basis + flow-excluded invariants→T1 tests.
- **Load-bearing invariants tested:** `test_exec_return_is_envelope_basis_not_full_nlv` + `test_reallocation_capital_flow_is_not_return` (T1) pin the two correctness properties.
- **Reuse, no new engine:** `plan_and_record` calls the existing `ExecutionService.rebalance_weights`; `record_exec_track` calls A's `run_track`; no new order engine or return store. The position-state lives in A's book-state under `multistrat_exec_pos` (separate from run_track's own `multistrat_exec` book_state).
- **No capital authorized:** the CLI keeps the existing `--live`/`allow_live` gate; dry-run default; paper only. `plan_and_record` records only on `execute=True`.
- **Type consistency:** `scaled_weights`/`compute_exec_return`/`build_pos_state` (T1) are consumed by `record_exec_track`/`plan_and_record` (T3/T4); `run_track(repo, "multistrat_exec", strategy, today, at)` matches A's signature; the registry `multistrat_exec` (T2) is what `run_track` resolves via `track_definition`.
