Skip to content

[Bug] oclite: Session resets after every message — agent loses conversation context #77

@randomm

Description

@randomm

Bug

After every message, currentSessionID is set to null in the finally blocks of both handleMessage() and handleCustomCommand(). This causes each user message to create a brand new session with zero conversation history.

Reproduction

  1. Send a message: "Is issue 184 still open?"
  2. Agent responds correctly about Can't continue session after closing opencode while working anomalyco/opencode#184
  3. Send follow-up: "Is there a PR linked to it?"
  4. Agent responds: "I don't have context for what 'it' refers to"

Root Cause

File: packages/opencode/src/cli/lite/index.ts

Line ~540 (handleMessage finally block):

finally {
  isOperationInProgress = false
  currentSessionID = null  // ← BUG
}

Line ~455 (handleCustomCommand finally block):

finally {
  isOperationInProgress = false
  currentSessionID = null  // ← SAME BUG
}

Evidence

  • Token count drops from 51.7k to 25.8k between messages (no history loaded)
  • Session.createNext() is called every message instead of reusing the session
  • MessageV2.filterCompacted(MessageV2.stream(sessionID)) returns empty history for new sessions

Fix

Delete both currentSessionID = null lines. The session ID should persist across the REPL loop. It's already properly reset when the user runs /new (line ~275).

Acceptance Criteria

  • Conversation context preserved across multiple messages
  • /new command still creates a fresh session
  • bun run typecheck passes
  • bun test passes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions