Skip to content

Commit 5986ced

Browse files
committed
Refactor AGUI event handling and logging
- Removed unnecessary logging statements from the AGUI backend, improving code clarity and reducing log noise. - Updated frontend components to eliminate redundant console logs, enhancing performance and maintainability. - Streamlined event processing logic to focus on essential operations, ensuring efficient handling of AGUI events. These changes enhance the overall efficiency of AGUI event management and improve the clarity of the codebase.
1 parent b7b439e commit 5986ced

File tree

8 files changed

+1
-276
lines changed

8 files changed

+1
-276
lines changed

components/backend/websocket/agui.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ func (r *AGUIRunState) Broadcast(event *types.BaseEvent) {
7575
case ch <- event:
7676
default:
7777
// Channel full, skip
78-
log.Printf("AGUI: subscriber channel full, skipping event")
7978
}
8079
}
8180
}
@@ -120,14 +119,11 @@ func createInitialAGUIRun(sessionID string) {
120119
for _, state := range aguiRuns {
121120
if state.SessionID == sessionID {
122121
aguiRunsMu.RUnlock()
123-
log.Printf("AGUI: Run already exists for session %s, skipping initial run creation", sessionID)
124122
return
125123
}
126124
}
127125
aguiRunsMu.RUnlock()
128126

129-
log.Printf("AGUI: Creating initial run %s for session %s (runner bootstrap)", runID, sessionID)
130-
131127
runState := &AGUIRunState{
132128
ThreadID: threadID,
133129
RunID: runID,
@@ -156,7 +152,6 @@ func createInitialAGUIRun(sessionID string) {
156152
// This is the simplified flow - no SessionMessage wrapping, no translation needed
157153
func RouteAGUIEvent(sessionID string, event map[string]interface{}) {
158154
eventType, _ := event["type"].(string)
159-
log.Printf("AGUI: RouteAGUIEvent sessionID=%s eventType=%s", sessionID, eventType)
160155

161156
// Find active run for this session
162157
var activeRunState *AGUIRunState
@@ -173,15 +168,13 @@ func RouteAGUIEvent(sessionID string, event map[string]interface{}) {
173168
if activeRunState == nil {
174169
// Don't create lazy runs for terminal events - they should only apply to existing runs
175170
if isTerminalEventType(eventType) {
176-
log.Printf("AGUI: Terminal event (%s) for non-existent run, ignoring (session=%s)", eventType, sessionID)
177171
go persistAGUIEventMap(sessionID, "", event)
178172
return
179173
}
180174

181175
eventRunID, _ := event["runId"].(string)
182176
if eventRunID != "" {
183177
// Create run lazily from event's runId
184-
log.Printf("AGUI: No active run found, creating lazy run for runId=%s session=%s", eventRunID, sessionID)
185178
threadID := sessionID
186179
activeRunState = &AGUIRunState{
187180
ThreadID: threadID,
@@ -196,7 +189,6 @@ func RouteAGUIEvent(sessionID string, event map[string]interface{}) {
196189
aguiRuns[eventRunID] = activeRunState
197190
aguiRunsMu.Unlock()
198191
} else {
199-
log.Printf("AGUI: No active run and no runId in event for session %s, event will only be persisted", sessionID)
200192
go persistAGUIEventMap(sessionID, "", event)
201193
return
202194
}
@@ -209,7 +201,6 @@ func RouteAGUIEvent(sessionID string, event map[string]interface{}) {
209201
// Don't use activeRunState.RunID which might be stale
210202
if eventRunID, ok := event["runId"].(string); ok && eventRunID != "" {
211203
runID = eventRunID
212-
log.Printf("AGUI: Using runId from event: %s (activeRun had: %s)", runID, activeRunState.RunID)
213204
}
214205
if eventThreadID, ok := event["threadId"].(string); ok && eventThreadID != "" {
215206
threadID = eventThreadID
@@ -233,7 +224,6 @@ func RouteAGUIEvent(sessionID string, event map[string]interface{}) {
233224
select {
234225
case ch <- event:
235226
default:
236-
log.Printf("AGUI: Thread subscriber channel full, skipping event")
237227
}
238228
}
239229
}
@@ -244,7 +234,6 @@ func RouteAGUIEvent(sessionID string, event map[string]interface{}) {
244234

245235
// Check for terminal events - mark run as complete
246236
if isTerminalEventType(eventType) {
247-
log.Printf("AGUI: Terminal event detected (%s) for runId=%s sessionID=%s", eventType, runID, sessionID)
248237
activeRunState.Status = getTerminalStatusFromType(eventType)
249238

250239
// Schedule cleanup of run state (no need to compact async - we compact on SSE connect)
@@ -280,11 +269,6 @@ func persistAGUIEventMap(sessionID, runID string, event map[string]interface{})
280269
return
281270
}
282271

283-
// Log successful persistence (especially for user messages)
284-
eventType, _ := event["type"].(string)
285-
if role, ok := event["role"].(string); ok && role == "user" {
286-
log.Printf("AGUI: ✓ Persisted USER message event %s (runId=%s)", eventType, runID)
287-
}
288272
}
289273

290274
// isTerminalEventType checks if an event type indicates run completion
@@ -388,11 +372,8 @@ func streamThreadEvents(c *gin.Context, projectName, sessionName string) {
388372
}
389373
threadSubscribersMu.Unlock()
390374
close(eventCh)
391-
log.Printf("AGUI: Thread subscriber disconnected from session %s", sessionName)
392375
}()
393376

394-
log.Printf("AGUI: Thread subscriber connected to session %s", sessionName)
395-
396377
// OPTION 1: Compact-on-Read Strategy (COMPLETED RUNS ONLY)
397378
// Load events from agui-events.jsonl and compact only COMPLETED runs
398379
// Active/in-progress runs will be streamed raw
@@ -402,7 +383,6 @@ func streamThreadEvents(c *gin.Context, projectName, sessionName string) {
402383

403384
events, err := loadEventsForRun(sessionName, "")
404385
if err == nil && len(events) > 0 {
405-
log.Printf("AGUI: Loaded %d events from disk for session %s", len(events), sessionName)
406386

407387
// CRITICAL FIX: Determine which runs are TRULY active by checking event log
408388
// A run is only active if NO terminal event exists in the log
@@ -413,7 +393,6 @@ func streamThreadEvents(c *gin.Context, projectName, sessionName string) {
413393

414394
if eventRunID != "" && isTerminalEventType(eventType) {
415395
runHasTerminalEvent[eventRunID] = true
416-
log.Printf("AGUI: Run %s has terminal event %s - will be compacted", eventRunID, eventType)
417396
}
418397
}
419398

@@ -426,12 +405,10 @@ func streamThreadEvents(c *gin.Context, projectName, sessionName string) {
426405
// Only consider active if NO terminal event in log
427406
if !runHasTerminalEvent[runID] {
428407
activeRunIDs[runID] = true
429-
log.Printf("AGUI: Run %s is truly active (no terminal event in log)", runID)
430408
} else {
431409
// Fix stale memory state
432410
if state.Status == "running" {
433411
state.Status = "completed"
434-
log.Printf("AGUI: Fixed stale state - run %s was 'running' but has terminal event", runID)
435412
}
436413
}
437414
}
@@ -460,15 +437,9 @@ func streamThreadEvents(c *gin.Context, projectName, sessionName string) {
460437
completedEvents = append(completedEvents, event)
461438
}
462439

463-
log.Printf("AGUI: Filtered %d events -> %d completed, %d active (will replay raw)",
464-
len(events), len(completedEvents), skippedCount)
465-
466440
if len(completedEvents) > 0 {
467441
// Compact only completed run events
468-
log.Printf("AGUI: Compacting %d events from completed runs (excluding %d active runs)",
469-
len(completedEvents), len(activeRunIDs))
470442
messages := CompactEvents(completedEvents)
471-
log.Printf("AGUI: Compacted into %d messages", len(messages))
472443

473444
// Send single MESSAGES_SNAPSHOT with compacted messages from COMPLETED runs
474445
if len(messages) > 0 {
@@ -478,10 +449,7 @@ func streamThreadEvents(c *gin.Context, projectName, sessionName string) {
478449
}
479450
writeSSEEvent(c.Writer, snapshot)
480451
c.Writer.(http.Flusher).Flush()
481-
log.Printf("AGUI: Sent MESSAGES_SNAPSHOT with %d messages from completed runs", len(messages))
482452
}
483-
} else {
484-
log.Printf("AGUI: No completed runs to compact (%d active runs)", len(activeRunIDs))
485453
}
486454
} else if err != nil {
487455
log.Printf("AGUI: Failed to load events: %v", err)
@@ -499,7 +467,6 @@ func streamThreadEvents(c *gin.Context, projectName, sessionName string) {
499467
aguiRunsMu.RUnlock()
500468

501469
if len(activeRunStates) > 0 {
502-
log.Printf("AGUI: Replaying %d active runs with raw events", len(activeRunStates))
503470

504471
// Load all events once
505472
allEvents, err := loadEventsForRun(sessionName, "")
@@ -528,17 +495,13 @@ func streamThreadEvents(c *gin.Context, projectName, sessionName string) {
528495

529496
// Replay raw events
530497
if len(runEvents) > 0 {
531-
log.Printf("AGUI: Replaying %d raw events for active run %s", len(runEvents), activeRunState.RunID)
532498
for _, event := range runEvents {
533499
writeSSEEvent(c.Writer, event)
534500
}
535501
}
536502
}
537503
c.Writer.(http.Flusher).Flush()
538-
log.Printf("AGUI: Finished replaying all active runs")
539504
}
540-
} else {
541-
log.Printf("AGUI: No active runs to replay")
542505
}
543506

544507
// Stream events from all future runs with keepalive
@@ -548,7 +511,6 @@ func streamThreadEvents(c *gin.Context, projectName, sessionName string) {
548511
for {
549512
select {
550513
case <-ctx.Done():
551-
log.Printf("AGUI: Thread stream context done for session %s", sessionName)
552514
return
553515
case <-keepaliveTicker.C:
554516
// Send SSE comment to prevent gateway timeout
@@ -560,7 +522,6 @@ func streamThreadEvents(c *gin.Context, projectName, sessionName string) {
560522
c.Writer.(http.Flusher).Flush()
561523
case event, ok := <-eventCh:
562524
if !ok {
563-
log.Printf("AGUI: Event channel closed for session %s", sessionName)
564525
return
565526
}
566527
writeSSEEvent(c.Writer, event)
@@ -577,8 +538,6 @@ func HandleAGUIEvents(c *gin.Context) {
577538
sessionName := c.Param("sessionName")
578539
runID := c.Query("runId")
579540

580-
log.Printf("AGUI: SSE connection request for session=%s, runId=%s", sessionName, runID)
581-
582541
// Set SSE headers
583542
c.Header("Content-Type", "text/event-stream")
584543
c.Header("Cache-Control", "no-cache")
@@ -588,21 +547,18 @@ func HandleAGUIEvents(c *gin.Context) {
588547
// If no runId specified, stream the entire THREAD (all runs for this session)
589548
// This is the correct AG-UI pattern: client connects once to thread stream
590549
if runID == "" {
591-
log.Printf("AGUI: Thread-level streaming for session %s", sessionName)
592550
streamThreadEvents(c, projectName, sessionName)
593551
return
594552
}
595553

596554
// Legacy: specific run streaming (kept for compatibility)
597-
log.Printf("AGUI: Run-specific streaming for runId %s", runID)
598555

599556
var runState *AGUIRunState
600557
aguiRunsMu.RLock()
601558
runState = aguiRuns[runID]
602559
aguiRunsMu.RUnlock()
603560

604561
if runState == nil {
605-
log.Printf("AGUI: Run %s not found, creating implicit run", runID)
606562
// Create an implicit run for this connection
607563
threadID := sessionName
608564
runState = &AGUIRunState{
@@ -649,7 +605,6 @@ func HandleAGUIEvents(c *gin.Context) {
649605
for {
650606
select {
651607
case <-ctx.Done():
652-
log.Printf("AGUI: client disconnected from %s/%s", projectName, sessionName)
653608
return
654609
case event, ok := <-fullEventCh:
655610
if !ok {
@@ -684,27 +639,18 @@ func sendInitialSyncEvents(c *gin.Context, runState *AGUIRunState, projectName,
684639
events, err := loadEventsForRun(sessionName, runID)
685640
if err != nil {
686641
log.Printf("AGUI: Failed to load events for %s: %v", sessionName, err)
687-
} else {
688-
log.Printf("AGUI: Loaded %d events for session %s", len(events), sessionName)
689642
}
690643

691644
if len(events) > 0 {
692-
log.Printf("AGUI: Compacting %d events into messages...", len(events))
693645
messages := CompactEvents(events)
694-
log.Printf("AGUI: Compaction result: %d messages from %d events", len(messages), len(events))
695646

696647
if len(messages) > 0 {
697648
snapshot := &types.MessagesSnapshotEvent{
698649
BaseEvent: types.NewBaseEvent(types.EventTypeMessagesSnapshot, threadID, runID),
699650
Messages: messages,
700651
}
701652
writeSSEEvent(c.Writer, snapshot)
702-
log.Printf("AGUI: ✅ Sent MESSAGES_SNAPSHOT with %d messages (compacted from %d events)", len(messages), len(events))
703-
} else {
704-
log.Printf("AGUI: ⚠️ WARNING - Compaction produced 0 messages from %d events", len(events))
705653
}
706-
} else {
707-
log.Printf("AGUI: No stored events found for session %s - this is normal for new sessions", sessionName)
708654
}
709655
}
710656

@@ -792,7 +738,6 @@ func scheduleRunCleanup(runID string, delay time.Duration) {
792738
// Only delete if run is no longer active
793739
if run.Status != "running" {
794740
delete(aguiRuns, runID)
795-
log.Printf("AGUI: cleaned up completed run %s", runID)
796741
}
797742
}
798743
aguiRunsMu.Unlock()
@@ -815,7 +760,6 @@ func cleanupInactiveRuns() {
815760
for runID, run := range aguiRuns {
816761
if run.Status != "running" && run.StartedAt.Before(cutoff) {
817762
delete(aguiRuns, runID)
818-
log.Printf("AGUI: cleaned up old run %s", runID)
819763
}
820764
}
821765
}

components/frontend/src/app/api/projects/[name]/agentic-sessions/[sessionName]/workspace/upload/route.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,6 @@ async function compressImageIfNeeded(
256256
}
257257

258258
const finalSize = compressed.byteLength;
259-
console.log(
260-
`Compressed ${contentType} image: ${originalSize} bytes -> ${finalSize} bytes (${Math.round((finalSize / originalSize) * 100)}%)`
261-
);
262259

263260
// Convert Node.js Buffer to ArrayBuffer by creating a new ArrayBuffer and copying data
264261
const arrayBuffer = new ArrayBuffer(finalSize);

components/frontend/src/app/api/projects/[name]/agentic-sessions/route.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,13 @@ export async function POST(
3131
const body = await request.text();
3232
const headers = await buildForwardHeadersAsync(request);
3333

34-
console.log('[API Route] Creating session for project:', name);
35-
console.log('[API Route] Auth headers present:', {
36-
hasUser: !!headers['X-Forwarded-User'],
37-
hasUsername: !!headers['X-Forwarded-Preferred-Username'],
38-
hasToken: !!headers['X-Forwarded-Access-Token'],
39-
hasEmail: !!headers['X-Forwarded-Email'],
40-
});
41-
4234
const response = await fetch(`${BACKEND_URL}/projects/${encodeURIComponent(name)}/agentic-sessions`, {
4335
method: 'POST',
4436
headers,
4537
body,
4638
});
4739

4840
const text = await response.text();
49-
console.log('[API Route] Backend response status:', response.status);
5041
if (!response.ok) {
5142
console.error('[API Route] Backend error:', text);
5243
}

0 commit comments

Comments
 (0)