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
452 changes: 452 additions & 0 deletions browser_tests/tests/agent/agentCanvasLagsToolCallCompletion.spec.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/scripts/api.logs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('api.getLogs', () => {
outcomes: {
received: 0,
applied: 0,
appliedLive: 0,
skipped: 0,
errored: 0,
gap: 0,
Expand Down
33 changes: 33 additions & 0 deletions src/workbench/extensions/agent/AgentPanelRoot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3569,6 +3569,39 @@ describe('AgentPanelRoot workflow binding', () => {
expect(activity.editingTabPath).toBe('workflows/current.json')
})

// PM-1575 regression: the canvas-sync gate was wired to
// `agentPanelStore.enabled` (the panel feature flag), not to whether a CRDT
// doc subscription is actually connected. This suite -- like
// agentPanel.spec.ts and most of this file -- never sends a
// `doc_subscribed` frame, so the follower never connects; with the wrong
// gate, a mutating tool call's own successful frame was held at
// 'streaming' forever, since nothing was ever going to call
// `notifyCanvasCaughtUp()` to release it. Asserted on the store's own part
// state rather than the "Working..." composing status text upstream uses,
// since that composing affordance doesn't exist on this branch yet.
it('settles a mutating tool call immediately when no CRDT doc subscription is connected', async () => {
makeTab('wf-42')
mockMessagesEndpoint('wf-42')

await renderAndSend('add a node')

ws.emit('agent_tool_call', {
tool_call_id: 'call-add-node',
tool_name: 'add_node',
status: 'success',
duration_ms: 90,
thread_id: 'th-1',
message_id: 'm-1'
})

await vi.waitFor(() => {
expect(useAgentConversationStore().messages[0].parts[0]).toMatchObject({
type: 'tool',
state: 'done'
})
})
})

it('moves the spinner to the tab the agent creates mid-turn', async () => {
makeTab('wf-42')
mockMessagesEndpoint('wf-42')
Expand Down
55 changes: 55 additions & 0 deletions src/workbench/extensions/agent/AgentPanelRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,52 @@ const { activeTurnId: conversationTurnId } = storeToRefs(
useAgentConversationStore()
)

// PM-1575: a chat tool-call's own `status` says nothing about whether its
// effect has actually reached the canvas -- the CRDT doc_update travels a
// separate, unrelated listener (see agentEventTransport.ts's file header).
// Gate the transport's tool-call "done" affordance on canvas catch-up only
// while the CRDT follower is actually active, and re-check any parts it held
// back every time the bound workflow applies a fresh update.
//
// `agentPanelStore.enabled` alone is NOT that signal: it is the product
// feature flag ("is the agent panel available at all"), which is on in any
// environment or test that exercises the panel, whether or not a CRDT doc
// subscription for the bound workflow actually exists yet. Gating on it
// alone deferred every mutating tool call (add_node, set_widget, ...) to
// 'streaming' even when no doc_subscribed frame had ever been received --
// e.g. in agentPanel.spec.ts and every other spec that drives chat events
// without also standing up a doc host -- so nothing was ever going to call
// notifyCanvasCaughtUp() to rescue it, and the row (and the composing
// "Working..." status derived from every part being settled) stayed stuck
// until the 30s STALE_AFTER_MS fallback. `crdtStatus.value.connected` is the
// actual "the follower is subscribed and could receive a doc_update" signal
// (flipped true only by a real `doc_subscribed { ok: true }` frame); a
// disabled panel never starts the follower, so this implies `enabled` too.
// Read `outcomes.appliedLive`, never `outcomes.applied`: `applied` also
// counts a subscribe's own one-time catch-up frame, which lands whenever the
// follower (re)subscribes to the bound workflow and has nothing to do with
// any tool call in flight. Gating on raw `applied` made the FIRST
// canvas-mutating tool call after any (re)subscribe -- effectively every
// tool call, since a `running` frame is never sent in practice, see
// agentEventTransport.ts's file header -- read that unrelated catch-up as
// its own matching update and settle to 'done' immediately, defeating the
// wait this gate exists for.
conversationStore.setCanvasSyncGate(
() => crdtStatus.value.connected,
() => crdtStatus.value.outcomes.appliedLive
)
watch(
() => crdtStatus.value.outcomes.appliedLive,
(applied, previouslyApplied) => {
// `useAgentCrdtFollower`'s status falls back to a disabled status with
// `applied: 0` when the follower is torn down, and a restarted follower
// counts from 0 again -- so toggling the panel mid-turn can drive this
// DOWN, not just up. A decrease is not a catch-up: nothing was applied,
// so it must not release parts that are still genuinely waiting.
if (applied > previouslyApplied) conversationStore.notifyCanvasCaughtUp()
}
)

// The resumed turn's own workflow outlives a panel remount (the session
// binds it at ack; only newChat/loadThread reset it), while the active tab
// may have changed since - prefer the bound tab over active-tab derivation.
Expand Down Expand Up @@ -848,6 +894,15 @@ onBeforeUnmount(() => {
tabActivity.setEditing(null)
tabActivity.setCreating(false)
agentMinimapLayer.dispose()
// PM-1575: the store singleton outlives this component. Without resetting
// the gate here, a remount's own setCanvasSyncGate() call is the only
// thing standing between the old (now torn-down) follower's gate and a
// turn resumed in the meantime reading it -- reset to the always-safe
// default instead of leaving whatever this instance last set.
conversationStore.setCanvasSyncGate(
() => false,
() => 0
)
})

const history = useAgentChatHistoryStore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const status: AgentCrdtStatus = {
outcomes: {
received: 1,
applied: 1,
appliedLive: 1,
skipped: 0,
errored: 0,
gap: 0,
Expand Down
1 change: 1 addition & 0 deletions src/workbench/extensions/agent/crdt/CrdtDevPanel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const STATUS: AgentCrdtStatus = {
outcomes: {
received: 5,
applied: 4,
appliedLive: 4,
skipped: 1,
errored: 0,
gap: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const SNAPSHOT: CrdtDebugSnapshot = {
outcomes: {
received: 3,
applied: 3,
appliedLive: 3,
skipped: 0,
errored: 0,
gap: 0,
Expand Down
19 changes: 19 additions & 0 deletions src/workbench/extensions/agent/crdt/useAgentCrdtFollower.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ describe('useAgentCrdtFollower', () => {
expect(status().outcomes).toEqual({
received: 1,
applied: 1,
appliedLive: 1,
skipped: 0,
errored: 0,
gap: 0,
Expand Down Expand Up @@ -802,6 +803,23 @@ describe('useAgentCrdtFollower', () => {
unmount()
})

it('counts appliedLive for a live update but not for a subscribe catch-up frame', () => {
const { unmount, status } = mountFollower('wf-1')

dispatchFrame('doc_update', { workflowId: 'wf-1', seq: 4, catchUp: true })
expect(status().outcomes.applied).toBe(1)
expect(status().outcomes.appliedLive).toBe(0)

dispatchFrame('doc_update', {
workflowId: 'wf-1',
seq: 5,
catchUp: false
})
expect(status().outcomes.applied).toBe(2)
expect(status().outcomes.appliedLive).toBe(1)
unmount()
})

it('accumulates received/applied/skipped across mixed frames without resetting on unrelated activity', () => {
const { unmount, status } = mountFollower('wf-1')

Expand All @@ -815,6 +833,7 @@ describe('useAgentCrdtFollower', () => {
expect(status().outcomes).toEqual({
received: 3,
applied: 2,
appliedLive: 2,
skipped: 1,
errored: 1,
gap: 1,
Expand Down
20 changes: 20 additions & 0 deletions src/workbench/extensions/agent/crdt/useAgentCrdtFollower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ interface AgentCrdtOutcomeCounters {
received: number
/** Passed this composable's own filter and the adapter had a bound session to apply it to. */
applied: number
/**
* PM-1575: same as `applied`, excluding a subscribe's own catch-up frame
* (`update.catchUp`) -- the one-time state-vector sync that lands whenever
* a workflow is (re)subscribed to, unrelated to any in-flight tool call.
* `applied` alone is unusable as a canvas-sync gate for that reason: a tool
* call's baseline, captured before that catch-up lands, would otherwise
* read the catch-up itself as "the matching update already arrived" for
* whichever tool call happens to be first after a (re)subscribe. Consumers
* that need "did a LIVE update land" (agentEventTransport.ts's canvas-sync
* baseline) must read this field, not `applied`.
*/
appliedLive: number
/** Received but not applied: inactive target, workflow mismatch, or no bound adapter session. */
skipped: number
/** The merged doc failed the KA-11 read gate (`schema_error`). */
Expand Down Expand Up @@ -335,6 +347,7 @@ export function useAgentCrdtFollower(
outcomes: {
received: 0,
applied: 0,
appliedLive: 0,
skipped: 0,
errored: 0,
gap: 0,
Expand Down Expand Up @@ -397,6 +410,7 @@ function startAgentCrdtFollower(
const outcomes = ref<AgentCrdtOutcomeCounters>({
received: 0,
applied: 0,
appliedLive: 0,
skipped: 0,
errored: 0,
gap: 0,
Expand Down Expand Up @@ -698,6 +712,12 @@ function startAgentCrdtFollower(
outcomes.value = applied
? { ...outcomes.value, applied: outcomes.value.applied + 1 }
: { ...outcomes.value, skipped: outcomes.value.skipped + 1 }
if (applied && !update.catchUp) {
outcomes.value = {
...outcomes.value,
appliedLive: outcomes.value.appliedLive + 1
}
}
const materialized = applied ? reconcileLiveGraph(update.workflowId) : []
recordDevEvent('doc_update', {
workflowId: update.workflowId,
Expand Down
Loading
Loading