|
| 1 | +title: Gateway restart delivers an unclaimed interrupted session |
| 2 | + |
| 3 | +scenario: |
| 4 | + id: gateway-restart-unclaimed-delivery |
| 5 | + surface: runtime |
| 6 | + coverage: |
| 7 | + primary: |
| 8 | + - session-memory.recovery-delivery |
| 9 | + secondary: |
| 10 | + - session-memory.recovery-restart-recovery |
| 11 | + objective: Verify restart recovery delivers an unclaimed interrupted turn through its canonical persisted session route. |
| 12 | + successCriteria: |
| 13 | + - A real qa-channel inbound turn records the canonical persisted delivery route. |
| 14 | + - The Gateway restarts with an interrupted session that has no active delivery claim or run-specific delivery context. |
| 15 | + - Automatic recovery sends exactly one completed reply through the persisted qa-channel route. |
| 16 | + docsRefs: |
| 17 | + - docs/channels/qa-channel.md |
| 18 | + - docs/concepts/qa-e2e-automation.md |
| 19 | + codeRefs: |
| 20 | + - src/agents/main-session-recovery/main-session-restart-dispatch.ts |
| 21 | + - src/agents/main-session-recovery/main-session-restart-recovery-marking.ts |
| 22 | + - src/utils/delivery-context.shared.ts |
| 23 | + execution: |
| 24 | + kind: flow |
| 25 | + timeoutMs: 180000 |
| 26 | + retryCount: 0 |
| 27 | + suiteIsolation: isolated |
| 28 | + isolationReason: Seeds an unclaimed interrupted session while its Gateway child is stopped. |
| 29 | + summary: Persist a real channel route, seed an unclaimed interrupted turn during Gateway replacement, and verify exactly one recovered outbound reply. |
| 30 | + config: |
| 31 | + requiredProviderMode: mock-openai |
| 32 | + baselineMarker: UNCLAIMED-RECOVERY-BASELINE-OK |
| 33 | + recoveredMarker: UNCLAIMED-RECOVERY-DELIVERED-OK |
| 34 | + |
| 35 | +flow: |
| 36 | + steps: |
| 37 | + - name: resumes an unclaimed turn through its persisted session route |
| 38 | + actions: |
| 39 | + - call: waitForGatewayHealthy |
| 40 | + args: |
| 41 | + - ref: env |
| 42 | + - 60000 |
| 43 | + - call: waitForQaChannelReady |
| 44 | + args: |
| 45 | + - ref: env |
| 46 | + - 60000 |
| 47 | + - call: reset |
| 48 | + - set: conversationId |
| 49 | + value: |
| 50 | + expr: "`unclaimed-recovery-${randomUUID().slice(0, 8)}`" |
| 51 | + - set: sessionKey |
| 52 | + value: |
| 53 | + expr: "buildAgentSessionKey({ agentId: 'qa', channel: 'qa-channel', accountId: transport.accountId, peer: { kind: 'direct', id: `dm:${conversationId}` }, dmScope: env.cfg.session?.dmScope, identityLinks: env.cfg.session?.identityLinks })" |
| 54 | + - sendInbound: |
| 55 | + accountId: default |
| 56 | + conversation: |
| 57 | + id: |
| 58 | + ref: conversationId |
| 59 | + kind: direct |
| 60 | + senderId: |
| 61 | + ref: conversationId |
| 62 | + senderName: QA Restart Operator |
| 63 | + text: |
| 64 | + expr: "`Reply with only this exact marker: ${config.baselineMarker}`" |
| 65 | + - call: waitForOutboundMessage |
| 66 | + args: |
| 67 | + - ref: state |
| 68 | + - lambda: |
| 69 | + params: [candidate] |
| 70 | + expr: "candidate.direction === 'outbound' && candidate.conversation.id === conversationId && candidate.text.includes(config.baselineMarker)" |
| 71 | + - 60000 |
| 72 | + - call: readRawQaSessionStore |
| 73 | + saveAs: baselineStore |
| 74 | + args: |
| 75 | + - ref: env |
| 76 | + - set: baselineEntry |
| 77 | + value: |
| 78 | + expr: baselineStore[sessionKey] |
| 79 | + - assert: |
| 80 | + expr: "baselineEntry?.delivery?.kind === 'external' && baselineEntry.delivery.context.channel === 'qa-channel' && baselineEntry.delivery.context.to === `dm:${conversationId}`" |
| 81 | + message: real qa-channel ingress did not persist its authoritative delivery route |
| 82 | + - set: outboundStartIndex |
| 83 | + value: |
| 84 | + expr: "state.getSnapshot().messages.filter((message) => message.direction === 'outbound').length" |
| 85 | + - call: env.gateway.restartAfterStateMutation |
| 86 | + args: |
| 87 | + - lambda: |
| 88 | + async: true |
| 89 | + params: [ctx] |
| 90 | + expr: |- |
| 91 | + (async () => { |
| 92 | + const sessionStore = await qaImport('openclaw/plugin-sdk/session-store-runtime'); |
| 93 | + const transcript = await qaImport('openclaw/plugin-sdk/session-transcript-runtime'); |
| 94 | + const storePath = sessionStore.resolveStorePath(undefined, { |
| 95 | + agentId: 'qa', |
| 96 | + env: ctx.runtimeEnv, |
| 97 | + }); |
| 98 | + const now = Date.now() - 10_000; |
| 99 | + const appended = await transcript.appendSessionTranscriptMessageByIdentity({ |
| 100 | + agentId: 'qa', |
| 101 | + env: ctx.runtimeEnv, |
| 102 | + sessionId: baselineEntry.sessionId, |
| 103 | + sessionKey, |
| 104 | + storePath, |
| 105 | + now, |
| 106 | + message: { |
| 107 | + role: 'user', |
| 108 | + timestamp: now, |
| 109 | + content: [{ type: 'text', text: `Reply with only this exact marker: ${config.recoveredMarker}` }], |
| 110 | + }, |
| 111 | + }); |
| 112 | + if (!appended?.appended) { |
| 113 | + throw new Error('failed to persist the interrupted user turn'); |
| 114 | + } |
| 115 | + await sessionStore.upsertSessionEntry({ |
| 116 | + agentId: 'qa', |
| 117 | + env: ctx.runtimeEnv, |
| 118 | + sessionKey, |
| 119 | + storePath, |
| 120 | + entry: { |
| 121 | + ...baselineEntry, |
| 122 | + status: 'running', |
| 123 | + abortedLastRun: false, |
| 124 | + updatedAt: now, |
| 125 | + endedAt: undefined, |
| 126 | + restartRecoveryDeliveryRunId: undefined, |
| 127 | + restartRecoveryDeliverySourceRunId: undefined, |
| 128 | + restartRecoveryDeliveryContext: undefined, |
| 129 | + pendingFinalDelivery: undefined, |
| 130 | + }, |
| 131 | + }); |
| 132 | + const seeded = sessionStore.getSessionEntry({ |
| 133 | + agentId: 'qa', |
| 134 | + env: ctx.runtimeEnv, |
| 135 | + sessionKey, |
| 136 | + storePath, |
| 137 | + }); |
| 138 | + if ( |
| 139 | + seeded?.status !== 'running' || |
| 140 | + seeded.abortedLastRun === true || |
| 141 | + seeded.restartRecoveryDeliveryRunId !== undefined || |
| 142 | + seeded.restartRecoveryDeliveryContext !== undefined || |
| 143 | + seeded.delivery?.kind !== 'external' || |
| 144 | + seeded.delivery.context.to !== `dm:${conversationId}` |
| 145 | + ) { |
| 146 | + throw new Error(`failed to seed an unclaimed canonical session route: ${JSON.stringify(seeded)}`); |
| 147 | + } |
| 148 | + })() |
| 149 | + - call: waitForGatewayHealthy |
| 150 | + args: |
| 151 | + - ref: env |
| 152 | + - 60000 |
| 153 | + - call: waitForQaChannelReady |
| 154 | + args: |
| 155 | + - ref: env |
| 156 | + - 60000 |
| 157 | + - call: waitForOutboundMessage |
| 158 | + saveAs: recovered |
| 159 | + args: |
| 160 | + - ref: state |
| 161 | + - lambda: |
| 162 | + params: [candidate] |
| 163 | + expr: "candidate.direction === 'outbound' && candidate.conversation.id === conversationId && candidate.text.includes(config.recoveredMarker)" |
| 164 | + - 60000 |
| 165 | + - sinceIndex: |
| 166 | + ref: outboundStartIndex |
| 167 | + - set: outboundCountAfterRecovery |
| 168 | + value: |
| 169 | + expr: "state.getSnapshot().messages.filter((message) => message.direction === 'outbound').length" |
| 170 | + - waitForNoOutbound: |
| 171 | + quietMs: 1500 |
| 172 | + sinceIndex: |
| 173 | + ref: outboundCountAfterRecovery |
| 174 | + - set: recoveredMessages |
| 175 | + value: |
| 176 | + expr: "state.getSnapshot().messages.filter((candidate) => candidate.direction === 'outbound').slice(outboundStartIndex).filter((candidate) => candidate.conversation.id === conversationId && candidate.text.includes(config.recoveredMarker))" |
| 177 | + - assert: |
| 178 | + expr: recoveredMessages.length === 1 |
| 179 | + message: |
| 180 | + expr: "`expected exactly one recovered outbound delivery, got ${recoveredMessages.length}`" |
| 181 | + detailsExpr: "({ channel: 'qa-channel', recoveredMarker: config.recoveredMarker, delivered: recovered.text, outboundCount: recoveredMessages.length, deliveryClaimBeforeRestart: false })" |
0 commit comments