diff --git a/doc/plans/2026-10-25-teams-consent-expiry-sleep-audit.md b/doc/plans/2026-10-25-teams-consent-expiry-sleep-audit.md index cffea6acd9f..5a1e969678a 100644 --- a/doc/plans/2026-10-25-teams-consent-expiry-sleep-audit.md +++ b/doc/plans/2026-10-25-teams-consent-expiry-sleep-audit.md @@ -181,3 +181,39 @@ and the explicitly accepted company-deletion ownership policy. The report parent has a documentation-only follow-up after `c28de398` and still needs its own latest CI/reviews. This local Teams preparation must preserve that actual landed parent before publication; it is not authority to merge into an unmerged feature branch. + + +## Inherited retention CI fairness repair — October 28 + +Current Teams head `36f43922` received exact-head Greptile 5/5 and Ponytail 5/5, +but CI run `40708566195`, server shard 6/12 job `122887395220`, failed the existing +voice-retention case `pages through more than one batch of history across +companies`. The shard had 2,291 passed tests, one failed and one skipped. Its +initial assertion expected the other company's row already deleted after one +startup batch, even when its random ID put it beyond the first 100-row inventory +page. This CI failure is not accepted as green evidence. + +Placing the other company at a fixed final UUID reproduces the exact assertion. +The fixture now uses a supplied ID for both insertion and its transaction hint. +The test controls scheduler time, requires that row to remain before discovery, +then requires its deletion in the next fair batch after page-two discovery. It +also checks the first 25 deletions leave exactly 80 eligible rows, drains all +remaining history, and verifies SQL quiet. The existing five-second assertion +wait budget and global test timeout are unchanged. This corrects the acceptance +expectation without changing retention, Teams, or shared scheduler behavior. + +The complete 13-case retention suite passes. Its run spent 96.66 seconds in +module transforms but all actual cases completed successfully; no timeout was +increased and this was not counted as a failed test or silently retried. A +guarded mutation bypassing company rotation fails the new post-discovery fair +batch assertion. The original shared helper was restored byte-for-byte. The +previous 223-case Teams acceptance remains evidence for unchanged Teams source; +these 13 retention cases are a separate CI-repair acceptance group. Earlier +current-head Greptile/Ponytail scores become stale after publishing this test-only +follow-up, and fresh CI must pass independently. No old-job retry or waiver is +claimed. + +Logs: `/tmp/sleep26-36f-server6-job.log`, +`/tmp/sleep26-retention-fairness-red.log`, +`/tmp/sleep26-retention-fairness-green.log`, and +`/tmp/sleep26-retention-fairness-mutant-red.log`. diff --git a/server/src/__tests__/voice-inbound-retention.test.ts b/server/src/__tests__/voice-inbound-retention.test.ts index 306e43e9408..6bdedd256d5 100644 --- a/server/src/__tests__/voice-inbound-retention.test.ts +++ b/server/src/__tests__/voice-inbound-retention.test.ts @@ -56,7 +56,7 @@ const support = external ? { supported: true } : await getEmbeddedPostgresTestSu }); afterAll(async () => { await db?.$client.end({ timeout: 1 }); await temporary?.cleanup(); }); async function admission(patch: Partial = {}, writer = db) { - const id = randomUUID(); + const id = patch.id ?? randomUUID(); return writer.transaction(async tx => { await notifyVoiceInbound(tx, { kind: "admission", id }); return (await tx.insert(chatVoiceInboundCalls).values({ id, companyId, endpointId, providerSessionId: randomUUID(), state: "ended", cleanupConfirmedAt: new Date(), updatedAt: new Date(Date.now() - week - 1000), approvalCode: "123456", generation: 1, credentialFingerprint: "test", toolTokenHash: "a".repeat(64), requestFingerprint: id, expiresAt: new Date(Date.now() - week - 1000), ...patch }).returning())[0]; @@ -211,12 +211,22 @@ const support = external ? { supported: true } : await getEmbeddedPostgresTestSu expect(coordinator!.nextWakeAt()).toBeNull(); await quiet(); }); it("pages through more than one batch of history across companies", async () => { + vi.useFakeTimers({ toFake: ["Date", "setTimeout", "clearTimeout"], shouldAdvanceTime: false }); for (let i = 0; i < 104; i++) await admission(); - const other = await fixture(); const last = await admission({ companyId: other.companyId, endpointId: other.endpointId }); + const other = await fixture(); const last = await admission({ id: "ffffffff-ffff-4fff-bfff-ffffffffffff", companyId: other.companyId, endpointId: other.endpointId }); const service = await start(); - expect(await row(last.id)).toBeUndefined(); - await vi.waitFor(async () => { await vi.advanceTimersByTimeAsync(1000); expect(await service.load()).toHaveLength(0); }, { timeout: 5000 }); - await flush(); await quiet(); + expect(await row(last.id)).toBeDefined(); + expect(await service.load()).toHaveLength(80); + await vi.advanceTimersByTimeAsync(1000); + await vi.waitFor(async () => expect(await row(last.id)).toBeUndefined(), { interval: 0, timeout: 5000 }); + for (let pass = 0; pass < 20; pass++) { + await vi.advanceTimersByTimeAsync(1000); + await vi.waitFor(() => expect(coordinator!.nextWakeAt() !== null || idleWorkSnapshot().active === 0).toBe(true), { interval: 0, timeout: 5000 }); + } + await flush(); + expect(await service.load()).toHaveLength(0); + expect(await db.select().from(chatVoiceInboundCalls).where(eq(chatVoiceInboundCalls.companyId, companyId))).toHaveLength(0); + expect(await row(last.id)).toBeUndefined(); await quiet(); }); it("retains failed deletion for a bounded retry and then becomes quiet", async () => { const call = await admission();