Repository navigation
fix(core): recover compaction from empty text history - #5238
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4cb3ead559
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const structuralLegal = pass.messages('legalize-structure', relocated, (messages, ctx) => | ||
| cleanMessages(messages, ctx.report, spec.preserveSignedBlankText === true), | ||
| ); |
There was a problem hiding this comment.
Run cleanup after tool declaration deduplication
When a blank system message contains only tool declarations that are all shadowed by profile or newer declarations, this pass retains it because carriesStructure sees the pre-deduplication tools; the later legalizeTools pass then reduces tools to [], with no subsequent cleanup. The existing duplicate-declaration case in packages/core/test/llm/lifecycle/run.test.ts demonstrates that the resulting OpenAI request still contains { role: 'system', content: '' }, so providers returning the targeted empty-text 400 continue to fail and strict recovery rebuilds the same payload. Repeat cleanup after tool legalization or otherwise remove messages emptied by deduplication.
AGENTS.md reference: packages/core/src/llm/AGENTS.md:L1-L1
Useful? React with 👍 / 👎.
commit: |
7Sageer
left a comment
There was a problem hiding this comment.
工具声明去重仍会产生本 PR 要消除的空 system 文本,需要在最终编码前再清理一次。
| relocateToolMedia(messages, spec.media), | ||
| ); | ||
| const idsLegal = pass.messages('legalize-tool-call-ids', relocated, (messages) => | ||
| const structuralLegal = pass.messages('legalize-structure', relocated, (messages, ctx) => |
There was a problem hiding this comment.
[P1] legalize-structure 会把带 tools 的空 system 当结构消息保留,后续 legalizeTools 又可能将其所有声明作为旧重复项删除,留下 content: ''。当前 packages/core/test/llm/lifecycle/run.test.ts 新增用例的期望请求里已经包含这种 { role: 'system', content: '' },所以原报告的 provider 仍会 400。请在工具声明去重后清理这类已失去结构内容的消息,并把该 fixture 的期望改为不含空 system 文本。
* refactor(core): run loop turns on an independent state machine - add an actor runtime for loop and turn execution - unify turn hooks and asynchronous lifecycle settlement - simplify loop contracts and cover turn lifecycle behavior * fix(core): park recorded notifications until intake * fix(core): settle forced aborts past stuck hooks and tools * docs(core): document loop emitted events and public API * fix(agent-core-v2): skip onDidFinishStep hooks for aborted steps
* refactor(core): unify llm event stream and harden behavior tests - unify run boundaries, request summaries, delta events, retries, and outcomes - migrate Loop, agent-core-v2, and klient consumers to the unified event vocabulary - add aimock-backed transport coverage and restore historical LLM behavior tests - update the Nix dependency hash and affected snapshots * refactor(llm): legalize deferred tools in the resolver - strip deferred metadata during legalize for models without dynamic loading - stop convert from dropping deferred tools and dedupe declarations with top-level priority - merge protocol capabilities once at the encode pipeline entry - remove deferred tools in the dynamic loop resolver and announce their names first * refactor(llm): unify deferred tool request views - remove dynamic-only request branching from ToolSelect resolution - keep non-dynamic system schemas out of top-level tools - preserve baseline tools for side requests before capability shaping * refactor(llm): share the tool select request view - reuse deferred shaping in the resolver and request preview - preserve initial tool announcements in request previews - cover preview parity with deferred tools * refactor(llm): strip deferred metadata in tool select Remove deferred metadata from non-disclosure ToolSelect request views while preserving the loop baseline. Keep core legalization as the fallback for requests that bypass ToolSelect. * refactor(llm): contain tool disclosure in resolver * refactor(llm): hash the full request tool list - compute toolsHash over every input tool, including deferred ones - note the resolver and legalization timing on the llm run events * refactor(llm): remove the tool select experimental flag - drop the tool-select flag, env var, and [experimental] config entry - gate deferred tool disclosure solely on model capabilities - remove the desktop forced env and update the MCP and env-var docs - cover mid-loop active-tool requests with an empirical loop test * test(desktop): assert browser tool disclosure in the request view The previous assertions called loadableToolsAnnouncement() with no arguments, a calling form no production code uses; the model-facing disclosure is built per request by the ToolSelect resolver. Assert the request view instead: requestTools strips the deferred browser tool from the request tool list, shapeHistory injects the snapshot announcement naming it, and a reminder step after the control switch turns the removal into a <tools_removed> delta.
* test(core): cover empty text request recovery * fix(core): clean empty text before request encoding * chore: add empty text recovery changesets * test(core): cover cross-provider signed empty text * fix(core): drop unsupported signed blank text
4cb3ead to
bba9c9b
Compare
🦋 Changeset detectedLatest commit: bba9c9b The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
💡 Codex ReviewWhen a user sets AGENTS.md reference: AGENTS.md:L193-L197 kimi-code/packages/core/src/hook/loop/registry.ts Lines 136 to 138 in bba9c9b For existing compiled or JavaScript Loop consumers whose AGENTS.md reference: AGENTS.md:L207-L209 kimi-code/packages/core/src/llm/protocol/rules/tools.ts Lines 47 to 49 in bba9c9b When a caller uses the core requester directly without the Agent ToolSelect resolver, a system-message declaration sharing a name with a deferred profile tool is now dropped in favor of the profile entry. ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
aff4491 to
59cea24
Compare
Part 5/7 of the loop stack onto
main. Identical diff to #5214, previously reviewed and merged into the loop integration branch. Stacked on #5237; the shown diff contains only this PR's own changes.Requirement or Bug
Web 2.7.1 用户使用 Kimi K3.1 Pro 执行 compact 时,历史消息中的空
text会使压缩请求被 HTTP 400Invalid request: text content is empty拒绝,导致会话无法完成压缩。这个 PR 让包含空文本的旧会话在编码阶段得到清理,并让服务端的 empty-text 拒绝进入已有的 strict projection recovery。相邻的 #4300 处理空工具结果;本 PR 覆盖普通 user/assistant 空文本、跨 provider 的签名空文本,以及对应的恢复分类。
Bug Reproduction Steps
text,或从 Gemini 会话带来带thought_signature_b64的空文本。content: ""或含空textblock 的请求,服务端返回上述 400;该错误被归类为普通status,不会触发 strict recovery。修复后,空内容在发送前被移除,残余结构错误会进入 strict projection 重试。Root Cause
共享
runPipeline没有接入已有的cleanMessages(),所以空文本能一直到达协议出口。Gemini 所需的签名空文本也被无差别保留到其他协议,但这些协议不会保留其签名元数据,仍会发出空块。同时,
text content is empty不在结构错误识别列表中,导致已有 strict projection recovery 无法接管。这个 PR 是在共享编码与错误分类层修复根因,不是迁移会话数据或针对单一 provider 的绕过。Code Changes
legalize-structure,复用现有清理逻辑;工具调用、动态工具声明、媒体和有意义的文本继续保留,空工具结果仍由现有渲染逻辑生成非空状态文本。text content is empty识别为request_structure,复用现有 strict projection recovery,不新增 compact 专用恢复循环。@moonshot-ai/corepatch changeset。Behavior Changes and Affected Users
content: ""或空textblockthought_signature_b64的空文本text content is emptystatus,不进入 strict recoveryrequest_structure,执行一次 strict projection 重试验证结论:目标回归覆盖普通空白、签名空白、空 assistant、工具调用保留、空工具结果占位和错误分类;独立只读复审无 P0/P1/P2 发现。未做真实 provider 的 compact 端到端验证;最终基线的完整 core 套件交由 PR CI 验证。
验证明细
loop-refact基线:Kimi/OpenAI、Google GenAI、错误分类目标测试 3 passed / 60 skipped。packages/core与packages/agent-core-v2TypeScript 检查通过。pnpm lint通过,包括 comments、oxlint、import boundaries、guards、ratchet、test-doubles、quarantine 和 instructions。pnpm run check:duplication 3c7b8ecc7a8e85d2d06c38a6681ca4036288d876通过,无新增重复。Checklist
/approve).(无外部 issue;问题、复现和相关工作已在上方说明。)gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.