mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 09:39:53 +01:00
test(heartbeat): let a slow wait attempt finish instead of failing at its deadline (#22880)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Master deploys to staging only after the "Cloud readiness" workflow passes > - One test in the deferred receipt suite failed on a loaded 8-core CI runner, so the Docker image build was cancelled and every merge was held > - The test does not find a product defect. Its wait helper rejects at its deadline while an attempt that would pass is still running > - This pull request makes the deadline stop further retries, but lets the attempt in flight decide the result > - The benefit is that master deploys again, and the suite fails only when the expected state is really absent ## Linked Issues or Issue Description **What happened?** The "Cloud readiness" run for master failed two times in "General tests (server (1/10))". The failing test was `deferred-execution-receipt-work.test.ts > dispatches task Retry past a repeatedly invalidated backlog into real process output`. The error was "Expectation did not complete before its deadline", with no assertion error. The same test also failed on master before #22865 (an earlier readiness run on 2026-11-25 01:12Z), so #22865 did not cause it. **What did you expect?** The test passes when the Retry run starts and succeeds, also on a slow runner. **Steps to reproduce** Make `drainActiveRunExecutions` about 1 s slower, as on the loaded runner (see Verification). The test then fails every time with the same message. **Root cause** `waitForReal` set a wall-clock deadline and rejected when it fired, also while an attempt was still awaiting. Each attempt calls `drainActiveRunExecutions`, which waits for the real child process and its run writes. On the CI runner this test takes 21 to 27 s (2 s alone on a fast machine), so one drain can take longer than a deadline. The tightest deadline is the 1 s default in `finish()`. A deadline that fires during the first attempt rejects with no `lastError`, which is the exact CI message. The failed runs stopped at 20.9 s, 21.9 s and 23.0 s, and that is where `finish()` runs in a 26 to 27 s passing run. ## What Changed - `server/src/__tests__/deferred-execution-receipt-work.test.ts`: in `waitForReal`, the deadline marks the wait as expired. If no attempt is running, it rejects as before. If an attempt is running, that attempt decides: a pass resolves, a failure rejects with its real assertion error. No deadline, assertion or test step changed. ## Verification - Red: a local experiment (not committed) made `drainActiveRunExecutions` 1.1 s slower in this test. Before the fix: 3 of 3 runs failed with "Expectation did not complete before its deadline" at the helper deadline line. After the fix: 5 of 5 runs passed (14.5 to 14.9 s). - Under CPU throttling (`taskpolicy -b` with busy loops), one attempt's drain took 19.6 s and failed the 15 s wait before the fix. This shows the same slow-attempt failure at the other deadlines. - Without the experiment: the full test file passes, and the test passes alone (about 2 s). - The readiness shard command `pnpm test:run:general -- --group general-server-without-chat-or-native-runner --shard-index 0 --shard-count 10` with 7 workers passed this test locally. Results are in the PR comments. - CI supplies the 8-core runner coverage. ## Risks - Low risk. The change is test-only. A wait now can last one attempt longer than its deadline. The 90 s test timeout still bounds an attempt that never returns. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use and code execution in Claude Code. ## 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>
This commit is contained in:
1 parent
aeafc6a190
commit
06c184a92b
1 file changed
+29
-4
@@ -32,21 +32,46 @@ vi.setConfig({ testTimeout: 90_000 });
|
||||
// and actual child processes on wall time until an explicit idle deadline step.
|
||||
function waitForReal(assertion: () => unknown | Promise<unknown>, { timeout = 1000 } = {}) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
let settled = false, lastError: unknown;
|
||||
let settled = false, expired = false, attempting = false, lastError: unknown;
|
||||
let retry: ReturnType<typeof realTimeout> | undefined;
|
||||
const deadline = realTimeout(() => finish(lastError ?? new Error("Expectation did not complete before its deadline")), timeout);
|
||||
const deadline = realTimeout(() => {
|
||||
expired = true;
|
||||
if (!attempting) finish(lastError ?? new Error("Expectation did not complete before its deadline"));
|
||||
}, timeout);
|
||||
function finish(error?: unknown) {
|
||||
if (settled) return;
|
||||
settled = true; clearRealTimeout(deadline); if (retry) clearRealTimeout(retry);
|
||||
if (error) reject(error); else resolve();
|
||||
}
|
||||
async function attempt() {
|
||||
try { await assertion(); finish(); }
|
||||
catch (error) { lastError = error; if (!settled) retry = realTimeout(attempt, 50); }
|
||||
attempting = true;
|
||||
try { await assertion(); attempting = false; finish(); }
|
||||
catch (error) {
|
||||
attempting = false; lastError = error;
|
||||
if (expired) finish(error); else if (!settled) retry = realTimeout(attempt, 50);
|
||||
}
|
||||
}
|
||||
void attempt();
|
||||
});
|
||||
}
|
||||
describe("waitForReal", () => {
|
||||
const later = (ms: number) => new Promise(resolve => realTimeout(resolve, ms));
|
||||
it("resolves an attempt that passes after its deadline", async () => {
|
||||
await expect(waitForReal(() => later(60), { timeout: 10 })).resolves.toBeUndefined();
|
||||
});
|
||||
it("rejects with the error of an attempt that fails after its deadline", async () => {
|
||||
const failure = new Error("still missing");
|
||||
await expect(waitForReal(async () => { await later(60); throw failure; }, { timeout: 10 })).rejects.toBe(failure);
|
||||
});
|
||||
it("stops retrying a failing assertion at its deadline", async () => {
|
||||
let attempts = 0;
|
||||
await expect(waitForReal(() => { attempts++; throw new Error("absent"); }, { timeout: 120 })).rejects.toThrow("absent");
|
||||
const settled = attempts;
|
||||
await later(150);
|
||||
expect(settled).toBeGreaterThan(1);
|
||||
expect(attempts).toBe(settled);
|
||||
});
|
||||
});
|
||||
describe("deferred receipt durable dispatch", () => {
|
||||
let temporary: Awaited<ReturnType<typeof startEmbeddedPostgresTestDatabase>> | undefined;
|
||||
let db: ReturnType<typeof createDb>;
|
||||
|
||||
Reference in new issue
Block a user