feat(context): HiAgent subgoal-aware context compaction for long-horizon tasks (#2022)#2061
Merged
feat(context): HiAgent subgoal-aware context compaction for long-horizon tasks (#2022)#2061
Conversation
9f39418 to
a32c04d
Compare
Add SubgoalId, SubgoalState, Subgoal, and SubgoalRegistry to compaction_strategy.rs. Implements all registry operations: - push_active with auto-completion defense (M3 fix) - complete_active, extend_active with incremental tagging (S6 fix) - tag_range for retroactive tagging (S4 fix) - subgoal_state lookup, active_subgoal query - rebuild_after_compaction for post-drain index repair (S1 fix) All unit tests pass. Gated behind context-compression feature flag.
…ases B-E) Phase B: SubgoalExtractionResult + CompressionState fields (subgoal_registry, pending_subgoal, subgoal_user_msg_hash). maybe_refresh_subgoal() two-phase fire-and-forget using last 6 agent_visible messages (M2 fix). LLM signal drives transitions via COMPLETED: prefix (S3 fix). Retroactive tagging of pre-extraction messages on first subgoal creation (S4 fix). Phase C: score_blocks_subgoal() with Active=1.0/Completed=0.3/Outdated=0.1 tiers plus recency tiebreaker. score_blocks_subgoal_mig() combines subgoal tier relevance with pairwise MIG redundancy. Phase D: PruningStrategy::Subgoal and SubgoalMig variants with serde and FromStr support. prune_tool_outputs_subgoal/subgoal_mig() using shared evict_sorted_blocks() helper. Dispatch in prune_tool_outputs(). maybe_compact() Soft tier dispatches to maybe_refresh_subgoal() when subgoal strategy active. Rebuild after apply_deferred_summaries() to repair shifted indices (S5 fix). Phase E: Extract active-subgoal messages before drain in compact_context() and re-insert after pinned messages (S2 fix). rebuild_after_compaction() call after drain+reinsert to maintain index consistency (S1 fix).
- debug_dump: add dump_subgoal_registry() writing NNN-subgoal-registry.txt alongside pruning score dumps for subgoal strategy runs - /status command: show Pruning strategy, subgoal count, and active subgoal description when pruning_strategy is Subgoal or SubgoalMig - --init wizard: add subgoal and subgoal_mig to pruning strategy selection menu (items 4 and 5 in the Select list) - runner.rs: M4 fix — hard anyhow::bail! if SideQuest eviction and Subgoal pruning are both enabled (mutually exclusive subsystems)
S1: Preserve tier distinction in rebuild_after_compaction() - use span-aware matching to ensure Active vs Completed subgoal messages retain their tier assignment after compaction, preventing incorrect eviction by subsequent pruning operations. S2: Add unit test coverage for parse_subgoal_extraction_response() - implement 4 comprehensive tests covering well-formed input, malformed input with missing CURRENT prefix, and edge case of empty CURRENT line with fallback behavior. S3: Add missing debug dump call to prune_tool_outputs_subgoal_mig() - ensure consistent debug observability when dumping SubgoalRegistry state, matching the call present in the sibling prune_tool_outputs_subgoal() function. Also fix empty CURRENT detection in parser by avoiding trim_start() before newline split, ensuring malformed responses correctly trigger fallback to treating entire response as current subgoal.
…feature disabled The 'applied' variable is only used when context-compression feature is enabled. Use conditional compilation to avoid unused variable warning in other bundles.
c8c9ead to
526d7fd
Compare
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
Implements HiAgent-inspired subgoal-aware context compaction for improved handling of long-horizon multi-step tasks. Instead of purely token/recency-based compaction, the agent now:
Key Changes
Architecture
New LLM Call
Compaction Strategy: SubgoalMig
Code Review Fixes Applied
Testing