Skip to content

[Bug] Web UI "Fork" on latest assistant reply truncates turn via branch(entryId) instead of cloning full session like CLI /fork #365

Open

Description

@lutfi-zain

Describe the bug

In OMP Web, clicking the Fork button on the latest assistant message truncates the conversation, discarding that assistant reply (and any tools/actions in that turn) and rewinding the session back before the user prompt that produced it (putting the prompt back into the composer as an edit-and-resend draft).

In contrast, running /fork in the OMP CLI TUI creates an in-place clone of the entire session up to the current leaf (sessionManager.fork()), keeping all messages intact so the user can continue in a new branch without losing any history.


Visual Comparison: CLI /fork vs Web UI "Fork"

OMP Session Forking Topology & Discrepancy

graph TD
    subgraph Original ["1. Original Session 01a19af2-8b01..."]
        U0["[0] User: ECHO 5x FROM 0"] --> A1["[1] Assistant: 0 1 2 3 4"]
        A1 --> U2["[2] User e6b56c2a: NEXT"]
        U2 --> A3["[3] Assistant 14efbada: 5 6 7 8 9 - CURRENT LEAF"]
    end

    subgraph CLIFork ["2. OMP CLI /fork 01a19af4-3804... - Full Session Clone"]
        CU0["[0] User"] --> CA1["[1] Assistant: 0 1 2 3 4"]
        CA1 --> CU2["[2] User e6b56c2a: NEXT"]
        CU2 --> CA3["[3] Assistant 14efbada: 5 6 7 8 9 - PRESERVED 100%"]
        CA3 -->|Continues unbroken| CU4["[4] User: NEXT"]
        CU4 --> CA5["[5] Assistant: 10 11 12 13 14"]
    end

    subgraph WebFork ["3. OMP Web UI Fork on 3 01a19af4-d3a4... - Branch Rewind"]
        WU0["[0] User"] --> WA1["[1] Assistant: 0 1 2 3 4"]
        WA1 -.->|branch e6b56c2a cuts turn 2| CUT["❌ Turn 2 Discarded! 14efbada gone"]
        WA1 -->|Resent prompt NEXT from composer| WU2_NEW["[2] User c79fb6fb: NEXT"]
        WU2_NEW --> WA3_NEW["[3] Assistant b5f9f41d: 5 6 7 8 9"]
    end

    A3 -->|session.fork without entryId| CLIFork
    A3 -->|Web UI sends branch e6b56c2a| WebFork

    classDef orig fill:#1e293b,stroke:#3b82f6,stroke-width:2px,color:#f8fafc;
    classDef cli fill:#064e3b,stroke:#10b981,stroke-width:2px,color:#f8fafc;
    classDef web fill:#7f1d1d,stroke:#ef4444,stroke-width:2px,color:#f8fafc;
    classDef cut fill:#450a0a,stroke:#dc2626,stroke-width:2px,stroke-dasharray: 5 5,color:#fca5a5;

    class U0,A1,U2,A3 orig;
    class CU0,CA1,CU2,CA3,CU4,CA5 cli;
    class WU0,WA1,WU2_NEW,WA3_NEW web;
    class CUT cut;
Loading

Root Cause Analysis

In OMP core, RPC defines two distinct operations:

  1. fork(entryId?): When called without entryId, it invokes sessionManager.fork(), duplicating the full session file to a new session ID and retaining the full conversation tree.
  2. branch(entryId): Rewinds the session tree to before a specific user entry, discarding all entries after it, and returning the prompt text for edit-and-resend.

In ompweb/lib/rpc-manager.ts (lines 1984-1999):

