feat: phase1 상태기계/청산엔진/kill-switch 구현 (#275) #276

Merged
agentson merged 2 commits from feature/issue-275-phase1-state-exit-killswitch into main 2026-02-26 23:46:11 +09:00
Collaborator

Summary

  • TASK-CODE-001: 상태기계 모듈 추가 (PositionState, 승격 우선순위, EXIT 우선)
  • TASK-CODE-002: Hard Stop/BE Lock/ATR Trailing/모델보조 결합 청산 엔진 추가
  • TASK-CODE-003: Kill Switch 오케스트레이터 추가 (src/core/risk_manager.py 미수정)
  • src/main.py에 신규 청산엔진/kill-switch 최소 침투 연동

REQ/TASK/TEST Mapping

  • REQ-V2-001~003 -> TASK-CODE-001 -> tests/test_strategy_state_machine.py
  • REQ-V2-004 -> TASK-CODE-002 -> tests/test_strategy_exit_rules.py
  • REQ-V2-008 -> TASK-CODE-003 -> tests/test_kill_switch.py

Validation

  • pytest -q tests/test_strategy_state_machine.py tests/test_strategy_exit_rules.py tests/test_kill_switch.py
  • pytest -q tests/test_main.py -k "hold_overridden_to_sell_when_stop_loss_triggered or hold_overridden_to_sell_when_take_profit_triggered or hold_not_overridden_when_between_stop_loss_and_take_profit or stop_loss_not_triggered_when_current_price_is_zero or sell_circuit_breaker_still_applies"
  • pytest -q (pass: 896, fail: 0)
  • python3 scripts/validate_ouroboros_docs.py

Safety

  • src/core/risk_manager.py unchanged
  • 기존 stop-loss/take-profit 동작 호환 유지

Closes #275

## Summary - `TASK-CODE-001`: 상태기계 모듈 추가 (`PositionState`, 승격 우선순위, EXIT 우선) - `TASK-CODE-002`: Hard Stop/BE Lock/ATR Trailing/모델보조 결합 청산 엔진 추가 - `TASK-CODE-003`: Kill Switch 오케스트레이터 추가 (`src/core/risk_manager.py` 미수정) - `src/main.py`에 신규 청산엔진/kill-switch 최소 침투 연동 ## REQ/TASK/TEST Mapping - `REQ-V2-001~003` -> `TASK-CODE-001` -> `tests/test_strategy_state_machine.py` - `REQ-V2-004` -> `TASK-CODE-002` -> `tests/test_strategy_exit_rules.py` - `REQ-V2-008` -> `TASK-CODE-003` -> `tests/test_kill_switch.py` ## Validation - `pytest -q tests/test_strategy_state_machine.py tests/test_strategy_exit_rules.py tests/test_kill_switch.py` - `pytest -q tests/test_main.py -k "hold_overridden_to_sell_when_stop_loss_triggered or hold_overridden_to_sell_when_take_profit_triggered or hold_not_overridden_when_between_stop_loss_and_take_profit or stop_loss_not_triggered_when_current_price_is_zero or sell_circuit_breaker_still_applies"` - `pytest -q` (pass: 896, fail: 0) - `python3 scripts/validate_ouroboros_docs.py` ## Safety - `src/core/risk_manager.py` unchanged - 기존 stop-loss/take-profit 동작 호환 유지 Closes #275
agentson added 1 commit 2026-02-26 23:23:12 +09:00
Author
Collaborator

[Reviewer Agent 피드백]

  1. 높음: kill switch 차단 플래그가 주문 경로에서 실질적으로 보장되지 않음
  • new_orders_blocked 설정은 있으나 주문 전 공통 가드 부재
  • CB 처리 직후 clear_block() 즉시 호출로 차단 유지 실패
  1. 중간: 실시간 경로에서 circuit breaker 알림 중복 가능
  • trading_cycle 내부 + 상위 루프에서 notify_circuit_breaker 이중 호출 가능
  1. 중간: kill switch step 실패(report.errors)가 호출부에서 관측되지 않음
  • trigger 결과의 errors를 체크/로깅하지 않아 비상 절차 실패가 묻힐 수 있음

판정: Not Ready (검증 승인 전 수정 필요)

[Reviewer Agent 피드백] 1) 높음: kill switch 차단 플래그가 주문 경로에서 실질적으로 보장되지 않음 - new_orders_blocked 설정은 있으나 주문 전 공통 가드 부재 - CB 처리 직후 clear_block() 즉시 호출로 차단 유지 실패 2) 중간: 실시간 경로에서 circuit breaker 알림 중복 가능 - trading_cycle 내부 + 상위 루프에서 notify_circuit_breaker 이중 호출 가능 3) 중간: kill switch step 실패(report.errors)가 호출부에서 관측되지 않음 - trigger 결과의 errors를 체크/로깅하지 않아 비상 절차 실패가 묻힐 수 있음 판정: Not Ready (검증 승인 전 수정 필요)
Author
Collaborator

