Skip to content

Fix chat history truncation and remaining node_num==0 falsy checks - #15

Merged
hardcoreerik merged 2 commits into
mainfrom
fix/message-history-truncation-and-zero-node-nums
Aug 6, 2026
Merged

Fix chat history truncation and remaining node_num==0 falsy checks#15
hardcoreerik merged 2 commits into
mainfrom
fix/message-history-truncation-and-zero-node-nums

Conversation

@hardcoreerik

Copy link
Copy Markdown
Owner

Summary

  • MonitorStore.read_messages() sorted ORDER BY observed_at ASC LIMIT ? — once a user's message table exceeds the 5000-row default loaded at startup, this returned the oldest N messages and silently dropped every message newer than that, instead of showing recent chat history. Now selects the newest N (using rowid as a deterministic tiebreaker for same-timestamp rows), then re-sorts that selection chronologically for display.
  • Two remaining if value truthiness checks on node_num/to fields that mishandle a legitimate node_num == 0 or to == 0 (most instances of this bug class were already fixed in earlier PRs — these two were missed):
    • _device_summary(): NodeDB lookup and node-id formatting both skipped for local_num == 0.
    • _on_text_received(): to_num = packet.get("to") or packet.get("toNum") would fall through to toNum even when a genuine to == 0 was present.

Risk assessment

Low risk, isolated correctness fixes. No schema changes, no behavior change for the common case (table under the limit). read_messages()'s new query is a subquery + re-sort, tested against >limit, under-limit, DM/channel-mixed, and same-timestamp-tiebreak cases.

Test plan

  • pytest -q — 361 passed (25 new: test_monitor_store_message_history.py, test_zero_value_handling.py)
  • ruff check src tests scripts — clean
  • mypy src/meshchat — clean
  • Regression tests cover: >5000 messages returns newest N in chronological order; DM and channel messages both survive the newest-N cut; under-limit case unaffected; node_num == 0 NodeDB lookup/id formatting; to == 0 inbound packet resolves as a direct message instead of falling through to toNum.

🤖 Generated with Claude Code

… falsy checks

read_messages() sorted ascending before applying LIMIT, so once a user's
message table exceeded the 5000-row default, startup silently loaded the
oldest 5000 messages and dropped everything newer instead of showing recent
history. Now selects the newest N (rowid as a deterministic tiebreaker),
then re-sorts that selection chronologically.

Also fixes two remaining `if value` truthiness checks on node_num/to that
mishandle a legitimate node_num==0 or to==0: _device_summary()'s NodeDB
lookup/id-formatting, and the inbound "to" field resolution in
_on_text_received(). Most instances of this bug class were already fixed in
earlier PRs; these two were missed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@hardcoreerik, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 11 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 44489871-929e-48f3-ae1c-77fa9a35270d

📥 Commits

Reviewing files that changed from the base of the PR and between be8d113 and 6f7c4d6.

📒 Files selected for processing (5)
  • src/meshchat/controllers/meshtastic_controller.py
  • src/meshchat/database/schema.py
  • src/meshchat/services/monitor_store.py
  • tests/test_monitor_store_message_history.py
  • tests/test_zero_value_handling.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

…on unfixed code

With toNum=0xDEADBEEF, both old and new code classified to=0 as a DM
(0xDEADBEEF is not BROADCAST_NUM in either path), so the assertion could
never catch the regression. With toNum=0xFFFFFFFF (BROADCAST_NUM), the
old `to or toNum` path classifies as broadcast (destination_num=None)
while the fixed path uses to=0 as a DM (destination_num=sender_num).

Also update the stale comment in _POST_MIGRATE_INDEXES that referenced
the old "ORDER BY observed_at ASC LIMIT ?" shape that read_messages()
no longer uses after the newest-N subquery fix.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@hardcoreerik
hardcoreerik merged commit f194aab into main Aug 6, 2026
3 checks passed
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