Skip to content

fix(llmloop): avoid resending rejected compression input - #1885

Open
biheto wants to merge 2 commits into
alibaba:mainfrom
biheto:fix/compression-retry
Open

biheto wants to merge 2 commits into
alibaba:mainfrom
biheto:fix/compression-retry

Conversation

@biheto

@biheto biheto commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

Avoid resending the last rejected compression input when the review loop moves from asynchronous compression to its synchronous fallback. Related to #1877.

This is a controlled reproduction through the actual RunMainTask loop, not a production incident or a timing benchmark. The improvement is one fewer redundant request in the reproduced workflow; it does not make an oversized review succeed.

Reproduced execution path

On upstream 34517e3, with MaxTokens=1000:

  1. A file_read result takes the conversation above the 60% soft threshold. Background compression submits the old conversation prefix A and receives an HTTP 400 input rejection.
  2. The next tool result adds B, crossing the 80% warning threshold. Partitioning keeps B in the active zone, so the synchronous fallback still submits A. The complete conversation changed, but the compression request did not.
  3. The second rejection produces the existing StopCompression outcome. That stop was already correct; the second request was unnecessary.

The regression uses a barrier to complete the background failure before the next tool round, rather than relying on goroutine timing. Before applying the production change, its assertion failed with two compression requests. After the change, it observes one:

Full-loop measurement Before After
Main-task requests 2 2
Compression requests 2 1
Unique compression inputs 1 1
Completed false false
Stop reason compression compression

Run the regression from this branch:

make test 'PACKAGES=./internal/reviewtask -run TestCompressionRetryRejectedInput/main_loop_warning_threshold'

Relevant output:

# Before the production change
main_requests=2 compression_requests=2 unique_compression_inputs=1 duplicate_inputs=1 input_bytes=[3544 3544]

# Patched
main_requests=2 compression_requests=1 unique_compression_inputs=1 duplicate_inputs=0 input_bytes=[3544]
completed=false stop=compression

Here, input_bytes measures serialized shared message objects, not network bytes. A separate TestCompressionRetryHTTPBoundary exercises the real OpenAI SDK against a local HTTP server: the permanent-rejection cases send one 3521-byte request, while 429 recovery, an explicit provider retry directive, and a temporary 413 still permit recovery. No human-time, billing, or review-success-rate improvement is claimed.

Small, conversation-local change

  • Remember only the last rejected compression prefix's digest and original error in the existing compressionState. Hash the rendered compression zone, not the full history or message count. The template, model and completion limit are fixed within that conversation.
  • Recognize wrapped OpenAI/Anthropic SDK HTTP 400/413 errors. Do not cache responses carrying x-should-retry: true, Retry-After, or retry-after-ms; leave other statuses, timeouts and unrecognized errors alone. No classification by error-message text.
  • Keep the original failed request record and the unchanged history. A skipped send does not create a fictitious request record or turn an incomplete review into a completed one.
  • Keep state independent between conversations; a cancelled background job cannot overwrite a newer rejection. Different compression input can still be attempted.

There is no new CLI surface, persisted event/schema, history truncation, or all-history failure cache. This is narrower than the whole of #1877. It also differs from #1170's input-size bound and #1583's truncated-summary handling.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

How Has This Been Tested?

Integration commit: ed43293a513246598fc919ec1057dc627452cec1, merging upstream e170728a2f05cada736aa481ce7ef26bbbadd3fb into this PR branch without rewriting its history. The resolved tree is 342c18bc33fea639cacee29ad39e92878b076e10.

The merge preserves upstream's generic llmloop.Task / reviewtask split. Full-loop and real-SDK HTTP-boundary regression tests now live in internal/reviewtask; white-box cache and cancellation tests remain in internal/llmloop. The contribution remains limited to the rejected-input retry fix.

