小怡终审 2026-10-17 21:05 必须修的 4 项之一(-1 哨兵被当低分 ⇒ 触发器恒 fire): 1. selfoptimize.go: 新增 IsNA(v) 判 N/A(metricNA<0)。 2. executor.go: TGapDetected/TQualityDrop/TVValueLow 阈值比较前显式判 N/A, -1 不再被当「低于阈值」每轮触发(与旧 recall_hit_rate 恒=1 同类失真、方向相反)。 配 executor_na_test.go 反例(v=-1 断言不触发)+ 正向对照。 3. tuning.go: AnalyticsHandler 建议 builder 抽为纯函数 AnalyticsSuggestions, 统一走 ratioFor(-1/valid=0/样本不足 ⇒ 不产生建议);配 tuning_analytics_test.go 反例。 4. 两个 daily-check.sh: gap/auto/usefulness 值为 -1 时显示 —(N/A),不再打印误导性 -1/天。 测试命令(go.mod 在 go/ 下,须 cd go): cd go && go test ./internal/selfoptimize/... ./internal/api/routes/ (TestCommitConflictGate_E2E 为既有环境性 LLM 蒸馏用例,非本次改动路径,单独 FAIL) 生产部署仍待小怡终审 + 牧尘放行(本卡边界)。
73 lines
3.5 KiB
Bash
Executable File
73 lines
3.5 KiB
Bash
Executable File
#!/bin/bash
|
||
# 织忆每日健康检查脚本
|
||
# 用法: ./daily-check.sh
|
||
# 依赖: curl, jq (optional)
|
||
|
||
API_KEY="zhiyi-dev-key-2026"
|
||
BASE="http://localhost:7821"
|
||
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
|
||
|
||
pass() { echo -e "${GREEN}✅ $1${NC}"; }
|
||
warn() { echo -e "${YELLOW}⚠️ $1${NC}"; }
|
||
fail() { echo -e "${RED}❌ $1${NC}"; }
|
||
|
||
echo "=== 织忆每日健康检查 $(date '+%Y-%m-%d %H:%M') ==="
|
||
|
||
# 1. 服务存活
|
||
STATUS=$(curl -s $BASE/health | python3 -c "import sys,json; print(json.load(sys.stdin).get('status','?'))" 2>/dev/null)
|
||
[ "$STATUS" = "ok" ] && pass "服务存活" || fail "服务状态: $STATUS"
|
||
|
||
# 2. 核心统计
|
||
STATS=$(curl -s $BASE/api/v1/stats -H "X-API-Key: $API_KEY" 2>/dev/null)
|
||
echo "$STATS" | python3 -c "import sys,json; d=json.load(sys.stdin); print(f\"记忆: {d.get('total_memories',0)}, Episodes: {d.get('total_episodes',0)}, 坟场: {d.get('tombstone_count',0)}\")" 2>/dev/null
|
||
|
||
# 3. 自优化指标
|
||
METRICS=$(curl -s $BASE/api/v1/metrics/self -H "X-API-Key: $API_KEY" 2>/dev/null)
|
||
echo "$METRICS" | python3 -c "
|
||
import sys,json
|
||
d=json.load(sys.stdin)
|
||
# 2026-10-17:recall_hit_rate 已退役(恒=1、无区分度)。召回质量改用 recall_usefulness_rate
|
||
#(返回且被使用);-1 表示样本不足/无负反馈 = 数据不可解读,跳过告警,不误报。
|
||
hit = d.get('recall_usefulness_rate', -1)
|
||
loss = d.get('avg_distill_loss', -1)
|
||
gap = d.get('gap_closure_rate', -1)
|
||
auto = d.get('auto_resolve_rate', -1)
|
||
# -1 哨兵 = 样本不足/越界被拦,不可解读 ⇒ 显示 —(N/A),不得当成具体数字误导。
|
||
def fmt(v, pct=False):
|
||
if v is None or v < 0:
|
||
return '—(N/A)'
|
||
return ('%.0f%%' % (v*100)) if pct else ('%.2f' % v)
|
||
print('召回有用率: %s, 蒸馏损失: %s, gap闭合率: %s, auto_resolve率: %s' % (fmt(hit, True), fmt(loss), fmt(gap, True), fmt(auto, True)))
|
||
if loss is not None and loss >= 0 and loss > 0.3: print('⚠️ avg_distill_loss 超标')
|
||
if hit is not None and hit >= 0 and hit < 0.5: print('⚠️ recall_usefulness_rate 低于阈值')
|
||
" 2>/dev/null
|
||
|
||
# 4. 蒸馏状态
|
||
DISTILL=$(curl -s $BASE/api/v1/distill/status -H "X-API-Key: $API_KEY" 2>/dev/null)
|
||
echo "$DISTILL" | python3 -c "import sys,json; d=json.load(sys.stdin); print(f\"蒸馏队列: {d.get('queue_len',0)}, 今日已蒸: {d.get('daily_used',0)}, 剩余: {d.get('daily_remaining',0)}\")" 2>/dev/null
|
||
|
||
# 5. 触发器
|
||
TRIGGERS=$(curl -s $BASE/api/v1/triggers -H "X-API-Key: $API_KEY" 2>/dev/null)
|
||
echo "$TRIGGERS" | python3 -c "
|
||
import sys,json
|
||
d=json.load(sys.stdin)
|
||
for t in d.get('triggers',[]):
|
||
fail = t.get('fail_count',0)
|
||
urgency = t.get('urgency',0)
|
||
paused = t.get('paused',False)
|
||
status = '⏸' if paused else ('❌' if fail>0 else '✅')
|
||
print(f\"{status} {t['id']}: cooldown={t.get('cooldown','')}, fail={fail}, urgency={urgency}\")
|
||
" 2>/dev/null
|
||
|
||
# 6. 图谱
|
||
GRAPH=$(curl -s $BASE/api/v1/graph/stats -H "X-API-Key: $API_KEY" 2>/dev/null)
|
||
echo "$GRAPH" | python3 -c "import sys,json; d=json.load(sys.stdin); print(f\"图谱: {d.get('node_count',0)} 节点, {d.get('edge_count',0)} 边\")" 2>/dev/null
|
||
|
||
# 7. 冲突和缺口
|
||
CONFLICTS=$(curl -s $BASE/api/v1/conflicts -H "X-API-Key: $API_KEY" 2>/dev/null)
|
||
echo "$CONFLICTS" | python3 -c "import sys,json; d=json.load(sys.stdin); print(f\"冲突: {d.get('count',0)} 待处理, {d.get('pending',0)} 待定\")" 2>/dev/null
|
||
|
||
GAPS=$(curl -s $BASE/api/v1/gaps -H "X-API-Key: $API_KEY" 2>/dev/null)
|
||
echo "$GAPS" | python3 -c "import sys,json; d=json.load(sys.stdin); print(f\"缺口: {d.get('open',0)} 未关闭\")" 2>/dev/null
|
||
|
||
echo "=== 检查完成 ===" |