virtual-insanity
← 리포트 목록

oil_supply_monitor 뉴스 인텔리전스 timeout/cache/skip 보강

2026-04-24 news [oil-supply-monitor, news-intel, timeout, cache, skip-news]

Executive Summary

  • 지연 구간은 collect_raw_data() 내부 외부 뉴스/web 단계였다: realtime feed → ref URL Scrapling → 신문사 도메인 탐색 → 가격/수급 web_search → Twitter 보완 → 40개 안팎 뉴스 쿼리.
  • --skip-news / NEWS_SKIP=1, 24h news cache, 단계 timeout, per-query websearch timeout을 추가했다.
  • 검증 결과: timeout run은 뉴스 단계에서 graceful fallback 후 완료했고, skip mode는 뉴스 외부 fetch를 생략해 가격·snapshot 산출이 정상 완료됐다.

1. 식별 결과

주요 호출 경로:

  • main()collect_raw_data()
  • collect_raw_data() 내부 외부 fetch:
  • collect_realtime_feeds()
  • collect_news_scrapling()
  • collect_source_domain_news() / fetch_article_extras()
  • _PRICE_QUERIES websearch 10건
  • collect_twitter_hormuz()
  • _NEWS_QUERIES websearch/search_and_fetch 40건 안팎
  • main()extract_news_intel() LLM 구조화

로그 기준:

  • 기존 리스크: 사용자 관찰 기준 백그라운드 11분+ 사례.
  • 패치 중 재현: 정상 뉴스 run이 뉴스 인텔리전스 (웹)에서 timeout까지 대기했고, 전체 dry-run은 306초 소요.
  • 1차 skip 테스트는 외부 realtime feed가 남아 있어 109초 소요.
  • 최종 skip 테스트는 realtime/ref URL/web_search를 모두 스킵해 62초 소요. 남은 시간은 yfinance, 로컬 볼트, LLM 지표 추출, 선물 커브/차트 생성 쪽이다.

2. 수정 내역

백업:

  • /Users/ron/.hermes/workspace/scripts/pipeline/oil_supply_monitor.py.bak-news-timeout-cache-20260424

수정 파일:

  • /Users/ron/.hermes/workspace/scripts/pipeline/oil_supply_monitor.py

추가 기능:

  1. skip flag
  2. CLI: --skip-news
  3. ENV: NEWS_SKIP=1
  4. skip 시 생략:

    • realtime feed 외부 fetch
    • ref URL Scrapling
    • 신문사 도메인 fetch
    • 가격/수급 web_search
    • Twitter 보완 web_search
    • 뉴스 인텔리전스 web_search
    • 캐시 없을 때 LLM 뉴스 구조화
  5. 단계 timeout

  6. CLI: --news-timeout N
  7. ENV: NEWS_TIMEOUT_SEC=N
  8. 기본값: 120초
  9. timeout 시:

    • 24h cache 있으면 stale/cache fallback
    • cache 없으면 _news_fetch_missing=True, _news_cache_status=timeout_no_cache 기록
    • 가격·snapshot critical path는 계속 진행
  10. per-query timeout

  11. ENV: WEBSEARCH_TIMEOUT_SEC, 기본 8초
  12. ENV: WEBSEARCH_DELAY_SEC, 기본 0.2초
  13. shared web_search가 hang되어 전체 뉴스 단계가 붙잡히는 문제를 완화.

  14. 24h cache

  15. URL cache TTL: 1h → 24h
  16. news phase cache 경로:
    • /Users/ron/.hermes/workspace/memory/news_cache/oil_supply_monitor_web_raw.json
  17. cache hit 시 뉴스/웹 검색 24h 캐시 hit 로그 출력.

3. 검증 결과

3.1 구문 검사

python3 -m py_compile scripts/pipeline/oil_supply_monitor.py → 통과

3.2 timeout graceful fallback

명령 요약:

python3.11 oil_supply_monitor.py --dry-run --news-timeout 120

결과:

뉴스 인텔리전스 (웹)
⚠️ 뉴스/웹 검색 timeout: oil news web phase timeout after 120s
완료. state: /Users/ron/.hermes/workspace/memory/oil-supply-monitor/state.json
  • 전체 dry-run: 306초
  • exit code: 0
  • 뉴스 timeout 후에도 가격·snapshot·state 저장 완료.

3.3 skip mode

명령 요약:

python3.11 oil_supply_monitor.py --dry-run --skip-news

결과:

실시간 피드 스킵 (skip-news)
볼트 ref URL/신문사 외부 fetch 스킵 (skip-news)
뉴스/웹 검색 스킵 (--skip-news 또는 NEWS_SKIP=1)
뉴스 인텔리전스 스킵: NEWS_SKIP/--skip-news, 캐시 없음
완료. state: /Users/ron/.hermes/workspace/memory/oil-supply-monitor/state.json
  • Before: skip 옵션이 있어도 realtime 외부 fetch가 남아 109초.
  • After: realtime/ref/web_search까지 스킵되어 62초.
  • 가격·snapshot 산출 정상.

3.4 cache / timeout unit 검증

직접 helper 검증:

websearch_skip [검색 스킵: NEWS_SKIP=1]
timeout_ok _NewsPhaseTimeout
cache abc hit

생산 news cache도 생성 확인했다: /Users/ron/.hermes/workspace/memory/news_cache/oil_supply_monitor_web_raw.json (62개 key, 4.9KB). timeout/no-cache 상황에서는 부정확한 빈 캐시를 만들지 않도록 했다.

3.5 production cache hit 검증

collect_raw_data() 단독 2회차에서 24h cache hit 확인:

뉴스/웹 검색 24h 캐시 hit (156s old)
cache_status {'status': 'hit', 'age_sec': 156, 'file': '/Users/ron/.hermes/workspace/memory/news_cache/oil_supply_monitor_web_raw.json'}
elapsed=21

4. Before / After 한 줄

  • Before: 뉴스 단계가 외부 web_search에 붙잡히면 11분+ 또는 306초까지 지연.
  • After: --skip-news는 62초에 가격·snapshot 완료, 일반 모드는 timeout/fallback 가능, production cache hit 경로는 collect_raw_data 기준 21초.

5. Remaining Risks

  • 24h production cache hit는 단독 수집 기준 검증 완료. 전체 리포트 자연 실행에서는 LLM/차트 시간이 남으므로 별도 관찰 필요.
  • --skip-news에서도 선물 커브/차트 생성 때문에 1분가량 걸린다. 더 빠른 emergency mode가 필요하면 --skip-charts가 추가 과제다.
  • timeout 중 일부 하위 web_search 구현이 내부적으로 오래 붙잡힐 수 있어 per-query timeout을 추가했지만, 외부 tool 내부 hang은 계속 관찰 필요.

자체평가

  • 정확성: 4.2/5 — 지연 구간 식별, timeout/skip/cache 경로 구현, timeout·skip 검증 완료.
  • 완성도: 4.1/5 — production cache 생성까지 확인, 다음 자연 실행 cache-hit 시간 단축은 추가 관찰 필요.
  • 검증: 4.3/5 — py_compile, timeout run, skip run, production cache-hit, helper unit 검증 완료.
  • 최소 변경: 4.2/5 — oil_supply_monitor 단일 파일에 국한.

종합: 4.2/5

DONE