用户要求"AI 询问界面不要限时"。v2.0.44 改了界面侧(AiSurface 无限等)和
工具侧(ask_user 的 timeout 默认 0),但**漏了内核的工具执行超时**:
实测:弹窗 135 秒确实还在,但工具调用在 60.0 秒返回
{"ok":false,"error":"工具执行超时(60s)"} —— 用户后来点的选项根本
回不到模型手里,模型已经拿着"超时"自己往下写了。
改动:
- builtin_tools.run_with_timeout:timeout_s <= 0 = 不限时(thread.join() 不带参)
- tools/ask_user.py、tools/show_ui.py:声明 WAIT_FOR_USER = True
- tools_runtime:新增 _waits_for_user(),会等用户的工具把超时预算设成 0;
普通工具仍是 60 秒(死循环的安全网没丢)
验证(scripts/probe-ask-user-forever.py,真机跑):
修之前 60.0 秒 → {"ok":false,"error":"工具执行超时(60s)"}
修之后 66.2 秒 → {"ok":true,"result":{...,"choice":"B","timeout":false}}
守门:scripts/verify-ui-tools.py 新增一节(声明在不在、豁免逻辑在不在、
预算 0 是不是真的无限等、普通工具的 60 秒还在不在)。
文档:docs/AI界面能力.md 补"不限时要三处一起改"和客户端长连接为什么不断
(15 秒心跳 vs 120 秒 readTimeout)。
版本 2.0.45。
73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
"""验证:`ask_user` 弹窗**不限时**(用户要求"AI 询问界面不要限时")。
|
||
|
||
## 怎么验
|
||
|
||
以前是 120 秒到点自己消失。所以要证明"改了",必须**跨过 120 秒那条线**:
|
||
调一次 ask_user,然后在 5 秒 / 130 秒两个时刻截图:
|
||
|
||
· 5 秒:弹窗在(说明调通了)
|
||
· 130 秒:**弹窗还在**(说明真的不限时了。旧版这时候已经没了)
|
||
· 再点一下选项:请求返回,`timeout` 是 false、`choice` 是点的那个
|
||
|
||
★ 这个脚本会**阻塞到用户点为止**(那正是它要测的东西),所以必须后台跑。
|
||
|
||
用法:
|
||
adb forward tcp:15199 tcp:5199
|
||
python scripts/probe-ask-user-forever.py
|
||
"""
|
||
import json
|
||
import sys
|
||
import time
|
||
import urllib.request
|
||
|
||
try:
|
||
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
||
except Exception:
|
||
pass
|
||
|
||
URL = "http://127.0.0.1:15199"
|
||
|
||
|
||
def call(path, payload=None, method="POST", timeout=900):
|
||
data = json.dumps(payload, ensure_ascii=False).encode("utf-8") if payload is not None else None
|
||
req = urllib.request.Request(
|
||
URL + path, data=data, method=method,
|
||
headers={"Content-Type": "application/json; charset=utf-8"},
|
||
)
|
||
with urllib.request.urlopen(req, timeout=timeout) as r:
|
||
return json.loads(r.read().decode("utf-8"))
|
||
|
||
|
||
def main():
|
||
print("调 ask_user —— 这个请求会一直挂着,直到有人在弹窗上点一下", flush=True)
|
||
t0 = time.time()
|
||
try:
|
||
r = call("/api/tools/run", {
|
||
"name": "ask_user",
|
||
"args": {
|
||
"question": "不限时测试:随便点一个(我不催你)",
|
||
"options": [
|
||
{"label": "选项 A", "value": "A"},
|
||
{"label": "选项 B", "value": "B"},
|
||
{"label": "选项 C", "value": "C"},
|
||
],
|
||
},
|
||
}, timeout=900)
|
||
except Exception as exc: # noqa: BLE001
|
||
print(f"!! 请求失败({time.time() - t0:.1f} 秒后):{exc}", flush=True)
|
||
return 1
|
||
|
||
dt = time.time() - t0
|
||
print(f"\n等了 {dt:.1f} 秒才返回(旧版 120 秒就会 timeout)", flush=True)
|
||
print(json.dumps(r, ensure_ascii=False)[:500], flush=True)
|
||
|
||
if dt > 125 and not (r.get("result") or {}).get("timeout"):
|
||
print("\n✅ 不限时生效:超过 120 秒仍然等到了用户的选择", flush=True)
|
||
return 0
|
||
print("\n? 结果需要人工看一眼(可能点得太快,或 timeout 语义不对)", flush=True)
|
||
return 0
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|