From e7f62974f0b844b3955ca91e0c013cb888013329 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Wed, 18 Mar 2026 16:07:54 -0400 Subject: [PATCH] fix(pubsub): remove messages from leasing on nackWithResponse --- handwritten/pubsub/src/subscriber.ts | 2 ++ handwritten/pubsub/test/subscriber.ts | 24 ++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/handwritten/pubsub/src/subscriber.ts b/handwritten/pubsub/src/subscriber.ts index a08dc6d6646..46834636e1b 100644 --- a/handwritten/pubsub/src/subscriber.ts +++ b/handwritten/pubsub/src/subscriber.ts @@ -1163,6 +1163,8 @@ export class Subscriber extends EventEmitter { const response = await this.modAckWithResponse(message, 0); message.subSpans.nackEnd(); message.endParentSpan(); + this._inventory.remove(message); + return response; } diff --git a/handwritten/pubsub/test/subscriber.ts b/handwritten/pubsub/test/subscriber.ts index 5cf205cfd9b..d06bdb26efc 100644 --- a/handwritten/pubsub/test/subscriber.ts +++ b/handwritten/pubsub/test/subscriber.ts @@ -918,7 +918,7 @@ describe('Subscriber', () => { }); describe('nack', () => { - it('should modAck the message with a 0 deadline', async () => { + it('should modAck the message with a 0 deadline (nack)', async () => { const stub = sandbox.stub(subscriber, 'modAck'); await subscriber.nack(message); @@ -929,6 +929,17 @@ describe('Subscriber', () => { assert.strictEqual(deadline, 0); }); + it('should modAck the message with a 0 deadline (nackWithResponse)', async () => { + const stub = sandbox.stub(subscriber, 'modAckWithResponse'); + + await subscriber.nackWithResponse(message); + + const [msg, deadline] = stub.lastCall.args; + + assert.strictEqual(msg, message); + assert.strictEqual(deadline, 0); + }); + it('should log on ack completion', async () => { fakeLog = new FakeLog(s.logs.ackNack); @@ -942,7 +953,7 @@ describe('Subscriber', () => { assert.strictEqual(fakeLog.args![1], message.id); }); - it('should remove the message from the inventory', async () => { + it('should remove the message from the inventory (nack)', async () => { const inventory: FakeLeaseManager = stubs.get('inventory'); const stub = sandbox.stub(inventory, 'remove').withArgs(message); @@ -950,6 +961,15 @@ describe('Subscriber', () => { assert.strictEqual(stub.callCount, 1); }); + + it('should remove the message from the inventory (nackWithResponse)', async () => { + const inventory: FakeLeaseManager = stubs.get('inventory'); + const stub = sandbox.stub(inventory, 'remove').withArgs(message); + + await subscriber.nackWithResponse(message); + + assert.strictEqual(stub.callCount, 1); + }); }); describe('open', () => {