fix(tui): dedupe consecutive prompt history entries#27816
Merged
Conversation
Clearing a prompt with >=20 chars saves it to history. Restoring that entry from history and clearing again was appending a duplicate to both the in-memory store and prompt-history.jsonl. Skip the append when the new entry deep-equals the most recent one.
zenoda
pushed a commit
to zenoda/opencode
that referenced
this pull request
May 16, 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.
Summary
Clearing a prompt with at least 20 characters saves the draft to prompt history (in-memory +
prompt-history.jsonl). If you then press the history-previous keybind to restore that entry and clear it again, the same entry was being appended a second time — every cycle adds another duplicate.The fix is a standard shell-style dedupe: skip the append when the new entry deep-equals the most recent history entry.
Changes
packages/opencode/src/cli/cmd/tui/component/prompt/history.tsx— new pure helperisDuplicateEntry(prev, next)(deep compare via JSON), called at the top ofappend(). On a duplicate, only the index is reset (so navigation stays consistent), and no write hits memory or disk.packages/opencode/test/cli/cmd/tui/prompt-history.test.ts— unit tests for the dedupe helper covering no-previous, identical, differing input, differing parts, and differing mode.Test plan
bun run test test/cli/cmd/tui/prompt-history.test.ts— 5 passbun run typecheck— cleanprompt-history.jsonl