Files
PaperClipAI/server
Andrii VasylievandClaude d61877761a fix(docker): install lsof for listener ownership checks (#17770)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Paperclip can start and supervise local runtime services for a
workspace
> - `local-service-supervisor` finds the process that listens on a
service port with `lsof -nP -iTCP:<port> -sTCP:LISTEN -t`
> - The Docker image is based on `node:24-trixie-slim`, which does not
include `lsof`, and the Dockerfile does not install it
> - In the container, the lookup always fails and
`readLocalServicePortOwner` returns `null`
> - It also runs `ps -o command= -p <pid>` and `ps -o pgid= -p <pid>`
for its command and process-group checks, and the slim image has no `ps`
either
> - This pull request installs `lsof` and `procps` in the base stage of
the image
> - The benefit is that port-owner adoption, command matching and stop
checks have process evidence in Docker deployments too

## Linked Issues or Issue Description

No public issue exists for this. I searched open and closed issues and
pull requests for `lsof`, "listener" and changes to `Dockerfile`. I
found no related change.

**What happened?**

In the Docker image, `readLocalServicePortOwner` always returns `null`,
because `lsof` is not installed and the call fails with `ENOENT`, which
the function catches. Callers then act without listener evidence:
- `findLocalServiceRegistryRecordByRuntimeServiceId` removes a registry
record whose original PID is gone, even when another process of the
service still listens on the port.
- `adoptLocalServiceFromPortOwner` cannot adopt a running listener.
- The stop path (`targetIsGone`) treats the port as free when the target
PID is gone, even if a child process still listens on it.

The same applies to `ps`, which comes from `procps` on Debian:
`isLikelyMatchingCommand` catches the `ENOENT` and treats any live PID
as the recorded service, and `readLocalServiceProcessGroupId` returns
`null`, so `isLocalServiceProcessOwnedBy` cannot confirm group
ownership.

**Expected behavior**

The image contains the tools that the server calls at runtime. The
port-owner lookup returns the listening PID in Docker as it does on a
host with `lsof`.

**Steps to reproduce**

1. Run `docker run --rm node:24-trixie-slim sh -c 'command -v lsof ||
echo missing; command -v ps || echo missing'`. Both print `missing`.
2. The Dockerfile `base` stage installs `ca-certificates gosu curl gh
git wget ripgrep python3 tini` and no `lsof`. The `production` stage
starts from `base`.
3. In a container with `lsof` installed, start a listener on a port and
run `lsof -nP -iTCP:<port> -sTCP:LISTEN -t`. It prints the listener PID.

**Paperclip version or commit**

Seen on v2026.1023.0. The patch base is current `master` (`a52f622be8`).

**Deployment mode**

Docker image.

## What Changed

- Add `lsof` and `procps` to the `apt-get install` list in the `base`
stage of `Dockerfile`. The `production` stage starts from `base`.
- `container-init-reaping.test.ts` asserts that the `base` stage
installs both packages.

`procps` was suggested in review.

## Verification

- `node:24-trixie-slim` has no `lsof`. After `apt-get install lsof` in
that image, `lsof -nP -iTCP:43117 -sTCP:LISTEN -t` printed the PID of a
Node listener on port 43117.
- In `node:24-trixie-slim` with every package that the current `master`
Dockerfile installs (`base` and `production` stage apt lists), `ps` and
`lsof` are both missing and `procps` is not installed. After adding
`lsof procps`, `ps -o command= -p <pid>` and `ps -o pgid= -p <pid>` work
as the unprivileged `node` user.
- `npx vitest run src/__tests__/container-init-reaping.test.ts` in
`server`: 16 tests passed. With `procps` removed from the Dockerfile,
the new `procps` case fails.
- I did not build the full image locally, because the build includes the
Rust runner stages. The CI Docker jobs cover the build.

## Risks

- Low risk. Two small Debian packages in the base stage. The image grows
by the size of `lsof`, `procps` and their dependencies.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

AI-assisted with Claude Code and OpenAI Codex coding agents; exact model
versions are not listed.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [ ] 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 (none
needed: no documented behavior or setup changes)
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-12-05 02:25:43 -08:00
..