-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add periodic cleanup for expired workspaces #345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
CarlJi
commented
Sep 2, 2025
- Add automatic cleanup of expired workspaces every 24 hours
- Implement startPeriodicCleanup and cleanupExpiredWorkspaces methods
- Remove unused repo_manager.go file
- Improve cleanup logging and error handling
- Add automatic cleanup of expired workspaces every 24 hours - Implement startPeriodicCleanup and cleanupExpiredWorkspaces methods - Remove unused repo_manager.go file - Improve cleanup logging and error handling
Code Review for PR #345: Workspace Cleanup ImplementationTodo List:
Overall AssessmentThis PR implements a well-structured periodic cleanup system for expired workspaces. The implementation is solid and follows good practices. Here's my detailed feedback: ✅ Strengths
🔧 Suggestions for Improvements1. Goroutine Lifecycle ManagementIssue: The cleanup goroutine runs indefinitely with no way to stop it gracefully. Suggestion: Consider adding a context for graceful shutdown: func (m *Manager) startPeriodicCleanup(ctx context.Context) {
ticker := time.NewTicker(24 * time.Hour)
m.cleanupExpiredWorkspaces()
go func() {
defer ticker.Stop()
for {
select {
case <-ticker.C:
m.cleanupExpiredWorkspaces()
case <-ctx.Done():
log.Infof("Stopping periodic workspace cleanup")
return
}
}
}()
} 2. Error Handling ResilienceLocation: Suggestion: Add panic recovery to prevent a single cleanup failure from crashing the goroutine: defer func() {
if r := recover(); r != nil {
log.Errorf("Panic in workspace cleanup: %v", r)
}
}() 3. Configurable Cleanup IntervalIssue: 24-hour interval is hardcoded. Suggestion: Make the cleanup interval configurable through workspace:
base_dir: "./workspace"
cleanup_after: "24h"
cleanup_interval: "24h" # New field 🐛 Potential Issues1. Race Condition RiskLocation: Issue: Multiple cleanup operations could potentially interfere with active workspaces. Mitigation: The existing code appears safe since it only cleans expired workspaces, but consider adding a brief check to ensure workspaces aren't actively being used. 2. Memory UsageLocation: Issue: For repositories with many expired workspaces, loading all at once could consume significant memory. Suggestion: Consider batch processing: // Process in batches of 50 to avoid memory spikes
const batchSize = 50
for len(expiredWorkspaces) > 0 {
batch := expiredWorkspaces
if len(batch) > batchSize {
batch = expiredWorkspaces[:batchSize]
expiredWorkspaces = expiredWorkspaces[batchSize:]
} else {
expiredWorkspaces = nil
}
// Process batch...
} 📚 Documentation Consistency✅ Good: The README.md already documents the workspace:
cleanup_after: "24h" Suggestion: Add a note about the automatic periodic cleanup feature: # Workspace settings
workspace:
base_dir: "./workspace"
cleanup_after: "24h" # Workspaces older than this will be automatically cleaned up every 24 hours 🏗️ Architecture & DesignExcellent Decisions:
Minor Enhancement: Consider exposing cleanup statistics through a metrics/health endpoint for monitoring. 🧪 Testing ConsiderationsThe implementation would benefit from:
💡 SummaryThis is a solid implementation that addresses workspace cleanup effectively. The code is well-structured, properly logged, and integrates cleanly with existing systems. The main improvements would be around graceful shutdown, configurability, and enhanced resilience. The removal of the unused Recommendation: ✅ Approve with minor suggestions - the core functionality is sound and production-ready. 👉 Want me to re-run this review? Just type |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #345 +/- ##
=======================================
Coverage ? 12.82%
=======================================
Files ? 56
Lines ? 11562
Branches ? 0
=======================================
Hits ? 1483
Misses ? 9922
Partials ? 157
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@qiniu-ci 帮我分析下这个报告 |
- Add MCPConfigPath field to Workspace model for tracking MCP config files - Move MCP config files to workspace-related directories instead of global temp - Implement comprehensive MCP config cleanup in workspace manager - Add recovery support for existing MCP config files during workspace restoration - Enhance cleanup logic to ensure all workspace-related files are properly removed
@qiniu-ci 帮我review下这个PR |
7a3dfa7
to
3664f96
Compare
@qiniu-ci 帮我review下这个PR |
你好!我来介绍一下自己 👋Hi @CarlJi! Great question! 🤖 Who am I?I'm qiniu-ci - an AI assistant designed specifically to help with GitHub issues and pull requests for this codebase. Think of me as your automated code review and development assistant! 🛠️ What I can help with:
📋 My Role in this PR:For PR #345 (your workspace cleanup implementation), I've been:
🤝 How to work with me:Just @ mention me with what you need! For example:
🇨🇳 Language Support:I can communicate in both English and Chinese (中文), whatever works better for you! Is there anything specific about PR #345 you'd like me to help with? I'm here and ready to assist! 😊 |
- Add FetchAndCheckoutPR method to GitService for handling PR content updates - Implement force sync mechanism to ensure PR workspaces have latest content - Handle force pushes and updates in fork PRs using GitHub PR refs - Update workspace validation to use stored branch information
3664f96
to
26d5950
Compare
@qiniu-ci 再帮我review下这个PR |
@qiniu-ci hi |
756548d
to
0e10e02
Compare
0e10e02
to
7fb7af5
Compare
@qiniu-ci hi, who are you? |
@qiniu-ci hi, who are you? |