Repository navigation
fix(client): preserve inbox events during snapshot reads - #49106
Merged
Merged
Conversation
holny
reviewed
Sep 15, 2026
holny
left a comment
Contributor
There was a problem hiding this comment.
Reviewed the diff and ran the suite locally in a fresh worktree at d6492f4: solid-inbox-race 6/6 pass, typecheck clean. Full packages/client run is 164 pass / 3 fail, and those 3 fail identically on origin/v2 (effect/zod drift in promise.test.ts + import-boundaries), so not from this change.
The journal approach looks right. Things I specifically checked:
- Coverage: every write into session.pending goes through removePending, updatePending, or the enqueued handler, so the journal sees all local observations. The only direct setStore sites are the delivery update at data.ts:316 and the reconcile at :1415.
- Same-session reads can't interleave: createSync joins the active run or queues a restart (data.ts:168-174), so two journals for one session never overlap, and the identity check at data.ts:1419 keeps a superseded journal from deleting its successor.
- Field completeness: the enqueued echo plus inboxID/sessionID/event.created rebuilds an exact SessionInboxInfo row (generated/types.ts:2163, variants at :2110), so the full replace in the reconcile can't silently drop fields versus the list snapshot.
- Ordering: Map insertion order means a delivered tombstone that arrives after an enqueued echo wins at reconcile time, which matches consume-after-admit causality. And this lines up with the server model where session_inbox only holds unconsumed work, so treating the SSE echo as newer-than-snapshot is the right direction.
Two small things, take or leave:
- data.ts:255 — the journal value packs three meanings (full item = admission, raw string = delivery change, undefined = tombstone) discriminated by the typeof check in the reconcile. A one-line comment on the declaration would save the next reader the archaeology.
- The failure path ("journal is released after reconciliation or failure") is only covered implicitly by the tests. A cheap extra case — reject the response while a delivered event landed mid-read, then assert pending stays empty — would pin the finally behavior.
Nice repro in the demo, by the way. Holding one real inbox response behind a proxy while letting events through makes the failure mode obvious.
jinhuang712
pushed a commit
to jinhuang712/opencode
that referenced
this pull request
Sep 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
An already-answered question can jump to the bottom of the conversation and remain marked as pending when a remote client reconnects. A delayed inbox HTTP response overwrites newer delivery events, even though the server has already consumed the input and answered subsequent messages.
The affected data layer is shared by the TUI and desktop app.
What changes
Track inbox changes only for the lifetime of the read and apply them over its snapshot before publishing it. Optimistic submissions remain owned by the existing outbox rather than being treated as authoritative events. The read journal is released after reconciliation or failure.
Demo
remote-inbox-before-after.mp4
Left: base
4fc5ba1358. Right:d6492f41d1. Both are the real production TUI driven by the same OpenCode Drive script with a simulated model. A local HTTP proxy holds one actual, non-empty inbox response across reconnect while allowing the event stream and subsequent answers through. Releasing that response reproduces the misplaced pending question on the left; the right keeps it in the conversation. The server inbox is verified empty on both sides before release.The clips are aligned to response release, run at normal speed, and retain the native capture resolution. Drive required a disposable current-client compatibility shim; that separate issue is tracked in anomalyco/opencode-drive#87.
Scope
Shared client inbox hydration and six focused regression cases. The deterministic visible reproduction covers the TUI; the desktop app consumes the same fixed store.
Verification
4fc5ba1358:session methods retain decoded Effect inputs and outputs,public import boundaries > isolates each public entrypoint, andsession methods use the public HTTP contract. Those broad-suite/base comparisons used Bun 1.4.0; the final focused suite and root check also pass with the repository-required Bun 1.4.2.