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

推荐订阅源

G
Google Developers Blog
博客园 - 三生石上(FineUI控件)
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MongoDB | Blog
MongoDB | Blog
小众软件
小众软件
Y
Y Combinator Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
D
Docker
罗磊的独立博客
Microsoft Security Blog
Microsoft Security Blog
D
DataBreaches.Net
B
Blog
Vercel News
Vercel News
Recent Announcements
Recent Announcements
GbyAI
GbyAI
阮一峰的网络日志
阮一峰的网络日志
T
The Blog of Author Tim Ferriss
H
Hackread – Cybersecurity News, Data Breaches, AI and More
P
Proofpoint News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure 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
refactor(sessions): share bounded file range reads · open...
vincentkoc · 2026-06-22 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -0,0 +1,19 @@

1+

// Session file helpers share bounded random-access reads across transcript consumers.

2+

import type { FileHandle } from "node:fs/promises";

3+
4+

export async function readFileRangeAsync(

5+

fileHandle: FileHandle,

6+

position: number,

7+

length: number,

8+

): Promise<Buffer> {

9+

const buffer = Buffer.alloc(length);

10+

let offset = 0;

11+

while (offset < length) {

12+

const { bytesRead } = await fileHandle.read(buffer, offset, length - offset, position + offset);

13+

if (bytesRead <= 0) {

14+

break;

15+

}

16+

offset += bytesRead;

17+

}

18+

return offset === length ? buffer : buffer.subarray(0, offset);

19+

}

Original file line numberDiff line numberDiff line change

@@ -1,6 +1,7 @@

11

// Transcript streaming reads large JSONL files forward or backward without whole-file buffering.

22

import fs from "node:fs";

33

import readline from "node:readline";

4+

import { readFileRangeAsync } from "./file-range.js";

45
56

// Shared streaming helpers for JSONL session transcripts.

67

//

@@ -138,20 +139,3 @@ function decodeTrimmedLine(line: Buffer): string {

138139

const trimmed = line.toString("utf-8").trim();

139140

return trimmed;

140141

}

141-
142-

async function readFileRangeAsync(

143-

fileHandle: Awaited<ReturnType<typeof fs.promises.open>>,

144-

position: number,

145-

length: number,

146-

): Promise<Buffer> {

147-

const buffer = Buffer.alloc(length);

148-

let offset = 0;

149-

while (offset < length) {

150-

const { bytesRead } = await fileHandle.read(buffer, offset, length - offset, position + offset);

151-

if (bytesRead <= 0) {

152-

break;

153-

}

154-

offset += bytesRead;

155-

}

156-

return offset === length ? buffer : buffer.subarray(0, offset);

157-

}

Original file line numberDiff line numberDiff line change

@@ -15,6 +15,7 @@ import type {

1515

SessionEntry,

1616

} from "../config/sessions.js";

1717

import { isCompactionCheckpointTranscriptFileName } from "../config/sessions/artifacts.js";

18+

import { readFileRangeAsync } from "../config/sessions/file-range.js";

1819

import { streamSessionTranscriptLines } from "../config/sessions/transcript-stream.js";

1920

import { scanSessionTranscriptTree } from "../config/sessions/transcript-tree.js";

2021

import { CURRENT_SESSION_VERSION } from "../config/sessions/version.js";

@@ -158,29 +159,10 @@ export function resolveSessionCompactionCheckpointReason(params: {

158159

const SESSION_HEADER_READ_MAX_BYTES = 64 * 1024;

159160

const SESSION_TAIL_READ_INITIAL_BYTES = 64 * 1024;

160161
161-

type AsyncTranscriptFileHandle = Awaited<ReturnType<typeof fs.open>>;

162-
163-

async function readFileRangeAsync(

164-

fileHandle: AsyncTranscriptFileHandle,

165-

position: number,

166-

length: number,

167-

): Promise<Buffer> {

168-

const buffer = Buffer.alloc(length);

169-

let offset = 0;

170-

while (offset < length) {

171-

const { bytesRead } = await fileHandle.read(buffer, offset, length - offset, position + offset);

172-

if (bytesRead <= 0) {

173-

break;

174-

}

175-

offset += bytesRead;

176-

}

177-

return offset === length ? buffer : buffer.subarray(0, offset);

178-

}

179-
180162

async function readSessionHeaderFromTranscriptAsync(

181163

sessionFile: string,

182164

): Promise<{ id: string; cwd?: string } | null> {

183-

let fileHandle: AsyncTranscriptFileHandle | undefined;

165+

let fileHandle: Awaited<ReturnType<typeof fs.open>> | undefined;

184166

try {

185167

fileHandle = await fs.open(sessionFile, "r");

186168

const buffer = await readFileRangeAsync(fileHandle, 0, SESSION_HEADER_READ_MAX_BYTES);

@@ -289,7 +271,7 @@ export async function readSessionLeafStateFromTranscriptAsync(

289271

sessionFile: string,

290272

maxBytes = MAX_COMPACTION_CHECKPOINT_LEAF_SCAN_BYTES,

291273

): Promise<{ entryId: string; leafId: string | null } | null> {

292-

let fileHandle: AsyncTranscriptFileHandle | undefined;

274+

let fileHandle: Awaited<ReturnType<typeof fs.open>> | undefined;

293275

try {

294276

fileHandle = await fs.open(sessionFile, "r");

295277

const stat = await fileHandle.stat();