From 5d0b27acca7a5dbae1db666df25237d174b52449 Mon Sep 17 00:00:00 2001 From: Dotta <34892728+cryppadotta@users.noreply.github.com> Date: Fri, 13 Nov 2026 20:07:31 -0600 Subject: [PATCH] fix(run-events): watch both late appends for rejection as soon as they start (#21536) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The server stores each run event through `appendHeartbeatRunEvent` and `appendHeartbeatRunEventBatch` > - Pull request #21511 added a test that deletes a run while two appends wait for its row lock > - Both appends must fail, but the test attached the rejection check of the second append only after it awaited the first > - When the second append failed first, its rejection had no handler, and Vitest failed the whole shard with one unhandled error > - This pull request attaches both rejection checks when the appends start > - The benefit is that server test shards on master and on unrelated pull requests pass again ## Linked Issues or Issue Description Refs #21511 **What happened?** Server test shards failed on master and on unrelated pull requests. Every test passed. Vitest reported one unhandled error: `Error: heartbeat_run_event_binding_mismatch`, from `server/src/__tests__/heartbeat-run-event-atomic-append.test.ts`. **Expected behavior** The test awaits both expected failures. No rejection stays without a handler. **Steps to reproduce** Run the general server test shard that contains `heartbeat-run-event-atomic-append.test.ts` on master at `cefef8f11d`. Examples: master "verify / General tests (server (1/10))", pull request #21443 "ci / General tests (server (9/12))", pull request #21505 "ci / General tests (server (1/12))". ## What Changed - In the test "waits for Stop on the run row and appends after it, and fails without rows after a run deletion", the two `expect(...).rejects` checks are now created immediately after the two appends start. The test awaits them after it releases the deletion. - No product code changed. The product code rejects correctly; the test left one rejection without a handler for a short time. ## Verification - `pnpm --filter @paperclipai/server exec vitest run src/__tests__/heartbeat-run-event-atomic-append.test.ts`: 25 of 25 tests pass, three runs in a row, no unhandled error. - The failure before this change is the master shard named above. It depends on which append rejects first, so I did not get a local reproduction on demand. ## Risks Low risk. The change is in one test. The assertions are the same. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used - Claude Fable 5.2 (`claude-fable-5-2`), Claude Code, with tool use and code execution. ## 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 Fable 5.2 --- .../src/__tests__/heartbeat-run-event-atomic-append.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/src/__tests__/heartbeat-run-event-atomic-append.test.ts b/server/src/__tests__/heartbeat-run-event-atomic-append.test.ts index e7da91ca4b7..b805d99e9a6 100644 --- a/server/src/__tests__/heartbeat-run-event-atomic-append.test.ts +++ b/server/src/__tests__/heartbeat-run-event-atomic-append.test.ts @@ -322,11 +322,13 @@ describeEmbeddedPostgres("atomic ordinary run events", () => { }); const late = appendHeartbeatRunEventBatch(db, [4, 5].map(sourceSeq => nativeEvent(runId, sourceSeq))); const lateSingle = appendHeartbeatRunEvent(db, nativeEvent(runId, 4)); + const lateRejected = expect(late).rejects.toThrow("heartbeat_run_event_binding_mismatch"); + const lateSingleRejected = expect(lateSingle).rejects.toThrow("heartbeat_run_event_binding_mismatch"); const lateSettledWhileHeld = await settlesWhileHeld(late); await deletion.release(); expect(lateSettledWhileHeld).toBe(false); - await expect(late).rejects.toThrow("heartbeat_run_event_binding_mismatch"); - await expect(lateSingle).rejects.toThrow("heartbeat_run_event_binding_mismatch"); + await lateRejected; + await lateSingleRejected; expect(await readEvents(runId)).toEqual([]); });