Repository navigation
fix: checkpoint handled inbox events before turn completion (TASK-481) #2647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
20dda58
fix: checkpoint handled inbox events before turn completion (TASK-481)
lilyshen0722 d7dac9c
fix: defer inbox checkpoints for undelivered final-text replies
lilyshen0722 987c4fc
fix: stop inbox delivery renewal at the turn deadline
lilyshen0722 96bd72c
fix: bound inbox renewal request size
lilyshen0722 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
backend/__tests__/unit/services/agentEventService.renewDelivery.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| const mongoose = require('mongoose'); | ||
| const { setupMongoDb, closeMongoDb, clearMongoDb } = require('../../utils/testUtils'); | ||
| const AgentEvent = require('../../../models/AgentEvent'); | ||
| const AgentEventService = require('../../../services/agentEventService'); | ||
|
|
||
| describe('live inbox delivery renewal', () => { | ||
| beforeAll(setupMongoDb); | ||
| afterAll(closeMongoDb); | ||
| afterEach(clearMongoDb); | ||
|
|
||
| const delivery = async (fields = {}) => { | ||
| const row = { _id: new mongoose.Types.ObjectId(), agentName: 'wren', instanceId: 'default', | ||
| podId: new mongoose.Types.ObjectId(), type: 'chat.mention', status: 'delivered', attempts: 1, | ||
| deliveryNonce: 'current-nonce', deliveredAt: new Date('2026-01-01'), createdAt: new Date(), ...fields }; | ||
| await AgentEvent.collection.insertOne(row); | ||
| return row; | ||
| }; | ||
|
|
||
| test('extends only current delivery time, without acking or spending another attempt', async () => { | ||
| const row = await delivery(); | ||
| expect(await AgentEventService.renewDelivery(String(row._id), 'Wren', 'default', 'current-nonce')).toBe(true); | ||
| const after = await AgentEvent.findById(row._id).lean(); | ||
| expect(after.status).toBe('delivered'); | ||
| expect(after.deliveryNonce).toBe('current-nonce'); | ||
| expect(after.attempts).toBe(1); | ||
| expect(after.deliveredAt.getTime()).toBeGreaterThan(row.deliveredAt.getTime()); | ||
| }); | ||
|
|
||
| test('GC requeues only two unfinished events after three durable checkpoints', async () => { | ||
| const rows = []; | ||
| for (let i = 0; i < 5; i += 1) rows.push(await delivery()); | ||
| for (const row of rows.slice(0, 3)) { | ||
| expect(await AgentEventService.acknowledge(String(row._id), 'wren', 'default', | ||
| { outcome: 'acknowledged', reason: 'handled-checkpoint' }, 'current-nonce', 'mcp')).not.toBeNull(); | ||
| } | ||
| await AgentEventService.garbageCollect(); | ||
| const pending = await AgentEvent.find({ status: 'pending' }).lean(); | ||
| expect(pending.map((row) => String(row._id)).sort()).toEqual(rows.slice(3).map((row) => String(row._id)).sort()); | ||
| expect(await AgentEvent.countDocuments({ status: 'acked' })).toBe(3); | ||
| }); | ||
|
|
||
| test('a renewed live delivery survives the actual stale-delivery GC', async () => { | ||
| const row = await delivery(); | ||
| await AgentEventService.renewDelivery(String(row._id), 'wren', 'default', 'current-nonce'); | ||
| await AgentEventService.garbageCollect(); | ||
| expect((await AgentEvent.findById(row._id).lean()).status).toBe('delivered'); | ||
| }); | ||
|
|
||
| test.each([ | ||
| ['other-seat', 'default', 'current-nonce'], ['wren', 'another-instance', 'current-nonce'], | ||
| ['wren', 'default', 'old-nonce'], ['wren', 'default', ''], | ||
| ])('refuses wrong identity or nonce (%s/%s/%s)', async (agent, instance, nonce) => { | ||
| const row = await delivery(); | ||
| expect(await AgentEventService.renewDelivery(String(row._id), agent, instance, nonce)).toBe(false); | ||
| expect((await AgentEvent.findById(row._id).lean()).deliveredAt).toEqual(row.deliveredAt); | ||
| }); | ||
|
|
||
| test.each(['pending', 'acked', 'failed'])('does not revive a %s event', async (status) => { | ||
| const row = await delivery({ status }); | ||
| expect(await AgentEventService.renewDelivery(String(row._id), 'wren', 'default', 'current-nonce')).toBe(false); | ||
| expect((await AgentEvent.findById(row._id).lean()).status).toBe(status); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.