diff --git a/.coderabbit.yaml b/.coderabbit.yaml index 8fe51f496e6..107b16e1b19 100644 --- a/.coderabbit.yaml +++ b/.coderabbit.yaml @@ -153,10 +153,12 @@ reviews: - `sandbox-survival-e2e` — gateway restart recovery - `hermes-e2e` — Hermes agent onboard + inference - `rebuild-openclaw-e2e` — workspace state survives rebuild + - `openclaw-tui-chat-correlation-e2e` — baked OpenClaw chat send + patch preserves user/assistant turn correlation To run selectively: ``` - gh workflow run nightly-e2e.yaml --ref -f jobs=cloud-e2e,sandbox-survival-e2e,hermes-e2e,rebuild-openclaw-e2e + gh workflow run nightly-e2e.yaml --ref -f jobs=cloud-e2e,sandbox-survival-e2e,hermes-e2e,rebuild-openclaw-e2e,openclaw-tui-chat-correlation-e2e ``` - path: "Dockerfile.base" @@ -197,10 +199,12 @@ reviews: - `hermes-slack-e2e` — Hermes Slack policy + Python placeholder egress - `openshell-gateway-upgrade-e2e` — stale Linux Docker-driver gateway process restart after OpenShell upgrade + - `issue-3600-gpu-proof-optional-e2e` — direct GPU verification remains + optional when CUDA probing fails before sandbox creation To run selectively: ``` - gh workflow run nightly-e2e.yaml --ref -f jobs=cloud-e2e,sandbox-operations-e2e,rebuild-openclaw-e2e,channels-stop-start-e2e,messaging-compatible-endpoint-e2e,bedrock-runtime-compatible-anthropic-e2e,hermes-discord-e2e,hermes-slack-e2e,openshell-gateway-upgrade-e2e + gh workflow run nightly-e2e.yaml --ref -f jobs=cloud-e2e,sandbox-operations-e2e,rebuild-openclaw-e2e,channels-stop-start-e2e,messaging-compatible-endpoint-e2e,bedrock-runtime-compatible-anthropic-e2e,hermes-discord-e2e,hermes-slack-e2e,openshell-gateway-upgrade-e2e,issue-3600-gpu-proof-optional-e2e ``` - path: "src/lib/onboard/bedrock-runtime.ts" @@ -377,6 +381,27 @@ reviews: gh workflow run nightly-e2e.yaml --ref -f jobs=hermes-slack-e2e ``` + - path: "scripts/patch-openclaw-chat-send.js" + instructions: &e2e-openclaw-tui-chat-correlation | + This helper patches OpenClaw chat send behavior inside the sandbox + image. Changes can affect TUI message ordering, duplicate sends, and + user/assistant turn correlation when OpenClaw is the active agent. + + **E2E test recommendation:** + - `openclaw-tui-chat-correlation-e2e` - hermetic TUI chat proof for + correlated user/assistant turns + + To run selectively: + ``` + gh workflow run nightly-e2e.yaml --ref -f jobs=openclaw-tui-chat-correlation-e2e + ``` + + - path: "test/e2e/test-openclaw-tui-chat-correlation.sh" + instructions: *e2e-openclaw-tui-chat-correlation + + - path: "test/openclaw-tui-chat-correlation.test.ts" + instructions: *e2e-openclaw-tui-chat-correlation + - path: "test/e2e/test-openclaw-slack-pairing.sh" instructions: | This script validates OpenClaw Slack DM pairing across the gateway diff --git a/.github/workflows/nightly-e2e.yaml b/.github/workflows/nightly-e2e.yaml index 153ca321b0b..d222a0e6e10 100644 --- a/.github/workflows/nightly-e2e.yaml +++ b/.github/workflows/nightly-e2e.yaml @@ -82,6 +82,8 @@ on: Valid: cloud-e2e, cloud-onboard-e2e, cloud-inference-e2e, skill-agent-e2e, docs-validation-e2e, messaging-providers-e2e, openclaw-slack-pairing-e2e, + openclaw-tui-chat-correlation-e2e, + issue-3600-gpu-proof-optional-e2e, openclaw-discord-pairing-e2e, messaging-compatible-endpoint-e2e, kimi-inference-compat-e2e, @@ -395,6 +397,103 @@ jobs: path: /tmp/nemoclaw-e2e-openclaw-slack-pairing-install.log if-no-files-found: ignore + # ── OpenClaw TUI Chat Correlation E2E (#2603/#3145) ─────────── + # Creates a fresh OpenClaw sandbox, then runs the live gateway/webchat + # correlation harness against rapid sequential sends. + openclaw-tui-chat-correlation-e2e: + if: >- + github.repository == 'NVIDIA/NemoClaw' && + (github.event_name != 'workflow_dispatch' || + inputs.jobs == '' || + contains(format(',{0},', inputs.jobs), ',openclaw-tui-chat-correlation-e2e,')) + runs-on: ubuntu-latest + timeout-minutes: 75 + steps: + - name: Checkout + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + ref: ${{ inputs.target_ref || github.ref }} + + - name: Setup Node.js + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.0.0 + with: + node-version: "22" + + - name: Install test dependencies + run: npm ci --include=dev + + - name: Run OpenClaw TUI chat correlation E2E test + env: + NVIDIA_API_KEY: ${{ secrets.NVIDIA_API_KEY }} + NEMOCLAW_NON_INTERACTIVE: "1" + NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1" + NEMOCLAW_RECREATE_SANDBOX: "1" + NEMOCLAW_SANDBOX_NAME: "e2e-openclaw-tui-correlation" + GITHUB_TOKEN: ${{ github.token }} + run: bash test/e2e/test-openclaw-tui-chat-correlation.sh + + - name: Upload install log on failure + if: failure() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: install-log-openclaw-tui-chat-correlation + path: /tmp/nemoclaw-e2e-openclaw-tui-correlation-install.log + if-no-files-found: ignore + + # ── DGX Station GPU optional proof validation (#3600) ────────── + # CI cannot emulate GB300, but this guards the release-blocker mitigation: + # optional direct GPU proofs must not abort onboard before the fatal throw. + issue-3600-gpu-proof-optional-e2e: + if: >- + github.repository == 'NVIDIA/NemoClaw' && + (github.event_name != 'workflow_dispatch' || + inputs.jobs == '' || + contains(format(',{0},', inputs.jobs), ',issue-3600-gpu-proof-optional-e2e,')) + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - name: Checkout + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + ref: ${{ inputs.target_ref || github.ref }} + + - name: Setup Node.js + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.0.0 + with: + node-version: "22" + + - name: Verify optional GPU proof cannot abort onboard + run: | + node - <<'NODE' + const fs = require('node:fs'); + const source = fs.readFileSync('src/lib/onboard.ts', 'utf8'); + const start = source.indexOf('function verifyDirectSandboxGpu'); + if (start < 0) { + throw new Error('verifyDirectSandboxGpu function not found'); + } + const bodyStart = source.indexOf('{', start); + let depth = 0; + let end = -1; + for (let i = bodyStart; i < source.length; i += 1) { + if (source[i] === '{') depth += 1; + if (source[i] === '}') depth -= 1; + if (depth === 0) { + end = i + 1; + break; + } + } + if (bodyStart < 0 || end < 0) { + throw new Error('verifyDirectSandboxGpu function body not found'); + } + const fn = source.slice(start, end); + const optional = fn.indexOf('if (proof.optional === true) return;'); + const throwing = fn.indexOf('throw new Error(`GPU proof failed:'); + if (!(optional >= 0 && throwing >= 0 && optional < throwing)) { + throw new Error('optional GPU proof handling does not precede fatal throw'); + } + console.log('optional-before-throw=true'); + NODE + # ── OpenClaw Discord Pairing E2E (#4061) ────────────────────── # Hermetic Discord Gateway placeholder rewrite proof, then connect-shell # `openclaw pairing approve discord ` against shared state. @@ -1716,7 +1815,7 @@ jobs: ref: ${{ inputs.target_ref || github.ref }} - name: Setup Node - uses: actions/setup-node@v6 + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.0.0 with: node-version: "22" @@ -2359,6 +2458,8 @@ jobs: docs-validation-e2e, messaging-providers-e2e, openclaw-slack-pairing-e2e, + openclaw-tui-chat-correlation-e2e, + issue-3600-gpu-proof-optional-e2e, openclaw-discord-pairing-e2e, messaging-compatible-endpoint-e2e, channels-add-remove-e2e, @@ -2459,6 +2560,8 @@ jobs: docs-validation-e2e, messaging-providers-e2e, openclaw-slack-pairing-e2e, + openclaw-tui-chat-correlation-e2e, + issue-3600-gpu-proof-optional-e2e, openclaw-discord-pairing-e2e, messaging-compatible-endpoint-e2e, channels-add-remove-e2e, @@ -2616,6 +2719,8 @@ jobs: docs-validation-e2e, messaging-providers-e2e, openclaw-slack-pairing-e2e, + openclaw-tui-chat-correlation-e2e, + issue-3600-gpu-proof-optional-e2e, openclaw-discord-pairing-e2e, messaging-compatible-endpoint-e2e, channels-add-remove-e2e, diff --git a/Dockerfile b/Dockerfile index 1bd6febe753..87d2ca20eb7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -76,7 +76,9 @@ ENV NPM_CONFIG_AUDIT=false \ NPM_CONFIG_FETCH_TIMEOUT=300000 RUN npm ci --omit=dev COPY scripts/patch-openclaw-tool-catalog.js /usr/local/lib/nemoclaw/patch-openclaw-tool-catalog.js -RUN chmod 755 /usr/local/lib/nemoclaw/patch-openclaw-tool-catalog.js +COPY scripts/patch-openclaw-chat-send.js /usr/local/lib/nemoclaw/patch-openclaw-chat-send.js +RUN chmod 755 /usr/local/lib/nemoclaw/patch-openclaw-tool-catalog.js \ + /usr/local/lib/nemoclaw/patch-openclaw-chat-send.js # Upgrade OpenClaw if the base image is stale. # @@ -290,6 +292,22 @@ RUN set -eu; \ if grep -REq --include='*.js' 'DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS = (1e4|15e3)' "$OC_DIST"; then echo "ERROR: Patch 5 left a short handshake-timeout constant" >&2; exit 1; fi; \ if ! grep -REq --include='*.js' 'DEFAULT_PREAUTH_HANDSHAKE_TIMEOUT_MS = 6e4' "$OC_DIST"; then echo "ERROR: Patch 5 did not find patched 6e4 constant" >&2; exit 1; fi +# Patch OpenClaw chat.send gateway behavior for OpenClaw 2026.5.x. +# +# OpenClaw can accept rapid TUI/WebChat chat.send requests and then emit a +# terminal chat event with state="final" but no assistant message for the later +# submitted run. That makes clients treat the turn as complete even though no +# visible reply was delivered. The shim also correlates real agent run IDs back +# to the submitted chat.send run ID when OpenClaw starts an internal run with a +# different ID, carries that submitted ID through queued follow-up turns, and +# adds the submitted run ID as the transcript idempotency key. +# +# Removal criteria: drop when upstream OpenClaw fixes openclaw/openclaw#70164 +# and openclaw/openclaw#50298, or when NemoClaw no longer ships OpenClaw 2026.5.x. +# hadolint ignore=DL3059 +RUN node /usr/local/lib/nemoclaw/patch-openclaw-chat-send.js \ + /usr/local/lib/node_modules/openclaw/dist + # Patch OpenClaw's pinned 2026.5.18 compiled selection runtime to expose a # compact searchable tool catalog to the model while preserving the full # effective tool set behind tool_call. NEMOCLAW_TOOL_CATALOG=0 disables this diff --git a/scripts/patch-openclaw-chat-send.js b/scripts/patch-openclaw-chat-send.js new file mode 100755 index 00000000000..8ff17744c58 --- /dev/null +++ b/scripts/patch-openclaw-chat-send.js @@ -0,0 +1,249 @@ +#!/usr/bin/env node +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +/* + * Temporary NemoClaw compatibility shim for OpenClaw 2026.5.x chat.send + * gateway behavior. Remove this when upstream OpenClaw preserves submitted + * chat.send run lineage and stops emitting empty terminal chat events. + */ + +const fs = require("node:fs"); +const path = require("node:path"); + +const distDir = process.argv[2]; +if (!distDir) { + console.error("Usage: patch-openclaw-chat-send.js "); + process.exit(2); +} + +function fail(message) { + console.error(`ERROR: ${message}`); + process.exit(1); +} + +function listJsFiles(dir) { + return fs + .readdirSync(dir, { withFileTypes: true }) + .filter((entry) => entry.isFile() && entry.name.endsWith(".js")) + .map((entry) => path.join(dir, entry.name)); +} + +function patchChatSendFile(file) { + let source = fs.readFileSync(file, "utf8"); + const original = source; + + if (!source.includes("nemoclaw: correlate chat.send run ids")) { + const next = source.replace( + /(onAgentRunStart: \(runId\) => \{\n)(\s*)agentRunStarted = true;/, + (_match, prefix, indent) => + `${prefix}${indent}agentRunStarted = true;\n` + + `${indent}if (runId && runId !== clientRunId) context.addChatRun(runId, { sessionKey, clientRunId }); ` + + `// nemoclaw: correlate chat.send run ids (#2603, #3145)`, + ); + if (next === source) { + fail(`OpenClaw chat.send run-start shape not recognized in ${file}`); + } + source = next; + } + + if (!source.includes("idempotencyKey: clientRunId")) { + let inserted = false; + source = source.replace( + /(createIfMissing: true,\n)(\s*)(ttsSupplement: ttsSupplementMarker,)/g, + (match, prefix, indent, ttsLine, offset) => { + const preceding = source.slice(Math.max(0, offset - 300), offset); + if (preceding.includes("idempotencyKey:")) return match; + inserted = true; + return `${prefix}${indent}idempotencyKey: clientRunId,\n${indent}${ttsLine}`; + }, + ); + if (!inserted) { + fail(`OpenClaw chat.send transcript append shape not recognized in ${file}`); + } + } + + if (!source.includes("suppressing empty final event")) { + const next = source.replace( + /\n(\s*)broadcastChatFinal\(\{\n(\s*)context,\n\s*runId: clientRunId,\n\s*sessionKey,\n\s*message\n\s*\}\);/, + (_match, outerIndent, innerIndent) => + `\n${outerIndent}if (message) broadcastChatFinal({\n` + + `${innerIndent}context,\n` + + `${innerIndent}runId: clientRunId,\n` + + `${innerIndent}sessionKey,\n` + + `${innerIndent}message\n` + + `${outerIndent}}); else context.logGateway.warn("webchat chat.send completed without visible assistant reply; suppressing empty final event (nemoclaw #2603/#3145)");`, + ); + if (next === source) { + fail(`OpenClaw chat.send empty-final shape not recognized in ${file}`); + } + source = next; + } + + if (source !== original) { + fs.writeFileSync(file, source); + return true; + } + return false; +} + +function patchFollowupRunnerFile(file) { + let source = fs.readFileSync(file, "utf8"); + const original = source; + + if ( + source.includes( + "const runId = opts?.runId ?? crypto.randomUUID(); // nemoclaw: preserve chat.send run ids in followup queue", + ) + ) { + source = source.replace( + "const runId = opts?.runId ?? crypto.randomUUID(); // nemoclaw: preserve chat.send run ids in followup queue", + "const runId = queued.runId ?? opts?.runId ?? crypto.randomUUID(); // nemoclaw: preserve chat.send run ids in followup queue", + ); + } + + if (!source.includes("preserve chat.send run ids in followup queue")) { + const next = source.replace( + /(replyOperation = createReplyOperation\(\{\n\s*sessionId: run\.sessionId,\n\s*sessionKey: replySessionKey \?\? "",\n\s*resetTriggered: false,\n\s*upstreamAbortSignal: queued\.abortSignal \?\? opts\?\.abortSignal\n\s*\}\);\n\s*)const runId = crypto\.randomUUID\(\);/, + (_match, prefix) => + `${prefix}const runId = queued.runId ?? opts?.runId ?? crypto.randomUUID(); ` + + `// nemoclaw: preserve chat.send run ids in followup queue (#2603, #3145)`, + ); + if (next === source) { + fail(`OpenClaw followup runner run-id shape not recognized in ${file}`); + } + source = next; + } + + if (source !== original) { + fs.writeFileSync(file, source); + return true; + } + return false; +} + +function patchGetReplyFile(file) { + let source = fs.readFileSync(file, "utf8"); + const original = source; + + if (!source.includes("carry chat.send run id into queued followup")) { + const next = source.replace( + /(const followupRun = \{\n)(\s*)prompt: queuedBody,/, + (_match, prefix, indent) => + `${prefix}${indent}runId: opts?.runId, ` + + `// nemoclaw: carry chat.send run id into queued followup (#2603, #3145)\n` + + `${indent}prompt: queuedBody,`, + ); + if (next === source) { + fail(`OpenClaw get-reply followup run shape not recognized in ${file}`); + } + source = next; + } + + if (!source.includes("force webchat chat.send queued turns")) { + if (source.includes("const resolvedQueue = useFastReplyRuntime ? {")) { + source = source.replace( + "const resolvedQueue = useFastReplyRuntime ? {", + "let resolvedQueue = useFastReplyRuntime ? {", + ); + } else if (!source.includes("let resolvedQueue = useFastReplyRuntime ? {")) { + fail(`OpenClaw get-reply queue settings shape not recognized in ${file}`); + } + + const next = source.replace( + /\n(\s*)const piRuntime = useFastReplyRuntime \? null : await traceRunPhase\("reply\.load_pi_runtime", \(\) => loadPiEmbeddedRuntime\(\)\);/, + (_match, indent) => + `\n${indent}if (opts?.runId && sessionCtx.Provider === "webchat" && resolvedQueue.mode === "steer") resolvedQueue = {\n` + + `${indent}\t...resolvedQueue,\n` + + `${indent}\tmode: "followup",\n` + + `${indent}\tdebounceMs: 0\n` + + `${indent}}; // nemoclaw: force webchat chat.send queued turns to keep per-message replies (#2603, #3145)\n` + + `${indent}const piRuntime = useFastReplyRuntime ? null : await traceRunPhase("reply.load_pi_runtime", () => loadPiEmbeddedRuntime());`, + ); + if (next === source) { + fail(`OpenClaw get-reply pi runtime shape not recognized in ${file}`); + } + source = next; + } + + if (source !== original) { + fs.writeFileSync(file, source); + return true; + } + return false; +} + +const candidates = listJsFiles(distDir).filter((file) => { + const source = fs.readFileSync(file, "utf8"); + return source.includes('"chat.send"') && source.includes("onAgentRunStart"); +}); + +if (candidates.length !== 1) { + fail(`expected exactly one OpenClaw chat.send runtime file, found ${candidates.length}`); +} + +const chatFile = candidates[0]; +patchChatSendFile(chatFile); + +const getReplyCandidates = listJsFiles(distDir).filter((file) => { + const source = fs.readFileSync(file, "utf8"); + return ( + source.includes("resolveQueueSettings") && + (source.includes("const followupRun = {") || + source.includes("carry chat.send run id into queued followup")) + ); +}); + +if (getReplyCandidates.length !== 1) { + fail(`expected exactly one OpenClaw get-reply runtime file, found ${getReplyCandidates.length}`); +} + +const getReplyFile = getReplyCandidates[0]; +patchGetReplyFile(getReplyFile); + +const followupCandidates = listJsFiles(distDir).filter((file) => { + const source = fs.readFileSync(file, "utf8"); + return ( + source.includes("function createFollowupRunner") && + source.includes("replyOperation = createReplyOperation") && + (source.includes("const runId = crypto.randomUUID();") || + source.includes("preserve chat.send run ids in followup queue")) + ); +}); + +if (followupCandidates.length !== 1) { + fail( + `expected exactly one OpenClaw followup runner runtime file, found ${followupCandidates.length}`, + ); +} + +const followupFile = followupCandidates[0]; +patchFollowupRunnerFile(followupFile); + +const patched = fs.readFileSync(chatFile, "utf8"); +if (!patched.includes("nemoclaw: correlate chat.send run ids")) { + fail("chat.send run-id correlation patch did not apply"); +} +if (!patched.includes("idempotencyKey: clientRunId")) { + fail("chat.send transcript idempotency patch did not apply"); +} +if (!patched.includes("suppressing empty final event")) { + fail("chat.send empty-final suppression patch did not apply"); +} + +const patchedGetReply = fs.readFileSync(getReplyFile, "utf8"); +if (!patchedGetReply.includes("carry chat.send run id into queued followup")) { + fail("get-reply queued run-id patch did not apply"); +} +if (!patchedGetReply.includes("force webchat chat.send queued turns")) { + fail("get-reply webchat queue mode patch did not apply"); +} + +const patchedFollowup = fs.readFileSync(followupFile, "utf8"); +if (!patchedFollowup.includes("preserve chat.send run ids in followup queue")) { + fail("followup runner run-id patch did not apply"); +} + +console.log( + `INFO: patched OpenClaw chat.send compatibility in ${path.basename(chatFile)}, ${path.basename(getReplyFile)}, and ${path.basename(followupFile)}`, +); diff --git a/src/lib/sandbox/build-context.ts b/src/lib/sandbox/build-context.ts index 1bdf2016339..f436ac923b9 100644 --- a/src/lib/sandbox/build-context.ts +++ b/src/lib/sandbox/build-context.ts @@ -142,6 +142,10 @@ function stageOptimizedSandboxBuildContext( path.join(rootDir, "scripts", "patch-openclaw-tool-catalog.js"), path.join(stagedScriptsDir, "patch-openclaw-tool-catalog.js"), ); + fs.copyFileSync( + path.join(rootDir, "scripts", "patch-openclaw-chat-send.js"), + path.join(stagedScriptsDir, "patch-openclaw-chat-send.js"), + ); return { buildCtx, stagedDockerfile }; } diff --git a/test/e2e/test-openclaw-tui-chat-correlation.sh b/test/e2e/test-openclaw-tui-chat-correlation.sh new file mode 100755 index 00000000000..6491b2c5e85 --- /dev/null +++ b/test/e2e/test-openclaw-tui-chat-correlation.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Validation-only E2E for release-blocker close calls: +# #2603 - previous TUI/chat message disappears after reconnect/scroll +# #3145 - rapid sequential TUI messages duplicate or arrive out of order +# +# The Vitest live harness drives OpenClaw's gateway websocket directly against a +# real sandbox. This wrapper creates a fresh cloud-backed OpenClaw sandbox first +# so CI evidence is not dependent on a developer machine's stale sandbox state. + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +REPO="$(cd "${SCRIPT_DIR}/../.." && pwd)" + +SANDBOX_NAME="${NEMOCLAW_SANDBOX_NAME:-e2e-openclaw-tui-correlation}" +INSTALL_LOG="${E2E_OPENCLAW_TUI_CORRELATION_INSTALL_LOG:-/tmp/nemoclaw-e2e-openclaw-tui-correlation-install.log}" + +cleanup() { + if [ "${NEMOCLAW_E2E_SKIP_CLEANUP:-0}" = "1" ]; then + return + fi + SANDBOX_NAME="$SANDBOX_NAME" bash "${SCRIPT_DIR}/e2e-cloud-experimental/cleanup.sh" --verify >/dev/null 2>&1 || true +} +trap cleanup EXIT + +export NEMOCLAW_SANDBOX_NAME="$SANDBOX_NAME" +export E2E_CLOUD_ONBOARD_INSTALL_LOG="$INSTALL_LOG" +export NEMOCLAW_E2E_KEEP_SANDBOX=1 +export NEMOCLAW_NON_INTERACTIVE="${NEMOCLAW_NON_INTERACTIVE:-1}" +export NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE="${NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE:-1}" +export NEMOCLAW_RECREATE_SANDBOX="${NEMOCLAW_RECREATE_SANDBOX:-1}" + +bash "${SCRIPT_DIR}/test-cloud-onboard-e2e.sh" + +# Pick up PATH changes from the public installer in this shell. +# shellcheck source=test/e2e/lib/install-path-refresh.sh +. "${SCRIPT_DIR}/lib/install-path-refresh.sh" +nemoclaw_refresh_install_env +nemoclaw_ensure_local_bin_on_path +export PATH="/usr/local/bin:${HOME}/.local/bin:${PATH}" + +openclaw_version="$( + openshell sandbox exec --name "$SANDBOX_NAME" -- openclaw --version 2>&1 || true +)" +echo "Sandbox OpenClaw version: ${openclaw_version}" +if ! grep -q "2026.5.18" <<<"$openclaw_version"; then + echo "Expected fresh sandbox to run OpenClaw 2026.5.18" >&2 + exit 1 +fi + +cd "$REPO" + +if [ ! -x ./node_modules/.bin/vitest ]; then + echo "Restoring repository dev dependencies for the live Vitest harness" + npm ci --include=dev +fi + +NEMOCLAW_ISSUE_2603_LIVE=1 \ + NEMOCLAW_ISSUE_2603_SANDBOX="$SANDBOX_NAME" \ + ./node_modules/.bin/vitest run test/openclaw-tui-chat-correlation.test.ts --reporter=verbose diff --git a/test/e2e/test-token-rotation.sh b/test/e2e/test-token-rotation.sh index 7f2c86260ae..5a4c06e1e5f 100755 --- a/test/e2e/test-token-rotation.sh +++ b/test/e2e/test-token-rotation.sh @@ -324,7 +324,7 @@ process.exit('SLACK_APP_TOKEN' in h ? 0 : 1); echo "$ONBOARD_OUTPUT" | tail -30 fi - if echo "$ONBOARD_OUTPUT" | grep -q "credential(s) rotated"; then + if grep -q "credential(s) rotated" <<<"$ONBOARD_OUTPUT"; then pass "Credential rotation detected" else fail "Credential rotation not detected in onboard output" @@ -335,31 +335,31 @@ process.exit('SLACK_APP_TOKEN' in h ? 0 : 1); # Rotation message must name only the telegram-bridge provider — Discord # token is unchanged, so a stray discord-bridge entry would indicate a # false-positive in detectMessagingCredentialRotation. - if echo "$ONBOARD_OUTPUT" | grep -q "credential(s) rotated:.*telegram-bridge"; then + if grep -q "credential(s) rotated:.*telegram-bridge" <<<"$ONBOARD_OUTPUT"; then pass "Rotation message identifies telegram-bridge" else fail "Rotation message did not identify telegram-bridge" info "Onboard output:" - echo "$ONBOARD_OUTPUT" | grep "credential(s) rotated" || true + grep "credential(s) rotated" <<<"$ONBOARD_OUTPUT" || true fi - if echo "$ONBOARD_OUTPUT" | grep -q "credential(s) rotated:.*discord-bridge"; then + if grep -q "credential(s) rotated:.*discord-bridge" <<<"$ONBOARD_OUTPUT"; then fail "Rotation message unexpectedly named discord-bridge (Discord token did not change)" info "Onboard output:" - echo "$ONBOARD_OUTPUT" | grep "credential(s) rotated" || true + grep "credential(s) rotated" <<<"$ONBOARD_OUTPUT" || true else pass "Rotation message did not name discord-bridge (Discord unchanged)" fi - if echo "$ONBOARD_OUTPUT" | grep -qE "credential\(s\) rotated:.*slack-(bridge|app)"; then + if grep -qE "credential\(s\) rotated:.*slack-(bridge|app)" <<<"$ONBOARD_OUTPUT"; then fail "Rotation message unexpectedly named slack-bridge/slack-app (Slack tokens did not change)" info "Onboard output:" - echo "$ONBOARD_OUTPUT" | grep "credential(s) rotated" || true + grep "credential(s) rotated" <<<"$ONBOARD_OUTPUT" || true else pass "Rotation message did not name slack-bridge or slack-app (Slack unchanged)" fi - if echo "$ONBOARD_OUTPUT" | grep -q "Rebuilding sandbox"; then + if grep -q "Rebuilding sandbox" <<<"$ONBOARD_OUTPUT"; then pass "Sandbox rebuild triggered by rotation" else fail "Sandbox rebuild not triggered" @@ -385,7 +385,7 @@ process.exit('SLACK_APP_TOKEN' in h ? 0 : 1); echo "$ONBOARD_OUTPUT" | tail -30 fi - if echo "$ONBOARD_OUTPUT" | grep -q "reusing it"; then + if grep -q "reusing it" <<<"$ONBOARD_OUTPUT"; then pass "Sandbox reused when tokens unchanged" else fail "Sandbox was not reused (unexpected rebuild)" @@ -410,7 +410,7 @@ process.exit('SLACK_APP_TOKEN' in h ? 0 : 1); echo "$ONBOARD_OUTPUT" | tail -30 fi - if echo "$ONBOARD_OUTPUT" | grep -q "credential(s) rotated"; then + if grep -q "credential(s) rotated" <<<"$ONBOARD_OUTPUT"; then pass "Credential rotation detected" else fail "Credential rotation not detected in onboard output" @@ -419,31 +419,31 @@ process.exit('SLACK_APP_TOKEN' in h ? 0 : 1); fi # Symmetric assertion to Phase 2: only the discord-bridge entry should appear. - if echo "$ONBOARD_OUTPUT" | grep -q "credential(s) rotated:.*discord-bridge"; then + if grep -q "credential(s) rotated:.*discord-bridge" <<<"$ONBOARD_OUTPUT"; then pass "Rotation message identifies discord-bridge" else fail "Rotation message did not identify discord-bridge" info "Onboard output:" - echo "$ONBOARD_OUTPUT" | grep "credential(s) rotated" || true + grep "credential(s) rotated" <<<"$ONBOARD_OUTPUT" || true fi - if echo "$ONBOARD_OUTPUT" | grep -q "credential(s) rotated:.*telegram-bridge"; then + if grep -q "credential(s) rotated:.*telegram-bridge" <<<"$ONBOARD_OUTPUT"; then fail "Rotation message unexpectedly named telegram-bridge (Telegram token did not change)" info "Onboard output:" - echo "$ONBOARD_OUTPUT" | grep "credential(s) rotated" || true + grep "credential(s) rotated" <<<"$ONBOARD_OUTPUT" || true else pass "Rotation message did not name telegram-bridge (Telegram unchanged)" fi - if echo "$ONBOARD_OUTPUT" | grep -qE "credential\(s\) rotated:.*slack-(bridge|app)"; then + if grep -qE "credential\(s\) rotated:.*slack-(bridge|app)" <<<"$ONBOARD_OUTPUT"; then fail "Rotation message unexpectedly named slack-bridge/slack-app (Slack tokens did not change)" info "Onboard output:" - echo "$ONBOARD_OUTPUT" | grep "credential(s) rotated" || true + grep "credential(s) rotated" <<<"$ONBOARD_OUTPUT" || true else pass "Rotation message did not name slack-bridge or slack-app (Slack unchanged)" fi - if echo "$ONBOARD_OUTPUT" | grep -q "Rebuilding sandbox"; then + if grep -q "Rebuilding sandbox" <<<"$ONBOARD_OUTPUT"; then pass "Sandbox rebuild triggered by rotation" else fail "Sandbox rebuild not triggered" @@ -469,7 +469,7 @@ process.exit('SLACK_APP_TOKEN' in h ? 0 : 1); echo "$ONBOARD_OUTPUT" | tail -30 fi - if echo "$ONBOARD_OUTPUT" | grep -q "reusing it"; then + if grep -q "reusing it" <<<"$ONBOARD_OUTPUT"; then pass "Sandbox reused when tokens unchanged" else fail "Sandbox was not reused (unexpected rebuild)" @@ -494,7 +494,7 @@ process.exit('SLACK_APP_TOKEN' in h ? 0 : 1); echo "$ONBOARD_OUTPUT" | tail -30 fi - if echo "$ONBOARD_OUTPUT" | grep -q "credential(s) rotated"; then + if grep -q "credential(s) rotated" <<<"$ONBOARD_OUTPUT"; then pass "Credential rotation detected" else fail "Credential rotation not detected in onboard output" @@ -503,39 +503,39 @@ process.exit('SLACK_APP_TOKEN' in h ? 0 : 1); fi # Both slack-bridge (bot token) and slack-app (app token) should rotate. - if echo "$ONBOARD_OUTPUT" | grep -q "credential(s) rotated:.*slack-bridge"; then + if grep -q "credential(s) rotated:.*slack-bridge" <<<"$ONBOARD_OUTPUT"; then pass "Rotation message identifies slack-bridge" else fail "Rotation message did not identify slack-bridge" info "Onboard output:" - echo "$ONBOARD_OUTPUT" | grep "credential(s) rotated" || true + grep "credential(s) rotated" <<<"$ONBOARD_OUTPUT" || true fi - if echo "$ONBOARD_OUTPUT" | grep -q "credential(s) rotated:.*slack-app"; then + if grep -q "credential(s) rotated:.*slack-app" <<<"$ONBOARD_OUTPUT"; then pass "Rotation message identifies slack-app" else fail "Rotation message did not identify slack-app" info "Onboard output:" - echo "$ONBOARD_OUTPUT" | grep "credential(s) rotated" || true + grep "credential(s) rotated" <<<"$ONBOARD_OUTPUT" || true fi - if echo "$ONBOARD_OUTPUT" | grep -q "credential(s) rotated:.*telegram-bridge"; then + if grep -q "credential(s) rotated:.*telegram-bridge" <<<"$ONBOARD_OUTPUT"; then fail "Rotation message unexpectedly named telegram-bridge (Telegram token did not change)" info "Onboard output:" - echo "$ONBOARD_OUTPUT" | grep "credential(s) rotated" || true + grep "credential(s) rotated" <<<"$ONBOARD_OUTPUT" || true else pass "Rotation message did not name telegram-bridge (Telegram unchanged)" fi - if echo "$ONBOARD_OUTPUT" | grep -q "credential(s) rotated:.*discord-bridge"; then + if grep -q "credential(s) rotated:.*discord-bridge" <<<"$ONBOARD_OUTPUT"; then fail "Rotation message unexpectedly named discord-bridge (Discord token did not change)" info "Onboard output:" - echo "$ONBOARD_OUTPUT" | grep "credential(s) rotated" || true + grep "credential(s) rotated" <<<"$ONBOARD_OUTPUT" || true else pass "Rotation message did not name discord-bridge (Discord unchanged)" fi - if echo "$ONBOARD_OUTPUT" | grep -q "Rebuilding sandbox"; then + if grep -q "Rebuilding sandbox" <<<"$ONBOARD_OUTPUT"; then pass "Sandbox rebuild triggered by Slack rotation" else fail "Sandbox rebuild not triggered" @@ -561,7 +561,7 @@ process.exit('SLACK_APP_TOKEN' in h ? 0 : 1); echo "$ONBOARD_OUTPUT" | tail -30 fi - if echo "$ONBOARD_OUTPUT" | grep -q "reusing it"; then + if grep -q "reusing it" <<<"$ONBOARD_OUTPUT"; then pass "Sandbox reused when tokens unchanged" else fail "Sandbox was not reused (unexpected rebuild)" diff --git a/test/fetch-guard-patch-regression.test.ts b/test/fetch-guard-patch-regression.test.ts index f184daccfa0..418afcf3ee3 100644 --- a/test/fetch-guard-patch-regression.test.ts +++ b/test/fetch-guard-patch-regression.test.ts @@ -272,7 +272,7 @@ if (globalThis.proxyChecks.length !== 0) throw new Error('sandbox proxy validati const command = dockerRunCommandBetween( "# Patch OpenClaw media fetch for proxy-only sandbox", - "# Patch OpenClaw's pinned", + "# Patch OpenClaw chat.send gateway behavior", ).replaceAll("/usr/local/lib/node_modules/openclaw/dist", dist); const fakeBin = path.join(tmp, "bin"); fs.mkdirSync(fakeBin); diff --git a/test/openclaw-chat-send-patch.test.ts b/test/openclaw-chat-send-patch.test.ts new file mode 100644 index 00000000000..4c84c7cba14 --- /dev/null +++ b/test/openclaw-chat-send-patch.test.ts @@ -0,0 +1,210 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { spawnSync } from "node:child_process"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import { describe, expect, it } from "vitest"; + +const PATCH_SCRIPT = path.join( + import.meta.dirname, + "..", + "scripts", + "patch-openclaw-chat-send.js", +); + +function writeChatSendFixture(dist: string): string { + const fixture = path.join(dist, "chat-fixture.js"); + fs.writeFileSync( + fixture, + [ + 'const chatHandlers = {', + ' "chat.send": async ({ params, respond, context, client }) => {', + " const p = params;", + " const clientRunId = p.idempotencyKey;", + ' const sessionKey = "issue2603";', + " let agentRunStarted = false;", + " measureDiagnosticsTimelineSpan(\"gateway.chat_send.dispatch_inbound\", () => dispatchInboundMessage({", + " replyOptions: {", + " runId: clientRunId,", + " onAgentRunStart: (runId) => {", + " agentRunStarted = true;", + " if (!hasBeforeAgentRunGate) emitUserTranscriptUpdate();", + " }", + " }", + " })).then(async () => {", + " if (!agentRunStarted) {", + " let message;", + " if (transcriptReply || persistedContentForAppend?.length || assistantContent?.length) {", + " const appended = await appendAssistantTranscriptMessage({", + " message: transcriptReply,", + " sessionId,", + " storePath: latestStorePath,", + " sessionFile: latestEntry?.sessionFile,", + " agentId,", + " createIfMissing: true,", + " ttsSupplement: ttsSupplementMarker,", + " cfg", + " });", + " message = appended.message;", + " }", + " broadcastChatFinal({", + " context,", + " runId: clientRunId,", + " sessionKey,", + " message", + " });", + " }", + " });", + " }", + "};", + "", + ].join("\n"), + ); + return fixture; +} + +function writeFollowupRunnerFixture(dist: string): string { + const fixture = path.join(dist, "agent-runner.fixture.js"); + fs.writeFileSync( + fixture, + [ + "function createFollowupRunner(params) {", + " return async function runQueuedFollowup(queued, opts, run) {", + " let replyOperation;", + " replyOperation = createReplyOperation({", + " sessionId: run.sessionId,", + ' sessionKey: replySessionKey ?? "",', + " resetTriggered: false,", + " upstreamAbortSignal: queued.abortSignal ?? opts?.abortSignal", + " });", + " const runId = crypto.randomUUID();", + " if (run.sessionKey) registerAgentRunContext(runId, {", + " sessionKey: run.sessionKey,", + " verboseLevel: run.verboseLevel", + " });", + " return runId;", + " }", + "}", + "", + ].join("\n"), + ); + return fixture; +} + +function writeGetReplyFixture(dist: string): string { + const fixture = path.join(dist, "get-reply.fixture.js"); + fs.writeFileSync( + fixture, + [ + "async function getReplyFromConfig(params) {", + " const { cfg, opts, sessionCtx, sessionEntry, perMessageQueueMode, perMessageQueueOptions } = params;", + " const resolvedQueue = useFastReplyRuntime ? {", + ' mode: "collect",', + " debounceMs: 0,", + " cap: 1,", + ' dropPolicy: "summarize"', + " } : resolveQueueSettings({", + " cfg,", + " channel: sessionCtx.Provider,", + " sessionEntry,", + " inlineMode: perMessageQueueMode,", + " inlineOptions: perMessageQueueOptions", + " });", + ' const piRuntime = useFastReplyRuntime ? null : await traceRunPhase("reply.load_pi_runtime", () => loadPiEmbeddedRuntime());', + " const followupRun = {", + " prompt: queuedBody,", + " transcriptPrompt: transcriptCommandBody,", + " currentInboundEventKind: inboundEventKind,", + " currentInboundContext,", + " abortSignal: opts?.abortSignal,", + " run: { sessionId: preparedSessionState.sessionId }", + " };", + " return { resolvedQueue, piRuntime, followupRun };", + "}", + "", + ].join("\n"), + ); + return fixture; +} + +function runPatch(dist: string) { + return spawnSync(process.execPath, [PATCH_SCRIPT, dist], { + encoding: "utf-8", + timeout: 5000, + }); +} + +describe("OpenClaw chat.send compatibility patch", () => { + it("correlates agent runs, idempotently appends transcripts, and suppresses empty finals", () => { + const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-openclaw-chat-send-")); + const dist = path.join(tmp, "dist"); + fs.mkdirSync(dist); + const chatFixture = writeChatSendFixture(dist); + const followupFixture = writeFollowupRunnerFixture(dist); + const getReplyFixture = writeGetReplyFixture(dist); + + try { + const patch = runPatch(dist); + expect(patch.status, `${patch.stdout}${patch.stderr}`).toBe(0); + expect(patch.stdout).toContain("patched OpenClaw chat.send compatibility"); + + const patched = fs.readFileSync(chatFixture, "utf-8"); + expect(patched).toContain( + "context.addChatRun(runId, { sessionKey, clientRunId }); // nemoclaw: correlate chat.send run ids (#2603, #3145)", + ); + expect(patched).toContain("idempotencyKey: clientRunId"); + expect(patched).toContain("if (message) broadcastChatFinal({"); + expect(patched).toContain("suppressing empty final event"); + + const patchedFollowup = fs.readFileSync(followupFixture, "utf-8"); + expect(patchedFollowup).toContain( + "const runId = queued.runId ?? opts?.runId ?? crypto.randomUUID(); // nemoclaw: preserve chat.send run ids in followup queue (#2603, #3145)", + ); + const patchedGetReply = fs.readFileSync(getReplyFixture, "utf-8"); + expect(patchedGetReply).toContain( + "runId: opts?.runId, // nemoclaw: carry chat.send run id into queued followup (#2603, #3145)", + ); + expect(patchedGetReply).toContain( + 'if (opts?.runId && sessionCtx.Provider === "webchat" && resolvedQueue.mode === "steer") resolvedQueue = {', + ); + expect(patchedGetReply).toContain( + "}; // nemoclaw: force webchat chat.send queued turns to keep per-message replies (#2603, #3145)", + ); + + const rerun = runPatch(dist); + expect(rerun.status, `${rerun.stdout}${rerun.stderr}`).toBe(0); + const rerunPatched = fs.readFileSync(chatFixture, "utf-8"); + expect(rerunPatched.match(/context\.addChatRun\(runId/g)).toHaveLength(1); + expect(rerunPatched.match(/idempotencyKey: clientRunId/g)).toHaveLength(1); + expect(rerunPatched.match(/suppressing empty final event/g)).toHaveLength(1); + const rerunPatchedFollowup = fs.readFileSync(followupFixture, "utf-8"); + expect(rerunPatchedFollowup.match(/preserve chat\.send run ids in followup queue/g)).toHaveLength( + 1, + ); + const rerunPatchedGetReply = fs.readFileSync(getReplyFixture, "utf-8"); + expect(rerunPatchedGetReply.match(/carry chat\.send run id into queued followup/g)).toHaveLength( + 1, + ); + expect(rerunPatchedGetReply.match(/force webchat chat\.send queued turns/g)).toHaveLength(1); + } finally { + fs.rmSync(tmp, { recursive: true, force: true }); + } + }); + + it("fails closed when the OpenClaw chat.send source shape changes", () => { + const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-openclaw-chat-send-missing-")); + const dist = path.join(tmp, "dist"); + fs.mkdirSync(dist); + fs.writeFileSync(path.join(dist, "chat-fixture.js"), 'const handlers = { "chat.send": true };\n'); + + try { + const patch = runPatch(dist); + expect(patch.status).toBe(1); + expect(patch.stderr).toContain("expected exactly one OpenClaw chat.send runtime file"); + } finally { + fs.rmSync(tmp, { recursive: true, force: true }); + } + }); +}); diff --git a/test/openclaw-tui-chat-correlation.test.ts b/test/openclaw-tui-chat-correlation.test.ts index f0cfd5bb069..c7ef1604bd8 100644 --- a/test/openclaw-tui-chat-correlation.test.ts +++ b/test/openclaw-tui-chat-correlation.test.ts @@ -14,8 +14,9 @@ const LIVE_SCRIPT_NAME = "openclaw-issue2603-chat-correlation.cjs"; const ISSUE_2603_FIX_EXPECTATIONS = [ "no empty final event for a submitted chat.send run", + "each submitted prompt receives exactly one visible reply", "each visible reply remains correlated to the chat.send run that accepted the prompt", - "chat.history contains one user turn per submitted prompt", + "chat.history contains exactly one user turn per submitted prompt", ]; type ChatMessage = { @@ -72,7 +73,10 @@ type DuplicateUserTurn = { type Issue2603Analysis = { chatEvents: CompactChatEvent[]; emptyFinalsForSubmittedRuns: CompactChatEvent[]; + missingReplies: string[]; + duplicateReplies: { replyToken: string; count: number }[]; uncorrelatedReplies: UncorrelatedReply[]; + missingUserTurns: DuplicateUserTurn[]; duplicateUserTurns: DuplicateUserTurn[]; }; @@ -132,9 +136,15 @@ function analyzeIssue2603Trace({ sentRuns, events, historyMessages }: Issue2603T ); const uncorrelatedReplies: UncorrelatedReply[] = []; + const visibleReplyCounts = new Map(); + const finalReplyCounts = new Map(); for (const [replyToken, expectedRunId] of expectedRunByReplyToken) { for (const event of chatEvents) { if (!event.text.includes(replyToken)) continue; + visibleReplyCounts.set(replyToken, (visibleReplyCounts.get(replyToken) ?? 0) + 1); + if (event.state === "final") { + finalReplyCounts.set(replyToken, (finalReplyCounts.get(replyToken) ?? 0) + 1); + } if (event.runId !== expectedRunId) { uncorrelatedReplies.push({ replyToken, @@ -145,6 +155,15 @@ function analyzeIssue2603Trace({ sentRuns, events, historyMessages }: Issue2603T } } } + const missingReplies = sentRuns + .map((entry) => entry.replyToken) + .filter((replyToken) => !visibleReplyCounts.has(replyToken)); + const duplicateReplies = sentRuns + .map((entry) => ({ + replyToken: entry.replyToken, + count: finalReplyCounts.get(entry.replyToken) ?? 0, + })) + .filter((entry) => entry.count > 1); const userPromptCounts = countBy( historyMessages @@ -152,17 +171,21 @@ function analyzeIssue2603Trace({ sentRuns, events, historyMessages }: Issue2603T .map((message) => textFromMessage(message).trim()) .filter(Boolean), ); - const duplicateUserTurns = sentRuns + const userTurnCounts = sentRuns .map((entry) => ({ promptToken: entry.promptToken, count: userPromptCounts.get(entry.message) ?? 0, - })) - .filter((entry) => entry.count > 1); + })); + const missingUserTurns = userTurnCounts.filter((entry) => entry.count < 1); + const duplicateUserTurns = userTurnCounts.filter((entry) => entry.count > 1); return { chatEvents, emptyFinalsForSubmittedRuns, + missingReplies, + duplicateReplies, uncorrelatedReplies, + missingUserTurns, duplicateUserTurns, }; } @@ -172,7 +195,10 @@ function buildFailureSummary(analysis: Issue2603Analysis): string { { expectations: ISSUE_2603_FIX_EXPECTATIONS, emptyFinalsForSubmittedRuns: analysis.emptyFinalsForSubmittedRuns, + missingReplies: analysis.missingReplies, + duplicateReplies: analysis.duplicateReplies, uncorrelatedReplies: analysis.uncorrelatedReplies, + missingUserTurns: analysis.missingUserTurns, duplicateUserTurns: analysis.duplicateUserTurns, chatEvents: analysis.chatEvents, }, @@ -375,8 +401,8 @@ ws.on("error", (error) => { ws.on("open", async () => { try { await request("connect", { - minProtocol: 3, - maxProtocol: 3, + minProtocol: 4, + maxProtocol: 4, client: { id: "openclaw-control-ui", displayName: "issue2603-live-repro", @@ -496,6 +522,49 @@ describe("OpenClaw TUI chat correlation regression (#2603)", () => { ]); }); + it("does not classify a streamed delta plus final for the same run as a duplicate reply", () => { + const analysis = analyzeIssue2603Trace({ + sentRuns: [ + { + promptToken: "B2603", + replyToken: "B2603-REPLY", + runId: "a32dc5a4-9b45-4109-9b17-2fcd35787d0c", + message: "B2603: Second task. Reply exactly B2603-REPLY and nothing else.", + }, + ], + events: [ + { + event: "chat", + payload: { + runId: "a32dc5a4-9b45-4109-9b17-2fcd35787d0c", + state: "delta", + message: { role: "assistant", content: [{ type: "text", text: "B2603-REPLY" }] }, + }, + }, + { + event: "chat", + payload: { + runId: "a32dc5a4-9b45-4109-9b17-2fcd35787d0c", + state: "final", + message: { role: "assistant", content: [{ type: "text", text: "B2603-REPLY" }] }, + }, + }, + ], + historyMessages: [ + { + role: "user", + content: [ + { type: "text", text: "B2603: Second task. Reply exactly B2603-REPLY and nothing else." }, + ], + }, + ], + }); + + expect(analysis.missingReplies).toEqual([]); + expect(analysis.duplicateReplies).toEqual([]); + expect(analysis.uncorrelatedReplies).toEqual([]); + }); + it.runIf(process.env[LIVE_REPRO_ENV] === "1")( "keeps rapid live TUI/webchat sends correlated on a real OpenClaw sandbox", () => { @@ -506,7 +575,10 @@ describe("OpenClaw TUI chat correlation regression (#2603)", () => { const analysis = analyzeIssue2603Trace(repro); const failureSummary = buildFailureSummary(analysis); expect(analysis.emptyFinalsForSubmittedRuns, failureSummary).toEqual([]); + expect(analysis.missingReplies, failureSummary).toEqual([]); + expect(analysis.duplicateReplies, failureSummary).toEqual([]); expect(analysis.uncorrelatedReplies, failureSummary).toEqual([]); + expect(analysis.missingUserTurns, failureSummary).toEqual([]); expect(analysis.duplicateUserTurns, failureSummary).toEqual([]); }, 190_000, diff --git a/test/sandbox-build-context.test.ts b/test/sandbox-build-context.test.ts index 12ff1a56c66..c71a2be0cc8 100644 --- a/test/sandbox-build-context.test.ts +++ b/test/sandbox-build-context.test.ts @@ -74,6 +74,7 @@ describe("sandbox build context staging", () => { writeFixture(path.join("scripts", "generate-openclaw-config.py")); writeFixture(path.join("scripts", "seed-wechat-accounts.py")); writeFixture(path.join("scripts", "patch-openclaw-tool-catalog.js")); + writeFixture(path.join("scripts", "patch-openclaw-chat-send.js")); } function expectStagedBlueprintModes(buildCtx: string) { @@ -201,6 +202,9 @@ describe("sandbox build context staging", () => { expect(fs.existsSync(path.join(buildCtx, "scripts", "patch-openclaw-tool-catalog.js"))).toBe( true, ); + expect(fs.existsSync(path.join(buildCtx, "scripts", "patch-openclaw-chat-send.js"))).toBe( + true, + ); expect(fs.existsSync(path.join(buildCtx, "scripts", "lib", "sandbox-init.sh"))).toBe(true); expect(fs.existsSync(path.join(buildCtx, "scripts", "setup.sh"))).toBe(false); } finally {