feat(plan): compact context and start a fresh session when a plan is approved#705
Merged
Conversation
…approved Approving a plan in Plan Mode now summarizes the (usually exploration-heavy) planning conversation, starts a fresh session seeded with that summary, and points the agent back at the saved plan file to execute - so execution begins with an optimized, much smaller context window. - Thread the saved plan file path from the RequestPlanApproval tool result through PlanApprovalRequestedEvent and the plan-approval UI state so the post-approval continuation prompt can reference it. - Add compactThenExecutePlanCmd on the chat handler: force-optimize the conversation under a timeout, reseed a new session, add a plan-path-aware continue message, then resume. Fails open when compaction errors or times out. - Extract shared compaction helpers (optimize-with-timeout, reseed) reused by the /compact shortcut. - Construct the ConversationOptimizer unconditionally so compaction on plan approval runs regardless of compact.enabled; that flag now only gates the automatic mid-conversation compaction and the headless session rollover. - Document the behaviour in plan-mode.md and fix the stale compact.enabled default (true, not false) in configuration-reference.md. Closes #677
edenreich
commented
Jul 1, 2026
edenreich
commented
Jul 1, 2026
edenreich
commented
Jul 1, 2026
Co-authored-by: Eden Reich <eden.reich@gmail.com>
edenreich
added a commit
that referenced
this pull request
Jul 2, 2026
…714) ## Summary Accepting a plan dropped the agent into standard mode, forcing per-action approval during execution — the friction reported in #710. The default **Accept** now switches to **auto-accept mode**, so an already-reviewed plan executes without re-approving every step. ## Behavior The plan-approval prompt now offers: | Option | Key | Result | | --- | --- | --- | | **Accept** (default) | `Enter` / `y` | auto-accept mode (no per-action approval) | | **Approve Each Step** | `s` | standard mode (approve every action) | | **Reject** | `n` | ends the session (unchanged) | The cautious per-step path is preserved as an explicit choice, so no capability is lost. The mode is set on the `StateManager` rather than the conversation, so it survives the post-approval context compaction + fresh session from #705. > Note: the secondary keybinding changed from `a` to `s`. ## Changes - `applyPlanDecision` (approval coordinator): `Accept` → `AutoAccept`; new `AcceptStandard` → `Standard`. - Renamed the enum `PlanApprovalAcceptAndAutoApprove` → `PlanApprovalAcceptStandard`. - UI: relabeled the third button to "Approve Each Step", updated the plan-approval hint text, and rekeyed `a` → `s`. - Updated the `RequestPlanApproval` tool result + prompt copy to describe the new options. - Updated the coordinator tests for the swapped semantics. ## Testing - `task test` — full suite passes - `task lint` — 0 issues (golangci-lint + markdownlint) Closes #710
inference-gateway-releaser Bot
added a commit
that referenced
this pull request
Jul 2, 2026
## [0.127.0](v0.126.0...v0.127.0) (2026-07-02) ### 🚀 Features * **plan:** compact context and start a fresh session when a plan is approved ([#705](#705)) ([28ddba7](28ddba7)) * **memory:** configurable git sync backend ([#707](#707)) ([6a68c3d](6a68c3d)), closes [#670](#670) [#670](#670) * **history:** each subagent gets its own history file ([#711](#711)) ([16c8fa1](16c8fa1)), closes [#699](#699) ### 🐛 Bug Fixes * **plan:** accepting a plan switches to auto-accept mode by default ([#714](#714)) ([7b0befc](7b0befc)), closes [#710](#710) * **tools:** guard concurrent gitignore and screenshot caches ([#713](#713)) ([0ff4276](0ff4276)), closes [#712](#712) * **tools:** guard Registry.tools with RWMutex against concurrent MCP registration ([#709](#709)) ([8a70871](8a70871)), closes [#708](#708) * **ui:** update dim color from [#565f89](https://github.com/inference-gateway/cli/issues/565f89) to [#7a7f9a](https://github.com/inference-gateway/cli/issues/7a7f9a) for improved contrast ([#706](#706)) ([b2ee67e](b2ee67e)) ### 🔧 Build System * **deps:** bump github.com/go-telegram/bot from 1.21.0 to 1.22.0 in the gomod group ([#703](#703)) ([3de5136](3de5136)) * **deps:** bump the github-actions group with 5 updates ([#704](#704)) ([80221f7](80221f7))
Contributor
|
🎉 This PR is included in version 0.127.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #677.
When a plan is approved in Plan Mode, the agent now compacts the (usually exploration-heavy) planning conversation into a summary, starts a fresh session, and re-reads the approved plan from disk to execute — so execution begins with an optimized, much smaller context window.
Planning is read-heavy (
Read/Grep/Treeall over the codebase), and none of that exploration is needed once the plan is accepted. This reuses the existing/compactmachinery at plan-approval time.Behaviour
compact.enabledauto_at(80%)true(default)falseCompaction on plan approval runs regardless of
compact.enabled— that flag only governs the automatic mid-conversation compaction and the headless session rollover. It also fails open: if summarization errors or times out, execution still proceeds on the un-compacted conversation.Changes
RequestPlanApprovaltool result flows throughPlanApprovalRequestedEvent→PlanApprovalUIState, so the post-approval continuation prompt can reference it (internal/agent/agent.go,internal/domain/{events,state,interfaces}.go,internal/services/state_manager.go,internal/services/approvalcoord/coordinator.go).HandlePlanApprovalResponseEventcaptures the path and, on accept, runs a newcompactThenExecutePlanCmd: async optimize under a 70s timeout → reseed a new session → add a plan-path-aware continue message → resume the agent (internal/handlers/chat_handler.go, newinternal/handlers/chat_compaction.go).optimizeWithTimeout/reseedConversationWithMessages/nonHiddenMessages; the/compactshortcut now reuses them (behaviour unchanged).internal/container/container.gobuilds theConversationOptimizerunconditionally so approval compaction works even withcompact.enabled: false(force=truebypasses the enabled check).docs/plan-mode.md; fixed the stalecompact.enableddefault (it istrue, notfalse) indocs/configuration-reference.md.Testing
task build, fullgo test ./...,golangci-lint(0 issues),markdownlint— all green.extractPlanPath(edge cases),checkToolResultsStatuspath extraction,planExecutionContinuePrompt, andcompactPlanningContext(reseed / no-reduce / absent optimizer / no model), plus plan-path forwarding in the coordinator test.Manual check to run before merge
Interactive TUI + live gateway (not runnable in CI): Shift+Tab into Plan Mode, ask for a multi-file change so the model reads several files, Accept the plan, and confirm the history collapses to a
--- Context Summary ---, the agent re-Reads the plan file, and/contextshows a smaller token count. Repeat with Accept & Auto-Approve, and withcompact.enabled: false.Docs follow-up
A matching
[DOCS]issue should be filed forinference-gateway/docs(Plan Mode / compaction pages) per the docs follow-up rule.