Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(super-tabs): a message the agent received no longer shows Not sent after a long acknowledgement outage (#2404)

0xken15c1123c5ee69f
diff --git a/backend/integration/superTabTidy.test.ts b/backend/integration/superTabTidy.test.ts
index d83f18e76..1cba113b9 100644
--- a/backend/integration/superTabTidy.test.ts
+++ b/backend/integration/superTabTidy.test.ts
@@ -648,6 +648,60 @@ describe('a delivery that cannot move', () => {
deliveredAt: new Date(f.clock.now), holdReason: null })
})
+ // Prod 10-30: two hours of SWARM_BUSY kept hosts' acknowledgements out past the 10-minute quiet time. The pass ended claims
+ // the agents had received, their senders saw Not sent and sent them again, and the agents acted twice.
+ it('counts a quiet claim the pass ended as delivered once its host\'s acknowledgement gets through, and never types it again', async () => {
+ const f = await swarm()
+ const id = await toLead(f, 'Typed while the backend was busy.')
+ await f.timed.delivery(host, f.tab, f.lead, id, { type: 'claim', claimId: 'claim' })
+ await settleAfter(f, id, 10 * MINUTE + 1_000)
+ expect(await db.superTabDelivery.findUniqueOrThrow({ where: { id } })).toMatchObject({ status: 'cancelled', holdReason: 'claim_quiet', holdSince: null })
+ await expect(f.timed.delivery(host, f.tab, f.lead, id, { type: 'claim', claimId: 'claim' })).rejects.toMatchObject({ code: 'DELIVERY_REVOKED' })
+ await expect(f.timed.delivery(host, f.tab, f.lead, id, { type: 'ack', claimId: 'another', receipt: 'Typed.', uncertain: false }))
+ .rejects.toMatchObject({ code: 'DELIVERY_REVOKED' })
+ f.clock.now += 20 * MINUTE
+ await f.timed.delivery(host, f.tab, f.lead, id, { type: 'ack', claimId: 'claim', receipt: 'Typed.', uncertain: false })
+ expect(await db.superTabDelivery.findUniqueOrThrow({ where: { id } })).toMatchObject({ status: 'delivered', receipt: 'Typed.',
+ deliveredAt: new Date(f.clock.now), holdReason: null, claimId: 'claim' })
+ // Delivered stays delivered: a later pass ends nothing, and the same acknowledgement again changes nothing.
+ await settleAfter(f, id, 2 * HOUR)
+ await f.timed.delivery(host, f.tab, f.lead, id, { type: 'ack', claimId: 'claim', receipt: 'Typed.', uncertain: false })
+ expect(await status(id)).toBe('delivered')
+ })
+
+ it('never takes a late acknowledgement for a claim an archive ended, nor one the pass ended as unreadable, once the group is back', async () => {
+ const f = await swarm()
+ const archived = await toWorker(f, 'Ended by the archive.'), unread = await toWorker(f, 'Left claimed in the archived group.')
+ for (const id of [archived, unread]) await f.timed.delivery(host, f.tab, f.worker, id, { type: 'claim', claimId: 'claim' })
+ await f.execute({ type: 'conversation.archive', conversationId: f.group, archived: true })
+ expect(await db.superTabDelivery.findUniqueOrThrow({ where: { id: archived } })).toMatchObject({ status: 'cancelled', holdReason: null })
+ // As a backend from before the archive cancelled its deliveries left one: still claimed, quiet, in the archived group.
+ await db.superTabDelivery.update({ where: { id: unread }, data: { status: 'claimed' } })
+ await settleAfter(f, unread, 10 * MINUTE + 1_000)
+ expect(await db.superTabDelivery.findUniqueOrThrow({ where: { id: unread } })).toMatchObject({ status: 'cancelled', holdReason: null })
+ await f.execute({ type: 'conversation.archive', conversationId: f.group, archived: false })
+ for (const id of [archived, unread]) {
+ await expect(f.timed.delivery(host, f.tab, f.worker, id, { type: 'ack', claimId: 'claim', receipt: 'Typed.', uncertain: false }))
+ .rejects.toMatchObject({ code: 'DELIVERY_REVOKED' })
+ expect(await status(id)).toBe('cancelled')
+ }
+ })
+
+ it('never takes a late acknowledgement for a quiet claim the pass ended from another agent, or once its agent left the group', async () => {
+ const f = await swarm()
+ const id = await toWorker(f, 'Typed, then the worker was taken off the task.')
+ await f.timed.delivery(host, f.tab, f.worker, id, { type: 'claim', claimId: 'claim' })
+ await settleAfter(f, id, 10 * MINUTE + 1_000)
+ expect(await db.superTabDelivery.findUniqueOrThrow({ where: { id } })).toMatchObject({ status: 'cancelled', holdReason: 'claim_quiet' })
+ // The same claim id, sent as another agent of the same host: the delivery is looked up by its own agent, so it is not found.
+ await expect(f.timed.delivery(host, f.tab, f.lead, id, { type: 'ack', claimId: 'claim', receipt: 'Typed.', uncertain: false }))
+ .rejects.toMatchObject({ code: 'DELIVERY_REVOKED' })
+ await f.execute({ type: 'conversation.agent', conversationId: f.group, agentId: f.worker, present: false, lead: false })
+ await expect(f.timed.delivery(host, f.tab, f.worker, id, { type: 'ack', claimId: 'claim', receipt: 'Typed.', uncertain: false }))
+ .rejects.toMatchObject({ code: 'DELIVERY_REVOKED' })
+ expect(await db.superTabDelivery.findUniqueOrThrow({ where: { id } })).toMatchObject({ status: 'cancelled', receipt: null })
+ })
+
it('never types a hold the pass ended: claiming it again is refused', async () => {
const f = await swarm()
const id = await toLead(f, 'Held and ended, never typed.')
diff --git a/backend/src/superTabs/holdReason.ts b/backend/src/superTabs/holdReason.ts
index 278d40f20..2cdcd1d7f 100644
--- a/backend/src/superTabs/holdReason.ts
+++ b/backend/src/superTabs/holdReason.ts
@@ -7,3 +7,9 @@ import { z } from 'zod'
*/
export const holdReason = z.enum(['team_waiting_unavailable', 'team_waiting_user', 'team_waiting_draft', 'team_waiting_idle', 'team_waiting_control'])
export type HoldReason = z.infer<typeof holdReason>
+
+/** Not a host's reason, so no host can send it (routes/superTabs.ts takes only those above): the delivery pass writes it on a
+ * claim it ended because nothing touched it for 10 minutes (deliverySettle.ts CLAIM_QUIET_MS), so the host's acknowledgement
+ * that it typed it still counts if it comes late (store.ts delivery). Prod 10-30: acknowledgements failed through two hours
+ * of SWARM_BUSY and typed messages showed Not sent. */
+export const QUIET_CLAIM = 'claim_quiet'
diff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.ts
index 1d8d2cdd3..07abf508f 100644
--- a/backend/src/superTabs/store.ts
+++ b/backend/src/superTabs/store.ts
@@ -54,7 +54,7 @@ import {
activeWork, actorKey, agent, agentOnly, agentRole, appendPullRequestUrls, author, conversation, createSuperTab, fail, person, stableId, visibleState, finishWorker,
SuperTabError, forRecipients, isLeads, knownKind, parkLaterConversations, syncLeads, type Actor, type Agent, type Assignment, type Author, type CommandEffects, type Conversation, type MessageDraft, type Person, type SuperTabState,
} from './model.js'
-import type { HoldReason } from './holdReason.js'
+import { QUIET_CLAIM, type HoldReason } from './holdReason.js'
import { stuck } from './deliverySettle.js'
import { agentDisplayName } from './agentNames.js'
import { endedHolds, HOLDING, startedHolds, type WorkHold } from '../github/holds.js'
@@ -2943,9 +2943,10 @@ export class SuperTabStore {
parkLaterConversations(state)
syncLeads(state)
author(state, await this.actor(tx, user, state, agentId), true)
- // The delivery pass ended a hold (it keeps the hold's reason) as its host, its terminal free again, typed it: the
- // host's own confirmation counts, or the agent has it while its sender sees Not sent and sends it again (review of
- // #1941). Nothing else brings an ended delivery back.
+ // The delivery pass ended a hold (it keeps the hold's reason) as its host, its terminal free again, typed it, or a claim
+ // whose acknowledgement could not get through for 10 minutes (QUIET_CLAIM): the host's own confirmation counts, or the
+ // agent has it while its sender sees Not sent and sends it again (review of #1941, prod 10-30). Nothing else brings an
+ // ended delivery back: every other cancel clears the reason.
const typedAsEnded = delivery?.status === 'cancelled' && !!delivery.holdReason && action.type === 'ack' && delivery.claimId === action.claimId
if (!delivery || !this.deliveryAllowed(state, delivery) || delivery.status === 'cancelled' && !typedAsEnded ||
!await this.senderAllowed(tx, state, delivery)) fail('DELIVERY_REVOKED', 'This instruction is no longer authorized.', 403)
@@ -3120,7 +3121,10 @@ export class SuperTabStore {
/** Ends, as cancelled, those of this Swarm's open deliveries `rows` (as the delivery pass read them) that can no longer move
* (deliverySettle.ts). Each only as it was read: one its host acknowledged since, or a claim with no hold its host claimed
* again since, is kept. A held claim its host claims again still ends once its hold is over; it keeps its hold's reason,
- * so its sender learns why, and its host's confirmation that it typed it still counts (delivery). The number ended. */
+ * so its sender learns why, and its host's confirmation that it typed it still counts (delivery). So does a quiet claim's,
+ * which the pass marks claim_quiet: prod 10-30, two hours of SWARM_BUSY kept typed messages' acknowledgements out past
+ * CLAIM_QUIET_MS, and their senders saw Not sent and sent them again. One its recipient could no longer read is not
+ * marked: a group archived and reopened later must not take it back. The number ended. */
async settleDeliveries(tabId: string, rows: SuperTabDelivery[], now: number): Promise<number> {
return transaction(this.db, async tx => {
const row = await tx.superTab.findUnique({ where: { id: tabId }, select: SWARM_ROW })
@@ -3128,13 +3132,15 @@ export class SuperTabStore {
const state = row ? (await loadRow(tx, requireParts(row), { groupIds: [...new Set(rows.map(r => r.conversationId))] })).state : null
let settled = 0
for (const delivery of rows) {
- if (!stuck(delivery, !!state && this.deliveryAllowed(state, delivery), now)) continue
+ const reachable = !!state && this.deliveryAllowed(state, delivery)
+ if (!stuck(delivery, reachable, now)) continue
// A held claim is the same while its claim and hold are: its live host claims it again on every poll (cli
// superTabs/host.ts), so its write time would let it outrun the pass for good. Any other is as last written.
const unchanged = delivery.holdSince ? { claimId: delivery.claimId, holdReason: delivery.holdReason, holdSince: delivery.holdSince }
: { updatedAt: delivery.updatedAt }
+ const quiet = reachable && delivery.status === 'claimed' && !delivery.holdSince
settled += (await tx.superTabDelivery.updateMany({ where: { id: delivery.id, tabId, status: delivery.status, ...unchanged },
- data: { status: 'cancelled' } })).count
+ data: { status: 'cancelled', ...quiet ? { holdReason: QUIET_CLAIM } : {} } })).count
}
return settled
})
diff --git a/cli/src/superTabs/host.spec.ts b/cli/src/superTabs/host.spec.ts
index 1aa5192b3..7afe20deb 100644
--- a/cli/src/superTabs/host.spec.ts
+++ b/cli/src/superTabs/host.spec.ts
@@ -513,6 +513,157 @@ describe('Super Tab native delivery handoff', () => {
expect(t.core.turns.deliver).toHaveBeenCalledTimes(1)
expect(t.saved().entries).toEqual({})
})
+ describe('an acknowledgement the backend could not take', () => {
+ /** Typed, then every POST answers busy until `up`; the list and the receipt read say what the backend holds. */
+ const outage = (t: ReturnType<typeof setup>) => {
+ const original = vi.mocked(t.core.account.backend).getMockImplementation()!
+ const s = { down: true, ended: false, refusal: null as null | { status: number; code: string }, acks: 0 }
+ vi.mocked(t.core.account.backend).mockImplementation(async (method, path, body) => {
+ const command = body as Record<string, unknown> | undefined
+ if (command?.type === 'ack') s.acks++
+ if (method === 'POST' && path.endsWith('/deliveries/delivery')) {
+ if (s.down) return { status: 503, body: { success: false, error: { code: 'SWARM_BUSY', message: 'The Swarm is busy.' } } }
+ if (s.refusal) return { status: s.refusal.status, body: { success: false, error: { code: s.refusal.code, message: 'Refused.' } } }
+ }
+ if (s.ended && method === 'GET' && path.endsWith('/deliveries/delivery')) return { status: 200, body: { success: true, data: { id: 'delivery', status: 'cancelled' } } }
+ if (s.ended && method === 'GET' && path.endsWith('/deliveries')) return { status: 200, body: { success: true, data: [] } }
+ return original(method, path, body)
+ })
+ return s
+ }
+ const typed = async (t: ReturnType<typeof setup>) => {
+ const host = t.open()
+ await host.tick(); t.event('delivered')
+ expect(t.saved().entries.delivery.stage).toBe('delivered')
+ return host
+ }
+
+ it('is sent again with backoff: one that fails twice, then gets in, leaves the delivery delivered and the journal empty', async () => {
+ const t = setup(), host = await typed(t), s = outage(t)
+ const claimId = t.saved().entries.delivery.claimId
+ await host.tick().catch(() => {}); t.wait(1_000)
+ await host.tick().catch(() => {}); t.wait(2_000)
+ expect(s.acks).toBe(2)
+ expect(t.saved().entries.delivery.stage).toBe('delivered')
+ s.down = false
+ await host.tick()
+ expect(t.receipts).toEqual([expect.objectContaining({ type: 'ack', claimId, uncertain: false })])
+ expect(t.saved().entries).toEqual({})
+ expect(t.core.turns.deliver).toHaveBeenCalledTimes(1)
+ })
+
+ // The 10-30 SWARM_BUSY outage: acknowledgements failed for longer than the backend's 10-minute claim quiet time, so its
+ // delivery pass ended claims the agents had in fact received, and their senders saw Not sent.
+ it('is still sent once the backend\'s delivery pass ended the quiet claim, so the message counts as delivered', async () => {
+ const t = setup(), host = await typed(t), s = outage(t)
+ const claimId = t.saved().entries.delivery.claimId
+ await host.tick().catch(() => {}); t.wait(11 * 60_000)
+ s.down = false; s.ended = true
+ await host.tick(); await host.reconcileReceipts()
+ expect(t.receipts).toEqual([expect.objectContaining({ type: 'ack', claimId, uncertain: false })])
+ expect(t.saved().entries).toEqual({})
+ expect(t.core.turns.deliver).toHaveBeenCalledTimes(1)
+ })
+
+ it('is not sent again once the backend refuses it, as for a delivery an archive ended, and the entry goes', async () => {
+ for (const refusal of [{ status: 403, code: 'DELIVERY_REVOKED' }, { status: 403, code: 'FORBIDDEN' }, { status: 409, code: 'CLAIM_CONFLICT' }]) {
+ const t = setup(), host = await typed(t), s = outage(t)
+ s.down = false; s.ended = true; s.refusal = refusal
+ await host.reconcileReceipts()
+ expect(s.acks).toBe(1)
+ expect(t.saved().entries).toEqual({})
+ t.wait(10 * 60_000)
+ await host.tick(); await host.reconcileReceipts()
+ expect(s.acks).toBe(1)
+ expect(t.core.turns.deliver).toHaveBeenCalledTimes(1)
+ }
+ })
+
+ it('keeps the entry while the backend still cannot take it, trying again only after a growing wait, until it gets through', async () => {
+ const t = setup(), host = await typed(t), s = outage(t)
+ // The list says nothing waits, the receipt says ended, and the acknowledgement still answers busy.
+ s.ended = true
+ await host.reconcileReceipts()
+ expect(s.acks).toBe(1)
+ // 10 s, then 20 s: the receipts pass itself runs every 5 s.
+ t.wait(5_000); await host.reconcileReceipts()
+ expect(s.acks).toBe(1)
+ t.wait(6_000); await host.reconcileReceipts()
+ expect(s.acks).toBe(2)
+ t.wait(6_000); await host.reconcileReceipts()
+ expect(s.acks).toBe(2)
+ t.wait(15_000); await host.reconcileReceipts()
+ expect(s.acks).toBe(3)
+ expect(t.saved().entries.delivery.stage).toBe('delivered')
+ t.wait(41_000); s.down = false
+ await host.reconcileReceipts()
+ expect(s.acks).toBe(4)
+ expect(t.receipts).toEqual([expect.objectContaining({ type: 'ack', uncertain: false })])
+ expect(t.saved().entries).toEqual({})
+ expect(t.log).toHaveBeenCalledWith(expect.stringContaining('Delivery delivery was acknowledged after the backend ended it, 4 tries'))
+ })
+
+ it.each([['answers busy', null], ['drops the connection', 'socket closed']])('gives up after a day while the backend %s, said once, so the journal never fills', async (_case, dropped) => {
+ const t = setup(), host = await typed(t), s = outage(t)
+ s.ended = true
+ if (dropped) {
+ const original = vi.mocked(t.core.account.backend).getMockImplementation()!
+ vi.mocked(t.core.account.backend).mockImplementation(async (method, path, body) => {
+ if (method === 'POST' && path.endsWith('/deliveries/delivery')) { s.acks++; throw dropped }
+ return original(method, path, body)
+ })
+ }
+ await host.reconcileReceipts()
+ for (let i = 0; i < 400; i++) { t.wait(5 * 60_000); await host.reconcileReceipts() }
+ expect(t.saved().entries).toEqual({})
+ expect(t.log).toHaveBeenCalledWith(expect.stringContaining(`Gave up acknowledging delivery delivery to agent agent in Swarm tab after a day: ${dropped ?? 'The Swarm is busy.'}`))
+ expect(vi.mocked(t.log).mock.calls.filter(([line]) => String(line).startsWith('Gave up'))).toHaveLength(1)
+ const tries = s.acks
+ t.wait(10 * 60_000); await host.reconcileReceipts()
+ expect(s.acks).toBe(tries)
+ expect(t.core.turns.deliver).toHaveBeenCalledTimes(1)
+ })
+
+ it('writes nothing once the host stops during a late acknowledgement, and keeps the entry for the next host', async () => {
+ const t = setup(), host = await typed(t), s = outage(t)
+ s.down = false; s.ended = true
+ const original = vi.mocked(t.core.account.backend).getMockImplementation()!
+ vi.mocked(t.core.account.backend).mockImplementation(async (method, path, body) => {
+ if ((body as Record<string, unknown> | undefined)?.type === 'ack') host.stop()
+ return original(method, path, body)
+ })
+ await host.reconcileReceipts()
+ expect(s.acks).toBe(1)
+ expect(t.saved().entries.delivery.stage).toBe('delivered')
+ })
+
+ it('never retires an entry that replaced the one it acknowledged late while the answer was on its way', async () => {
+ const t = setup(), host = await typed(t), s = outage(t)
+ s.down = false; s.ended = true
+ const journal = (host as unknown as { journal: { entries: Record<string, Record<string, unknown>> } }).journal
+ const original = vi.mocked(t.core.account.backend).getMockImplementation()!
+ vi.mocked(t.core.account.backend).mockImplementation(async (method, path, body) => {
+ if ((body as Record<string, unknown> | undefined)?.type === 'ack') journal.entries.delivery = { ...journal.entries.delivery, claimId: 'newer' }
+ return original(method, path, body)
+ })
+ await host.reconcileReceipts()
+ expect(s.acks).toBe(1)
+ expect(journal.entries.delivery).toMatchObject({ claimId: 'newer' })
+ })
+
+ it('never acknowledges late a delivery it reported uncertain, nor one its host never typed', async () => {
+ for (const stage of ['unknown', 'held'] as const) {
+ const t = setup(), host = t.open()
+ await host.tick()
+ if (stage === 'held') t.event('rejected', 'team_waiting_busy'); else t.event('unknown', 'lost acknowledgement')
+ const s = outage(t)
+ s.down = false; s.ended = true
+ await host.reconcileReceipts()
+ expect(s.acks).toBe(0)
+ expect(t.saved().entries).toEqual({})
+ }
+ })
+ })
it('drops the lease of a held delivery answered while its lease was being granted', async () => {
const t = setup(), host = t.open()
await host.tick(); t.event('rejected', 'team_waiting_busy')
diff --git a/cli/src/superTabs/host.ts b/cli/src/superTabs/host.ts
index 7c5acd47f..fa6bf5b3a 100644
--- a/cli/src/superTabs/host.ts
+++ b/cli/src/superTabs/host.ts
@@ -254,6 +254,16 @@ const PUSH_LEASE_MS = 10 * 60_000
const LEAD_RETRY_MS = 5_000
const LEAD_RETRY_MAX_MS = 30 * 60_000
const LEAD_REOPEN_WAIT_MS = 60_000
+/** Prod 10-30: acknowledgements failed through two hours of SWARM_BUSY, past the backend's 10-minute claim quiet time
+ * (backend superTabs/deliverySettle.ts CLAIM_QUIET_MS), so its delivery pass ended claims the agents had in fact received and
+ * their senders saw Not sent. A typed delivery the backend ended is acknowledged again after 10 s, doubling to 5 minutes, for
+ * a day; the backend takes it for a claim its pass ended, and refuses it for one a person, an archive or a stop ended. */
+const LATE_ACK_RETRY_MS = 10_000
+const LATE_ACK_RETRY_MAX_MS = 5 * 60_000
+const LATE_ACK_GIVE_UP_MS = 24 * 60 * 60_000
+/** A refusal no later acknowledgement can change: the delivery is no longer this agent's, or another claim or receipt holds it.
+ * A sign-in (401), an update (426), throttling (429) and a server failure (5xx) say nothing of the delivery. */
+const ackRefused = (error: unknown) => error instanceof SuperTabHostError && [400, 403, 404, 409].includes(error.status)
/** The first wait after a session the backend ended could not be closed or acknowledged, doubling up to ten minutes. */
const END_RETRY_MS = 5_000
const END_RETRY_MAX_MS = 10 * 60_000
@@ -361,6 +371,8 @@ export class SuperTabHost {
private timer: ReturnType<typeof setTimeout> | null = null
/** Per agent's delivery list and per delivery's claim, the failures in a row and when it may be asked again. */
private readonly deliveryRetries = new Map<string, { failures: number; retryAt: number; since: number; saidAt?: number; said?: string; list?: string }>()
+ /** Per typed delivery the backend ended before it heard the acknowledgement: the failed late tries and when the next may run. */
+ private readonly lateAcks = new Map<string, { failures: number; retryAt: number; since: number }>()
private native: NativeRecorder | null = null
private machines: ContributedMachines | null = null
private readonly machineDeps: Partial<MachineDeps>
@@ -739,12 +751,47 @@ export class SuperTabHost {
const terminal = entry.stage === 'prepared' ? ['answered', 'cancelled'] : ['delivered', 'confirmed', 'superseded', 'cancelled', 'answered']
if (result.id !== entry.deliveryId || !terminal.includes(String(result.status))) continue
if (this.journal.entries[entry.deliveryId] !== entry || this.active.has(typedId(entry))) continue
- delete this.journal.entries[entry.deliveryId]
- this.withheld.clear(entry.deliveryId)
- this.persist()
+ if (entry.stage === 'delivered' && result.status === 'cancelled') {
+ const done = await this.ackLate(entry)
+ if (this.stopped) return
+ if (!done) continue
+ }
+ this.retireEntry(entry)
} catch { /* Missing authority or a network failure is not a receipt. */ }
}
}
+ /** Only while it is still this entry: a late acknowledgement's answer must not retire one that replaced it meanwhile. */
+ private retireEntry(entry: Entry): void {
+ if (this.journal.entries[entry.deliveryId] !== entry) return
+ delete this.journal.entries[entry.deliveryId]
+ this.lateAcks.delete(entry.deliveryId)
+ this.withheld.clear(entry.deliveryId)
+ this.persist()
+ }
+ /** The agent has a delivery the backend ended, as cancelled, before this host's acknowledgement got through: it is sent again,
+ * with the same claim and receipt. Whether the entry is done: taken, refused for good, or a day of failures. Only a typed one:
+ * one reported uncertain, or never typed, is never confirmed this way. */
+ private async ackLate(entry: Entry): Promise<boolean> {
+ const now = this.now(), late = this.lateAcks.get(entry.deliveryId)
+ if (late && now < late.retryAt) return false
+ try {
+ await backend(this.core, 'POST', `/api/super-tabs/${entry.tabId}/agents/${entry.agentId}/deliveries/${entry.deliveryId}`,
+ { type: 'ack', claimId: entry.claimId, receipt: entry.receipt, uncertain: false })
+ if (late) this.log(`Delivery ${entry.deliveryId} was acknowledged after the backend ended it, ${late.failures + 1} tries, ${Math.round((this.now() - late.since) / 60_000)} min.`)
+ return true
+ } catch (error) {
+ if (ackRefused(error)) return true
+ const retry = late ?? { failures: 0, retryAt: 0, since: now }
+ if (this.now() - retry.since >= LATE_ACK_GIVE_UP_MS) {
+ this.log(`Gave up acknowledging delivery ${entry.deliveryId} to agent ${entry.agentId} in Swarm ${entry.tabId} after a day: `
+ + `${error instanceof Error ? error.message : String(error)}. Its sender sees Not sent.`)
+ return true
+ }
+ retry.retryAt = this.now() + Math.min(LATE_ACK_RETRY_MAX_MS, LATE_ACK_RETRY_MS * 2 ** retry.failures++)
+ this.lateAcks.set(entry.deliveryId, retry)
+ return false
+ }
+ }
private async leases(): Promise<boolean> {
return this.core.turns.leaseDeliveries('superTabs', Object.fromEntries(this.authorized))
@@ -1320,6 +1367,7 @@ export class SuperTabHost {
if (!entry) return
const id = typedId(entry)
delete this.journal.entries[deliveryId]
+ this.lateAcks.delete(deliveryId)
this.withheld.clear(deliveryId)
this.authorized.delete(id)
if (this.active.delete(id)) this.core.turns.cancelDelivery(id)