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

推荐订阅源

N
Netflix TechBlog - Medium
IT之家
IT之家
博客园_首页
Hugging Face - Blog
Hugging Face - Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
美团技术团队
小众软件
小众软件
博客园 - 叶小钗
WordPress大学
WordPress大学
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
罗磊的独立博客
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Last Week in AI
Last Week in AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
宝玉的分享
宝玉的分享
博客园 - 【当耐特】
月光博客
月光博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
酷 壳 – CoolShell
酷 壳 – CoolShell
人人都是产品经理
人人都是产品经理

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
perf: avoid eager trajectory session manager import · ope...
steipete · 2026-04-24 · via Recent Commits to openclaw:main

@@ -1,8 +1,7 @@

11

import fs from "node:fs";

22

import path from "node:path";

33

import type { AgentMessage } from "@mariozechner/pi-agent-core";

4-

import type { SessionEntry, SessionHeader } from "@mariozechner/pi-coding-agent";

5-

import { SessionManager } from "@mariozechner/pi-coding-agent";

4+

import type { FileEntry, SessionEntry, SessionHeader } from "@mariozechner/pi-coding-agent";

65

import { sanitizeDiagnosticPayload } from "../agents/payload-redaction.js";

76

import { resolveStateDir } from "../config/paths.js";

87

import {

@@ -57,6 +56,90 @@ const MAX_TRAJECTORY_RUNTIME_EVENTS = 200_000;

5756

const MAX_TRAJECTORY_TOTAL_EVENTS = 250_000;

5857

const MAX_TRAJECTORY_SESSION_FILE_BYTES = 50 * 1024 * 1024;

595859+

function parseSessionEntries(content: string): FileEntry[] {

60+

return content

61+

.split(/\r?\n/u)

62+

.map((line) => line.trim())

63+

.filter(Boolean)

64+

.flatMap((line) => {

65+

try {

66+

return [JSON.parse(line) as FileEntry];

67+

} catch {

68+

return [];

69+

}

70+

});

71+

}

72+73+

function migrateLegacySessionEntries(entries: FileEntry[]): void {

74+

const header = entries.find((entry): entry is SessionHeader => entry.type === "session");

75+

const version = header?.version ?? 1;

76+

if (version < 2) {

77+

let previousId: string | null = null;

78+

let index = 0;

79+

for (const entry of entries) {

80+

if (entry.type === "session") {

81+

entry.version = 2;

82+

continue;

83+

}

84+

const mutable = entry as unknown as Record<string, unknown>;

85+

if (typeof mutable.id !== "string") {

86+

mutable.id = `legacy-${index++}`;

87+

}

88+

mutable.parentId = previousId;

89+

const entryId = mutable.id;

90+

previousId = typeof entryId === "string" ? entryId : null;

91+

if (entry.type === "compaction" && typeof mutable.firstKeptEntryIndex === "number") {

92+

const target = entries[mutable.firstKeptEntryIndex];

93+

if (target && target.type !== "session") {

94+

mutable.firstKeptEntryId = (target as unknown as Record<string, unknown>).id;

95+

}

96+

delete mutable.firstKeptEntryIndex;

97+

}

98+

}

99+

}

100+

if (version < 3) {

101+

for (const entry of entries) {

102+

if (entry.type === "session") {

103+

entry.version = 3;

104+

continue;

105+

}

106+

if (entry.type === "message") {

107+

const message = (entry as { message?: { role?: string } }).message;

108+

if (message?.role === "hookMessage") {

109+

message.role = "custom";

110+

}

111+

}

112+

}

113+

}

114+

}

115+116+

function readSessionBranch(filePath: string): {

117+

header: SessionHeader | null;

118+

leafId: string | null;

119+

branchEntries: SessionEntry[];

120+

} {

121+

const fileEntries = parseSessionEntries(fs.readFileSync(filePath, "utf8"));

122+

migrateLegacySessionEntries(fileEntries);

123+

const header =

124+

fileEntries.find((entry): entry is SessionHeader => entry.type === "session") ?? null;

125+

const entries = fileEntries.filter(

126+

(entry): entry is SessionEntry =>

127+

entry.type !== "session" &&

128+

typeof (entry as { id?: unknown }).id === "string" &&

129+

(typeof (entry as { timestamp?: unknown }).timestamp === "string" ||

130+

typeof (entry as { timestamp?: unknown }).timestamp === "number"),

131+

);

132+

const byId = new Map(entries.map((entry) => [entry.id, entry]));

133+

const leafId = entries.at(-1)?.id ?? null;

134+

const branchEntries: SessionEntry[] = [];

135+

let current = leafId ? byId.get(leafId) : undefined;

136+

while (current) {

137+

branchEntries.unshift(current);

138+

current = current.parentId ? byId.get(current.parentId) : undefined;

139+

}

140+

return { header, leafId, branchEntries };

141+

}

142+60143

function parseJsonlFile<T>(

61144

filePath: string,

62145

params: {

@@ -748,10 +831,7 @@ export function exportTrajectoryBundle(params: BuildTrajectoryBundleParams): {

748831

`Trajectory session file is too large to export (${sessionStat.size} bytes; limit ${MAX_TRAJECTORY_SESSION_FILE_BYTES})`,

749832

);

750833

}

751-

const sessionManager = SessionManager.open(params.sessionFile);

752-

const header = sessionManager.getHeader();

753-

const leafId = sessionManager.getLeafId();

754-

const branchEntries = sessionManager.getBranch(leafId ?? undefined);

834+

const { header, leafId, branchEntries } = readSessionBranch(params.sessionFile);

755835

const runtimeFile = resolveTrajectoryRuntimeFile({

756836

runtimeFile: params.runtimeFile,

757837

sessionFile: params.sessionFile,