Skip to content

Message IDs wrap around, silently dropping new user input in sessions with history #42639

Closed

Description

@uponepro

Description

In a session with existing message history, a new user message can be silently
ignored — the agent loop exits without processing it.

Root cause: Identifier.ascending() IDs are NOT monotonic. packages/opencode/src/id/id.ts
encodes Date.now()*0x1000 + counter into a 6-byte (48-bit) field:

let now = BigInt(currentTimestamp) * BigInt(0x1000) + BigInt(counter)
const timeBytes = Buffer.alloc(6) // only 48 bits

Date.now()*0x1000 (~7.2e15 in 2026) exceeds 2^48 (~2.8e14) by ~25x, so the high
bits are truncated. A freshly generated "msg_000..." sorts before older IDs.

MessageV2.latest() picks the latest message by info.id > user.id (string
compare), assuming IDs are monotonic (its comment says so). After wraparound it
returns a stale message; the run loop then sees lastUser.id < lastAssistant.id
and exits, dropping the new input.

Suggested fix: compare by info.time.created (a real ms timestamp) with id as
tiebreaker, matching the existing (desc time_created, desc id) pagination
ordering.

Plugins

N/A (default config)

OpenCode version

v1.18.15 (also confirmed on dev @ 5d0f866)

Steps to reproduce

  1. Start a session and exchange a few messages (build up message history).
  2. Wait until the 48-bit timestamp field wraps — current date (2026) is already
    in the wrap window, since Date.now()*0x1000 overflows 2^48.
  3. Send a new user message in the SAME session.
  4. Observe: the agent does not respond. The run loop logs "exiting loop" and
    the new input is never sent to the model.

Reproduction is time-dependent (tied to the wraparound point of the 48-bit
timestamp), so it is intermittent rather than on every message.

A reliable way to reproduce without waiting: unit-test latest() with messages
whose time.created increases but whose ids wrap (a fresh "msg_000..." after
older "msg_0a8a...").

Screenshot and/or share link

No response

Operating System

Linux

Terminal

No response

Activity

  1. github-actions commented on Aug 14, 2026

    @github-actions
    Contributor

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

  2. sungch888 commented on Aug 15, 2026

    @sungch888

    Additional confirmed reproduction + evidence from a real install (Windows, opencode desktop bundle + CLI):

    1. Wrap point measured precisely: the 6-byte field rolls over at 2026-08-14 11:23:02 UTC on this machine. A message at 08-13 15:28 UTC gets ID prefix FFBBCCE2D000 (msg_ffbbcce2d001uUMvHYqYBDb6Cp) while messages a few hours later start with 000E.../0039.... So latest() picks the stale ffb... assistant as the "latest".

    2. Concrete sorted-vs-time mismatch in the affected session:

      • chronologically last message: msg_003a81e41001ylDQOsSbNrB8ZX (user)
      • lexicographically max message: msg_ffbbcce2d001uUMvHYqYBDb6Cp (assistant, finish=stop)
        → loop condition lastUser.id < lastAssistant.id is true and the loop breaks with only loop step=0 -> exiting loop in the log; no process/stream ever runs.
    3. Affects any session spanning the wrap point, regardless of model/provider. In our case the stuck session had messages with 4 different models (deepseek-v4-flash-free, qwen, minimax, local) - all silently dropped. Confirms it is not provider/model related.

    4. CLI reproduces it too (not desktop-UI only): opencode run --session <id> ... --print-logs on the same DB logs loop step=0 then exiting loop immediately.

    5. Workaround for users until merged: sessions created entirely after the wrap time (all IDs monotonic) keep working; for stuck sessions, --fork into a new session works.

    FWIW the bundled desktop code path is latest() selecting by info.id > user.id (string compare) in packages/opencode/src/session/message-v2.ts, exactly as described. The proposed fix (order by time.created with id tiebreaker) is correct; id.ts should also keep more than 6 bytes (or use a proper monotonic ULID) so IDs stay sortable across wraps.

  3. ChananM commented on Aug 16, 2026

    @ChananM
  4. rekram1-node commented on Aug 17, 2026

    @rekram1-node
    Collaborator

    If u update to latest this was fixed

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