Skip to content

fix: use mutable output buffer - #1

Merged
alexleensar merged 2 commits into
mainfrom
fix/mutable-output-buffer
Jul 31, 2026
Merged

fix: use mutable output buffer#1
alexleensar merged 2 commits into
mainfrom
fix/mutable-output-buffer

Conversation

@alexleensar

@alexleensar alexleensar commented Jul 30, 2026

Copy link
Copy Markdown

Problem

  • Outbound data is accumulated in immutable bytes. Appending data and retaining the unsent portion repeatedly copies queued bytes, increasing CPU cost as the backlog grows.
  • Marti debug logging lacks useful routing context.

Unaddressed

Unbounded queue growth. This is a preexisting issue that can lead to a memory leak. Will fix in another PR.

Solution

  • Queue serialized event and management payloads in an unbounded OutputBuffer backed by a deque. It uses memoryview for a single chunk, combines up to 4,096 bytes of small chunks per socket write, and removes only bytes accepted by the socket.
  • Disconnect clients when a nonempty socket write makes no progress.
  • Log only the Marti UID, source callsign, and destinations.
  • Add tests for ordering, batching, partial and blocked writes, appends between partial writes, zero-progress writes, the existing write-size limit, immutable queued data, and management responses.

Testing

  • All 28 unit tests pass.
  • Will deploy to corp for further testing before PR into source repo

@alexleensar alexleensar changed the title Use a mutable output buffer fix: use mutable output buffer Jul 30, 2026

@brady-saronic brady-saronic left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Whoop Whoop! Good work @alexleensar !

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves outbound socket transmission efficiency by replacing immutable bytes concatenation with a dedicated mutable output queue (OutputBuffer), and enhances Marti routing debug logs with more actionable context.

Changes:

  • Introduces OutputBuffer (deque-backed) and migrates socket TX paths to queue/appends + partial-write removal.
  • Updates Marti routing debug logging to include event UID, source callsign, and destinations.
  • Adds unit tests covering ordering, batching, partial/blocked writes, and zero-progress disconnect behavior for both TAK and mgmt sockets.

Reviewed changes

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

Show a summary per file
File Description
tests/test_takclient.py Adds unit tests for OutputBuffer immutability enforcement and socket TX ordering/batching/partial-write behaviors.
tests/test_mgmt.py Adds unit test ensuring management responses are transmitted in-order via the updated buffering approach.
taky/cot/router.py Improves Marti debug logging with UID/source/destinations context while preserving routing behavior.
taky/cot/mgmt.py Switches management response buffering from bytes += ... to OutputBuffer.append(...).
taky/cot/client.py Implements OutputBuffer and migrates SocketClient/SocketTAKClient TX buffering to avoid repeated bytes copying.

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

@alexleensar
alexleensar merged commit 7b5ebc0 into main Jul 31, 2026
1 check 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.

4 participants