Files
trex-core/docs/batches/bat-036_20260611_safety-sell-disable-mode/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

2.4 KiB

BAT-036 Design

  • Status: confirmed
  • Batch: BAT-036

Architecture Summary

  • DaemonInstanceConfig에 safety_sell_enabled: bool = True 필드를 추가하고 per-instance TOML 파싱 경로(from_toml)와 DaemonConfig.from_config() 전파 경로를 업데이트한다.
  • Daemon.start() 내부 workers 리스트 구성 시 safety_sell_enabled 값을 체크해 False이면 ("trex-safety-sell", self._safety_sell_loop) 항목을 포함하지 않는다.

Changed Areas

  • Docs: 없음 (docs 변경 없음)
  • Modules:
    • trex_core/runtime/config.py — DaemonInstanceConfig 필드 + from_toml + from_config 전파
    • trex_core/runtime/daemon.py — start() workers 분기
  • Tests:
    • config 파싱 단위 테스트
    • daemon workers 구성 테스트

Key Decisions

  1. absent=true 기본값: from_toml() 내 data.get("safety_sell_enabled", True). TOML 키 부재 시 True → 기존 배포 동작 보존.

  2. DaemonConfig 전파 경로: DaemonConfig.from_config() → DaemonInstanceConfig.from_toml() → DaemonInstanceConfig.safety_sell_enabled → DaemonConfig 생성자 또는 속성으로 전달. Daemon.__init__ 에서 self._config.safety_sell_enabled 로 참조.

  3. workers 조건 분기 위치: daemon.py:328 workers 리스트 구성 블록 내, ("trex-safety-sell", self._safety_sell_loop) 항목을 조건부로 append. 리스트 구성 후 순회 루프(for name, target in workers:)는 변경 없음.

  4. 로그 메시지: logger.warning("safety_sell disabled — trex-safety-sell worker not started. Autonomous safety-sell will NOT run."). RUNNING 로그(기존)로 전체 워커 시작 상태를 가시화.

  5. AC-6 보존: _safety_sell_loop 제거가 아닌 workers 리스트 미포함. Daemon._safety_sell_loop 메서드 자체는 삭제하지 않는다(CLI exit/cancel/kill-switch 독립 경로는 이 메서드를 직접 호출하지 않으므로 무관).

Edge Cases

  • safety_sell_enabled=True (기본): workers에 포함, 기존 동작과 동일
  • safety_sell_enabled=False: workers에 미포함, 경고 로그, 나머지 워커 영향 없음
  • TOML 키 오타(예: "safety_sell_enable"): get() 기본값 True 처리 → 활성화(안전한 방향)

Architecture Impact

  • runtime-flows: no (daemon 기동 흐름만 경미하게 변경, 문서 갱신 불필요)
  • project-structure: no

Reference Doc Update Plan

  • docs/interface-contract.md: 없음
  • docs/runtime-flows.md: 없음