Validation on Windows amd64, GCC 16.2.0 UCRT, and Git Bash for Make recipes, using both CI-pinned Go 1.26.10 and Go 1.27.0:

  • make license-add: no missing headers. make check: passed on the final commit with Go 1.26.10 and on the identical pre-commit tree with Go 1.27.0. make build: passed on the final commit with both toolchains; --version reports ed43293.
  • Full make test 'PACKAGES=./... -p 2 -timeout 600s': 26 packages passed on the final commit with each toolchain, with the Makefile's -race enabled.
  • Full make coverage 'PACKAGES=./... -covermode=atomic -p 2 -timeout 600s': 91.0% with Go 1.26.10; 92.3% with Go 1.27.0. Both exceed the 90% gate.
  • make test 'PACKAGES=./internal/llm ./internal/llmloop ./internal/reviewtask -p 2 -run CompressionRetry\|NonRetryableInput -count=30 -timeout 180s': passed with -race on the final commit with Go 1.26.10 and on the identical pre-commit tree with Go 1.27.0. The actual-loop regression still reports main_requests=2 compression_requests=1 unique_compression_inputs=1 duplicate_inputs=0, completed=false stop=compression; the original failed request record is retained.
  • Tests cover changed inputs of the same message count, conversation isolation, error/history preservation, transient recovery, provider hints, and a cancelled old job returning after a newer failure.
  • Generated provider presets, SHA-pinned action references, npm run test:launcher, and CLI version/help smoke checks: passed.
  • GOTOOLCHAIN=go1.26.10 go run golang.org/x/vuln/cmd/[email protected] ./...: passed, no vulnerabilities found. The same scan using this host's Go 1.27.0 reported standard-library vulnerabilities, so the project's pinned toolchain was used for this check; no dependency or toolchain policy changes are part of this PR.
  • Earlier OCR source reviews: complete, 3 production files, 0 findings (e58882fb-6dd9-480e-8cfd-30c8285fdeda); recovery-header refinement: complete, 1 file, 0 findings (d16c6f36-92e7-408d-8ba5-faa2d5397d71). Pre-commit integration review: complete, both selected integration-related production files (compression.go, loop.go), 0 findings (274bf138-d99d-4cad-9635-305e2e436bc9). That last run recorded one failed attempt to read a directory as a file; it is not a claim of a fresh eight-file review or a substitute for execution tests or personal review.
  • The previous local race-binary startup failure (0xc0000139, GCC 8.1.0) was resolved for this validation by selecting GCC 16.2.0 UCRT in the test process only. System-wide configuration was not changed.

Platform limits: Windows-specific skips remain, including POSIX permissions/signals, PTY and symlink-dependent cases. Linux-only paths and the upstream cross-platform CI matrix are not claimed as locally executed. All Make commands above used an explicit Git Bash SHELL on this host.

Local Go 1.26.10 setup note: initial Makefile package discovery failed on automatic VCS stamping in this nested worktree. Its first make check did not pass; rerunning with process-local GOFLAGS=-buildvcs=false passed. The same setting was used for the Go 1.26.10 coverage, repeated regression and build runs. It does not disable race detection; the final commit SHA is recorded separately in the logs and binary version.

Checklist

  • Code style, license, English-source and whitespace checks pass.
  • I have personally reviewed and understood all AI-assisted changes.
  • Regression tests distinguish the duplicate-send behavior before and after the change.
  • New and existing unit tests pass with race detection; platform-specific skips are disclosed above.
  • Documentation assessed: no new user-facing option or configuration to document.
  • I have signed the CLA.
  • I have reviewed the AI output and will answer substantive maintainer questions from my own understanding.

AI assistance: OpenAI Codex / GPT-6 Astra assisted with investigation, implementation, tests and this PR description. OpenCodeReview / gpt-5.6-sol performed the automated source reviews. Those reviews do not certify the contributor's personal-review checklist items. No AI authorship trailers are included in the commit.

Related Issues

Related to #1877; not claiming to close all of its recovery-policy scenarios.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 3 selected item(s).

@NanaseInori NanaseInori left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all seven changed files and the surrounding async cancellation/application path against #1877. I found no blocking defect in the scoped duplicate-request fix.

The rejection key covers the rendered compressible prefix rather than the full conversation length, and both synchronous call sites reuse the same conversation-local state. The cancellation check and cache update execute under the same mutex as cancelPendingCompression, so a superseded background attempt cannot overwrite the newer cached rejection. The cached path preserves the original error/history and returns before creating a fictitious request record.

