Files
PaperClipAI/tests
DottaandClaude Opus 5.5 3e869c6f08 test(restart-chaos): quiet period before the end-of-wave grade, explicit swap moments, request records and release attribution (#21215)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The restart-chaos harness grades every task at the end of a
release-swap wave, locally (RS1) and on a hosted staging instance
(hosted mode)
> - The first hosted 3-release run graded 79 / 80, and the one failure
was a harness artefact: the drain declared quiet 20 s after a parent's
run ended, before the product's children-completed wake created its
continuation, so the task read as "nothing pending" and cleanup then
cancelled the continuation
> - The same run showed three more reporting gaps: per-turn product
notices counted as duplicated comments, failed requests could not be
broken down because request records stayed in memory (and the API count
included the health probes), and the per-swap table charged every failed
run to the last swap before it
> - Separately, the local swap timeline marked the start of a swap with
`fault_started` carrying `"signal":"SIGTERM"`, while the outgoing
server's real SIGTERM was `fault_server_down`; that has led to wrong
conclusions twice
> - This pull request fixes the drain rule, the comment count, the
request records, the release attribution and the swap timeline
> - The benefit is that the one number and the per-swap table mean what
they say

## Linked Issues or Issue Description

Refs #21153
Refs #21126

**Describe the bug**
1. A task whose continuation is created after the drain declares quiet
is graded `nothing pending`, and cleanup cancels the continuation.
2. "Prepared <document> for this response." notices, one per turn, count
as duplicated agent comments.
3. Request failures cannot be broken down after the run, and the API
continuity count includes health probes.
4. A failed run is attributed to the last swap before it, however long
after.
5. `fault_started` carries `"signal":"SIGTERM"` for an overlap swap,
though it marks the swap request; the outgoing SIGTERM is a different
event.

**Steps to reproduce**
Run a hosted or local release-swap wave with parent tasks whose subtasks
finish near the end of the wave.

**Expected behavior**
The grade waits for continuations, notices are informational, request
records are saved, failed runs are attributed to a release only when
live at it or soon after, and the timeline names each swap moment.

## What Changed

- `release-swap-grade.ts`: shared `drainState` (quiet only when nothing
is progressing and no run was created or finished for 90 s,
`QUIET_PERIOD_MS`); `failedAtSwap` / `swapForFailedRun` /
`failedOutsideSwaps` (a failed run counts at a swap if it was live at
the outgoing SIGTERM or failed within 15 minutes of it,
`RELEASE_FAILURE_WINDOW_MS`, and at most one swap); `isAutoNotice`; the
summary lists failed runs outside any release window and the notice
repeats as information.
- `release-swap-finish.ts` (local RS1): uses `drainState` and the new
attribution; the duplicate-comment query separates the notice.
- `hosted-grade.ts`: uses `drainState` (`--hosted-quiet-seconds`,
default 90); reads runs, tasks and task views again immediately before
grading; breaks request failures down by status and by inside/outside
the release windows.
- `hosted-api.ts`, `hosted-main.ts`: every request record carries kind
(health or API) and a path class with ids replaced; `requests.jsonl` is
written to the results directory; API continuity no longer includes
health probes.
- `hosted-readers.ts`: duplicated agent comments and notice repeats are
returned separately.
- `release-swap-driver.ts`, `release-swap-moments.ts` (new): the
timeline records `swap_incoming_spawned`, `swap_incoming_ready`,
`swap_traffic_switched`, `swap_outgoing_sigterm` and
`swap_outgoing_exited`; the summary prints the five times per swap and,
for every run started during the swap, the two moments it started
between and which server started it; `release-swap.json` carries both.
- `supervisor.ts` (same line count, still 1,000 lines): `fault_started`
for an overlap swap carries `marks: "swap_requested"` instead of a
signal. No test reads that signal; `fault_server_down` stays.
- `README.md`: documents the quiet period, attribution window, notice
rule, request records and swap moments.

## Verification

- `node server/node_modules/vitest/vitest.mjs run --config
tests/restart-chaos/vitest.config.ts` on the hosted, release-swap and
triggers test files: 105 tests pass across 12 files.
- Red/green for the drain race (`hosted-drain.test.ts`): a parent's run
ends, a children-completed continuation is created 20 s later and
succeeds; with the old rule (quiet period 0) the task grades
`still_working`/not by the continuation, with the new rule it grades
`pass` after the continuation ends.
- New tests for the notice filter, `pathClass` and the request
breakdown, the 15-minute attribution, and the five swap moments (both
the timeline events from the driver and the summary placement of runs
between moments, with the starting server).
- `node server/node_modules/typescript/bin/tsc -p
tests/restart-chaos/tsconfig.json`: clean.

## Risks

- Low risk: harness-only. The end-of-wave grade waits up to 90 s longer
after the last run change, within the existing drain cap.
- Per-swap failed-run counts change meaning: runs that failed more than
15 minutes after a stop and were not live at it move to the "failed
outside a release window" line.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, used through Claude
Code with tool use (shell, file edits). Default context window; no
extended thinking mode.

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

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 17:45:08 -06:00
..