[PR #218] [MERGED] Quick fix for assistant mode #244

Closed
opened 2026-06-06 22:09:51 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/vxcontrol/pentagi/pull/218
Author: @asdek
Created: 3/19/2026
Status: Merged
Merged: 3/19/2026
Merged by: @asdek

Base: masterHead: bug/quick_fix_assistant_mode


📝 Commits (5)

  • bb50d10 fix: enhance QA summarization logic to prevent double summarization of sections
  • fa70b03 feat: update model configurations for Anthropic and OpenAI providers
  • 852c48b fix: improve streaming log handling and cache updates
  • 41add52 fix: textarea focus
  • 329a6ff fix: empty flow assistant logs when no updates occur

📊 Changes

13 files changed (+225 additions, -87 deletions)

View changed files

📝 backend/pkg/controller/aslog.go (+9 -1)
📝 backend/pkg/csum/chain_summary.go (+24 -7)
📝 backend/pkg/database/assistantlogs.sql.go (+10 -0)
📝 backend/pkg/database/querier.go (+1 -0)
📝 backend/pkg/providers/anthropic/config.yml (+11 -11)
📝 backend/pkg/providers/openai/config.yml (+24 -24)
📝 backend/pkg/providers/openai/models.yml (+28 -0)
📝 backend/pkg/tools/executor.go (+1 -1)
📝 backend/sqlc/models/assistantlogs.sql (+4 -0)
📝 frontend/src/components/ui/input-group.tsx (+1 -1)
📝 frontend/src/features/flows/flow-form.tsx (+17 -1)
📝 frontend/src/lib/apollo.ts (+93 -39)
📝 frontend/src/styles/index.css (+2 -2)

📄 Description

Description of the Change

Problem

Multiple performance and quality issues affecting agent execution and UI responsiveness:

Empty Assistant Logs:

  • Backend created empty AssistantLog records when LLM sent only result (tool call JSON) without message chunks
  • Records remained in database with message="", polluting UI with blank entries
  • Occurred during tool executions (file, terminal operations)

Memory Growth in Browser:

  • Each streaming chunk created new objects in Apollo Cache (300-400MB per agent call)
  • String concatenation generated intermediate copies: 6 bytes → 11 bytes → ... → 100KB
  • 1000+ chunks resulted in exponential memory consumption

Subscription Cache Handling:

  • New assistant logs from subscriptions failed to appear in UI when not pre-cached
  • toReference(..., true) only created references to existing objects
  • Streaming updates ignored if log didn't exist in cache

Outdated Model Configurations:

  • Anthropic and OpenAI provider configurations had lower max_tokens limits
  • Missing GPT-5.4 series models with advanced capabilities

QA Summarization Redundancy:

  • Chain summary logic could double-summarize already processed sections
  • Wasted tokens and processing time on redundant operations

Minor UI Issue:

  • Textarea focus behavior inconsistent

Solution

Backend - Empty Log Cleanup:

  • Added wasUpdated flag in workerMsgUpdater to track if record received any content/thinking/result chunks
  • Created DeleteFlowAssistantLog SQL query for cleanup
  • Delete record on timeout if never updated (no meaningful data)
  • Preserves records with any content or result

Frontend - Memory Optimization:

  • Implemented 100ms throttling for streaming updates (10 updates/sec vs 1000+)
  • Fixed cache update logic: new logs now properly added via toReference(...) without second parameter
  • Modified update strategy to add missing objects to cache arrays
  • Result: ~90% memory reduction (40MB vs 400MB per call)

Frontend - Streaming Performance:

  • Refactored Observable handling to skip intermediate chunks (return early instead of data: {})
  • Custom Observable in createStreamingLink with conditional observer.next() calls
  • Chunks accumulate locally, emit to UI only every 100ms
  • Font path fixes in CSS for proper italic style loading

Model Configuration Updates:

  • Increased Anthropic max_tokens limits for better performance
  • Added GPT-5.4 series models with updated pricing and capabilities
  • Enhanced model descriptions

Summarization Improvements:

  • Added checks to skip sections already containing summarized content
  • Improved recent section handling for AST generation
  • Reduced redundant LLM calls

Textarea Fix:

  • Corrected focus behavior

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • 🚀 New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Configuration change
  • 🧪 Test update
  • 🛡️ Security update

Areas Affected

  • Core Services (Frontend UI/Backend API)
  • AI Agents (Researcher/Developer/Executor)
  • Security Tools Integration
  • Memory System (Vector Store/Knowledge Base)
  • Monitoring Stack (Grafana/OpenTelemetry)
  • Analytics Platform (Langfuse)
  • External Integrations (LLM/Search APIs)
  • Documentation
  • Infrastructure/DevOps

Testing and Verification

Test Configuration

PentAGI Version: Latest development
Docker Version: 24.0.x
Host OS: macOS/Linux
LLM Provider: OpenAI, Anthropic
Enabled Features: Core

Test Steps

  1. Empty logs cleanup: Create flow with tool-heavy agent execution (file operations), verify no empty logs in assistantlogs table
  2. Memory usage: Run 3 consecutive agent calls with long responses, monitor browser tab memory (should stay under 100MB increase total)
  3. Streaming display: Verify assistant responses appear smoothly every ~100ms during generation
  4. Cache handling: Open new flow, verify assistant logs from subscriptions appear immediately in UI
  5. Model configs: Test flows with updated Anthropic/OpenAI models, verify higher token limits work
  6. Summarization: Run multiple flows with QA patterns, verify no redundant summarization in logs

Test Results

  • Empty logs eliminated: Zero blank records in assistantlogs after tool executions
  • Streaming smooth: Text appears progressively at 10 updates/sec
  • Subscriptions work: New logs from assistantLogUpdated display correctly
  • Models validated: GPT-5.4 series and updated Anthropic configs functional
  • Summarization efficient: No duplicate processing observed
  • Backend compilation clean
  • Frontend linting passed

Security Considerations

No Security Impact:

  • Backend changes improve data quality (delete empty records)
  • Frontend changes are performance optimizations
  • Model configuration updates don't change authentication or authorization
  • No new dependencies or external services

Performance Impact

Major Improvements:

  • Browser memory: 90% reduction (40MB vs 400MB per agent call with 1000+ chunks)
  • Apollo Cache efficiency: ~100 updates vs 1000+ per streaming response
  • React rendering: 10 renders/sec vs 1000+ during streaming
  • Database cleanup: Eliminates accumulation of empty records
  • Summarization: Skips redundant operations, saves LLM tokens

Streaming Trade-off:

  • Throttling to 100ms (10 updates/sec) provides smooth visual streaming while preventing memory bloat
  • Users see progressive text generation without performance degradation

Documentation Updates

  • README.md updates
  • API documentation updates
  • Configuration documentation updates
  • GraphQL schema updates
  • Other

Deployment Notes

Database Migration:

  • New SQL function: DeleteFlowAssistantLog (sqlc-generated)
  • No schema changes, backward compatible

Environment Variables:

  • No new configuration required
  • Existing deployments work without changes

Deployment Steps:

  1. Pull latest changes
  2. Rebuild: docker compose build
  3. Restart: docker compose up -d
  4. sqlc generation happens automatically during build

Compatibility:

  • Fully backward compatible
  • No breaking changes
  • Existing flows unaffected

Checklist

Code Quality

  • My code follows the project's coding standards
  • I have added/updated necessary documentation
  • I have added tests to cover my changes
  • All new and existing tests pass
  • I have run go fmt and go vet (for Go code)
  • I have run npm run lint (for TypeScript/JavaScript code)

Security

  • I have considered security implications
  • Changes maintain or improve the security model
  • Sensitive information has been properly handled

Compatibility

  • Changes are backward compatible
  • No breaking changes
  • Dependencies are properly updated

Documentation

  • Documentation is clear and complete
  • Comments are added for non-obvious code
  • API changes are documented (no API changes)

Additional Notes

Key Changes by Category

Critical Fixes

Empty Assistant Logs Cleanup (Commit 329a6ff):

  • File: backend/pkg/controller/aslog.go
  • Added wasUpdated boolean flag in workerMsgUpdater goroutine
  • Tracks if any chunk updates occurred (Content, Thinking, Flush, Result types)
  • On timeout: deletes record if wasUpdated == false
  • Result: Eliminates empty records created when LLM sends only tool call JSON without message

Streaming Memory Optimization (Commit 852c48b):

  • File: frontend/src/lib/apollo.ts
  • Implemented 100ms throttling via shouldEmitUpdate function and lastUpdateTimestamps Map
  • Changed cache reference logic: toReference(newItem) creates new objects only for assistantLogUpdated when missing
  • Modified update strategy to add new objects to arrays if not present
  • Custom Observable skips intermediate chunks, emits every 100ms
  • Result: 90% memory reduction (40MB vs 400MB), smooth streaming at 10 FPS

Font Loading Fix (Commit 852c48b):

  • File: frontend/src/styles/index.css
  • Corrected italic font file paths
  • Result: Proper italic rendering

Feature Updates

Model Configuration Enhancement (Commit fa70b03):

  • Files: backend/pkg/providers/anthropic/config.yml, backend/pkg/providers/openai/config.yml, backend/pkg/providers/openai/models.yml
  • Increased max_tokens limits for Anthropic models (better long-form output)
  • Updated OpenAI to GPT-5.4 series with new pricing structure
  • Added GPT-5.4 model descriptions reflecting advanced capabilities
  • Result: Better output quality from updated models

QA Summarization Optimization (Commit bb50d10):

  • File: backend/pkg/csum/chain_summary.go
  • Added checks to prevent re-summarizing sections already containing summaries
  • Improved section retention logic for AST generation
  • Result: Reduced redundant LLM calls, token savings

Textarea Focus (Commit 41add52):

  • Minor UI improvement
  • Result: Better UX consistency

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/vxcontrol/pentagi/pull/218 **Author:** [@asdek](https://github.com/asdek) **Created:** 3/19/2026 **Status:** ✅ Merged **Merged:** 3/19/2026 **Merged by:** [@asdek](https://github.com/asdek) **Base:** `master` ← **Head:** `bug/quick_fix_assistant_mode` --- ### 📝 Commits (5) - [`bb50d10`](https://github.com/vxcontrol/pentagi/commit/bb50d10e04a7d6d6329e1ee82b5c6b5a58d9325f) fix: enhance QA summarization logic to prevent double summarization of sections - [`fa70b03`](https://github.com/vxcontrol/pentagi/commit/fa70b03ff5e380a961f6aba6cd695ed484ab8a20) feat: update model configurations for Anthropic and OpenAI providers - [`852c48b`](https://github.com/vxcontrol/pentagi/commit/852c48b04188d3d444f08ab6912452d18a229c7c) fix: improve streaming log handling and cache updates - [`41add52`](https://github.com/vxcontrol/pentagi/commit/41add52bb1f63a58bb7e327ebbc013114fa307bb) fix: textarea focus - [`329a6ff`](https://github.com/vxcontrol/pentagi/commit/329a6ffc9fe7d697cbf64913c8d2721e7d487648) fix: empty flow assistant logs when no updates occur ### 📊 Changes **13 files changed** (+225 additions, -87 deletions) <details> <summary>View changed files</summary> 📝 `backend/pkg/controller/aslog.go` (+9 -1) 📝 `backend/pkg/csum/chain_summary.go` (+24 -7) 📝 `backend/pkg/database/assistantlogs.sql.go` (+10 -0) 📝 `backend/pkg/database/querier.go` (+1 -0) 📝 `backend/pkg/providers/anthropic/config.yml` (+11 -11) 📝 `backend/pkg/providers/openai/config.yml` (+24 -24) 📝 `backend/pkg/providers/openai/models.yml` (+28 -0) 📝 `backend/pkg/tools/executor.go` (+1 -1) 📝 `backend/sqlc/models/assistantlogs.sql` (+4 -0) 📝 `frontend/src/components/ui/input-group.tsx` (+1 -1) 📝 `frontend/src/features/flows/flow-form.tsx` (+17 -1) 📝 `frontend/src/lib/apollo.ts` (+93 -39) 📝 `frontend/src/styles/index.css` (+2 -2) </details> ### 📄 Description <!-- Thank you for your contribution to PentAGI! Please fill out this template completely to help us review your changes effectively. Any PR that does not include enough information may be closed at maintainers' discretion. --> ### Description of the Change #### Problem Multiple performance and quality issues affecting agent execution and UI responsiveness: **Empty Assistant Logs:** - Backend created empty AssistantLog records when LLM sent only `result` (tool call JSON) without message chunks - Records remained in database with `message=""`, polluting UI with blank entries - Occurred during tool executions (file, terminal operations) **Memory Growth in Browser:** - Each streaming chunk created new objects in Apollo Cache (300-400MB per agent call) - String concatenation generated intermediate copies: 6 bytes → 11 bytes → ... → 100KB - 1000+ chunks resulted in exponential memory consumption **Subscription Cache Handling:** - New assistant logs from subscriptions failed to appear in UI when not pre-cached - `toReference(..., true)` only created references to existing objects - Streaming updates ignored if log didn't exist in cache **Outdated Model Configurations:** - Anthropic and OpenAI provider configurations had lower max_tokens limits - Missing GPT-5.4 series models with advanced capabilities **QA Summarization Redundancy:** - Chain summary logic could double-summarize already processed sections - Wasted tokens and processing time on redundant operations **Minor UI Issue:** - Textarea focus behavior inconsistent #### Solution **Backend - Empty Log Cleanup:** - Added `wasUpdated` flag in `workerMsgUpdater` to track if record received any content/thinking/result chunks - Created `DeleteFlowAssistantLog` SQL query for cleanup - Delete record on timeout if never updated (no meaningful data) - Preserves records with any content or result **Frontend - Memory Optimization:** - Implemented 100ms throttling for streaming updates (10 updates/sec vs 1000+) - Fixed cache update logic: new logs now properly added via `toReference(...)` without second parameter - Modified `update` strategy to add missing objects to cache arrays - **Result**: ~90% memory reduction (40MB vs 400MB per call) **Frontend - Streaming Performance:** - Refactored Observable handling to skip intermediate chunks (return early instead of `data: {}`) - Custom Observable in `createStreamingLink` with conditional `observer.next()` calls - Chunks accumulate locally, emit to UI only every 100ms - Font path fixes in CSS for proper italic style loading **Model Configuration Updates:** - Increased Anthropic max_tokens limits for better performance - Added GPT-5.4 series models with updated pricing and capabilities - Enhanced model descriptions **Summarization Improvements:** - Added checks to skip sections already containing summarized content - Improved recent section handling for AST generation - Reduced redundant LLM calls **Textarea Fix:** - Corrected focus behavior ### Type of Change <!-- Mark with an `x` all options that apply --> - [x] 🐛 Bug fix (non-breaking change which fixes an issue) - [x] 🚀 New feature (non-breaking change which adds functionality) - [ ] 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 📚 Documentation update - [x] 🔧 Configuration change - [ ] 🧪 Test update - [ ] 🛡️ Security update ### Areas Affected <!-- Mark with an `x` all components that are affected --> - [x] Core Services (Frontend UI/Backend API) - [ ] AI Agents (Researcher/Developer/Executor) - [ ] Security Tools Integration - [ ] Memory System (Vector Store/Knowledge Base) - [ ] Monitoring Stack (Grafana/OpenTelemetry) - [ ] Analytics Platform (Langfuse) - [x] External Integrations (LLM/Search APIs) - [ ] Documentation - [ ] Infrastructure/DevOps ### Testing and Verification #### Test Configuration ```yaml PentAGI Version: Latest development Docker Version: 24.0.x Host OS: macOS/Linux LLM Provider: OpenAI, Anthropic Enabled Features: Core ``` #### Test Steps 1. **Empty logs cleanup**: Create flow with tool-heavy agent execution (file operations), verify no empty logs in `assistantlogs` table 2. **Memory usage**: Run 3 consecutive agent calls with long responses, monitor browser tab memory (should stay under 100MB increase total) 3. **Streaming display**: Verify assistant responses appear smoothly every ~100ms during generation 4. **Cache handling**: Open new flow, verify assistant logs from subscriptions appear immediately in UI 5. **Model configs**: Test flows with updated Anthropic/OpenAI models, verify higher token limits work 6. **Summarization**: Run multiple flows with QA patterns, verify no redundant summarization in logs #### Test Results - ✅ **Empty logs eliminated**: Zero blank records in assistantlogs after tool executions - ✅ **Streaming smooth**: Text appears progressively at 10 updates/sec - ✅ **Subscriptions work**: New logs from `assistantLogUpdated` display correctly - ✅ **Models validated**: GPT-5.4 series and updated Anthropic configs functional - ✅ **Summarization efficient**: No duplicate processing observed - ✅ Backend compilation clean - ✅ Frontend linting passed ### Security Considerations **No Security Impact:** - Backend changes improve data quality (delete empty records) - Frontend changes are performance optimizations - Model configuration updates don't change authentication or authorization - No new dependencies or external services ### Performance Impact **Major Improvements:** - **Browser memory**: 90% reduction (40MB vs 400MB per agent call with 1000+ chunks) - **Apollo Cache efficiency**: ~100 updates vs 1000+ per streaming response - **React rendering**: 10 renders/sec vs 1000+ during streaming - **Database cleanup**: Eliminates accumulation of empty records - **Summarization**: Skips redundant operations, saves LLM tokens **Streaming Trade-off:** - Throttling to 100ms (10 updates/sec) provides smooth visual streaming while preventing memory bloat - Users see progressive text generation without performance degradation ### Documentation Updates - [ ] README.md updates - [ ] API documentation updates - [ ] Configuration documentation updates - [ ] GraphQL schema updates - [ ] Other ### Deployment Notes **Database Migration:** - New SQL function: `DeleteFlowAssistantLog` (sqlc-generated) - No schema changes, backward compatible **Environment Variables:** - No new configuration required - Existing deployments work without changes **Deployment Steps:** 1. Pull latest changes 2. Rebuild: `docker compose build` 3. Restart: `docker compose up -d` 4. sqlc generation happens automatically during build **Compatibility:** - ✅ Fully backward compatible - ✅ No breaking changes - ✅ Existing flows unaffected ### Checklist #### Code Quality - [x] My code follows the project's coding standards - [ ] I have added/updated necessary documentation - [ ] I have added tests to cover my changes - [x] All new and existing tests pass - [x] I have run `go fmt` and `go vet` (for Go code) - [x] I have run `npm run lint` (for TypeScript/JavaScript code) #### Security - [x] I have considered security implications - [x] Changes maintain or improve the security model - [x] Sensitive information has been properly handled #### Compatibility - [x] Changes are backward compatible - [x] No breaking changes - [x] Dependencies are properly updated #### Documentation - [x] Documentation is clear and complete - [x] Comments are added for non-obvious code - [x] API changes are documented (no API changes) ### Additional Notes ## Key Changes by Category ### Critical Fixes **Empty Assistant Logs Cleanup** (Commit 329a6ff): - **File**: `backend/pkg/controller/aslog.go` - Added `wasUpdated` boolean flag in `workerMsgUpdater` goroutine - Tracks if any chunk updates occurred (Content, Thinking, Flush, Result types) - On timeout: deletes record if `wasUpdated == false` - **Result**: Eliminates empty records created when LLM sends only tool call JSON without message **Streaming Memory Optimization** (Commit 852c48b): - **File**: `frontend/src/lib/apollo.ts` - Implemented 100ms throttling via `shouldEmitUpdate` function and `lastUpdateTimestamps` Map - Changed cache reference logic: `toReference(newItem)` creates new objects only for `assistantLogUpdated` when missing - Modified `update` strategy to add new objects to arrays if not present - Custom Observable skips intermediate chunks, emits every 100ms - **Result**: 90% memory reduction (40MB vs 400MB), smooth streaming at 10 FPS **Font Loading Fix** (Commit 852c48b): - **File**: `frontend/src/styles/index.css` - Corrected italic font file paths - **Result**: Proper italic rendering ### Feature Updates **Model Configuration Enhancement** (Commit fa70b03): - **Files**: `backend/pkg/providers/anthropic/config.yml`, `backend/pkg/providers/openai/config.yml`, `backend/pkg/providers/openai/models.yml` - Increased `max_tokens` limits for Anthropic models (better long-form output) - Updated OpenAI to GPT-5.4 series with new pricing structure - Added GPT-5.4 model descriptions reflecting advanced capabilities - **Result**: Better output quality from updated models **QA Summarization Optimization** (Commit bb50d10): - **File**: `backend/pkg/csum/chain_summary.go` - Added checks to prevent re-summarizing sections already containing summaries - Improved section retention logic for AST generation - **Result**: Reduced redundant LLM calls, token savings **Textarea Focus** (Commit 41add52): - Minor UI improvement - **Result**: Better UX consistency --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-06 22:09:52 -04:00
yindo closed this issue 2026-06-06 22:09:52 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vxcontrol/pentagi#244