fix: Resolve null coalescing, feature verification, and test abort handling issues

This commit is contained in:
gsxdsm
2026-02-16 12:27:56 -08:00
parent 434792a2ef
commit 0b03e70f1d
7 changed files with 109 additions and 45 deletions

View File

@@ -90,25 +90,10 @@ export class PlanApprovalService {
this.pendingApprovals.delete(key);
}
// Set up timeout to prevent indefinite waiting and memory leaks
// timeoutId stored in closure, NOT in PendingApproval object
const timeoutId = setTimeout(() => {
const pending = this.pendingApprovals.get(key);
if (pending) {
logger.warn(
`Plan approval for feature ${featureId} timed out after ${timeoutMinutes} minutes`
);
this.pendingApprovals.delete(key);
reject(
new Error(
`Plan approval timed out after ${timeoutMinutes} minutes - feature execution cancelled`
)
);
}
}, timeoutMs);
// Wrap resolve/reject to clear timeout when approval is resolved
// This ensures timeout is ALWAYS cleared on any resolution path
// Define wrappers BEFORE setTimeout so they can be used in timeout callback
let timeoutId: NodeJS.Timeout;
const wrappedResolve = (result: PlanApprovalResult) => {
clearTimeout(timeoutId);
resolve(result);
@@ -119,6 +104,23 @@ export class PlanApprovalService {
reject(error);
};
// Set up timeout to prevent indefinite waiting and memory leaks
// Now timeoutId assignment happens after wrappers are defined
timeoutId = setTimeout(() => {
const pending = this.pendingApprovals.get(key);
if (pending) {
logger.warn(
`Plan approval for feature ${featureId} timed out after ${timeoutMinutes} minutes`
);
this.pendingApprovals.delete(key);
wrappedReject(
new Error(
`Plan approval timed out after ${timeoutMinutes} minutes - feature execution cancelled`
)
);
}
}, timeoutMs);
this.pendingApprovals.set(key, {
resolve: wrappedResolve,
reject: wrappedReject,