chore: 가드 발동률 실측 스크립트
2026-09-04 가드 패치(db6a863/10e54d3/b2075c6)가 실사용에서 어떻게 도는지 며칠 뒤 재려고 만들었다. 기준선은 .smallclaw/logs/audit/guard-baseline.json(머신 로컬, gitignore 대상)에 줄 번호 + 꼬리 30줄 지문으로 박혀 있다 — 로그에 타임스탬프가 없어서다. 로테이션되면 지문이 안 맞고, 그때는 경고를 내고 전체를 잰다. 패치 직전 기준값(전체 340턴): NUMERIC 재프롬프트 24(0.07/턴), AUTO-RECOVER 37(0.11/턴), SEARCH-ABANDONMENT 7(0.02/턴), 합성 Answer: 줄 1건, standing down 0(미존재). 판독 기준은 스크립트 말미에 적어 뒀다 — 관련성 관문이 헐거우면 NUMERIC이 계속 맞는 답을 지우고, 빡빡하면 standing down이 과해져 진짜 날조가 통과한다. 양방향 모두 봐야 한다. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Rfme1WVEPkpNwnf5oVNXXc
This commit is contained in:
1 parent
b2075c62d8
commit
1b52acf615
1 file changed
+118
Executable
+118
@@ -0,0 +1,118 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
가드 발동률 실측 — 2026-09-04 가드 패치(db6a863 / 10e54d3 / b2075c6) 이후 구간을 잰다.
|
||||
|
||||
왜 필요한가. 이번 패치들은 전부 실사용 로그를 표본으로 보정했지만, 보정 자체가 맞았는지는
|
||||
"패치 이후 로그"로만 확인할 수 있다([[feedback_calibrate_on_real_data]]). 특히 두 가지가
|
||||
반대 방향으로 어긋날 수 있다:
|
||||
· 관련성 관문(sourceCoversQuery)이 너무 헐거우면 → NUMERIC-GROUNDING이 계속 맞는 답을 지운다
|
||||
· 너무 빡빡하면 → 진짜 날조가 그대로 통과한다(standing down이 과하게 잦아진다)
|
||||
|
||||
사용:
|
||||
python3 scripts/guard-firing-audit.py # 기준선 이후 구간만
|
||||
python3 scripts/guard-firing-audit.py --all # 로그 전체(패치 전 비교용)
|
||||
|
||||
기준선은 .smallclaw/logs/audit/guard-baseline.json 에 줄 번호 + 꼬리 지문으로 박혀 있다.
|
||||
로그가 로테이션되면 지문이 안 맞고, 그때는 경고를 내고 전체를 잰다.
|
||||
"""
|
||||
|
||||
import json
|
||||
import hashlib
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from collections import Counter
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
LOG = os.path.join(ROOT, '.smallclaw/logs/gateway.log')
|
||||
BASELINE = os.path.join(ROOT, '.smallclaw/logs/audit/guard-baseline.json')
|
||||
|
||||
# 세는 대상. (라벨, 정규식, 이번 패치와의 관계)
|
||||
PATTERNS = [
|
||||
('NUMERIC standing down', r'NUMERIC-GROUNDING: standing down', 'new'),
|
||||
('NUMERIC 재프롬프트', r'NUMERIC-GROUNDING POST-CHECK', 'should-drop'),
|
||||
('SEARCH-ABANDONMENT', r'SEARCH-ABANDONMENT POST-CHECK', 'was-dead'),
|
||||
('DEAD-END FALLBACK', r'DEAD-END FALLBACK POST-CHECK', 'new'),
|
||||
('SYCOPHANTIC', r'SYCOPHANTIC-CONFIRMATION POST-CHECK', 'new'),
|
||||
('AUTO-RECOVER', r'\[v2\] AUTO-RECOVER \(', 'baseline'),
|
||||
('EMPTY-GROUNDING', r'EMPTY-GROUNDING POST-CHECK', 'baseline'),
|
||||
('INTENT-ONLY', r'INTENT-ONLY POST-CHECK', 'baseline'),
|
||||
('MESSAGING', r'MESSAGING POST-CHECK', 'baseline'),
|
||||
('STALE-VERSION QUERY', r'STALE-VERSION QUERY', 'baseline'),
|
||||
('중복 도구호출 SKIP', r'SKIP: duplicate tool call', 'baseline'),
|
||||
('합성 Answer: 줄', r'TOOL OK: Answer: The current', 'should-be-0'),
|
||||
]
|
||||
|
||||
USER_RE = re.compile(r'^\[v2\] USER \[')
|
||||
FIG_RE = re.compile(r'figure\(s\) not found in tool output \[([^\]]*)\]')
|
||||
COV_RE = re.compile(r'cover only (\d+)% of the query')
|
||||
|
||||
|
||||
def load_lines():
|
||||
if not os.path.exists(LOG):
|
||||
sys.exit(f'로그가 없습니다: {LOG}')
|
||||
return open(LOG, errors='replace').read().splitlines()
|
||||
|
||||
|
||||
def slice_from_baseline(lines):
|
||||
"""기준선 이후만 잘라낸다. 로테이션됐으면 (전체, False)."""
|
||||
if not os.path.exists(BASELINE):
|
||||
return lines, False
|
||||
meta = json.load(open(BASELINE))
|
||||
n = meta['baselineLines']
|
||||
if len(lines) < n:
|
||||
return lines, False # 로테이션돼 짧아졌다
|
||||
fp = hashlib.sha256('\n'.join(lines[max(0, n - 30):n]).encode()).hexdigest()[:16]
|
||||
if fp != meta['tailFingerprint']:
|
||||
return lines, False
|
||||
return lines[n:], True
|
||||
|
||||
|
||||
def main():
|
||||
lines = load_lines()
|
||||
if '--all' in sys.argv:
|
||||
seg, anchored = lines, False
|
||||
scope = '로그 전체'
|
||||
else:
|
||||
seg, anchored = slice_from_baseline(lines)
|
||||
scope = '기준선 이후' if anchored else '로그 전체 (⚠ 기준선 유실 — 로테이션된 듯)'
|
||||
|
||||
turns = sum(1 for l in seg if USER_RE.match(l))
|
||||
print(f'구간: {scope} — {len(seg):,}줄, 사용자 턴 {turns}건\n')
|
||||
if turns == 0:
|
||||
print('아직 이 구간에 대화가 없습니다. 며칠 더 쓰고 다시 도세요.')
|
||||
return
|
||||
|
||||
print(f'{"가드":<24}{"발동":>6}{"턴당":>9} 비고')
|
||||
print('-' * 62)
|
||||
note = {'new': '이번에 추가', 'should-drop': '줄어야 정상', 'was-dead': '패치 전 0건이었음',
|
||||
'should-be-0': '0이어야 정상', 'baseline': ''}
|
||||
for label, pat, kind in PATTERNS:
|
||||
c = sum(1 for l in seg if re.search(pat, l))
|
||||
print(f'{label:<24}{c:>6}{c / turns:>9.2f} {note[kind]}')
|
||||
|
||||
# 지워진 수치가 실제로 무엇이었는지 — 사용자가 원한 답이 지워졌는지 눈으로 본다.
|
||||
figs = [m.group(1) for l in seg for m in [FIG_RE.search(l)] if m]
|
||||
if figs:
|
||||
print(f'\n지워진 수치 (총 {len(figs)}건, 최근 12건):')
|
||||
for f in figs[-12:]:
|
||||
print(f' · {f}')
|
||||
print(' ↑ 사용자가 원했던 답이 여기 섞여 있으면 관련성 관문이 아직 헐겁다.')
|
||||
|
||||
covs = [int(m.group(1)) for l in seg for m in [COV_RE.search(l)] if m]
|
||||
if covs:
|
||||
print(f'\nstanding down 커버리지 분포: {sorted(covs)}')
|
||||
print(f' 중앙값 {sorted(covs)[len(covs)//2]}% (임계값 34%)')
|
||||
near = [c for c in covs if 25 <= c <= 33]
|
||||
if near:
|
||||
print(f' ⚠ 임계값 근처({25}~33%) {len(near)}건 — 경계가 애매한 사례가 쌓이면 값 재검토')
|
||||
|
||||
print('\n판독 기준')
|
||||
print(' · 합성 Answer: 줄이 0이 아니면 → generic 경로가 되살아났는지 확인')
|
||||
print(' · SEARCH-ABANDONMENT가 여전히 0이면 → 포기 어법이 또 바뀐 것(NOTHING_FOUND 갱신)')
|
||||
print(' · DEAD-END FALLBACK이 턴당 0.05 넘으면 → 임계값(PRIOR_DEAD_ENDS_REQUIRED=1)이 낮음')
|
||||
print(' · standing down이 NUMERIC 재프롬프트보다 훨씬 많으면 → 관문이 너무 빡빡')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in new issue
Block a user