Repository navigation
feat(resilience): expose model cooldown list with manual re-enable #2146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| name: Claude Code Review | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, ready_for_review, reopened] | ||
| # Optional: Only run on specific file changes | ||
| # paths: | ||
| # - "src/**/*.ts" | ||
| # - "src/**/*.tsx" | ||
| # - "src/**/*.js" | ||
| # - "src/**/*.jsx" | ||
|
|
||
| jobs: | ||
| claude-review: | ||
| # Optional: Filter by PR author | ||
| # if: | | ||
| # github.event.pull_request.user.login == 'external-contributor' || | ||
| # github.event.pull_request.user.login == 'new-developer' || | ||
| # github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' | ||
|
|
||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| pull-requests: read | ||
| issues: read | ||
| id-token: write | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 1 | ||
|
|
||
| - name: Run Claude Code Review | ||
| id: claude-review | ||
| uses: anthropics/claude-code-action@v1 | ||
| with: | ||
| claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} | ||
| plugin_marketplaces: 'https://github.com/anthropics/claude-code.git' | ||
| plugins: 'code-review@claude-code-plugins' | ||
| prompt: '/code-review:code-review ${{ github.repository }}/pull/${{ github.event.pull_request.number }}' | ||
| # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md | ||
| # or https://code.claude.com/docs/en/cli-reference for available options | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| name: Claude Code | ||
|
|
||
| on: | ||
| issue_comment: | ||
| types: [created] | ||
| pull_request_review_comment: | ||
| types: [created] | ||
| issues: | ||
| types: [opened, assigned] | ||
| pull_request_review: | ||
| types: [submitted] | ||
|
|
||
| jobs: | ||
| claude: | ||
| if: | | ||
| (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) || | ||
| (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) || | ||
| (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) || | ||
| (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude'))) | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| pull-requests: read | ||
| issues: read | ||
| id-token: write | ||
| actions: read # Required for Claude to read CI results on PRs | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 1 | ||
|
|
||
| - name: Run Claude Code | ||
| id: claude | ||
| uses: anthropics/claude-code-action@v1 | ||
| with: | ||
| claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} | ||
|
|
||
| # This is an optional setting that allows Claude to read CI results on PRs | ||
| additional_permissions: | | ||
| actions: read | ||
| # Optional: Give a custom prompt to Claude. If this is not specified, Claude will perform the instructions specified in the comment that tagged it. | ||
| # prompt: 'Update the pull request description to include a summary of changes.' | ||
|
|
||
| # Optional: Add claude_args to customize behavior and configuration | ||
| # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md | ||
| # or https://code.claude.com/docs/en/cli-reference for available options | ||
| # claude_args: '--allowed-tools Bash(gh pr *)' | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| "use client"; | ||
|
|
||
| import { useCallback, useEffect, useMemo, useState } from "react"; | ||
| import { Button, Card } from "@/shared/components"; | ||
| import { useNotificationStore } from "@/store/notificationStore"; | ||
|
|
||
| type CooldownItem = { | ||
| provider: string; | ||
| model: string; | ||
| reason: string; | ||
| remainingMs: number; | ||
| unavailableSince: string; | ||
| }; | ||
|
|
||
| function formatRemaining(ms: number): string { | ||
| const totalSec = Math.max(0, Math.ceil(ms / 1000)); | ||
| const min = Math.floor(totalSec / 60); | ||
| const sec = totalSec % 60; | ||
| return `${min}m ${sec}s`; | ||
| } | ||
|
|
||
| export default function ModelCooldownsCard() { | ||
| const notify = useNotificationStore(); | ||
| const [items, setItems] = useState<CooldownItem[]>([]); | ||
| const [loading, setLoading] = useState(true); | ||
| const [busyKey, setBusyKey] = useState<string | null>(null); | ||
|
|
||
| const load = useCallback(async () => { | ||
| try { | ||
| const res = await fetch("/api/resilience/model-cooldowns", { cache: "no-store" }); | ||
| const json = await res.json(); | ||
| if (!res.ok) throw new Error(json?.error || `HTTP ${res.status}`); | ||
| setItems(Array.isArray(json.items) ? json.items : []); | ||
| } catch (error) { | ||
| notify.error(error instanceof Error ? error.message : "Failed to load cooldowns"); | ||
| } finally { | ||
| setLoading(false); | ||
| } | ||
| }, [notify]); | ||
|
|
||
| useEffect(() => { | ||
| void load(); | ||
| const timer = setInterval(() => { | ||
| void load(); | ||
| }, 5000); | ||
| return () => clearInterval(timer); | ||
| }, [load]); | ||
|
|
||
| const clearOne = useCallback( | ||
| async (provider: string, model: string) => { | ||
| const key = `${provider}::${model}`; | ||
| setBusyKey(key); | ||
| try { | ||
| const res = await fetch("/api/resilience/model-cooldowns", { | ||
| method: "DELETE", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify({ provider, model }), | ||
| }); | ||
| const json = await res.json(); | ||
| if (!res.ok) throw new Error(json?.error || `HTTP ${res.status}`); | ||
| notify.success(`Modelo reativado: ${provider}/${model}`); | ||
| await load(); | ||
| } catch (error) { | ||
| notify.error(error instanceof Error ? error.message : "Failed to clear cooldown"); | ||
| } finally { | ||
| setBusyKey(null); | ||
| } | ||
| }, | ||
| [load, notify] | ||
| ); | ||
|
|
||
| const clearAll = useCallback(async () => { | ||
| setBusyKey("ALL"); | ||
| try { | ||
| const res = await fetch("/api/resilience/model-cooldowns", { | ||
| method: "DELETE", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify({ all: true }), | ||
| }); | ||
| const json = await res.json(); | ||
| if (!res.ok) throw new Error(json?.error || `HTTP ${res.status}`); | ||
| notify.success("Todos os modelos em cooldown foram reativados."); | ||
| await load(); | ||
| } catch (error) { | ||
| notify.error(error instanceof Error ? error.message : "Failed to clear cooldowns"); | ||
| } finally { | ||
| setBusyKey(null); | ||
| } | ||
| }, [load, notify]); | ||
|
|
||
| const hasItems = items.length > 0; | ||
| const sorted = useMemo(() => [...items].sort((a, b) => b.remainingMs - a.remainingMs), [items]); | ||
|
|
||
| return ( | ||
| <Card className="p-6"> | ||
| <div className="flex items-start justify-between gap-4"> | ||
| <div> | ||
| <h2 className="text-lg font-bold text-text-main">Modelos em cooldown</h2> | ||
| <p className="mt-1 text-sm text-text-muted"> | ||
| Lista de modelos temporariamente isolados por falha. Quando o cooldown expira, eles | ||
| voltam automaticamente. | ||
| </p> | ||
|
Comment on lines
+98
to
+102
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This component contains hardcoded Portuguese strings (e.g., "Modelos em cooldown"). Since the project uses |
||
| </div> | ||
| <div className="flex gap-2"> | ||
| <Button size="sm" variant="secondary" onClick={() => void load()} disabled={loading}> | ||
| Atualizar | ||
| </Button> | ||
| <Button | ||
| size="sm" | ||
| variant="primary" | ||
| onClick={() => void clearAll()} | ||
| disabled={!hasItems || busyKey === "ALL"} | ||
| > | ||
| Reativar todos | ||
| </Button> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="mt-4 space-y-2"> | ||
| {loading ? ( | ||
| <p className="text-sm text-text-muted">Carregando...</p> | ||
| ) : !hasItems ? ( | ||
| <p className="text-sm text-text-muted">Nenhum modelo em cooldown no momento.</p> | ||
| ) : ( | ||
| sorted.map((item) => { | ||
| const rowKey = `${item.provider}::${item.model}`; | ||
| return ( | ||
| <div | ||
| key={rowKey} | ||
| className="rounded-lg border border-border bg-bg-subtle px-3 py-2 flex items-center justify-between gap-3" | ||
| > | ||
| <div className="min-w-0"> | ||
| <p className="text-sm font-medium text-text-main truncate"> | ||
| {item.provider}/{item.model} | ||
| </p> | ||
| <p className="text-xs text-text-muted"> | ||
| motivo: {item.reason} • restante: {formatRemaining(item.remainingMs)} | ||
| </p> | ||
| </div> | ||
| <Button | ||
| size="sm" | ||
| variant="secondary" | ||
| onClick={() => void clearOne(item.provider, item.model)} | ||
| disabled={busyKey === rowKey} | ||
| > | ||
| Reativar | ||
| </Button> | ||
| </div> | ||
| ); | ||
| }) | ||
| )} | ||
| </div> | ||
| </Card> | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
setIntervalfor polling can lead to overlapping requests if the network is slow or the server response time exceeds the interval (5 seconds). It is generally safer to use a recursivesetTimeoutpattern or check theloadingstate before initiating a new fetch to ensure only one request is active at a time.