Repository navigation
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
There was a problem hiding this comment.
The approach looks sound. Ordering a page against the stream with a seq read in the same transaction is the right layer for this race. I checked it by running the PR's race tests against the base: 8 of the 17 fail there and all pass here. The client, server message and TUI data tests also pass, and I ran a TUI smoke test with the simulated model.
Public API: GET /api/session/:id/message (both the plain and the media-URI response) gains an optional experimental: { seq?: Event.Seq }. It is only set on a first page of a Session that has durable events. The client types gain MessageListOutput.experimental / SessionMessagesResponse.experimental, and two new functions are added: SharedEvents.reset() and data.session.hydrate(id, { signal }). Existing callers are unaffected. The app and TUI move from message.sync + pending.sync to hydrate, but both functions remain. All of this is backwards compatible, and older servers without seq keep today's behavior.
One thing to fix: packages/protocol/openapi.json was not regenerated. bun run check:generated in packages/protocol passes on the base and fails on this branch, so please run bun run generate there. There is also a small note on the test helper inline.
| } | ||
| }) | ||
|
|
||
| async function settled() { |
There was a problem hiding this comment.
settled() waits a fixed 50 microtask turns. Several tests rely on that being enough for the fetch, decode and store chain to finish, so they will break silently if that chain gains a few more awaits. Could these tests await the specific read, like the ones using Promise.withResolvers, or wait for a condition instead?
On a bad connection the timeline drifts from the server: a prompt the server already delivered stays Pending at the bottom, under its own reply, and rows go missing or out of order until the session is reopened.
The live stream (
/api/event) is volatile by design (specs/v2/session.md: "no replay guarantee"; request/response consumers use authoritative projections). The client broke that contract in four places:message.syncreplaced the transcript with a page read before events that had already been applied live, wiping replies and prompt deliveries.session.inbox.deliveredstayed lost.pending.syncnever cleared a prompt the server accepted (outbox kept it), so only a transcript page that happened to contain it could settle it.SharedEventskept the socket open while another subscriber (the/goalRPC) held it, so a stall or resync reconnected to the same dead socket.Ordering reads against the stream
GET /api/session/:id/messagenow returnsexperimental.seq: the Session's durable sequence, read in the same transaction as the page. Projections and the sequence advance in one write transaction (Buscommit), so the page reflects exactly the durable events up toseq.transcriptReads,handleEvent).seqskips the folds that mirror the projection (message.update); pending-input overlays still apply (message.overlay).createSync(offline)).seqkeep today's behavior: the page wins.Settling prompts the server accepted
Catching up reliably
data.session.hydrate(id, { signal })loads the transcript and pending input and retries failed reads (500 ms → 5 s) while connected. The app's session resolution and the TUI's rows use it on every (re)connect and abort it when the target changes.SharedEvents.reset()drops the shared stream for every subscriber; the connection calls it on a stall, a connect timeout and a forced resync, so the reconnect opens a new socket.Visual
Added by the opencode bot (AI-generated).
Fixes #56725
Related: #59615, #59542, #56748
Public API: adds optional
experimental.seqto the session messages response,SharedEvents.reset()anddata.session.hydrate()(backwards compatible)