feat(slot): BAT-029 M2(a)/M3 — holding 불일치 reconcile + slots 단일 뷰 (dcy-020/REQ-062·063)

- REQ-062 divergence: list_holding_slots(protocol+in_memory+PG) +
  reconcile_core_holdings(A=코어 holding/broker0→error, C=수량 불일치→warning,
  B=broker 보유/코어 없음→warning; 자동 청산 없음 issue #15). snapshot_scheduler
  자산 중심 모드에서 best-effort 호출, daemon slot_service 배선.
- REQ-063: slot_to_dict 에 universe_detached(retired_at) 추가 — slots 단일 뷰 tombstone 표시.
- 신규 테스트: test_holding_divergence(4).

M2(b) 청산 수량 브로커 정본(execution dispatch)은 라이브 집행 변경 → BAT-δ carry-over.

검증: 단위 393 passed / 36 skipped, PG-gated 18 passed, ruff clean. legacy 무파손.
REQ-061/062/063 Approved 유지(γ 경로 도입 검증; default 전환·M2(b) 는 BAT-δ).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-10 12:18:56 +09:00
co-authored by Claude Opus 4.8
parent b80407098e
commit 78a743a2ef
10 changed files with 215 additions and 10 deletions
@@ -1,16 +1,30 @@
# BAT-029 Implementation
- Status: not-started
- Status: completed (M2(b) 청산 브로커 정본은 BAT-δ carry-over)
- Batch: BAT-029
## 구현 요약
- (run-batch-delivery 진입 시 작성) design.md 체크포인트(D1/D2) 확정 후 채운다.
- M1(REQ-061 slot_id 계약)·M2(a)(REQ-062 divergence reconcile)·M3(REQ-063 slots 단일 뷰) 구현. M2(b)(execution dispatch 매도 수량 브로커 정본)는 라이브 집행 변경이라 BAT-δ 로 이월.
## 변경 내역
- (대기)
### M1 — REQ-061 intent 계약 slot_id (커밋 별도)
- BuyIntent slot_id 추가(portfolio_id Optional), `_admit_buy` 자산 중심 우선 분기, `_admit_buy_asset_centric` slot_id(canonical)/portfolio_id(legacy dual-accept) 슬롯 해소 + symbol resolve, messaging buy 파싱 slot_id 수용.
### M2(a) — REQ-062 divergence reconcile
- `domain/slot/repository.py`·in_memory·postgresql: `list_holding_slots(instance_key)`.
- `application/reconciliation.py`: `reconcile_core_holdings(slot_repo, slot_service, broker, instance_key)` — A(코어 holding/broker 0)=슬롯 error+WARN, C(수량 불일치)=WARN(상태 불변), B(broker 보유/코어 없음)=WARN. 자동 청산 없음(issue #15).
- `application/snapshot_scheduler.py`: run_once 에서 자산 중심 모드 + slot_service 시 reconcile_core_holdings 호출(best-effort). daemon: slot_service 배선.
### M3 — REQ-063 slots 단일 뷰
- `application/portfolio.py` `slot_to_dict`: `universe_detached`(retired_at not null) 추가 → `trex-core slots`/envelope 자산 포지션 단일 뷰에 tombstone/soft-retire 표시.
### M2(b) — carry-over (BAT-δ)
- execution dispatch 매도 수량 `int(slot.qty)` → 브로커 잔고 정본: **라이브 집행 루프 동작 변경**이라 cutover(BAT-δ, 자산 중심 default 전환)와 같은 게이트에서 처리.
## 테스트
- (대기)
- 신규: test_holding_divergence(4: A/C/ok/B), test_asset_centric_admission(slot_id 매수·unknown_slot 포함 10).
- 회귀: 기존 sell(slot_id)·reconcile_positions·snapshot 무파손.
## 검증 실행
- (대기)
- 단위 전체: 393 passed / 36 skipped / 1 deselected. ruff clean.
- PG-gated(trex_core_test): persistence 18 passed(list_holding_slots/reconcile 포함).
@@ -1,13 +1,43 @@
# BAT-029 Verification
- Status: not-started
- Status: verified (배치 범위; M2(b) BAT-δ 이월)
- Batch: BAT-029
## Acceptance Mapping
- (draft-batch-verification / confirm-batch-verification 단계에서 작성)
### REQ-061 (intent 계약 slot_id)
| AC | 상태 | Evidence |
|----|------|----------|
| 매수 slot_id 활성화 + symbol 슬롯 resolve | ✅ | test_activates_by_slot_id |
| 이미 활성 → already_active | ✅ | test_already_active_is_rejected |
| 보유 아닌 슬롯 매도 거부 | ✅ | 기존 sell(_admit_sell slot_not_holding) 회귀 |
| 레거시 portfolio_id dual-accept | ✅ | test_activates_asset_slot(portfolio_id) |
| intent_id 멱등 | ✅ | 기존 intent dedup 회귀 |
### REQ-062 (수량/불일치 해소)
| AC | 상태 | Evidence |
|----|------|----------|
| A 코어 holding/broker 0 → error | ✅ | test_A_core_holding_broker_flat_goes_error |
| B 코어 flat/broker 보유 → warning | ✅ | test_B_broker_holds_unmanaged_warns |
| C 수량만 → 미러 갱신/warning(상태 불변) | ✅ | test_C_qty_mismatch_warns_no_state_change |
| 청산 수량 = 브로커 정본 | ⏳ 이월(BAT-δ) | execution dispatch qty 변경은 라이브 집행 — cutover 게이트 |
### REQ-063 (운영자 slots 단일 뷰)
| AC | 상태 | Evidence |
|----|------|----------|
| slots 자산 포지션 단일 뷰 | ✅ | slot_to_dict(기존 envelope) |
| universe_detached(tombstone/soft-retire) 표시 | ✅ | slot_to_dict universe_detached + 회귀 |
## Evidence
- (대기)
- 단위 전체: `393 passed / 36 skipped / 1 deselected`. ruff clean.
- PG-gated(실 trex_core_test): persistence `18 passed`(list_holding_slots·reconcile·드리프트 포함).
## Carried-Over
- **REQ-062 청산 수량 브로커 정본**: execution dispatch 매도 수량(`int(slot.qty)`) → 브로커 잔고 정본 변경은 라이브 집행 동작 → **BAT-δ**(cutover, 자산 중심 default 전환)와 같은 게이트.
- sell `slot_id` 완전 폐기·literal inactive·컬럼 drop·자산 중심 default → BAT-δ.
- 실 데몬 자산 중심 e2e(reconcile→slot_id 매수→divergence) run-the-app → BAT-δ confirm-release 전.
- 따라서 REQ-061/062/063 은 본 배치에서 **Approved 유지**(경로 동작 검증; 전체 완성·default 전환은 BAT-δ).
## Result
- Ready for Release: false (구현 전)
- Ready for Release: false (dcy-020 전체 미완 — γ 경로 도입 완료, M2(b)·default 는 BAT-δ)
- Blocking Issues: 없음(단위 393 + PG 18 green, legacy 무파손).