feat(agent)!: suppress success comments for autofill and embedding agents (#510)

* feat(agent)!: suppress success comments for autofill and embedding agents

* fix(agent): ensure createCommentActivity runs on workflow cancellation
This commit is contained in:
Yiling-J
2026-10-31 12:02:30 +08:00
committed by GitHub
parent 77bd1422d8
commit ff3d71ed3d
11 changed files with 343 additions and 185 deletions
+23 -1
View File
@@ -23,7 +23,7 @@ import {
import * as piAgent from '../index'
import { type AgentHarness, type Session } from '@earendil-works/pi-agent-core'
import { DatabaseSessionStorage, type DatabaseSessionMetadata } from '../database-session-storage'
import { triggerLocalCancel, runInLocalTaskContext } from '@shumai/workflow-core'
import { triggerLocalCancel, runInLocalTaskContext, DBOS, DBOSError } from '@shumai/workflow-core'
import { logger } from '@shumai/core/src/logger'
import {
@@ -1240,6 +1240,28 @@ describe('Agent Database Activities Integration', () => {
const deleted = await prisma.assetComment.findUnique({ where: { id: comment.id } })
expect(deleted).toBeNull()
})
it('should create comment even if cancelled with DBOSWorkflowCancelledError (runOnCancel: true)', async () => {
const realCancelErr = new DBOSError.DBOSWorkflowCancelledError('test-workflow-id')
const isWithinWorkflowSpy = vi.spyOn(DBOS, 'isWithinWorkflow').mockReturnValue(true)
const runStepSpy = vi.spyOn(DBOS, 'runStep').mockRejectedValue(realCancelErr)
const comment = await createCommentActivity({
assetId: asset.id,
message: 'Autofill failed: workflow cancelled',
agentId: 'default',
})
expect(comment.id).toBeDefined()
expect(comment.message).toBe('Autofill failed: workflow cancelled')
const savedComment = await prisma.assetComment.findUnique({ where: { id: comment.id } })
expect(savedComment).not.toBeNull()
expect(savedComment?.message).toBe('Autofill failed: workflow cancelled')
isWithinWorkflowSpy.mockRestore()
runStepSpy.mockRestore()
})
})
describe('Context Retrievals', () => {