Files
PaperClipAI/tests
DottaandClaude Opus 5.5 30d99f4e32 test(restart-chaos): add time faults (TM1-TM3): freeze, sleep with aged rows, aged outage (#20458)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - The restart chaos harness (`tests/restart-chaos/`) tests if agent
tasks survive control-plane restarts.
> - Each wave runs for minutes on a fresh instance. Nothing time-bound
ever expires during a wave.
> - Production failures on 2026-11-09 were about time: an OAuth refresh
after more than 1 h made pending approvals invalid (#20340), and a
timeout used the wrong window (#20330).
> - This pull request adds a fourth fault family, time faults (TM1–TM3).
The faults make leases, deadlines and waits expire during a run or
across a restart. They do not change product code.
> - The benefit is that waves now find failures that occur only when
time passes. The first waves found one: a run whose turn completes after
a host sleep fails, and the task needs Retry.

## Linked Issues or Issue Description

Refs #20340
Refs #20330

**What is the problem?**
The chaos harness never moves the clock, so it cannot find failures
where a lease, a deadline or a pending wait expires.

**What is the solution?**
Add three time faults. Each one makes stored deadlines lapse in a way
that a real host sees: a process pause, a host sleep, or a long outage.

**Why is it needed?**
Two days of chaos testing did not find the failures of #20340 and
#20330, because no wave lasted long enough for a deadline to pass.

## What Changed

- Add `TM1`, `TM2` and `TM3` to `--faults` (`time-faults.ts`,
`time-faults-config.ts`):
- **TM1 freeze**: send `SIGSTOP` to the server process only, for 95–150
s, then send `SIGCONT`. The runner and Postgres continue. The pause is
longer than the controller-instance lease (90 s) and the
execution-control deadline (60 s).
- **TM2 sleep**: send `SIGSTOP` to the server and all of its
descendants. While they are stopped, move every database time back by
the age. Then send `SIGCONT`. This is a stand-in for a laptop sleep.
- **TM3 aged outage**: send `SIGKILL` to the server tree (as K1). While
it is down, move every database time back by the age. Then start a
replacement. With `--workloads G1 --triggers approval`, an approval
stays pending for a day across a restart.
- Add `--time-age-hours` (1–72, default 26). TM faults run only with
`--env local`, and not with storms, crash points or K14.
- Aging is one transaction. It moves every `timestamp` column, and every
time inside a `jsonb` column (ISO strings in their own format, and epoch
milliseconds in the wave's window), back by the same interval. Triggers
are off for the shift. Copies of a time in JSON (for example the comment
`updatedAt` in a continuation receipt) still match their columns. The
first wave showed that a shift of the columns only causes false
failures.
- The identity, state and time columns of the time-bound tables are
written before the shift to `<wave>/time-faults/<faultId>.json`.
Per-table counts go to the fault receipt (`timeFault`) and the timeline
(`time_fault_aged`).
- The observer and grader read through `TimeShiftedApi`. It adds the age
back to each time that a shift moved, so R4, R5, U1–U4 and the speed
budgets use real time.
- Make small additions to the registries: `types.ts` (fault kinds,
receipt field, option), `config.ts`, `scheduler.ts` (a seeded freeze
length only for TM tasks, so the plans of existing seeds do not change),
`supervisor.ts` (the freeze and aging hooks), `main.ts` (one line for
the API) and the README.

## Verification

- `pnpm exec vitest run --config tests/restart-chaos/vitest.config.ts`:
30 files, 368 tests pass. The new tests are:
- `time-faults.test.ts`: option parsing, freeze order, Postgres
exclusion, statement generation, and reading times back at their real
time.
- `time-faults-db.test.ts`: aging runs on real embedded Postgres. The
test checks that trigger rewrites are suppressed, that JSON copies match
their columns, that text columns do not change, that the evidence file
is written, and that an age the wave nearly outlived is refused.
- `node scripts/typecheck-test-projects.mjs tests/restart-chaos` passes.
- Live waves (local, codex), each run from a separate worktree and one
wave per slot:

| Wave | Scenario | Result |
| --- | --- | --- |
| `w-20261110T031929-s301` (A1,C1 × TM1–TM3) | First run, before JSON
aging | t01: TM1 missed, because A1 finished first. t02: pass. t03 (C1):
its turn completed after TM2 and failed with
`native_session_lease_lost`; a follow-up comment woke a new run. After
TM3, that run failed with `continuation_user_authorization_missing` and
needed Retry. That second failure was a harness artifact: the receipt
kept the comment's `updatedAt` in JSON, which the first version did not
shift. JSON aging fixes it. |
| `w-20261110T041910-s303` (B5 × TM1–TM3) | Freeze, sleep, aged outage |
t01 and t02 crossed TM1, then TM2. Both turns completed after the thaw
and failed with `native_session_lease_lost`, so both needed Retry (R3).
This is a **product failure**; see below. t03 (TM3, 26 h aged outage):
**pass**, with no Retry. |
| `w-20261110T050125-s302` (G1 × TM3, `--triggers approval`) | Aged
wait: an approval pending for 26 h across a restart | **Pass** (2/2).
Both approvals were still pending after the restart and the board
decided after the fault: t01 rejected, so the task is cancelled; t02
approved, so it is done with exactly one subtask. No Retry; U1–U4 pass.
|
| `w-20261110T051535-s304` (B5, TM2 with `--time-age-hours 1`, then TM1;
one task at a time) | Attribute the failure | t01 (TM2 sleep, only 1 h):
its turn completed after the thaw, then failed with
`native_session_lease_lost`, so the task needed Retry. This reproduces
the product failure. t02 (TM1 alone, 113 s server-only freeze):
**pass**. The failure follows the database clock jump, not the pause. |

**Product failure found (not fixed in this PR).** A local native run
whose host sleeps longer than the 20-minute execution lease loses its
completed work. After the wake, the provider finishes the turn and the
brief is saved. Then result acceptance (`native-session-executor.ts`,
the transaction at about line 12031) requires
`native_run_finalizations.lease_expires_at > clock_timestamp()`. The
database clock has moved on, so the run fails with
`native_session_lease_lost`, and the task shows "Couldn't finish this
attempt … Retry". No other boot claimed the lease: the owner, attempt
and controller identity are unchanged, and the server's monotonic
deadline did not expire. The lease is fenced by wall-clock expiry alone.
A safe fix changes lease fencing semantics, which is a
heartbeat-boundary decision, so I report it here rather than include a
fix in this harness PR. Reproduce with `--workloads B5 --faults TM2`
(`--time-age-hours 1` is enough; see `w-20261110T051535-s304`).

## Risks

- Harness-only change; no product code changes. Waves that do not use TM
faults are unchanged. `TimeShiftedApi` returns responses unchanged when
no shift was applied.
- `SIGSTOP` goes only to the wave server's own process tree. The tree is
found from the server PID, and Postgres is excluded. Every frozen
process gets `SIGCONT` in a `finally` block and in a process `exit`
hook.
- Aging is a model: the database becomes what it would be if everything
happened the age earlier. Times outside Postgres (in-memory timers,
runner state files), times inside `text` columns, and HMACs over a time
are not moved. The README lists these limits. Agent JWT expiry is not
covered: native runs mint a token for each tool call.

## Model Used

- Anthropic Claude, model ID `claude-opus-5-5`, used through Claude Code
with tool use (shell, file edits) and extended thinking.

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

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 23:44:52 -06:00
..