Skip to content

chat: deferred turns, Turn union, and legacy tail-window paging - #620

Open
Osvaldo Ortega (osortega) wants to merge 6 commits into
mainfrom
agents/chat-history-navigation
Open

Osvaldo Ortega (osortega) wants to merge 6 commits into
mainfrom
agents/chat-history-navigation

Conversation

@osortega

@osortega Osvaldo Ortega (osortega) commented Nov 20, 2026 •

Copy link
Copy Markdown

Lets a client show a long chat's full prompt list without downloading every response, and expand turns on demand. This builds on the design discussed with Osvaldo Ortega (@osortega).

Protocol

  1. Clients opt in with ClientCapabilities.deferredTurns. Hosts MUST NOT send deferred turns to clients that didn't declare it, so existing clients keep receiving full turns.
  2. Entries in ChatState.turns may be a DeferredTurn. It keeps the turn's id, message, state, usage and timing, sets isDeferred: true, and omits responseParts. Deferred turns stay in place in turns, so actions that refer to turns by ID keep working.
  3. fetchDeferredTurns { channel, turnId, endTurnId? } asks the host to dispatch chat/turnsMaterialized, which replaces the deferred turns in that inclusive range with full turns, in place.
  4. chat/turnResume does nothing on a deferred turn. The host must materialize it first.

Breaking SDK change (wire format unchanged): Turn is now the union MaterializedTurn | DeferredTurn, and the old full Turn is renamed MaterializedTurn. Code that reads responseParts must narrow to the materialized variant first. Each native client models Turn as a two-variant union, decoding isDeferred: true as deferred and anything else as materialized.

Deprecation: tail-window paging (view.turns, ChatState.turnsNextCursor, fetchTurns, chat/turnsLoaded) is now @deprecated with stability Legacy (3). It still works for 1.x clients that don't declare deferredTurns. Hosts SHOULD send deferred-capable clients every retained turn, deferring any they choose, rather than a tail window.

This replaces the earlier listChatTurns/readChatTurns design in this PR. #623 was stacked on that design and will need rework.

Spec: Deferred turns

Other changes

  • JSON Schema now emits { type: boolean, const } for boolean literal types, so oneOf can tell MaterializedTurn from DeferredTurn. This also tightens the existing approved literal on toolCallConfirmed.
  • New shared fixtures: reducer 330–332 and round-trip 100–101.

Validation: npm run generate and npm test pass (677). The client suites pass in TypeScript, Go, Rust (with fmt and clippy), Swift, Kotlin (JDK 17 in podman) and .NET (offline restore on the local SDK, because podman couldn't reach nuget.org).

Let clients list prompt previews, read a contiguous window by turn ID, and locate matching text without extending the live subscription.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Make the prompt index and direct turn-window reads available on their own. Advertise the pair with a per-chat presence object; keep subscription paging unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@osortega Osvaldo Ortega (osortega) changed the title chat: add read-only history navigation and search chat: list prompts and read turn windows without loading the gap Nov 20, 2026
Start at the selected turn rather than centering a window. Return opaque continuations on each available side, leaving the live chat subscription unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@osortega Osvaldo Ortega (osortega) changed the title chat: list prompts and read turn windows without loading the gap chat: list prompts, open a turn by ID, and page by cursor Nov 20, 2026
Rework the history-navigation proposal into deferred turns, per discussion
with Osvaldo:

- ChatState.turns is now ChatStateTurn[] (Turn | DeferredTurn), discriminated
  by isDeferred. A DeferredTurn keeps id, message, state, usage and timing
  but omits responseParts.
- Clients opt in with ClientCapabilities.deferredTurns; hosts must not send
  deferred turns to clients that don't declare it.
- New chat-channel command fetchDeferredTurns { turnId, endTurnId? } asks the
  host to dispatch chat/turnsMaterialized, which replaces deferred turns in
  place with full turns.
- chat/turnsLoaded may carry deferred turns; chat/turnResume is a no-op on a
  deferred turn.
- Remove listChatTurns/readChatTurns, historyBrowsing, and @wireFields
  generator support.
- Native clients model ChatStateTurn as a two-variant union with hand-written
  reducer support; JSON Schema now emits const for boolean literal types.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Rename the full completed-turn type Turn -> MaterializedTurn, and make
  Turn the MaterializedTurn | DeferredTurn union used by ChatState.turns and
  chat/turnsLoaded (formerly ChatStateTurn). This is a breaking change for
  SDK source; the wire format is unchanged.
- Mark tail-window paging (SubscribeView.turns, ChatState.turnsNextCursor,
  fetchTurns, chat/turnsLoaded) @deprecated and Legacy (stability 3) in
  favour of deferred turns. It stays supported for 1.x clients that don't
  declare deferredTurns; hosts SHOULD NOT window deferred-capable clients.
- Update all native generators, reducers, docs, and change fragments.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@connor4312 Connor Peet (connor4312) changed the title chat: list prompts, open a turn by ID, and page by cursor chat: deferred turns, Turn union, and legacy tail-window paging Nov 24, 2026
@connor4312
Connor Peet (connor4312) marked this pull request as ready for review November 24, 2026 22:58
Regenerate clients after the merge and renumber the deferred-turn round-trip
fixtures to 103-104 to avoid colliding with main's 100-102.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants