Skip to content

V2: session.time_updated goes stale during active turns, breaking recency sort #36893

Closed

Description

@kitlangton

Summary

The session row's time_updated is only bumped by a small set of projected events, so a session that is actively streaming an assistant turn keeps a stale timestamp. Session lists sort by time_updated, so the most active session can appear old.

Evidence

Session ses_09f05df32ffewmX7otmzvMPbKb (next channel), 2026-07-14: session metadata time_updated remained at 14:43:36Z while durable events (steps, tools, text, executions) continued for more than an hour afterward. Event persistence itself was healthy and contiguous.

Where

packages/core/src/session/projector.ts sets time_updated only for:

  • session creation
  • input admitted
  • agent selected
  • model selected
  • title updated
  • revert set/cleared

Step, tool, text, reasoning, compaction, and execution lifecycle events do not touch it.

packages/core/src/session.ts:414 sorts session lists by SessionTable.time_updated, so the staleness is user-visible as wrong recency ordering (for example in session pickers and the web app list).

Suggested Direction

Bump time_updated (to event.created) when projecting execution and step lifecycle events — session.execution.started/succeeded/failed at minimum, since they bracket every turn cheaply. Updating on every projected session event would also be correct but touches the row far more often for streaming deltas.

A regression test: project an admitted input followed by step/tool/execution events and assert time_updated equals the terminal execution event's timestamp.

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Jul 14, 2026
  2. rasitakyol commented on Jul 16, 2026

    @rasitakyol

    I rechecked this on current dev (c69abee). The projector still does not bump time_updated for execution/step/tool/text events, but SessionV2.list now orders by time_created, so the reported recency-sort path no longer matches the current implementation. Should this be reframed as restoring last-activity ordering (and then bumping time_updated on execution lifecycle events), or considered superseded by the created-time ordering change?

  3. rodboev commented on Sep 1, 2026

    @rodboev

    This also affects transcript viewers that use session.time_updated as a change-detection signal for the container.

    Without a reliable session-level timestamp that envelopes child writes, viewers have to periodically scan message and part rows across every session to determine which ones changed, and that doesn't scale on large databases where OpenCode activity leads to 200-700% CPU usage, because one active session triggers a full re-read of every session's children.

    Bumping time_updated on execution lifecycle events as suggested here would let viewers skip unchanged sessions using just the session row, without periodic full-table verification passes.

  4. lancy69 commented on Sep 2, 2026

    @lancy69

    I'd like to work on this. My understanding is that the projector should bump session.time_updated (to event.created) when projecting execution lifecycle events (session.execution.started/succeeded/failed), with a regression test asserting time_updated matches the terminal execution event. Validation would be bun typecheck and the projector tests in packages/core.

    One question first: since SessionV2.list now orders by time_created (per the comment above), should the fix also restore last-activity ordering in that list, or just keep time_updated accurate as a change-detection signal for viewers?

  5. Namit2003 commented on Sep 14, 2026

    @Namit2003
    Contributor

    Can I pick this up? If lancy69 is still on it, no worries, happy to step back.

    Still repros on dev (228e909). The step started/ended/failed handlers in the projector only update the message row, they never touch time_updated on the session row. So it just sits at whatever it was before the turn started.

    Plan is to set time_updated from the event timestamp in those three handlers and add a test. Not going to touch the list sort order unless you want that changed too.

    #43847 is against the old v2 branch btw, so it won't merge as is.

  6. lancy69 commented on Sep 15, 2026

    @lancy69

    Hello @Namit2003! I was waiting for an approval from any maintainer. I was not sure if I can open a PR directly without being assigned to, so I didn't touch it till now. You may pick this up if you like :)

  7. rodboev commented on Sep 15, 2026

    @rodboev

    As far as I know you don't need approval; you can open PRs here. If you can fix, that'd be great.

  8. Namit2003 commented on Sep 15, 2026

    @Namit2003
    Contributor

    Thanks both. Will get a PR up against dev shortly.

  9. added a commit that references this issue on Sep 29, 2026
    0ca4289
  10. bilogic commented on Oct 7, 2026

    @bilogic

    Will this move sessions to the top only if:

    1. session is pending answers to questions
    2. session is completed

    and not when streaming/working?

  11. jlongster commented on Oct 7, 2026

    @jlongster
    Contributor

    Merged the PR, sorry for the delay. @bilogic it'll update it whenever something changes

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

    2.0coreAnything 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