[PR #6445] fix: resolve broken forked sessions with compactions due to missing parent-child message references #11911

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

Original Pull Request: https://github.com/anomalyco/opencode/pull/6445

State: closed
Merged: Yes


Summary

Forking a compacted session fails with:

prompt is too long: 203573 tokens > 200000 maximum

The bug was introduced in commit 9a0735de7 on 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 id via Identifier.ascending("message"), but the code never updated the parentID field. Assistant messages have a parentID that points to their corresponding user message. After forking, those parentID values 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 parentID references to point to the new IDs. This restores the parent-child relationships that filterCompacted() relies on to detect compaction breakpoints.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6445 **State:** closed **Merged:** Yes --- ## Summary Forking a compacted session fails with: ``` prompt is too long: 203573 tokens > 200000 maximum ``` The bug was introduced in commit `9a0735de7` on 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 `id` via `Identifier.ascending("message")`, but the code never updated the `parentID` field. Assistant messages have a `parentID` that points to their corresponding user message. After forking, those `parentID` values 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 `parentID` references to point to the new IDs. This restores the parent-child relationships that `filterCompacted()` relies on to detect compaction breakpoints.
yindo added the pull-request label 2026-02-16 18:16:51 -05:00
yindo closed this issue 2026-02-16 18:16:51 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11911