Skip to content

The agent that grows with you

test(desktop): sampler fails a transiently misordered transcript

Brooklyn Nicholson72103912e0dd
diff --git a/apps/desktop/e2e/core/README.md b/apps/desktop/e2e/core/README.md
index 6f6a1a87780..9d6c2b2bcd8 100644
--- a/apps/desktop/e2e/core/README.md
+++ b/apps/desktop/e2e/core/README.md
@@ -14,6 +14,9 @@ A small, deterministic Electron suite that guards three issue classes end to end
- no marker is ever rendered twice, even transiently (in-page
MutationObserver sampler — the #120005 garble healed on its own in the
final DOM, so a final-state check alone misses it);
+ - no message is ever rendered out of order, even transiently: the same
+ sampler fails a reply above its own prompt and two messages that swap
+ places between frames;
- backend stream integrity: each turn's concatenated `message.delta` /
`reasoning.delta` equals what the provider streamed, and
`message.complete` equals the final completion.
diff --git a/apps/desktop/e2e/core/oracle.ts b/apps/desktop/e2e/core/oracle.ts
index 357d7c32a98..dc208c68c85 100644
--- a/apps/desktop/e2e/core/oracle.ts
+++ b/apps/desktop/e2e/core/oracle.ts
@@ -14,8 +14,9 @@
* renderer groups bubbles (live vs hydrated grouping legitimately differs).
*
* Final-state checks converge with a deadline (hydration is asynchronous);
- * transient duplicates are caught separately by an in-page MutationObserver
- * sampler that is never allowed to see a marker twice.
+ * transient faults are caught separately by an in-page MutationObserver
+ * sampler that is never allowed to see a marker twice, a reply above its own
+ * prompt, or two messages swap places between frames.
*/
import { expect, type Page } from '@playwright/test'
@@ -54,7 +55,7 @@ export function userMarkerFor(marker: string): string {
return marker.replace(/^[AR](\d+)i?-/, 'U$1-')
}
-// ─── Transient-duplicate sampler ────────────────────────────────────────
+// ─── Transient duplicate / order sampler ────────────────────────────────
/** Idempotent; re-run after every reload (the observer dies with the document). */
export async function installDuplicateSampler(page: Page): Promise<void> {
@@ -66,9 +67,26 @@ export async function installDuplicateSampler(page: Page): Promise<void> {
}
const re = new RegExp(source, 'g')
- w.__coreSampler = { samples: 0, violations: [] as { marker: string; count: number; text: string }[] }
+ w.__coreSampler = {
+ samples: 0,
+ violations: [] as { marker: string; count: number; text: string }[],
+ order: [] as { detail: string; text: string }[]
+ }
+ // "x|y": x has been seen above y. A later frame with y above x is a flip.
+ const above = new Set<string>()
let scheduled = false
+ const orderViolation = (detail: string, text: string) => {
+ if (w.__coreSampler.order.length < 20) {
+ w.__coreSampler.order.push({
+ detail,
+ at: Math.round(performance.now()),
+ route: location.hash,
+ text: text.replace(/\s+/g, ' ').slice(0, 600)
+ })
+ }
+ }
+
const sample = () => {
scheduled = false
const viewports = [...document.querySelectorAll('[data-slot="aui_thread-viewport"]')] as HTMLElement[]
@@ -86,6 +104,26 @@ export async function installDuplicateSampler(page: Page): Promise<void> {
counts.set(match, (counts.get(match) ?? 0) + 1)
}
+ // Message order, top to bottom by first appearance. Reasoning is left
+ // out: live and history place the thinking block differently.
+ const sequence = [...counts.keys()].filter(marker => !marker.startsWith('R'))
+
+ sequence.forEach((marker, index) => {
+ const prompt = marker.replace(/^A(\d+)i?-/, 'U$1-')
+
+ if (prompt !== marker && sequence.indexOf(prompt) > index) {
+ orderViolation(`reply ${marker} rendered above its prompt ${prompt}`, text)
+ }
+
+ for (const later of sequence.slice(index + 1)) {
+ if (above.has(`${later}|${marker}`)) {
+ orderViolation(`${marker} moved above ${later}`, text)
+ }
+
+ above.add(`${marker}|${later}`)
+ }
+ })
+
for (const [marker, count] of counts) {
if (count > 1 && w.__coreSampler.violations.length < 20) {
// Where the copies live: one bubble with doubled text vs two bubbles.
@@ -121,8 +159,8 @@ export async function installDuplicateSampler(page: Page): Promise<void> {
}, ANY_MARKER_RE.source)
}
-async function samplerViolations(page: Page): Promise<{ samples: number; violations: any[] }> {
- return page.evaluate(() => (window as any).__coreSampler ?? { samples: 0, violations: [] })
+async function samplerViolations(page: Page): Promise<{ order: any[]; samples: number; violations: any[] }> {
+ return page.evaluate(() => (window as any).__coreSampler ?? { order: [], samples: 0, violations: [] })
}
// ─── Rendered view ──────────────────────────────────────────────────────
@@ -475,4 +513,5 @@ export async function assertTranscriptOracle(
expect(transient.violations, `transient duplicate render during [${label}] (${transient.samples} samples)`).toEqual(
[]
)
+ expect(transient.order, `transient misordered render during [${label}] (${transient.samples} samples)`).toEqual([])
}