The tests exercise the actual main-loop threshold transition, changed inputs with the same message count, independent conversations, transient recovery, recovery headers, and an old cancelled request completing after a replacement. The typed-error classifier avoids treating plain error text as an HTTP input rejection.

Compared with #1170 and #1893, this fixes repeated submission of a rejected input; it does not claim to bound that input or make an oversized review complete. That distinction matches the linked issue and the PR's deliberately narrower scope.

This is a source-and-test review, not a local Go/race-suite execution. GitHub currently reports this branch as unmergeable; the integration conflict needs resolution and the resulting head should run the required checks, including working race validation. This approval does not certify the author's outstanding human-review attestations.

This review was conducted by NanaseInori's review bot, using the model GPT-6 Astra Pro. If you need a human review, please manually @NanaseInori.

@biheto

biheto commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

我审查了所有七个更改过的文件以及相关的异步取消/应用路径。 #1877 我在范围重叠请求修复中没有发现阻断缺陷。

拒绝键覆盖渲染后的可压缩前缀,而非整个通话时长,两个同步呼叫站点都重复使用相同的会话本地状态。取消检查和缓存更新在与 cancelPendingCompression 相同的静止假体下执行,因此被替换的后台尝试无法覆盖较新的缓存拒绝。缓存路径保留原始错误/历史,并在创建虚构请求记录前返回。

测试包括实际的主环阈值转换、相同消息计数的变换输入、独立对话、瞬态恢复、恢复头以及替换后完成的旧取消请求。类型错误分类器避免将纯错误文本视为 HTTP 输入拒绝。

与 #1170 和 #1893 相比,这解决了拒绝输入的重复提交;它并不声称要约束这些输入,也不会让一份冗长的审查变得完整。这一区分与相关议题及公关故意更狭窄的范围相符。

这是一次源代码和测试评测,不是本地的围棋/竞速套件执行。GitHub 目前报告该分支不可合并;集成冲突需要解决,导致的负责人应执行必要的检查,包括工作种族验证。本批准不证明作者卓越的人工审核证明。

本次评测由七濑 Inori 的评测机器人进行,使用了 GPT-6 Astra Pro 模型。如果你需要人工审核,请手动 @NanaseInori 。

感谢详细审查,尤其是对异步取消、旧后台任务完成顺序,以及错误分类边界的核对。

我会保持当前改动范围:避免重复提交已被拒绝且内容未改变的压缩输入,不将其扩展为输入大小限制,也不把它描述为长评审完整性的解决方案。

接下来会先解决与目标分支的集成冲突,核对冲突处理没有改变原有行为,再针对最终提交重新执行项目要求的检查、完整测试和相关回归测试,包括在支持的环境中运行 race 检测。

完成后会补充最终提交 SHA、实际执行的命令及结果。如果有未完成或受环境限制的检查,也会明确说明,不将此次源码审查批准视为运行验证的替代。

感谢指出剩余的集成和验证事项!

@biheto

biheto commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

感谢详细审查。与目标分支的集成冲突已解决,更新已推送到同一个 PR,最终提交为:

ed43293

此次集成适配了主干的 llmloop.Task / reviewtask 拆分:真实评审循环及 HTTP 边界回归测试迁入 reviewtask,缓存和异步取消相关测试保留在 llmloop。

已针对最终提交完成实际验证:

  • 完整 26 个包的测试通过,保持 -race 开启。
  • 相关回归测试在 race 模式下重复 30 次,通过。
  • make check、make build 和漏洞检查通过。
  • 项目 CI 固定的 Go 1.26.10 下,完整覆盖率为 91.0%,超过 90% 门槛。
    关键回归结果保持为:
    main_requests=2 compression_requests=1
    unique_compression_inputs=1 duplicate_inputs=0
    completed=false stop=compression
    即相同的拒绝输入不再重复发送,同时保留原始失败记录、历史和既有停止结果,并未将未完成的评审标记为完成。

GitHub 目前确认已无合并冲突;远端 Linux CI、五项跨平台构建及 CLA 均通过。Windows 原生任务和三项 CodeQL 检查仍在排队,因此暂不声称全部远端检查通过。

实际命令、工具链版本、环境问题的处理及平台跳过项均已更新到 PR 正文。

This branch has not been deployed

No deployments
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