Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
]
},
"scripts": {
"test": "node test/embedder-error-hints.test.mjs && node test/migrate-legacy-schema.test.mjs && node --test test/config-session-strategy-migration.test.mjs && node test/update-consistency-lancedb.test.mjs && node test/cli-smoke.mjs && node test/functional-e2e.mjs && node test/retriever-rerank-regression.mjs && node test/smart-memory-lifecycle.mjs && node test/smart-extractor-branches.mjs && node test/plugin-manifest-regression.mjs",
"test": "node test/embedder-error-hints.test.mjs && node test/migrate-legacy-schema.test.mjs && node --test test/config-session-strategy-migration.test.mjs && node test/update-consistency-lancedb.test.mjs && node test/cli-smoke.mjs && node test/functional-e2e.mjs && node test/retriever-rerank-regression.mjs && node test/smart-memory-lifecycle.mjs && node test/smart-extractor-branches.mjs && node test/plugin-manifest-regression.mjs && node --test test/adaptive-retrieval-skip-heartbeat.test.mjs",
"test:openclaw-host": "node test/openclaw-host-functional.mjs"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions src/adaptive-retrieval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const SKIP_PATTERNS = [
/^[\p{Emoji}\s]+$/u,
// Heartbeat/system (match anywhere, not just at start, to handle prefixed formats)
/HEARTBEAT/i,
/^(no[_-]?reply|noreply)\s*[.!]?$/i,
/^(heartbeat(_ok|_fail|_err|_error)?|heartbeat\s*(ok|fail|error)|health[_ -]?check|system[_ -]?check|status[_ -]?check)\s*[.!]?$/i,
/^\[System/i,
// Single-word utility pings
/^(ping|pong|test|debug)\s*[.!?]?$/i,
Expand Down Expand Up @@ -57,6 +59,10 @@ function normalizeQuery(query: string): string {
// 3. Strip OpenClaw timestamp prefix [Mon 2026-03-02 04:21 GMT+8].
s = s.trim().replace(/^\[[A-Za-z]{3}\s\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}\s[^\]]+\]\s*/, "");

// 4. Strip heartbeat/healthcheck wrappers.
s = s.trim().replace(/^\[(heartbeat|health[-_ ]?check|system[-_ ]?check)[^\]]*\]\s*/i, "");
s = s.trim().replace(/^(heartbeat|health[-_ ]?check|system[-_ ]?check)\s*[:\-]\s*/i, "");

const result = s.trim();
return result;
}
Expand Down
27 changes: 27 additions & 0 deletions test/adaptive-retrieval-skip-heartbeat.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, it } from "node:test";
import assert from "node:assert/strict";
import jitiFactory from "jiti";

const jiti = jitiFactory(import.meta.url, { interopDefault: true });

const { shouldSkipRetrieval } = jiti("../src/adaptive-retrieval.ts");

describe("shouldSkipRetrieval heartbeat/NO_REPLY", () => {
const cases = [
"NO_REPLY",
"no_reply",
"no-reply",
"HEARTBEAT_OK",
"heartbeat ok",
"heartbeat: NO_REPLY",
"[heartbeat] NO_REPLY",
"health_check",
"system-check",
];

for (const input of cases) {
it(`skips retrieval for ${input}`, () => {
assert.equal(shouldSkipRetrieval(input), true);
});
}
});
Loading