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

推荐订阅源

小众软件
小众软件
C
Check Point Blog
Vercel News
Vercel News
Y
Y Combinator Blog
G
Google Developers Blog
P
Proofpoint News Feed
WordPress大学
WordPress大学
MongoDB | Blog
MongoDB | Blog
博客园 - 司徒正美
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
N
Netflix TechBlog - Medium
L
LangChain Blog
V
V2EX
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
博客园_首页
B
Blog RSS Feed
The Cloudflare Blog
MyScale Blog
MyScale Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Security Blog
Microsoft Security 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(sessions): stream transcript reverse scans · openclaw...
steipete · 2026-05-11 · via Recent Commits to openclaw:main

@@ -3,8 +3,8 @@ import os from "node:os";

33

import path from "node:path";

44

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

55

import {

6-

readSessionTranscriptTailLines,

76

streamSessionTranscriptLines,

7+

streamSessionTranscriptLinesReverse,

88

} from "./transcript-stream.js";

991010

// Regression coverage for #54296: the transcript readers must stay correct and

@@ -95,67 +95,100 @@ describe("streamSessionTranscriptLines", () => {

9595

});

9696

});

979798-

describe("readSessionTranscriptTailLines", () => {

99-

it("returns trimmed non-empty lines in reverse order for short files", async () => {

98+

describe("streamSessionTranscriptLinesReverse", () => {

99+

it("yields trimmed non-empty lines in reverse order for short files", async () => {

100100

fs.writeFileSync(transcriptPath, "first\nsecond\nthird\n", "utf-8");

101101102-

const lines = await readSessionTranscriptTailLines(transcriptPath);

102+

const lines = await collect(streamSessionTranscriptLinesReverse(transcriptPath));

103103104104

expect(lines).toEqual(["third", "second", "first"]);

105105

});

106106107-

it("returns undefined when the file cannot be opened", async () => {

108-

const lines = await readSessionTranscriptTailLines(path.join(tempDir, "missing.jsonl"));

107+

it("returns an empty iterator when the file cannot be opened", async () => {

108+

const lines = await collect(

109+

streamSessionTranscriptLinesReverse(path.join(tempDir, "missing.jsonl")),

110+

);

109111110-

expect(lines).toBeUndefined();

112+

expect(lines).toEqual([]);

111113

});

112114113-

it("returns an empty array for an empty file", async () => {

115+

it("returns an empty iterator for an empty file", async () => {

114116

fs.writeFileSync(transcriptPath, "", "utf-8");

115117116-

const lines = await readSessionTranscriptTailLines(transcriptPath);

118+

const lines = await collect(streamSessionTranscriptLinesReverse(transcriptPath));

117119118120

expect(lines).toEqual([]);

119121

});

120122121-

it("drops the leading partial line when the window does not start at byte zero", async () => {

122-

// Build a file longer than the requested tail window. The first line of

123-

// the slice we end up reading should be a suffix of an earlier line; the

124-

// helper must discard it so callers do not see corrupt JSON.

125-

const longPrefix = "x".repeat(2048);

126-

const content = `${longPrefix}\nbeta\ngamma\n`;

127-

fs.writeFileSync(transcriptPath, content, "utf-8");

123+

it("preserves complete lines across chunk boundaries", async () => {

124+

const longLine = "x".repeat(2048);

125+

fs.writeFileSync(transcriptPath, `${longLine}\nbeta\ngamma\n`, "utf-8");

128126129-

const lines = await readSessionTranscriptTailLines(transcriptPath, {

130-

maxBytes: 16,

131-

});

127+

const lines = await collect(

128+

streamSessionTranscriptLinesReverse(transcriptPath, {

129+

chunkBytes: 1024,

130+

}),

131+

);

132132133-

expect(lines).not.toContain(longPrefix);

134-

expect(lines).toEqual(["gamma", "beta"]);

133+

expect(lines).toEqual(["gamma", "beta", longLine]);

135134

});

136135137-

it("does not drop the first line when the window covers the entire file", async () => {

138-

fs.writeFileSync(transcriptPath, "alpha\nbeta\ngamma\n", "utf-8");

136+

it("preserves multibyte UTF-8 across chunk boundaries", async () => {

137+

const firstLine = `${"a".repeat(1100)}🌊`;

138+

const secondLine = `${"b".repeat(1100)}✅`;

139+

fs.writeFileSync(transcriptPath, `${firstLine}\n${secondLine}\n`, "utf-8");

139140140-

const lines = await readSessionTranscriptTailLines(transcriptPath, {

141-

maxBytes: 64 * 1024,

142-

});

141+

const lines = await collect(

142+

streamSessionTranscriptLinesReverse(transcriptPath, {

143+

chunkBytes: 1024,

144+

}),

145+

);

143146144-

expect(lines).toEqual(["gamma", "beta", "alpha"]);

147+

expect(lines).toEqual([secondLine, firstLine]);

148+

});

149+150+

it("honours an abort signal between reverse lines", async () => {

151+

fs.writeFileSync(transcriptPath, "one\ntwo\nthree\n", "utf-8");

152+

const controller = new AbortController();

153+154+

const out: string[] = [];

155+

for await (const line of streamSessionTranscriptLinesReverse(transcriptPath, {

156+

signal: controller.signal,

157+

})) {

158+

out.push(line);

159+

if (line === "three") {

160+

controller.abort();

161+

}

162+

}

163+164+

expect(out).toEqual(["three"]);

145165

});

146166147-

it("clamps a sub-minimum maxBytes to the floor instead of returning nothing", async () => {

167+

it("clamps a sub-minimum chunk size without dropping older lines", async () => {

148168

fs.writeFileSync(transcriptPath, "alpha\nbeta\ngamma\n", "utf-8");

149169150-

const lines = await readSessionTranscriptTailLines(transcriptPath, {

151-

maxBytes: 16,

152-

});

170+

const lines = await collect(

171+

streamSessionTranscriptLinesReverse(transcriptPath, {

172+

chunkBytes: 16,

173+

}),

174+

);

153175154-

// The full file is smaller than the 1 KiB floor, so we still read the

155-

// whole file and return all three lines in reverse order.

156176

expect(lines).toEqual(["gamma", "beta", "alpha"]);

157177

});

158178179+

it("does not emit a partial prefix until the full first line is available", async () => {

180+

const firstLine = "prefix".repeat(400);

181+

fs.writeFileSync(transcriptPath, `${firstLine}\nbeta\ngamma`, "utf-8");

182+183+

const lines = await collect(

184+

streamSessionTranscriptLinesReverse(transcriptPath, {

185+

chunkBytes: 1024,

186+

}),

187+

);

188+189+

expect(lines).toEqual(["gamma", "beta", firstLine]);

190+

});

191+159192

it("preserves JSONL line ordering so reverse scans hit the newest match first", async () => {

160193

fs.writeFileSync(

161194

transcriptPath,

@@ -167,10 +200,9 @@ describe("readSessionTranscriptTailLines", () => {

167200

"utf-8",

168201

);

169202170-

const lines = await readSessionTranscriptTailLines(transcriptPath);

203+

const lines = await collect(streamSessionTranscriptLinesReverse(transcriptPath));

204+

const parsed = lines.map((line) => JSON.parse(line) as { id: string });

171205172-

expect(lines).toBeDefined();

173-

const parsed = lines!.map((line) => JSON.parse(line) as { id: string });

174206

expect(parsed.map((entry) => entry.id)).toEqual(["third", "second", "first"]);

175207

});

176208

});