From d7c47a80920c9ae8a7690a0f0c89527e7664beca Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 3 Nov 2026 08:53:05 +0000 Subject: [PATCH 1/2] fix(mcp): close post-#30 catalog, re-tick, steer, and watermark residuals Advertise tools.listChanged and send tools/list_changed after initialize so hosts refresh a catalog that already lists swarm_doctor. Omit gate_soft_continue on unfinished soft-gap tick and fuse envelopes (never write false) and set soft_gap.tick=false. Drop bench freeze and baseline from those solidify steers. Fast-skip a watermark only when the full hash matches, so a same-size rewrite is not a silent skip. Co-authored-by: Steper Lin --- AGENTS.md | 21 ++- CHANGELOG.md | 4 + DEBUG.md | 34 ++++ README.md | 6 +- README.zh.md | 4 +- examples/swarm-quickstart/README.md | 2 +- src/evolver/gep/material.py | 17 +- src/evolver/mcp_server.py | 78 ++++++-- src/evolver/swarm.py | 174 ++++++++++++------ tests/gep/test_material.py | 21 ++- .../test_mcp_host_usability_pending_smoke.py | 114 +++++++++--- tests/test_mcp_protocol.py | 39 +++- 12 files changed, 386 insertions(+), 128 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 2894092..b5dd88a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -395,20 +395,24 @@ prompt 的宿主)。`boot_once` 只登记会话(`swarm_hook_event` session_s instrument 增加「核心循环工具 / Core Loop Tools」。soft-accept 的 T0 为 minimal (`t0_probe.py`);成功结算后 `pending_solidify` 为 false(`last_run` 与 `last_solidify` 的 run id 一致)。`swarm_boot` / `swarm_status` 带 `source_revision`, -boot 自动 ack 本 agent 的 `swarm.hello`。安装或拉代码后须重启 MCP;若宿主目录仍只列出 +boot 自动 ack 本 agent 的 `swarm.hello`。安装或拉代码后须重启 MCP。握手广告 `tools.listChanged=true`,并在 +`notifications/initialized` 之后发 `notifications/tools/list_changed`。stdio +`tools/list` 同一页(无 `nextCursor`)已含只读 `swarm_doctor`。若宿主目录仍只列出 `swarm_tick` 的 `agent_name` 与 `include_prompt`,或搜不到 `swarm_doctor`,那是客户端 -对 `tools/list` 的缓存(现网 schema 已含 `prompt_mode`/`checklist_only` 与只读 -`swarm_doctor`),新开宿主会话才会重读。 +没重读这份清单(旧会话把 `listChanged: false` 当成目录永不变)。新开宿主会话才会重读。 +服务端不另造一个假工具。 已暂停时 `next_action=await_supervisor_resume`。有待固化 run 时 `next_action` 仍是 `swarm_solidify`(`hint` 写明先固化;软缺口留在 `warning`,不盖掉这句),并带 `readonly_smoke`:只读冒烟用 `swarm_doctor` / `swarm_status`,不结算、不放宽门、不写 Parent。软缺口(`soft_continue=true`)下 `swarm_doctor` 同样给出 `next_action=swarm_solidify`、`tick_again=false` 与 preserve 三元组,不写 `gate_soft_continue`、不写 `session_not_failed`;`soft_continue` 仍为 true。 -这条引导上 `fixes` 不把 `evolver doctor --fix` 列为当前步骤;boot/status,以及 -第一次未完成 run 的 tick 与保险丝,其 `commands` 与 `next_steps` 同样不把它当成 -现在要执行的修复。没有未完成 run,或固化之后,列出这条命令仍然合适。本工具仍不执行它。 -有软缺口时,第一次 tick 与保险丝写 `gate_soft_continue=true`,不写成 false。 +这条引导上 `fixes` 不把 `evolver doctor --fix`、`evolver bench freeze` 或 +`evolver bench baseline` 列为当前步骤;boot/status,以及第一次未完成 run 的 tick +与保险丝,其 `commands` 与 `next_steps` 同样不把这三条当成现在要执行的修复。 +没有未完成 run,或固化之后,列出它们仍然合适。本工具仍不执行它们,也不写 Parent baseline。 +有软缺口时,boot/status 仍写 `gate_soft_continue=true`。第一次 tick 与保险丝不写这个键 +(缺席,不写成 false),并写 `soft_gap.advisory=true`、`soft_gap.tick=false`。 硬阻断的 doctor 仍是 `ok=false`,不另给这个动作,也不写 `tick_again`。 此时 `boot_once` 为空。忽略 `next_action` 再调 `swarm_tick` 时默认不启新周期。 第一次 `ok=true`、`severity=soft`、`cycle_started=false`、`progress=false`、 @@ -421,8 +425,7 @@ Parent。软缺口(`soft_continue=true`)下 `swarm_doctor` 同样给出 没有 `loop_fuse`。常驻 instructions 写 `loop_fuse=pending_redirect_loop`, 不把裸码当成 `next_action`。软缺口留在 `warning`。两次返回都带 `preserve_pending=true`、`abandon_run=false`、 -`action_required=swarm_solidify`(boot/status 在仍要固化时同样带上)。有软缺口时, -有软缺口时,第一次 tick 与保险丝都写 `gate_soft_continue=true`(true 不是 false,也不是再 tick 的许可;`ok` 第一次仍为 true, +`action_required=swarm_solidify`(boot/status 在仍要固化时同样带上)。有软缺口时,第一次 tick 与保险丝不写 `gate_soft_continue`(缺席不是 false,也不是再 tick 的许可;`soft_gap.advisory=true`,`soft_gap.tick=false`;`ok` 第一次仍为 true, 没有 `error`;`tick_again=false` 与 `retryable=false` 都表示不要再 tick,第一次也写 `retryable=false`)。两次 tick 都带 `session_not_failed=true`:先读它,会话没有失败。`loop_fuse` 不在 `error` 里, preserve 三元组仍指向 `swarm_solidify`。 diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e11b0b..7207f42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased ### Fixed +- **MCP 工具目录:`tools.listChanged` 改为 true,并在 initialized 后发 `notifications/tools/list_changed`**:stdio `tools/list` 本来就在同一页(无 `nextCursor`)列出只读 `swarm_doctor`。握手原先广告 `listChanged: false`,把目录当成不变的宿主会留着加工具之前的缓存:调用打到新进程,目录仍缺 `swarm_doctor`。现在广告列表可变,并在 `notifications/initialized` 之后发一次 `notifications/tools/list_changed`。不注册不存在的工具。仍忽略该通知的宿主要新开一次会话。 +- **MCP 宿主可用性:软缺口 tick 与保险丝不再用 `gate_soft_continue=true` 邀请再 tick**:第一次未完成 run 的 `swarm_tick` 与 `loop_fuse=pending_redirect_loop` 去掉这个键,不写成 false。同时写 `soft_gap.advisory=true`、`soft_gap.tick=false`。只在旗标为 true 时再 tick 的宿主停住;只把严格 false 当成整段失败的宿主不结束会话。boot / status 仍写 `gate_soft_continue=true`。`tick_again=false`、`retryable=false`、保险丝的 `ok=false`、`session_not_failed` 与 preserve 三元组不动。doctor 仍不写 `gate_soft_continue`,也不写 `soft_gap`。不结算这条 run,不写 Parent baseline,不放宽固化门。 +- **MCP 宿主可用性:软固化引导不再把 freeze / baseline 当当前步骤**:未完成 run 的 boot / status / doctor / 第一次 tick / 保险丝,从 `commands` 或 `fixes` 去掉精确的 `evolver bench freeze` 与 `evolver bench baseline`,`next_steps` 里点名它们的句子改成先 `swarm_solidify`。没有未完成 run 时这两条仍在。不执行它们,不写 Parent baseline,不放宽固化门。 +- **水印:同长度改写即使 mtime 被还原也重新摄取;相同字节重写仍是 noop**:快跳过同时核对全文哈希。mtime 与大小没变但字节变了,走全量重扫,不再记成 `skipped`。相同字节且 mtime 已变时仍是 `rewrite_noop`,不追加记录。 - **MCP 宿主可用性:未完成 run 的软缺口 tick 与保险丝写 `gate_soft_continue=true`**:第一次未完成 run 的 `swarm_tick`,以及同一条 run 再 tick 的 `loop_fuse=pending_redirect_loop`,在软缺口上保留 `apply_soft_gap` 写下的 `gate_soft_continue=true`,与 boot / status 同一口径。这个键不写成 false。`tick_again=false`、`retryable=false`、保险丝的 `ok=false`、`session_not_failed` 与 preserve 三元组不动。没有软缺口的重定向仍不写这个键。doctor 仍不写。不结算这条 run,不写 Parent baseline,不放宽固化门,不执行 `evolver doctor --fix`。 - **MCP 宿主可用性:未完成 run 的第一次 tick 与保险丝也不把 `evolver doctor --fix` 当当前步骤**:软缺口固化引导上,第一次 `swarm_tick` 与 `loop_fuse=pending_redirect_loop` 的 `commands` 去掉精确的 `evolver doctor --fix`,`next_steps` 里点名它的句子改成先 `swarm_solidify`(`next_action` / preserve / `action_required`)。`gate_soft_continue` 在这两份信封上仍缺席,不写成 false。`tick_again=false` 与保险丝的 `ok=false` 不动。没有未完成 run 的 tick、boot、doctor 仍列出这条命令。本工具仍不执行 `--fix`。不结算这条 run,不写 Parent baseline,不放宽固化门。 - **MCP 宿主可用性:软缺口固化引导不再把 `evolver doctor --fix` 当当前步骤**:未完成 run 且 soft-continue 时,`swarm_doctor` 的 `fixes` 去掉这条命令。boot / status 的 `commands` 同样去掉它,`next_steps` 里点名它的句子改成先 `swarm_solidify`(`next_action` / preserve / `action_required`)。`soft_continue` 仍为 true,`gate_soft_continue` 在 boot/status 仍为 true,doctor 仍不写这个键,也不写 `session_not_failed`。没有未完成 run 时,`fixes` / `commands` 仍列出 `evolver doctor --fix`。固化之后同样可以再列。本工具仍不执行 `--fix`。第一次 tick 与保险丝的 `commands` 不动。不结算这条 run,不写 Parent baseline,不放宽固化门。 diff --git a/DEBUG.md b/DEBUG.md index 68fa5e9..9b1d812 100644 --- a/DEBUG.md +++ b/DEBUG.md @@ -63,6 +63,10 @@ | 58 | 外部 MCP 评审 P1 四项全属实并修:solidify/propose 未取实例锁、journal 裸句柄、instructions 漏新工具、测试名实不符 + 版本硬编码 | swarm/mcp/tests | 评估会话 | 未发版 | | 69 | 未完成 run 的第一次 tick 重定向不写 `retryable`,缺席被当成再 tick | mcp/swarm | MCP 易用性 | 未发版 | | 74 | 未完成 run 的第一次 tick 与保险丝仍把 `evolver doctor --fix` 列成当前步骤 | mcp/swarm | MCP 易用性 | 未发版 | +| 76 | 宿主目录缺 `swarm_doctor`:握手广告 `listChanged: false` | mcp | MCP 易用性 | 未发版 | +| 77 | 只认 `gate_soft_continue=true` 的宿主在 tick 与保险丝上再 tick | mcp/swarm | MCP 易用性 | 未发版 | +| 78 | 软固化引导仍列出 `bench freeze` / `bench baseline` | mcp/swarm | MCP 易用性 | 未发版 | +| 79 | 相同长度改写若 mtime 被还原,水印快跳过当成未改 | material | 水印 | 未发版 | ## 条目 @@ -1273,3 +1277,33 @@ - **修复**:软缺口上的第一次 tick 与保险丝保留 true,并在 `hold_tick` 上再写一次 true,不写 false。停 tick 仍看 `tick_again=false`、`retryable=false`、`next_action=swarm_solidify`,保险丝的 `ok` 仍为 false。`session_not_failed` 与 preserve 三元组不动。没有软缺口的重定向不写这个键。doctor 仍不写。`commands` 里 `evolver doctor --fix` 的延后不动。不结算,不写 Parent baseline,不放宽固化门,不执行 `--fix`。目录缓存(DEBUG #61)未做假修复。 - **经验**:**软缺口旗标的原义是「缺口是建议」,停 tick 要写在 `tick_again` 上。** 把 true 从 tick 信封拿掉,只认这个键的宿主就和 boot 对不上。写成 false 会重开 DEBUG #67。 - **仍在**:只看 `gate_soft_continue=true`、完全不看 `tick_again` / `next_action` / `ok` / `retryable` 的宿主,第一次 tick 与保险丝之后仍可能再 tick。没有把这个旗标写成 false。doctor 仍不写 `gate_soft_continue`,只读 `soft_continue=true` 的冒烟余项仍在。把保险丝 `ok=false` 当成整段失败、且不读 `session_not_failed` 与 `loop_fuse` 的宿主(DEBUG #68 余项 2)仍会停掉会话;`ok` 留着 false。`commands` 里仍可能有 `evolver bench freeze` 与 `evolver bench baseline`。目录缓存(DEBUG #61)没有做假修复。 + +### 76. 宿主目录缺 `swarm_doctor`:`listChanged` 广告成 false(MCP 易用性,已修) + +- **症状**:stdio `tools/list` 能列出只读 `swarm_doctor`(29 个工具里的一个,无 `nextCursor`,带 `cursor` 再要一页也仍在),宿主目录(GetDynamicTools / 旧会话)却经常没有它。`swarm_tick(prompt_mode=short)` 调用行为正确,展示的参数仍只有 `agent_name` 与 `include_prompt`。 +- **根因**:注册没有漏。`MCPServer` 的握手用默认 `NotificationOptions()`,`tools.listChanged` 为 false。把「列表不变」当成可以跨重启留目录的宿主,不会重读已经换过的 `tools/list`。调用打到新进程,目录留在旧进程的快照上。不是分页把工具切掉(整页约 25KB,doctor 在中部)。 +- **修复**:初始化广告 `tools.listChanged=true`(prompts / resources 一并标可变)。`notifications/initialized` 之后发一次 `notifications/tools/list_changed`。不另注册一个假 `swarm_doctor`。测试钉住:能力位、通知、同一页且 cursor 不丢这个名字。 +- **经验**:**目录与调用分属两层,但「列表永不变」是服务端自己说的。** 先对同一进程打 `tools/list`。齐全之后,若握手仍写 `listChanged: false`,宿主缓存不是纯属仓外。仍忽略通知的宿主要新开一次会话。 +- **仍在**:不听 `notifications/tools/list_changed`、也不在新会话重读 `tools/list` 的宿主,目录仍旧。没有为它造工具。 + +### 77. 只认 `gate_soft_continue=true` 的宿主在 tick 与保险丝上再 tick(MCP 易用性,已修) + +- **症状**:#75 之后,未完成 run 的软缺口第一次 `swarm_tick` 与 `loop_fuse=pending_redirect_loop` 写 `gate_soft_continue=true`。只看这个键为 true、不看 `tick_again` / `next_action` / `ok` / `retryable` 的宿主会再 tick。写成 false 会重开 DEBUG #67。 +- **根因**:停 tick 的字段这些宿主不读。true 的原义在它们那里就是「继续」。boot / status 仍需要这个 true,软缺口才看得见。 +- **修复**:仅 tick 与保险丝去掉这个键,不写成 false。同时写 `soft_gap`(`present` / `advisory` 为 true,`tick` 为 false,`code` 为缺口码)。boot / status 仍是 `gate_soft_continue=true`,且不带 `soft_gap`。doctor 仍不写这两个。`tick_again=false`、`retryable=false`、保险丝 `ok=false`、`session_not_failed` 与 preserve 三元组不动。不结算,不写 Parent baseline,不放宽固化门。 +- **经验**:**「看见软缺口」和「不要再 tick」不要挤在同一个布尔上。** boot / status 留 true。tick 信封用缺席挡住只认 true 的宿主,用 `soft_gap` 留下建议位,用严格 false 以外的字段停 tick。 +- **仍在**:把缺席的 `gate_soft_continue` 当成继续、且不看 `tick_again` / `soft_gap.tick` / `next_action` 的宿主,仍可能再 tick。没有写成 false。boot / status 上只看 true 的宿主仍可能再 tick。doctor 上只读 `soft_continue=true` 的冒烟余项仍在。把保险丝 `ok=false` 当成整段失败、且不读 `session_not_failed` 与 `loop_fuse` 的宿主(DEBUG #68 余项 2)仍会停掉会话。 + +### 78. 软固化引导仍列出 `evolver bench freeze` / `evolver bench baseline`(MCP 易用性,已修) + +- **症状**:#73 / #74 拿掉 `evolver doctor --fix` 之后,未完成 run 的 boot / status / doctor / 第一次 tick / 保险丝的 `commands` 或 `fixes` 仍列出 `evolver bench freeze` 与 `evolver bench baseline`。只读清单的宿主会去装包或写 Parent,而不是 `swarm_solidify`。 +- **根因**:开箱目录把这两条和 `--fix` 放在一起。剥离只匹配了 `--fix` 那一条。 +- **修复**:同一条固化引导上,精确的 freeze 与 baseline 也从 `commands` / `fixes` 去掉,`next_steps` 里点名它们的句子改成先 `swarm_solidify`。没有未完成 run 时清单不变。硬阻断不改这份清单。不执行这些命令,不写 Parent baseline,不放宽固化门。 +- **经验**:**当前步骤的清单里,不该现在跑的安装命令要一起拿掉。** 只删 `--fix` 时,旁边的 freeze / baseline 会变成新的当前步骤。 + +### 79. 同长度改写若 mtime 被还原,水印当成没改过(已修) + +- **症状**:`test_identical_rewrite_is_noop` 在写后会把 mtime 还原成创建时戳的文件系统上得到 `mode=skipped`,而不是 `rewrite_noop`。同长度、内容已变、mtime 被还原成水印里那一记时,快跳过会把新字节当成未改动。 +- **根因**:快跳过只比 `mtime_ns` 与 `size`。相同字节的重写若 mtime 没留下变化,就走不到全文哈希备忘。同长度的真改写也会被这道比较吞掉。GitHub CI 的 ext4 会在写入时推进 mtime,所以这条测试在那边是绿的。 +- **修复**:快跳过同时要求 `full_hash` 与水印一致。大小与 mtime 没变但字节变了,走全量重扫。相同字节且 mtime 已经不同,仍是 `rewrite_noop`,不追加记录。测试在重写之后再 touch,避免「写入把 touch 撤掉」让用例没走到备忘路径。 +- **经验**:**mtime 不是内容。** 快跳过可以省读盘,但不能在哈希已经算出来之后还只信时间戳。 diff --git a/README.md b/README.md index fc4584a..3917994 100644 --- a/README.md +++ b/README.md @@ -237,11 +237,11 @@ For **ZCode** or direct virtualenv execution: After `uv sync`, a pull, or any install, **restart the MCP server**. A long-lived `evolver mcp` process keeps the old modules in memory. `swarm_boot` and `swarm_status` expose `source_revision` (the git SHA of the running source tree) next to `code_staleness`; boot also auto-acks this agent's own pending `swarm.hello`. -Live `tools/list` already publishes `swarm_tick` parameters `prompt_mode` (`full` or `short`) and `checklist_only`, with descriptions on those fields, and read-only `swarm_doctor`. A host catalog that still lists only `agent_name` and `include_prompt`, or that cannot find `swarm_doctor`, is a stale client session. Restarting the server reloads the code; start a new host session so the client reads `tools/list` again. +Live `tools/list` already publishes `swarm_tick` parameters `prompt_mode` (`full` or `short`) and `checklist_only`, with descriptions on those fields, and read-only `swarm_doctor`, in one page (`nextCursor` absent). Initialize advertises `tools.listChanged=true` and, after `notifications/initialized`, sends `notifications/tools/list_changed` so a host does not treat that catalog as immutable. A host catalog that still lists only `agent_name` and `include_prompt`, or that cannot find `swarm_doctor`, ignored that refresh. Start a new host session so the client reads `tools/list` again. The server does not invent a second tool entry. -If a previous run is unfinished, `swarm_boot` keeps `next_action=swarm_solidify`, sets top-level `pending_solidify`, and adds `readonly_smoke` (`tools`: `swarm_doctor` and `swarm_status`, `settles_run`: false). On a soft gap it also sets `tick_again=false` while `gate_soft_continue` stays true. `hint` says to solidify first. A soft gap (`no_baseline` / `pack_absent` / `unmeasured`) still attaches `warning` and `next_steps`, and it does not replace that hint or weaken the gate. A read-only smoke can call `swarm_doctor` or `swarm_status`; neither settles the run nor invents a Parent baseline. A `swarm_tick` in that state does not start a cycle. The first call stays soft (`ok` true, `severity` soft, `cycle_started` false, `progress` false, `redirect_count` 1, `retryable` false, `next_action` still `swarm_solidify`, `last_run` unchanged). An omitted `retryable` is not a license to tick again. The same call again on that run returns `ok` false, `loop_fuse=pending_redirect_loop`, `redirect_reason=pending_redirect_loop`, `severity` soft, `retryable` false, and no `error` field. It still does not start a cycle. `loop_fuse` and that `redirect_reason` are the tick-loop fuse. The code is not an `error` and not a `next_action`. `next_action` stays `swarm_solidify`. `dispatch_reason` stays `pending_solidify`. The first redirect keeps `redirect_reason=pending_solidify` and does not set `loop_fuse`. Connect-time instructions name `loop_fuse=pending_redirect_loop` the same way. The fuse is not a gate failure and not an abandon signal; a soft gap stays on `warning` and `next_steps`. Both returns set `preserve_pending` true, `abandon_run` false, and `action_required` to `swarm_solidify` (boot and status do too while solidify is still next). Do not drop the unfinished run. When a soft gap is present, `gate_soft_continue` is true on the first redirect and on the fuse (`tick_again` is false). True is not false and not a license to tick: the first redirect keeps `ok` true and sets no `error`, so a host that treats only a strict false as session death stays in the session. Stop-tick stays on `tick_again` and `retryable`. This path never writes `gate_soft_continue=false`. Both tick returns set `session_not_failed` true. Read that field before other flags: true means the session is not failed, and `loop_fuse` does not abandon the run when the preserve flags say to call `swarm_solidify`. `next_steps` starts with `swarm_solidify`. Boot and status keep `gate_soft_continue` true while a run is still unfinished, set `tick_again` false on that soft gap, and they do not set `session_not_failed`. Pass `supersede_pending=true` to replace that run. Pause and the compaction checkpoint still refuse the cycle. +If a previous run is unfinished, `swarm_boot` keeps `next_action=swarm_solidify`, sets top-level `pending_solidify`, and adds `readonly_smoke` (`tools`: `swarm_doctor` and `swarm_status`, `settles_run`: false). On a soft gap it also sets `tick_again=false` while `gate_soft_continue` stays true. `hint` says to solidify first. A soft gap (`no_baseline` / `pack_absent` / `unmeasured`) still attaches `warning` and `next_steps`, and it does not replace that hint or weaken the gate. A read-only smoke can call `swarm_doctor` or `swarm_status`; neither settles the run nor invents a Parent baseline. A `swarm_tick` in that state does not start a cycle. The first call stays soft (`ok` true, `severity` soft, `cycle_started` false, `progress` false, `redirect_count` 1, `retryable` false, `next_action` still `swarm_solidify`, `last_run` unchanged). An omitted `retryable` is not a license to tick again. The same call again on that run returns `ok` false, `loop_fuse=pending_redirect_loop`, `redirect_reason=pending_redirect_loop`, `severity` soft, `retryable` false, and no `error` field. It still does not start a cycle. `loop_fuse` and that `redirect_reason` are the tick-loop fuse. The code is not an `error` and not a `next_action`. `next_action` stays `swarm_solidify`. `dispatch_reason` stays `pending_solidify`. The first redirect keeps `redirect_reason=pending_solidify` and does not set `loop_fuse`. Connect-time instructions name `loop_fuse=pending_redirect_loop` the same way. The fuse is not a gate failure and not an abandon signal; a soft gap stays on `warning` and `next_steps`. Both returns set `preserve_pending` true, `abandon_run` false, and `action_required` to `swarm_solidify` (boot and status do too while solidify is still next). Do not drop the unfinished run. When a soft gap is present, the first redirect and the fuse omit `gate_soft_continue` (absent, never false) and set `soft_gap.advisory` true with `soft_gap.tick` false. `tick_again` is false. That omission is not a failed session: the first redirect keeps `ok` true and sets no `error`, so a host that treats only a strict false as session death stays in the session. Stop-tick stays on `tick_again` and `retryable`. This path never writes `gate_soft_continue=false`. Both tick returns set `session_not_failed` true. Read that field before other flags: true means the session is not failed, and `loop_fuse` does not abandon the run when the preserve flags say to call `swarm_solidify`. `next_steps` starts with `swarm_solidify`. Boot and status keep `gate_soft_continue` true while a run is still unfinished, set `tick_again` false on that soft gap, and they do not set `session_not_failed`. Pass `supersede_pending=true` to replace that run. Pause and the compaction checkpoint still refuse the cycle. -A cold `swarm_status` (this process has not called `swarm_boot`) returns `next_action=swarm_boot` and a short hint. After boot, status keeps `agent_name`, `source_revision`, and any soft `gap` / warnings. `tool_asset_search`, `tool_mailbox_poll`, `tool_cycle_timeline`, and `swarm_approvals` always return `{ok, items, hint}` — an empty match is not a blank body. `swarm_approvals` also keeps `pending` (the same rows as `items`) and `recent`. Read-only `swarm_doctor` mirrors `evolver doctor` without `--fix` (`ok`, soft warnings, command hints in `fixes`). `no_baseline` / `pack_absent` / `unmeasured` stay soft-continue. When a run is unfinished and that report is soft-continue, doctor also sets `next_action=swarm_solidify`, `tick_again=false`, `pending_solidify`, and the preserve triad (`preserve_pending`, `abandon_run=false`, `action_required=swarm_solidify`). `soft_continue` stays true. It still does not settle the run, write a Parent baseline, or execute `evolver doctor --fix`. On that steer, `fixes` does not list `evolver doctor --fix` as a current step. Boot and status `commands` and `next_steps` do not present it as the current action either. The first unfinished-run tick and the `loop_fuse=pending_redirect_loop` envelope do the same in `commands` and `next_steps`. `gate_soft_continue` is true on those soft-gap tick envelopes and is never false. The command stays listed when no run is unfinished, and after solidify. Doctor still leaves `gate_soft_continue` and `session_not_failed` absent. A hard blocker keeps `ok` false and does not add that action or `tick_again`. The first unfinished-run tick and the fuse already set `tick_again` false. +A cold `swarm_status` (this process has not called `swarm_boot`) returns `next_action=swarm_boot` and a short hint. After boot, status keeps `agent_name`, `source_revision`, and any soft `gap` / warnings. `tool_asset_search`, `tool_mailbox_poll`, `tool_cycle_timeline`, and `swarm_approvals` always return `{ok, items, hint}` — an empty match is not a blank body. `swarm_approvals` also keeps `pending` (the same rows as `items`) and `recent`. Read-only `swarm_doctor` mirrors `evolver doctor` without `--fix` (`ok`, soft warnings, command hints in `fixes`). `no_baseline` / `pack_absent` / `unmeasured` stay soft-continue. When a run is unfinished and that report is soft-continue, doctor also sets `next_action=swarm_solidify`, `tick_again=false`, `pending_solidify`, and the preserve triad (`preserve_pending`, `abandon_run=false`, `action_required=swarm_solidify`). `soft_continue` stays true. It still does not settle the run, write a Parent baseline, or execute `evolver doctor --fix`. On that steer, `fixes` does not list `evolver doctor --fix` as a current step. Boot and status `commands` and `next_steps` do not present it as the current action either. The first unfinished-run tick and the `loop_fuse=pending_redirect_loop` envelope do the same in `commands` and `next_steps`. `gate_soft_continue` is omitted on those soft-gap tick envelopes and is never false. `soft_gap.tick` is false. `evolver bench freeze` and `evolver bench baseline` are not current steps on that steer. The command stays listed when no run is unfinished, and after solidify. Doctor still leaves `gate_soft_continue` and `session_not_failed` absent. A hard blocker keeps `ok` false and does not add that action or `tick_again`. The first unfinished-run tick and the fuse already set `tick_again` false. `swarm_boot(project=...)` binds a directory only when that path exists. `bound_paths.repo_root` is the code root (the git root walked from that directory, or the directory itself). `bound_paths.workspace_root` is the mutation directory. When they differ, or when `project` is a free-text label rather than a directory, the same object carries `warning` and `next_steps`. That is a soft warning: `ok` stays true and the loop still continues. A label is not turned into a new workspace. diff --git a/README.zh.md b/README.zh.md index 3017456..7a16f97 100644 --- a/README.zh.md +++ b/README.zh.md @@ -242,7 +242,7 @@ uv run evolver migrate-state 若上一轮 run 还没固化,`swarm_boot` 的 `next_action` 仍是 `swarm_solidify`,顶层带 `pending_solidify`,并多一个 `readonly_smoke`(`tools` 为 `swarm_doctor` 与 `swarm_status`,`settles_run` 为 false)。软缺口上同时写 `tick_again=false`,`gate_soft_continue` 仍为 true。`hint` 写明先固化。软缺口(`no_baseline` / `pack_absent` / `unmeasured`)仍附 `warning` 与 `next_steps`,但不盖掉这句 hint,也不放宽固化门。只读冒烟可以调 `swarm_doctor` 或 `swarm_status`:它们不结算这条 run,也不伪造 Parent baseline。 -本进程尚未 `swarm_boot` 时,`swarm_status` 返回 `next_action=swarm_boot` 和一句 hint。boot 之后 status 仍带 `agent_name`、`source_revision`,以及软缺口的 `gap` / warnings。`tool_asset_search`、`tool_mailbox_poll`、`tool_cycle_timeline`、`swarm_approvals` 一律返回 `{ok, items, hint}`,没有命中也不是空正文。`swarm_approvals` 另外保留 `pending`(与 `items` 同一队列)和 `recent`。只读 `swarm_doctor` 等同 `evolver doctor` 且不执行 `--fix`(`ok`、软警告、`fixes` 里的命令提示)。`no_baseline` / `pack_absent` / `unmeasured` 仍是 soft-continue。有未完成 run 且这份报告是 soft-continue 时,doctor 也给出 `next_action=swarm_solidify`、`tick_again=false`、`pending_solidify` 和 preserve 三元组(`preserve_pending`、`abandon_run=false`、`action_required=swarm_solidify`)。`soft_continue` 仍为 true。它仍不结算这条 run,不写 Parent baseline,也不执行 `evolver doctor --fix`。这条引导上 `fixes` 不把 `evolver doctor --fix` 列为当前步骤。boot / status 的 `commands` 与 `next_steps`,以及第一次未完成 run 的 tick 与保险丝的 `commands` / `next_steps`,同样不把它当成现在要执行的修复。这两份软缺口 tick 信封上 `gate_soft_continue=true`,不写成 false。没有未完成 run,或固化之后,列出这条命令仍然合适。doctor 仍不写 `gate_soft_continue` 与 `session_not_failed`。硬阻断保持 `ok=false`,不另给这个动作,也不写 `tick_again`。第一次未完成 run 的 tick 与保险丝本来就写了 `tick_again=false`。 +本进程尚未 `swarm_boot` 时,`swarm_status` 返回 `next_action=swarm_boot` 和一句 hint。boot 之后 status 仍带 `agent_name`、`source_revision`,以及软缺口的 `gap` / warnings。`tool_asset_search`、`tool_mailbox_poll`、`tool_cycle_timeline`、`swarm_approvals` 一律返回 `{ok, items, hint}`,没有命中也不是空正文。`swarm_approvals` 另外保留 `pending`(与 `items` 同一队列)和 `recent`。只读 `swarm_doctor` 等同 `evolver doctor` 且不执行 `--fix`(`ok`、软警告、`fixes` 里的命令提示)。`no_baseline` / `pack_absent` / `unmeasured` 仍是 soft-continue。有未完成 run 且这份报告是 soft-continue 时,doctor 也给出 `next_action=swarm_solidify`、`tick_again=false`、`pending_solidify` 和 preserve 三元组(`preserve_pending`、`abandon_run=false`、`action_required=swarm_solidify`)。`soft_continue` 仍为 true。它仍不结算这条 run,不写 Parent baseline,也不执行 `evolver doctor --fix`。这条引导上 `fixes` 不把 `evolver doctor --fix` 列为当前步骤。boot / status 的 `commands` 与 `next_steps`,以及第一次未完成 run 的 tick 与保险丝的 `commands` / `next_steps`,同样不把它当成现在要执行的修复。这两份软缺口 tick 信封不写 `gate_soft_continue`(缺席,不写成 false),并带 `soft_gap.advisory=true`、`soft_gap.tick=false`。`evolver bench freeze` 与 `evolver bench baseline` 也不是当前步骤。没有未完成 run,或固化之后,列出这条命令仍然合适。doctor 仍不写 `gate_soft_continue` 与 `session_not_failed`。硬阻断保持 `ok=false`,不另给这个动作,也不写 `tick_again`。第一次未完成 run 的 tick 与保险丝本来就写了 `tick_again=false`。 `swarm_boot(project=...)` 只在路径是已存在目录时绑定。`bound_paths.repo_root` 是代码根(从该目录向上找到的 git 根,否则就是该目录本身)。`bound_paths.workspace_root` 是变异所用目录。两者不一致,或 `project` 只是一段自由文本而不是目录时,同一对象带 `warning` 和 `next_steps`。这是软警告:`ok` 仍为 true,循环继续。自由文本不会被当成新的工作区。 @@ -277,7 +277,7 @@ uv run evolver migrate-state soft-accept 选用 minimal T0 探针(`determine_t0_mode` 返回 `minimal`;`skip` 也已实现)。验收钩子(`solidify_hook`)在本轮已标 `soft_accept` 时按这个深度跑。硬接受仍跑完整 T0。若结算裁决带了 skip 或 minimal 探针,warnings 里会有 `t0_skipped_soft` 或 `t0_probe=minimal`。 -`pending_solidify` 仅在 `last_run.run_id` 与 `last_solidify.run_id` 不同时为真。成功的 solidify(含 soft-accept)会写下 `last_solidify`,下一次 status 或 boot 报告 `pending_solidify: false`,开局动作回到 `swarm_tick`。仍有待固化 run 时,`boot_once` 为空,宿主先固化。此时再调 `swarm_tick` 默认不启新周期。第一次仍是软返回(`ok` 为 true,`severity=soft`,`cycle_started=false`,`progress=false`,`redirect_count=1`,`next_action` 仍是 `swarm_solidify`,不改 `last_run`)。同一条 run 再 tick 返回 `ok=false`、`loop_fuse=pending_redirect_loop`、`redirect_reason=pending_redirect_loop`、`severity=soft`、`retryable=false`,并且没有 `error` 字段,仍然不启周期。`loop_fuse` 与这个 `redirect_reason` 是 tick 空转保险丝,不是 `error`,也不是 `next_action`。`next_action` 仍是 `swarm_solidify`。`dispatch_reason` 仍是 `pending_solidify`。第一次重定向的 `redirect_reason` 仍是 `pending_solidify`,没有 `loop_fuse`。常驻 instructions 写 `loop_fuse=pending_redirect_loop`。这不是门禁失败,也不是放弃;软缺口留在 `warning` 与 `next_steps`。两次返回都带 `preserve_pending=true`、`abandon_run=false`、`action_required=swarm_solidify`(boot 与 status 在仍要固化时同样带上)。不要丢掉这条未完成 run。有软缺口时,第一次 tick 与保险丝都写 `gate_soft_continue=true`(true 不是 false,也不是再 tick 的许可;`ok` 第一次仍为 true,没有 `error`;`tick_again=false` 与 `retryable=false` 都表示不要再 tick,第一次也写 `retryable=false`)。这条路径不写 `gate_soft_continue=false`。只把严格 false 当成整段会话失败的宿主因此不会停掉会话。两次 tick 都带 `session_not_failed=true`:先读这个字段,会话没有失败;`loop_fuse` 不在 `error` 里,preserve 三元组仍指向 `swarm_solidify`。`next_steps` 第一条是调用 `swarm_solidify`。boot 与 status 的 `gate_soft_continue` 仍为 true,未完成软缺口同时写 `tick_again=false`,且不带 `session_not_failed`。要替换这条 run 才传 `supersede_pending=true`。暂停与压缩检查点仍优先于这个参数。 +`pending_solidify` 仅在 `last_run.run_id` 与 `last_solidify.run_id` 不同时为真。成功的 solidify(含 soft-accept)会写下 `last_solidify`,下一次 status 或 boot 报告 `pending_solidify: false`,开局动作回到 `swarm_tick`。仍有待固化 run 时,`boot_once` 为空,宿主先固化。此时再调 `swarm_tick` 默认不启新周期。第一次仍是软返回(`ok` 为 true,`severity=soft`,`cycle_started=false`,`progress=false`,`redirect_count=1`,`next_action` 仍是 `swarm_solidify`,不改 `last_run`)。同一条 run 再 tick 返回 `ok=false`、`loop_fuse=pending_redirect_loop`、`redirect_reason=pending_redirect_loop`、`severity=soft`、`retryable=false`,并且没有 `error` 字段,仍然不启周期。`loop_fuse` 与这个 `redirect_reason` 是 tick 空转保险丝,不是 `error`,也不是 `next_action`。`next_action` 仍是 `swarm_solidify`。`dispatch_reason` 仍是 `pending_solidify`。第一次重定向的 `redirect_reason` 仍是 `pending_solidify`,没有 `loop_fuse`。常驻 instructions 写 `loop_fuse=pending_redirect_loop`。这不是门禁失败,也不是放弃;软缺口留在 `warning` 与 `next_steps`。两次返回都带 `preserve_pending=true`、`abandon_run=false`、`action_required=swarm_solidify`(boot 与 status 在仍要固化时同样带上)。不要丢掉这条未完成 run。有软缺口时,第一次 tick 与保险丝不写 `gate_soft_continue`(缺席不是 false,也不是再 tick 的许可;`soft_gap.advisory=true`,`soft_gap.tick=false`;`ok` 第一次仍为 true,没有 `error`;`tick_again=false` 与 `retryable=false` 都表示不要再 tick,第一次也写 `retryable=false`)。这条路径不写 `gate_soft_continue=false`。只把严格 false 当成整段会话失败的宿主因此不会停掉会话。两次 tick 都带 `session_not_failed=true`:先读这个字段,会话没有失败;`loop_fuse` 不在 `error` 里,preserve 三元组仍指向 `swarm_solidify`。`next_steps` 第一条是调用 `swarm_solidify`。boot 与 status 的 `gate_soft_continue` 仍为 true,未完成软缺口同时写 `tick_again=false`,且不带 `session_not_failed`。要替换这条 run 才传 `supersede_pending=true`。暂停与压缩检查点仍优先于这个参数。 下列情况仍硬停(不要重试同一次失败):diff 里的密钥或凭据、改写 `~/.evolver/` 下的引擎状态、`val_seal` 泄露。损坏的 bench 门(`gate_error`)以及验证面改动的 anchor 失败也会拒绝。没有假说时本轮仍被拒(`hypothesis_missing`),直到 `swarm_hypothesis` 成功。 diff --git a/examples/swarm-quickstart/README.md b/examples/swarm-quickstart/README.md index 0434b10..e1a05de 100644 --- a/examples/swarm-quickstart/README.md +++ b/examples/swarm-quickstart/README.md @@ -50,7 +50,7 @@ swarm_boot ─▶ swarm_status ─▶ swarm_hook_event(信号采集) | `claude-code.mcp.json` | Claude Code | 项目根 `.mcp.json` | | `cursor-mcp.json` | Cursor | `.cursor/mcp.json` | -连上之后,本条消息已有别的任务就做那件事。没有别的任务时宿主调用 `swarm_boot`,再用一句话说明实际状态。若只调了 `swarm_status` 且本进程还没 boot,`next_action` 是 `swarm_boot`。空的 `tool_asset_search` / `tool_mailbox_poll` / `tool_cycle_timeline` / `swarm_approvals` 返回 `{ok, items, hint}`(`swarm_approvals` 另含 `pending` 与 `recent`)。`swarm_tick` 的 `prompt_mode` 默认 `full`;短载荷须显式 `prompt_mode=short` 或 `checklist_only=true`,此时 `engine_log` 不再内联 GEP 全文。只读 `swarm_doctor` 等同 `evolver doctor`(不执行 `--fix`)。有未完成 run 且 doctor 为 soft-continue 时,它的 `next_action` 也是 `swarm_solidify`,并写 `tick_again=false`(`soft_continue` 仍为 true;不写 `gate_soft_continue` / `session_not_failed`,不结算,不写 Parent,不执行 `evolver doctor --fix`。这条路径的 `fixes`、boot/status 的 `commands` 与 `next_steps`,以及第一次未完成 run 的 tick 与保险丝的 `commands` / `next_steps`,不把 `evolver doctor --fix` 当成当前步骤(tick 上软缺口写 `gate_soft_continue=true`,不写成 false);没有未完成 run,或固化之后,列出它仍然合适)。宿主工具目录若仍看不到 `prompt_mode` / `checklist_only` 或 `swarm_doctor`,那是客户端对 `tools/list` 的缓存:重启 MCP 进程后新开一次会话才会重读。有未完成 run 时 `swarm_boot` 的 `next_action` 仍是 `swarm_solidify`,软缺口同时写 `tick_again=false`(`gate_soft_continue` 仍为 true),`hint` 写明先固化,并带 `readonly_smoke`(`swarm_doctor` / `swarm_status` 不结算、不放宽门);软缺口留在 `warning`。此时直接 `swarm_tick` 不启新周期(第一次 `cycle_started=false`、`ok=true`、`progress=false`,不改 `last_run`;同一条 run 再 tick 得到 `ok=false`、`loop_fuse=pending_redirect_loop`、`redirect_reason=pending_redirect_loop`,没有 `error` 字段,`next_action` 仍是 `swarm_solidify`(保险丝码不是 `next_action`;`dispatch_reason` 仍是 `pending_solidify`;第一次的 `redirect_reason` 仍是 `pending_solidify`),仍不启周期,不是门禁失败,也不是放弃;两次都带 `preserve_pending=true`、`abandon_run=false`,不要丢掉这条 run。有软缺口时第一次 tick 与保险丝都写 `gate_soft_continue=true`(true 不是 false,也不是再 tick 的许可;`ok` 第一次仍为 true,没有 `error`;`tick_again=false` 与 `retryable=false` 都表示不要再 tick,第一次也写 `retryable=false`;两次都带 `session_not_failed=true`,先读它,会话没有失败,`loop_fuse` 不放弃这条 run;`next_steps` 第一条是 `swarm_solidify`)。boot / status 的 `gate_soft_continue` 仍为 true,未完成软缺口同时写 `tick_again=false`,且不带 `session_not_failed`)。要替换才传 `supersede_pending=true`。`boot_once` 只登记会话,不在开机时同步技能。冻结包未装或没有基线时 boot / `swarm_tick` **soft-continue**(带 warnings + next_steps,可进入循环);Accept/publish 可 soft-accept(不伪造 Parent baseline、不打开 val 密封材料)。已暂停时仍返回 `await_supervisor_resume`。用户说「停」,宿主调用 `swarm_supervise` action=pause;说「继续」,宿主转达 resume。也可以对它说「启动蜂群进化」。返回的 instrument 按步执行 `swarm_tick → 执行 → swarm_distill → swarm_hypothesis → swarm_solidify → swarm_feedback`,直到终止条件。`swarm_hypothesis` 可带 `expected_outcome` 写预计通过的检查,结算时引擎对照实测写 `prediction_delta`;上一轮输出被截断时按问题调用 `episode_inspect` 读回原文;收到压缩信号或连续 4 次固化失败时先调 `swarm_checkpoint_working` 写下 `WORKING_SESSION.md`。`dispatch_prompt` 标 **PROPOSAL REQUIRED** 时改走 `swarm_propose`,不得自由编辑。`next_action=await_human_approval` 停住:`swarm_approvals` 读给人,人决定后才 `swarm_approval_resolve`。 +连上之后,本条消息已有别的任务就做那件事。没有别的任务时宿主调用 `swarm_boot`,再用一句话说明实际状态。若只调了 `swarm_status` 且本进程还没 boot,`next_action` 是 `swarm_boot`。空的 `tool_asset_search` / `tool_mailbox_poll` / `tool_cycle_timeline` / `swarm_approvals` 返回 `{ok, items, hint}`(`swarm_approvals` 另含 `pending` 与 `recent`)。`swarm_tick` 的 `prompt_mode` 默认 `full`;短载荷须显式 `prompt_mode=short` 或 `checklist_only=true`,此时 `engine_log` 不再内联 GEP 全文。只读 `swarm_doctor` 等同 `evolver doctor`(不执行 `--fix`)。有未完成 run 且 doctor 为 soft-continue 时,它的 `next_action` 也是 `swarm_solidify`,并写 `tick_again=false`(`soft_continue` 仍为 true;不写 `gate_soft_continue` / `session_not_failed`,不结算,不写 Parent,不执行 `evolver doctor --fix`。这条路径的 `fixes`、boot/status 的 `commands` 与 `next_steps`,以及第一次未完成 run 的 tick 与保险丝的 `commands` / `next_steps`,不把 `evolver doctor --fix`、`evolver bench freeze` 或 `evolver bench baseline` 当成当前步骤(tick 上软缺口不写 `gate_soft_continue`,不写成 false,并写 `soft_gap.tick=false`);没有未完成 run,或固化之后,列出它仍然合适)。宿主工具目录若仍看不到 `prompt_mode` / `checklist_only` 或 `swarm_doctor`,那是客户端没重读 `tools/list`。握手现已广告 `tools.listChanged=true`,并在 initialized 之后发 `notifications/tools/list_changed`。仍忽略的宿主要新开一次会话。服务端不另造假工具。有未完成 run 时 `swarm_boot` 的 `next_action` 仍是 `swarm_solidify`,软缺口同时写 `tick_again=false`(`gate_soft_continue` 仍为 true),`hint` 写明先固化,并带 `readonly_smoke`(`swarm_doctor` / `swarm_status` 不结算、不放宽门);软缺口留在 `warning`。此时直接 `swarm_tick` 不启新周期(第一次 `cycle_started=false`、`ok=true`、`progress=false`,不改 `last_run`;同一条 run 再 tick 得到 `ok=false`、`loop_fuse=pending_redirect_loop`、`redirect_reason=pending_redirect_loop`,没有 `error` 字段,`next_action` 仍是 `swarm_solidify`(保险丝码不是 `next_action`;`dispatch_reason` 仍是 `pending_solidify`;第一次的 `redirect_reason` 仍是 `pending_solidify`),仍不启周期,不是门禁失败,也不是放弃;两次都带 `preserve_pending=true`、`abandon_run=false`,不要丢掉这条 run。有软缺口时第一次 tick 与保险丝不写 `gate_soft_continue`(缺席不是 false,也不是再 tick 的许可;`soft_gap.advisory=true`,`soft_gap.tick=false`;`ok` 第一次仍为 true,没有 `error`;`tick_again=false` 与 `retryable=false` 都表示不要再 tick,第一次也写 `retryable=false`;两次都带 `session_not_failed=true`,先读它,会话没有失败,`loop_fuse` 不放弃这条 run;`next_steps` 第一条是 `swarm_solidify`)。boot / status 的 `gate_soft_continue` 仍为 true,未完成软缺口同时写 `tick_again=false`,且不带 `session_not_failed`)。要替换才传 `supersede_pending=true`。`boot_once` 只登记会话,不在开机时同步技能。冻结包未装或没有基线时 boot / `swarm_tick` **soft-continue**(带 warnings + next_steps,可进入循环);Accept/publish 可 soft-accept(不伪造 Parent baseline、不打开 val 密封材料)。已暂停时仍返回 `await_supervisor_resume`。用户说「停」,宿主调用 `swarm_supervise` action=pause;说「继续」,宿主转达 resume。也可以对它说「启动蜂群进化」。返回的 instrument 按步执行 `swarm_tick → 执行 → swarm_distill → swarm_hypothesis → swarm_solidify → swarm_feedback`,直到终止条件。`swarm_hypothesis` 可带 `expected_outcome` 写预计通过的检查,结算时引擎对照实测写 `prediction_delta`;上一轮输出被截断时按问题调用 `episode_inspect` 读回原文;收到压缩信号或连续 4 次固化失败时先调 `swarm_checkpoint_working` 写下 `WORKING_SESSION.md`。`dispatch_prompt` 标 **PROPOSAL REQUIRED** 时改走 `swarm_propose`,不得自由编辑。`next_action=await_human_approval` 停住:`swarm_approvals` 读给人,人决定后才 `swarm_approval_resolve`。 ## 开箱 / Open box(首次准备的一条命令) diff --git a/src/evolver/gep/material.py b/src/evolver/gep/material.py index 88c35cd..202860b 100644 --- a/src/evolver/gep/material.py +++ b/src/evolver/gep/material.py @@ -5,7 +5,7 @@ logs, llm traces, tool events) enter ONE pipeline here instead of being re-scanned wholesale every cycle: -- **Watermark dedup** per source file: ``(mtime_ns, size)`` fast-skip; +- **Watermark dedup** per source file: ``(mtime_ns, size, full_hash)`` fast-skip; grew-with-identical-head ⇒ append-only delta from the old size (aligned to the next newline); otherwise full rescan with a bounded full-content memo catching rewrite/rename/truncate no-ops. @@ -176,14 +176,21 @@ def ingest_file(path: Path | str, *, kind: str = "session_log") -> dict[str, Any wm = watermarks.get(source_key) data = src.read_bytes() + full_hash = hashlib.sha256(data).hexdigest() + recent = list(wm.get("recent_full_hashes", [])) if wm else [] - # Fast-skip: mtime+size unchanged. - if wm is not None and wm.get("size") == stat.st_size and wm.get("mtime_ns") == stat.st_mtime_ns: + # Fast-skip only when the bytes match too. A same-size rewrite that + # preserves mtime (some filesystems restore the previous stamp on write) + # must not be treated as unchanged. + if ( + wm is not None + and wm.get("size") == stat.st_size + and wm.get("mtime_ns") == stat.st_mtime_ns + and wm.get("full_hash") == full_hash + ): return summary # Rewrite no-op: identical full content seen recently. - full_hash = hashlib.sha256(data).hexdigest() - recent = list(wm.get("recent_full_hashes", [])) if wm else [] if full_hash in recent: watermarks[source_key] = { **(wm or {}), diff --git a/src/evolver/mcp_server.py b/src/evolver/mcp_server.py index e3c0436..3cc4e72 100644 --- a/src/evolver/mcp_server.py +++ b/src/evolver/mcp_server.py @@ -334,6 +334,46 @@ def standing_instructions() -> str: ) +def _enable_tool_catalog_refresh(server: Any) -> None: + """Tell hosts the tool list can change, and ping them once they initialize. + + ``tools.listChanged`` defaults to false. A host that treats that as + "catalog is immutable" keeps a session cache from before ``swarm_doctor`` + existed: calls hit the new process, ``tools/list`` on that process already + includes the tool, and the host catalog still omits it. Advertising + ``listChanged`` and sending ``notifications/tools/list_changed`` after + ``notifications/initialized`` is the server-side refresh. This does not + register a tool the server does not implement. + """ + low = server._lowlevel_server + original = low.create_initialization_options + + def create_initialization_options(*args: Any, **kwargs: Any) -> Any: + from mcp.server.lowlevel.server import NotificationOptions + + if not args and kwargs.get("notification_options") is None: + kwargs["notification_options"] = NotificationOptions( + prompts_changed=True, + resources_changed=True, + tools_changed=True, + ) + return original(*args, **kwargs) + + low.create_initialization_options = create_initialization_options + + async def _on_initialized(ctx: Any, params: Any) -> None: + _ = params + await ctx.session.send_tool_list_changed() + + from mcp_types import NotificationParams + + low.add_notification_handler( + "notifications/initialized", + NotificationParams, + _on_initialized, + ) + + def build_server() -> Any: """Construct the MCP server instance (stdio transport via ``run``).""" from mcp.server.mcpserver import MCPServer @@ -423,7 +463,8 @@ def tool_swarm_boot( directory, is a soft warning; the loop still continues. An unfinished run on a soft gap keeps next_action=swarm_solidify, gate_soft_continue=true, and tick_again=false. This steer does not - list evolver doctor --fix as a current step in commands or next_steps. + list evolver doctor --fix, evolver bench freeze, or evolver bench + baseline as a current step in commands or next_steps. This call does not settle the run or write a Parent baseline. """ from evolver.swarm import swarm_boot @@ -473,12 +514,13 @@ async def tool_swarm_tick( "is not a gate failure and not an abandon signal. Both returns set " "session_not_failed=true, preserve_pending=true, " "abandon_run=false, and action_required=swarm_solidify. " - "A soft gap stays in warning. gate_soft_continue=true " - "on those redirects: true is not false and not a license to " - "tick, so do not treat the session as failed. This path never " - "writes gate_soft_continue=false. tick_again=false means do " + "A soft gap stays in warning. Boot and status keep " + "gate_soft_continue=true. The first redirect and the fuse omit " + "that key and set soft_gap.advisory=true with soft_gap.tick=false. " + "Absent is not false. This path never writes " + "gate_soft_continue=false. tick_again=false means do " "not tick. The first redirect keeps ok true and sets no error. " - "true starts a new cycle " + "supersede_pending=true starts a new cycle " "and replaces that run. Does not weaken the solidify gate " "or write a Parent baseline. Checkpoint and pause still " "refuse the cycle." @@ -510,14 +552,15 @@ async def tool_swarm_tick( action_required=swarm_solidify. Read session_not_failed before other flags. True means the session is not failed: do not drop the unfinished run, call swarm_solidify. A soft gap stays in warning. - On a soft gap, gate_soft_continue=true on the first redirect and on the - fuse. True is the soft gap, not a license to tick, and it is not false, - so do not treat the session as failed. This path never writes - gate_soft_continue=false. tick_again=false means do not tick. + On a soft gap, boot and status keep gate_soft_continue=true. The first + redirect and the fuse omit that key and set soft_gap.advisory=true with + soft_gap.tick=false. Absent is not false, so do not treat the session + as failed. This path never writes gate_soft_continue=false. + tick_again=false means do not tick. The first redirect keeps ok true and sets no error. - This steer does not list evolver doctor --fix as the current step - in commands or next_steps. The command stays listed when no run is - unfinished. + This steer does not list evolver doctor --fix, evolver bench freeze, + or evolver bench baseline as the current step in commands or next_steps. + Those commands stay listed when no run is unfinished. This call does not execute it. Pass supersede_pending=true to replace that run. This does not weaken the solidify gate and does not write a Parent baseline. @@ -659,7 +702,8 @@ def tool_swarm_status() -> dict[str, Any]: After boot, an unfinished run on a soft gap keeps next_action=swarm_solidify, gate_soft_continue=true, and tick_again=false. This steer does not - list evolver doctor --fix as a current step in commands or next_steps. + list evolver doctor --fix, evolver bench freeze, or evolver bench + baseline as a current step in commands or next_steps. This call does not settle the run or write a Parent baseline. """ from evolver.swarm import swarm_status @@ -671,8 +715,9 @@ def tool_swarm_doctor() -> dict[str, Any]: While a run is unfinished and the report is soft-continue, next_action is swarm_solidify and tick_again=false. soft_continue stays true. - fixes does not list evolver doctor --fix as a current step. - That command stays listed when no run is unfinished, and after solidify. + fixes does not list evolver doctor --fix, evolver bench freeze, or + evolver bench baseline as a current step. + Those commands stay listed when no run is unfinished, and after solidify. This call does not settle the run, write a Parent baseline, or execute evolver doctor --fix. gate_soft_continue and session_not_failed stay absent. """ @@ -958,6 +1003,7 @@ def resource_events_recent() -> list[dict[str, Any]]: )(fn) server.prompt(name="evolver_swarm", title="Evolver Swarm Takeover")(prompt_evolver_swarm) + _enable_tool_catalog_refresh(server) return server diff --git a/src/evolver/swarm.py b/src/evolver/swarm.py index 7fb6909..6f9fb6b 100644 --- a/src/evolver/swarm.py +++ b/src/evolver/swarm.py @@ -303,10 +303,11 @@ def build_instrument_prompt(state: dict[str, Any]) -> str: `action_required=swarm_solidify`。 `session_not_failed=true` 表示会话没有失败, 先读它再读别的旗标。`tick_again=false` 与 `retryable=false` 都表示不要再 tick (第一次重定向也写 `retryable=false`,`ok` 仍为 true)。 - 有软缺口时第一次 tick 与保险丝都写 `gate_soft_continue=true` - (`ok` 第一次仍为 true,没有 `error`):true 不是 false, - 不是失败的会话,也不是再 tick 的许可,软缺口仍在 `warning`。 - 停 tick 看 `tick_again=false`。再 tick 才是 `ok=false`、 + boot 与 status 的 `gate_soft_continue=true` 仍在。第一次 tick 与保险丝不写这个键 + (缺席,不写成 false),并写 `soft_gap.advisory=true`、`soft_gap.tick=false` + (`ok` 第一次仍为 true,没有 `error`):缺席不是失败的会话, + 也不是再 tick 的许可,软缺口仍在 `warning` 与 `soft_gap`。 + 停 tick 看 `tick_again=false` 与 `soft_gap.tick=false`。再 tick 才是 `ok=false`、 `loop_fuse=pending_redirect_loop`、`redirect_reason=pending_redirect_loop`、 没有 `error` 字段、`next_action` 仍是 `swarm_solidify`(保险丝码不是 `next_action`)、`severity=soft`、`retryable=false`:这不是门禁失败,也不放弃 @@ -358,7 +359,8 @@ def build_instrument_prompt(state: dict[str, Any]) -> str: 调用 `swarm_solidify`。`next_action` 仍是 `swarm_solidify`。没有 `error` 字段。 不是固化门失败,也不是整段会话失败。先读 `session_not_failed`,再读 `preserve_pending=true`、`abandon_run=false`,不要放弃这条 run。有软缺口时 - 第一次 tick 与保险丝的 `gate_soft_continue=true`,true 不是再 tick 的许可。 + 第一次 tick 与保险丝不写 `gate_soft_continue`(缺席,不写成 false), + `soft_gap.tick=false` 不是再 tick 的许可。 `retryable=true` 的拒绝是稳态,回到步骤 1。 @@ -409,8 +411,9 @@ def build_instrument_prompt(state: dict[str, Any]) -> str: `evolver setup` / `evolver doctor --fix` / `evolver bench freeze`。 有未完成 run 时,这条命令不是当前步骤:先 `swarm_solidify`。 此时 `swarm_doctor` 的 `fixes`、boot/status 的 `commands`,以及第一次 - tick 与保险丝的 `commands` 和 `next_steps`,都不把 `evolver doctor --fix` - 当当前步骤。没有未完成 run,或固化之后,列出它仍然合适。 + tick 与保险丝的 `commands` 和 `next_steps`,都不把 `evolver doctor --fix`、 + `evolver bench freeze` 或 `evolver bench baseline` 当当前步骤。没有未完成 run, + 或固化之后,列出它们仍然合适。 soft-accept 可发布但会警告;装包仍强烈推荐。 - `reason=no_baseline`:**可继续**。建议在另一上下文写好 val 沙箱后执行 `evolver bench baseline`(或 doctor --fix 在沙箱齐时测量)。基线不由候选 @@ -810,6 +813,15 @@ def swarm_status() -> dict[str, Any]: _DOCTOR_FIX_COMMAND: Final = "evolver doctor --fix" +_BENCH_FREEZE_COMMAND: Final = "evolver bench freeze" +_BENCH_BASELINE_COMMAND: Final = "evolver bench baseline" +_STEER_COMMANDS_NOT_CURRENT: Final = frozenset( + { + _DOCTOR_FIX_COMMAND, + _BENCH_FREEZE_COMMAND, + _BENCH_BASELINE_COMMAND, + } +) _DOCTOR_FIX_NOT_CURRENT: Final = ( "Current action is swarm_solidify " "(next_action, preserve_pending, action_required). " @@ -817,14 +829,26 @@ def swarm_status() -> dict[str, Any]: "That command is appropriate after this run is solidified, " "or when no run is unfinished." ) +_BENCH_NOT_CURRENT: Final = ( + "Current action is swarm_solidify " + "(next_action, preserve_pending, action_required). " + "Do not run evolver bench freeze or evolver bench baseline before solidify. " + "This steer does not settle the run and does not write a Parent baseline. " + "Those commands are appropriate after this run is solidified, " + "or when no run is unfinished." +) def _commands_without_current_doctor_fix(items: list[Any] | None) -> list[str]: - """Drop the exact ``evolver doctor --fix`` command. Other commands stay.""" + """Drop setup commands that are not the current solidify step. + + Exact ``evolver doctor --fix``, ``evolver bench freeze``, and + ``evolver bench baseline`` leave the list. Other commands stay. + """ kept: list[str] = [] for item in items or []: text = str(item).strip() - if not text or text == _DOCTOR_FIX_COMMAND: + if not text or text in _STEER_COMMANDS_NOT_CURRENT: continue if text not in kept: kept.append(text) @@ -832,14 +856,18 @@ def _commands_without_current_doctor_fix(items: list[Any] | None) -> list[str]: def _steps_without_current_doctor_fix(items: list[Any] | None) -> list[str]: - """Replace a step that tells the host to run ``evolver doctor --fix`` now.""" + """Replace a step that tells the host to run setup commands now.""" kept: list[str] = [] for item in items or []: text = str(item).strip() if not text: continue - if text != _DOCTOR_FIX_NOT_CURRENT and _DOCTOR_FIX_COMMAND in text: - text = _DOCTOR_FIX_NOT_CURRENT + if text not in (_DOCTOR_FIX_NOT_CURRENT, _BENCH_NOT_CURRENT): + mentions_bench = _BENCH_FREEZE_COMMAND in text or _BENCH_BASELINE_COMMAND in text + if _DOCTOR_FIX_COMMAND in text: + text = _DOCTOR_FIX_NOT_CURRENT + elif mentions_bench: + text = _BENCH_NOT_CURRENT if text not in kept: kept.append(text) return kept @@ -875,9 +903,10 @@ def _attach_unfinished_run_to_doctor(report: dict[str, Any]) -> dict[str, Any]: only on strict false would tick again. ``soft_continue`` stays true: that bit means the gap is not a hard stop. Unfinished soft-gap boot and status set the same ``tick_again`` false and keep ``gate_soft_continue`` true. - ``fixes`` does not list ``evolver doctor --fix`` as a current step. That - command stays listed when no run is unfinished. This does not run - ``--fix`` and does not write a Parent baseline. + ``fixes`` does not list ``evolver doctor --fix``, ``evolver bench freeze``, + or ``evolver bench baseline`` as a current step. Those commands stay + listed when no run is unfinished. This does not run ``--fix``, does not + freeze a pack, and does not write a Parent baseline. """ if not _pending_solidify_state(): return report @@ -898,10 +927,12 @@ def _attach_unfinished_run_to_doctor(report: dict[str, Any]) -> dict[str, Any]: "This doctor call does not settle the run, does not write a Parent " "baseline, and does not relax the solidify gate. " "Soft gaps stay advisory. Do not apply fixes before swarm_solidify. " - "fixes does not list `evolver doctor --fix` as a current step. " + "fixes does not list `evolver doctor --fix`, `evolver bench freeze`, " + "or `evolver bench baseline` as a current step. " "Do not run evolver doctor --fix before solidify. " - "This tool does not execute it. " - "That command is appropriate after this run is solidified, " + "Do not run evolver bench freeze or evolver bench baseline before solidify. " + "This tool does not execute them. " + "Those commands are appropriate after this run is solidified, " "or when no run is unfinished. " ) out["hint"] = lead + str(out.get("hint") or "") @@ -917,8 +948,9 @@ def swarm_doctor() -> dict[str, Any]: hints for the host to show a person; this function never runs them. A soft-continue report with an unfinished run also sets ``next_action=swarm_solidify`` and ``tick_again=false``. ``soft_continue`` - stays true. On that steer, ``fixes`` does not list ``evolver doctor --fix`` - as a current step. The command stays listed when no run is unfinished. + stays true. On that steer, ``fixes`` does not list ``evolver doctor --fix``, + ``evolver bench freeze``, or ``evolver bench baseline`` as a current step. + Those commands stay listed when no run is unfinished. A hard blocker does not gain either field. """ from evolver.ops.open_box import SOFT_GAP_ERRORS, doctor @@ -1103,8 +1135,8 @@ def _stamp_preserve_pending(payload: dict[str, Any]) -> None: def _stamp_session_not_failed(payload: dict[str, Any]) -> None: """The unfinished-run tick redirect is not a failed session. - A soft-gap redirect keeps ``gate_soft_continue`` true. ``loop_fuse= - pending_redirect_loop`` is the tick fuse and is not an ``error``. + A soft-gap redirect omits ``gate_soft_continue`` and sets ``soft_gap``. + ``loop_fuse=pending_redirect_loop`` is the tick fuse and is not an ``error``. Hosts read ``session_not_failed`` before either signal. True means call ``swarm_solidify`` and keep the run. The preserve triad still says how. Absent on boot, status, and a real cycle: this flag is not a general @@ -1122,13 +1154,14 @@ def _prefer_solidify_steps( """Name ``swarm_solidify`` as the next call while a run is unfinished. ``hold_tick`` is only the pending tick redirect that already carries a - soft gap. ``apply_soft_gap`` sets ``gate_soft_continue`` true. This keeps - that true on the first redirect and on the fuse, the same advisory bit - boot and status already show. True is not a license to tick: - ``tick_again`` stays false. This never writes false. Strict false is - session death for a host that ignores ``session_not_failed``. ``ok`` and - ``error`` are left alone. Boot and status keep the same true and also - set ``tick_again`` false. Doctor still omits the key. + soft gap. ``apply_soft_gap`` sets ``gate_soft_continue`` true. This drops + that key on the first redirect and on the fuse. Absent is not true, so a + host that ticks only while the flag is true stops. Absent is not false, so + a host that dies on strict false stays up. ``soft_gap.advisory`` stays true + and ``soft_gap.tick`` is false. ``tick_again`` stays false. This never + writes false. Boot and status keep the true bit and also set + ``tick_again`` false. Doctor still omits the key and does not set + ``soft_gap``. """ rid = str(run_id if run_id is not None else payload.get("run_id") or "").strip() who = f"run_id={rid}" if rid else "this unfinished run" @@ -1141,8 +1174,9 @@ def _prefer_solidify_steps( if hold_tick and not closed: lead += ( " session_not_failed=true. " - "gate_soft_continue=true. " - "True is the soft gap, not a license to tick, and not a failed session. " + "gate_soft_continue is absent, not false. " + "soft_gap.advisory=true. soft_gap.tick=false. " + "Absent is not a license to tick, and not a failed session. " "tick_again=false means do not tick. " "ok is still true and there is no error. " "retryable=false means do not tick." @@ -1150,8 +1184,9 @@ def _prefer_solidify_steps( elif hold_tick and closed: lead += ( " session_not_failed=true. " - "gate_soft_continue=true. " - "True is the soft gap, not a license to tick, and not a failed session. " + "gate_soft_continue is absent, not false. " + "soft_gap.advisory=true. soft_gap.tick=false. " + "Absent is not a license to tick, and not a failed session. " "tick_again=false means do not tick. " "loop_fuse=pending_redirect_loop is not an error field. " "redirect_reason=pending_redirect_loop is that fuse, not a next_action. " @@ -1182,12 +1217,22 @@ def _prefer_solidify_steps( payload["next_steps"] = rewritten if not hold_tick: return - # Keep the true apply_soft_gap wrote. Never assign false (DEBUG #67). - payload["gate_soft_continue"] = True + # Drop the true apply_soft_gap wrote. Never assign false (DEBUG #67). + payload.pop("gate_soft_continue", None) + gap_code = str(payload.get("gap") or payload.get("gate_gap") or "").strip() + soft_gap: dict[str, Any] = { + "present": True, + "advisory": True, + "tick": False, + } + if gap_code: + soft_gap["code"] = gap_code + payload["soft_gap"] = soft_gap if closed: steer = ( "session_not_failed=true. " - "gate_soft_continue=true: do not call swarm_tick. " + "gate_soft_continue is absent, not false. " + "soft_gap.advisory=true. soft_gap.tick=false: do not call swarm_tick. " "Call swarm_solidify. loop_fuse=pending_redirect_loop is not a failed session. " "redirect_reason=pending_redirect_loop is that fuse, not a next_action. " "There is no error field." @@ -1195,7 +1240,8 @@ def _prefer_solidify_steps( else: steer = ( "session_not_failed=true. " - "gate_soft_continue=true: do not call swarm_tick. " + "gate_soft_continue is absent, not false. " + "soft_gap.advisory=true. soft_gap.tick=false: do not call swarm_tick. " "Call swarm_solidify. ok is true and there is no error. " "The session is not failed. The soft gap stays advisory." ) @@ -1217,10 +1263,10 @@ def _pending_redirect_note(count: int, closed: bool, *, gap: bool) -> str: soft_flag = "" if gap: soft_flag = ( - "gate_soft_continue=true. " - "True is not false, so this is not a failed session. " - "True is the soft gap, not a license to tick. " - "The soft gap stays in warning. " + "gate_soft_continue is absent, not false. " + "Absent is not a failed session. " + "soft_gap.advisory=true. soft_gap.tick=false is not a license to tick. " + "The soft gap stays in warning and soft_gap. " ) if not closed: return ( @@ -1273,22 +1319,24 @@ def _pending_tick_redirect(gap: str | None) -> dict[str, Any]: means do not tick. The first call still keeps ``ok`` true. Read ``session_not_failed`` before other flags. True means the session is not failed: call ``swarm_solidify`` and keep the run. - When a soft gap is present, ``gate_soft_continue`` stays true on the - first redirect and on the fuse, the same bit ``apply_soft_gap`` writes - for boot and status. True is not a license to tick. This path never - writes false: a host that treats strict false as session death stays - up even if it ignores ``session_not_failed``. ``tick_again`` is false. + When a soft gap is present, the first redirect and the fuse omit + ``gate_soft_continue`` and set ``soft_gap`` (``advisory`` true, ``tick`` + false). Boot and status keep the true bit. This path never writes false: + a host that treats strict false as session death stays up even if it + ignores ``session_not_failed``. A host that ticks only while the flag is + true stops. ``tick_again`` is false. The first call keeps ``ok`` true and sets no ``error``. The gap itself stays in ``warning``. An unfinished soft-gap boot or status keeps ``gate_soft_continue`` true and sets ``tick_again`` false. ``session_not_failed`` stays absent there. Doctor still omits the key. ``supersede_pending=true`` is the explicit replace. No Parent baseline is written. - On a soft gap, ``commands`` drops the exact ``evolver doctor --fix`` - and a ``next_steps`` entry that names that command is rewritten so the - current step is ``swarm_solidify``. ``gate_soft_continue`` stays true - and is never false. ``tick_again`` stays false. This does not execute - ``--fix``. + On a soft gap, ``commands`` drops ``evolver doctor --fix``, + ``evolver bench freeze``, and ``evolver bench baseline``. A ``next_steps`` + entry that names one of those commands is rewritten so the current step + is ``swarm_solidify``. ``gate_soft_continue`` is omitted and is never + false. ``soft_gap.tick`` is false. ``tick_again`` stays false. This does + not execute ``--fix`` and does not write a Parent baseline. """ meta = _pending_solidify_meta() count = _bump_pending_redirect(str(meta.get("run_id") or "")) @@ -1385,14 +1433,14 @@ def _pending_tick_redirect(gap: str | None) -> dict[str, Any]: "next_action stays swarm_solidify. " "The fuse is not an error and not a next_action. " "preserve_pending=true, abandon_run=false. Not a gate failure. " - "gate_soft_continue=true. tick_again=false means do not tick again. " + "gate_soft_continue is absent, not false. " + "soft_gap.tick=false means do not tick again. " "The soft gap stays advisory." ) if loop_warn not in warnings: warnings.append(loop_warn) surfaced["warnings"] = warnings - # Keep gate_soft_continue true. ok and error stay as set above. - # True is the soft gap, not a failed session, and not a license to tick. + # Omit gate_soft_continue. Never write false. soft_gap keeps the advisory. _prefer_solidify_steps(surfaced, hold_tick=True) _defer_doctor_fix_on_steer(surfaced) return surfaced @@ -1448,8 +1496,10 @@ def _opening_action(state: dict[str, Any]) -> tuple[str, str]: "存在待固化 run——先调用 `swarm_solidify` 完成固化,再回到步骤 1。" "此时直接 `swarm_tick` 不启新周期(`cycle_started=false`,`progress=false`)。" "两次 tick 返回都带 `session_not_failed=true`:会话没有失败。" - "有软缺口时这次 tick 与保险丝的 `gate_soft_continue=true`" - "(`ok` 第一次仍为 true,没有 `error`):true 不是 false,不是失败的会话," + "boot 与 status 的 `gate_soft_continue=true` 仍在。" + "有软缺口时这次 tick 与保险丝不写这个键(缺席,不写成 false)," + "并写 `soft_gap.advisory=true`、`soft_gap.tick=false`" + "(`ok` 第一次仍为 true,没有 `error`):缺席不是失败的会话," "也不是再 tick 的许可。`tick_again=false` 表示不要再 tick。" "同一条 run 再 tick 得到 `loop_fuse=pending_redirect_loop`" "与 `redirect_reason=pending_redirect_loop`" @@ -1821,12 +1871,14 @@ async def swarm_tick( ``abandon_run`` false, and ``retryable`` false. An omitted ``retryable`` is not permission to tick again. The first call still keeps ``ok`` true. Read ``session_not_failed`` before other flags. - A soft gap keeps ``gate_soft_continue`` true on the first redirect and - on the fuse, and never writes false. True is not a license to tick. + A soft gap omits ``gate_soft_continue`` on the first redirect and + on the fuse, and never writes false. ``soft_gap.advisory`` is true and + ``soft_gap.tick`` is false. Boot and status keep the true bit. The first call keeps ``ok`` true and sets no ``error``. - This steer does not list ``evolver doctor --fix`` as the current step - in ``commands`` or ``next_steps``. The command stays listed when no - run is unfinished. This call does not execute it. + This steer does not list ``evolver doctor --fix``, ``evolver bench freeze``, + or ``evolver bench baseline`` as the current step in ``commands`` or + ``next_steps``. Those commands stay listed when no run is unfinished. + This call does not execute them and does not write a Parent baseline. Neither call starts a cycle or replaces ``last_run``. ``supersede_pending=True`` is the explicit replace. Checkpoint and pause still outrank that flag and do not consume the redirect count. diff --git a/tests/gep/test_material.py b/tests/gep/test_material.py index 80fde04..50a78e7 100644 --- a/tests/gep/test_material.py +++ b/tests/gep/test_material.py @@ -56,14 +56,31 @@ def test_append_only_growth_emits_delta(self, log_file: Path) -> None: def test_identical_rewrite_is_noop(self, log_file: Path) -> None: content = log_file.read_text(encoding="utf-8") ingest_file(log_file) - # Rewrite identical bytes (mtime changes → not the fast-skip path). - _touch(log_file) + # Rewrite identical bytes. Touch after the write: some filesystems + # restore the previous mtime on write, which would collapse this into + # the fast-skip. The content memo is what proves the noop. log_file.write_text(content, encoding="utf-8") + _touch(log_file) summary = ingest_file(log_file) assert summary["mode"] == "rewrite_noop" assert summary["added"] == 0 assert len(read_records()) == 3 + def test_same_size_change_with_restored_mtime_reingests(self, log_file: Path) -> None: + ingest_file(log_file) + original = log_file.read_bytes() + stamped = log_file.stat().st_mtime_ns + mutated = b"Z" + original[1:] + assert len(mutated) == len(original) + assert mutated != original + log_file.write_bytes(mutated) + os.utime(log_file, ns=(stamped, stamped)) + summary = ingest_file(log_file) + assert summary["mode"] == "full" + assert summary["added"] > 0 + texts = [r["text"] for r in read_records()] + assert any(text.startswith("Z") for text in texts) + def test_changed_rewrite_reingests(self, log_file: Path) -> None: ingest_file(log_file) _touch(log_file) diff --git a/tests/test_mcp_host_usability_pending_smoke.py b/tests/test_mcp_host_usability_pending_smoke.py index 805735c..3488436 100644 --- a/tests/test_mcp_host_usability_pending_smoke.py +++ b/tests/test_mcp_host_usability_pending_smoke.py @@ -233,27 +233,54 @@ def _host_next_call(payload: dict[str, Any]) -> str: def _assert_doctor_fix_deferred(payload: dict[str, Any]) -> None: - """Soft solidify steer: exact ``evolver doctor --fix`` is not current. + """Soft solidify steer: setup commands are not the current step. - Other catalog commands stay. The preserve triad still names solidify. + ``evolver doctor --fix``, ``evolver bench freeze``, and + ``evolver bench baseline`` stay off ``commands`` and ``fixes``. + The preserve triad still names solidify. """ assert _checklist_runs_doctor_fix_now(payload) is False + assert _checklist_runs_bench_setup_now(payload) is False commands = [str(item).strip() for item in payload.get("commands") or []] + fixes = [str(item).strip() for item in payload.get("fixes") or []] assert "evolver doctor --fix" not in commands + assert "evolver bench freeze" not in commands + assert "evolver bench baseline" not in commands + assert "evolver bench freeze" not in fixes + assert "evolver bench baseline" not in fixes gap = payload.get("gap") - if gap == "pack_absent": - assert "evolver bench freeze" in commands - if gap == "no_baseline": - assert "evolver bench freeze" in commands - assert "evolver bench baseline" in commands - if gap in ("pack_absent", "no_baseline"): + if gap in ("pack_absent", "no_baseline", "unmeasured"): steps = [str(step).lower() for step in payload.get("next_steps") or []] - assert any("do not run evolver doctor --fix before solidify" in step for step in steps) + assert any("before solidify" in step for step in steps) + assert not any( + "evolver bench freeze" in step and "do not run" not in step for step in steps + ) + assert not any( + "evolver bench baseline" in step and "do not run" not in step for step in steps + ) assert payload.get("action_required") == "swarm_solidify" assert payload.get("preserve_pending") is True assert payload.get("abandon_run") is False +def _checklist_runs_bench_setup_now(payload: dict[str, Any]) -> bool: + """True when a list offers freeze or baseline as the current step.""" + for key in ("fixes", "commands"): + for item in payload.get(key) or []: + text = str(item).strip() + if text in ("evolver bench freeze", "evolver bench baseline"): + return True + for step in payload.get("next_steps") or []: + text = str(step) + lowered = text.lower() + if "evolver bench freeze" not in text and "evolver bench baseline" not in text: + continue + if "do not run" in lowered and "before solidify" in lowered: + continue + return True + return False + + def _checklist_runs_doctor_fix_now(payload: dict[str, Any]) -> bool: """True when a list offers ``evolver doctor --fix`` as the current step. @@ -304,10 +331,12 @@ def _assert_preserve_pending(payload: dict[str, Any]) -> None: def _assert_stop_is_not_failure(payload: dict[str, Any], *, closed: bool, gap: bool) -> None: """Stop-tick signals stay off the fail and abandon fields. - A soft gap writes ``gate_soft_continue=true`` and never false, so a host + A soft gap omits ``gate_soft_continue`` and never writes false, so a host that dies on strict false stays up. A host that loops only while the flag - is true sees the same advisory bit as boot and status. Stop-tick stays on - ``tick_again`` and ``retryable``. Without a soft gap the key stays absent. + is true does not tick. ``soft_gap.advisory`` stays true and + ``soft_gap.tick`` is false. Boot and status keep the true bit. Stop-tick + stays on ``tick_again``, ``retryable``, and ``soft_gap.tick``. Without a + soft gap the key stays absent and ``soft_gap`` is absent. The fuse code lives in ``loop_fuse``. ``error`` is absent, so a host that abandons on any error keeps the run. ``ok`` is still false on the fuse. """ @@ -346,13 +375,20 @@ def _assert_stop_is_not_failure(payload: dict[str, Any], *, closed: bool, gap: b assert _host_solidifies_only_if_error_is_the_fuse(payload) is False assert _host_solidifies_when_it_reads_the_fuse(payload) is False if gap: - assert payload.get("gate_soft_continue") is True - assert _host_ticks_only_on_gate_soft_continue(payload) is True - assert "gate_soft_continue=true" in note + assert "gate_soft_continue" not in payload + assert payload.get("gate_soft_continue") is not False + assert _host_ticks_only_on_gate_soft_continue(payload) is False + soft_gap = payload["soft_gap"] + assert soft_gap["present"] is True + assert soft_gap["advisory"] is True + assert soft_gap["tick"] is False + assert soft_gap["code"] == payload.get("gap") + assert "soft_gap.tick=false" in note assert "not a failed session" in note.lower() assert "not a license to tick" in note else: assert "gate_soft_continue" not in payload + assert "soft_gap" not in payload assert _host_ticks_only_on_gate_soft_continue(payload) is False @@ -408,7 +444,10 @@ def test_prompt_mode_and_doctor_are_listed_with_descriptions(self) -> None: assert "prompt_mode=short" in description assert "\n " not in description joined = " ".join(description.split()) - assert "does not list evolver doctor --fix as the current step" in joined + assert "does not list evolver doctor --fix" in joined + assert "evolver bench freeze" in joined + assert "evolver bench baseline" in joined + assert "as the current step" in joined doctor = tools["swarm_doctor"] assert doctor.annotations is not None @@ -419,7 +458,9 @@ def test_prompt_mode_and_doctor_are_listed_with_descriptions(self) -> None: assert "Parent baseline" in description assert "session_not_failed" in description assert "tick_again=false" in description - assert "does not list evolver doctor --fix as a current step" in description + assert "does not list evolver doctor --fix" in description + assert "evolver bench baseline" in description + assert "as a current step" in description boot_desc = " ".join((tools["swarm_boot"].description or "").split()) status_desc = " ".join((tools["swarm_status"].description or "").split()) @@ -428,7 +469,9 @@ def test_prompt_mode_and_doctor_are_listed_with_descriptions(self) -> None: assert "tick_again=false" in status_desc assert "gate_soft_continue" in status_desc for text in (boot_desc, status_desc): - assert "does not list evolver doctor --fix as a current step" in text + assert "does not list evolver doctor --fix" in text + assert "evolver bench freeze" in text + assert "as a current step" in text class TestPendingBootSmokeHint: @@ -500,6 +543,11 @@ def test_pending_boot_keeps_solidify_and_names_a_read_only_smoke( assert _checklist_runs_doctor_fix_now(boot) is False assert _checklist_runs_doctor_fix_now(status) is False assert _checklist_runs_doctor_fix_now(state) is False + assert _checklist_runs_bench_setup_now(boot) is False + assert _checklist_runs_bench_setup_now(status) is False + assert _checklist_runs_bench_setup_now(state) is False + assert "soft_gap" not in boot + assert "soft_gap" not in status def test_soft_boot_without_a_pending_run_does_not_grow_a_smoke_block( self, isolated_swarm_env: Path @@ -519,8 +567,9 @@ def test_soft_boot_without_a_pending_run_does_not_grow_a_smoke_block( assert _steps_invite_another_tick(boot) is True hint = str(boot.get("hint") or "") assert "recommended" in hint or "Soft-accept" in hint or "soft-continue" in hint - # No unfinished run: doctor --fix stays a listed setup command. + # No unfinished run: doctor --fix and bench setup stay listed. assert _checklist_runs_doctor_fix_now(boot) is True + assert "evolver bench freeze" in boot.get("commands") or [] def test_checkpoint_outranks_the_smoke_block(self, isolated_swarm_env: Path) -> None: from evolver.gep.compact_gate import request_checkpoint @@ -568,6 +617,7 @@ def test_pending_doctor_on_a_soft_gap_names_solidify( assert "gate_soft_continue" not in idle assert "tick_again" not in idle assert _checklist_runs_doctor_fix_now(idle) is True + assert "evolver bench freeze" in idle["fixes"] _write_pending("run_doctor_soft") report = swarm_doctor() @@ -585,6 +635,7 @@ def test_pending_doctor_on_a_soft_gap_names_solidify( _assert_preserve_pending(report) assert "session_not_failed" not in report assert "gate_soft_continue" not in report + assert "soft_gap" not in report assert report.get("error") not in _SOFT_GAPS assert _host_dies_on_soft_continue_false_ignoring_new_flags(report) is False assert _host_smoke_decides_without_next_action(report) == "swarm_solidify" @@ -598,8 +649,15 @@ def test_pending_doctor_on_a_soft_gap_names_solidify( assert "tick_again=false" in hint assert "Parent baseline" in hint assert "Do not apply fixes before swarm_solidify" in hint - assert "does not list `evolver doctor --fix` as a current step" in hint + assert "does not list `evolver doctor --fix`" in hint + assert "`evolver bench freeze`" in hint + assert "`evolver bench baseline`" in hint + assert "as a current step" in hint assert "do not run evolver doctor --fix before solidify" in hint.lower() + assert ( + "do not run evolver bench freeze or evolver bench baseline before solidify" + in hint.lower() + ) assert "does not execute" in hint assert "not installed" in hint.lower() or "do not block the loop" in hint.lower() assert not baseline_path().exists() @@ -650,7 +708,8 @@ def test_instrument_names_the_read_only_alternative_only_while_pending(self) -> assert "loop_fuse=pending_redirect_loop" in pending assert "redirect_reason=pending_redirect_loop" in pending assert "gate_soft_continue=true" in pending - assert "gate_soft_continue is omitted" not in pending + assert "soft_gap.tick=false" in pending + assert "不写这个键" in pending assert "error=pending_redirect_loop" not in pending assert "next_action=pending_redirect_loop" not in pending assert "session_not_failed=true" in pending @@ -719,10 +778,11 @@ async def boom(is_loop: bool = False) -> dict[str, Any]: assert "not installed" not in hint.lower() assert result.get("gap") in _SOFT_GAPS assert any("cycle_started=false" in str(item) for item in result.get("warnings") or []) - # Soft-gap solidify steer: doctor --fix is not the current step. - # Other catalog commands stay. The flag is true, never false. + # Soft-gap solidify steer: setup commands are not the current step. + # The continue flag is absent, never false. soft_gap says do not tick. _assert_doctor_fix_deferred(result) - assert result.get("gate_soft_continue") is True + assert "gate_soft_continue" not in result + assert result["soft_gap"]["tick"] is False assert result.get("soft_continue") is not False assert not (isolated_swarm_env / "evolution" / "swarm_state.json").exists() @@ -818,7 +878,8 @@ async def boom(is_loop: bool = False) -> dict[str, Any]: assert first.get("error") is None assert first["redirect_count"] == 1 _assert_doctor_fix_deferred(first) - assert first.get("gate_soft_continue") is True + assert "gate_soft_continue" not in first + assert first["soft_gap"]["advisory"] is True assert first["progress"] is False assert first["tick_again"] is False assert first["tick_closed"] is False @@ -853,7 +914,8 @@ async def boom(is_loop: bool = False) -> dict[str, Any]: _assert_solidify_step_first(closed) assert _host_next_call(closed) == "swarm_solidify" _assert_doctor_fix_deferred(closed) - assert closed.get("gate_soft_continue") is True + assert "gate_soft_continue" not in closed + assert closed["soft_gap"]["tick"] is False assert closed.get("soft_continue") is not False assert closed["ok"] is False note = str(closed.get("note") or "") diff --git a/tests/test_mcp_protocol.py b/tests/test_mcp_protocol.py index 6269314..5e303b9 100644 --- a/tests/test_mcp_protocol.py +++ b/tests/test_mcp_protocol.py @@ -54,6 +54,7 @@ def __init__(self, tmp_path: Path) -> None: ) self._id = 0 self.init_result: dict = {} + self.notifications: list[dict] = [] def request(self, method: str, params: dict | None = None) -> dict: self._id += 1 @@ -67,9 +68,15 @@ def send(self, msg: dict) -> None: def recv(self) -> dict: assert self.proc.stdout is not None - line = self.proc.stdout.readline() - assert line, "server closed the stream (crashed?)" - return json.loads(line) # stdout must contain ONLY JSON-RPC frames + while True: + line = self.proc.stdout.readline() + assert line, "server closed the stream (crashed?)" + msg = json.loads(line) # stdout must contain ONLY JSON-RPC frames + # Server-initiated notifications (tools/list_changed) are not replies. + if "id" not in msg and str(msg.get("method") or "").startswith("notifications/"): + self.notifications.append(msg) + continue + return msg def call_tool(self, name: str, args: dict) -> dict: result = self.request("tools/call", {"name": name, "arguments": args})["result"] @@ -125,6 +132,32 @@ def test_instructions_carry_swarm_directive(self, client: _McpClient) -> None: assert len(instructions) < 1200 assert "swarm_hook_event" not in instructions + def test_tools_list_publishes_doctor_and_asks_hosts_to_refresh( + self, client: _McpClient + ) -> None: + """The stdio frame is the catalog. Hosts must not treat it as immutable. + + ``swarm_doctor`` is in this one page (no ``nextCursor``). A cursor + argument does not drop it. ``tools.listChanged`` is true, and + ``notifications/initialized`` is answered with + ``notifications/tools/list_changed``. A host catalog that still omits + the tool after that notification is a client cache, not a missing + registration. This test does not invent a second tool entry. + """ + tools_cap = client.init_result["result"]["capabilities"]["tools"] + assert tools_cap["listChanged"] is True + listed = client.request("tools/list")["result"] + assert listed.get("nextCursor") in (None, "") + names = [tool["name"] for tool in listed["tools"]] + assert names.count("swarm_doctor") == 1 + doctor = next(tool for tool in listed["tools"] if tool["name"] == "swarm_doctor") + assert doctor["annotations"]["readOnlyHint"] is True + paged = client.request("tools/list", {"cursor": "1"})["result"] + assert paged.get("nextCursor") in (None, "") + assert [tool["name"] for tool in paged["tools"]].count("swarm_doctor") == 1 + methods = {note.get("method") for note in client.notifications} + assert "notifications/tools/list_changed" in methods + def test_tools_list_is_the_closed_surface(self, client: _McpClient) -> None: from tests.mcp_surface import MCP_PROMPT_NAMES, MCP_RESOURCE_URIS, MCP_TOOL_NAMES From 203fe36c52dcc65b7ae8d7d3e868ede4f776bcbf Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 3 Nov 2026 09:50:40 +0000 Subject: [PATCH 2/2] fix(test): skip tools/list_changed when the e2e MCP client reads replies The catalog refresh notification has no id. The e2e recv treated the next stdout line as the JSON-RPC result, so tools/call and prompts/get raised KeyError on result. Read until the matching id, and pin that pairing with a regression. Co-authored-by: Steper Lin --- CHANGELOG.md | 1 + tests/e2e/test_swarm_full_e2e.py | 49 ++++++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7207f42..f992bb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased ### Fixed +- **MCP e2e 客户端跳过 `notifications/tools/list_changed`**:stdio 握手后这条通知没有 `id`。e2e 的 `recv` 原先把下一行当成响应,随后的 `tools/call` 与 `prompts/get` 在 `["result"]` 上 `KeyError`。现在读到带 `id` 的帧才返回,并按请求 id 配对。协议测试里的客户端本来就会跳过通知。 - **MCP 工具目录:`tools.listChanged` 改为 true,并在 initialized 后发 `notifications/tools/list_changed`**:stdio `tools/list` 本来就在同一页(无 `nextCursor`)列出只读 `swarm_doctor`。握手原先广告 `listChanged: false`,把目录当成不变的宿主会留着加工具之前的缓存:调用打到新进程,目录仍缺 `swarm_doctor`。现在广告列表可变,并在 `notifications/initialized` 之后发一次 `notifications/tools/list_changed`。不注册不存在的工具。仍忽略该通知的宿主要新开一次会话。 - **MCP 宿主可用性:软缺口 tick 与保险丝不再用 `gate_soft_continue=true` 邀请再 tick**:第一次未完成 run 的 `swarm_tick` 与 `loop_fuse=pending_redirect_loop` 去掉这个键,不写成 false。同时写 `soft_gap.advisory=true`、`soft_gap.tick=false`。只在旗标为 true 时再 tick 的宿主停住;只把严格 false 当成整段失败的宿主不结束会话。boot / status 仍写 `gate_soft_continue=true`。`tick_again=false`、`retryable=false`、保险丝的 `ok=false`、`session_not_failed` 与 preserve 三元组不动。doctor 仍不写 `gate_soft_continue`,也不写 `soft_gap`。不结算这条 run,不写 Parent baseline,不放宽固化门。 - **MCP 宿主可用性:软固化引导不再把 freeze / baseline 当当前步骤**:未完成 run 的 boot / status / doctor / 第一次 tick / 保险丝,从 `commands` 或 `fixes` 去掉精确的 `evolver bench freeze` 与 `evolver bench baseline`,`next_steps` 里点名它们的句子改成先 `swarm_solidify`。没有未完成 run 时这两条仍在。不执行它们,不写 Parent baseline,不放宽固化门。 diff --git a/tests/e2e/test_swarm_full_e2e.py b/tests/e2e/test_swarm_full_e2e.py index f707704..1700c6e 100644 --- a/tests/e2e/test_swarm_full_e2e.py +++ b/tests/e2e/test_swarm_full_e2e.py @@ -85,6 +85,7 @@ def __init__(self, cwd: Path, extra_env: dict[str, str] | None = None) -> None: env=env, ) self._id = 0 + self.notifications: list[dict[str, Any]] = [] self.init_result: dict[str, Any] = {} self.init_result = self.request( "initialize", @@ -103,15 +104,31 @@ def send(self, msg: dict[str, Any]) -> None: self.proc.stdin.flush() def recv(self) -> dict[str, Any]: + """Read the next JSON-RPC response, skipping server notifications. + + ``notifications/initialized`` is answered with + ``notifications/tools/list_changed``. That frame has no ``id``. + Treating it as the reply desynchronizes every later ``tools/call`` + and ``prompts/get`` (they see a notification and KeyError on + ``result``). + """ assert self.proc.stdout is not None - line = self.proc.stdout.readline() - assert line, "server closed the stream (crashed?)" - return json.loads(line) + while True: + line = self.proc.stdout.readline() + assert line, "server closed the stream (crashed?)" + msg = json.loads(line) + if "id" not in msg and str(msg.get("method") or "").startswith("notifications/"): + self.notifications.append(msg) + continue + return msg def request(self, method: str, params: dict[str, Any] | None = None) -> dict[str, Any]: self._id += 1 - self.send({"jsonrpc": "2.0", "id": self._id, "method": method, "params": params or {}}) - return self.recv() + expected = self._id + self.send({"jsonrpc": "2.0", "id": expected, "method": method, "params": params or {}}) + msg = self.recv() + assert msg.get("id") == expected, msg + return msg def call(self, name: str, args: dict[str, Any] | None = None) -> Any: result = self.request("tools/call", {"name": name, "arguments": args or {}})["result"] @@ -267,6 +284,28 @@ def _run_precompact_hook(ws: Path) -> dict[str, Any]: class TestFullSurfaceE2E: + def test_00_list_changed_does_not_desync_the_next_response(self, client: _McpClient) -> None: + """The post-initialize catalog notification is not a JSON-RPC result. + + Handshake advertises ``tools.listChanged``. The server then emits + ``notifications/tools/list_changed``. The next ``tools/list`` and + ``prompts/get`` must still pair on ``id`` and carry ``result``. + """ + tools = client.request("tools/list") + assert "result" in tools + assert tools["id"] == client._id + names = [tool["name"] for tool in tools["result"]["tools"]] + assert names.count("swarm_doctor") == 1 + prompt = client.request( + "prompts/get", + {"name": "evolver_swarm", "arguments": {"agent_name": "e2e-notify"}}, + ) + assert "result" in prompt + assert prompt["id"] == client._id + assert "EVOLVER SWARM" in prompt["result"]["messages"][0]["content"]["text"] + methods = {note.get("method") for note in client.notifications} + assert "notifications/tools/list_changed" in methods + def test_01_boot_status_and_resources(self, client: _McpClient, e2e_ws: Path) -> None: assert "EVOLVER SWARM" in client.init_result["result"]["instructions"]