Skip to content

fix: cap recall injection size to prevent context bloat in long sessions - #77

Open
evilh2019 wants to merge 1 commit into
adoresever:mainfrom
evilh2019:fix/recall-injection-bloat
Open

fix: cap recall injection size to prevent context bloat in long sessions#77
evilh2019 wants to merge 1 commit into
adoresever:mainfrom
evilh2019:fix/recall-injection-bloat

Conversation

@evilh2019

Copy link
Copy Markdown

问题 / Problem

assembleContextrecalled 节点 + 本会话全部 active 节点(含 content 全文)+ 每节点最多 500 条原始消息的 episodic trace 全量注入 system prompt。

在长会话中(本机单会话累积 411 个 active 节点),每次用户消息的 runtime-context 注入达到 ~310KB(约 10 万+ tokens),导致:

  • 上下文窗口瞬间爆满,触发 DSH harness 的 compaction
  • compaction 会抢占正在执行的工具调用 → 工具被 abort(tool call aborted / TOOL_OUTCOME_UNKNOWN
  • 任务被反复打断,工具结果丢失(即使命令已执行完)

修复 / Fix

src/format/assemble.ts 加体量上限:

  1. selected 截断:recalled 节点全保留(已有 recallMaxNodes 限制,默认 6),active 节点只取 最近 15 个(按 updatedAt 排序)——防御长会话累积节点全量注入
  2. episodic 截断:每个 top 节点原始消息从 500 条降到 30 条,每条从 200 字符降到 120 字符

验证 / Verification

  • 修复前:注入 ~310KB(194 skills / 133 tasks / 88 events / 421 edges 全量)
  • 修复后:注入降至数 KB(recalled 3 + active 最近 15),工具中断消失
  • 小会话(节点 < 15)行为不变:active 截断是上限而非下限,不改变召回语义

assembleContext was injecting ALL session-active nodes (411 in a long
session) with full content plus up to 500 raw messages per episodic trace,
producing ~310KB runtime-context per user message. That overflowed the
context window and let DSH compaction preempt in-flight tool calls
('tool call aborted' / TOOL_OUTCOME_UNKNOWN).

Fix: inject ONLY the query-targeted recall nodes (recalled <=
recallMaxNodes, semantic search already covers this session's relevant
nodes). Session-active nodes are no longer dumped by time; a 3-node
fallback covers the empty-recall case. Episodic traces are capped to
30 msgs x 120 chars per top node.
@evilh2019
evilh2019 force-pushed the fix/recall-injection-bloat branch from 5193782 to 3c313d0 Compare August 22, 2026 02:35
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.

2 participants