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
3 changes: 3 additions & 0 deletions src/workbench/extensions/agent/crdt/devPanelLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const DEV_EVENT_KINDS = [
'doc_subscribed',
'doc_update',
'doc_ops_result',
'doc_ops_result_dropped',
'human_ops_settled',
'doc_reset',
'doc_nodes_changed',
Expand Down Expand Up @@ -106,6 +107,7 @@ const STRUCTURAL_STRING_KEYS = new Set([
'outcome',
'phase',
'prompt_id',
'reason',
'removed',
'scope',
'seq',
Expand All @@ -114,6 +116,7 @@ const STRUCTURAL_STRING_KEYS = new Set([
'source',
'state',
'status',
'subscribed_workflow_id',
'tab',
'tab_id',
'target',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ vi.mock<unknown>(import('./agentCrdtProjection'), () => ({
}
}))

vi.mock(import('./devPanelLog'), () => ({
recordDevEvent: vi.fn(),
sanitizeDevEventDetail: vi.fn((detail: unknown) => detail)
}))
vi.mock(import('./devPanelLog'), { spy: true })

vi.mock(import('@/platform/telemetry/reportError'), () => ({
reportError: telemetryState.reportError
Expand All @@ -158,6 +155,7 @@ vi.mock<unknown>(import('@/scripts/app'), () => ({
}))

import { SUBSCRIBE_ACK_TIMEOUT_MS } from './agentCrdtDocLifecycle'
import { clearDevEvents, devEvents } from './devPanelLog'
import {
STALE_AFTER_MS,
SUBSCRIBE_CATCHUP_GRACE_MS,
Expand Down Expand Up @@ -650,6 +648,49 @@ describe('useAgentCrdtFollower', () => {
unmount()
})

it('logs each dropped op result with its reason, subscribed target, and frame', async () => {
clearDevEvents()
const { workflowId, isTargetActive, unmount } = mountFollower('wf-1')
dispatchFrame('doc_subscribed', { ok: true })
const staleFailure = {
workflowId: 'wf-2',
ok: false,
skipped: ['op-2'],
failed: { op_id: 'op-2', code: 'unknown_node' }
}

dispatchFrame('doc_ops_result', staleFailure)
workflowId.value = 'wf-2'
await nextTick()
dispatchFrame('doc_ops_result', { workflowId: 'wf-1', ok: true })
isTargetActive.value = false
await nextTick()
dispatchFrame('doc_ops_result', { workflowId: 'wf-2', ok: true })

expect(
devEvents.value
.filter((event) => event.kind === 'doc_ops_result_dropped')
.map((event) => event.detail)
).toEqual([
{
reason: 'workflow_mismatch',
subscribedWorkflowId: 'wf-1',
frame: staleFailure
},
{
reason: 'workflow_mismatch',
subscribedWorkflowId: 'wf-2',
frame: { workflowId: 'wf-1', ok: true }
},
{
reason: 'inactive_target',
subscribedWorkflowId: 'wf-2',
frame: { workflowId: 'wf-2', ok: true }
}
])
unmount()
})

it('FEC-5: an idle doc still expires', () => {
vi.useFakeTimers()
const setup = mountFollower('wf-1')
Expand Down
25 changes: 22 additions & 3 deletions src/workbench/extensions/agent/crdt/useAgentCrdtFollower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ export interface AgentCrdtStatus {
outcomes: AgentCrdtOutcomeCounters
}

type OpsResultDropReason = 'inactive_target' | 'workflow_mismatch'

function opsResultDropReason(
active: boolean,
workflowId: unknown,
subscribedWorkflowId: string | null
): OpsResultDropReason | null {
if (!active) return 'inactive_target'
return workflowId === subscribedWorkflowId ? null : 'workflow_mismatch'
}

export interface AgentCrdtFollowerEvents {
onMaterialized?: (event: {
workflowId: string
Expand Down Expand Up @@ -618,11 +629,19 @@ function startAgentCrdtFollower(
const onOpsResult: EventListener = (event) => {
if (!(event instanceof CustomEvent)) return
const detail = event.detail as { workflowId?: unknown } | null
if (
!isTargetActive.value ||
detail?.workflowId !== subscribedWorkflowId.value
const dropReason = opsResultDropReason(
isTargetActive.value,
detail?.workflowId,
subscribedWorkflowId.value
)
if (dropReason !== null) {
recordDevEvent('doc_ops_result_dropped', {
reason: dropReason,
subscribedWorkflowId: subscribedWorkflowId.value,
frame: event.detail ?? null
})
return
}
lifecycle.onDocumentResult()
lastFrameType.value = event.type
recordDevEvent('doc_ops_result', event.detail ?? null)
Expand Down
Loading