mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 20:40:43 +00:00
fix: sanitize assembled diagnostic context
This commit is contained in:
@@ -97,6 +97,45 @@ describe("diagnostic stability recorder", () => {
|
||||
expect(snapshot.events[1]).not.toHaveProperty("reason");
|
||||
});
|
||||
|
||||
it("summarizes assembled context diagnostics without prompt text", async () => {
|
||||
startDiagnosticStabilityRecorder();
|
||||
|
||||
emitDiagnosticEvent({
|
||||
type: "context.assembled",
|
||||
runId: "run-secret",
|
||||
sessionId: "session-secret",
|
||||
provider: "openai",
|
||||
model: "gpt-5.4",
|
||||
channel: "telegram",
|
||||
trigger: "user-message",
|
||||
messageCount: 4,
|
||||
historyTextChars: 1200,
|
||||
historyImageBlocks: 1,
|
||||
maxMessageTextChars: 800,
|
||||
systemPromptChars: 300,
|
||||
promptChars: 100,
|
||||
promptImages: 1,
|
||||
contextTokenBudget: 200_000,
|
||||
reserveTokens: 20_000,
|
||||
});
|
||||
await new Promise<void>((resolve) => setImmediate(resolve));
|
||||
|
||||
const snapshot = getDiagnosticStabilitySnapshot({ limit: 10 });
|
||||
|
||||
expect(snapshot.events[0]).toMatchObject({
|
||||
type: "context.assembled",
|
||||
provider: "openai",
|
||||
model: "gpt-5.4",
|
||||
channel: "telegram",
|
||||
count: 4,
|
||||
context: { limit: 200_000 },
|
||||
});
|
||||
expect(snapshot.events[0]).not.toHaveProperty("runId");
|
||||
expect(snapshot.events[0]).not.toHaveProperty("sessionId");
|
||||
expect(snapshot.events[0]).not.toHaveProperty("promptChars");
|
||||
expect(snapshot.events[0]).not.toHaveProperty("systemPromptChars");
|
||||
});
|
||||
|
||||
it("sanitizes tool and model diagnostic error categories", async () => {
|
||||
startDiagnosticStabilityRecorder();
|
||||
|
||||
|
||||
@@ -246,6 +246,14 @@ function sanitizeDiagnosticEvent(event: DiagnosticEventPayload): DiagnosticStabi
|
||||
case "run.attempt":
|
||||
record.count = event.attempt;
|
||||
break;
|
||||
case "context.assembled":
|
||||
record.channel = event.channel;
|
||||
record.provider = event.provider;
|
||||
record.model = event.model;
|
||||
record.count = event.messageCount;
|
||||
record.context =
|
||||
event.contextTokenBudget !== undefined ? { limit: event.contextTokenBudget } : undefined;
|
||||
break;
|
||||
case "diagnostic.heartbeat":
|
||||
record.webhooks = { ...event.webhooks };
|
||||
record.active = event.active;
|
||||
|
||||
Reference in New Issue
Block a user