Skip to content

Commit b373e58

Browse files
committed
extensions: address idle-compact review fixes
1 parent 3955553 commit b373e58

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

pi/extensions/idle-compact.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@ function getConfig() {
5656
function isSocketAlive(socketPath: string): Promise<boolean> {
5757
return new Promise((resolve) => {
5858
const socket = net.createConnection(socketPath);
59-
const timeout = setTimeout(() => {
60-
socket.removeAllListeners();
61-
socket.destroy();
62-
resolve(false);
63-
}, 300);
59+
let settled = false;
6460

6561
const cleanup = (alive: boolean) => {
62+
if (settled) return;
63+
settled = true;
6664
clearTimeout(timeout);
6765
socket.removeAllListeners();
6866
if (alive) socket.end();
6967
else socket.destroy();
7068
resolve(alive);
7169
};
7270

71+
const timeout = setTimeout(() => cleanup(false), 300);
72+
7373
socket.once("connect", () => cleanup(true));
7474
socket.once("error", () => cleanup(false));
7575
});
@@ -121,7 +121,12 @@ function hasInProgressTodos(): boolean {
121121
const jsonEnd = content.indexOf("\n\n");
122122
const jsonStr = jsonEnd > 0 ? content.slice(0, jsonEnd) : content;
123123
const frontMatter = JSON.parse(jsonStr.trim());
124-
if (frontMatter.status === "in-progress" || frontMatter.status === "in_progress") {
124+
if (
125+
frontMatter.status === "in-progress" ||
126+
frontMatter.status === "in_progress" ||
127+
(typeof frontMatter.assigned_to_session === "string" &&
128+
frontMatter.assigned_to_session.trim().length > 0)
129+
) {
125130
return true;
126131
}
127132
} catch {
@@ -169,7 +174,8 @@ export default function idleCompactExtension(pi: ExtensionAPI): void {
169174

170175
// Check 1: context usage above threshold?
171176
const usage = lastCtx.getContextUsage();
172-
if (!usage || usage.tokens === null || usage.contextWindow === null) return;
177+
if (!usage || usage.tokens === null || usage.contextWindow === null || usage.contextWindow <= 0)
178+
return;
173179

174180
const pctUsed = (usage.tokens / usage.contextWindow) * 100;
175181
if (pctUsed < thresholdPct) {

0 commit comments

Comments
 (0)