fix(inbox): a failed PUT no longer lets the next message overtake it (4.13.1)
Some checks failed
Docker build and publish / docker (push) Has been cancelled
Publish / publish (push) Has been cancelled
Cross-platform vectors / TypeScript vectors (bun) (push) Has been cancelled
Cross-platform vectors / Kotlin vectors (gradle) (push) Has been cancelled
Test / test (push) Has been cancelled
Some checks failed
Docker build and publish / docker (push) Has been cancelled
Publish / publish (push) Has been cancelled
Cross-platform vectors / TypeScript vectors (bun) (push) Has been cancelled
Cross-platform vectors / Kotlin vectors (gradle) (push) Has been cancelled
Test / test (push) Has been cancelled
flushOnce drained a recipient's bucket in order but carried on past a failure, delivering N+1 before N's retry. For sender-key broadcasts the receiver cannot open N once past it — frozen terminal output in Prism. Stop the bucket at the first failure; other recipients still drain in parallel. Also corrects senderKeyDecrypt's doc, which claimed a skipped-key cache that never existed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -467,6 +467,58 @@ describe('Inbox orchestrator', () => {
|
||||
await aliceInbox.tick();
|
||||
expect(await aliceInbox.pendingCount()).toBe(0);
|
||||
});
|
||||
|
||||
test('a failed PUT holds back the rest of its recipient\'s queue, so order survives the retry', async () => {
|
||||
const store = new MemoryInboxStore();
|
||||
const app = createInboxServer({ crypto, store, disableRateLimit: true });
|
||||
const alice = await makeIdentity();
|
||||
const bob = await makeIdentity();
|
||||
const bobClient = new InboxClient({
|
||||
baseUrl: 'http://localhost',
|
||||
crypto,
|
||||
signingPrivateKey: bob.signingPrivateKey,
|
||||
fetch: honoFetch(app),
|
||||
});
|
||||
await bobClient.register({ address: 'bob', signingKey: bob.signingPublicKey });
|
||||
|
||||
// The FIRST PUT fails once. Before the fix the second envelope was
|
||||
// delivered in the same round and the first only on the retry —
|
||||
// bob received them in the wrong order.
|
||||
let failsLeft = 1;
|
||||
const flakyFetch: typeof fetch = (async (input, init) => {
|
||||
const m = (init as RequestInit | undefined)?.method ?? 'GET';
|
||||
const u = typeof input === 'string' ? input : input instanceof URL ? input.toString() : (input as Request).url;
|
||||
if (m === 'POST' && u.includes('/v1/inbox/bob') && !u.includes('/fetch') && failsLeft > 0) {
|
||||
failsLeft--;
|
||||
throw new Error('transient network');
|
||||
}
|
||||
return honoFetch(app)(input, init);
|
||||
}) as typeof fetch;
|
||||
|
||||
const aliceInbox = new Inbox({
|
||||
baseUrl: 'http://localhost',
|
||||
ownAddress: 'alice',
|
||||
crypto,
|
||||
signingPrivateKey: alice.signingPrivateKey,
|
||||
signingPublicKey: alice.signingPublicKey,
|
||||
pollIntervalMs: 0,
|
||||
fetch: flakyFetch,
|
||||
queueStore: new MemoryOutgoingQueueStore(),
|
||||
});
|
||||
const delivered: string[] = [];
|
||||
aliceInbox.on((e) => {
|
||||
if (e.name === 'inbox.message_delivered') delivered.push(e.data.msgId);
|
||||
});
|
||||
|
||||
const first = await aliceInbox.send({ recipientAddress: 'bob', envelope: randBytes(40) });
|
||||
const second = await aliceInbox.send({ recipientAddress: 'bob', envelope: randBytes(40) });
|
||||
|
||||
await aliceInbox.tick();
|
||||
expect(delivered).toEqual([]);
|
||||
expect(await aliceInbox.pendingCount()).toBe(2);
|
||||
await aliceInbox.tick();
|
||||
expect(delivered).toEqual([first, second]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('tamper detection', () => {
|
||||
|
||||
Reference in New Issue
Block a user