Files
trex-core/docs/batches/bat-035_20260611_strategy-read-surface-slots-req/design.md
T
genichinandClaude Opus 4.8 f0ad37747b feat(rel-007): dcy-025/024 + BAT-035/036 — slots.req 즉시 교체 + safety_sell_enabled
BAT-035 (dcy-025): trex.snapshot.req → trex.slots.req 즉시 교체
- topology: SNAPSHOT_REQ_QUEUE 제거, SLOTS_REQ_QUEUE = "trex.slots.req" 추가
- portfolio.py: View/build_snapshot_envelope/SnapshotEnvelope/_asset_to_dict 제거;
  slot_to_dict 시그니처 확장(snapshot_store/watchdog_store/pause_store/watchdog_timeout_sec)
  — asset_quantity(hub)/cash_balance/cash_estimated/warned/watchdog{}/paused 병합 (REQ-074)
- messaging_handlers.py: make_snapshot_rpc_handler 제거, make_slots_rpc_handler 추가
  — filter(all/inactive/pending/holding/error) + spy(bool) 처리; strategy 필드 제외 (REQ-073/074)
- daemon.py: _snapshot_rpc_loop → _slots_rpc_loop, make_slots_rpc_handler 연결
- cli.py: universe/slots → slots_queue + spy=True + server-side filter; buyable→inactive 매핑 (REQ-063)
- rabbitmq.py: snapshot_queue → slots_queue
- docs: interface-contract.md + runtime-flows.md slots.req 계약으로 업데이트 (REQ-075)
- REQ-028: Implemented → Deprecated (코드 삭제 완료)
- 테스트: test_snapshot_handler/selection/rpc_watchdog/messaging_snapshot_consumer 삭제;
  test_slots_handler.py(신규, 13 cases), test_killswitch_masking_resume 재작성,
  test_ledger_option_d._apply_cash_estimate → slots handler 경유, test_topology/cli_operator 갱신

BAT-036 (dcy-024): per-instance safety_sell_enabled 플래그
- config.py: DaemonInstanceConfig + DaemonConfig 에 safety_sell_enabled: bool = True 추가;
  from_toml 파싱, from_config 전파
- daemon.py: start() workers 조건부 — safety_sell_enabled=false 시 trex-safety-sell 미기동 + WARNING
- tests: test_instance_config.py 에 safety_sell_enabled 파싱 3개 케이스 추가

REQ: 073/074/075/021/034/063/048/005 Approved → Implemented

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-11 14:45:45 +09:00

4.0 KiB

BAT-035 Design

  • Status: confirmed
  • Batch: BAT-035

Architecture Summary

  • trex.snapshot.req RPC 파이프라인(큐 선언·핸들러·View enum·assets[]/available_slots/watchdog[] 구조)을 제거하고 trex.slots.req 단일 RPC로 즉시 교체한다.
  • 슬롯 행(slot_to_dict)이 자산·워치독·overlay를 흡수해 소비자 측 배열 조인을 없앤다.
  • 변경은 topology → messaging_handlers → portfolio → CLI 레이어 순으로 안쪽부터 바깥으로 진행한다.

Changed Areas

  • Docs: docs/interface-contract.md (snapshot→slots 계약 교체 + 필드별 정본 출처 표), docs/runtime-flows.md (read 흐름 교체)
  • Modules:
    • trex_core/adapters/messaging/topology.py — SNAPSHOT_REQ_QUEUE → SLOTS_REQ_QUEUE, snapshot_queue() → slots_queue()
    • trex_core/application/messaging_handlers.py — make_slots_rpc_handler 신설, make_snapshot_rpc_handler 제거, _attach_watchdog 제거
    • trex_core/application/portfolio.py — slot_to_dict 확장, View enum 제거, build_snapshot_envelope 제거
    • CLI 모듈 — slots.req 사용, spy=true, filter 매핑
  • Tests:
    • tests/adapters/messaging/ — topology 단언
    • tests/application/ — slots 핸들러·slot_to_dict·divergence·overlay

Key Decisions

  1. 즉시 교체(lockstep): snapshot.req 큐·핸들러·legacy stub 경로를 같은 커밋에서 제거한다. 전략 모듈(trex-orb-v1)은 배포 전 lockstep 대응 완료 상태여야 한다(REQ-073, dcy-025 OQ-1).

  2. slot_to_dict 서명 확장: slot_to_dict(s, *, snapshot_store=None, watchdog_store=None, pause_store=None) → dict. snapshot_store 없으면 asset_quantity=None, cash_balance=None, cash_estimated=False; watchdog_store 없으면 watchdog=None; pause_store 없으면 paused=False. None 필드는 응답에 그대로 포함(소비자가 구분 가능).

  3. warned 계산: warned = (slot.qty != asset_quantity). asset_quantity가 None(snapshot 미연결)이면 warned=False(불확정, 조용히 처리). slot.qty는 슬롯 미러 값.

  4. watchdog 행 흡수: watchdog: {expired: bool, last_seen: str|null}. watchdog_store.get(slot_id) → WatchdogEntry(last_seen_at, timeout_sec). expired = (now - last_seen_at) > timeout_sec (또는 last_seen_at is None). WatchdogStore None 이면 watchdog 필드 전체 None.

  5. filter 분기: filter → {all: 전체, inactive: status==inactive, pending: status in (pending_buy, pending_sell), holding: status==holding, error: status==error}. 미지정/null/"all" = 전체. 미지정 값은 all로 처리(조용히).

  6. spy 분기: spy=true → holding 슬롯 워치독 미터치. spy=false or 미지정 → holding 슬롯 watchdog.update(). REQ-034 CHG-01 시맨틱.

  7. View enum 제거: portfolio.py:65의 class View(str, Enum) 전체 제거. 호출 지점(build_snapshot_envelope, CLI) 정리.

  8. build_snapshot_envelope 제거: portfolio.py:340의 build_snapshot_envelope 함수 전체 제거. messaging_handlers.py 의 snapshot 경로(221~244) 같이 제거.

  9. REQ-028 Deprecated 전환: 이번 배치에서 snapshot.req 코드가 제거되면 REQ-028 상태를 Implemented→Deprecated로 전환한다.

Edge Cases

  • asset_quantity(hub) = 0 이고 qty(slot) = 0 → warned=False (정상 일치)
  • asset_quantity(hub) = 0 이고 qty(slot) = 1 → warned=True (divergence)
  • snapshot_store 미연결(degraded) → asset_quantity=None, cash_balance=None, cash_estimated=False, degraded=true
  • spy=true 요청인데 holding 슬롯 없음 → watchdog 터치 없음, 정상 반환
  • invalid filter 값("buyable" 등) → all 처리 (하위호환, CLI 매핑은 상위 계층에서 처리)

Architecture Impact

  • runtime-flows: yes (snapshot → slots 흐름 교체)
  • project-structure: no (파일 추가 없음, 기존 파일 수정)

Reference Doc Update Plan

  • docs/interface-contract.md: snapshot 섹션 제거 → slots.req 계약 + 필드별 정본 출처 표 추가 (REQ-075 AC-1)
  • docs/runtime-flows.md: read 흐름 snapshot→slots 교체 (REQ-075 AC-2)