Skip to content

Conversation

@ryanwyler
Copy link
Contributor

@ryanwyler ryanwyler commented Dec 30, 2025

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.

…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
@ryanwyler ryanwyler force-pushed the fix/fork-parent-id-mapping branch from a0121b1 to 88060ae Compare December 31, 2025 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant