Skip to content

test(daemon): run the stalled-reader backpressure test over a Unix socket, not TCP loopback - #31256

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/daemon-backpressure-test-main
Oct 21, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/daemon-backpressure-test-main

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​14 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​8
Prod 0 0 0 0

ELI5

A daemon test kept failing in CI for PRs that didn't touch the daemon. The test stalls a reader and floods a socket to check that the terminal producer pauses. It used a local network (TCP) connection. On Linux, the kernel quietly buffers several megabytes on that kind of connection, so the flood disappeared into the kernel and the producer was never asked to pause. The real daemon stream uses a Unix socket (a named pipe on Windows), which buffers very little. The test now uses that.

What Changed

  • Problem: on current main, src/main/daemon/daemon-stream-backpressure-socket.test.ts "bounds 1024-character writes (hidden=false) and resumes" fails in PR CI (expected false to be true at the paused check), for example in run 39507563418 on a workflow-only PR. The other three cases pass.
  • Cause: the test, not production. The backpressure code (daemon-stream-backpressure.ts, daemon-stream-data-batcher.ts, session-producer-pause.ts) hasn't changed since perf(daemon): send PTY output to main as raw bytes, not NDJSON #27006 (10-09). It counts bytes as backlog until their socket write completes. Over TCP loopback, Linux autotunes the kernel buffers, so writes keep completing into the kernel and the counted backlog stays below the 4 MiB pause threshold until most of the 8 MiB flood has gone. A standalone probe on an Ubuntu 24.04 box, writing 8 MiB to a paused reader: over TCP the kernel took about 2.5 MiB, and the 4 MiB threshold was reached only after about 6.9 MiB had been written. Over a Unix socket the kernel took about 0.1 to 0.2 MiB, and the threshold was reached at about 4.2 MiB. A CI runner with somewhat larger TCP buffers never reaches the threshold within 8 MiB. On macOS, TCP loopback buffers only about 0.5 MiB, which is why the test passes locally.
  • Change: the test listens on a Unix socket in a unique directory under /tmp on POSIX, or a named pipe using a unique temporary-directory basename on Windows, the same way daemon-health.test.ts builds one, and removes the directory afterwards. The fixed POSIX root keeps the complete socket path below the kernel limit even with a long TMPDIR. The assertions are unchanged.
  • No user-facing change.

Why

Making the test use the daemon's real transport removes the dependence on kernel TCP tuning, without loosening any threshold or assertion. Raising the flood size or lowering the threshold would only move the margin. Faking the socket would stop exercising real kernel backpressure, which is the point of this test.

Plan (light path), all four criteria:

  • Small: zero production lines; one test file, +14/-6.
  • Outside risky shipped areas: no saved data, wire, RPC, lifecycle, process, build or cross-version change.
  • Not a repeat fix: the touched file's previous change was September 19, outside the last 30 days, with no intervening fix or revert.
  • Local effect: only the test fixture changes; no code shipped in the app changes.

Still catches the regression: with the pause threshold temporarily raised to 64 MiB, both visible-session cases fail. Reverted before committing; independently confirmed during review.

Linked Issue

N/A, main fix.

Visual Proof

N/A: test-only change, no UI.

Testing

  • Ran the file 5 times under Bun and 5 times under Node on macOS: 4/4 pass each time.
  • Ran the threshold check described above, which fails both visible cases.
  • Corrected fixture: named Node test on macOS passes all four cases with default TMPDIR and with the reviewer's 96-byte TMPDIR; temporary-root cleanup leaves no entries.
  • Final-head Linux CI: full PR workflow 39515093491 passed on 346b4d7e41c9cd9c6d7d01fd3535324bba77e0d2, including static analysis, all five test shards, relay integration, selection evidence and the aggregate gate.
  • Direct Windows named-pipe test: all four cases passed on final head 346b4d7e41c9cd9c6d7d01fd3535324bba77e0d2, Windows low spec, Node v24.18.0, exit 0, through qa-gate ticket 938.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Cross-platform: Unix socket path on macOS/Linux uses a unique directory under the fixed /tmp root to stay below the kernel byte limit; Windows keeps os.tmpdir() and uses only the unique basename for its named pipe. Direct Windows named-pipe execution passed all four cases on the final head.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…cket, not TCP loopback

