Skip to content

Fix own profile disappearing after failed relay fetch#426

Merged
benthecarman merged 1 commit intosledtools:masterfrom
benthecarman:fix-profile-cache-wipe
Mar 4, 2026
Merged

Fix own profile disappearing after failed relay fetch#426
benthecarman merged 1 commit intosledtools:masterfrom
benthecarman:fix-profile-cache-wipe

Conversation

@benthecarman
Copy link
Copy Markdown
Collaborator

@benthecarman benthecarman commented Mar 4, 2026

Summary

  • When fetch_metadata returns None (relay unreachable/timeout), apply_my_profile_metadata was overwriting the cached profile with empty data because it used now_seconds() as event_created_at, which is always newer than the real cached timestamp
  • The subs_force_reconnect change (disconnects WebSockets on foreground) made this more frequent by creating a race between the relay disconnect and the concurrent profile fetch
  • Fix: skip upsert_profile when metadata is None, preserving the existing cached profile

Test plan

  • Added apply_my_profile_none_metadata_preserves_cached_profile test
  • Manual: kill the app, disable network, relaunch — profile should still display from cache
  • Manual: foreground the app on a slow network — profile should not flash empty

🤖 Generated with Claude Code


Open with Devin

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an issue where profile information could be lost when metadata retrieval returns no data.
  • Tests

    • Added test coverage to verify profile data preservation when metadata is unavailable.

When `fetch_metadata` returns `None` (relay unreachable or timeout),
`apply_my_profile_metadata` was creating an empty `ProfileCache` with
`event_created_at = now_seconds()`. Because `now_seconds()` is always
newer than the cached event timestamp, `upsert_profile` would overwrite
the good cached data with empty data, making the profile vanish.

This became more frequent after the `subs_force_reconnect` change which
disconnects relay WebSockets on foreground — creating a race where the
concurrent profile fetch hits a disconnected relay and gets `None`.

Skip the `upsert_profile` call when metadata is `None` so the existing
cached profile is preserved.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c4df25a3-9c19-4efb-9e42-3bc5bba0e1f9

📥 Commits

Reviewing files that changed from the base of the PR and between c63a873 and 086f0db.

📒 Files selected for processing (2)
  • rust/src/core/mod.rs
  • rust/src/core/profile.rs

📝 Walkthrough

Walkthrough

A bug fix is implemented in apply_my_profile_metadata to prevent overwriting cached profiles when metadata fetch returns None. A unit test is added to verify this cache preservation behavior.

Changes

Cohort / File(s) Summary
Profile Metadata Guard
rust/src/core/profile.rs
Modified apply_my_profile_metadata to only upsert ProfileCache when metadata is Some(metadata), preserving existing cache when metadata is None.
Test Coverage
rust/src/core/mod.rs
Added unit test apply_my_profile_none_metadata_preserves_cached_profile to verify that cached profiles remain unchanged when apply_my_profile_metadata receives None metadata.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A cache preserved, not swept away,
When None arrives to ruin the day,
The guard stands firm, the profile stays,
Safe in memory, come what may! 📦✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly summarizes the main fix: preventing the own profile from disappearing when relay fetch fails, which is the core issue addressed in both code changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@benthecarman benthecarman merged commit e171da8 into sledtools:master Mar 4, 2026
18 checks passed
@benthecarman benthecarman deleted the fix-profile-cache-wipe branch March 4, 2026 21:45
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.

1 participant