fix(tui): fetch messages from server in undo/redo to fix trimmed cache bug#28660
Open
lexlian wants to merge 4 commits into
Open
fix(tui): fetch messages from server in undo/redo to fix trimmed cache bug#28660lexlian wants to merge 4 commits into
lexlian wants to merge 4 commits into
Conversation
…e bug The /undo and /redo commands searched the TUI's in-memory message cache which is capped at 100 messages per session. When an agent loop generates enough assistant/tool messages to push the total past 100, the oldest user messages are shift()ed out, making undo unavailable for earlier messages. Fix both undo and redo handlers to fetch messages directly from the server API (sdk.client.session.messages) instead of relying on the capped local store. The server always has the complete message history from the database. Also add a fallback for prompt restoration: try local cache first, then fall back to server-returned parts when the local cache entry is missing. Fixes anomalyco#28257
getScrollAcceleration expects Pick<TuiConfig.Info, 'scroll_acceleration' | 'scroll_speed'> but was passed the full TuiConfig.Resolved type. Pick the two required fields explicitly.
This reverts commit e9234d1.
Verifies server-side revert works correctly when session has more than 100 messages, which is the underlying behavior the TUI fix depends on. The TUI's local message cache caps at 100 entries per session (sync.tsx:272), so the undo/redo fix fetches from the server which always has the complete message history.
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.
Issue for this PR
Closes #28257
Type of change
What does this PR do?
Root cause: The TUI's undo/redo commands searched
sync.data.message[sessionID], an in-memory message cache capped at 100 entries per session. When an agent loop generates enough assistant/tool messages to push the total past 100, the oldest user messages are shifted out. /undo then silently fails because it can't find earlier user messages.Why TUI fails but Web UI works: The web UI doesn't maintain a capped local message cache. Each request to the server fetches complete history from the database, so revert always finds the correct user message. The TUI sync context caps messages at 100 (sync.tsx:272) for performance, but the undo handler depended on that trimmed cache instead of fetching from the server.
Fix: Both undo and redo handlers now call
sdk.client.session.messages()to fetch complete message history from the server, then find the target user message. The server always has the full message list from the database. For prompt restoration, a fallback (sync.data.part[id] ?? message.parts) handles trimmed entries.Files changed:
packages/opencode/src/cli/cmd/tui/routes/session/index.tsx— undo handler (line 598) and redo handler (line 637) fetch from server instead of local cachepackages/opencode/test/session/revert-trimmed-cache.test.ts— new test verifying server-side revert works with 100+ messagesHow did you verify your code works?
test/session/revert-trimmed-cache.test.ts: creates 100+ messages with 2 user messages, verifies sequential revert/unrevert works correctlytest/session/revert-compact.test.tsChecklist