Skip to content

fix: Remove state_key: null from Seshat search results#31524

Merged
dbkr merged 4 commits intoelement-hq:developfrom
shinaoka:shinaoka/fix-state-key-null
Feb 5, 2026
Merged

fix: Remove state_key: null from Seshat search results#31524
dbkr merged 4 commits intoelement-hq:developfrom
shinaoka:shinaoka/fix-state-key-null

Conversation

@shinaoka
Copy link
Contributor

PR: Remove state_key: null from Seshat search results

Summary

Seshat (local search index) incorrectly includes "state_key": null for non-state events in search results. This causes matrix-js-sdk to incorrectly treat them as state events, which prevents encrypted messages from rendering properly in search results.

Changes

  • Remove state_key: null from main search result events
  • Remove state_key: null from context events (events_before / events_after)
  • Add unit tests for the fix

Files Changed

  • src/Searching.ts - Add post-processing to remove null state_key
  • test/unit-tests/Searching-test.ts - Add tests

Tests

Unit tests added in test/unit-tests/Searching-test.ts:

  • removes state_key: null from search results - Verifies that state_key: null is removed from main search result events and context events
  • does not modify events without state_key: null - Verifies that events without state_key are not accidentally modified

Related Issues

This is a workaround for a Seshat bug where non-state events are serialized with state_key: null instead of omitting the field entirely.

Checklist

Copy link
Member

@dbkr dbkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch, thanks for the fix!

src/Searching.ts Outdated
for (const searchResult of localResult.results) {
const event = searchResult.result as unknown as Record<string, unknown>;
if (event && "state_key" in event && event.state_key === null) {
delete event.state_key;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non blocking, but if (event?.state.key === null) delete event.state_key would probably be more succinct here (if it doesn't exist it will be undefined)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion. I have fixed it.

Seshat includes "state_key": null for non-state events, which causes
matrix-js-sdk to incorrectly treat them as state events. This prevents
encrypted messages from rendering properly in search results.

This fix removes the null state_key from search results and context
events before passing them to the SDK.
@dbkr
Copy link
Member

dbkr commented Feb 5, 2026

Sorry, this is now failing the threshold for test coverage: would you be able to add a test to make up the 4%?

@dbkr
Copy link
Member

dbkr commented Feb 5, 2026

Thanks!

@dbkr dbkr added this pull request to the merge queue Feb 5, 2026
Merged via the queue into element-hq:develop with commit 8de804d Feb 5, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-Defect Z-Community-PR Issue is solved by a community member's PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants