mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-06 15:39:41 +02:00
feat: comprehensive codebase improvements (cleanup, logic, performance)
Code Cleanups: - Consolidated PlanTaskStatus and TddPhase types to types.ts - Standardized node: prefix for Node.js builtin imports - Fixed timer type to NodeJS.Timeout in respawn-controller Logic Improvements: - Fixed AI check race condition with UUID tracking in respawn-controller - Added comprehensive _isStopped guards in session timer callbacks - Made RalphTracker reset events non-reentrant via process.nextTick() - Improved SessionManager mutex pattern reliability Performance Optimizations: - Fixed pendingToolCalls memory leak with TTL cleanup in subagent-watcher - Improved LRUMap.newest() from O(n) to O(1) with _newestKey tracking Documentation: - Enhanced README antiflicker section with 6-layer technical details Version: 0.1441 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
*/
|
||||
|
||||
import { EventEmitter } from 'node:events';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { Session } from './session.js';
|
||||
import { AiIdleChecker, type AiCheckResult, type AiCheckState } from './ai-idle-checker.js';
|
||||
import { AiPlanChecker, type AiPlanCheckResult } from './ai-plan-checker.js';
|
||||
@@ -716,6 +717,9 @@ export class RespawnController extends EventEmitter {
|
||||
/** Timestamp when plan check was started (to detect stale results) */
|
||||
private planCheckStartTime: number = 0;
|
||||
|
||||
/** Unique ID for current AI check request (to detect stale results) */
|
||||
private _currentAiCheckId: string | null = null;
|
||||
|
||||
/** Timer for /clear step fallback (sends /init if no prompt detected) */
|
||||
private clearFallbackTimer: NodeJS.Timeout | null = null;
|
||||
|
||||
@@ -2131,6 +2135,10 @@ export class RespawnController extends EventEmitter {
|
||||
this.logAction('ai-check', `Spawning AI idle checker (${reason})`);
|
||||
this.emit('aiCheckStarted');
|
||||
|
||||
// Generate unique ID for this check to detect stale results
|
||||
const checkId = randomUUID();
|
||||
this._currentAiCheckId = checkId;
|
||||
|
||||
// Get the terminal buffer for analysis
|
||||
const buffer = this.terminalBuffer.value;
|
||||
|
||||
@@ -2141,6 +2149,12 @@ export class RespawnController extends EventEmitter {
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate this is the result for the current check (not a stale one)
|
||||
if (this._currentAiCheckId !== checkId) {
|
||||
this.log(`AI check result ignored (stale check ID: ${checkId.substring(0, 8)})`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.verdict === 'IDLE') {
|
||||
// Cancel any pending confirmation timers - AI has spoken
|
||||
this.cancelTrackedTimer('completion-confirm', this.completionConfirmTimer, 'AI verdict: IDLE');
|
||||
@@ -2173,6 +2187,10 @@ export class RespawnController extends EventEmitter {
|
||||
this.startPreFilterTimer();
|
||||
}
|
||||
}).catch((err) => {
|
||||
// Validate this is the error for the current check
|
||||
if (this._currentAiCheckId !== checkId) {
|
||||
return; // Stale check, ignore error
|
||||
}
|
||||
if (this._state === 'ai_checking') {
|
||||
const errorMsg = err instanceof Error ? err.message : String(err);
|
||||
this.logAction('ai-check', `Failed: ${errorMsg.substring(0, 50)}`);
|
||||
|
||||
Reference in New Issue
Block a user