| name | timeout-prevention-operation-batching |
| description | Track execution time, identify operation batching opportunities, and prevent timeout violations. Use when approaching time limits or when performing many sequential operations to optimize execution and prevent 300-second timeout failures. |
Timeout Prevention and Operation Batching
Overview
Strategies for tracking execution time, identifying batching opportunities, and preventing timeout violations. Helps agents optimize operation patterns to stay within 300-second iteration limits.
Problem: Multiple tasks exceeded 300-second timeout limits due to excessive sequential operations (168+ shell commands in single iterations).
Solution: Monitor elapsed time, batch independent operations, and prioritize critical work when approaching limits.
Impact: Reduce timeout occurrences by 70-80%, improve task completion rates.
Time Tracking
Checkpoint Strategy
Monitor elapsed time at key checkpoints:
## Execution Checkpoints
1. **Start**: Record start time
2. **After Planning**: Check elapsed time after planning phase
3. **After Implementation**: Check elapsed time after code changes
4. **Before Testing**: Check elapsed time before browser/testing phase
5. **Soft Warning**: Alert at 200s (2/3 of 300s limit)
Time Monitoring Pattern
const startTime = Date.now();
const planningTime = Date.now() - startTime;
if (planningTime > 60) {
console.warn('Planning phase took longer than expected');
}
const elapsedTime = Date.now() - startTime;
if (elapsedTime > 200) {
console.warn('Approaching timeout limit - optimize remaining operations');
}
Soft Timeout Warnings
Alert agent when approaching 200s (2/3 of limit):
ā ļø **SOFT TIMEOUT WARNING** (200s / 300s limit)
When approaching 200 seconds:
- Prioritize critical operations
- Batch non-critical operations
- Skip optional verification steps
- Report progress immediately
- Consider deferring non-essential work
Operation Batching Patterns
Pattern 1: Batch Independent File Reads
Read multiple files in parallel instead of sequentially:
const file1 = read_file('src/scenes/GameScene.ts');
const file2 = read_file('src/scenes/MainMenu.ts');
const file3 = read_file('src/types/GameState.ts');
const [file1, file2, file3] = await Promise.all([
read_file('src/scenes/GameScene.ts'),
read_file('src/scenes/MainMenu.ts'),
read_file('src/types/GameState.ts')
]);
Pattern 2: Group Related Grep Searches
Combine multiple grep operations:
grep('GameState', 'src/**/*.ts');
grep('generateMaze', 'src/**/*.ts');
grep('TILE_SIZE', 'src/**/*.ts');
codebase_search('Where is GameState used and how is maze generation implemented?');
Pattern 3: Consolidate Browser Commands
Batch browser eval commands into single blocks:
agent-browser eval "window.__TEST__.commands.gameState()"
agent-browser eval "window.__TEST__.commands.setLevel(2)"
agent-browser eval "window.__TEST__.commands.setScore(100)"
agent-browser eval "
const state = window.__TEST__.commands.gameState();
window.__TEST__.commands.setLevel(2);
window.__TEST__.commands.setScore(100);
return state;
"
Pattern 4: Combine Viewport Tests
Test multiple viewports in single browser session:
agent-browser open "http://localhost:5173?scene=GameScene"
agent-browser viewport 500 400
agent-browser snapshot
agent-browser close
agent-browser open "http://localhost:5173?scene=GameScene"
agent-browser viewport 1024 768
agent-browser snapshot
agent-browser close
agent-browser open "http://localhost:5173?scene=GameScene"
agent-browser viewport 500 400
agent-browser snapshot
agent-browser viewport 1024 768
agent-browser snapshot
agent-browser viewport 1920 1080
agent-browser snapshot
agent-browser close
Pattern 5: Test Matrix Strategy
Test minimum and maximum viewports first, intermediate only if needed:
const viewports = [
{ width: 500, height: 400 },
{ width: 1920, height: 1080 },
];
if (issuesFound) {
viewports.push(
{ width: 1024, height: 768 },
{ width: 1280, height: 720 }
);
}
Priority Guidance
Critical vs Non-Critical Operations
When approaching timeout, prioritize:
## Priority Levels
### Critical (Must Complete)
- Core functionality implementation
- TypeScript compilation checks
- Critical bug fixes
- Success criteria verification
### Important (Should Complete)
- Browser testing for main scenarios
- Documentation updates
- Progress.txt updates
### Optional (Can Defer)
- Additional viewport testing
- Edge case testing
- Code cleanup
- Non-critical documentation
Timeout Scenario Strategy
When at 200s+ elapsed time:
1. **Skip optional operations**: Defer non-critical testing
2. **Batch aggressively**: Combine all remaining operations
3. **Prioritize verification**: Focus on success criteria
4. **Report progress**: Update progress.txt immediately
5. **Complete marker**: Output completion marker if criteria met
Checkpoint Strategy
Progress Reports
Force progress reports every 60-90 seconds:
## Progress Checkpoint (60s elapsed)
- [x] Planning phase complete
- [x] File analysis complete
- [ ] Implementation in progress
- [ ] Testing pending
## Progress Checkpoint (120s elapsed)
- [x] Planning phase complete
- [x] File analysis complete
- [x] Implementation complete
- [ ] Testing in progress
## Progress Checkpoint (180s elapsed)
- [x] Planning phase complete
- [x] File analysis complete
- [x] Implementation complete
- [x] Testing complete
- [ ] Final verification pending
Silent Hang Prevention
Report progress regularly to prevent silent hangs:
const lastReport = Date.now();
const REPORT_INTERVAL = 60000;
function checkProgress() {
const elapsed = Date.now() - lastReport;
if (elapsed > REPORT_INTERVAL) {
console.log(`Progress: ${currentPhase} - ${elapsedTime}s elapsed`);
lastReport = Date.now();
}
}
Best Practices
- Monitor time: Track elapsed time at checkpoints
- Batch operations: Group independent operations
- Prioritize critical: Focus on essential work when time is limited
- Report progress: Update every 60-90 seconds
- Soft warnings: Alert at 200s to optimize remaining work
- Parallel reads: Read multiple files simultaneously
- Consolidate commands: Batch browser and shell commands
- Test matrices: Test critical viewports first
Common Pitfalls
Pitfall 1: Sequential File Reads
Problem: Reading files one at a time
Solution: Batch independent file reads
read_file('file1.ts');
read_file('file2.ts');
read_file('file3.ts');
Promise.all([
read_file('file1.ts'),
read_file('file2.ts'),
read_file('file3.ts')
]);
Pitfall 2: Multiple Browser Sessions
Problem: Opening new browser session for each test
Solution: Reuse single session for multiple tests
agent-browser open "http://localhost:5173"
agent-browser snapshot
agent-browser close
agent-browser open "http://localhost:5173"
agent-browser snapshot
agent-browser close
agent-browser open "http://localhost:5173"
agent-browser snapshot
agent-browser reload
agent-browser snapshot
agent-browser close
Pitfall 3: No Time Awareness
Problem: Not monitoring elapsed time
Solution: Track time at checkpoints
const startTime = Date.now();
const elapsed = Date.now() - startTime;
if (elapsed > 200000) {
}
Integration with Other Skills
file-operation-optimization: Uses batching patterns for file operations
agent-browser: Applies batching to browser commands
refactoring-workflow-optimization: Uses time tracking during refactoring
Related Skills
file-operation-optimization - File reading and caching strategies
agent-browser - Browser automation patterns
refactoring-workflow-optimization - Refactoring with time awareness
Remember
- Track time: Monitor elapsed time at checkpoints
- Batch operations: Group independent operations
- Prioritize: Focus on critical work when time is limited
- Report progress: Update every 60-90 seconds
- Soft warnings: Alert at 200s (2/3 of limit)
- Prevent timeouts: Optimize patterns to stay within 300s limit