refactor: move usage cost cache into agent database (#106051)

* refactor(infra): rename usage cache lock owner field

* refactor(state): migrate usage cost cache to SQLite

* fix(state): satisfy SQLite migration gates

* refactor(state): keep usage cache access synchronous

* chore: leave release notes to release workflow

* fix(state): satisfy dependency export gate
This commit is contained in:
Peter Steinberger
2026-07-12 22:39:54 -07:00
committed by GitHub
parent 8c7f3d087f
commit db252ac417
12 changed files with 598 additions and 391 deletions

View File

@@ -31,6 +31,7 @@ function requireFirstEmbeddedAgentRequest(): {
provider?: string;
model?: string;
disableTools?: boolean;
sessionFile?: string;
} {
const [call] = runEmbeddedAgentMock.mock.calls;
if (!call) {
@@ -40,7 +41,12 @@ function requireFirstEmbeddedAgentRequest(): {
if (!request || typeof request !== "object" || Array.isArray(request)) {
throw new Error("expected embedded OpenClaw agent extraction request");
}
return request as { provider?: string; model?: string; disableTools?: boolean };
return request as {
provider?: string;
model?: string;
disableTools?: boolean;
sessionFile?: string;
};
}
describe("commitment extraction runtime", () => {
@@ -268,6 +274,7 @@ describe("commitment extraction runtime", () => {
expect(request.provider).toBe("openai");
expect(request.model).toBe("gpt-5.5");
expect(request.disableTools).toBe(true);
expect(request.sessionFile).toBeUndefined();
});
it("backs off hidden extraction after terminal model or auth failures", async () => {

View File

@@ -1,11 +1,9 @@
// Runs commitment extraction, scheduling, and follow-up lifecycle work.
import { randomUUID } from "node:crypto";
import path from "node:path";
import { resolveExpiresAtMsFromDurationMs } from "@openclaw/normalization-core/number-coercion";
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
import { resolveAgentWorkspaceDir } from "../agents/agent-scope.js";
import type { OpenClawConfig } from "../config/config.js";
import { resolveStateDir } from "../config/paths.js";
import { createSubsystemLogger } from "../logging/subsystem.js";
import { resolveCommitmentTimezone, resolveCommitmentsConfig } from "./config.js";
import {
@@ -211,16 +209,6 @@ function openTerminalFailureCooldown(
});
}
function resolveExtractionSessionFile(agentId: string, runId: string): string {
return path.join(
resolveStateDir(),
"commitments",
"extractor-sessions",
agentId,
`${runId}.jsonl`,
);
}
function joinPayloadText(result: EmbeddedAgentPayloadResult): string {
return (
result.payloads
@@ -260,7 +248,6 @@ async function defaultExtractBatch(params: {
sessionKey: `agent:${first.agentId}:commitments:${runId}`,
agentId: first.agentId,
trigger: "manual",
sessionFile: resolveExtractionSessionFile(first.agentId, runId),
workspaceDir: resolveAgentWorkspaceDir(cfg, first.agentId),
config: cfg,
provider: modelRef.provider,