Files
trex-core/docs/batches/bat-012_20260607_kill-switch-control/implementation.md
T

3.8 KiB

BAT-012 Implementation

  • Status: completed
  • Batch: BAT-012

Plan Summary

  • 구현 순서(planning Delivery Plan): REQ-044 store/마이그레이션 → REQ-043 제어 채널/dispatch → REQ-045 kill_switch 실행 → REQ-046 masking/resume → REQ-047 baseline 정합. 각 단계 unit test green 후 진행.

Changed Files

  • (구현 시 기록)

신규 파일 (예정)

  • trex_core/adapters/persistence/sql/005_create_killswitch_exclusion.sql (REQ-044)
  • trex_core/adapters/portfolio/killswitch_store.py — PostgreSQLKillSwitchStore (REQ-044)
  • trex_core/application/killswitch.py — 범위별 holding 순차 sell() 진입점 (REQ-045)
  • tests/adapters/portfolio/test_killswitch_store.py (REQ-044)
  • tests/application/test_control_dispatch.py (REQ-043)
  • tests/application/test_killswitch_execution.py (REQ-045)
  • tests/application/test_killswitch_masking_resume.py (REQ-046)

기존 파일 수정 (예정)

  • trex_core/adapters/messaging/topology.py — CONTROL_REQ_QUEUE (REQ-043)
  • trex_core/application/messaging_handlers.py — make_control_rpc_handler + kill_switch/resume_kill_switch (REQ-043/045/046)
  • trex_core/application/portfolio.py — masking 소스 확장 (REQ-046)
  • trex_core/runtime/daemon.py — control consumer 전환 + killswitch_store 배선 (REQ-043/045/046)
  • docs/interface-contract.md, docs/runtime-flows.md, docs/project-structure.md (REQ-047)

Changed Files (실제)

  • 신규: sql/005_create_killswitch_exclusion.sql, adapters/portfolio/killswitch_store.py(PostgreSQLKillSwitchStore), application/killswitch.py(KillSwitchService), 테스트 4개(test_killswitch_store / test_control_dispatch / test_killswitch_execution / test_killswitch_masking_resume).
  • 수정: adapters/messaging/topology.py(CONTROL_REQ_QUEUE), adapters/messaging/rabbitmq.py(control 큐 declare), application/portfolio.py(GLOBAL_KILLSWITCH + KillSwitchStore Protocol + InMemoryKillSwitchStore + envelope masking), application/messaging_handlers.py(make_control_rpc_handler + kill_switch/resume_kill_switch + snapshot handler killswitch_store), runtime/daemon.py(control consumer 전환 + KillSwitchService + killswitch_store 배선), tests/conftest.py(killswitch_exclusion truncate), baseline 3문서(REQ-047).

Execution Log

  1. REQ-044 store + 005 마이그레이션 → 단위 5 passed(PG 5 gated).
  2. REQ-045 KillSwitchService → 단위 6 passed.
  3. REQ-043 control dispatch(topology+handler+daemon) → 단위 9 passed, import/회귀 green.
  4. REQ-046 masking + resume → 단위 6 passed.
  5. REQ-047 baseline 3문서 정합.
  6. 전체 회귀: 단위 262 passed / 28 skipped, ruff clean.
  7. 인프라 게이트(PG+RabbitMQ): 290 passed(마이그레이션 001~005 + killswitch PG round-trip 포함).
  8. paper 데몬 e2e(control RPC): buy 2 → kill_switch global(liquidated=2) → 양쪽 holding→pending_sell(emergency_stop)→closed, killswitch_exclusion=[('*',2026-06-07)] → resume_kill_switch global → exclusion 0. PASS.

Validation

  • 단위: pytest -q --deselect ...::test_sandbox_token_and_submit → 262 passed / 28 skipped.
  • 인프라 게이트: TREX_RABBITMQ_TEST_URL=... TREX_POSTGRESQL_TEST_DSN=...(trex_core_test) pytest -q → 290 passed.
  • lint: ruff check trex_core tests → All passed.
  • e2e: 위 8 (paper 데몬 control RPC kill_switch/resume).

Remaining Risks

  • R-1(제어 큐 rename 하위호환): control.req 단일화 구현. 기존 trex.pause.req 사용 RPC 클라이언트 이전은 release rollout 결정(REQ-043 Notes). CLI 무영향.
  • R-5 해소: 005 실 PG round-trip = 인프라 게이트 290 passed(killswitch PG 테스트 green).
  • (이월) 실 KIS LIVE kill_switch 발동→실매도 제출→에러 관찰은 차기 거래일 운영 실증(safety-sell LIVE 선례). paper/mock 으로 충분 검증.