fix(agent-kimicode): close wire stream on interrupted summary reads
This commit is contained in:
parent
c14eb3c011
commit
a4828ba644
|
|
@ -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"],
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue