Skip to content

Commit 1249a8d

Browse files
committed
fix(gateway): preserve OpenAI usage aliases in chat history
1 parent 6ea907c commit 1249a8d

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Docs: https://docs.openclaw.ai
4646
- Skills: watch each shared skill directory once across agent workspaces instead of once per agent, preventing file-descriptor exhaustion (`EMFILE`) that disposed bundle-mcp processes and stalled sessions on multi-agent gateways. Fixes #84968. (#85130) Thanks @openperf.
4747
- Cron: honor `cron.retry.retryOn: ["network"]` for common network error codes such as `EAI_AGAIN`, `EHOSTUNREACH`, and `ENETUNREACH`.
4848
- Gateway chat: broadcast returned agent-run error payloads after an agent starts so ACP/WebChat clients receive terminal idle-timeout errors. Fixes #84945.
49+
- Gateway chat display: preserve OpenAI-compatible `prompt_tokens`, `completion_tokens`, and `total_tokens` usage fields in sanitized chat history so llama.cpp sessions keep context counts. Fixes #77992. Thanks @MarTT79.
4950
- Dashboard/CLI: allow macOS browser launching through `open` even when SSH environment variables are present, while preserving Linux SSH no-display protection. Fixes #67088. Thanks @theglove44.
5051
- Codex app-server: keep native web search observations out of mirrored chat transcripts while preserving tool progress telemetry. Fixes #85109. Thanks @ugitmebaby.
5152
- Agents/OpenAI: preserve structured provider error code, type, and redacted body metadata on boundary-aware transport failures.

src/gateway/chat-display-projection.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,21 @@ function sanitizeUsage(raw: unknown): Record<string, number> | undefined {
228228
const knownFields = [
229229
"input",
230230
"output",
231+
"total",
231232
"totalTokens",
232233
"inputTokens",
233234
"outputTokens",
235+
"promptTokens",
236+
"completionTokens",
234237
"cacheRead",
235238
"cacheWrite",
236239
"cache_read_input_tokens",
237240
"cache_creation_input_tokens",
241+
"input_tokens",
242+
"output_tokens",
243+
"prompt_tokens",
244+
"completion_tokens",
245+
"total_tokens",
238246
];
239247

240248
for (const k of knownFields) {

src/gateway/server-methods/server-methods.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,35 @@ describe("sanitizeChatHistoryMessages", () => {
530530
]);
531531
});
532532

533+
it("preserves OpenAI-compatible assistant usage aliases for display context", () => {
534+
const result = sanitizeChatHistoryMessages([
535+
{
536+
role: "assistant",
537+
content: [{ type: "text", text: "done" }],
538+
usage: {
539+
prompt_tokens: 11,
540+
completion_tokens: 1,
541+
total_tokens: 12,
542+
provider_payload: "discard",
543+
},
544+
timestamp: 1,
545+
},
546+
]);
547+
548+
expect(result).toEqual([
549+
{
550+
role: "assistant",
551+
content: [{ type: "text", text: "done" }],
552+
usage: {
553+
prompt_tokens: 11,
554+
completion_tokens: 1,
555+
total_tokens: 12,
556+
},
557+
timestamp: 1,
558+
},
559+
]);
560+
});
561+
533562
it("drops commentary-only assistant entries when phase exists only in textSignature", () => {
534563
const result = sanitizeChatHistoryMessages([
535564
{

0 commit comments

Comments
 (0)