Skip to content

Persist enabled tool set across sessions; compact history in chunks

Choose a tag to compare

@paul356 paul356 released this 14 Sep 14:11
· 59 commits to main since this release
09adb6f

What's New in 0.2.4-bugfix2

Session tool-set persistence and restore fixes (#136, #137, #139)

  • Session files now persist the enabled tool set (schema v3). session_store moves to SCHEMA_VERSION 3; the saved payload carries the sorted enabled-tool names, so a restored session ships the previously active schemas again instead of forcing the model to re-issue enable_tool calls. Legacy v1/v2 files restore an empty set — exactly today's fresh-session behavior.
  • New public API on the LLM client: get_enabled_tools() / set_enabled_tools(). The panel's save/restore paths now use them; restored names stay inert until the tool catalog is fetched (same lazy semantics as before).
  • Fixed set_history regression. The schema-v3 change accidentally deleted LLMClient.set_history, breaking both the manual Load Session path and the auto-restore path with AttributeError. It is restored with its original defensive-copy / empty-clears semantics, plus a regression test guarding existence, round-trip, and restore-order independence.
  • Auto-restore now re-enables persisted tools — the auto-restore path calls set_enabled_tools() just like manual load, so restored sessions ship the enabled schemas in both paths.
  • Enabled set survives backend URL changes. set_base_url no longer clears the enabled set: the enabled set is session state (persisted with the session), while only the tool-registry cache belongs to the backend endpoint. Names a new backend no longer registers are pruned lazily once the catalog is known.

Chunked history compaction with eviction-first budget handling (#141)

When a session transcript approaches the context window, compaction previously returned False if history was too short to compact, or a single summarisation call could itself overflow the model window — hard-failing the turn with Context window overflow. Compaction is reworked to:

  • Dedup superseded tool turns as a compaction sub-step instead of a standalone budget lever.
  • Batch-compact the prefix in map-reduce chunks at turn boundaries: each compaction call stays within half the context window; a single turn larger than the budget is hard-split by characters.
  • Absorb the oldest preserved recent turns into the summary when the recent block alone would exceed the post-compaction budget (target_history_tokens), so a huge recent block cannot overflow either.
  • Evict enabled tool schemas first (meta tools enable_tool / disable_tool / get_tool_schema are never evicted) and only compact history when eviction alone cannot reach the compaction target.

This fixes the 'too short to compact' deadlock when the transcript exceeds the window and keeps every compaction call itself within the window.

Verification

  • Full unit suite (tests/unit/plugin): 261 passed.
  • PR #142 CI (develop → main): all checks green — Test Python 3.13, Test Windows (integration), Lint and Format, Security Scan, Build Package, Detect Changed Paths.
  • PR #142 merged develop → main as 09adb6f; the attached zip is built from that merge commit by the Build KiCad Plugin ZIP workflow.

中文说明(Chinese Summary)

会话工具集持久化与恢复修复(#136 / #137 / #139)

  • 会话文件现在持久化启用的工具集(schema v3):session_store 升级到 SCHEMA_VERSION 3,保存时写入排序后的启用工具名。恢复会话时自动带上之前启用的 schema,模型不必重新调用 enable_tool。旧版 v1/v2 文件恢复为空集,与新会话行为完全一致。
  • LLM 客户端新增公开 API:get_enabled_tools() / set_enabled_tools(),面板的保存/恢复路径均已接入;恢复的工具名在拉取工具目录之前保持惰性(与原有语义一致)。
  • 修复 set_history 回归:schema v3 改动意外删除了 LLMClient.set_history,导致手动「加载会话」和自动恢复两条路径报 AttributeError。现已按原语义(防御性拷贝、空串清空)恢复,并新增回归测试覆盖存在性、往返与恢复顺序无关性。
  • 自动恢复路径重新启用持久化工具:与手动加载一致,自动恢复也会调用 set_enabled_tools(),两条路径都带上启用的 schema。
  • 切换后端 URL 不再清空启用集:启用集是会话状态(随会话持久化),只有工具目录缓存属于后端端点。新后端未注册的工具名会在目录可知后惰性剔除。

历史分块压缩 + 先淘汰工具再压缩(#141)

当会话接近上下文窗口时,压缩此前会在历史太短无法压缩时返回 False,或单次摘要调用本身可能超出模型窗口,从而报 Context window overflow 硬失败。现在压缩被重构为:

  • 去重过期的工具轮,作为压缩子步骤而非独立预算杠杆。
  • 按 turn 边界对前缀做 map-reduce 分块批量压缩:每次压缩调用保持在半窗口以内;单轮超过预算时按字符硬切分。
  • 当 recent 块单独就超出压缩后预算(target_history_tokens)时,把最老的保留轮折入摘要,巨大 recent 块也无法造成溢出。
  • 先驱逐启用的工具 schema(enable_tool / disable_tool / get_tool_schema 三个元工具永不驱逐),仅当驱逐不足以达到压缩目标时才压缩历史。

由此修复「太短无法压缩」的死锁——转录超窗时也能正常工作,且每次压缩调用自身都不会超出窗口。

验证

  • 单测全量(tests/unit/plugin):261 通过。
  • PR #142 CI(develop → main)全绿:Test Python 3.13、Test Windows (integration)、Lint and Format、Security Scan、Build Package、Detect Changed Paths。
  • PR #142 将 develop 合入 main(09adb6f);附件 zip 即由该 merge commit 经 Build KiCad Plugin ZIP workflow 构建。