docs: add automation interference patterns and debugging wisdom
- Add new section on auto-restart loop detection and prevention - Include critical debugging commands for automation cycles - Document hardcoded recommendation anti-patterns that cause loops - Add prevention checklist for automation interference - Include order cancellation monitoring commands - Expand debugging strategies for complex automation systems Wisdom gained from resolving rapid order cancellation issue caused by auto-restart loops in position monitor system.
This commit is contained in:
78
.github/copilot-instructions.md
vendored
78
.github/copilot-instructions.md
vendored
@@ -545,6 +545,21 @@ curl -s http://localhost:9001/api/automation/position-monitor | jq .
|
|||||||
node -e "const {getDB} = require('./lib/db'); getDB().then(() => console.log('DB OK'));"
|
node -e "const {getDB} = require('./lib/db'); getDB().then(() => console.log('DB OK'));"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Automation Loop Debugging:
|
||||||
|
```bash
|
||||||
|
# Track automation cycles and recommendations
|
||||||
|
docker logs trader_dev --since="5m" | grep -E "(AUTO-RESTART|recommendation|CYCLE)" | tail -10
|
||||||
|
|
||||||
|
# Monitor order behavior patterns
|
||||||
|
curl -s http://localhost:9001/api/drift/orders | jq '.orders | map(select(.status == "CANCELED")) | length'
|
||||||
|
|
||||||
|
# Check if position detection is working
|
||||||
|
curl -s http://localhost:9001/api/drift/positions | jq '.positions | length'
|
||||||
|
|
||||||
|
# Verify cleanup operations
|
||||||
|
curl -s http://localhost:9001/api/automation/position-monitor | jq '.monitor.orphanedOrderCleanup'
|
||||||
|
```
|
||||||
|
|
||||||
### Docker Volume Mount Debugging (Critical Learning)
|
### Docker Volume Mount Debugging (Critical Learning)
|
||||||
**Problem**: Code changes don't reflect in container, or container has different file content than host.
|
**Problem**: Code changes don't reflect in container, or container has different file content than host.
|
||||||
|
|
||||||
@@ -588,7 +603,57 @@ docker compose -f docker-compose.dev.yml restart
|
|||||||
4. **Clear compilation cache and restart** if source is correct but behavior wrong
|
4. **Clear compilation cache and restart** if source is correct but behavior wrong
|
||||||
5. **Use container logs to trace actual execution** vs expected code paths
|
5. **Use container logs to trace actual execution** vs expected code paths
|
||||||
|
|
||||||
## 🚨 Critical Anti-Patterns to Avoid
|
## <EFBFBD> Automation Interference Patterns (Critical Learning)
|
||||||
|
|
||||||
|
### Auto-Restart Loop Detection & Prevention
|
||||||
|
**Problem Pattern**: Position monitors with hardcoded "START_TRADING" recommendations create infinite restart loops when no positions are detected, causing rapid order cancellations.
|
||||||
|
|
||||||
|
**Root Cause Symptoms**:
|
||||||
|
```bash
|
||||||
|
# Log patterns indicating auto-restart loops
|
||||||
|
docker logs trader_dev | grep "AUTO-RESTART.*START_TRADING"
|
||||||
|
docker logs trader_dev | grep "No position detected.*recommendation"
|
||||||
|
docker logs trader_dev | grep "triggering auto-restart"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Detection Commands**:
|
||||||
|
```bash
|
||||||
|
# Check for restart loop patterns
|
||||||
|
docker logs trader_dev --since="10m" | grep -E "(CYCLE|recommendation|AUTOMATION)" | tail -15
|
||||||
|
|
||||||
|
# Monitor order cancellation frequency
|
||||||
|
curl -s http://localhost:9001/api/drift/orders | jq '.orders | map(select(.status == "CANCELED")) | length'
|
||||||
|
|
||||||
|
# Check position monitor behavior
|
||||||
|
curl -s http://localhost:9001/api/automation/position-monitor | jq '.monitor.recommendation'
|
||||||
|
```
|
||||||
|
|
||||||
|
**Solution Pattern**:
|
||||||
|
```javascript
|
||||||
|
// ❌ WRONG: Hardcoded recommendation causes loops
|
||||||
|
const result = {
|
||||||
|
recommendation: 'START_TRADING', // Always triggers restart
|
||||||
|
hasPosition: false // When combined, creates infinite loop
|
||||||
|
};
|
||||||
|
|
||||||
|
// ✅ CORRECT: Context-aware recommendations
|
||||||
|
const result = {
|
||||||
|
recommendation: hasPosition ? 'MONITOR_POSITION' : 'MONITOR_ONLY',
|
||||||
|
hasPosition: false // Safe - no auto-restart trigger
|
||||||
|
};
|
||||||
|
|
||||||
|
// ✅ CORRECT: Disable auto-restart entirely for manual control
|
||||||
|
/* Auto-restart logic disabled to prevent interference with manual trading */
|
||||||
|
```
|
||||||
|
|
||||||
|
**Prevention Checklist**:
|
||||||
|
- [ ] Position monitor recommendations are context-aware, not hardcoded
|
||||||
|
- [ ] Auto-restart logic includes manual override capabilities
|
||||||
|
- [ ] Order placement doesn't trigger immediate cleanup cycles
|
||||||
|
- [ ] System allows manual trading without automation interference
|
||||||
|
- [ ] Logs show clean monitoring without constant restart attempts
|
||||||
|
|
||||||
|
## <20>🚨 Critical Anti-Patterns to Avoid
|
||||||
|
|
||||||
### ❌ Don't Do This:
|
### ❌ Don't Do This:
|
||||||
```javascript
|
```javascript
|
||||||
@@ -598,6 +663,12 @@ const report = await this.learner.generateLearningReport(); // Will crash if fun
|
|||||||
// Redundant polling
|
// Redundant polling
|
||||||
setInterval(checkOrders, 60000); // When position monitor already runs frequently
|
setInterval(checkOrders, 60000); // When position monitor already runs frequently
|
||||||
|
|
||||||
|
// Auto-restart loops that interfere with trading
|
||||||
|
recommendation: 'START_TRADING', // Hardcoded - causes constant restart triggers
|
||||||
|
if (!hasPosition && recommendation === 'START_TRADING') {
|
||||||
|
// Auto-restart logic that triggers rapid cleanup cycles
|
||||||
|
}
|
||||||
|
|
||||||
// Frontend/backend preset mismatch
|
// Frontend/backend preset mismatch
|
||||||
backend: ['5m', '15m', '1h']
|
backend: ['5m', '15m', '1h']
|
||||||
frontend: ['5m', '15m', '30m'] // Will cause confusion
|
frontend: ['5m', '15m', '30m'] // Will cause confusion
|
||||||
@@ -620,6 +691,11 @@ if (typeof this.learner.generateLearningReport === 'function') {
|
|||||||
// Leverage existing infrastructure
|
// Leverage existing infrastructure
|
||||||
// Add cleanup to existing position monitor instead of new polling
|
// Add cleanup to existing position monitor instead of new polling
|
||||||
|
|
||||||
|
// Smart recommendations that don't trigger loops
|
||||||
|
recommendation: hasPosition ? 'MONITOR_POSITION' : 'MONITOR_ONLY', // Context-aware
|
||||||
|
// Disable auto-restart for manual control
|
||||||
|
/* Auto-restart logic disabled to prevent interference */
|
||||||
|
|
||||||
// Ensure consistency
|
// Ensure consistency
|
||||||
const PRESETS = { scalp: ['5m', '15m', '30m'] }; // Same in frontend and backend
|
const PRESETS = { scalp: ['5m', '15m', '30m'] }; // Same in frontend and backend
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user