Skip to content

Session.fork does not remap CompactionPart.tail_start_id, breaking filterCompacted and inflating forked context #24700

Closed

Description

@dixoxib

Description

Session.fork copies all messages and remaps messageID and parentID via an idMap, but does not remap tail_start_id inside CompactionPart parts.

Root cause
src/session/session.ts:596–602 — the part spread includes the raw (old) tail_start_id:

for (const part of msg.parts) {
  yield* updatePart({
    ...part,                          // spread includes un-remapped tail_start_id
    id: PartID.ascending(),
    messageID: cloned.id,
    sessionID: session.id,
  })
}

filterCompacted (src/session/message-v2.ts:1072) relies on tail_start_id:
retain = part.tail_start_id // ← old message ID, never remapped

Forked session has new message IDs → msg.info.id === retain never matches → break never hit → all pre‑summary messages unfiltered.

Impact
Forked session context inflates massively (~300k → ~800k tokens observed per API-Usage response).

Fix
Remap tail_start_id in the fork loop via idMap, analogous to parentID (lines 588–593).

Plugins

no

OpenCode version

fresh clone

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 28, 2026
  2. spark4862 commented on Apr 29, 2026

    @spark4862
    Contributor

    Thanks for filing this and for letting me take the PR. I’ve submitted #24898 with the tail_start_id remap in Session.fork plus a regression test (messages-pagination.test.ts).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions