Files
PaperClipAI/packages
Devin FoleyandPaperclip bc548a736a test: fix CLI bind races and SSH fixture input (#23830)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - CI runs fixtures for real CLI servers and SSH commands.
> - The CLI fixture can lose its fallback port before the server binds
it.
> - The SSH login-profile fixture must supply the command payload on
stdin.
> - These fixture failures stop CI before it can verify the application
behavior.
> - This pull request adds bounded CLI bind retries and supplies the SSH
stdin payload.
> - The fixtures retain their startup deadlines, child identity checks,
and behavior assertions.

## Linked Issues or Issue Description

**What happened?**

[Source verification 47462717613, attempt
2](https://github.com/paperclipai/paperclip/actions/runs/47462717613/job/145492578739)
failed in `cli/src/__tests__/company-import-export-e2e.test.ts`. The
fixture occupied port 41511. The server selected 41512, then exited with
`listen EADDRINUSE: address already in use 127.0.0.1:41512`. The suite
failed before health readiness. The other 354 files passed, with 3,971
tests passed and one skipped. This cancelled [image run
47462717565](https://github.com/paperclipai/paperclip/actions/runs/47462717565).

The SSH login-profile fixture also ran the command bootstrap without its
stdin payload. It exited with code 125 before it could check profile
behavior. [CI run 47464397195 on
`ef3250d`](https://github.com/paperclipai/paperclip/actions/runs/47464397195/job/145497678930)
failed on that test. The CLI shard passed in the same run.

**Expected behavior**

A fixture can start a fresh attempt after it loses a listener bind race
to another local process. A configuration error, signal exit, health
timeout, or test assertion must still fail. Runtime discovery must use
the child PID and actual fallback port. The SSH fixture must supply
`stdinPrefix` to execute the generated remote command.

**Steps to reproduce**

The failed source was master `dfe392dada69838da3d7c33a0ef00d7e4cfc60f3`,
in local trusted mode. Reserve a loopback port, then make a child
process bind that port. The new socket regression test does this without
timing assumptions. Without the retry policy, the first collision aborts
startup.

For the SSH failure, run `PAPERCLIP_VITEST_RETRY=0 pnpm exec vitest run
packages/adapter-utils/src/ssh-fixture.test.ts -t 'survives a bash-only
login profile' --maxWorkers=1` on a host with `dash`. Before the stdin
fix, it exits 125 with empty output.

Refs #23813: that separate database teardown fix is already in this
master revision. This failure is a listener bind collision.

## What Changed

- Retry only a child exit with code 1 and the listener `EADDRINUSE`
diagnostic on stderr. Limit startup to three attempts.
- Release the old port reservation and start a fresh child with a fresh
requested-port reservation on each attempt.
- Share the original 90-second startup deadline across attempts. Keep
the PID-matched runtime health check and the assertion that the server
used a fallback port.
- Recognize a child that has already exited by signal, so cleanup does
not wait for a past exit event.
- Add real-socket regression tests for recovery, failure limits, and
other startup errors.
- Pass `target.stdinPrefix` to the SSH login-profile fixture process, as
required by the existing transport contract.

## Verification

- CLI red: with the policy set to one attempt, the socket recovery test
failed with the same `EADDRINUSE` diagnostic as CI. The bounded-attempt
test also failed.
- CLI green: `PAPERCLIP_VITEST_RETRY=0 pnpm exec vitest run
cli/src/__tests__/server-startup.test.ts
cli/src/__tests__/company-import-export-e2e.test.ts --maxWorkers=1`
passed both suites and all five tests after rebase. CLI typecheck
passed. These files have not changed since that verification.
- SSH red: the targeted login-profile test failed locally with exit 125
and retries disabled, matching the CI failure on `ef3250d`.
- SSH green: `PAPERCLIP_VITEST_RETRY=0 pnpm exec vitest run
packages/adapter-utils/src/ssh-fixture.test.ts --maxWorkers=1` passed 26
tests, with two skipped. `pnpm exec tsc --noEmit -p
packages/adapter-utils/tsconfig.json` passed.
- The test budget check passed for all three changed test files. `git
diff --check` passed. Final head:
`4b0a5e4b96702829454b101b57be313b8908a63e`.
- The CLI dependency-selection plan retained 2,347 of 3,084 test files
on the previous head. Required CI will verify the final head with the
SSH correction. No full local suite was run.
- [Greptile rated final head `4b0a5e4b96702829454b101b57be313b8908a63e`
5/5](https://github.com/paperclipai/paperclip/pull/23830#issuecomment-7429780977),
with no actionable findings or review threads. Final check results: 76
passed, six skipped, none pending or failed. The [final CI
workflow](https://github.com/paperclipai/paperclip/actions/runs/47465088910)
passed, and GitHub reports no merge conflicts.
- Operational recovery: [image run
47463279495](https://github.com/paperclipai/paperclip/actions/runs/47463279495/job/145501215693)
passed exact-source verification and published the AMD64/ARM64 manifest
for master `6a5dfc028831831756bea006df4e399e31cdf281`. Tag:
`ghcr.io/paperclipai/paperclip:sha-6a5dfc0`. Digest:
`sha256:44576ab5bc386903dd592ed1f3e7277f60e0cd6c696590996d02330be2fbdbff`.
All publication gates remained in place. This establishes publication
recovery; these fixture changes address recurrence and still need to
merge.

## Risks

- Low risk. This changes test fixture startup only.
- A persistent collision still fails after three attempts. Other
failures retain their diagnostics and do not retry. Each recovered
collision emits a warning in the test log.
- Production listener selection is unchanged. This PR does not add a
production server restart policy.
- No documentation change is needed because the application contract
does not change.

## Model Used

- OpenAI `gpt-6.1-sol`, through the Codex harness in T3 Code, with xhigh
reasoning effort and shell tools. The context window size is not
exposed.

## 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
- [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

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-12-04 20:25:05 -06:00
..