Skip to content

fix: add automatic 1 Hz keepalive heartbeat for stealth Python clients#361

Merged
from2001 merged 3 commits intodevelopfrom
claude/issue-356-20260303-1109
Mar 13, 2026
Merged

fix: add automatic 1 Hz keepalive heartbeat for stealth Python clients#361
from2001 merged 3 commits intodevelopfrom
claude/issue-356-20260303-1109

Conversation

@from2001
Copy link
Collaborator

@from2001 from2001 commented Mar 3, 2026

The Python stealth client was disconnecting because no periodic signal was sent to keep the server's 5-second CLIENT_TIMEOUT from expiring.

Mirrors Unity's TransformSyncManager architecture:

  • Add STEALTH_HEARTBEAT_INTERVAL = 1.0 (matches HEARTBEAT_INTERVAL_SECONDS)
  • send_stealth_handshake() now sets _is_stealth_mode = True and starts the internal heartbeat
  • _maybe_send_stealth_heartbeat() is called each _receive_loop iteration; re-enqueues a stealth packet whenever the interval elapses
  • No caller change needed: one send_stealth_handshake() call is enough

Closes #356

Generated with Claude Code

The Python stealth client was disconnecting because no periodic signal
was sent to keep the server's 5-second CLIENT_TIMEOUT from expiring.

Mirrors Unity's TransformSyncManager architecture:
- Add STEALTH_HEARTBEAT_INTERVAL = 1.0 (matches HEARTBEAT_INTERVAL_SECONDS)
- send_stealth_handshake() now sets _is_stealth_mode = True and starts
  the internal heartbeat via _send_stealth_heartbeat()
- _maybe_send_stealth_heartbeat() is called each _receive_loop iteration;
  it re-enqueues a stealth packet whenever the interval elapses
- No caller change needed: one send_stealth_handshake() call is enough

Also adds test_stealth_heartbeat.py with 11 tests covering the unit-level
timer logic and an integration test that verifies the client stays
registered past the server timeout with a short CLIENT_TIMEOUT config.

Closes #356

Co-authored-by: Masahiro Yamaguchi <from2001@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an automatic keepalive heartbeat for Python “stealth” clients so they remain connected past the server’s CLIENT_TIMEOUT, aligning Python behavior with Unity’s periodic stealth signaling.

Changes:

  • Introduces STEALTH_HEARTBEAT_INTERVAL = 1.0 and stealth-mode state/timer tracking in the Python client.
  • Makes send_stealth_handshake() enable stealth mode and trigger periodic heartbeats from the receive loop.
  • Adds unit + integration tests validating the 1 Hz heartbeat and that the client remains registered beyond a shortened server timeout.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
STYLY-NetSync-Server/src/styly_netsync/client.py Adds stealth heartbeat interval constant, stealth state, and periodic heartbeat emission in _receive_loop.
STYLY-NetSync-Server/tests/test_stealth_heartbeat.py New tests for stealth heartbeat behavior (unit + end-to-end server/client).
STYLY-NetSync-Server/src/styly_netsync/client_simulator.py Formatting-only change to battery drain constant expression.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@from2001 from2001 requested a review from mhama March 3, 2026 12:55
@mhama
Copy link
Collaborator

mhama commented Mar 10, 2026

LGTM

@from2001 from2001 merged commit af55bea into develop Mar 13, 2026
7 checks passed
@from2001 from2001 deleted the claude/issue-356-20260303-1109 branch March 13, 2026 22:18
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.

python stealth client doesn't keep connection

3 participants