Severity: Medium
Location: src/agent.ts:165 (readTodayLog), src/heartbeat.ts:165-166 (all heartbeat logging calls)
Description:
readTodayLog() is called on every /api/logs request with no caching. Additionally, all appendLog() calls throughout heartbeat.ts are synchronous fs.appendFileSync operations that block the event loop. Under high task volume, these synchronous disk writes can add latency to heartbeat ticks and WebSocket message handling.
For example in heartbeat.ts:237-252 (the tick() function), every poll cycle writes 2-3 log entries synchronously. With polling at 10s intervals, that's 14,000+ synchronous disk writes per day.
Suggested Fix:
- Add a write buffer/batch for log entries — collect entries in memory, flush every 5-10 seconds or N entries
- Add an LRU read cache for
readTodayLog() with a 5-second TTL
- Make
appendLog asynchronous or use a worker thread for disk I/O
Severity: Medium
Location:
src/agent.ts:165(readTodayLog),src/heartbeat.ts:165-166(all heartbeat logging calls)Description:
readTodayLog()is called on every/api/logsrequest with no caching. Additionally, allappendLog()calls throughoutheartbeat.tsare synchronousfs.appendFileSyncoperations that block the event loop. Under high task volume, these synchronous disk writes can add latency to heartbeat ticks and WebSocket message handling.For example in
heartbeat.ts:237-252(thetick()function), every poll cycle writes 2-3 log entries synchronously. With polling at 10s intervals, that's 14,000+ synchronous disk writes per day.Suggested Fix:
readTodayLog()with a 5-second TTLappendLogasynchronous or use a worker thread for disk I/O