Skip to content

Commit dc93ea6

Browse files
authored
fix(qa): follow durable finals after streamed previews (#119378)
* test(qa): isolate memory scenario evidence * test(qa): follow durable progress completion * test(qa): run doctor migration noninteractively * test(qa): split active memory follow-up * test(qa): wait for preview retirement * test(qa): require ordered preview retirement * test(qa): record ordered durable reply evidence * test(qa): preserve durable delivery budgets * test(qa): isolate durable lifecycle by account * test(qa): scope durable reply assertions by account * test(qa): preserve durable conversation identity
1 parent 1aeecb9 commit dc93ea6

3 files changed

Lines changed: 185 additions & 28 deletions

File tree

‎extensions/qa-lab/src/scenario-catalog-causality.test.ts‎

Lines changed: 124 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { describe, expect, it } from "vitest";
2+
import { createQaBusState } from "./bus-state.js";
23
import { readQaScenarioById, readQaScenarioExecutionConfig } from "./scenario-catalog.js";
34
import { readFlowAssertExpression, requireFlowScenario } from "./scenario-catalog.test-utils.js";
5+
import { runLoadedScenarioFlow } from "./scenario-flow-runner.test-support.js";
46

57
describe("qa scenario catalog causality", () => {
68
it("loads live gateway sentinel scenarios for harness self-health", () => {
@@ -144,24 +146,30 @@ describe("qa scenario catalog causality", () => {
144146
"thread-memory-isolation",
145147
"poll",
146148
"finalRequest.toolOutputCallId === searchResultRequest.plannedToolCallId",
149+
null,
147150
],
148151
[
149152
"memory-tools-channel-context",
150153
"poll",
151154
"finalRequest.toolOutputCallId === searchResultRequest.plannedToolCallId",
155+
"durableChannelLifecycle",
152156
],
153157
[
154158
"agent-tool-consumption",
155159
"immediate",
156160
"getResultRequest.toolOutputCallId === searchResultRequest.plannedToolCallId",
161+
null,
157162
],
158163
] as const)(
159164
"asserts the complete memory tool chain before %s delivery",
160-
(scenarioId, requestCollectionMode, finalLinkNeedle) => {
165+
(scenarioId, requestCollectionMode, finalLinkNeedle, durableWaitSaveAs) => {
161166
const scenario = requireFlowScenario(readQaScenarioById(scenarioId));
162167
const actions = scenario.execution.flow?.steps[0]?.actions ?? [];
163-
const outboundIndex = actions.findIndex(
164-
(action) => (action as { call?: string }).call === "waitForOutboundMessage",
168+
const outboundIndex = actions.findIndex((action) =>
169+
durableWaitSaveAs
170+
? (action as { call?: string }).call === "waitForCondition" &&
171+
(action as { saveAs?: string }).saveAs === durableWaitSaveAs
172+
: (action as { call?: string }).call === "waitForOutboundMessage",
165173
);
166174
const requestCollectionIndex = actions.findIndex((action) =>
167175
requestCollectionMode === "poll"
@@ -193,6 +201,15 @@ describe("qa scenario catalog causality", () => {
193201
expect(finalRequestAssertIndex, scenarioId).toBeGreaterThan(searchResultAssertIndex);
194202
expect(outboundIndex, scenarioId).toBeGreaterThan(finalRequestAssertIndex);
195203

204+
if (durableWaitSaveAs) {
205+
const durableWait = actions[outboundIndex] as
206+
| { args?: Array<{ lambda?: { expr?: string } }> }
207+
| undefined;
208+
const durableExpr = durableWait?.args?.[0]?.lambda?.expr ?? "";
209+
expect(durableExpr, scenarioId).toContain("event.cursor < finalSent.cursor");
210+
expect(durableExpr, scenarioId).toContain("event.cursor < previewRetired.cursor");
211+
}
212+
196213
if (requestCollectionMode === "poll") {
197214
const requestPoll = actions[requestCollectionIndex] as
198215
| { args?: Array<{ lambda?: { expr?: string } }> }
@@ -212,4 +229,108 @@ describe("qa scenario catalog causality", () => {
212229
}
213230
},
214231
);
232+
233+
it.each([
234+
["memory-tools-channel-context", "durableChannelLifecycle", 30000],
235+
["agent-progress-evidence", "durableCompletionLifecycle", 60000],
236+
] as const)("keeps the policy-aware durable delivery budget for %s", (scenarioId, saveAs, ms) => {
237+
const scenario = requireFlowScenario(readQaScenarioById(scenarioId));
238+
const actions = scenario.execution.flow?.steps[0]?.actions ?? [];
239+
const durableWait = actions.find(
240+
(action) =>
241+
(action as { call?: string }).call === "waitForCondition" &&
242+
(action as { saveAs?: string }).saveAs === saveAs,
243+
);
244+
245+
expect(durableWait, scenarioId).toMatchObject({
246+
args: [expect.any(Object), { expr: `liveTurnTimeoutMs(env, ${ms})` }],
247+
});
248+
});
249+
250+
it.each([
251+
{
252+
scenarioId: "memory-tools-channel-context",
253+
saveAs: "durableChannelLifecycle",
254+
cursorName: "busCursorBeforeInbound",
255+
conversationKey: "channelId",
256+
markerKey: "expectedNeedle",
257+
targetPrefix: "channel",
258+
},
259+
{
260+
scenarioId: "agent-progress-evidence",
261+
saveAs: "durableCompletionLifecycle",
262+
cursorName: "busCursorBefore",
263+
conversationKey: "conversationId",
264+
markerKey: "completionText",
265+
targetPrefix: "dm",
266+
},
267+
] as const)("isolates $scenarioId durable lifecycle evidence by account", async (fixture) => {
268+
const scenario = requireFlowScenario(readQaScenarioById(fixture.scenarioId));
269+
const actions = scenario.execution.flow?.steps[0]?.actions ?? [];
270+
const durableWaitIndex = actions.findIndex(
271+
(action) =>
272+
(action as { call?: string }).call === "waitForCondition" &&
273+
(action as { saveAs?: string }).saveAs === fixture.saveAs,
274+
);
275+
const cardinalityAssertIndex = actions.findIndex((action) =>
276+
readFlowAssertExpression(action).includes(
277+
fixture.scenarioId === "memory-tools-channel-context"
278+
? "visibleChannelOutbounds.length === 1"
279+
: "completionMessages.length === 1",
280+
),
281+
);
282+
expect(durableWaitIndex, fixture.scenarioId).toBeGreaterThanOrEqual(0);
283+
expect(cardinalityAssertIndex, fixture.scenarioId).toBeGreaterThan(durableWaitIndex);
284+
if (durableWaitIndex < 0 || cardinalityAssertIndex <= durableWaitIndex) {
285+
throw new Error(`missing durable lifecycle assertion path for ${fixture.scenarioId}`);
286+
}
287+
const postWaitAssertionPath = actions.slice(durableWaitIndex, cardinalityAssertIndex + 1);
288+
289+
const config = scenario.execution.config ?? {};
290+
const conversationId = String(config[fixture.conversationKey]);
291+
const marker = String(config[fixture.markerKey]);
292+
const target = `${fixture.targetPrefix}:${conversationId}`;
293+
const state = createQaBusState();
294+
for (const accountId of ["foreign", "qa-channel"]) {
295+
const preview = state.addOutboundMessage({ accountId, to: target, text: marker });
296+
state.deleteMessage({ accountId, messageId: preview.id });
297+
state.addOutboundMessage({ accountId, to: target, text: marker });
298+
}
299+
const foreignKind = fixture.targetPrefix === "dm" ? "channel" : "dm";
300+
const foreignKindTarget = `${foreignKind}:${conversationId}`;
301+
const foreignKindPreview = state.addOutboundMessage({
302+
accountId: "qa-channel",
303+
to: foreignKindTarget,
304+
text: marker,
305+
});
306+
state.deleteMessage({ accountId: "qa-channel", messageId: foreignKindPreview.id });
307+
state.addOutboundMessage({
308+
accountId: "qa-channel",
309+
to: foreignKindTarget,
310+
text: marker,
311+
});
312+
313+
await expect(
314+
runLoadedScenarioFlow(fixture.scenarioId, {
315+
state,
316+
flow: {
317+
steps: [
318+
{
319+
name: "keeps foreign account lifecycle evidence isolated",
320+
actions: [
321+
{ set: "outboundStartIndex", value: { expr: "0" } },
322+
{ set: fixture.cursorName, value: { expr: "0" } },
323+
...postWaitAssertionPath,
324+
{
325+
assert: {
326+
expr: `${fixture.saveAs}.message.accountId === transport.accountId`,
327+
},
328+
},
329+
],
330+
},
331+
],
332+
},
333+
}),
334+
).resolves.toMatchObject({ status: "pass" });
335+
});
215336
});

‎qa/scenarios/memory/memory-tools-channel-context.yaml‎

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ flow:
7979
- set: outboundStartIndex
8080
value:
8181
expr: "state.getSnapshot().messages.length"
82+
- set: busCursorBeforeInbound
83+
value:
84+
expr: "state.getSnapshot().cursor"
8285
- sendInbound:
8386
conversation:
8487
id:
@@ -123,27 +126,38 @@ flow:
123126
expr: "finalRequest.cursor > searchResultRequest.cursor && finalRequest.toolOutputCallId === searchResultRequest.plannedToolCallId && finalRequest.toolOutputStructuredError !== true && String(finalRequest.toolOutput ?? '').includes(config.expectedMemoryPath) && String(finalRequest.toolOutput ?? '').includes(config.expectedNeedle) && !finalRequest.plannedToolName"
124127
message:
125128
expr: "`final request did not consume the matching successful memory_get result: ${JSON.stringify(finalRequest)}`"
126-
- call: waitForOutboundMessage
127-
saveAs: outbound
129+
- call: waitForCondition
130+
saveAs: durableChannelLifecycle
128131
args:
129-
- ref: state
130132
- lambda:
131-
params: [candidate]
132-
expr: "candidate.direction === 'outbound' && candidate.conversation.id === config.channelId && candidate.conversation.kind === 'channel' && candidate.text.includes(config.expectedNeedle)"
133+
expr: |-
134+
(() => {
135+
const snapshot = state.getSnapshot();
136+
const visible = snapshot.messages.slice(outboundStartIndex).filter((message) => message.accountId === transport.accountId && message.direction === "outbound" && !message.deleted && message.conversation.id === config.channelId && message.conversation.kind === "channel" && message.text.includes(config.expectedNeedle));
137+
if (visible.length !== 1) return undefined;
138+
const candidate = visible[0];
139+
const events = snapshot.events.filter((event) => event.cursor > busCursorBeforeInbound && "message" in event && event.message.accountId === transport.accountId && event.message.direction === "outbound" && event.message.conversation.id === config.channelId && event.message.conversation.kind === "channel" && event.message.text.includes(config.expectedNeedle));
140+
const finalSent = events.find((event) => event.kind === "outbound-message" && event.message.id === candidate.id);
141+
if (!finalSent) return undefined;
142+
const previewRetired = events.find((event) => event.kind === "message-deleted" && event.message.id !== candidate.id && event.cursor < finalSent.cursor);
143+
if (!previewRetired) return undefined;
144+
const previewSent = events.find((event) => event.kind === "outbound-message" && event.message.id === previewRetired.message.id && event.cursor < previewRetired.cursor);
145+
return previewSent ? { message: candidate, previewId: previewRetired.message.id, finalId: candidate.id, previewSentCursor: previewSent.cursor, previewDeletedCursor: previewRetired.cursor, finalSentCursor: finalSent.cursor } : undefined;
146+
})()
133147
- expr: liveTurnTimeoutMs(env, 30000)
134-
- sinceIndex:
135-
ref: outboundStartIndex
136-
- call: sleep
137-
args: [4000]
148+
- set: durableChannelOutbound
149+
value:
150+
expr: durableChannelLifecycle.message
138151
- set: visibleChannelOutbounds
139152
value:
140-
expr: "state.getSnapshot().messages.slice(outboundStartIndex).filter((message) => message.direction === 'outbound' && !message.deleted && message.conversation.id === config.channelId && message.conversation.kind === 'channel')"
153+
expr: "state.getSnapshot().messages.slice(outboundStartIndex).filter((message) => message.accountId === transport.accountId && message.direction === 'outbound' && !message.deleted && message.conversation.id === config.channelId && message.conversation.kind === 'channel')"
141154
- assert:
142-
expr: "visibleChannelOutbounds.length === 1 && visibleChannelOutbounds[0].id === outbound.id"
155+
# Tool-backed finals replace their streamed preview; prove sent -> deleted -> final ordering first.
156+
expr: "visibleChannelOutbounds.length === 1 && visibleChannelOutbounds[0].id === durableChannelOutbound.id"
143157
message:
144158
expr: "`expected exactly one visible QA-room reply after the ordered memory result: ${JSON.stringify(visibleChannelOutbounds)}`"
145159
- assert:
146-
expr: "(outbound.text.match(new RegExp(config.expectedNeedle, 'g')) ?? []).length === 1"
160+
expr: "(durableChannelOutbound.text.match(new RegExp(config.expectedNeedle, 'g')) ?? []).length === 1"
147161
message:
148-
expr: "`final QA-room reply must contain ${config.expectedNeedle} exactly once: ${outbound.text}`"
149-
detailsExpr: "`${outbound.text}; path=${config.expectedMemoryPath}; matched=${searchResultRequest.toolOutputCallId === searchPlanRequest.plannedToolCallId}; room=${config.channelId}`"
162+
expr: "`final QA-room reply must contain ${config.expectedNeedle} exactly once: ${durableChannelOutbound.text}`"
163+
detailsExpr: "`${durableChannelOutbound.text}; path=${config.expectedMemoryPath}; matched=${searchResultRequest.toolOutputCallId === searchPlanRequest.plannedToolCallId}; room=${config.channelId}; lifecycle=${JSON.stringify({ previewId: durableChannelLifecycle.previewId, previewSentCursor: durableChannelLifecycle.previewSentCursor, previewDeletedCursor: durableChannelLifecycle.previewDeletedCursor, finalId: durableChannelLifecycle.finalId, finalSentCursor: durableChannelLifecycle.finalSentCursor })}`"

0 commit comments

Comments
 (0)