Skip to content

Improve radio recovery, message delivery and housekeeping - #1

Open
enotikov wants to merge 1 commit into
mainfrom
claude/epic-mccarthy-918ijy
Open

enotikov wants to merge 1 commit into
mainfrom
claude/epic-mccarthy-918ijy

Conversation

@enotikov

Copy link
Copy Markdown
Owner

Summary

Fixes found during a full code review of the project.

Reliability

  • Radio auto-reconnect. meshcore was created with auto_reconnect=True, max_reconnect_attempts=0, and the library's attempts < max_attempts check means zero reconnect attempts. StationService only marked the link as disconnected, so after a USB unplug or BLE drop the station stayed offline until a manual reconnect or service restart. The library's auto-reconnect is now off; StationService schedules its own reconnect loop on an unexpected disconnect, and the port is re-resolved on each attempt. There is no reconnect during maintenance (firmware flashing) or shutdown. transport.start() releases any previous session first.
  • Outgoing queue loop. An unexpected error (e.g. SQLite) used to end _queue_loop silently. Errors are now logged and the loop keeps running.
  • ACK outside the send lock. Direct messages use send_msg, return sent with ack_timeout, and the ACK is awaited in a background task. The next queued messages are no longer blocked by the ACK wait. The status then becomes delivered or unconfirmed. The transport caches ACKs that arrive before the waiter is registered. Pending ACK waits are marked unconfirmed on shutdown.
  • Senders known only by key prefix. An incoming message with a key prefix is attached to the one known contact with that prefix. When the full key appears, prefix stub contacts are merged into it: messages, packets, unread count, favorite/blocked flags and notes carry over. Only hex prefixes are merged into 64-hex keys.

Performance / housekeeping

  • Message timelines load in one query for chat, search and the queue (previously N+1).
  • list_serial_ports() and firmware-upload writes no longer block the event loop.
  • meshcore_station.main no longer creates a database on import (app is lazy); uvicorn starts through create_app with factory=True.
  • Automatic-backup rotation orders by the timestamp embedded in the file name, not the local-time prefix, so it is safe when clocks change for DST.
  • postinst removes stale .venv.release.* environments and keeps the active and previous ones. Relative symlink targets are normalized.
  • Release .deb files are no longer tracked in git (/dist/ is in .gitignore); v1.0.0 and v1.0.1 remain in GitHub Releases.

Testing

  • python -m pytest -q: 71 passed (12 new in tests/test_reliability.py: reconnect, no reconnect during maintenance, queue survival, ACK without blocking, early ACK, stub merging and protection of non-hex IDs, backup ordering, side-effect-free import, installer pruning).
  • compileall, node --check app.js, dash -n deploy/postinst.sh.
  • Smoke test: server started through the factory in simulator mode, /api/status and message sending work.
  • Reconnect and ACKs have not been tested on a real Heltec V4 / BLE; a hardware check is needed before release.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NXj9Mqu9E6pSbpkbkvVXyi


Generated by Claude Code

- Reconnect the radio from StationService after unexpected disconnects
  (meshcore auto-reconnect was disabled by max_reconnect_attempts=0).
- Keep the outgoing queue loop alive after unexpected errors.
- Await direct-message ACKs outside the send lock, with early-ACK caching.
- Resolve prefix-only senders to known contacts and merge prefix stubs.
- Batch message timeline queries; move blocking I/O off the event loop.
- Build the app lazily and run uvicorn with the factory.
- Sort automatic backups by creation time; prune stale release venvs.
- Stop tracking release .deb files in git.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NXj9Mqu9E6pSbpkbkvVXyi
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.

2 participants