Skip to content

fix(agent): skills install/uninstall now refresh; harden sessionless dispatch - #63

Merged
tallcode merged 3 commits into
mainfrom
claude/fervent-banach-d86eaf
Jul 28, 2026
Merged

tallcode merged 3 commits into
mainfrom
claude/fervent-banach-d86eaf

Conversation

@tallcode

Copy link
Copy Markdown
Collaborator

问题

GUI「全部技能」点击「安装」/「卸载」后,按钮状态不更新,只有重启才显示正确状态。安装/卸载本身是成功的(磁盘已写入),纯粹是展示层没刷新。

根因(两个叠加的 bug)

  1. refresh_skills 被错误地放进 session-scoped 分支。 GUI/CLI 在安装/卸载后会立即调用 refresh_skills 且不带 session_id,于是它撞上 session 解析门、返回 "session not found"。GUI 的 agent_bridge::refresh_skills 是 best-effort(let _ = 吞掉错误),所以这个失败完全静默 —— 缓存从未失效,已安装列表直到重启 / TTL 过期才更新。
  2. 旧的 5 秒限流。 即使 (1) 修好,cmd_refresh_skills 里的进程级 5s 限流也会被启动 / 打开页面时的扫描消耗掉,导致安装/卸载后的那次失效被跳过。

修复

  • refresh_skills 移到 sessionless 分支(与 get_commands 并列),无需 session 即可失效缓存。
  • cmd_refresh_skills 改为无条件失效缓存:安装/卸载是在上次扫描之后写盘的,缓存对它们必然是脏的;失效是 O(1),随后的重扫会重新填充(并预热缓存,让 GUI 紧接着的 get_commands 命中快路径拿到新状态)。删除限流常量与 LAST_REFRESH 静态量。

审计收尾(防止同类问题)

  • 删除 session-scoped 分支里不可达的 new_session 死分支(它在上方 sessionless 分支已处理),留 NOTE 防止被「好心」加回。
  • 删除空壳命令 abort_shell 及其测试:全仓(agent/TUI/GUI/CLI/channels)零调用方,且 handler 什么都不做只返回 ok —— 真正的 shell 终止走 agent loop 的 abort 命令(GUI runs 面板的终止按钮用的就是它)。让一个未实现的命令静默返回 ok 会误导调用方。
  • 新增表驱动回归测试 sessionless_commands_do_not_require_session_id:make_cmd() 总会注入 session id,恰好掩盖了 refresh_skills 这类「sessionless 命令被误挪进 session-scoped 分支」的 bug。该测试用空 session 构造每个 sessionless 命令,断言它既不撞 session 解析门(唯一的 "pass a valid session_id" 措辞)、也是已知命令。

验证

cargo fmt --check / cargo clippy --all-targets -D warnings / cargo test --lib 全部通过(765 passed)。

🤖 Generated with Claude Code

tallcode and others added 3 commits July 28, 2026 18:02
cmd_refresh_skills gated cache invalidation behind a 5s process-global rate limit. That limit was consumed by the harmless scan the GUI fires on startup, page open, and agent (re)connect, so the invalidation that matters - the one right after install/uninstall writes to disk - was silently skipped. get_commands then kept returning the pre-write cache and the Skills view showed stale installed/uninstalled state until restart.

Drop the rate limit and invalidate unconditionally; invalidation is O(1) and the rescan warms the cache so the GUI's follow-up get_commands hits the fast path with the new state. Remove the now-inapplicable rate-limit test.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
refresh_skills was registered in the session-scoped branch, so the sessionless call the GUI/CLI make right after install/uninstall (no session_id) failed with 'session not found' and was swallowed by the best-effort caller. cmd_refresh_skills never ran, the skills discovery cache was never invalidated, and get_commands kept returning the pre-write list - the installed/uninstalled state only caught up after restart or the 60s TTL.

Move it next to get_commands in the sessionless branch. The existing test missed this because make_cmd() always injects a session id; add a regression test that calls it with an empty session.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Follow-up audit to the refresh_skills session-mismatch fix:

- Drop the unreachable `new_session` arm from the session-scoped branch.
  It is dispatched in the sessionless branch above (a new session has no
  existing session to resolve), so an arm after the resolution gate was
  dead code. Replaced with a NOTE so it isn't "helpfully" re-added.

- Drop the `abort_shell` no-op command and its test. It had zero callers
  anywhere (agent/TUI/GUI/CLI/channels) and did nothing but return ok —
  real shell abort flows through the agent-loop `abort` command (the GUI
  runs-panel terminate button already uses it). Keeping a silent ok for an
  unimplemented command was misleading; an unknown command now errors
  honestly.

- Add `sessionless_commands_do_not_require_session_id`: a table-driven
  regression test. make_cmd() always injects a session id, which hid the
  refresh_skills bug (a sessionless command silently moved into the
  session-scoped branch). The test builds each sessionless command with an
  empty session and asserts it never trips the resolution gate (the unique
  "pass a valid session_id" phrase) and is a known command.

cargo fmt/clippy/test all clean (765 passed).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@tallcode
tallcode enabled auto-merge (squash) July 28, 2026 10:59
@tallcode
tallcode merged commit afc3f2c into main Jul 28, 2026
17 checks passed
@tallcode
tallcode deleted the claude/fervent-banach-d86eaf branch July 28, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant