Files
PaperClipAI/packages/paperclip-runner/runner
DottaandClaude Opus 5.5 03d88e4216 fix(runner): wait out a short-lived foreign orphan before refusing a lost runnerd's lineage proof (#23006)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Paperclip Runner stops a lost (killed) local runnerd's provider and
tool processes from runnerd's durable process lineage journal
(`paperclip-runnerd reap-lineage`)
> - The reap refuses its proof (`unattributed_orphan`) while a live
orphan (parent PID 1) of this user exists that started after the dead
runnerd's last sample. Ownership of such a process cannot be proven, so
this rule is deliberate
> - The reap refused at the first sight of such an orphan, even when
another program left it and it exited a moment later. On a busy host,
short-lived orphans of the same user are common
> - When the reap refuses, closing the session fails with
`NativeSessionCloseUnrecoverableError: provider_transport_failed: runner
did not durably suspend before checkpoint`, so recovery of a lost
runnerd fails for a reason that has nothing to do with that runnerd
> - This is the intermittent failure of the Runner test "stops a lost
runnerd's provider and escaped tool job from its lineage journal
(journal=true)" in Cloud readiness, which blocks Docker publishing and
staging deploys
> - This pull request makes the reap wait out unattributed orphans until
its deadline, and refuse only if one still lives then
> - The benefit is that a lost runnerd's cleanup is proven on a busy
host, and master's Cloud readiness stops failing on this test

## Linked Issues or Issue Description

**What happened?**

`verify / Verify Paperclip Runner (protocol (3/4))` in the Cloud
readiness workflow failed intermittently on master (for example commits
64bef50be0 and 3f1632c7b7) in `src/live/runnerd-codex-transport.test.ts`
> "stops a lost runnerd's provider and escaped tool job from its lineage
journal (journal=true)". The error was
`NativeSessionCloseUnrecoverableError: provider_transport_failed: runner
did not durably suspend before checkpoint` from `finishClose` in
`runnerd-codex-transport.ts`, with `proofWindowEnd:
"suspend_not_completed"`. The test passed on other attempts and locally.

**Expected behavior**

When a local runnerd is killed, close proves its provider and escaped
tool job stopped from the lineage journal and ends the session as a
crash stop. A process that another program starts and that exits on its
own does not make the proof fail.

**Steps to reproduce**

1. Run the test while short-lived orphan processes of the same user
start on the host, for example `( sleep 0.2 & )` every 0.5 s, with 14
busy loops of CPU load.
2. The reap reports
`{"verified":false,"reason":"unattributed_orphan","signalled":2,"remaining":[...]}`.
The remaining PIDs are the foreign orphans. The test's own provider and
tool job were already stopped.
3. Close throws the same error as CI.

Root cause: `reap_journals` in
`packages/paperclip-runner/runner/crates/runner-core/src/process_lineage/journal.rs`
returned `unattributed_orphan` immediately when a live unattributed
orphan was in the first clean process table read. In CI, other test
files in the same shard leave short-lived orphans of the same user (for
example a fake provider whose runnerd was killed). This is a product
race, not only a test timing issue: on a real host with several agents,
any short-lived orphan of the same user that starts in that window makes
the lost runnerd's recovery fail.

## What Changed

- `reap_journals`: an unattributed orphan no longer refuses the proof at
once. The reap re-reads the process table every 10 ms and refuses with
`unattributed_orphan` only if such an orphan still lives at its
deadline. It still never signals an unattributed process.
- A table read is per process and not atomic, so a parent can exit
during a read and hide its re-parented child. Three rules close that:
- A process whose parent is not alive in the same read counts as an
orphan.
- The reap keeps every unattributed orphan and each process seen under
it (by parent, group or session; PID and start time; never signalled)
across reads, and waits until all of them are gone. It uses the existing
`LineageState` walk, seeded through a new `LineageState::track_roots`.
- Every proof needs `CLEAN_READS_REQUIRED_FOR_A_PROOF` (2) consecutive
clean reads (about 10 ms more).
- The reap reads the table through an injectable reader.
Controlled-table tests cover each rule, and each test fails when its
rule is removed:
`reaping_counts_a_process_whose_parent_exited_during_the_first_read`,
`reaping_keeps_an_orphans_descendants_across_reads`,
`reaping_needs_consecutive_clean_reads_before_a_proof`.
`reaping_follows_an_orphan_tree_through_successive_torn_reads` covers an
orphan A whose child B forks C and exits.
-
`reaping_keeps_a_process_in_an_orphans_group_or_session_after_the_orphan_exits`
fails without group and session membership.
- The `reap_journals` doc describes these rules. The journal tests moved
to `process_lineage/journal/tests.rs`.
- New Rust test
`reaping_waits_out_a_short_lived_orphan_it_cannot_attribute`: an orphan
that lives 0.5 s during the reap. The proof holds, and the orphan is not
signalled.
- `reaping_refuses_an_orphan_born_after_the_last_sample` uses a 1 s
deadline instead of 5 s, because the refusal now waits until the
deadline.
- `runnerd-codex-transport.test.ts`: the lost-runnerd test gets a
`foreignOrphan=true` case. After runnerd is killed (so its journal is
final), the test starts a 1.5 s orphan of the same user. This forces the
CI ordering deterministically. The test asserts the same things as
before: verified report, provider and tool job stopped, no queued
suspend. It also asserts that the orphan exited on its own before close
returned.
- No change to what the reap proves or signals, and no change to the
TypeScript close path.

## Verification

- Deterministic reproduction, before the fix (master `journal.rs`):
`foreignOrphan=true` fails with the CI signature
(`NativeSessionCloseUnrecoverableError ... runner did not durably
suspend before checkpoint`, reap reason `unattributed_orphan`). After
the fix: passes.
- Rust red/green: `cargo test --release -p paperclip-runner-core --lib
reaping_waits_out` fails on master's reap loop and passes with the fix.
All 16 `process_lineage` lib tests pass.
- Repeated runs on macOS (18 cores), 14 busy loops of CPU load plus a
short-lived foreign orphan every 0.5 s, `vitest run
src/live/runnerd-codex-transport.test.ts -t "lineage journal"`, 30 runs
each:
- Before the fix: 0/30 runs passed. The original `journal=true` case
failed in 8 of 30 runs with the CI signature.
- After the fix: 29/30 and 25/30 runs passed. Every remaining failure
ran to the 5 s deadline with only macOS launchd agents left (Spotlight
`mdworker_shared`, `CommCenter`, `IMTransferAgent`). Those are
long-lived processes with parent PID 1 that the reap cannot attribute,
so the refusal is correct. Linux CI hosts do not start such agents.
- `cargo fmt --check` passes.
`tests/runner-e2e/source-sdk-public-inputs.json` is unchanged (checked
with the sync script).

## Risks

- A close that must refuse because of a long-lived unattributed orphan
now takes until the reap deadline (about 4.5 s) instead of returning at
once. The outcome is the same fail-closed result.
- On macOS, launchd agents (for example Spotlight workers) have parent
PID 1 and can still make the reap refuse when one starts during the
proof window. That is the existing deliberate rule and is not changed
here.
- Low risk otherwise. The reap still never signals a process it cannot
attribute.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use
(shell, file edits) and extended reasoning.

## 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
- [x] I will address all Greptile and reviewer comments before
requesting merge

Refs #20849

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 19:39:54 -06:00
..