fix(agent-kimicode): close wire stream on interrupted summary reads

This commit is contained in:
i-trytoohard 2026-05-21 07:24:07 +05:30
parent c14eb3c011
commit a4828ba644
2 changed files with 23 additions and 3 deletions

View File

@ -57,6 +57,21 @@ export default tseslint.config(
"no-debugger": "error",
"no-duplicate-imports": "error",
"no-template-curly-in-string": "warn",
"no-restricted-syntax": [
"error",
{
selector:
"CallExpression[callee.name='createInterface'] Property[key.name='input'] > CallExpression[callee.name='createReadStream']",
message:
"Do not pass createReadStream() inline to createInterface(); keep the stream in a variable and close/destroy it in a finally block.",
},
{
selector:
"CallExpression[callee.name='createInterface'] Property[key.name='input'] > CallExpression[callee.property.name='createReadStream']",
message:
"Do not pass createReadStream() inline to createInterface(); keep the stream in a variable and close/destroy it in a finally block.",
},
],
"prefer-const": "error",
"no-var": "error",
eqeqeq: ["error", "always"],

View File

@ -52,9 +52,12 @@ async function extractKimiSummary(sessionDir: string): Promise<string | null> {
// still be planted as symlinks pointing at /etc/passwd or /dev/zero.
if (!(await isKimiSessionFile(wirePath))) return null;
let summary: string | null = null;
let stream: ReturnType<typeof createReadStream> | null = null;
let rl: ReturnType<typeof createInterface> | null = null;
try {
const rl = createInterface({
input: createReadStream(wirePath, { encoding: "utf-8" }),
stream = createReadStream(wirePath, { encoding: "utf-8" });
rl = createInterface({
input: stream,
crlfDelay: Infinity,
});
let bytes = 0;
@ -85,9 +88,11 @@ async function extractKimiSummary(sessionDir: string): Promise<string | null> {
// Skip malformed line
}
}
rl.close();
} catch {
return null;
} finally {
rl?.close();
stream?.destroy();
}
return summary;
}