Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/workbench/extensions/agent/AgentPanelRoot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11425,11 +11425,46 @@ describe('AgentPanelRoot workflow binding', () => {
seq: 1
})

vi.mocked(reportError).mockClear()
agentSocket.drop()
await sendFromComposer('second message')

expect(bodies[1]).toHaveProperty('workflow_id', 'wf-42')
expect(bodies[1]).not.toHaveProperty('draft')
expect(reportError).toHaveBeenCalledTimes(1)
expect(reportError).toHaveBeenCalledWith(expect.any(Error), {
surface: 'agent',
errorType: 'agent_canvas_draft_withheld_stale',
level: 'warning',
tags: {
failure_kind: 'bad_state',
feature_area: 'agent',
operation: 'send',
outcome: 'withheld'
},
context: { workflowId: 'wf-42' }
})
})

it('reports nothing when a connected canvas sends its draft', async () => {
const bodies = await bindAndSettle()
ws.emit('doc_subscribed', {
v: 1,
workflow_id: 'wf-42',
ok: true,
seq: 1
})
vi.mocked(reportError).mockClear()

await sendFromComposer('second message')

expect(bodies[1]).toHaveProperty('draft')
expect(reportError).not.toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
errorType: 'agent_canvas_draft_withheld_stale'
})
)
})

it('seeds the draft for a bound document while the agent identity is still pending', async () => {
Expand Down
22 changes: 21 additions & 1 deletion src/workbench/extensions/agent/AgentPanelRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -801,12 +801,32 @@ function targetWorkflowDraft(origin?: TurnOrigin): DraftSnapshot | undefined {
if (workflowDetached.value) return undefined
const target = originWorkflow(origin)
if (!target) return undefined
if (canvasMissedDocumentFrames(cloudIdFor(target))) return undefined
const documentId = cloudIdFor(target)
if (canvasMissedDocumentFrames(documentId)) {
if (target.activeState) reportWithheldDraft(documentId)
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
return undefined
}
const content = serializedCanvas(target)
if (!content) return undefined
return { content }
}

function reportWithheldDraft(workflowId: string | undefined): void {
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
const errorType = 'agent_canvas_draft_withheld_stale'
reportError(new Error('agent canvas draft withheld: canvas may be stale'), {
surface: 'agent',
errorType,
level: 'warning',
tags: {
failure_kind: 'bad_state',
feature_area: 'agent',
operation: 'send',
outcome: 'withheld'
},
context: { workflowId }
})
}

function canvasMissedDocumentFrames(documentId: string | undefined): boolean {
return (
documentId !== undefined &&
Expand Down
Loading