-
Notifications
You must be signed in to change notification settings - Fork 5.2k
fix: resolve broken forked sessions with compactions due to missing parent-child message references #6445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
…arent-child message references When forking a session, message IDs are regenerated but parentID references in assistant messages were not updated to point to the new IDs. This broke features that rely on parent-child relationships, such as compaction breakpoints. ## Problem Forking a compacted session would fail with: ``` prompt is too long: 203573 tokens > 200000 maximum ``` The forked session didn't honor the compaction breakpoint because the parent-child message relationships were broken. ## Fix Added an ID mapping that tracks old ID -> new ID, then updates parentID references when cloning assistant messages. ## Changes - packages/opencode/src/session/index.ts - Add ID mapping in fork function to preserve parent-child relationships
a0121b1 to
88060ae
Compare
ryanwyler
added a commit
to gignit/opencode
that referenced
this pull request
Jan 2, 2026
…older messages Adds a new "collapse" compaction mode that preserves recent context while summarizing older messages, with intelligent merging of historical summaries across multiple compaction cycles. The problem: Standard compaction summarizes the entire conversation, reducing visible context to just 1 message - a brief summary. The agent loses access to working code, user preferences, design decisions - essentially starting blind after each compaction. When multiple compactions occur, each new summary only knows about messages since the last compaction, causing progressive amnesia. The solution: Collapse compaction keeps the agent intelligent: 1. Selective compression - Only summarizes OLD messages while keeping recent work fully visible: - Extracts oldest 65% of tokens and creates a rich summary at a breakpoint - Uses newest 15% as reference context for the summarizing LLM - Everything after the breakpoint (35%) remains as full messages - Result: 168 visible messages vs 1 with standard compaction 2. Rich context restoration document - The summary preserves: - Current task state, next steps, blockers - Working code blocks verbatim - User directives and preferences - Design decisions and lessons learned - Technical facts (paths, function names, config values) 3. Rolling knowledge accumulation - When creating a new summary, includes up to N previous summaries in the prompt with instructions to MERGE all historical context. Each compaction consolidates everything that came before - nothing is ever lost. A session can run indefinitely with unlimited compactions and the agent retains access to critical knowledge from day one. 4. Chain protection - Ensures compaction breakpoints don't split message chains (user message + assistant responses linked by parentID). Configuration: compaction.method: "collapse" (default: "standard") compaction.trigger: 0.85 compaction.extractRatio: 0.65 compaction.recentRatio: 0.15 compaction.summaryMaxTokens: 10000 compaction.previousSummaries: 3 Changes: - src/session/compaction.ts - Main collapse logic, processCollapse(), helpers - src/session/index.ts - Fork fix: preserve parentID references when forking - src/id/id.ts - Add insert() for positioning messages between existing IDs - src/session/message-v2.ts - filterCompacted() breakpoint detection - src/session/prompt.ts - Integrate collapse breakpoint into prompt building - src/config/config.ts - Compaction config schema - src/cli/cmd/tui/routes/session/index.tsx - TUI toggle - src/cli/cmd/tui/routes/session/sidebar.tsx - Sidebar display - src/server/server.ts - Unified compaction flow - test/id-chain-fix.test.ts - Tests for ID insertion - SDK types regenerated Includes fork fix from anomalyco#6445: preserve parentID references when forking sessions to prevent broken compaction detection.
Contributor
Author
Collaborator
|
/review |
Contributor
|
lgtm |
shuv1337
added a commit
to Latitudes-Dev/shuvcode
that referenced
this pull request
Jan 9, 2026
Cherry-picked from upstream a5edf3a. Fixes missing parent-child message references when cloning sessions.
aryasaatvik
pushed a commit
to aryasaatvik/opencode
that referenced
this pull request
Jan 10, 2026
…arent-child message references (anomalyco#6445)
fwang
pushed a commit
to lifefloating/opencode
that referenced
this pull request
Jan 10, 2026
…arent-child message references (anomalyco#6445)
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
Forking a compacted session fails with:
The bug was introduced in commit
9a0735de7on October 6, 2025 with the commit message "Add session forking functionality and simplify remove logic".This was a bug from day one of the fork feature - it just wasn't noticed until compaction logic (which relies on parent-child relationships) was added later.
The Bug
When forking was originally implemented, each message gets a new
idviaIdentifier.ascending("message"), but the code never updated theparentIDfield. Assistant messages have aparentIDthat points to their corresponding user message. After forking, thoseparentIDvalues still reference the old message IDs from the source session, which don't exist in the forked session.Fix
Maintain an ID mapping (old -> new) when cloning messages, updating
parentIDreferences to point to the new IDs. This restores the parent-child relationships thatfilterCompacted()relies on to detect compaction breakpoints.