fix(harness): keep compacted prompt ending on a user turn#81
Open
adolfo-tamayo wants to merge 1 commit into
Open
fix(harness): keep compacted prompt ending on a user turn#81adolfo-tamayo wants to merge 1 commit into
adolfo-tamayo wants to merge 1 commit into
Conversation
|
@adolfo-tamayo is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
Collaborator
|
Thanks this looks great. We're finishing some setup on our side to be able to accept contributions. Will get this merged in the next day or two |
0766f20 to
6cb419d
Compare
The trailing-assistant guard was gated on `recent.length > 0`, so it only fired when the kept recent window trailed with an assistant message. When `recent` is empty — a single oversized turn, or `keep` decaying to 0 — the assembled prompt ends on the summary's assistant block. Providers without assistant-prefill support (e.g. Anthropic) reject a prompt that doesn't end on a user turn, so the turn fails immediately after compaction. Move the guard onto the fully-assembled `compacted` array: append the synthetic "Continue." user message whenever the final message is an assistant turn, regardless of how it got there. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Adolfo Tamayo <atamayobr@gmail.com>
6cb419d to
db09f70
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #80.
Problem
After compaction, the next model call can fail terminally on Anthropic models with "This model does not support assistant message prefill. The conversation must end with a user message."
The existing trailing-assistant guard only fires when the kept recent window trails with an assistant message (
recent.length > 0 && recent.at(-1)?.role === "assistant"). It never covers the case whererecentis empty — a single oversized tool-result turn, orkeepdecaying to 0 — so the summary's own assistant block becomes the final message, the guard is skipped, and Anthropic rejects the prompt. The turn cannot recover, since each retry re-compacts to the same assistant-terminal shape.Fix
Move the guard off
recentand onto the fully-assembledcompactedarray: append the synthetic"Continue."user message whenever the final message is an assistant turn, however it got there.Tests
recentWindowSize: 0forces an empty recent window, and the compacted result must still end on a user turn.folds oversized recent tool results into the summary...test, which had asserted the buggy assistant-terminal output; it now expects the trailing"Continue."user turn.pnpm run test:unit -- compaction→ all green (26 passing).