Skip to content

feat(daemon): raise trace socket receive buffer to absorb trace2 bursts - #1762

Merged
svarlamov merged 3 commits into
mainfrom
devin/1783521668-trace-socket-recv-buffer
Jul 8, 2026
Merged

feat(daemon): raise trace socket receive buffer to absorb trace2 bursts#1762
svarlamov merged 3 commits into
mainfrom
devin/1783521668-trace-socket-recv-buffer

Conversation

@Siddhant-K-code

@Siddhant-K-code Siddhant-K-code commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Git writes trace2 frames synchronously to the daemon's Unix socket. With small kernel socket buffers (macOS defaults to ~8 KiB), a bursty trace2 stream can fill the receive buffer and block the raw git process in write() until the daemon drains it — the back-pressure freeze class flagged for larger change-sets. This raises the trace socket's SO_RCVBUF so those bursts are absorbed in-kernel.

Shipped as a small, standalone PR so it can land independently of the socket-drain health work.

What changed (Unix only; Windows uses named pipes and is untouched):

// new: SO_RCVBUF helper, applied on the trace listener AND each accepted conn
set_socket_recv_buffer(fd, trace_socket_recv_buffer_bytes())  // setsockopt(SO_RCVBUF)

trace_listener_loop_actor:
  listener = bind(trace.sock)
+ set_trace_listener_recv_buffer(&listener)   // accepted conns inherit it early
  for stream in listener.incoming():
+     set_trace_socket_recv_buffer(&stream)    // backstop per-connection
  • Default target is a conservative 512 KiB (TRACE_SOCKET_RECV_BUFFER_BYTES), and is overridable at runtime via GIT_AI_TRACE_SOCKET_RECV_BUFFER_BYTES so it can be ramped toward 1 MiB without a code change. 0 disables the bump.
  • The constant and all setsockopt code are #[cfg(not(windows))]; Windows trace ingestion uses named pipes, so there is nothing to gate there.

Important: this is a mitigation, not a guarantee. A larger buffer absorbs bursty trace output, but any finite buffer can still fill if the daemon genuinely stops draining — that drain-stall detection is handled separately (ping/sentinel health check, #1735).

Testing

  • set_socket_recv_buffer raises a socket's SO_RCVBUF toward the target. The assertion is robust to Linux clamping SO_RCVBUF to net.core.rmem_max (CI runners default to ~208 KiB): it passes if the buffer reaches the target or grows past the socket's default baseline.
  • A zero target is a verified no-op (does not error, does not shrink the existing buffer).
  • cargo fmt, cargo clippy --all-targets -- -D warnings, cargo doc all clean (Rust 1.93.0, matching CI).

Link to Devin session: https://app.devin.ai/sessions/a9931f84ae914fcc82663a2e52106bd5
Requested by: @Siddhant-K-code


Open in Devin Review

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@Siddhant-K-code Siddhant-K-code self-assigned this Jul 8, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration Bot added a commit that referenced this pull request Jul 8, 2026
…th checks

Replace the trace-ingest drain watchdog (which restarted the daemon on a
detected stall, risking memory spikes and restart loops) with a liveness
ping/sentinel mechanism that alerts instead of restarting.

The socket health-check loop now sends a Ping control request and a trace
sentinel line each tick, tracking when each socket last acknowledged a ping
(control: request round-trips; trace: the reader stamps a received-timestamp).
If a socket goes unacknowledged past a generous threshold it warns exactly once
per stall episode. The pre-existing connect-probe restart safety net for a dead
listener is retained unchanged.

Socket receive-buffer tuning is split out into a separate PR (#1762).

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…nection

A Unix-domain listener's SO_RCVBUF is not inherited by accepted connections,
so the listener-level call was a no-op wasted syscall with a misleading
comment. Keep only the per-connection buffer bump, which is what takes effect.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

Open in Devin Review

Comment thread src/daemon.rs
…lake)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@svarlamov
svarlamov merged commit fcb075f into main Jul 8, 2026
36 checks passed
@svarlamov
svarlamov deleted the devin/1783521668-trace-socket-recv-buffer branch July 8, 2026 23:50
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