Skip to content

fix: improve compaction continuation to prevent agent from stopping#16073

Open
guazi04 wants to merge 1 commit intoanomalyco:devfrom
guazi04:fix/agent-stops-after-compaction
Open

fix: improve compaction continuation to prevent agent from stopping#16073
guazi04 wants to merge 1 commit intoanomalyco:devfrom
guazi04:fix/agent-stops-after-compaction

Conversation

@guazi04
Copy link

@guazi04 guazi04 commented Mar 5, 2026

Issue for this PR

Closes #13217

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

After compaction, the agent frequently stops working instead of continuing. This affects all providers and has been confirmed by 8+ users.

Root cause: Two issues combine:

  1. The synthetic continuation message after compaction says "Continue if you have next steps, or stop and ask for clarification" — this gives the model explicit permission to stop. After seeing a compressed summary, models frequently choose to stop.

  2. The compaction summary prompt doesn't ask for remaining tasks or next actions. Without clear direction in the summary, the model has nothing to continue with.

Fix (single file, compaction.ts, +47/-2 lines):

  1. Replaced the continuation message with an assertive 3-line directive that tells the model to read the summary and take the next concrete step. It still allows asking questions when genuinely blocked on missing info.

  2. Enhanced the summary prompt with 4 new sections: current status, remaining tasks, next actions, and open questions — so the summary captures what to do next.

  3. Inject session todos into the compaction prompt unconditionally (even when a plugin provides a custom prompt), so the summary agent faithfully captures remaining work.

  4. Include incomplete todos in the continuation message with an explicit instruction to resume the in-progress item.

I identified this by studying how oh-my-opencode's plugins (compaction-context-injector, todo-continuation-enforcer) solve this same problem — they enrich the compaction context and aggressively prevent the model from stopping. This PR brings the core fix upstream without requiring plugins.

How did you verify your code works?

  • bun typecheck passes cleanly
  • Backward-compatible: when no todos exist, behavior is identical except for the improved continuation message
  • The overflow-specific media attachment prefix is preserved
  • The replay path (when a previous user message exists) is unchanged
  • The plugin hook (experimental.session.compacting) continues to work as before

Screenshots / recordings

N/A — backend logic change, no UI impact.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

After compaction, the synthetic continuation message gave the model
permission to stop ('or stop and ask for clarification'), causing the
agent to frequently stop working instead of resuming the task.

Changes:
- Replace ambiguous continuation message with assertive directive
  that instructs the model to continue from where it left off
- Enhance compaction summary prompt with sections for current status,
  remaining tasks, next actions, and open questions
- Inject session todo list into compaction prompt so the summary
  agent faithfully captures remaining work
- Include incomplete todos in continuation message to give the model
  explicit next steps after compaction

Closes anomalyco#13217
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 5, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

The following comment was made by an LLM, it may be inaccurate:

I found related PRs that might be duplicates or closely related:

Potential Duplicates:

  1. PR fix: auto-resume agent loop after context compaction #12970 - "fix: auto-resume agent loop after context compaction"

  2. PR fix: compaction bugs #13946 and #13980 #14245 - "fix: compaction bugs Bug: opencode run exits after compaction when compaction model's token usage exceeds overflow threshold #13946 and Bug: compaction.reserved config is ignored for models without explicit 'input' limit #13980"

  3. PR fix(opencode): skip overflow check on compaction summaries #15129 - "fix(opencode): skip overflow check on compaction summaries"

Why they might be related:

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 5, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

Stops after compaction

1 participant