Repository navigation
Description
现象
#1148(#1113)给 plan 加了可选的 --baseline-sample N:先对种子打分,再决定要不要引用付费 run。同一条 plan 上,--probe 在模型调用失败时会:
- 退出码 1(配置答案,不是 spec 错误)
- 人类输出里保留已经算好的 plan,并给出可行动的
next:/then: plan <spec> --probe --json写出完整对象:ok: true(plan 本身成立)、ready: false、probe行、next为修复建议
但 --baseline-sample 撞上同样的供应商/订阅失败时,走的是另一条提前 return 2 的路径:只往 stderr 打一行 error: baseline sample failed: …,stdout 为空,--json 也没有任何对象,也没有 ready / next / then。宿主或脚本按 --json 解析会直接失败,用户也看不到已经通过校验的 plan。
复现
环境:ThinkFlowLab/agentdescent main 7e5fd0ace4c63b23fb9091eb3eb4d8688505a1b2(0.10.0),pip install -e ".[mcp]"。用离线 demo 的 12 条 text 用例写成 spec,agent/reflect 为 openai_compatible + Ark Coding deepseek-v4-flash(当前订阅为 InvalidSubscription,恰好是这条路径的真实失败;任何会在打分时抛错的 provider 错误都可以复现)。
agentdescent init ./prompt.txt --kind text --data ./cases.jsonl --out ./spec.json \
--algorithm gepa --agent openai_compatible \
--model deepseek-v4-flash \
--base-url https://ark.cn-beijing.volces.com/api/coding/v3 \
--rounds 1 --workers 1
# 对照:--probe 的契约(exit 1,stdout 有 JSON)
agentdescent plan ./spec.json --probe --json
# exit 1
# stdout: { "ok": true, "ready": false, "probe": { "ok": false, "rows": [...] },
# "next": "renew the subscription at the provider, or point api_key_env / model at another plan" }
# 问题:同一失败,--baseline-sample --json
agentdescent plan ./spec.json --baseline-sample 3 --json
# exit 2
# stderr:
# baseline sample: scoring the seed on up to 3 task(s) costs 3 agent call(s)
# error: baseline sample failed: SubscriptionInactive: … returned HTTP 400
# for model 'deepseek-v4-flash': {"error":{"code":"InvalidSubscription",…}}
# stdout: (空)不加 --json 时也一样:stderr 只有上面两行,stdout 为空,没有 then: agentdescent plan ./spec.json --baseline-sample 3。
对照:同一份离线 demo spec(agentdescent.demo:offline_text_agent)上 --baseline-sample 3 --json 成功时是有信封的(ok: true,baseline: {sample, score, saturation, headroom})。--probe 与「无 headroom」拒绝(#1148)也都会写出 JSON。缺口只在打分过程中的 provider/backend 异常。
代码:agentdescent/cli.py 里 _seed_baseline_score 的 except 直接 print(..., file=sys.stderr); return 2,发生在 _out(payload, as_json=True) / _print_plan(...) 之前。tests/test_plan_headroom_shape.py 覆盖了成功、饱和、--force 和 --baseline-sample 0 输入错误,没有覆盖打分失败。
预期
--baseline-sample 在种子打分因供应商/订阅/端点失败时,应与 --probe 对齐:这是配置答案,不是 spec 坏了。
- 人类输出保留已算好的 plan,把失败写清楚,并给出可行动的
next:(与 probe 同类的修复建议)和then: agentdescent plan <spec> --baseline-sample N。 --json写出完整对象:ok仍表示 plan 本身成立,ready: false,baseline携带失败详情(不要只丢一行 stderr),next为修复建议。- 退出码 1(与拒绝的 probe / 无 headroom 相同),不是 2。
- 不写 run store 条目(现在也没有,应保持)。
输入错误(--baseline-sample 0 等)可以继续 stderr + exit 2。
建议修法(单 PR)
在 cli.py 的 baseline except 里不要提前 return 2:把失败记进 payload["baseline"](例如 ok: false + 异常类型与信息),设 ready: false 和 next/then_line,然后照常走 _out / _print_plan,返回 1。能复用 probe 已有的 SubscriptionInactive / QuotaExhausted / ProviderConfigError 修复文案更好,避免再发明一套。在 tests/test_plan_headroom_shape.py 加一行本地假 endpoint / 抛错后端,同时钉住人类输出和 --json。不必改 evolve。
验收
- 对会在打分时失败的 model-backed spec:
plan --baseline-sample N与plan --baseline-sample N --json都给出上述信封和next/then,exit 1,stdout 在--json下可json.loads。 - 同一 spec 上
plan --probe --json的现有契约不变。 - 离线成功样本、饱和
no headroom、--force、--baseline-sample 0的现有测试仍过。 - 不向 run store 写入条目。
Activity