[PR #12153] fix: validate prompt history/stash entries to prevent JSON display bug #14092

Closed
opened 2026-02-16 18:18:54 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12153

State: closed
Merged: No


Summary

Fixes a bug where corrupted prompt history/stash entries with non-string input fields would display as JSON in the input box.

Problem

When prompt-history.jsonl or prompt-stash.jsonl files get corrupted, entries with non-string input fields (objects, arrays, numbers) would pass through the filter and display as [object Object] or JSON text in the input box, preventing users from typing or reverting messages.

Solution

Added runtime validation to filter functions in both history.tsx and stash.tsx:

history.tsx:

.filter((line): line is PromptInfo => {
  return line !== null && typeof line === "object" && typeof line.input === "string" && Array.isArray(line.parts)
})

stash.tsx:

.filter((line): line is StashEntry => {
  return line !== null && typeof line === "object" && typeof line.input === "string" && Array.isArray(line.parts) && typeof line.timestamp === "number"
})

Testing

  • Added comprehensive test file test/cli/tui/prompt-corruption.test.ts with 5 test cases
  • Tests cover validation logic, edge cases, and file operations
  • All tests pass: bun test test/cli/tui/prompt-corruption.test.ts

Self-Healing

The existing self-healing behavior is preserved - corrupted files are automatically rewritten with only valid entries after loading.

Fixes #12151

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12153 **State:** closed **Merged:** No --- ## Summary Fixes a bug where corrupted prompt history/stash entries with non-string input fields would display as JSON in the input box. ## Problem When `prompt-history.jsonl` or `prompt-stash.jsonl` files get corrupted, entries with non-string `input` fields (objects, arrays, numbers) would pass through the filter and display as `[object Object]` or JSON text in the input box, preventing users from typing or reverting messages. ## Solution Added runtime validation to filter functions in both `history.tsx` and `stash.tsx`: **history.tsx:** ```typescript .filter((line): line is PromptInfo => { return line !== null && typeof line === "object" && typeof line.input === "string" && Array.isArray(line.parts) }) ``` **stash.tsx:** ```typescript .filter((line): line is StashEntry => { return line !== null && typeof line === "object" && typeof line.input === "string" && Array.isArray(line.parts) && typeof line.timestamp === "number" }) ``` ## Testing - Added comprehensive test file `test/cli/tui/prompt-corruption.test.ts` with 5 test cases - Tests cover validation logic, edge cases, and file operations - All tests pass: `bun test test/cli/tui/prompt-corruption.test.ts` ## Self-Healing The existing self-healing behavior is preserved - corrupted files are automatically rewritten with only valid entries after loading. Fixes #12151
yindo added the pull-request label 2026-02-16 18:18:54 -05:00
yindo closed this issue 2026-02-16 18:18:54 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14092