Files
PaperClipAI/server
Devin FoleyandPaperclip 8ffc5748a2 fix(server): stop libc detection from reverse-resolving every socket (#16333)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - #15683 made new Codex agents default to Paperclip Runner on Linux,
which needs the host's glibc version
> - `localAgentRunnerTarget()` reads that version from
`process.report.getReport()`
> - Unless `excludeNetwork` is set, Node's diagnostic report resolves
the endpoints of every open socket with synchronous reverse DNS on the
main thread
> - `GET /adapters` calls it once per adapter on every request, so on a
host whose proxy address has no fast PTR answer, the whole server stops
responding
> - This pull request excludes network data from the report and detects
libc once per process
> - The benefit is that runner selection costs a few milliseconds once,
instead of blocking the server on every request

## Linked Issues or Issue Description

Regression from #15683.

**What happened?**
After #15683, a server running behind a reverse proxy stopped
responding. Requests, database replies, log output and health checks all
stalled for minutes. The Node main thread was idle on CPU but blocked in
a synchronous DNS read: reverse (PTR) lookups of the proxy's address,
each waiting for the resolver timeout.

**Expected behavior**
Detecting the C library must not block the event loop on DNS, and must
not repeat on every request.

**Steps to reproduce**
1. Run the server on Linux where the reverse DNS lookup of a connected
peer's address is slow (for example, a proxy address whose PTR lookup
times out).
2. Open the board, which polls `GET /adapters`.
3. The server stops answering. Each `getReport()` call reverse-resolves
every open socket synchronously.

Measured on Node 24.21 with one open TCP connection to such a peer:
`process.report.getReport()` took **9,774 ms** with network data and **4
ms** with `excludeNetwork`. A busy server has hundreds of open sockets.

**Paperclip version/commit**
`master` after #15683.

## What Changed

- `server/src/lib/agent-runner-platform.ts`:
- Generates the report with `process.report.excludeNetwork = true` and
restores the previous value in `finally`.
- Detects libc once per process and caches the result, because the C
library cannot change while the process runs. A failed report also
caches "unknown", so it is never retried per request.
  - Adds `resetLocalAgentRunnerTargetCacheForTests()`.
- Reads `excludeNetwork` through a narrow typed view, because the
installed Node type definitions do not declare it yet.
- New `server/src/__tests__/agent-runner-platform.test.ts`.
- `agent-runner-selection.test.ts` and
`dev-runner-native-binary.test.ts` reset the cache between cases,
because they change the mocked glibc version per case.

## Verification

- `pnpm exec vitest run src/__tests__/agent-runner-platform.test.ts
src/services/agent-runner-selection.test.ts
src/__tests__/dev-runner-native-binary.test.ts
src/services/local-ai-browser-login.test.ts` (in `server/`): 165 passed.
New tests:
- The report is generated with `excludeNetwork` set, and the previous
setting is restored.
  - Five calls generate one report.
- A failing report gives `libc: "unknown"` once and restores the
setting.
  - No report is generated off Linux.
- `pnpm typecheck` in `server/`: passed.
- Measured on Node 24.21 (above): 9,774 ms → 4 ms for one report with
one slow-PTR socket open.

## Risks

- Low risk. The detected glibc version is the same; only the network
section of the report is skipped, and nothing reads it.
- The cached result does not change until restart. The C library cannot
change while the process runs.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), 1M context, through Claude Code
with tool use (shell, file edits, test runs, live diagnosis of the
stalled process).

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [ ] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-10-14 16:48:05 -05:00
..