惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
N
Netflix TechBlog - Medium
P
Proofpoint News Feed
D
Docker
J
Java Code Geeks
L
LangChain Blog
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
I
InfoQ
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
T
Tailwind CSS Blog
M
MIT News - Artificial intelligence
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
腾讯CDC
罗磊的独立博客
U
Unit 42
爱范儿
爱范儿
Vercel News
Vercel News
MyScale Blog
MyScale Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(compaction): trim prefix when transcript ends in an o...
yetval · 2026-06-23 · via Recent Commits to openclaw:main
1+

import { describe, expect, it } from "vitest";

2+

import type { AgentMessage } from "../../types.js";

3+

import type { SessionTreeEntry } from "../types.js";

4+

import { estimateTokens, findCutPoint } from "./compaction.js";

5+6+

const KEEP_RECENT_TOKENS = 20000;

7+

const LARGE_TOOL_OUTPUT = "x".repeat(120000);

8+9+

function userText(text: string, timestamp: number): AgentMessage {

10+

return { role: "user", content: [{ type: "text", text }], timestamp };

11+

}

12+13+

function assistantText(text: string, timestamp: number): AgentMessage {

14+

return {

15+

role: "assistant",

16+

content: [{ type: "text", text }],

17+

api: "anthropic-messages",

18+

provider: "anthropic",

19+

model: "claude-fable-5",

20+

usage: {

21+

input: 0,

22+

output: 0,

23+

cacheRead: 0,

24+

cacheWrite: 0,

25+

totalTokens: 0,

26+

cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },

27+

},

28+

stopReason: "stop",

29+

timestamp,

30+

};

31+

}

32+33+

function toolResultText(text: string, timestamp: number): AgentMessage {

34+

return {

35+

role: "toolResult",

36+

toolCallId: "call-1",

37+

toolName: "bash",

38+

content: [{ type: "text", text }],

39+

isError: false,

40+

timestamp,

41+

};

42+

}

43+44+

function messageEntry(message: AgentMessage, index: number): SessionTreeEntry {

45+

return {

46+

type: "message",

47+

id: `entry-${index}`,

48+

parentId: index === 0 ? null : `entry-${index - 1}`,

49+

timestamp: new Date(message.timestamp).toISOString(),

50+

message,

51+

};

52+

}

53+54+

function buildTranscript(): SessionTreeEntry[] {

55+

const messages: AgentMessage[] = [

56+

userText("start of the conversation", 1),

57+

assistantText("first reply", 2),

58+

userText("please run the command", 3),

59+

assistantText("running it now", 4),

60+

toolResultText(LARGE_TOOL_OUTPUT, 5),

61+

];

62+

return messages.map((message, index) => messageEntry(message, index));

63+

}

64+65+

describe("findCutPoint with a trailing oversized tool result", () => {

66+

it("counts the final tool result as larger than the keep budget", () => {

67+

const trailing = toolResultText(LARGE_TOOL_OUTPUT, 5);

68+69+

expect(estimateTokens(trailing)).toBeGreaterThanOrEqual(KEEP_RECENT_TOKENS);

70+

});

71+72+

it("trims the prefix instead of keeping the whole transcript", () => {

73+

const entries = buildTranscript();

74+75+

const result = findCutPoint(entries, 0, entries.length, KEEP_RECENT_TOKENS);

76+77+

expect(result.firstKeptEntryIndex).toBeGreaterThan(0);

78+

expect(result.firstKeptEntryIndex).toBe(3);

79+

});

80+

});