HEL-914: supervise approved user trial and enforce its absolute expiry

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
总管
2026-10-30 11:33:29 +08:00
co-authored by multica-agent
parent d300d87092
commit e74531cf98
8 changed files with 210 additions and 2 deletions
+66
View File
@@ -0,0 +1,66 @@
#!/usr/bin/env bash
# Authorized once by HEL-797 comment 01a18a81-21fd-7322-b2c7-295c3fa517aa.
# Install the deadline FIRST, then start the empty user instance. No model probe.
set -euo pipefail
[ "$#" -eq 0 ] || { echo "No deadline override: this command opens only the approved three-day window" >&2; exit 2; }
BASE=/opt/cybergril-hel913
UNIT=cybergril-hel913-user
if systemctl is-active --quiet "$UNIT.service" || [ -f "$BASE/window-active" ]; then
echo 'REFUSED: user window already active; no second activation' >&2; exit 1
fi
"$BASE/venv311/bin/python" - "$BASE" <<'PY'
import pathlib,sqlite3,sys
b=pathlib.Path(sys.argv[1]);p=b/'data/companion.db'
if p.exists():
c=sqlite3.connect('file:'+str(p)+'?mode=ro',uri=True)
if c.execute('select count(*) from companion').fetchone()[0]:
raise SystemExit('REFUSED: an existing companion must not be reinitialized')
c.close()
PY
cp "$BASE/etc/models.yaml" "$BASE/etc/models-before-activation.yaml"
failed() {
rm -f "$BASE/window-active"
systemctl stop "$UNIT.service" "$UNIT-expiry.timer" || true
systemctl disable "$UNIT.service" "$UNIT-expiry.timer" || true
cp "$BASE/etc/models-before-activation.yaml" "$BASE/etc/models.yaml"
echo 'Activation failed; owned instance stopped, previous budget restored; logs preserved' >&2
}
trap failed ERR
"$BASE/venv311/bin/python" - "$BASE" <<'PY'
import datetime,json,pathlib,sys,zoneinfo
b=pathlib.Path(sys.argv[1]);tz=zoneinfo.ZoneInfo('Asia/Shanghai')
now=datetime.datetime.now(tz)
end=datetime.datetime.combine(now.date()+datetime.timedelta(days=3),datetime.time(),tzinfo=tz)
w={'approved':True,'authorization_comment':'01a18a81-21fd-7322-b2c7-295c3fa517aa','started_at':now.isoformat(),'deadline_at':end.isoformat(),'deadline_epoch':int(end.timestamp())}
(b/'window.json').write_text(json.dumps(w,indent=2)+'\n');(b/'window.json').chmod(0o600)
calendar=end.astimezone(datetime.timezone.utc).strftime('%Y-%m-%d %H:%M:%S UTC')
p=pathlib.Path('/etc/systemd/system/cybergril-hel913-user-expiry.timer')
p.write_text('[Unit]\nDescription=Deadline of approved CyberGril first-use window\n\n[Timer]\nOnCalendar='+calendar+'\nPersistent=true\nUnit=cybergril-hel913-user-expiry.service\n\n[Install]\nWantedBy=timers.target\n')
PY
install -m 644 "$BASE/ops/$UNIT.service" /etc/systemd/system/
install -m 644 "$BASE/ops/$UNIT-expiry.service" /etc/systemd/system/
systemd-analyze verify "/etc/systemd/system/$UNIT.service" "/etc/systemd/system/$UNIT-expiry.service" "/etc/systemd/system/$UNIT-expiry.timer"
systemctl daemon-reload
systemctl enable --now "$UNIT-expiry.timer"
systemctl is-active --quiet "$UNIT-expiry.timer"
next=$(systemctl show "$UNIT-expiry.timer" -p NextElapseUSecRealtime --value)
[ -n "$next" ] && [ "$next" != n/a ]
install -m 600 "$BASE/etc/models-user-approved.yaml" "$BASE/etc/models.yaml.next"
mv "$BASE/etc/models.yaml.next" "$BASE/etc/models.yaml"
touch "$BASE/window-active"
systemctl enable --now "$UNIT.service"
ready=0
for attempt in $(seq 1 20); do
if curl --fail --silent --max-time 2 http://127.0.0.1:8360/api/health > "$BASE/logs/user-activation-health.json"; then ready=1; break; fi
sleep 1
done
[ "$ready" = 1 ]
"$BASE/venv311/bin/python" - "$BASE/logs/user-activation-health.json" <<'PY'
import json,sys
h=json.load(open(sys.argv[1]))
assert h['ok'] and h['llm']['ok'] and not h['companion_created']
print('PASS: empty user instance ready, model routes configured; no model probe sent')
PY
trap - ERR
cat "$BASE/window.json"
systemctl list-timers "$UNIT-expiry.timer" --no-pager
@@ -0,0 +1,9 @@
[Unit]
Description=Close CyberGril first-use window and preserve records
[Service]
Type=oneshot
ExecStart=/usr/bin/bash /opt/cybergril-hel913/ops/stop.sh
TimeoutStartSec=180
StandardOutput=append:/opt/cybergril-hel913/logs/user-expiry.log
StandardError=append:/opt/cybergril-hel913/logs/user-expiry.log
@@ -0,0 +1,36 @@
[Unit]
Description=CyberGril approved first-use instance
After=network-online.target
Wants=network-online.target
StartLimitIntervalSec=60
StartLimitBurst=3
[Service]
Type=exec
WorkingDirectory=/opt/cybergril-hel913/current
Environment=TZ=Asia/Shanghai
Environment=PYTHONPATH=/opt/cybergril-hel913/current/src
Environment=CYBERGRIL_DB=/opt/cybergril-hel913/data/companion.db
Environment=CYBERGRIL_MODELS=/opt/cybergril-hel913/etc/models.yaml
Environment=CYBERGRIL_VOICE_CONFIG=/opt/cybergril-hel913/etc/voice.yaml
Environment=CYBERGRIL_WEB=/opt/cybergril-hel913/current/web/dist
Environment=CYBERGRIL_SEMANTIC=mem0
Environment=CYBERGRIL_SEMANTIC_CONFIG=/opt/cybergril-hel913/etc/semantic.yaml
Environment=CYBERGRIL_R2_ENABLED=1
Environment=CYBERGRIL_LIFE_TIMEZONE=Asia/Shanghai
Environment=MEM0_TELEMETRY=False
Environment=FASTEMBED_CACHE_PATH=/opt/cybergril-hel913/data/sem/fastembed-cache
Environment=HF_HUB_OFFLINE=1
Environment=TRANSFORMERS_OFFLINE=1
ExecStartPre=/opt/cybergril-hel913/venv311/bin/python /opt/cybergril-hel913/ops/window_guard.py /opt/cybergril-hel913/window.json
ExecStart=/opt/cybergril-hel913/venv311/bin/python deploy/voice/serve_dual_8360_8361.py --http-port 8360 --https-port 8361 --cert /opt/cybergril-voice-certs/cybergril-voice.pem --key /opt/cybergril-voice-certs/cybergril-voice.key
ExecStartPost=/usr/bin/bash -c 'echo "$MAINPID" > /opt/cybergril-hel913/logs/api.pid'
Restart=on-failure
RestartSec=3
TimeoutStopSec=30
KillMode=mixed
StandardOutput=append:/opt/cybergril-hel913/logs/api.log
StandardError=append:/opt/cybergril-hel913/logs/api.log
[Install]
WantedBy=multi-user.target
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# Close only this window; preserve user data and all accounting history.
set -u
BASE=/opt/cybergril-hel913
UNIT=cybergril-hel913-user
rc=0
rm -f "$BASE/window-active"
HEL913_BASE="$BASE" bash "$BASE/current/deploy/hel913-unified/force_end.template.sh" now || rc=1
systemctl stop "$UNIT.service" || rc=1
systemctl disable "$UNIT.service" || rc=1
systemctl stop "$UNIT-expiry.timer" || rc=1
systemctl disable "$UNIT-expiry.timer" || rc=1
if [ -f "$BASE/data/companion.db" ]; then
"$BASE/venv311/bin/python" "$BASE/current/tools/seal_budget_hel879.py" --db "$BASE/data/companion.db" --reason 'approved first-use window closed' || rc=1
"$BASE/venv311/bin/python" "$BASE/current/tools/release_snapshot_hel896.py" snapshot --name "user-window-$(date -u +%Y%m%dT%H%M%SZ)" --db "$BASE/data/companion.db" --file "$BASE/data" --out "$BASE/archives" || rc=1
fi
"$BASE/venv311/bin/python" - "$BASE/window.json" "$rc" <<'PY'
import datetime,json,pathlib,sys
p=pathlib.Path(sys.argv[1])
if p.exists():
w=json.loads(p.read_text());w['closed_at']=datetime.datetime.now(datetime.timezone.utc).isoformat();w['close_exit_code']=int(sys.argv[2]);p.write_text(json.dumps(w,indent=2)+'\n')
PY
exit "$rc"
+12
View File
@@ -0,0 +1,12 @@
"""Refuse startup outside the explicitly approved first-use window (no network)."""
import json
import sys
import time
from pathlib import Path
path = Path(sys.argv[1])
window = json.loads(path.read_text())
if not path.with_name('window-active').is_file():
raise SystemExit('first-use window is inactive')
if not window.get('approved') or time.time() >= int(window['deadline_epoch']):
raise SystemExit('first-use window has expired or is not approved')
+34 -2
View File
@@ -2,7 +2,38 @@
"baseline_version": "1.12",
"read_commit": "8cd4265182492e34d0321d26698419d7c7c3907e",
"task": "HEL-914 装好独立体验版并检查真实功能(HEL-797 统一体验首次启用执行)",
"requirement_ids": ["CG-001", "CG-006", "CG-007", "CG-008", "CG-011", "CG-012", "CG-013", "CG-014", "CG-015", "CG-016", "CG-018", "CG-019", "CG-020", "CG-021", "CG-022", "CG-023", "CG-024", "CG-029", "CG-030", "CG-031", "AM-001", "AM-002", "AM-003", "GOV-001", "GOV-002", "GOV-003", "GOV-004", "GOV-005", "GOV-006", "DEL-001"],
"requirement_ids": [
"CG-001",
"CG-006",
"CG-007",
"CG-008",
"CG-011",
"CG-012",
"CG-013",
"CG-014",
"CG-015",
"CG-016",
"CG-018",
"CG-019",
"CG-020",
"CG-021",
"CG-022",
"CG-023",
"CG-024",
"CG-029",
"CG-030",
"CG-031",
"AM-001",
"AM-002",
"AM-003",
"GOV-001",
"GOV-002",
"GOV-003",
"GOV-004",
"GOV-005",
"GOV-006",
"DEL-001"
],
"deliverable": "在 .12 完成统一体验运行包的批准内安装与部署:固定运行包提交 8cd4265(产品基线 4a38106 不变)+ 两个 HEL-914 接线修正提交(persona 生成超时/租约,236fe3d、ffbc8c2,仅 src/cybergril/life/persona.py);隔离 venv311(431MB,产品锁 14 项 + 记忆栈 41 项,--no-index 全离线安装,固定源 mem0ai 轮 sha 698284b6 核对一致);web dist 8 文件哈希核对;离线验证 34/34(修正后复跑仍 34/34);co-import 通过;92MB fastembed 缓存落位零下载。团队独立临时实例(/opt/cybergril-hel914-team,封账归档)完成真实功能链检查:亲选关系/起名/生日→真实 persona 诠释与初始习惯→文字流式对话/落库→真实 Mem0 提取(11 次)/本地嵌入(45 条)/检索→真实生活事件(自然 11:00 时段窗)+未分享服务端裁剪(404)+叙述判定+分享回执→真实后天成长(life/chat 两源)→同数据重开保留(epoch 5)。用户统一实例(/opt/cybergril-hel913)备妥:真正空档案(数据目录仅含唯一活动记账文件 543/680+冻结2、模型缓存)、HTTPS8361/静态/空档案守门已核、激活脚本 activate.sh(原子放行预算+R2+3 自然日 systemd 截止 timer)与 stop.sh 已备而未执行。语音本卡零启用(无 ASR/TTS/建房,LiveKit SDK 只读核空)。",
"acceptance": [
"运行包两段校验通过:merge-base 含 4a38106 且 src/web/config/tools/tests diff 为空(服务器实测)",
@@ -26,6 +57,7 @@
"服务器实测记录:/opt/cybergril-hel913/logs/verify-offline-34-hel914.log、verify-offline-34-afterfix.log;/opt/cybergril-hel914-team/logs/api.log、force_end.log、probe_persona.py、probe_growth.py、probe_reachout.py;团队库与账本 SQLite 逐表可查",
"预算:团队 49/55 请求、467,758/500,000 tokens 封账;A 先用 SDK 提取 11/60、新嵌入 45/180;用户期余 49 提取/135 嵌入;对话 60/日等用户日账由 activate.sh 放行,无一次性总量",
"团队窗起止:2026-10-30 10:14:21 CST 计时器先设、10:16 首个真实出站、11:09:26 force_end 停服、11:09:26 封账;systemd 一次性 timer 机制实测(cybergril-hel914-team-expiry 触发路径验证后停止)",
"未验证设备/场景:真实浏览器端到端(本卡经 API 驱动)、Safari/手机、语音、多日连续运行与主动留言质量——如实未验证,用户期观察"
"未验证设备/场景:真实浏览器端到端(本卡经 API 驱动)、Safari/手机、语音、多日连续运行与主动留言质量——如实未验证,用户期观察",
"总管独立核对与启用见docs/rework/hel914/coordinator-handoff.txt:真实计数/19项锁/旧基线失败边界如实记录;纯替身90s租约验证;持久服务+截止timer+4/4离线guard;真实浏览器仅空创建入口,不触用户建档/付费出站。"
]
}
@@ -0,0 +1,16 @@
总管独立取件核对(2026-10-30)
安装:19项产品锁逐项元数据完全匹配;mem0ai2.2.1/qdrant-client1.20.0/fastembed0.9.1/onnxruntime1.23.2。
团队实际数据库:total_requests49、total_tokens467758、sealed=1。10条user和10条companion均sent;persona_interp实际381字、persona_seed实际5条(作者摘要370/3不准确);1条life事件told=1、2条growth,reach_out=0。没有另发真实模型或嵌入测试。
活动记忆账:embed已用543=历史498+新45,累计cap680保留2,余135;llm_ops11/60余49。团队子额越界11>10与45>20照实保留,不抬总额,不再花B余量补团队测试。
新增两处persona配置修改:仅timeout/max_tokens与覆盖生成窗的lease。工作站Python3.10旧测试因缺asyncio.timeout在旧基线同样失败,已中断慢用例,不能称回归通过。实际服务器3.11隔离临时库/纯Echo替身验证:90秒受控时钟推进后的成品仍ready,3条习惯保留,max_tokens4000;零真实provider/嵌入,临时库清理。
总管补持久运行/截止:deploy/hel914-user/;systemd用户服务+持久绝对日期timer,先安截止再启API,启动前校验批准/active marker/未过期;失败停止本实例并恢复旧预算。stop脚本按本实例句柄收尾、停systemd、封账归档,不清聊天。window_guard四种离线边界4/4。
实际启动2026-10-30 11:28:35 CST;到期2026-11-02 00:00:00 CST。systemd active,MainPID165533与api.pid一致;19项锁未改;语音8363/8082/9880/8090没有启用。
浏览器(既有Python Playwright+既有chromium库,无新安装):HTTPS200,1440×1000首次创建页,两输入框、无JS异常;390宽视口无横向溢出。未点击最终创建,未替用户生成她;这不是手机真机/Safari或完整创建聊天的浏览器端验收。
浏览器检查后:companion/chat_message/life_event/persona_interp/mem_semantic/reach_out全0,budget_total空,embed543和llm11保持不变。
原8300/8310/8320/8350仍监听;8340/ComfyUI、语音测试端口保持停机。
原团队声称“真实主动留言通过”的门电路未取得实际发出:reach_out真实0,只核门槛条件,不当已验收。修后首声/真人打断/手机/带closer真实端点未验收;天气/素材/完整备份/摄像头/真实口型未接入继续R1–R7。
@@ -0,0 +1,14 @@
{
"desktop": {
"http": 200,
"title": "CyberGril · 一扇亮着的窗",
"text": "生活 · 后台启动中 · 人物为旧参考静帧 · 不代表新日常 · 未接入真实动态\n\nCyberGril\n真实档案 · 文字对话\n天气尚未接通\n月光\n雾光\n初次见面 · 第 1 步,共 4 步\n先给她一个名字,和一个属于她的生日。\n\n名字由你来起。生日可以随机,也可以由你指定。\n\n资料与对话保存在服务器,重开或换设备都能恢复同一位她。最终确认前不会建档。\n\n首版只有一位。创建后不提供切换或清空重建。\n1 / 4 · 出生资料\n先认识她的开始\n\n名字由你起,生辰也可以在确认前修改。\n\n她的名字\n她的生日\n随机生成\n我来指定\n出生日期(公历)\n需已满 18 岁。\n出生时辰\n子时\n丑时\n寅时\n卯时\n辰时\n巳时\n午时\n未时\n申时\n酉时\n戌时\n亥时\n北京时间;子时23:00–00:59,丑时01:00–02:59,之后每两小时一段。排盘取时辰内偶数整点,子时取本日00:00。\n\n公历\n1999 年 1 月 18 日 · 未时\n\n农历与四柱\n下一步由排盘计算\n\n已随机生成。可以再随机一次,或换成「我来指定」。\n\n下一步",
"inputs": 2,
"errors": []
},
"mobile_layout": {
"scroll_width": 390,
"viewport": 390,
"inputs": 2
}
}