Skip to content

fix: validate prompt history/stash entries to prevent JSON display bug#12154

Closed
Ashwinhegde19 wants to merge 4 commits into
anomalyco:devfrom
Ashwinhegde19:fix/prompt-corruption-validation2
Closed

fix: validate prompt history/stash entries to prevent JSON display bug#12154
Ashwinhegde19 wants to merge 4 commits into
anomalyco:devfrom
Ashwinhegde19:fix/prompt-corruption-validation2

Conversation

@Ashwinhegde19

Copy link
Copy Markdown

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

Add runtime validation to filter out corrupted entries with non-string input fields.
Previously, only null values were filtered, allowing objects with corrupted input
fields to display as JSON in the input box.

Changes:
- history.tsx: Validate input is string and parts is array
- stash.tsx: Validate input is string, parts is array, and timestamp is number
- Add comprehensive tests for validation logic

This prevents the input box from showing [object Object] or JSON structures
when prompt history/stash files are corrupted.

Fixes anomalyco#12151
@github-actions

github-actions Bot commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

@Ashwinhegde19

Copy link
Copy Markdown
Author

Note on Test Failure:

The CI test failure is in @opencode-ai/app#test (Playwright E2E tests), which is unrelated to this PR.

Details:

  • ✅ Our new test passes: packages/opencode/test/cli/tui/prompt-corruption.test.ts (5/5 tests pass locally)
  • ❌ Failure is in packages/app Playwright E2E tests - a pre-existing CI flakiness issue
  • 📁 This PR only modifies files in packages/opencode (history.tsx, stash.tsx, test file)

The app package's E2E tests are known to be flaky in CI. This is a separate issue from the prompt corruption bug fix.

@Ashwinhegde19
Ashwinhegde19 force-pushed the fix/prompt-corruption-validation2 branch from 4da805d to a4ee507 Compare February 4, 2026 17:12
@R44VC0RP
R44VC0RP requested review from rekram1-node and removed request for rekram1-node February 4, 2026 18:23
@github-actions

github-actions Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

@github-actions github-actions Bot closed this Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: validate prompt history/stash entries to prevent JSON display bug

1 participant