Skip to content

feat(harness): background drain ingestion, auto-context snapshot cache, and configurable reasoning-effort policy - #28

Open
LiuStar656 wants to merge 3 commits into
diqierjia:mainfrom
LiuStar656:feat/harness-background-drain
Open

feat(harness): background drain ingestion, auto-context snapshot cache, and configurable reasoning-effort policy#28
LiuStar656 wants to merge 3 commits into
diqierjia:mainfrom
LiuStar656:feat/harness-background-drain

Conversation

@LiuStar656

Copy link
Copy Markdown

feat(harness): background drain ingestion, auto-context snapshot cache, and configurable reasoning-effort policy

Problem

The DeepSeek Harness integration ingests memory synchronously: every completed
agent turn immediately runs StrataGate's LLM memory work (appendTurn, block
sealing, activated-memory retrieval) inline on the hot path, so conversation
assembly blocks on memory processing. The structured-call reasoning-effort
policy is also not user-configurable: force-off raises a desktop
notification and fails the structured call on providers that do not advertise
off.

Solution

Three commits, one concern each:

  1. da9ea51 — Background drain + snapshot cache (src/runtime.ts, src/index.ts, tests).
    Turns are folded on the hot path then only counted and queued; the actual
    LLM memory work runs on an unref()'d timer with per-session
    serialization, count-triggered eager draining (≥3 queued turns → 150 ms),
    and exponential backoff on failure. The system-prompt/assemble hook reads
    a synchronous snapshot cache refreshed by the drain instead of doing
    flush + retrieval inline; an empty or stale snapshot is skipped, or carries
    an explicit staleness marker. flush() stays the explicit synchronous
    point; a public refreshAutoContext(session) provides a deterministic
    refresh for tests and admin flows.
  2. 08600b8 — Effort degrade instead of failure (src/llm.ts, src/config.ts, tests).
    When the provider does not advertise off, force-off now falls back to
    the model default with a single warning instead of failing the structured
    call. The resolved config field is optional (default auto), so existing
    plugin configs and tests stay valid.
  3. a31d7c6 — Effort policy setting (src/client.js, src/index.ts, package.json, CHANGELOG).
    New @deepseek-ai/dsh-settings wiring: the effort policy (auto | force-off) is a user-editable switch on the plugin's settings page, bound
    through the client settings.section registration
    (register.inject carries hooks/setEffort/resetEffort) and mirrored into
    the model bridge on every change, so the current mode is read per structured
    call. Adds the peer/dev dependency and lockfile update; CHANGELOG gains the
    Unreleased entries.

Acceptance

  • npm run check --workspace stratagate-dsh — zero type errors.
  • npm run test --workspace stratagate-dsh — 59/59 passing (8 files),
    including new background-drain/snapshot-cache tests and the adapted
    plugin-composition test (assemble skips the memory context until the drain
    has rendered a snapshot).
  • Hot-path assemble is a synchronous cache read: no IO, never throws.
  • Backwards compatible: flush() still forces queued turns; config defaults
    unchanged; upstream multibatch protocol and turn-stopping are preserved.

中文说明

问题

DeepSeek Harness 集成的记忆摄取是同步的:每次回合结束都立即在热路径上运行
StrataGate 的 LLM 记忆处理(appendTurn、封存、激活记忆检索),对话组装会被
记忆工作阻塞;推理档位策略也不可配置,force-off 在模型不支持 off 时会发
桌面通知并使结构化调用失败。

方案(三个 commit,各管一事)

  1. da9ea51 后台计数驱动摄取 + 快照缓存(src/runtime.ts、src/index.ts、测试)。
    回合在热路径只折叠入队并计数;真正的 LLM 记忆工作在 unref() 定时器上执行,
    按会话串行,批量压力触发 eager drain(队列 ≥3 回合 → 150ms),失败指数退避。
    system-prompt/assemble 钩子改为读取后台 drain 渲染的同步快照缓存,空/过期
    快照直接跳过或带显式过时标记,热路径永不阻塞。flush() 仍是显式同步点;
    新增公开 refreshAutoContext(session) 供测试与管理流程确定性刷新。
  2. 08600b8 降级代替失败(src/llm.ts、src/config.ts、测试)。
    提供方不支持 off 时,force-off 退回模型默认档位并告警一次,不再失败。
    resolved 配置字段改为可选(默认 auto),现有插件配置与测试无需改动。
  3. a31d7c6 档位设置化(src/client.js、src/index.ts、package.json、CHANGELOG)。
    新接入 @deepseek-ai/dsh-settings:档位策略(auto | force-off)成为插件
    设置页的用户可编辑开关,经客户端 settings.section 注册
    register.inject 携带 hooks/setEffort/resetEffort)注入记忆 UI,改动即时
    镜像到模型桥,每次结构化调用按当前档位执行。新增 peer/dev 依赖与 lockfile
    更新;CHANGELOG 补充 Unreleased 条目。

验收

  • npm run check --workspace stratagate-dsh:零类型错误。
  • npm run test --workspace stratagate-dsh:59/59 通过(8 个文件),
    含新增的后台 drain/快照缓存测试与适配后的插件组装测试
    (assemble 在 drain 渲染出快照前跳过记忆上下文)。
  • 热路径 assemble 为同步缓存读:无 IO、永不 throw。
  • 向后兼容:flush() 仍强制消费积压回合;配置默认值不变;
    保留上游 multibatch 协议与 turn-stopping 行为。

Turns are folded on the hot path then only counted and queued; the actual
LLM memory work (appendTurn + auto-context rendering) runs on an unref'd
timer with per-session serialization, count-triggered eager draining and
exponential backoff. The system-prompt/assemble hook reads a synchronous
snapshot cache refreshed by the drain instead of doing flush + retrieval
inline, so hot-path assembly never blocks on StrataGate memory work.
Empty or stale snapshots are skipped or carry an explicit staleness marker.

Also adapts the plugin and runtime tests: assemble skips the memory context
until the background drain has rendered a snapshot, and tests wait for the
eager drain rather than an inline flush.
When the provider does not advertise off, force-off now falls back to the
model default and warns once, instead of raising a desktop notification and
failing the structured call. The effort field is optional in the resolved
config (default 'auto') so existing plugin configs and tests stay valid.
Wires @deepseek-ai/dsh-settings: the effort policy (auto | force-off) is a
user-editable switch on the plugin settings page, bound through the client
settings section (register.inject carries hooks/setEffort/resetEffort) and
mirrored into the model bridge on every change, so the current mode is read
per structured call. Adds the dsh-settings peer/dev dependency and updates
the lockfile; CHANGELOG gains the Unreleased entries for all three changes.
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