Skip to content

Commit 5f8c957

Browse files
ArvorCoclaude
andcommitted
fix(agents): add debug logging for rate limit detection
- Add RELENTLESS_DEBUG env var to log rate limit detection details - Make model not found pattern more specific (JSON API format only) - Logs pattern matched, output sample, and timestamp Usage: RELENTLESS_DEBUG=1 relentless run --feature <name> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d6ffe8f commit 5f8c957

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/agents/claude.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,42 @@ export const claudeAdapter: AgentAdapter = {
180180
},
181181

182182
detectRateLimit(output: string): RateLimitInfo {
183+
// Debug: Log to file when rate limit is detected
184+
const debugRateLimit = (pattern: string, message: string) => {
185+
if (process.env.RELENTLESS_DEBUG) {
186+
const debugInfo = {
187+
timestamp: new Date().toISOString(),
188+
pattern,
189+
message,
190+
outputLength: output.length,
191+
outputSample: output.slice(0, 500),
192+
outputEnd: output.slice(-500),
193+
};
194+
console.error(`[RELENTLESS_DEBUG] Rate limit detected: ${JSON.stringify(debugInfo, null, 2)}`);
195+
}
196+
};
197+
183198
if (output.includes("[Relentless] Idle timeout")) {
199+
debugRateLimit("idle_timeout", "Claude idle timeout");
184200
return {
185201
limited: true,
186202
message: "Claude idle timeout",
187203
};
188204
}
189205

190206
if (/(?:operation not permitted|permission denied|\beperm\b).*(?:\/\.claude|\.claude)/i.test(output)) {
207+
debugRateLimit("permission_error", "Claude unavailable due to permission error");
191208
return {
192209
limited: true,
193210
message: "Claude unavailable due to permission error",
194211
};
195212
}
196213

197214
// More specific pattern for actual API model not found errors
198-
// Avoid matching if Claude just mentions "model" and "not_found_error" in conversation
199-
if (/error.*model.*not[_\s]?found|model.*not[_\s]?found.*error|"type":\s*"not_found_error"/i.test(output)) {
215+
// Only match JSON API error responses, not conversational mentions
216+
const modelNotFoundPattern = /"type":\s*"not_found_error".*"model"/i;
217+
if (modelNotFoundPattern.test(output)) {
218+
debugRateLimit("model_not_found", "Claude model not found");
200219
return {
201220
limited: true,
202221
message: "Claude model not found",
@@ -225,6 +244,7 @@ export const claudeAdapter: AgentAdapter = {
225244
}
226245
}
227246

247+
debugRateLimit("hit_your_limit", "Claude Code rate limit exceeded");
228248
return {
229249
limited: true,
230250
resetTime,

0 commit comments

Comments
 (0)