Skip to content

fix(agent): stop compaction summaries hijacking the current task (salvages #44345 + #41650)#44454

Merged
teknium1 merged 4 commits into
mainfrom
fix/compression-stale-task-hijack
Jun 11, 2026
Merged

fix(agent): stop compaction summaries hijacking the current task (salvages #44345 + #41650)#44454
teknium1 merged 4 commits into
mainfrom
fix/compression-stale-task-hijack

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Compaction summaries can no longer hijack the current task: the "consistent → use as background" carveout in SUMMARY_PREFIX is removed, all summary sections are framed as historical (DO NOT EXECUTE), and the retired prefix is frozen so pre-upgrade sessions keep summary detection.

Root cause: SUMMARY_PREFIX licensed the model to treat the stale summary as active context whenever the latest user message was "consistent" with the old Active Task — so topic overlap resumed dead work (#41607), vague follow-ups got scope-expanded from old "Remaining Work" sections (#38364), and idle-resumed sessions re-executed stale Active Tasks (#42812).

Closes #41607. Closes #38364. Closes #42812.

Changes

  • agent/context_compressor.py: heading constants (HISTORICAL_*) replace actionable section names across all 3 template sites (deterministic fallback, LLM template, iterative-update prompt) — from fix(agent): frame compaction handoff sections as historical context #44345 by @konsisumer
  • agent/context_compressor.py: SUMMARY_PREFIX carveout removed; topic overlap explicitly does NOT mean resume — from fix(agent): strengthen compression preamble vs stale tasks (#41607) #41650 by @kyssta-exe (merged with the heading constants)
  • agent/context_compressor.py: carveout-era prefix frozen into _HISTORICAL_SUMMARY_PREFIXES (neither contributor PR did this; without it, summaries persisted by current builds lose detection/renormalization after upgrade)
  • Tests: updated heading/prefix assertions + new contract tests (test_no_background_consistency_carveout, test_replaced_prefixes_are_frozen_for_renormalization — exercises detection + strip for every frozen prefix)

Validation

Before After
Topic-overlap follow-up after compaction resumes stale Active Task latest message wins, stale items discarded
Summary persisted by current build, read post-upgrade loses detection detected + renormalized via frozen prefix
pytest tests/agent/ -k "compress or summary or compaction" 197 passed

Attribution

Salvages #44345 (@konsisumer, base) and #41650 (@kyssta-exe, carveout removal) — both cherry-picked with authorship preserved; rebase-merge to keep per-commit credit. Supersedes #41634 and #38368.

Infographic

compaction-stale-task-hijack-fix

konsisumer and others added 3 commits June 11, 2026 12:41
The prompt consolidation above retires the carveout-era prefix. Without a
frozen copy in _HISTORICAL_SUMMARY_PREFIXES, summaries persisted by
pre-upgrade builds would lose detection (_is_context_summary_content) and
renormalization (_strip_summary_prefix) — the exact regression class the
tuple exists to prevent. Adds contract tests covering every frozen prefix.

Refs #41607 #38364 #42812
@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: fix/compression-stale-task-hijack vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 10764 on HEAD, 10764 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5637 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@liuhao1024

Copy link
Copy Markdown
Contributor

Verification: Compaction Summary Prefix Hardening

This is a well-structured fix. Verified:

  1. Frozen prefix tuple — the carveout-era prefix ("you may use the summary as background") is correctly added to _HISTORICAL_SUMMARY_PREFIXES for renormalization of persisted summaries from older builds.

  2. Heading constants — extracting HISTORICAL_TASK_HEADING etc. as module-level constants and referencing them in both the prefix and template sections prevents drift between the prefix's detection text and the actual headings.

  3. Topic overlap neutralization — the old "consistent → use as background" carveout (which licensed stale-task resumption) is explicitly removed and replaced with "topic overlap does NOT mean resume". The regression tests in test_summary_prefix_semantics.py::test_no_background_consistency_carveout pin this.

  4. Test coveragetest_resume_stale_active_task.py updates all heading references and adds the "carveout must stay gone" assertion. The new test_handoff_sections_are_framed_as_historical test ensures the live prefix uses historical-sounding names, not active-sounding ones.

Clean fix, no issues found.

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent loop, run_agent.py, prompt builder P1 High — major feature broken, no workaround labels Jun 11, 2026
…erences

Legibility pass on the consolidated prefix: collapse the topic-overlap rule
from three overlapping sentences into one WINS sentence + one discard/no-wrap-up
sentence (same constraints, less dilution), fix the module docstring to
describe the headings that actually shipped, and correct the #10896 comment's
heading name (Historical Pending User Asks).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

5 participants