[PR #1755] [CLOSED] Feat: Introduce Mid-Stream /compact + Loop Continuation #10046

Closed
opened 2026-02-16 18:14:36 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opencode/pull/1755
Author: @spoons-and-mirrors
Created: 8/9/2025
Status: Closed

Base: devHead: feat/mid-stream-compact


📝 Commits (1)

  • a46911d feat: add mid-stream /compact command and keeps the agent loop going

📊 Changes

1 file changed (+301 additions, -4 deletions)

View changed files

📝 packages/opencode/src/session/index.ts (+301 -4)

📄 Description

Summary

Add mid-stream context compaction: when the model is generating and a tool call is about to run but accumulated tokens approach the context limit ( >90% ), we interrupt, summarize (/compact), then execute the deferred tool call(s) and seamlessly continue the agent loop.

This does not count as a new message from the user to "message credits" subscriptions like copilot.

Key Points

  • Detects nearing context limit during streaming (before a tool executes).
  • Stores pending tool call(s) and aborts the stream with a controlled MidStreamCompactionError.
  • Runs summarize (same as /compact) without locking conflicts.
  • Executes deferred tool call results.
  • Schedules continuation asynchronously to avoid deadlock while lock is still held (prevents stuck "working...").
  • Works alongside existing pre-chat auto summarize.

Result

Long running reasoning/research sessions are now much less likely to exceed context limit; the agent keeps going automatically after compaction.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opencode/pull/1755 **Author:** [@spoons-and-mirrors](https://github.com/spoons-and-mirrors) **Created:** 8/9/2025 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `feat/mid-stream-compact` --- ### 📝 Commits (1) - [`a46911d`](https://github.com/anomalyco/opencode/commit/a46911df6587ddc94701507e7b2246453b1caa1c) feat: add mid-stream /compact command and keeps the agent loop going ### 📊 Changes **1 file changed** (+301 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `packages/opencode/src/session/index.ts` (+301 -4) </details> ### 📄 Description ## Summary Add mid-stream context compaction: when the model is generating and a tool call is about to run but accumulated tokens approach the context limit ( >90% ), we interrupt, summarize (/compact), then execute the deferred tool call(s) and seamlessly continue the agent loop. This does `not` count as a new message from the user to "message credits" subscriptions like copilot. ## Key Points - Detects nearing context limit during streaming (before a tool executes). - Stores pending tool call(s) and aborts the stream with a controlled `MidStreamCompactionError`. - Runs summarize (same as /compact) without locking conflicts. - Executes deferred tool call results. - Schedules continuation asynchronously to avoid deadlock while lock is still held (prevents stuck "working..."). - Works alongside existing pre-chat auto summarize. ## Result Long running reasoning/research sessions are now much less likely to exceed context limit; the agent keeps going automatically after compaction. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 18:14:36 -05:00
yindo closed this issue 2026-02-16 18:14:36 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10046