diff --git a/docs/subsystems/compaction.i18n.yaml b/docs/subsystems/compaction.i18n.yaml index fb62fa8a42..0520ce323c 100644 --- a/docs/subsystems/compaction.i18n.yaml +++ b/docs/subsystems/compaction.i18n.yaml @@ -15,8 +15,8 @@ en: 9dde333b53c14f24 zh: 8959aafefc55f9a4 /compaction/the-service: - en: 6c613669a0a61c16 - zh: e9f23445bc0a5537 + en: 85c4e66d472b4569 + zh: afb47f8bad9efa3a /compaction/tool-result-pruning-outcomes: en: 27091b0a3d454575 zh: e22431e27e1349f2 diff --git a/docs/subsystems/compaction.md b/docs/subsystems/compaction.md index 415c3b06be..54572b585d 100644 --- a/docs/subsystems/compaction.md +++ b/docs/subsystems/compaction.md @@ -100,6 +100,8 @@ type ManualCompactionErrorCode = Pressure compaction runs at `agent/pre-step` against the committed request header and at `agent/request` against a changed destination before its header is logged. Model-switch summaries retain the previous route unless an explicit summary target is configured; a failed switch preserves that header and any completed reductions. Once pressure or canonical overflow qualifies, compaction-basic invokes optional [`ctx.toolResultPruner`](../../packages/compaction/compaction-tool-result-pruner/README.md) before range selection, remeasures through `ctx.tokenMeter`, and can advance the surface without a summary. Failed-request recovery runs through `agent/request-error` after the failed step closes and returns a retry action only when the surface replacement generation advances, even if later summary work throws after pruning; cancellation still wins. Region boundaries preserve tool-call/result pairing but not whole turns, allowing early closed steps of one oversized turn to compact. `dsh-compaction-basic` owns thresholds, retained-tail policy, overflow caps, and failure handling. +When an automatically selected or `/compact` summary receives `LlmError(CONTEXT_WINDOW_EXCEEDED)` and existing recovery listeners decline it, compaction-basic retries a smaller tool-balanced prefix after cancellation and stability checks. Only the successfully summarized prefix is replaced; a single indivisible unit that still overflows fails. Explicit `compactRegion(start, end)` calls retain their exact range. The [package contract](../../packages/compaction/compaction-basic/README.md) defines prefix sizing and retry costs. + The Service Definition exports `toolPairingBalancedBefore(session, seq)` and `toolPairingBalancedAfter(session, seq)` for the tool-call/result pairing checks before and after a seq. Both validate current surface membership and reject missing seqs and orphan results; the [package contract](../../packages/compaction/compaction/README.md#tool-pairing-boundaries) defines their cache behavior. ## Tool-result pruning outcomes diff --git a/docs/subsystems/compaction.zh.md b/docs/subsystems/compaction.zh.md index 94b9256e05..bf15640564 100644 --- a/docs/subsystems/compaction.zh.md +++ b/docs/subsystems/compaction.zh.md @@ -100,6 +100,8 @@ type ManualCompactionErrorCode = 压力压缩在 `agent/pre-step` 按已提交请求 header 执行,也在 `agent/request` 按已改变的目标执行,先于其 header 记入日志。除非配置了显式摘要目标,模型切换摘要仍使用先前路由;切换失败会保留该 header 与已完成的缩减。一旦压力或规范化溢出满足条件,compaction-basic 会在选择范围前调用可选的 [`ctx.toolResultPruner`](../../packages/compaction/compaction-tool-result-pruner/README.zh.md),再通过 `ctx.tokenMeter` 重新测量,并且可以在不生成摘要的情况下推进 surface。失败请求的恢复在失败的步骤关闭后通过 `agent/request-error` 运行;仅当 surface replacement generation 前进时才返回重试动作,即便后续摘要工作在剪枝后抛异常亦如此;取消仍然优先。区域边界保持工具调用/结果配对,但不保持整个轮次,因此一个过大轮次中较早关闭的步骤可以被压缩。`dsh-compaction-basic` 拥有阈值、保留尾部策略、溢出上限与失败处理。 +自动选区或 `/compact` 的摘要收到 `LlmError(CONTEXT_WINDOW_EXCEEDED)` 且既有恢复监听器未处理时,compaction-basic 在取消与稳定性检查后重试更小的工具配对完整前缀。只替换成功完成摘要的前缀;单个不可拆分单元仍超限时失败。显式 `compactRegion(start, end)` 调用保持精确范围。[包约定](../../packages/compaction/compaction-basic/README.zh.md)定义前缀大小和重试成本。 + 该 Service Definition 导出 `toolPairingBalancedBefore(session, seq)` 与 `toolPairingBalancedAfter(session, seq)`,用于检查 seq 之前与之后的工具调用/结果配对。两者都会验证当前 surface 成员关系,并拒绝缺失的 seq 与遗留结果;[包约定](../../packages/compaction/compaction/README.zh.md#tool-pairing-boundaries)定义其缓存行为。 ## 工具结果剪枝产出 diff --git a/packages/compaction/compaction-basic/src/region.ts b/packages/compaction/compaction-basic/src/region.ts index eb4c7174c5..01b05c35e3 100644 --- a/packages/compaction/compaction-basic/src/region.ts +++ b/packages/compaction/compaction-basic/src/region.ts @@ -168,7 +168,8 @@ export function selectCompactableRange( * @param start - inclusive first surface-node seq. * @param end - inclusive last surface-node seq. * @param agent - agent used by the summarizer. - * @param options - bracket owner, stability rule, and optional durability checkpoint. + * @param options - bracket owner, stability rule, self-selected prefix shrink policy, + * optional source-command correlation, and optional durability checkpoint. * @param signal - optional summarization cancellation signal. * @returns the successful durable compaction result. */ diff --git a/packages/test-support/session-snapshot/README.i18n.yaml b/packages/test-support/session-snapshot/README.i18n.yaml index 5efc7d808e..3d9fb67a69 100644 --- a/packages/test-support/session-snapshot/README.i18n.yaml +++ b/packages/test-support/session-snapshot/README.i18n.yaml @@ -27,8 +27,8 @@ en: 6b11d5111e1a3222 zh: de4d3889b1a5ebb4 /deepseek-ai-dsh-session-snapshot/use-this-package/platform-and-composition-variants: - en: 6a01d3687551b6b5 - zh: 6715d9aed8a4b9d2 + en: c2e458293560d96d + zh: 882f02e28172f450 /deepseek-ai-dsh-session-snapshot/use-this-package/what-can-go-wrong: en: 0b03592947ca43d6 zh: b14a64238c4b5f80 diff --git a/packages/test-support/session-snapshot/README.md b/packages/test-support/session-snapshot/README.md index a9adf44c13..5bff76eb8e 100644 --- a/packages/test-support/session-snapshot/README.md +++ b/packages/test-support/session-snapshot/README.md @@ -90,7 +90,7 @@ A pin owns its generated `system-prompt.expected.md` or `tool-schemas.expected.j A scenario requiring a non-Windows host declares `posixOnly`, which skips its run test on Windows while the fixture guards keep covering its committed files everywhere; a scenario whose composition needs a usable `pwsh` declares `pwshOnly`. `workspaceParent` moves the generated child cwd outside the platform temp directory when temporary-directory grants are themselves under test; a scenario's committed `workspace/` is copied into that child first, then `prepareWorkspace` runs against the generated cwd before the agent starts. Default generated workspaces are stored in session fixtures as `{{cwd}}`, so platform temp roots and random basenames do not affect recordings. Headless manifests use `workspace.parent: outside-temp` when the Session workspace grant itself is under test. The adapter allocates beside the platform temp root when its parent is writable and outside system temporary grants, otherwise under home, and rejects any generated cwd already covered by automatic temporary write grants. -ACP scenarios that persist token prices for runtime-context text can set `workspaceCwdTextLength: 192`. The harness resolves the parent directory through the native filesystem API before padding the cwd to that JSON-quoted length and retains a unique random suffix; it rejects lengths that cannot accommodate the temporary root before allocating directories. Other scenarios keep their ordinary temporary paths. +ACP scenarios that persist token prices for runtime-context text can set `workspaceCwdTextLength` to an exact JSON-quoted cwd length. The harness resolves the parent directory through the native filesystem API before padding the cwd to that length and retains a unique random suffix; it rejects lengths that are not safe integers or cannot accommodate the temporary root and generated basename before allocating directories. Other scenarios keep their ordinary temporary paths. ### What can go wrong diff --git a/packages/test-support/session-snapshot/README.zh.md b/packages/test-support/session-snapshot/README.zh.md index aba1440298..14de6d6069 100644 --- a/packages/test-support/session-snapshot/README.zh.md +++ b/packages/test-support/session-snapshot/README.zh.md @@ -90,7 +90,7 @@ Headless/ACP 与 SDK 适配器在规范化之前,将原始目录中的子创 需要非 Windows 主机的场景声明 `posixOnly`,在 Windows 上跳过运行测试,但 fixture 保护仍在所有平台覆盖其已提交文件;组合需要可用 `pwsh` 的场景声明 `pwshOnly`。当临时目录授权自身待测时,`workspaceParent` 将生成子级 cwd 移出平台临时区域;场景签入的 `workspace/` 会先复制到该子级,随后 `prepareWorkspace` 在 agent 启动前针对生成 cwd 运行。默认生成的 workspace 在会话 fixture 中存储为 `{{cwd}}`,使平台临时根目录与随机 basename 不影响录制。headless manifest 在测试 Session workspace 授权本身时使用 `workspace.parent: outside-temp`。适配器在父目录可写且位于系统临时授权之外时,于平台临时根目录旁分配目录,否则使用 home,并拒绝已被自动临时写授权覆盖的生成 cwd。 -持久记录 runtime-context 文本 token 计价的 ACP 场景可设置 `workspaceCwdTextLength: 192`。harness 先通过原生文件系统 API 解析父目录,再将 cwd 填充至该 JSON 引用字符串长度,并保留唯一随机后缀;若指定长度容不下临时根目录,则在分配目录前拒绝。其他场景保留普通临时路径。 +持久记录 runtime-context 文本 token 计价的 ACP 场景可将 `workspaceCwdTextLength` 设为 cwd 的精确 JSON 引用字符串长度。harness 先通过原生文件系统 API 解析父目录,再将 cwd 填充至该长度,并保留唯一随机后缀;若指定长度不是安全整数,或容不下临时根目录和生成的目录名,则在分配目录前拒绝。其他场景保留普通临时路径。 ### 可能出什么问题 diff --git a/snapshots/acp/acp.snapshot.ts b/snapshots/acp/acp.snapshot.ts index bd61115132..03029f50ab 100644 --- a/snapshots/acp/acp.snapshot.ts +++ b/snapshots/acp/acp.snapshot.ts @@ -46,6 +46,7 @@ const controllerCases: readonly { name: 'summary-overflow', hasModelTurn: true, configPath: join(corpusDir, 'summary-overflow', 'cordis.yml'), + // Pins the runtime-context token price recorded in summary-overflow/session.v4.jsonl. workspaceCwdTextLength: 192, }, ] as const