mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-03-18 22:33:08 +00:00
Changes from fix/dev-server-hang
This commit is contained in:
@@ -598,24 +598,23 @@ wss.on('connection', (ws: WebSocket) => {
|
||||
|
||||
// Subscribe to all events and forward to this client
|
||||
const unsubscribe = events.subscribe((type, payload) => {
|
||||
logger.info('Event received:', {
|
||||
// Use debug level for high-frequency events to avoid log spam
|
||||
// that causes progressive memory growth and server slowdown
|
||||
const isHighFrequency =
|
||||
type === 'dev-server:output' || type === 'test-runner:output' || type === 'feature:progress';
|
||||
const log = isHighFrequency ? logger.debug.bind(logger) : logger.info.bind(logger);
|
||||
|
||||
log('Event received:', {
|
||||
type,
|
||||
hasPayload: !!payload,
|
||||
payloadKeys: payload ? Object.keys(payload) : [],
|
||||
wsReadyState: ws.readyState,
|
||||
wsOpen: ws.readyState === WebSocket.OPEN,
|
||||
});
|
||||
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
const message = JSON.stringify({ type, payload });
|
||||
logger.info('Sending event to client:', {
|
||||
type,
|
||||
messageLength: message.length,
|
||||
sessionId: (payload as Record<string, unknown>)?.sessionId,
|
||||
});
|
||||
ws.send(message);
|
||||
} else {
|
||||
logger.info('WARNING: Cannot send event, WebSocket not open. ReadyState:', ws.readyState);
|
||||
logger.warn('Cannot send event, WebSocket not open. ReadyState:', ws.readyState);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -88,9 +88,13 @@ const PORT_PATTERNS: Array<{ pattern: RegExp; description: string }> = [
|
||||
},
|
||||
];
|
||||
|
||||
// Throttle output to prevent overwhelming WebSocket under heavy load
|
||||
const OUTPUT_THROTTLE_MS = 4; // ~250fps max update rate for responsive feedback
|
||||
const OUTPUT_BATCH_SIZE = 4096; // Smaller batches for lower latency
|
||||
// Throttle output to prevent overwhelming WebSocket under heavy load.
|
||||
// 100ms (~10fps) is sufficient for readable log streaming while keeping
|
||||
// WebSocket traffic manageable. The previous 4ms rate (~250fps) generated
|
||||
// up to 250 events/sec which caused progressive browser slowdown from
|
||||
// accumulated console logs, JSON serialization overhead, and React re-renders.
|
||||
const OUTPUT_THROTTLE_MS = 100; // ~10fps max update rate
|
||||
const OUTPUT_BATCH_SIZE = 8192; // Larger batches to compensate for lower frequency
|
||||
|
||||
export interface DevServerInfo {
|
||||
worktreePath: string;
|
||||
|
||||
@@ -90,8 +90,8 @@ describe('DevServerService Event Types', () => {
|
||||
|
||||
// 2. Output & URL Detected
|
||||
mockProcess.stdout.emit('data', Buffer.from('Local: http://localhost:5173/\n'));
|
||||
// Throttled output needs a bit of time
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
// Throttled output needs a bit of time (OUTPUT_THROTTLE_MS is 100ms)
|
||||
await new Promise((resolve) => setTimeout(resolve, 250));
|
||||
expect(emittedEvents['dev-server:output'].length).toBeGreaterThanOrEqual(1);
|
||||
expect(emittedEvents['dev-server:url-detected'].length).toBe(1);
|
||||
expect(emittedEvents['dev-server:url-detected'][0].url).toBe('http://localhost:5173/');
|
||||
|
||||
Reference in New Issue
Block a user