Skip to content

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.
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