qwen-code PR skips re-injecting identical hook context, curbing O(T²) token cost
yiliang114 · ghdev · 2026-10-14
PR #14129 in QwenLM/qwen-code fixes a token-cost issue: a UserPromptSubmit hook returning additionalContext appends its payload to the user message every turn, and an unchanged payload accumulates permanently in session history, costing tokens on the order of T² over a session.
The fix: if the hook's bytes exactly match a block already appended in the shallow conversation history, it skips re-injection and corrects the stored transcript to match what the model actually received. Byte-level comparison means no state can go stale; an in-process receipt stamp prevents spoofing—model output, IDE-supplied blocks, or caller-authored copies of the injection shape cannot suppress fresh delivery. Since the stamp can't survive serialization, resumed sessions re-derive it from per-turn hook provenance, re-injecting when no provenance exists.
The bundled retrieval extensions are the easiest way to hit this: their auto-recall hooks render identical bytes turn after turn when upstream results are stable.
More from coding & agent
- Garry Tan endorses Aside Browser as the fix for agents getting blocked on the web — garrytan · 2026-10-23
- 1Password launches tool letting AI agents log in for you without seeing your password — AndrewSchmidtFC · 2026-10-23
- MCP server turned rogue 30 days after approval, prompting open-source mcp-guard lockfile tool — ErgoniaWorks · 2026-10-23
- Test: Coding Agents Won't Use an MCP Tool Unless AGENTS.md Mentions It — colinmcnamara · 2026-10-23
- Open-Source Tennis Models Plus Claude Turn Video Into a World-Class Coach — tweetsatpreet · 2026-10-23
- awesome-ai-apps: 132 Free Open-Source AI Agent and RAG Projects on GitHub — Arindam_1729 · 2026-10-23