Fix five flaky server integration tests

Merged
CH
3h ago
+45-12

Why

I ranked integration test failures from PR runs since Nov 10 (86 failed shard logs) by how many unrelated branches each spec failed on. Five specs account for most of the noise. Each one races the CI worker or a timing window.

flowchart LR
  A[Test mutates metadata] --> B[Listener queues a job]
  B --> C[CI worker runs the job]
  A --> D[Test asserts or acts directly]
  C -. holds a lock or rewrites state .-> D
  D --> E{Race}
  E -->|worker first| F[Flaky failure]
  E -->|test first| G[Pass]

Before / after

SpecFailuresBeforeAfter
record-access-group (+ query-many-records-through-access-groups, access-groups-shared-by-value)~24Rule upsert queues a sync, and the sync queues a compute job. The test's recompute uses SKIP LOCKED, so rows held by the worker stay NULLDrain jobs before the direct sync and again before the recompute
chat-channel-deletion-and-summaries~21Deleting the destination queues MoveDeletedAgentChatChannelThreadsJob, which holds its deletion lock, so the next delete gets CHAT_CHANNEL_BUSYdeleteChannelBehindStaleCache drains events and jobs
api-rate-limit71 request per 1s token bucket with continuous refill, so a request over 1s on a loaded runner refilled the bucket5s window, bucket reset by deleting its Redis key instead of sleeping, Retry-After checked as a range
sdk-client-core-module-schema-text6createOneObject leaves deferred index/FK builds, so the next sync gets DEFERRED_WORKSPACE_MIGRATION_ACTIONS_IN_PROGRESSWait for deferred operations first. The wait helper now reuses SCHEMA_AFFECTING_DEFERRED_WORKSPACE_OPERATIONS (it was missing rebuild_object)
core-workflow-execution "refuses a submission while its run is stopping"5The executor job is still running when the form reads PENDING, sees the forced STOPPING and fails the formDrain jobs before forcing STOPPING

Test-only changes, no production code touched.