Skip to content

fix(reasoning-drop): auto-disable compress reasoning drop on strict-echo upstreams (#361) - #363

Merged
ranxianglei merged 3 commits into
masterfrom
2026-09-10_strict-echo-reasoning-gate
Sep 12, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-09-10_strict-echo-reasoning-gate

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Auto-disable the compress.reasoning.drop pass on strict-echo thinking upstreams so a DeepSeek thinking-mode session can't be broken by the default drop:true.

Why

dropCompressReasoning() (default drop:true) strips the reasoning run preceding a closed compress round. On strict-echo thinking upstreams (DeepSeek thinking mode: reasoning_content must be passed back when tools are in play) that independently reproduces the HTTP 400 on the next request — the same failure class fixed proxy-side in billion-context#690 and kernel-side (fold atomicity) in acp-kernel#245.

Verified against the original report in billion-context#684, which states the closed-compress DROP is a loss path distinct from the fold split and reproduces the identical invalid_request_error ("The reasoning_content in the thinking mode must be passed back to the API") even after a single closed compress round.

#348 tightened closed-round detection and kept a manual per-provider drop:false escape hatch, but the drop pass itself had no provider strictness gate — this PR adds the auto gate.

How

Ported the sibling isStrictReasoningEcho() detector, adapted to pi's signal sources:

  • New pure isStrictReasoningEcho(provider?, baseUrl?) — static DeepSeek check from ctx.model.baseUrl / provider name (case-insensitive substring).
  • New pure applyStrictReasoningGate(cfg, provider?, baseUrl?) — forces drop:false on a strict-echo upstream, preserving threshold; no-op (same reference) otherwise.
  • Wired into runtime.reasoningDropFor(ctx); logs compress-reasoning-auto-disabled once per session.

The gate overrides an explicit drop:true (safety wins). Cost-free for non-thinking models on those hosts (they emit no thinking parts). GLM-thinking / QwQ / self-hosted mirrors are deliberately not auto-detected (avoids disabling the pass for their non-thinking models) — they keep the documented manual override.

No learn-on-400 self-heal here: the in-process adapter does not own the HTTP layer (Pi makes the LLM call; no extension hook observes the upstream 400), unlike the proxy.

Scope

  • 6 files: src/reasoning-drop.ts, src/runtime.ts, tests/reasoning-drop.test.ts, CHANGELOG.md, CONFIGURATION.md, CONFIGURATION.zh-CN.md.
  • Does not bump the acp-kernel pin (stays at master's 0.0.62). Full closure pairs with acp-kernel 0.0.63 turn-integrity (压缩失败或者终止 #245), which lands in the next release PR.
  • Verified locally: typecheck clean, 700 tests (697 pass / 0 fail / 3 skipped), build success.

中文摘要:为 DeepSeek 思考模式等严格回传上游自动禁用 compress reasoning drop(默认 drop:true 会丢 reasoning 触发 HTTP 400),移植代理侧 #690 的静态 deepseek 检测并接入 runtime,GLM/QwQ/自托管镜像仍走手动 drop:false;已验证 typecheck/测试/构建全绿。

Fixes #361

@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Extension Artifact

Branch: 2026-09-10_strict-echo-reasoning-gate (5c70710)

Option A — Install from npm PR tag (recommended)

pi install npm:billion-context-pi@pr-363

Each push to this PR publishes a new version under the pr-363 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pi-pr363.tgz
pi install ./package

This comment is automatically updated on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,开始 review PR #363(auto-disable compress reasoning drop on strict-echo upstreams)。先做重复筛查 + 合理性审核(问题复现/根因层次/方案评估),再查 diff 整洁度,随后本地跑 typecheck / 700 tests / build。有结论会回贴。

ework-agent added 3 commits September 10, 2026 23:42
…cho upstreams (#361)

The default drop:true dropCompressReasoning pass strips the reasoning run
preceding a closed compress round. On strict-echo thinking upstreams
(DeepSeek thinking mode: tools in play require reasoning_content to be
passed back) that independently reproduces the HTTP 400 on the next
request — the same failure class fixed proxy-side in billion-context#690
and kernel-side (fold atomicity) in acp-kernel#245. #348 left a manual
per-provider drop:false escape hatch but no auto gate.

Port the sibling isStrictReasoningEcho() detector, adapted to pi's signal
sources: static DeepSeek check from ctx.model.baseUrl/provider name
(case-insensitive substring). The in-process adapter does not own the HTTP
layer, so there is no learn-on-400 self-heal here — GLM-thinking / QwQ /
self-hosted mirrors keep the documented manual override. Gate forces
drop:false regardless of config (safety wins), cost-free for non-thinking
models on those hosts, logs once per session.

Fixes #361
Drives the real production path (createRuntime -> reloadConfig ->
reasoningDropFor) to cover what the pure-function tests cannot:
ctx.model.baseUrl reaching the gate when the provider name does not
contain 'deepseek', an explicit drop:true losing to the safety
override, threshold survival, and the info log firing exactly once
per session.
A literal backslash-n glued the ```json opener to the prose line, so
the fence never opened mid-line and the next physical fence line
started a stray code block that swallowed the following sections in
rendered output. Split onto its own line (matches CONFIGURATION.zh-CN.md).
@ranxianglei
ranxianglei force-pushed the 2026-09-10_strict-echo-reasoning-gate branch from b5d09e5 to 5c70710 Compare September 10, 2026 15:50
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

Review complete — approved, ready to merge.

Triage (bug class — verified before touching anything):

  • The reported failure is real and this hits the right layer. dropCompressReasoning() (src/reasoning-drop.ts:133) strips thinking parts from closed-round compress messages under the default drop:true (threshold 2048) with no provider awareness — on DeepSeek thinking mode the next request loses reasoning_content → HTTP 400. This is a loss path distinct from the kernel fold split (acp-kernel#245) and the proxy fix (billion-context#690): neither covers this in-process pass, so gating it pi-side is the correct place, not a band-aid.
  • Signal source verified against the installed host types: baseUrl and provider are real fields on pi-ai's Model<TApi> (dist/types.d.ts:647) and ExtensionContext.model (pi-coding-agent 0.83.0), so detection works at runtime — not just plausible typing.
  • Design checks out: safety-first (explicit drop:true loses), threshold preserved, same-reference no-op for non-strict upstreams, log-once per session, GLM-thinking/QwQ/self-hosted mirrors deliberately left on the manual override. Skipping learn-on-400 self-heal is right here — the in-process adapter doesn't own the HTTP layer.
  • Dup screen: extends Protected-message exemption inflates the incompressible context floor: per-compression reasoning is never reclaimable (~83.5% of measured residual) #336/reasoning-drop never fires in single-user-message marathon sessions (closed-turn gate unreachable) #348 rather than duplicating them; twin fixes live in other repos.

Verification (run locally on the branch): typecheck clean · 702 tests, 0 fail / 3 skipped · build success.

Two small issues I fixed directly on the branch (head is now 5c70710; also rebased onto current master a8dfb49 since the PR was behind — only package.json/lockfile moved, conflict-free):

  1. test(reasoning-drop) — added tests/e2e-reasoning-drop-gate.test.ts (+2 e2e tests). The pure-function tests alone would still pass if someone removed the gate call in runtime.reasoningDropFor or stopped passing ctx.model.baseUrl into it; the new file drives the real createRuntime → reloadConfig → reasoningDropFor pipeline and covers: baseUrl-only detection (provider name without "deepseek"), explicit drop:true losing to the gate, threshold survival, and exactly-once-per-session logging.
  2. docs(configuration) — pre-existing render bug in the exact paragraph this PR documents: CONFIGURATION.md:536 contained a literal \n gluing the ```json opener to the prose line, so the fence never opened and the next physical fence line started a stray code block that swallowed the following sections in rendered output. Split onto its own line (matches CONFIGURATION.zh-CN.md). Revert-able as its own commit if you disagree.

The json-example re-indent in your diff is fine — it aligns the fence with the surrounding block's 3-space convention.

Full closure pairs with acp-kernel 0.0.63 turn-integrity (#245) in the next release PR as you noted — nothing further needed here.

中文一句话:审核确认 strict-echo 自动禁用 reasoning drop 的修复定位正确(pi 侧 DROP pass 缺严格回传门控,属独立丢失路径,与内核/代理修复互补),已直接补齐 e2e 接线测试并修复 CONFIGURATION.md 一处既有代码围栏渲染 bug,rebase 至最新 master 后 typecheck/702 测试/构建全绿,可以合并。

@ranxianglei
ranxianglei merged commit 785caa4 into master Sep 12, 2026
9 checks passed
HangxiangMa pushed a commit to HangxiangMa/billion-context-pi that referenced this pull request Sep 21, 2026
…-echo-reasoning-gate

fix(reasoning-drop): auto-disable compress reasoning drop on strict-echo upstreams (ranxianglei#361)
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.

Twin of billion-context#684: reasoning-drop needs a strict-echo gate (DeepSeek thinking mode)

1 participant