GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(session): add viewed state by kitlangton · Pull Request #42811 · anomalyco/opencode

Conversation

@kitlangton

@kitlangton kitlangton commented Aug 15, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Problem

Unread state previously lived in each TUI's local tab file. That made attention state client-specific instead of a fact about the Session:

sessionFinishes()

clientA.unread = true
clientB.opensSession()
clientB.unread = false
clientA.unread = true // the clients still disagree

The state also disappeared with local storage and could not be reconstructed by replaying server history.

Change

Sessions now expose two server-owned timestamps plus the last terminal outcome, and the TUI derives unread state from them:

function isUnread(session: Session.Info) {
  if (session.time.idle === undefined) return false
  if (session.time.viewed === undefined) return true
  return session.time.idle > session.time.viewed
}

time.idle records the latest user-visible terminal execution. time.viewed records the latest idle transition acknowledged through POST /api/session/:sessionID/view. outcome records whether the run recorded at time.idle succeeded, failed, or was interrupted, so failed background sessions keep their distinct error treatment across restarts and clients.

How It Works

function projectTerminal(event: ExecutionTerminal) {
  projectExecution(event)
  if (event.type === "session.execution.interrupted" && event.reason === "shutdown") return

  // Strictly advance even when two terminal events share a millisecond.
  session.time.idle = Math.max(event.created, (session.time.idle ?? event.created - 1) + 1)
  session.outcome = terminalOutcome(event.type) // "succeeded" | "failed" | "interrupted"
  preserve(session.time.updated)
}

function viewSession(sessionID: Session.ID) {
  const session = select(sessionID, ["time.idle", "time.viewed"])

  if (!session) throw new Session.NotFoundError({ sessionID })
  if (session.time.idle === undefined) return
  if (session.time.viewed !== undefined && session.time.viewed >= session.time.idle) return

  // The event carries the idle watermark the viewer observed, so a completion
  // that lands between this check and projection stays unread.
  publish({ type: "session.viewed", sessionID, idle: session.time.idle })
}

function projectViewed(event: SessionViewed) {
  // Monotone: duplicates and stale watermarks never regress the projection.
  session.time.viewed = Math.max(event.idle, session.time.viewed ?? event.idle)
  preserve(session.time.updated)
}

function tabUnread(rootID: Session.ID) {
  // Unread reads the root session only: background subagent completions wake the
  // parent, whose own idle transition then carries the signal.
  const root = session(rootID)
  if (!isUnread(root)) return undefined
  return root.outcome === "failed" ? "error" : "activity"
}

function acknowledgeVisibleSession(rootID: Session.ID) {
  // Runs even with tabs disabled: viewed state is server-global.
  if (!terminal.focused) return
  const root = session(rootID)
  if (!isUnread(root) || acknowledged.get(rootID) === root.time.idle) return
  return api.session.view({ sessionID: rootID })
}

The TUI no longer persists or mutates its own unread map. It refreshes authoritative Session info after terminal and viewed events for sessions it has loaded, derives the tab marker from the root session's own timestamps, and marks the root viewed when that session is visible in a focused terminal.

Example

// No completed execution
{ idle: undefined, viewed: undefined }        // read

// An execution fails
{ idle: 100, viewed: undefined, outcome: "failed" } // tab unread with error styling

// Any focused TUI opens the root tab
{ idle: 100, viewed: 100 }                    // every client converges to read

// A later execution finishes
{ idle: 200, viewed: 100, outcome: "succeeded" } // unread again, activity styling

Flow

sequenceDiagram
    participant Runner
    participant Bus as Durable event bus
    participant Store as Session projection
    participant B as Viewing TUI
    participant A as Other TUI

    Runner->>Bus: execution terminal
    Bus->>Store: advance time.idle, record outcome
    Bus-->>A: terminal event, refresh Session
    Bus-->>B: terminal event, refresh Session
    B->>Store: POST /session/:id/view
    Store->>Bus: session.viewed (observed idle watermark)
    Bus->>Store: time.viewed = max(watermark, time.viewed)
    Bus-->>A: viewed event, refresh Session
    Bus-->>B: viewed event, refresh Session
