perf(agents): bound claude orphan transcript scan · openclaw/openclaw@f848a6f
obviyus
·
2026-05-30
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -106,6 +106,7 @@ export function claudeCliSessionTranscriptPath(params: {
|
106 | 106 | } |
107 | 107 | |
108 | 108 | const CLAUDE_CLI_TRANSCRIPT_FLUSH_GRACE_MS = 250; |
| 109 | +const CLAUDE_CLI_ORPHAN_PROBE_TAIL_BYTES = 1024 * 1024; |
109 | 110 | |
110 | 111 | export async function claudeCliSessionTranscriptHasContent(params: { |
111 | 112 | sessionId: string | undefined; |
@@ -166,10 +167,18 @@ async function jsonlFileHasOrphanedTrailingToolUse(filePath: string): Promise<bo
|
166 | 167 | |
167 | 168 | const fh = await fs.open(filePath, "r"); |
168 | 169 | try { |
169 | | -const rl = readline.createInterface({ input: fh.createReadStream({ encoding: "utf-8" }) }); |
| 170 | +const tailBytes = Math.min(stat.size, CLAUDE_CLI_ORPHAN_PROBE_TAIL_BYTES); |
| 171 | +const start = stat.size - tailBytes; |
| 172 | +const buffer = Buffer.alloc(tailBytes); |
| 173 | +const { bytesRead } = await fh.read(buffer, 0, tailBytes, start); |
| 174 | +let tailText = buffer.toString("utf-8", 0, bytesRead); |
| 175 | +if (start > 0) { |
| 176 | +const firstNewline = tailText.indexOf("\n"); |
| 177 | +tailText = firstNewline === -1 ? "" : tailText.slice(firstNewline + 1); |
| 178 | +} |
170 | 179 | let lastAssistantToolUseIds: Set<string> = new Set(); |
171 | 180 | let answeredToolResultIds: Set<string> = new Set(); |
172 | | -for await (const line of rl) { |
| 181 | +for (const line of tailText.split(/\r?\n/)) { |
173 | 182 | if (!line.trim()) { |
174 | 183 | continue; |
175 | 184 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。