Skip to content

fix(reasoning): close rounds on tool-result evidence, not user messages - #349

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-10_reasoning-round-evidence
Sep 9, 2026
Merged

fix(reasoning): close rounds on tool-result evidence, not user messages#349
ranxianglei merged 1 commit into
masterfrom
2026-09-10_reasoning-round-evidence

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #348

Problem

The compress.reasoning drop (shipped in #339, aligned with opencode-acp #377) closed a turn only when a genuine user message existed after the compress call. Long agentic sessions have no user messages after the opening prompt (observed: session 01a086ff — 64 entries, only 2 genuine user messages, 30 compress calls), so every compress round stayed "active" forever and its thinking survived as a permanent uncompressible floor. Observed with threshold: 1: 0 drop events; retained thinking 20612 / 8411 / 10581 chars.

Fix

Round closure is now judged on round evidence:

  • every compress toolCall in the message has its toolResult (role toolResult, matching toolCallId) at a later index, and
  • at least one message exists after that result (the round has demonstrably moved on).

Safety gates preserved:

  • in-flight calls (result missing, or result still the last message) are never touched;
  • the nudge push runs after the drop, so a synthetic user-role nudge can never close a round;
  • per-provider compress.providers.<name>.reasoning.drop = false remains the escape hatch for reasoning-replay providers (GLM).

Verification

  • Full pipeline repro on the real session 01a086ff (threshold: 1): compress-anchor thinking 20612 → 0 chars, deterministic across runs; non-compress thinking (82–1893 chars) untouched.
  • Test suite rewritten + extended: 653 pass / 0 fail (3 pre-existing skips). New reasoning-drop never fires in single-user-message marathon sessions (closed-turn gate unreachable) #348 scenarios: no-user-message assistant chain closes, result pending, result-before-call, mismatched id, mixed compress+other calls.
  • npm run typecheck clean.

Repro artifacts: ~/tmp/repro-rd.mjs (drives the dist transform with the real session entries).

…es (#348)

Long agentic sessions have no user messages after the opening prompt, so
the old 'genuine user message after the compress call' closure gate was
unreachable — every compress stayed 'active' forever and its thinking
survived as a permanent uncompressible floor (0 drops observed; 20.6K /
8.4K / 10.6K chars retained in session 01a086ff).

A round is now closed when EVERY compress toolCall in the message has its
toolResult (role toolResult, matching toolCallId) at a later index and at
least one message exists after that result. In-flight calls (result
missing or still the last message) stay untouched; the nudge push runs
after the drop so a synthetic nudge can never close a round; per-provider
compress.providers.<name>.reasoning.drop=false remains the escape hatch
for reasoning-replay providers (GLM).

Verified against the real session through the full transform pipeline:
compress-anchor thinking 20612 -> 0 chars with threshold:1, non-compress
thinking untouched. Tests: rewritten gate suite + new #348 scenarios
(no-user-message assistant chain, pending result, result-before-call,
mismatched id, mixed calls).
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

📦 Built Extension Artifact

Branch: 2026-09-10_reasoning-round-evidence (bc99b8c)

Option A — Install from npm PR tag (recommended)

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

Each push to this PR publishes a new version under the pr-349 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-pr349.tgz
pi install ./package

This comment is automatically updated on each push.

@ranxianglei
ranxianglei merged commit 1bdb4bf into master Sep 9, 2026
9 checks passed
@ranxianglei ranxianglei mentioned this pull request Sep 9, 2026
HangxiangMa pushed a commit to HangxiangMa/billion-context-pi that referenced this pull request Sep 10, 2026
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.

reasoning-drop never fires in single-user-message marathon sessions (closed-turn gate unreachable)

1 participant