fix(agent): pin reply language to the latest live user message - #58348
fix(agent): pin reply language to the latest live user message#58348lkz-de wants to merge 1 commit into
Conversation
Related to the context-compaction handoff family (merged #44454, #42895, #41650) but a distinct mechanism: those addressed stale task headings hijacking resumed sessions, whereas this fixes the summarizer preamble making the summary language behave like a latent reply-language instruction after resume. Not a duplicate — same file ( |
|
Amended this PR to close the remaining language-steering path more completely. This update:
Validation run:
|
|
Small note on the stable prompt wording: the final sentence in the reply-language guard ("If the latest user message is English ... reply in English") is intentionally explicit even though it is logically covered by the more general rule above it. Reason: in practice, English is the easiest case for a model to treat as an unstated default, so spelling it out reduces the chance that older summary language, quoted text, or a prior assistant turn is treated as stronger than the user's latest live message. The intent is not to privilege English as a policy exception; it is to make the default-case interpretation unambiguous in the prompt itself. |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for tracing the compaction handoff path and preserving historical-prefix renormalization.
Problems
agent/context_compressor.py:1720reverses the current same-language summary policy atagent/context_compressor.py:1996-1997. Maintainer commit13294c2dadded that policy specifically because English summaries muddied non-English conversations. This needs an explicit product-direction decision before replacing it with neutral English.- The new “must NEVER be treated as a reply-language instruction” text is sent only to the auxiliary summarizer (
agent/context_compressor.py:2115-2144); the subsequent chat context stores only its returned summary (:2205-2213). It cannot itself constrain a later reply.
Suggested changes
- Keep the current summary-language policy unless maintainers explicitly choose to reverse
13294c2d; evaluate the handoff/system-prompt guard as the narrower fix. - Add one transcript-assembly regression covering a foreign summary followed by a newer live user message.
Automated hermes-sweeper review.
| @@ -1694,8 +1720,10 @@ def _generate_summary( | |||
| "compact record of prior work. " | |||
There was a problem hiding this comment.
This reverses the current same-language summary policy introduced by maintainer commit 13294c2d, whose stated purpose was to avoid muddling non-English conversations with English context. Please retain that policy unless maintainers explicitly choose the product-direction reversal; the reply-language guard can be considered independently.
| @@ -1694,8 +1720,10 @@ def _generate_summary( | |||
| "compact record of prior work. " | |||
| "Produce only the structured summary; do not add a greeting, " | |||
| "preamble, or prefix. " | |||
There was a problem hiding this comment.
This instruction is sent only to the auxiliary summarizer, and _generate_summary() stores only its returned content in the later transcript. It cannot directly control the reply model on a later turn; the handoff/system-prompt guidance is the mechanism that reaches that model.
|
Thanks — agreed on the boundary. The stable prompt guard is the narrow load-bearing fix here: the latest live user message should control reply language even when older summaries, quoted text, or prior assistant turns are in a different language. I also agree that reversing the existing same-language summary policy needs an explicit product-direction decision rather than being smuggled in under this bugfix. I’ll refresh this by keeping the existing summary-language policy, dropping that policy reversal from this PR, and adding the transcript-assembly regression for a foreign-language summary followed by a newer live user message so the later reply-language guard is exercised on the assembled context rather than only in isolation. |
c54c7c0 to
1d11378
Compare
|
Refreshed the branch onto current The current head keeps the latest-live-user language authority in the compaction handoff and stable prompt, preserves retired summary-prefix stripping, and drops the broader summary-language policy change from the earlier version of this PR. Verification on the refreshed branch: scripts/run_tests.sh tests/agent/test_compress_focus.py tests/agent/test_system_prompt.py tests/agent/test_summary_prefix_semantics.py tests/agent/test_summary_prefix_tool_use.py -- --tb=short -qResult: |
a1ca33a to
8032018
Compare
8032018 to
253277a
Compare
|
Rebased this onto current Verification:
I also attempted the wider Scope note: the previous |
253277a to
223281c
Compare
|
Pushed a refreshed follow-up on current This keeps the PR's user-facing language guard intact and updates the micro-compaction regression after the CI slice caught the expected accounting edge from the longer summary preamble. The test still asserts cumulative savings go positive across repeated passes; the synthetic fixture now needs five passes instead of four because the added live-language sentence increases the one-time marker overhead. Local verification on the refreshed head: python -m pytest tests/agent/test_micro_compaction.py::TestMicroCompaction::test_cumulative_savings_accumulate_across_passes tests/agent/test_compress_focus.py tests/agent/test_summary_prefix_semantics.py -q --maxfail=1
# 10 passed in 1.03sI also spot-checked that the newly frozen historical prefix entry matches the previous |
Summary
This PR closes a stale-language steering path in resumed conversations.
A resumed conversation can contain a large historical compaction summary. The active reply language should follow the user's latest live message, not the language of that historical summary or older quoted context.
This refresh narrows the branch to that rule:
Why
The original handoff fix addressed stale task resumption, but the reply-language rule still needed to be explicit. Without that guard, a long historical summary can remain salient enough to steer a later answer into the wrong language even when the latest live user message is in English.
Fix
SUMMARY_PREFIXRESPONSE_LANGUAGE_GUIDANCEto the stable prompt_HISTORICAL_SUMMARY_PREFIXESTesting
Run after the refresh:
Result:
29 tests passed, 0 failedOverlap check
This remains in the original bug family: replies should follow the latest live user message, not stale compaction context. The refresh deliberately avoids changing the broader summary-language policy.
Risk
Low. The change is limited to compaction handoff wording, stable prompt guidance, and regression tests. It does not change session persistence, tool execution, or message routing behavior.