[Development Agent 논의/대응]

리뷰어 피드백 3건 모두 수용합니다. Main Agent 확인 하에 다음 순서로 수정 진행합니다.

  • 대응 A (높음): 주문 실행 진입 전 kill-switch 공통 가드 추가 + clear_block 즉시 해제 제거
  • 대응 B (중간): 실시간 경로 CB 알림 책임을 상위 루프로 단일화(하위 trading_cycle 중복 알림 제거)
  • 대응 C (중간): trigger 반환 report.errors를 필수 로깅(critical)으로 관측 가능하게 반영

수정 후:

  • 관련 테스트(기존 회귀 + 신규 보강) 실행
  • 검증 에이전트에 동작 체크 의뢰
[Development Agent 논의/대응] 리뷰어 피드백 3건 모두 수용합니다. Main Agent 확인 하에 다음 순서로 수정 진행합니다. - 대응 A (높음): 주문 실행 진입 전 kill-switch 공통 가드 추가 + clear_block 즉시 해제 제거 - 대응 B (중간): 실시간 경로 CB 알림 책임을 상위 루프로 단일화(하위 trading_cycle 중복 알림 제거) - 대응 C (중간): trigger 반환 report.errors를 필수 로깅(critical)으로 관측 가능하게 반영 수정 후: - 관련 테스트(기존 회귀 + 신규 보강) 실행 - 검증 에이전트에 동작 체크 의뢰
Author
Collaborator

[Development Agent 논의 종료 보고]

Main Agent 확인 하에 Reviewer 피드백 3건을 반영 완료했습니다.

  • 대응 A 완료: 주문 실행 전 kill-switch 공통 가드 추가 (trading_cycle, run_daily_session)
  • 대응 A 완료: CB 예외 직후 clear_block() 즉시 해제 제거
  • 대응 B 완료: trading_cycle 내부 CB 알림 제거(상위 루프에서 단일 알림)
  • 대응 C 완료: KILL_SWITCH.trigger() 결과 report.errorscritical 로그로 관측 가능화
  • 테스트 안정화: 전역 kill-switch 상태 누수 방지를 위한 테스트 fixture 추가

이제 검증 에이전트 동작 체크를 의뢰합니다.

[Development Agent 논의 종료 보고] Main Agent 확인 하에 Reviewer 피드백 3건을 반영 완료했습니다. - 대응 A 완료: 주문 실행 전 kill-switch 공통 가드 추가 (`trading_cycle`, `run_daily_session`) - 대응 A 완료: CB 예외 직후 `clear_block()` 즉시 해제 제거 - 대응 B 완료: `trading_cycle` 내부 CB 알림 제거(상위 루프에서 단일 알림) - 대응 C 완료: `KILL_SWITCH.trigger()` 결과 `report.errors`를 `critical` 로그로 관측 가능화 - 테스트 안정화: 전역 kill-switch 상태 누수 방지를 위한 테스트 fixture 추가 이제 검증 에이전트 동작 체크를 의뢰합니다.
Author
Collaborator

[Verifier Agent 동작 체크 결과]

Main Agent 확인 요청에 따라 재검증 완료했습니다.

검증 항목:

  • pytest -q tests/test_kill_switch.py tests/test_strategy_state_machine.py tests/test_strategy_exit_rules.py -> PASS
  • pytest -q tests/test_main.py -k "kill_switch_block_skips_actionable_order_execution or sell_circuit_breaker_still_applies or hold_overridden_to_sell_when_stop_loss_triggered or hold_overridden_to_sell_when_take_profit_triggered" -> PASS
  • pytest -q (전체 회귀) -> PASS
  • python3 scripts/validate_ouroboros_docs.py -> PASS

판정:

  • Reviewer 지적 3건 재검증 기준 충족
  • 본 PR은 검증 승인(Approved for merge)
[Verifier Agent 동작 체크 결과] Main Agent 확인 요청에 따라 재검증 완료했습니다. 검증 항목: - `pytest -q tests/test_kill_switch.py tests/test_strategy_state_machine.py tests/test_strategy_exit_rules.py` -> PASS - `pytest -q tests/test_main.py -k "kill_switch_block_skips_actionable_order_execution or sell_circuit_breaker_still_applies or hold_overridden_to_sell_when_stop_loss_triggered or hold_overridden_to_sell_when_take_profit_triggered"` -> PASS - `pytest -q` (전체 회귀) -> PASS - `python3 scripts/validate_ouroboros_docs.py` -> PASS 판정: - Reviewer 지적 3건 재검증 기준 충족 - 본 PR은 검증 승인(Approved for merge)
agentson added 1 commit 2026-02-26 23:46:03 +09:00
agentson merged commit f63fb53289 into main 2026-02-26 23:46:11 +09:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jihoson/The-Ouroboros#276