fix(agents): stabilize flaky API tests — readLiveRunsQueryInt NaN guard + annotation wake determinism #187

Merged
andrei merged 2 commits from feature/claude-fix-flaky-issue-list-limit into master 2026-07-05 11:38:12 +00:00
Owner

Thinking Path

  • Paperclip — платформа для управления AI-агентами, которые ведут задачи компании (issues, checkout, heartbeat)
  • Подсистема: серверные vitest-тесты Agents API (server/src/__tests__/)
  • Проблема: 2 flaky-теста в Agents CI / API Tests периодически падали под mock-isolation и в race по времени пробуждения ассайни
  • Без фикса CI периодически краснеет без реальной регрессии, что маскирует настоящие баги и тратит ресурсы на перезапуски
  • Этот PR добавляет defensive guard против NaN в readLiveRunsQueryInt и делает детерминированным тест wake-уведомления по комментарию аннотации
  • Польза: стабильный зелёный CI для Agents API Tests без flaky перезапусков

Linked Issues or Issue Description

Переоткрытие вместо закрытого #172 (flaky-тесты Agents CI / API Tests, тот же корень проблемы).

What Changed

  • readLiveRunsQueryInt: заменён Math.min(undefined - max, parsed) (даёт NaN под mock-isolation) на defensive Number.isFinite(max) guard.
  • Тест wake-уведомления по комментарию аннотации: user-comment на annotation теперь детерминированно будит assignee через queueAnnotationCommentWakeup (fire-and-forget после ответа), тест обновлён на expect + vi.waitFor + mockClear.

Verification

  • pnpm exec vitest run для затронутых файлов: guard-тест 3/3, annotation wake-тест 6/6 в двух последовательных прогонах (детерминированность подтверждена повтором).
  • pnpm typecheck (pre-push) — 0 ошибок.
  • Известный отдельный infra-timing flake (costs-DB) не относится к этому PR, не устраняется в его рамках.

Risks

Низкий риск: изменения ограничены defensive guard и детерминизацией существующего теста, поведение production-кода не меняется вне обработки edge-case NaN.

Model Used

Claude (claude-sonnet-4-6), Claude Code CLI, tool use (Bash/Edit/Read), без extended thinking режима.

Checklist

  • I have included a thinking path that traces from project context to this change
  • I have specified the model used (with version and capability details)
  • I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work
  • Я поискал похожие PR и подтверждаю, что дубликатов нет
  • I have either (a) linked existing issues with Fixes: # / Closes # / Refs # OR (b) described the issue in-PR following the relevant issue template
  • I have not referenced internal/instance-local Paperclip issues or links (only public GitHub #NNN / github.com/paperclipai/paperclip URLs)
  • My branch name describes the change and contains no internal Paperclip ticket id or instance-derived details
  • I have run tests locally and they pass
  • I have added or updated tests where applicable
  • I have updated relevant documentation to reflect my changes
  • 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
  • I will address all Greptile and reviewer comments before requesting merge
## Thinking Path > - Paperclip — платформа для управления AI-агентами, которые ведут задачи компании (issues, checkout, heartbeat) > - Подсистема: серверные vitest-тесты Agents API (`server/src/__tests__/`) > - Проблема: 2 flaky-теста в Agents CI / API Tests периодически падали под mock-isolation и в race по времени пробуждения ассайни > - Без фикса CI периодически краснеет без реальной регрессии, что маскирует настоящие баги и тратит ресурсы на перезапуски > - Этот PR добавляет defensive guard против NaN в `readLiveRunsQueryInt` и делает детерминированным тест wake-уведомления по комментарию аннотации > - Польза: стабильный зелёный CI для Agents API Tests без flaky перезапусков ## Linked Issues or Issue Description Переоткрытие вместо закрытого #172 (flaky-тесты `Agents CI / API Tests`, тот же корень проблемы). ## What Changed - `readLiveRunsQueryInt`: заменён `Math.min(undefined - max, parsed)` (даёт NaN под mock-isolation) на defensive `Number.isFinite(max)` guard. - Тест wake-уведомления по комментарию аннотации: user-comment на annotation теперь детерминированно будит assignee через `queueAnnotationCommentWakeup` (fire-and-forget после ответа), тест обновлён на `expect` + `vi.waitFor` + `mockClear`. ## Verification - `pnpm exec vitest run` для затронутых файлов: guard-тест 3/3, annotation wake-тест 6/6 в двух последовательных прогонах (детерминированность подтверждена повтором). - `pnpm typecheck` (pre-push) — 0 ошибок. - Известный отдельный infra-timing flake (`costs-DB`) не относится к этому PR, не устраняется в его рамках. ## Risks Низкий риск: изменения ограничены defensive guard и детерминизацией существующего теста, поведение production-кода не меняется вне обработки edge-case NaN. ## Model Used Claude (claude-sonnet-4-6), Claude Code CLI, tool use (Bash/Edit/Read), без 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] Я поискал похожие PR и подтверждаю, что дубликатов нет - [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 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 - [ ] 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
test(annotation): assert + await the intended assignee wake — fix flaky API test
Some checks failed
security/pr-scan No security concerns detected
PR Quality Gates / PR Quality Gates (pull_request_target) Successful in 5s
Agents CI / API Tests (pull_request) Has been cancelled
Agents CI / Typecheck and Build (pull_request) Has been cancelled
8cf7087fd6
The 'document annotation routes' tests asserted mockHeartbeatService.wakeup was NOT called
when a user comments on an annotation thread. But queueAnnotationCommentWakeup (upstream
'Guard document comment wake boundaries' #7766) intentionally wakes the assignee agent so it
sees a non-self user's comment. The wake is dispatched fire-and-forget after the response,
so the synchronous not.toHaveBeenCalled() assertion raced it → non-deterministic 'Agents CI /
API Tests' failure.

Update the two comment/thread-create cases to await the wake (vi.waitFor) and clear the mock
before the resolve step so the 'resolve does not wake' assertion stays valid. Test-only; the
forked wake behaviour is unchanged. 6/6 deterministic across repeated runs.

All checks passing — ready for review and maintainer approval.

— paperclip-gates

✅ All checks passing — ready for review and maintainer approval. — paperclip-gates
ci: re-trigger API Tests (prior run hit Docker-network race, not a test failure)
Some checks failed
security/pr-scan No security concerns detected
PR Quality Gates / PR Quality Gates (pull_request_target) Successful in 7s
Agents CI / Typecheck and Build (pull_request) Successful in 5m45s
Agents CI / API Tests (pull_request) Failing after 9m29s
64b96f7722
Run 35825 failed at infra level: 'failed to set up container networking: network
WORKFLOW-... not found' — the postgres service container never started (concurrent job on
the shared runner tore down the Docker network). Tests never executed; the NaN guard and
annotation-wake fixes on this branch are unaffected. Empty commit to re-run CI.
andrei merged commit 19ae4c789f into master 2026-07-05 11:38:12 +00:00
andrei deleted branch feature/claude-fix-flaky-issue-list-limit 2026-07-05 11:38:13 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
europa-tech-srl/europa-tech-agents!187
No description provided.