Skip to content

[FEATURE]: Re-announce tools after context compaction #20290

@AndresCdo

Description

@AndresCdo

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

After context compaction, the model loses awareness of available tools and capabilities because the compacted message history no longer contains the original tool announcements.

Problem: When SessionCompaction.process() runs, it replaces the full message history with a summary. The model no longer sees the tool definitions that were present in earlier turns. This can cause the model to:

  • Stop using tools it previously had access to
  • Become confused about what capabilities are available
  • Ask the user to re-list available tools

Proposed Solution: After compaction completes, inject a synthetic user message that reminds the model it still has access to all previously available tools and should continue with its current task.

// After compaction.process() returns "continue":
const userMsg: MessageV2.User = {
  id: MessageID.ascending(),
  sessionID,
  role: "user",
  time: { created: Date.now() },
  agent: lastUser.agent,
  model: lastUser.model,
}
yield* sessions.updateMessage(userMsg)
yield* sessions.updatePart({
  id: PartID.ascending(),
  messageID: userMsg.id,
  sessionID,
  type: "text",
  text: "<system-reminder>Context was compacted. You still have access to all previously available tools and capabilities. Continue with your current task.</system-reminder>",
  synthetic: true,
})

Impact: Prevents model confusion after compaction, especially in long-running agentic sessions where compaction happens multiple times.

Risk: Minimal — single synthetic message, marked as synthetic: true so it does not appear in user-facing history.

Related

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions