Skip to content

fix(session): preserve wait-for-user state after compaction#18941

Open
Haohao-end wants to merge 1 commit intoanomalyco:devfrom
Haohao-end:fix/18794-compact-wait-state
Open

fix(session): preserve wait-for-user state after compaction#18941
Haohao-end wants to merge 1 commit intoanomalyco:devfrom
Haohao-end:fix/18794-compact-wait-state

Conversation

@Haohao-end
Copy link

Issue for this PR

Closes #18794

Type of change

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

What does this PR do?

This fixes an unwanted continuation after /compact.

Before this change, SessionCompaction.process() would inject a synthetic "continue" user message whenever compaction returned continue and auto-compaction was enabled. That also happened when the previous assistant message had already naturally finished and should have been waiting for user input.

I changed that logic so the synthetic continuation is only injected when compaction is actually resuming work:

  • keep the existing replay path for interrupted overflow cases
  • keep continuation for assistant states that still need to resume
  • do not inject a synthetic continue message when the previous assistant had already naturally stopped or was effectively waiting for the user

This works because the decision is now based on the assistant state before compaction, instead of only looking at the compaction result itself.

How did you verify your code works?

I tested locally with:

  • cd packages/opencode && bun test test/session/compaction.test.ts --timeout 30000
  • bun turbo typecheck

I also added regression tests for these cases:

  • no replay + assistant already stopped naturally -> no synthetic continue is injected
  • overflow + replay available -> the interrupted user message is replayed
  • overflow + replay unavailable -> the existing synthetic continue behavior is preserved

Screenshots / recordings

Not applicable.

Checklist

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

@github-actions
Copy link
Contributor

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

Based on my search, I found one potentially related PR:

This PR is related because it also addresses session compaction behavior, specifically around how compaction recovery is handled. Since PR #18941 modifies the logic for when synthetic continuation messages are injected during compaction, and PR #18873 deals with preventing replaying compaction recovery as user prompts, there could be overlapping concerns around compaction state management.

However, they appear to address different aspects of the compaction flow (continuation injection vs. replay handling), so they're likely complementary rather than duplicates.

@Haohao-end
Copy link
Author

This PR is related to #18873, but it fixes a different part of the compaction flow.

So these two PRs are complementary, not duplicates.

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.

/compact causes the agent to continue unexpectedly

1 participant