Repository navigation
fix(agent-core-v2): keep media recovery across turns and compaction - #4413
Conversation
…very Add failing tests showing that requests after a media-degraded or media-stripped recovery do not extend the previous request's prefix: the next turn and compaction requests resend full media first, and a compaction request re-captures the strip snapshot, hiding media that the loop request still showed.
🦋 Changeset detectedLatest commit: 83fd0ad The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
Media recovery after a provider rejection was keyed by turn id and only honored for turn requests, so the next turn and compaction requests resent full media, got rejected again, and re-captured the strip snapshot. Keep a single agent-level recovery keyed by model alias and context prefix revision, applied to every later request until the model changes or the history is rewritten.
Keep the per-request strip retry budget separate from the inherited media snapshot so newly added media can recover from 413 and image-format rejections. Stop recapturing once this request has stripped its media or an inherited snapshot leaves no visible media. Advance the context prefix revision when context state is restored so undo invalidates media recovery without adding service dependencies. Cover later turns, automatic and manual compaction, bounded retries, and real prompt-to-undo flows for both degraded and stripped media.
|
@codex review |
Codex Review SummaryThis 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. |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ 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". |
…ness Every harness agent now checks that the first attempt of each turn request (a new turn or a later step) and of each full compaction request extends the last successful turn request: same model profile fields (cache key, thinking, extra params, response format, tool message conversion), same system prompt, same tools unless the tool-name set changed, and a history prefix. Requests after a model switch or a context prefix rewrite are skipped, and media turned into the degraded placeholder at the same position is allowed while the request runs under media-degraded recovery. Violations fail the running test. Add an end-to-end case that runs a turn after media recovery so the next-turn check sees both degraded and stripped projections.
Bring the branch up to main (including the compaction prompt-cache prefix matrix and its findGenerateCallPrefixBreak helper) together with the rebased media recovery change, which folds the standalone compaction media test into that matrix, and the test-harness guard that checks next-turn, next-step, and full compaction requests extend the last turn request.
…empt Recovery retries were recorded as the next baseline without being compared. Compare profile fields, system prompt, and tools on every attempt, and only treat a same-position media replacement as a prefix when it is the degraded placeholder or a single media path tag. Count real comparisons so an unwired guard fails the media-recovery test.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 83fd0ade82
ℹ️ 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".
| recovery.modelAlias !== request.modelAlias || | ||
| recovery.contextRevision !== request.contextRevision |
There was a problem hiding this comment.
Invalidate recovery when an alias is reconfigured
When an active session's provider or model configuration is replaced without changing its alias, the model catalog rebuilds the requester but the history revision remains unchanged, so this check continues applying the old backend's degraded/stripped-media policy. A newly configured media-capable backend therefore silently receives omitted or reduced media until the history is rewritten or the process restarts; before this commit, each new turn retried the full media. Include the resolved provider/model identity in the recovery key or invalidate recovery on catalog changes.
AGENTS.md reference: AGENTS.md:L131-L133
Useful? React with 👍 / 👎.
The behaviour of MoonshotAI#4421 has been in the requester since 94397aa, but its suite still asserted only that the lowered system message lost its `tools` field, which a message kept in place would also satisfy. Assert instead that no system message survives and the history keeps its length, and rename the case after what it protects. Also settle ten ledger rows that were already implemented here: MoonshotAI#3733, MoonshotAI#4413, MoonshotAI#4418, MoonshotAI#4421, MoonshotAI#4435, MoonshotAI#4460, MoonshotAI#4465, MoonshotAI#4516, MoonshotAI#4523, MoonshotAI#4532 and the MoonshotAI#4558 test calibration, each with a probe over the suite that pins it. Two rows carried a probe without a test-name selector (MoonshotAI#4557, MoonshotAI#4558), which aborted `--verify` for every other row; MoonshotAI#4557 is a changelog sync and now carries a manual probe.
MoonshotAI#4410 MoonshotAI#4413 MoonshotAI#4431 MoonshotAI#4450 MoonshotAI#4451 MoonshotAI#4485 MoonshotAI#4524 were each implemented earlier — the compaction prefix suite, the media-recovery case, the OAuth callback socket drain, the split delivering-work section, the compaction wording, the reasoning-key order and the 10-step todo reminder are all in the tree and pinned by their own tests. Each row now carries that probe. Only MoonshotAI#4410 needed care: upstream patched paths that this fork renamed (`human/llm/builtin/protocol` versus `human/llm/requester/bases`), so the matching was done on the behaviour — stripDynamicToolContext is gone and extractEventUsage already reads usage only on terminal response events. Ledger: closed 22 -> 28, remaining 71.
Requirement or Bug
修复媒体恢复在后续 turn 和压缩时失效,导致原始媒体被重复发送、新增媒体被误删的问题。
Bug Reproduction Steps
/compact:原图被重发并再次被拒。Root Cause
恢复状态按 turnId 保存且仅 turn 请求读取;继承的 strip 快照与单次请求的重试预算耦合;undo 恢复历史时未递增
prefixRevision。这是根本修复:恢复状态改为跟随模型和上下文前缀,并独立限制单次请求的 strip 重试。
Code Changes
llmRequester.mediaRecovery。Behavior Changes and Affected Users
影响范围:通过 TUI、print、desktop、web、VS Code、ACP 或 SDK 使用图片,并遇到 413 或图片格式拒绝的会话。
/compact用户mediaDegradedTurns/mediaStrippedTurnsmediaRecovery/api/v1/debug、kimi-inspect 及旧 key 读取方未触发媒体恢复的请求,以及配置、命令、wire 和 SDK 导出契约不变。
测试覆盖与验证:
llmRequester:跨 turn、auto / manual compaction、模型 / revision 失效、新增媒体与 strip 重试上限。undo:degraded / stripped 恢复后 undo 会恢复原媒体。fullCompaction:18 个前缀矩阵用例;harness 守卫覆盖后续 turn / step / compaction。tool.test.ts的既有超时和rpc-events.test.ts的ENOTEMPTY(单独重跑通过),均与 PR 无关。类型、无注释和 manifest 检查通过;lint:imports剩 4 处既有问题。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.