Repository navigation
fix(compaction): send the session id as the summary prompt cache key - #1165
Merged
vastsa merged 2 commits intoSep 28, 2026
Merged
Conversation
The summary of a context checkpoint reaches the same gateway backend as the conversation it summarizes, but the Responses-shaped adapters attach `prompt_cache_key` only while the caller keeps some cache retention, and pi-agent-core asks for `"none"` on a summary. The summary therefore travelled without the conversation identity every other turn of the session sends, and a gateway fronting a Codex backend answered 400 `invalid_responses_request` (on anyrouter: "invalid codex request"), failing `/compact` and automatic compaction with `Summarization failed`. `withCompactionRequestHeaders` adds the session id as `prompt_cache_key` for `openai-responses` and `openai-codex-responses`: on a shallow copy, after an existing `onPayload` hook, clamped to the adapter's 64-character limit, and only while no key is set yet. Every other wire API keeps its payload byte-identical, and an unchanged payload keeps the hook's own return value. A single-variable probe against the failing gateway showed the same summary body answered 400 alone and 200 with the key. Unit tests cover the key, the clamp, an existing key, and existing hook semantics; a runtime test asserts the outbound summary request carries the session id. Docs: the compaction seam note carries the change in English and zh-CN, the /compact scenario expects the conversation identity, and the unreleased highlights entry records the fix.
Contributor
|
确认根因链成立,这份实现的边界处理是我见得最干净的几处之一:
与 #1164 的关系值得维护者注意:两者是同一问题的两面——#1164 是"摘要失败时无法知道请求形状"(可观测性),本 PR 是其中被探针定位出的那一个具体根因(缺 验证侧无保留意见:真实网关 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
在对接 Codex 后端的网关上,
/compact与自动上下文压缩失败(本机在 anyrouter 复现:api_style=responses、模型gpt-6-astra),而同一会话、同一提供商、同一模型的普通回合正常:摘要请求不经过 agent 的
streamFn,因此是会话里唯一不携带对话身份的请求。本 PR 让它带上该身份,其他行为不变。根因
compact自行组装流选项并交给Models.completeSimple,其中要求cacheRetention: "none";pi-ai 的 Responses 适配器因此不发送该字段:普通回合通过
streamFn传入sessionId: this.sessionId,总是带prompt_cache_key。单变量探针(同一端点、提供商、模型与凭据,每次只改一个字段):invalid codex requestprompt_cache_keytools/tool_choiceprompt_cache_key+instructions{model, input: "ping", stream: false}说明拒绝与摘要的提示形状、developer 角色、
max_output_tokens或缺少 Codex 信封无关:缺该 key 的请求一律被拒。改动
withCompactionRequestHeaders(已经给这一个请求套上会话标头的接缝)为两个 Responses 形状的 API 补回对话 key:onPayload钩子的返回值都保持原对象,未改动时原样返回;clampOpenAIPromptCacheKey(适配器 64 字符上限),且仅在尚未设置时添加;cacheRetention、Anthropiccache_control/prompt_cache_retention与 Codex 会话标头均不受影响。文档
docs/spec/03-runtime/02-agent-runtime.md、docs/spec/06-delivery/04-e2e-test-plan.md(均含 zh-CN)与docs/project/unreleased.md。不涉及 ADR:检查点载荷与details.failureReason词表未变。验证
pnpm -r --if-present test— 全工作区通过;agent-runtime75 文件 / 1127 测试,含 key 注入、长度截断、已存在 key、既有钩子语义,以及通过真实 Responses 适配器断言出站摘要体携带会话 id。agent-runtime与 desktop typecheck、check-architecture.mjs(base 取origin/main)、docs:check、docs:build、check:agent-policy、check:release-docs、check:pr-base— 全部通过(即仓库 CI 会跑的门禁)。/compact:成功。兼容性与风险
两个线协议的摘要请求多一个标准字段;无迁移、无 schema 或持久化格式变更,回退该提交即恢复原行为。