Skip to content

Commit 075c4b6

Browse files
committed
fix(memory): stop cancelled memory reads before tails and provenance
1 parent 8f7f8f2 commit 075c4b6

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎apps/sim/lib/memory/application/use-cases.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,36 @@ describe('Memory application use cases', () => {
157157
)
158158
expect(mocks.readBoundProvenance).not.toHaveBeenCalled()
159159
})
160+
it('stops a list cancelled during its billing lookup before reading tails or provenance', async () => {
161+
queueTableRows(schemaMock.memory, [
162+
{
163+
id: 'memory-1',
164+
key: 'conversation-1',
165+
data: [],
166+
storageVersion: 2,
167+
secretProvenanceVersion: null,
168+
},
169+
])
170+
const controller = new AbortController()
171+
await expect(
172+
listMemoriesUseCase.execute({
173+
principal: ACTORLESS_DEPLOYED_PRINCIPAL,
174+
input: {
175+
workspaceId: WORKSPACE_ID,
176+
limit: 50,
177+
includePersistedSecretProvenance: true,
178+
signal: controller.signal,
179+
resolveBillingAttribution: async () => {
180+
controller.abort(new Error('cancelled'))
181+
return BILLING_ATTRIBUTION
182+
},
183+
},
184+
})
185+
).rejects.toThrow('cancelled')
186+
expect(mocks.readPlainMemoryTail).not.toHaveBeenCalled()
187+
expect(mocks.readBoundProvenance).not.toHaveBeenCalled()
188+
})
189+
160190
it('enforces one appended-history budget across the entire list response', async () => {
161191
queueTableRows(
162192
schemaMock.memory,

‎apps/sim/lib/memory/application/use-cases.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ async function readMemoryResults(
137137
input.resolveBillingAttribution
138138
)))
139139
: undefined
140+
input.signal?.throwIfAborted()
140141
const records: MemoryRecord[] = []
141142
const readProvenance: MemoryReadProvenance[] = []
142143
const tailBudget = new PlainMemoryReadBudget()
@@ -145,6 +146,7 @@ async function readMemoryResults(
145146
? readBoundMemorySecretProvenance({ ...record, provenanceContentHash, status, entries })
146147
: undefined
147148
if (record.storageVersion === 2) {
149+
input.signal?.throwIfAborted()
148150
const tail = await readPlainMemoryTail(record.id, workspaceId, tailBudget)
149151
record.data = [
150152
...(Array.isArray(record.data) ? record.data : [record.data]),

0 commit comments

Comments
 (0)