Loading

Reviewer Map

  • packages/schema defines the timestamps, outcome, and the durable session.viewed event with its idle watermark.
  • packages/core owns persistence, migration, terminal/viewed projection, replay, and Session.view.
  • packages/protocol, packages/server, and generated clients expose the HTTP operation.
  • packages/client/src/solid/data.ts refreshes shared Solid Session info after authoritative events, for sessions the client already loaded.
  • packages/tui/src/context/session-tabs.tsx removes local unread ownership and derives/acknowledges the root session's state.

Demo

Two wall-clock-aligned OpenCode Drive TUIs share one isolated server. The left client stays on Active workspace; the right client opens unread tab 1. The purple unread marker appears in both clients, then clears in the left client as soon as the right client views the completed background session.

session-viewed-two-clients-synced.mp4

Verification

TUI: 735 passed / 5 skipped. Core: 1856 passed / 16 skipped, including viewed-watermark race, outcome projection, replay, migration, and transfer coverage. Client, Server, Schema suites and Client, Core, Protocol, TUI, generated, and workspace typechecks pass. Two packages/client test failures and one packages/schema failure reproduce on a pristine origin/v2 checkout and are unrelated to this branch.

Scope

  • outcome is projected purely from existing terminal event types; no new durable event was added for it, and "running" liveness deliberately stays with the execution claim and live event stream rather than this field.
  • The session.viewed event carries the observed idle watermark, so a delayed or duplicate view request can never mark a newer completion viewed; concurrent requests append harmless monotone facts rather than introducing a process-local lock.
  • Client event handling refreshes only sessions already loaded by that client, matching sibling event handlers.
  • Acknowledgement is decoupled from the tabs feature: a TUI with tabs.enabled: false still reports viewed state that other clients depend on.
  • Tab unread deliberately reads the root session only. Background subagent completions notify and wake the parent, whose own idle transition carries the signal; subagent sessions' viewed state is currently unconsumed, and per-subagent unread (plus wake durability across server restarts) is out of scope.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions github-actions Bot added the contributor label Aug 15, 2026
@kitlangton
kitlangton force-pushed the session-viewed-state branch 4 times, most recently from 61e5c7f to c9d35f2 Compare August 20, 2026 21:08
@Enough1122

Enough1122 commented Aug 21, 2026

Copy link
Copy Markdown

AI code review — automated review for reference; please use your judgment.

Diff too large for automated review (36 files, ~490KB, including generated client/schema/migration artifacts) — recommend human review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TonisOrmisson TonisOrmisson mentioned this pull request Aug 21, 2026
[FEATURE]: Desktop - Show session attention count on the Windows taskbar #43937
Closed
1 task done
@kitlangton
kitlangton force-pushed the session-viewed-state branch 2 times, most recently from 789c109 to 3cae56e Compare August 21, 2026 19:38
kitlangton added 5 commits August 21, 2026 15:48
@kitlangton
feat(session): add viewed state
28423bd
@kitlangton
refactor(tui): read unread from root session only
543369c
@kitlangton
chore(www): regenerate openapi mirrors
ef0cfe4
@kitlangton
chore(core): format schema snapshot
1c0adaf
@kitlangton
refactor(server): use missingSession helper in view handler
6558490
@kitlangton
kitlangton force-pushed the session-viewed-state branch from 3cae56e to 6558490 Compare August 21, 2026 19:51
@kitlangton
fix(session): preserve viewed-state ordering
4077f52
@kitlangton
kitlangton merged commit c29a7c1 into v2 Aug 21, 2026
8 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@kitlangton
kitlangton deleted the session-viewed-state branch August 21, 2026 23:34
jinhuang712 pushed a commit to jinhuang712/opencode that referenced this pull request Sep 26, 2026
@kitlangton
feat(session): add viewed state (anomalyco#42811)
fbeb8f6
@opencode-agent opencode-agent Bot mentioned this pull request Oct 15, 2026
[FEATURE]: Mark TUI tabs unread, with plugin support #55599
Open
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

contributor

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@kitlangton @Enough1122
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.