case "fork": {
  // omp's `branch` is pi-web's fork: it creates a branched session file
  // and switches this live process onto it (entryId must be a user
  // message entry, matching the web UI's fork buttons).
  const result = await this.proc.sendCommand<{ text: string; cancelled: boolean }>({
    type: "branch",
    entryId: command.entryId as string,
  });
  ...

And in ompweb/lib/chat-fork.ts (lines 17-18 & 51-54):

// The newest reply has no next prompt, so it falls back to its own turn's
// prompt with the edit-and-resend prefill (#103).
for (let index = 0; index < roles.length; index++) {
  ...
  if (targets[index] || !ownUserEntryId || ownIsFirstPrompt) continue;
  if (roles[index] === "user" || roles[index] === "assistant") {
    targets[index] = { entryId: ownUserEntryId, editPrompt: true };
  }
}

Because OMP core's branch strictly requires a user entry ID, forking an intermediate assistant reply can target the subsequent user entry (preserving that assistant reply). But for the latest assistant reply, there is no subsequent user entry, so it falls back to ownUserEntryId (the prompt that started the turn). Branching at that prompt truncates everything from that prompt onwards!


Reproducible Evidence (Side-by-Side Comparison)

We tested this in a controlled session with the prompt "YOUR ONLY NEED TO ECHO NUMBER 5x FROM 0 UNTIL I INSTRUCTING OTHERWISE":

1. Original Session (01a19af2-8b01-75f2-9d5e-2b8db233aa49)

  • [0] user: YOUR ONLY NEED TO ECHO NUMBER 5x FROM 0 UNTIL I INSTRUCTING OTHERWISE.
  • [1] assistant: 0 1 2 3 4
  • [2] user (id=e6b56c2a): NEXT
  • [3] assistant (id=14efbada): 5 6 7 8 9

2. Forked via CLI /fork (01a19af4-3804-728c-8b55-9b53eec2386c)

Running /fork in OMP CLI clones the complete session:

  • [0] user: YOUR ONLY NEED TO ECHO NUMBER 5x...
  • [1] assistant: 0 1 2 3 4
  • [2] user (id=e6b56c2a): NEXT
  • [3] assistant (id=14efbada): 5 6 7 8 9 (Preserved 100%!)
  • [4] user: NEXT
  • [5] assistant: 10 11 12 13 14

3. Forked via Web UI "Fork" on message [3] (01a19af4-d3a4-7224-9fc6-d98ee437ec9e)

Clicking "Fork" on message [3] in OMP Web:

  • [0] user: YOUR ONLY NEED TO ECHO NUMBER 5x...
  • [1] assistant: 0 1 2 3 4
  • Message [2] and [3] were completely deleted from history.
  • The prompt "NEXT" was dumped into the composer as an edit draft.
  • Sending "NEXT" created a fresh [2] user and generated [3] assistant: 5 6 7 8 9 all over again.

Raw Session Exports (HTML)

All three full session exports generated via omp --export are available for download/inspection in this public Gist:
📦 Gist: OMP Session HTML Exports (Original vs CLI /fork vs Web UI Fork)

  • original-session.html
  • forked-cli-session.html
  • forked-web-session.html

Expected Behavior

  1. Session-Level Fork: Support full-session cloning like CLI /fork (e.g. a "Fork Session" button in session header or sidebar that issues RPC fork without entryId).
  2. Clarify or Fix Message-Level Fork:
    • If clicking "Fork" on a message is meant as a time-travel branch/edit-prompt, the action label or tooltip should reflect that (e.g. "Branch & Edit Prompt" instead of "Fork").
    • Or, for the latest assistant reply, allow forking without discarding the reply (either via RPC fork at current leaf or preserving the message).

Environment

  • OS: Linux (Ubuntu 24.04 LTS x86_64)
  • Node.js: v24.19.0
  • omp version: 18.12.6
  • omp-web version: 0.6.0

Activity

  1. lutfi-zain commented on Nov 2, 2026

    @lutfi-zain
    ContributorAuthor

    Submitted PR #373 with the fix:

    • Clicking fork on the latest message / active leaf now sends parameterless { type: "fork" }, cloning the session in place with complete history intact (matching CLI /fork).
    • Historical forking retains the { type: "branch", entryId } time-travel rewind.
    • Tooltips now clearly distinguish between "Fork session (clone full conversation)" on the leaf and "Branch from here (rewind to prompt)" on older turns.
    • Also adds concurrency guards against streaming in rpc-manager.ts and unlocks forking for single-turn sessions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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