Linux autotunes TCP loopback buffers to several MiB, so the kernel absorbed
most of the 8 MiB flood, write callbacks completed, and the producer never
reached the 4 MiB high-water mark on some CI runners. The daemon stream runs
over a Unix socket or named pipe, whose small fixed kernel buffers keep the
backlog in the daemon's own accounting.
@brennanb2025
brennanb2025 marked this pull request as ready for review October 20, 2026 23:02
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The backpressure test now uses a Unix socket on non-Windows platforms and a named pipe on Windows instead of a TCP loopback server. It creates a platform-specific endpoint, connects the server and writer through that endpoint, and removes the temporary directory during teardown.

Priority: ⬇️ Low

Merge Risk: 🟡 Moderate · up to 346b4

On a remote test worker with restricted /tmp, the backpressure test fails before its assertions run. Preserve the socket-path limit while supporting a configured writable temporary root before merging.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly identifies the main change: the stalled-reader backpressure test now uses a Unix socket instead of TCP loopback.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The pull request description is complete and follows the required template. It explains the problem, change, rationale, testing, cross-platform considerations, lack of UI impact, and checklist status.…
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1 files.

Full details: Description check

Explanation

The pull request description is complete and follows the required template. It explains the problem, change, rationale, testing, cross-platform considerations, lack of UI impact, and checklist status. The Linked Issue section says "N/A" even though the template normally requires an issue for outside contributors, but the author identifies this as a main fix and the omission is not critical for this test-only change.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0953fc3f-6518-4198-9aa9-05a603038d3b
📥 Commits

Reviewing files that changed from the base of the PR and between f812c67 and 346b4d7.

📒 Files selected for processing: 1
  • src/main/daemon/daemon-stream-backpressure-socket.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

@brennanb2025

brennanb2025 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

The stalled-reader backpressure test was failing on unrelated Linux CI changes because TCP loopback buffers could absorb the capped flood before the producer paused. The test now uses the daemon's local transport: a Unix socket on macOS/Linux and a named pipe on Windows. No shipped code or user-facing behavior changes.

The light-path review completed in two rounds, including one fix and a re-check by the same reviewer. Review found that a long valid TMPDIR exceeded the Unix socket path limit; commit 346b4d7e now uses a fixed-length POSIX root. All existing assertions remain unchanged. No proven code findings remain open. An automated review raised a residual concern about environments with a writable custom temp root but a restricted /tmp. The test uses the same fixed POSIX root assumption already used by the daemon’s short endpoint path; no such supported-runner failure was established. This concern is deferred rather than adding configurable fixture roots.

Verified on final head 346b4d7e41c9cd9c6d7d01fd3535324bba77e0d2:

  • The named test passes all four cases on macOS with both default and 96-byte TMPDIR, independently repeated by the reviewer.
  • The Windows named-pipe test passes all four cases under Node v24.18.0, exit 0, on the qa-gate-admitted Windows low-spec machine (ticket 938).
  • Full PR CI is green, including static analysis, all five test shards, relay integration and the aggregate gate: run 39515093491.
  • Independently raising the pause threshold from 4 to 64 MiB fails exactly both visible-session cases; both hidden cases pass. The fixture-only follow-up preserves that logic.

Readiness checks found no shipped, mobile, saved-data or version-compatibility changes. App QA is skipped because the only changed file is a test (qa=none). This test still bypasses real PTYs and transport negotiation; it does not establish app latency or full daemon-stack behavior. The earlier failure in #30633 was verified directly; the numerical buffer probe and reported #30644 recurrence were not independently reproduced.

For Brennan's review: main-versus-branch screenshots are not applicable because no UI changes. The only judgment point is the transport and bounded temporary path; assertions are unchanged.

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.

1 participant