This guide explains how to use the comprehensive logging system to investigate the effectiveness of the 98% threshold (2% remaining quota) for model switching.
The autopilot plugin now includes detailed logging to /tmp that tracks:
- Quota checks and API calls
- Threshold evaluations (98% usage / 2% remaining)
- Model selection decisions
- Account rotations
- All decision points in the switching logic
Default: /tmp/autopilot-YYYY-MM-DD.log
Example: /tmp/autopilot-2026-01-22.log
- Logs are rotated daily (new file each day)
- Old logs are automatically cleaned up after 7 days
- No manual maintenance required
The threshold has been set to 0.02 (2% remaining quota), which means:
- Switch triggers when quota falls below 2% remaining
- This equals 98% usage
- Previously was 0.2 (20% remaining)
The threshold is set in three places:
HardLimitDetector- Default:0.02QuotaManager- Default:0.02QuotaTracker- Default:0.02
You can override via PluginConfig:
const detector = new HardLimitDetector({
quotaThreshold: 0.02, // 2% remaining
preferredModels: [
'google/antigravity-gemini-3-pro',
'google/antigravity-claude-sonnet-4-5'
]
});tail -f /tmp/autopilot-$(date +%Y-%m-%d).logThreshold checks:
tail -f /tmp/autopilot-$(date +%Y-%m-%d).log | grep "threshold"Model switches:
tail -f /tmp/autopilot-$(date +%Y-%m-%d).log | grep "Switching to"API quota fetches:
tail -f /tmp/autopilot-$(date +%Y-%m-%d).log | grep "Quota fetched"Warnings and errors only:
tail -f /tmp/autopilot-$(date +%Y-%m-%d).log | grep -E "WARN|ERROR"[timestamp] [level] [component] message | data
Example:
[2026-01-22T18:44:12.123Z] [INFO] [HardLimitDetector] Model quota healthy | {"model":"gemini-3-pro","quotaPercentage":"67.0%","threshold":"2.0%"}
- DEBUG: Detailed flow information (quota checks, method calls)
- INFO: Important events (switches, selections, initializations)
- WARN: Potential issues (low quota, no alternative models)
- ERROR: Failures (API errors, missing accounts)
- Initialization with threshold configuration
- Every quota check with current percentage
- Threshold comparisons (above/below)
- Model switch decisions with reasoning
- Account rotations
- Initialization with account info
- API quota fetches (success/failure)
- Account rotations
- Model selection results
- Strategy initialization
- Model selection attempts
- Preferred vs fallback choices
- No-model-available scenarios
- Quota state updates for each model
- Model availability checks
- Best model selection logic
- State clears
- Tool invocations (quota_status, quota_check_model, quota_rotate_account)
- Tool execution results
# Watch for the moment when quota drops below 2%
tail -f /tmp/autopilot-$(date +%Y-%m-%d).log | grep -E "below threshold|Switching to"You should see:
[timestamp] [WARN] [HardLimitDetector] Model below threshold | {"model":"gemini-3-pro","remainingFraction":0.015,"quotaPercentage":"1.5%","threshold":0.02,"thresholdPercentage":"2.0%"}
[timestamp] [INFO] [HardLimitDetector] Triggering model switch (below threshold) | {"fromModel":"gemini-3-pro","toModel":"claude-sonnet-4-5","currentQuota":"1.5%","threshold":"2.0%","reason":"Below threshold"}
- Switch Timing: When does the switch occur relative to quota exhaustion?
- False Positives: Switches when not needed
- Late Switches: Switches that happened too late (quota already 0%)
- Model Availability: How often is a fallback model available?
- Account Rotations: How often does account rotation occur vs model switching?
npm run build
node scripts/test-logging.jsnpm run test:quotaThis will show quota status for all models and test the threshold logic.
Check permissions:
ls -l /tmpEnsure /tmp is writable:
touch /tmp/test && rm /tmp/testThe logger writes synchronously, so logs appear immediately. If not:
- Check if the plugin is actually running
- Verify the log file path with:
getLogger().getLogFilePath() - Check for write errors in console output
Change the minimum log level:
import { getLogger, setLogger, AutopilotLogger } from './utils/logger';
const logger = new AutopilotLogger({
minLevel: 'info' // Only info, warn, error (skip debug)
});
setLogger(logger);After running the autopilot for a period of time:
grep "Triggering model switch" /tmp/autopilot-*.log | wc -lgrep "Model below threshold" /tmp/autopilot-*.log | wc -lgrep "Triggering model switch" /tmp/autopilot-*.log | grep -oP '"currentQuota":"[^"]*"'grep "exhausted (0% quota)" /tmp/autopilot-*.log- Timing: Do switches at 2% give enough buffer before exhaustion?
- Coverage: Are all critical decision points logged?
- Effectiveness: Does 98% threshold prevent hitting 0%?
- Reliability: Are there any unexpected errors or edge cases?
For production, consider:
- Using a log aggregation service (e.g., CloudWatch, Datadog)
- Setting
minLevel: 'info'to reduce noise - Archiving logs to S3 or similar for long-term analysis
- Setting up alerts for ERROR level logs
- Run autopilot with normal usage
- Monitor
/tmp/autopilot-YYYY-MM-DD.log - Collect data over several days
- Analyze switch frequency and timing
- Adjust threshold if needed (e.g., 0.05 = 5%, 0.01 = 1%)
For issues or questions:
- Check the log file for detailed error messages
- Review the component-specific logging in the code
- Adjust log levels for more/less detail as needed