mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 01:41:36 +00:00
Sessions: persist prompt-token totals without usage
This commit is contained in:
@@ -960,6 +960,43 @@ describe("runReplyAgent messaging tool suppression", () => {
|
||||
expect(store[sessionKey]?.totalTokensFresh).toBe(true);
|
||||
expect(store[sessionKey]?.model).toBe("claude-opus-4-5");
|
||||
});
|
||||
|
||||
it("persists totalTokens from promptTokens when provider omits usage", async () => {
|
||||
const storePath = path.join(
|
||||
await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-session-store-")),
|
||||
"sessions.json",
|
||||
);
|
||||
const sessionKey = "main";
|
||||
const entry: SessionEntry = {
|
||||
sessionId: "session",
|
||||
updatedAt: Date.now(),
|
||||
inputTokens: 111,
|
||||
outputTokens: 22,
|
||||
};
|
||||
await saveSessionStore(storePath, { [sessionKey]: entry });
|
||||
|
||||
runEmbeddedPiAgentMock.mockResolvedValueOnce({
|
||||
payloads: [{ text: "hello world!" }],
|
||||
messagingToolSentTexts: ["different message"],
|
||||
messagingToolSentTargets: [{ tool: "slack", provider: "slack", to: "channel:C1" }],
|
||||
meta: {
|
||||
agentMeta: {
|
||||
promptTokens: 41_000,
|
||||
model: "claude-opus-4-5",
|
||||
provider: "anthropic",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const result = await createRun("slack", { storePath, sessionKey });
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
const store = loadSessionStore(storePath, { skipCache: true });
|
||||
expect(store[sessionKey]?.totalTokens).toBe(41_000);
|
||||
expect(store[sessionKey]?.totalTokensFresh).toBe(true);
|
||||
expect(store[sessionKey]?.inputTokens).toBe(111);
|
||||
expect(store[sessionKey]?.outputTokens).toBe(22);
|
||||
});
|
||||
});
|
||||
|
||||
describe("runReplyAgent reminder commitment guard", () => {
|
||||
|
||||
Reference in New Issue
Block a user