fix(vehicle): reset stale BLE reassembly frames#58
Merged
Conversation
added 2 commits
July 10, 2026 10:53
ReassemblingBuffer only resynchronized on a protobuf decode failure, so a chunk dropped mid-message left a stale partial frame that got prepended to the next message, corrupting it until a lucky decode error resynced. Discard the partial when a chunk arrives more than 1s after the previous one, matching the reset semantics in Tesla's official Go SDK.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Add a time-based reset to ReassemblingBuffer (BLE reassembly), matching Tesla's official Go SDK. The Go SDK (teslamotors/vehicle-command, pkg/connector/ble/ble.go) resets its input buffer when more than rxTimeout (1s) passes since the last received chunk; our ReassemblingBuffer previously only resynchronized on a protobuf decode failure, so a chunk dropped mid-message could leave a stale partial frame in the buffer that gets prepended to the next message, corrupting it until a lucky decode error resynced. Fix: track last-chunk receive time via time.monotonic() in ReassemblingBuffer, added a module constant STALE_CHUNK_TIMEOUT = 1.0 matching the Go SDK's 1s value (no new config knob, per repo style), and discard the in-progress partial buffer if the next chunk arrives more than that long after the previous one, before appending the new data. Deliberately out of scope: exception wrapping, timeout/retry logic, and any change to the separate ack-loss/stalled-link behavior documented elsewhere in AGENTS.md (this is a frame-integrity hardening only, not a fix for that). Added two new mocked-clock tests to tests/test_ble_reassembling_buffer.py: one verifying a stale partial (>1s gap) is discarded so the following message decodes cleanly (confirmed this fails without the fix - the stale partial poisons the next message and it never decodes), and one verifying fast multi-chunk messages arriving under 1s apart still reassemble correctly as before. All existing tests, ruff, and pyright pass. Also added a short entry to AGENTS.md documenting the new reset semantics and Go SDK parity motivation, since it's durable project knowledge for future BLE work.
What Changed
ReassemblingBufferhandling by tracking the last received chunk time and discarding stale partial frames after the 1-second inter-chunk timeout.Risk Assessment
✅ Low: The change is tightly scoped to BLE frame reassembly, preserves existing complete-message behavior, and adds focused regression coverage for the new stale-partial reset path.
Testing
Inspected the scoped BLE buffer diff, ran the targeted reassembly tests, captured a direct ReassemblingBuffer transcript proving stale partial discard and under-timeout reassembly behavior, then ran the full
testssuite; all checks passed and transient worktree test artifacts were removed.Evidence: BLE reassembly behavior transcript
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
git diff --stat 759d6fa34108597ef09095771480318a39ac5b5a..113735ae3587357c45bc50b6dfe84aa58aefcbfdgit diff 759d6fa34108597ef09095771480318a39ac5b5a..113735ae3587357c45bc50b6dfe84aa58aefcbfd -- tesla_fleet_api/tesla/vehicle/bluetooth.py tests/test_ble_reassembling_buffer.pyuv run pytest tests/test_ble_reassembling_buffer.pyuv run python - <<'PY' | tee /tmp/no-mistakes-evidence/01KX4R7G5PPC2SG75829WYGSSB/ble-reassembling-buffer-transcript.txtuv run pytest tests✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.