mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 17:33:31 +00:00
fix: address code review - nested object hashing and error logging
This commit is contained in:
committed by
Gustavo Madeira Santana
parent
40939b29a2
commit
917dddb27b
@@ -17,16 +17,25 @@ export const CRITICAL_THRESHOLD = 20;
|
||||
*/
|
||||
export function hashToolCall(toolName: string, params: unknown): string {
|
||||
try {
|
||||
const paramsStr =
|
||||
typeof params === "object" && params !== null
|
||||
? JSON.stringify(params, Object.keys(params).toSorted())
|
||||
: String(params);
|
||||
const paramsStr = stableStringify(params);
|
||||
return `${toolName}:${paramsStr}`;
|
||||
} catch {
|
||||
return `${toolName}:${String(params)}`;
|
||||
}
|
||||
}
|
||||
|
||||
function stableStringify(value: unknown): string {
|
||||
if (value === null || typeof value !== "object") {
|
||||
return JSON.stringify(value);
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
return `[${value.map(stableStringify).join(",")}]`;
|
||||
}
|
||||
const obj = value as Record<string, unknown>;
|
||||
const keys = Object.keys(obj).toSorted();
|
||||
return `{${keys.map((k) => `${JSON.stringify(k)}:${stableStringify(obj[k])}`).join(",")}}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect if an agent is stuck in a repetitive tool call loop.
|
||||
* Checks if the same tool+params combination has been called excessively.
|
||||
|
||||
@@ -320,7 +320,9 @@ export function startDiagnosticHeartbeat() {
|
||||
pruneStaleCommandPolls(state);
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
.catch((err) => {
|
||||
diag.debug(`command-poll-backoff prune failed: ${String(err)}`);
|
||||
});
|
||||
|
||||
for (const [, state] of diagnosticSessionStates) {
|
||||
const ageMs = now - state.lastActivity;
|
||||
|
||||
Reference in New Issue
Block a user