Carry receiver failure fairness repair into sleep-26-teams-consent-expiry

Co-Authored-By: Paperclip <noreply@paperclip.ing>

* codex/sleep-25-voice-call-reports:
  Keep healthy receivers moving after a slow failed batch
This commit is contained in:
DottaandPaperclip committed 2026-10-27 13:06:41 -05:00
commit aa082e4679
3 files changed
+32 -3

No files matched your search

@@ -248,3 +248,26 @@ full-refresh failure/backoff case. Server typecheck and build pass. Prior broad
consumer/workspace verification remains recorded above; these 45 overlap that
coverage and are not an additional unique total. Publication requires fresh
remote CI and review. The full migration inventory remains outstanding.
## Healthy receiver progress after a slow failed batch
The receiver worker already stores a retry deadline for each failed receiver and
scope. It now supplies that deadline calculation through the coordinator's
`nextRunAtOnError` contract as well. A completed batch can take longer than the
one-second batching interval. When that batch contained an error, the coordinator
previously ignored an already-due healthy backlog and waited for its generic
30-second retry. The changed registration lets healthy due entries proceed while
the failed receiver retains its own exponential backoff.
The existing 105-receiver PostgreSQL regression now runs with both an immediate
failure and a controlled 1,100 ms elapsed interval in the failed provider call.
The latter failed before the repair: its next wake was 30 seconds away although
healthy receivers were due. Afterward, all 105 are attempted before retrying the
failed receiver, which is attempted once during the healthy drain. Recovery then
settles and two former poll periods add no SQL. The assertion helper advances its
own fake clock; the test no longer adds an extra second on every assertion retry.
All 20 receiver lifecycle cases and the server production typecheck pass on the
owning branch. This changes one coordinator registration and adds no provider
branch, queue, table, or independent timer. Current-head CI and combined-stack
verification remain separate gates.
@@ -192,15 +192,20 @@ const support = external ? { supported: true } : await getEmbeddedPostgresTestSu
await endpoint();
await settled(); expect(reconcile).toHaveBeenCalledOnce(); expect(errors.length).toBeGreaterThan(0); errors.length = 0; await quiet();
});
it("loads inventory in bounded pages and drains a backlog despite one failed receiver", async () => {
it.each([0, 1100])("drains paged inventory despite a failed receiver after %i ms", async delay => {
for (let i = 0; i < 105; i++) await endpoint();
const service = chatReceiverSchedule(db, { reconcile, stop });
const reads = vi.spyOn(db, "select"); const inventory = await service.load({ kind: "company", id: companyId });
expect(inventory).toHaveLength(105); expect(reads).toHaveBeenCalledTimes(2); reads.mockRestore();
const failedId = inventory[0].id;
reconcile.mockImplementation(async id => { if (id === failedId) throw new Error("bad credential"); return "owned"; });
reconcile.mockImplementation(async id => {
if (id === failedId) { vi.setSystemTime(Date.now() + delay); throw new Error("bad credential"); }
return "owned";
});
await start(service);
await vi.waitFor(async () => { await vi.advanceTimersByTimeAsync(1000); expect(new Set(reconcile.mock.calls.map(([id]) => id)).size).toBe(105); }, { timeout: 5000 });
expect(coordinator!.nextWakeAt()).not.toBeNull();
expect(coordinator!.nextWakeAt()!).toBeLessThanOrEqual(Date.now() + 1000);
await vi.waitFor(() => expect(new Set(reconcile.mock.calls.map(([id]) => id)).size).toBe(105), { timeout: 5000 });
expect(reconcile.mock.calls.filter(([id]) => id === failedId)).toHaveLength(1);
reconcile.mockResolvedValue("owned"); await settled(); errors.length = 0; await quiet();
});
@@ -83,6 +83,7 @@ export function registerChatReceiverWork(
// The coordinator independently fences unresolved database transactions.
hasPending: async () => canRun() && dirty.size > 0,
nextRunAt: next,
nextRunAtOnError: next,
});
return { ready: worker.ready, changed(id: string) {
dirty.add(receiverScopeHint({ kind: "endpoint", id })); worker.wake();