From 8b4b6aec87a42c7ccbc95c707aadb4cbea689e78 Mon Sep 17 00:00:00 2001 From: Dotta <34892728+cryppadotta@users.noreply.github.com> Date: Thu, 12 Nov 2026 18:19:32 -0600 Subject: [PATCH] test(chat): keep the Retry route's background nudge out of the board-message retry test (#21174) 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 chat-channel integration suite runs in 3 "General tests (chat)" CI shards on every PR > - "retries the saved board-message turn in a connected task after environment qualification failed before provider startup" failed on 4 unrelated PR branches in 48 hours > - Every failure is a foreign-key error when the test deletes its saved Retry: `heartbeat_runs_wakeup_request_id_agent_wakeup_requests_id_fk` > - `POST /issues/:id/retry` answers 202 and then calls `heartbeat.resumeTaskRetry` without awaiting it. When that nudge created a run before the test's cleanup, the delete failed > - The test drives dispatch itself (`resumeExecutionWaitComments`), so the background nudge only adds a race > - This pull request gives the test's route a heartbeat service whose nudge does nothing > - The benefit is that the chat shard stops failing at random on unrelated PRs ## Linked Issues or Issue Description **What happened?** `server/src/__tests__/chat-channels.integration.test.ts` "retries the saved board-message turn in a connected task after environment qualification failed before provider startup" failed with `update or delete on table "agent_wakeup_requests" violates foreign key constraint "heartbeat_runs_wakeup_request_id_agent_wakeup_requests_id_fk"` on PRs that did not touch chat or Retry code (for example codex/github-pat-without-cloud, fix/21017-workspace-source-lock-wait, fix/codex-internal-interrupt-recovery). **Expected behavior** The test passes every time. Its Retry dispatch happens only where the test starts it. **Steps to reproduce** Add a 300 ms wait at the start of the `denySource` cleanup (before the `agent_wakeup_requests` delete) and run the test. On master it fails 3 of 3 times with the CI error, because the route's background nudge creates a run first. **Paperclip version or commit** master at 4e932fd178 and later. **Deployment mode** CI server tests (embedded PostgreSQL). **Agent adapter(s) involved** N/A, CI test. ## What Changed - `server/src/__tests__/chat-channels.integration.test.ts`: while the test builds `issueRoutes`, `heartbeatService` returns the real service with a no-op `resumeTaskRetry`. The spy is restored right after the routes are built. The same pattern is used in `heartbeat-native-restart-suspension.test.ts`. - No product code changes. The nudge is only a latency optimization. Maintenance redelivers saved Retries (see the comment in `routes/issues.ts`). ## Verification - Forced race (300 ms wait before cleanup): master 0 of 3 pass with the CI error; this branch 3 of 3 pass. - Loop on this branch, no injection, 2 parallel loops on a loaded machine: 25 of 25 pass. - `npx vitest run src/__tests__/chat-channels.integration.test.ts -t "retries the saved board-message turn in a connected task after environment qualification failed"`. ## Risks - Low risk. Test-only change. The test still exercises the real Retry route and the real dispatch path that it drives explicitly. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, in Claude Code with tool use (shell, GitHub CLI, Vitest). ## 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 --- server/src/__tests__/chat-channels.integration.test.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/src/__tests__/chat-channels.integration.test.ts b/server/src/__tests__/chat-channels.integration.test.ts index cacb87a0d20..b8e2cb9fbd0 100644 --- a/server/src/__tests__/chat-channels.integration.test.ts +++ b/server/src/__tests__/chat-channels.integration.test.ts @@ -93,6 +93,7 @@ import { appendHeartbeatRunEvent } from "../services/heartbeat-run-events.js"; import { companySkillService } from "../services/company-skills.js"; import { companyObservability } from "@paperclipai/db"; import * as runIdentityModule from "../services/run-identity.js"; +import * as heartbeatModule from "../services/heartbeat.js"; import { chatGitHubRegistrations, chatGitHubReviews, chatGitHubConfigurations, toolCatalogEntries } from "@paperclipai/db"; import { AsyncLocalStorage } from "node:async_hooks"; import * as cloudRuntimeIdentity from "../services/cloud-runtime-identity.js"; @@ -66632,7 +66633,14 @@ describeEmbeddedPostgres("chat channel control-plane integration", () => { const app = express(); app.use(express.json()); app.use((req, _res, next) => { req.actor = boardActor(companyId); next(); }); - app.use("/api", issueRoutes(db, createStorageService().storage, { chatRunRetries: f.service })); + const actualHeartbeatService = heartbeatModule.heartbeatService; + const routeHeartbeat = vi.spyOn(heartbeatModule, "heartbeatService").mockImplementation((database, options) => + ({ ...actualHeartbeatService(database, options), resumeTaskRetry: async () => undefined })); + try { + app.use("/api", issueRoutes(db, createStorageService().storage, { chatRunRetries: f.service })); + } finally { + routeHeartbeat.mockRestore(); + } app.use(errorHandler); const denySource = async (apply: () => Promise, restore: () => Promise, stale = false) => { try {