Skip to content

test(engine): lock in turn continuation after auto-compaction and long polls (#2129, #2136) - #2178

Draft
jacktrnr wants to merge 1 commit into
mainfrom
fix/2129-2136-continuation-findings
Draft

jacktrnr wants to merge 1 commit into
mainfrom
fix/2129-2136-continuation-findings

Conversation

@jacktrnr

Copy link
Copy Markdown
Contributor

Summary

I investigated #2129 and #2136 against the persisted session records (message and part rows plus the engine log) of the exact incidents each issue cites. In neither incident did the v1 session loop end the turn. So this PR has no engine change. It adds three session-loop regression tests that lock in the behavior both issues ask for, and it records the findings. It is a draft because the reported root causes could not be confirmed. The record contradicts them.

Refs #2129, refs #2136 (this PR does not close them; see "Proposed disposition").

Findings

#2129: the auto-compaction turn did not end on the summary

  • Both auto-compactions on the cited dates (2026-10-27 17:01 UTC and 2026-10-30 22:41 UTC) were provider overflows (Input is too long for requested model). Each has a compaction part with auto: true, overflow: true.
  • In both, SessionCompaction.process replayed the pending user request. The replay message was created 1 ms (10-30) and 4 ms (10-27) after the summary message completed. The engine log shows the loop going straight to the next step with no exiting loop. The same loop then answered the request (10-30: three new figure versions, finish stop at 22:44:56).
  • The quote in the issue, "The user resent the same message since I never actually presented H1-H3", is the model's reasoning about the engine's replay. The replay is a verbatim, non-synthetic copy of the user message (by upstream design), so the model and the transcript-mining pass that drafted fix(engine): after auto-compaction the turn ends with the summary and the user's request is dropped #2129 both read it as a user resend. The user sent nothing between the overflow and the answer.
  • The other compactions in that window were manual (auto: false). By design they end on the summary.

#2136: the polling turn did not end silently

  • The issue was filed from the session where it happened. The poll is the sleep 420; … bash call with a 500 s timeout. It started at 22:59:21 UTC and returned at 23:06:21.
  • The user's "continue. you stopped mid session" arrived at 23:04:53, 3.5 minutes into the 7-minute sleep, while the tool was still running. A second user message (23:01:45) was also sent mid-poll.
  • The log shows loop step=30 running for the whole sleep, then step=31 at 23:06:21 the moment the tool returned, and the session went on working until 23:41. There is no assistant message in the session with a silent stop (finish: stop with no text).
  • So what ended the turn was neither a model stop reason, a loop exit condition, nor a timeout. The turn never ended. The perceived stop was a long tool call that produced no visible output. The UI gives no running/elapsed signal during a silent sleep, which is a UX question outside the engine loop.
  • Upstream Assistant turn that ends with reasoning only (no text, no tool call, finish "stop") is settled silently and the agent stops anomalyco/opencode#55378 (a reasoning-only stop turn settled silently) is a different mechanism. The amicode silent-turn guard already covers it when the reasoning text is non-empty, and nothing in this incident matches it.

Tests (session loop, existing TestLLMServer harness)

In packages/opencode/test/session/prompt.test.ts:

  1. loop answers the replayed request after auto-compacting a provider overflow (#2129): a 413 overflow leads to a summary, then the replayed request, which is answered in the same loop. The last model request carries both the pending request and the summary.
  2. loop continues the turn after auto-compacting at the context limit mid-task (#2129): a tool step whose usage crosses the usable context leads to compaction, then the auto-continue instruction, and the turn goes on past the summary.
  3. loop continues after a polling bash call and picks up a message sent mid-poll (#2136): two sleep; echo polls. The loop returns each result to the model and picks up a user message sent during the first poll.

All three pass on unmodified main, which is consistent with the findings. To show they guard the reported symptoms, I mutated the materialized loop and confirmed that:

  • with break after compaction (turn ends on the summary), tests 1 and 2 fail;
  • with the exit test treating a tool step as terminal (turn ends after a tool call), test 3 fails (2 calls instead of 3).

Observation (not changed)

On the non-replay auto path (test 2), the continued turn receives [compaction prompt, summary, preserved tail, "Continue if you have next steps, or stop and ask…"]. If the turn's user message falls outside the preserved tail (2k–8k tokens), the request reaches the model only through the summary. The summarizer template does capture it ("Current request: …" in the real summaries), and no incident shows a drop. Making the request verbatim on this path would be a compaction-design change (#1820/#1927 territory), not a fix for these reports.

Proposed disposition

Verification

  • bun test test/session/prompt.test.ts test/session/compaction.test.ts (materialized tree): 118 pass, 2 skip, 0 fail
  • bash packages/app-bundle/scripts/engine_typecheck_gate.sh: OK (only Base-pin drift: manifest upstream_base_sha stale vs absorbed overlay #1229 allowlisted errors)
  • node packages/app-bundle/scripts/refresh_manifest.mjs then drift_gate.mjs: PASS (manifest hash updated for the test file)

🤖 Generated with Claude Code

…g polls (#2129, #2136)

Session-loop regression guards for the two "dropped continuation" reports.
The persisted records of the cited incidents show the v1 loop did not end
either turn, so this adds no engine change:

- #2129: both auto-compactions (10-27, 10-30) were provider overflows. The
  loop replayed the pending request 1 ms after the summary finished and
  answered it in the same loop. The "user resent the same message" seen in
  the model's reasoning was that engine replay, not the user.
- #2136: the user's "you stopped" message arrived 3.5 min into a 7-min
  `sleep 420` bash poll. The tool returned at 23:06:21 and the loop went
  straight to the next step. No silent stop exists in that session.

Tests (each fails under a mutation that reintroduces the reported symptom):
- overflow -> compaction -> replayed request answered in the same loop
- token-limit compaction mid-task -> turn continues past the summary
- polling bash calls -> loop continues, picks up a message sent mid-poll

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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.

1 participant