Skip to content

Bug: SessionSummary runs on every processor finish-step and repeatedly loads full session history #21761

Closed as not planned

Description

@sjawhar

Bug Description

Tool-using sessions can freeze the TUI and drive multi-GB RSS growth because SessionSummary.summarize(...) is invoked on every assistant finish-step, and summarize() loads the full session history (Session.messages({ sessionID })) every time.

This creates a hot loop during multi-step agent execution:

  1. prompt loop re-enters for normal tool-assisted execution
  2. processor finish-step fires for each assistant model turn
  3. processor calls SessionSummary.summarize(...)
  4. summarize loads the full session history and hydrates all parts
  5. memory spikes and repeats on every turn

Root Cause

Primary trigger

packages/opencode/src/session/processor.ts

Inside the finish-step event handler, the processor unconditionally calls:

SessionSummary.summarize({
  sessionID: ctx.sessionID,
  messageID: ctx.assistantMessage.parentID,
})

That means summary runs once per assistant model turn, not once per overall user prompt.

Expensive operation

packages/opencode/src/session/summary.ts

summarize() calls:

const all = yield* sessions.messages({ sessionID: input.sessionID })

With no limit, this hydrates the full message history every time.

Evidence

Live diagnostic repro with labeled binary:

  • prompt loop entry: 4
  • summary start: 4
  • summary loaded messages: 4
  • prompt loop summary trigger: 1
  • prune start: 0
  • session messages full: 10
  • message hydrate: 45

This proves:

  • prompt loop re-entry is happening during normal multi-step execution
  • repeated full-history loads are coming from summary, not prune
  • processor-side summary calls explain the count gap beyond the one prompt-loop trigger

User Impact

  • standalone TUI freezes / becomes unresponsive
  • process RSS grows into multi-GB territory
  • likely contributes to shared serve memory drift under long-running tool sessions

Proposed Fix

  1. Remove the processor-side SessionSummary.summarize(...) call from finish-step
  2. Keep summary responsibility at the prompt-loop level instead of per-step
  3. Add a cheap guard in summary.ts to skip work if the target user message already has summary.diffs

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    perfIndicates a performance issue or need for optimization
    on Apr 9, 2026
  2. github-actions commented on Apr 9, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  3. sjawhar commented on Apr 9, 2026

    @sjawhar
    Author

    Re: possible duplicates (#20302, #20285, #18136)

    These are closely related, but not clean duplicates of #21761:

    So #21761 is the concrete root-cause bug report for one specific repeated full-history load path we traced with live diagnostics.

    PR with fix: #21762

  4. removed
    perfIndicates a performance issue or need for optimization
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  5. github-actions commented on Jul 6, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions