Say when a Claude usage limit resets
Run 355 stopped on the 5-hour usage window with the balance wording. The diagnostic now names the reset time the CLI reports.
This commit is contained in:
@@ -303,7 +303,8 @@ type claudeStreamRecord struct {
|
||||
} `json:"output_tokens_details"`
|
||||
} `json:"usage"`
|
||||
RateLimit *struct {
|
||||
Status string `json:"status"`
|
||||
Status string `json:"status"`
|
||||
ResetsAt int64 `json:"resetsAt"`
|
||||
} `json:"rate_limit_info"`
|
||||
Message *struct {
|
||||
Error string `json:"error"`
|
||||
@@ -346,6 +347,7 @@ func (c *ClaudeStageClient) run(ctx context.Context, env, args []string, model,
|
||||
c.WorkStarted = true
|
||||
var final *claudeStreamRecord
|
||||
var refusal, limited bool
|
||||
var resetsAt int64
|
||||
var authFailed, sessionMismatch, modelMismatch bool
|
||||
scanned := make(chan error, 1)
|
||||
go func() {
|
||||
@@ -372,6 +374,7 @@ func (c *ClaudeStageClient) run(ctx context.Context, env, args []string, model,
|
||||
case "rate_limit_event":
|
||||
if record.RateLimit != nil && record.RateLimit.Status == "rejected" {
|
||||
limited = true
|
||||
resetsAt = record.RateLimit.ResetsAt
|
||||
}
|
||||
case "assistant":
|
||||
if record.Message != nil {
|
||||
@@ -441,6 +444,11 @@ func (c *ClaudeStageClient) run(ctx context.Context, env, args []string, model,
|
||||
case authFailed:
|
||||
return "", fmt.Errorf("%w: %w", ErrHarnessTransport, errClaudeSignedOut)
|
||||
case refusal || (limited && (final == nil || final.IsError)):
|
||||
if resetsAt > 0 {
|
||||
// A usage window, not an empty account: say when it reopens (a
|
||||
// time only; no provider text is copied).
|
||||
return "", fmt.Errorf("%w: %w; the Claude usage limit resets at %s", ErrHarnessTransport, opencode.ErrProviderQuota, time.Unix(resetsAt, 0).Format("15:04 on 2 Jan"))
|
||||
}
|
||||
return "", fmt.Errorf("%w: %w", ErrHarnessTransport, opencode.ErrProviderQuota)
|
||||
case sessionMismatch || modelMismatch:
|
||||
return "", fmt.Errorf("%w: Claude Code did not start the requested session and model", ErrHarnessTransport)
|
||||
|
||||
@@ -70,7 +70,7 @@ case "$FAKE_CLAUDE_CASE" in
|
||||
;;
|
||||
limited)
|
||||
init "$session" "$model"
|
||||
echo '{"type":"rate_limit_event","rate_limit_info":{"status":"rejected"}}'
|
||||
echo '{"type":"rate_limit_event","rate_limit_info":{"status":"rejected","resetsAt":1794409200}}'
|
||||
echo '{"type":"result","subtype":"success","is_error":true,"result":"PROVIDER-BODY-SECRET","session_id":"'"$session"'",'"$usage"'}'
|
||||
exit 1
|
||||
;;
|
||||
@@ -251,9 +251,12 @@ func TestClaudeStageMissingExecutableIsRetryableReachFailure(t *testing.T) {
|
||||
|
||||
func TestClaudeStageFailuresAreFixedText(t *testing.T) {
|
||||
for which, check := range map[string]func(error) bool{
|
||||
"exit": func(err error) bool { return errors.Is(err, ErrHarnessTransport) },
|
||||
"quota": func(err error) bool { return errors.Is(err, opencode.ErrProviderQuota) },
|
||||
"limited": func(err error) bool { return errors.Is(err, opencode.ErrProviderQuota) },
|
||||
"exit": func(err error) bool { return errors.Is(err, ErrHarnessTransport) },
|
||||
"quota": func(err error) bool { return errors.Is(err, opencode.ErrProviderQuota) },
|
||||
// A usage window names when it reopens.
|
||||
"limited": func(err error) bool {
|
||||
return errors.Is(err, opencode.ErrProviderQuota) && strings.Contains(err.Error(), "usage limit resets at")
|
||||
},
|
||||
"auth": func(err error) bool { return errors.Is(err, errClaudeSignedOut) },
|
||||
"maxturns": func(err error) bool { return strings.Contains(err.Error(), "(error_max_turns)") },
|
||||
"othermodel": func(err error) bool { return errors.Is(err, ErrHarnessTransport) },
|
||||
|
||||
Reference in New Issue
Block a user