Files
PaperClipAI/packages
Devin FoleyandPaperclip 07150650c9 test(runner): drain reattachment writers before deleting state (#23673)
## Thinking Path

> - Paperclip manages agent work through durable Runner sessions.
> - Release images require Cloud readiness for their exact source
commit.
> - A reattachment test keeps a slow event backlog active during
controller recovery.
> - Its bounded close can return before queued journal writes finish.
> - The fixture then deletes the state directory and can fail with
`ENOTEMPTY`.
> - This pull request joins the fixture writers before it removes their
files.

## Linked Issues or Issue Description

**What happened?**

[Docker run
47193580475](https://github.com/paperclipai/paperclip/actions/runs/47193580475/attempts/1)
was cancelled after [Cloud readiness protocol lane
4/4](https://github.com/paperclipai/paperclip/actions/runs/47193580507/job/144565884014)
failed. The event-backlog reattachment test reported `ENOTEMPTY` while
removing its control-plane directory. A rerun passed on the same source
commit, without fixing the race.

**Expected behavior**

The fixture must finish all admitted writes and stop its child before it
deletes state, including when the transport close deadline expires.

**Steps to reproduce**

Run `runnerd-codex-transport-reattach-carried-commands.test.ts` with a
one-millisecond close budget for the event-backlog case. Before this
fix, the new cleanup assertion finds one accounting callback still
active.

**Paperclip version or commit**

Observed on `23ca89e3764377224bc43527bdfa547e9608f1db`. The fix starts
from `7e025ae65f9050030edf4d2cab006aa981569261`.

**Deployment mode**

Source checkout in GitHub Actions. Local reproduction uses macOS arm64,
Node 25.6.1, and the real Rust Runner with the hermetic fake Codex
fixture.

Searched open PRs and issues for `ENOTEMPTY`, carried commands, and
Runner teardown. No duplicate fix was found. Related earlier work:
#21161 and #21442.

## What Changed

- Retain all registered fixture authorities, including the detached
controller.
- Disable new upgrades, confirm the original child exited, stop
authorities, and drain admitted connection processing before deleting
state.
- Exercise an expired close budget in the existing backlog case. Assert
that accounting writes have finished before deletion.
- The fixture owns this cleanup. Runtime close behavior and its
deadlines do not change.

## Verification

- Red: the focused backlog test fails with `state cleanup must wait for
admitted event writes: expected 1 to be +0` before the teardown fix.
- Green: `pnpm exec vitest run
src/live/runnerd-codex-transport-reattach-carried-commands.test.ts` from
the Runner package: 11 passed, retries disabled.
- `pnpm exec tsc -p tsconfig.test.json --noEmit` from the Runner
package: passed.
- `git diff --check` and local secret/PII diff review: passed.
- `pnpm verify --explain`: exit 2. The conservative selector cannot
resolve this Runner test graph. Focused local checks passed; required PR
CI supplies the broader coverage.
- Tested file contents match PR head
`0a6b92e026ae0fdd684cd0e8e2ff7cf513732a02`.
- Final review: all 90 checks are clean, GitHub reports `CLEAN` /
`MERGEABLE`, and there are no unresolved review threads. The branch
includes current `master`.
- An initial local attempt could not run because debug binaries were not
built yet. Agent preflight completed before the red-green run.
- [Linux Runner Vitest lanes
1–6](https://github.com/paperclipai/paperclip/actions/runs/47222552156):
passed on PR head. Typecheck, build, Runner static checks, and support
suites also passed.
- [Greptile
review](https://github.com/paperclipai/paperclip/pull/23673#issuecomment-7394943956):
5/5 on PR head, no actionable findings or review threads. The
current-head check passed.
- [Server shard
14/20](https://github.com/paperclipai/paperclip/actions/runs/47222552156/job/144668670033)
was cancelled after its runner received a shutdown signal. This is
recorded runner loss, not an assertion failure. The repository started
attempt 2 automatically on the same PR head. The retry passed and the
full [PR CI
workflow](https://github.com/paperclipai/paperclip/actions/runs/47222552156/attempts/2)
completed successfully. Both Runner image builds, the macOS runtime
build, and all security scans also passed.

## Risks

Low risk. Only one test fixture changes. Teardown now waits for its
admitted writes instead of deleting their directory early. A stuck write
can fail the existing test timeout and preserve the state directory. No
schema, API, deployment, or runtime behavior changes. The code and
regression test describe the behavior; no documentation update is
needed.

## Model Used

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

## 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-03 15:12:47 -08:00
..
…