From ded0588d3a7c2aeab4bfa95d826d620e66c96562 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Thu, 24 Sep 2026 09:05:22 +0000 Subject: [PATCH 1/6] test: repro input garbling on an agent-created multiline text node (PM-1673) Typing into a PrimitiveStringMultiline the agent created garbles the input after the turn has finished. The doc binding and widgetMintPort outlive the turn, so every keystroke mints a set_widget op the host broadcasts back; the setWidget case in graphMutations writes it straight through setWidgetValue without consulting skipStaleReconcile, and WidgetGrid's v-model then patches el.value on the focused textarea, collapsing the caret. Adds two cases against the recorded agent-l4-zimage-string-node-prompt run: the per-keystroke round trip itself (passes, states the premise), and one deliberately stale echo landing mid-keystroke (test.fail, the defect). Exposes hostWidgetValue on the harness and reuses it in resyncWidget. --- .../fixtures/agentConversationFixture.ts | 15 +- .../agentMultilineTextEchoGarbling.spec.ts | 171 ++++++++++++++++++ 2 files changed, 181 insertions(+), 5 deletions(-) create mode 100644 browser_tests/tests/agent/agentMultilineTextEchoGarbling.spec.ts diff --git a/browser_tests/fixtures/agentConversationFixture.ts b/browser_tests/fixtures/agentConversationFixture.ts index b925e3cd630..698adc18b6a 100644 --- a/browser_tests/fixtures/agentConversationFixture.ts +++ b/browser_tests/fixtures/agentConversationFixture.ts @@ -685,6 +685,15 @@ export class AgentConversationHarness { return Object.keys(this.host.graph().nodes) } + /** What the host document holds for one widget; undefined when it has none. */ + hostWidgetValue(nodeId: string, widget: string): unknown { + const widgets = z + .record(z.string(), z.unknown()) + .optional() + .parse(this.host.graph().nodes[nodeId]?.widgets) + return widgets?.[widget] + } + // A host-side edit outside the recording, pushed as one `doc_update`. The // follower applies frames in order, so a rendered effect of this edit // proves every earlier frame (a catch-up included) has been applied too. @@ -922,11 +931,7 @@ export class AgentConversationHarness { } async resyncWidget(nodeId: string, widget: string): Promise { - const widgets = z - .record(z.string(), z.unknown()) - .optional() - .parse(this.host.graph().nodes[nodeId]?.widgets) - const value = widgets?.[widget] + const value = this.hostWidgetValue(nodeId, widget) if (value === undefined) throw new Error(`Host widget ${nodeId}.${widget} does not exist`) const operation = { diff --git a/browser_tests/tests/agent/agentMultilineTextEchoGarbling.spec.ts b/browser_tests/tests/agent/agentMultilineTextEchoGarbling.spec.ts new file mode 100644 index 00000000000..5db009f0212 --- /dev/null +++ b/browser_tests/tests/agent/agentMultilineTextEchoGarbling.spec.ts @@ -0,0 +1,171 @@ +import { expect } from '@playwright/test' + +import { agentConversationTest as test } from '@e2e/fixtures/agentConversationFixture' + +/** + * PM-1673: typing into an agent-created multiline text node garbles the input + * after the agent turn has finished. Three properties of the report shape + * these tests: the turn was over (no agent write was in flight), the node is a + * plain `PrimitiveStringMultiline` rather than the `CLIPTextEncode` prompt + * widget PM-1191 is scoped to, and it was first seen on prod, where the round + * trip to the doc host is far slower than in any local run. + * + * The recorded case is a real run in which the agent adds a + * `PrimitiveStringMultiline` and sets its `value` widget - the generic + * multiline text node the report names, reached the way the reporter reached + * it. + * + * `humanOpsHost: 'apply'` is what makes these tests about the reported bug + * rather than about an injected frame: the fake host judges and broadcasts + * every op the page mints, so the page's own keystrokes come back to it as + * `doc_update` frames exactly as prod's doc host returns them. + */ +const CASE = 'agent-l4-zimage-string-node-prompt' +const TEXT_NODE_ID = '3876406316923056' +const TEXT_WIDGET = 'value' +const AGENT_VALUE = 'a red bicycle on a pier at dusk' + +// Slow enough that each keystroke's own echo lands before the next one, so a +// spontaneous echo collision cannot decide these tests. The defect needs a +// frame that is stale when it applies, and the only one here is delivered +// deliberately. +const SETTLED_KEYSTROKE_MS = 300 + +test.describe( + 'Agent-created multiline text node accepts typing after the turn ends (PM-1673)', + { tag: ['@cloud', '@agent', '@widget', '@vue-nodes'] }, + () => { + test.use({ conversationCase: CASE, humanOpsHost: 'apply' }) + + /** + * The premise behind the report. Once the agent has bound a doc to this + * workflow the binding outlives the turn - `shouldMint` consults only the + * product flag, the doc binding and teardown, never whether a turn is + * running - so `widgetMintPort` mints a `set_widget` op off the + * `widgetValueStore` `setValue` seam on every keystroke. A user typing + * into an agent-created widget while the agent sits idle is still driving + * a write/echo round trip per character, which is why "the agent turn + * looked over" does not rule out a CRDT race. + */ + test('each keystroke after the turn still round-trips through the CRDT host', async ({ + agentConversation + }) => { + test.setTimeout(90_000) + await agentConversation.runTurns() + + const field = agentConversation.vueNodes + .getNodeLocator(TEXT_NODE_ID) + .getByLabel(TEXT_WIDGET, { exact: true }) + await expect(field).toHaveValue(AGENT_VALUE) + + await field.click() + // Not `End`: the value wraps across two visual lines at this node's + // width, and `End` stops at the end of the wrapped line it is on. + await field.press('ControlOrMeta+End') + await field.pressSequentially('!!', { delay: SETTLED_KEYSTROKE_MS }) + + const outcomes = await agentConversation.waitForHumanOps(2) + expect( + outcomes.filter((outcome) => outcome.outcome === 'rejected') + ).toEqual([]) + // The document itself moved, so the round trip is real rather than a + // frame the page sent and dropped. + expect(agentConversation.hostWidgetValue(TEXT_NODE_ID, TEXT_WIDGET)).toBe( + `${AGENT_VALUE}!!` + ) + await expect(field).toHaveValue(`${AGENT_VALUE}!!`) + }) + + /** + * The defect. One of those per-keystroke round trips comes back late - on + * prod that is the latency to the doc host; here one frame is delivered + * deliberately, carrying the value as of an earlier keystroke. + * `graphMutations`' `setWidget` case, which is the op shape an echo + * arrives as, calls `setWidgetValue` directly and never consults + * `skipStaleReconcile`, so the stale value is written over the newer live + * one. That guard is reached only from `applyWidgetValues` with + * `guardLocalEdits` set, which only `reconcileNode` passes. + * + * `WidgetGrid.vue` binds the textarea's `model-value` straight at + * `widgetValueStore`'s value with no local edit buffer, so the store write + * reaches the focused `