Repository navigation
ci: consolidate Gemini + quota-gate + Jules workflows onto master-staging #75
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 15 commits
189b5ce
ac2361e
3f74515
8aef0d1
64a290c
438206c
76fbb5c
75ea254
b8450eb
817b6ef
ffd2dca
4646d92
3ed8b21
5d2b037
698386f
5f87f51
27e0b15
8814878
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,161 @@ | ||
| name: 'Gemini Quota Gate' | ||
| description: | | ||
| Throttle Gemini free-tier API calls so CI does not exhaust quotas. | ||
| Free-tier limits are multi-dimensional (RPM + TPM + RPD), NOT a hard | ||
| 20/day cap. Typical Flash free tier is ~15 RPM and ~1000–1500 RPD | ||
| (varies by model; Pro is lower). This gate tracks a per-day counter | ||
| with a safety margin (default 900 RPD) and supports multi-key rotation. | ||
| When exhausted, sets skip=true and posts a graceful comment instead of | ||
| hard-failing with TerminalQuotaError. Pair with continue-on-error on | ||
| the Gemini CLI step for transient RPM 429s within the day. | ||
|
|
||
| inputs: | ||
| daily-limit: | ||
| description: 'Max Gemini free-tier requests per day (safety margin on RPD; default 900)' | ||
| required: false | ||
| default: '900' | ||
| pr-number: | ||
| description: 'PR or issue number for the graceful skip comment' | ||
| required: false | ||
| default: '' | ||
| command: | ||
| description: 'The Gemini command (review/triage/invoke) for the skip message' | ||
| required: false | ||
| default: 'review' | ||
| has-backup-key: | ||
| description: 'Set to "true" if GEMINI_API_KEY_BACKUP secret is configured' | ||
| required: false | ||
| default: 'false' | ||
|
|
||
| outputs: | ||
| skip: | ||
| description: '"true" if quota exhausted and the job should be skipped' | ||
| value: ${{ steps.check.outputs.skip }} | ||
| remaining: | ||
| description: 'Remaining quota for today' | ||
| value: ${{ steps.check.outputs.remaining }} | ||
| use_backup_key: | ||
| description: '"true" if the backup key should be used instead of primary' | ||
| value: ${{ steps.check.outputs.use_backup_key }} | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Get Pacific date key (RPD resets midnight PT) | ||
| id: date | ||
| run: echo "key=$(TZ=America/Los_Angeles date +%Y-%m-%d)" >> "$GITHUB_OUTPUT" | ||
| shell: bash | ||
|
|
||
| - name: Restore quota counter | ||
| id: restore | ||
| uses: actions/cache/restore@v4 | ||
| with: | ||
| path: /tmp/gemini-quota | ||
| key: gemini-quota-${{ steps.date.outputs.key }} | ||
| restore-keys: gemini-quota-${{ steps.date.outputs.key }} | ||
| enableCrossOsArchive: true | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
Comment on lines
+49
to
+56
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. 📝 Info: Quota counter cache is scoped per branch, so the daily limit is under-counted Caches saved from a PR branch are not readable from other branches (only the base/default branch cache is inherited), so the daily request counter effectively restarts for each new PR branch. With a 900/day margin this is unlikely to matter in practice, but the gate cannot enforce a repo-wide RPD ceiling as the description implies. Also worth noting: two concurrent runs restore the same counter and each save under a run-scoped key, so parallel workflows double-spend without incrementing each other. Was this helpful? React with 👍 or 👎 to provide feedback.
Comment on lines
+49
to
+56
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. 🟡 Daily request budget is tracked separately per branch, so the limit can be exceeded many times over The daily counter is kept in a per-workflow-run cache entry that GitHub isolates per branch ( Cache scoping mechanismGitHub Actions cache entries created by a run on branch Additionally, two runs on the same branch that overlap in time both restore the same value and both write If a globally-consistent counter is required, an approach that is not branch-scoped is needed (e.g. a repository variable via the API, a gist, or a dedicated branch/issue used as state) — or the gate should be documented as best-effort per branch. Was this helpful? React with 👍 or 👎 to provide feedback.
Comment on lines
+49
to
+56
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. 📝 Info: Quota gate never restores the backup counter path correctly after a skip-only run When the primary counter is exhausted and no backup key is configured, the step sets Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| - name: Check / update daily Gemini quota | ||
| id: check | ||
| env: | ||
| DAILY_LIMIT: ${{ inputs.daily-limit }} | ||
| PR_NUMBER: ${{ inputs.pr-number }} | ||
| COMMAND: ${{ inputs.command }} | ||
| HAS_BACKUP_KEY: ${{ inputs.has-backup-key }} | ||
| run: | | ||
| set -eu | ||
|
|
||
| COUNTER_DIR="/tmp/gemini-quota" | ||
| COUNTER_FILE="${COUNTER_DIR}/counter.txt" | ||
| BACKUP_FILE="${COUNTER_DIR}/backup_counter.txt" | ||
|
|
||
| mkdir -p "$COUNTER_DIR" | ||
|
|
||
| CURRENT=$(cat "$COUNTER_FILE" 2>/dev/null || echo "0") | ||
| # Normalize CURRENT to 0 if empty or non-numeric | ||
| if ! [[ "$CURRENT" =~ ^[0-9]+$ ]]; then | ||
| CURRENT=0 | ||
| fi | ||
| LIMIT="$DAILY_LIMIT" | ||
| REMAINING=$(( LIMIT - CURRENT )) | ||
|
|
||
| echo "Gemini quota (primary key): $CURRENT / $LIMIT used today (RPD safety margin), $REMAINING remaining" | ||
| echo "Note: RPM (~15/min Flash free) is enforced by the API; this gate tracks daily RPD only." | ||
|
|
||
| if [ "$CURRENT" -ge "$LIMIT" ]; then | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| if [ "$HAS_BACKUP_KEY" = "true" ]; then | ||
| BACKUP_CURRENT=$(cat "$BACKUP_FILE" 2>/dev/null || echo "0") | ||
| # Normalize BACKUP_CURRENT to 0 if empty or non-numeric | ||
| if ! [[ "$BACKUP_CURRENT" =~ ^[0-9]+$ ]]; then | ||
| BACKUP_CURRENT=0 | ||
| fi | ||
| BACKUP_REMAINING=$(( LIMIT - BACKUP_CURRENT )) | ||
| echo "Gemini quota (backup key): $BACKUP_CURRENT / $LIMIT, $BACKUP_REMAINING remaining" | ||
|
|
||
| if [ "$BACKUP_CURRENT" -lt "$LIMIT" ]; then | ||
| echo "Primary key exhausted — rotating to backup key" | ||
| NEW=$(( BACKUP_CURRENT + 1 )) | ||
| echo "$NEW" > "$BACKUP_FILE" | ||
| echo "skip=false" >> "$GITHUB_OUTPUT" | ||
| echo "remaining=$(( LIMIT - NEW ))" >> "$GITHUB_OUTPUT" | ||
| echo "use_backup_key=true" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
| fi | ||
|
timerloggedout-spec marked this conversation as resolved.
Resolved
|
||
|
|
||
| echo "skip=true" >> "$GITHUB_OUTPUT" | ||
| echo "remaining=0" >> "$GITHUB_OUTPUT" | ||
| echo "use_backup_key=false" >> "$GITHUB_OUTPUT" | ||
| echo "::warning::Gemini free-tier daily RPD safety margin exhausted ($CURRENT/$LIMIT). Skipping to avoid TerminalQuotaError. RPD resets at midnight Pacific." | ||
| else | ||
| NEW=$(( CURRENT + 1 )) | ||
| echo "$NEW" > "$COUNTER_FILE" | ||
| echo "skip=false" >> "$GITHUB_OUTPUT" | ||
| echo "remaining=$(( LIMIT - NEW ))" >> "$GITHUB_OUTPUT" | ||
| echo "use_backup_key=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
Comment on lines
+110
to
+116
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. 📝 Info: Quota counter is subject to lost updates across concurrent runs The daily counter is restored from a shared cache, incremented locally, and saved under a run-unique key ( Was this helpful? React with 👍 or 👎 to provide feedback.
Owner
Author
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. @blocks fix this 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. Kimi Code: Rate limit or quota exceeded. Please wait before trying again. Detailserror: failed to run prompt: provider.rate_limit: 429 Your account org-da892ad7697f4eaeb9d8f03819ab836d is suspended due to insufficient balance, please recharge your account or check your plan and billing detailsSee log: /home/user/.kimi-code/logs/kimi-code.log |
||
| shell: bash | ||
|
|
||
| - name: Save quota counter | ||
| if: always() && steps.check.outputs.skip != 'true' | ||
|
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. 📝 Info: Quota counter is saved even when the gate step itself failed The save step uses Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| uses: actions/cache/save@v4 | ||
| with: | ||
| path: /tmp/gemini-quota | ||
| key: gemini-quota-${{ steps.date.outputs.key }}-${{ github.run_id }}-${{ github.run_attempt }} | ||
| enableCrossOsArchive: true | ||
|
Comment on lines
+119
to
+125
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. 📝 Info: Quota cache restore relies on prefix matching, which does work here I checked whether the exact Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| - name: Post graceful skip comment | ||
| if: steps.check.outputs.skip == 'true' && inputs.pr-number != '' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const prNumber = Number(process.env.PR_NUMBER); | ||
| if (!prNumber) return; | ||
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| per_page: 100, | ||
| }); | ||
| const marker = '<!-- gemini-quota-skip -->'; | ||
| if (comments.some(c => c.body && c.body.includes(marker))) { | ||
| core.info('Quota skip comment already exists'); | ||
| return; | ||
| } | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| body: [ | ||
| marker, | ||
| `⚠️ **Gemini CLI** ${process.env.COMMAND || 'review'} skipped — free-tier daily RPD safety margin exhausted.`, | ||
| '', | ||
| 'Limits are **RPM + TPM + RPD** (not a hard 20/day). RPD resets at midnight Pacific.', | ||
| 'This is **not a failure** — CI stays green. Other agents (CodeRabbit, Jules) continue.', | ||
| '', | ||
| 'To increase capacity: paid key, or `GEMINI_API_KEY_BACKUP` for multi-key rotation.', | ||
| ].join('\n'), | ||
| }); | ||
| env: | ||
| PR_NUMBER: ${{ inputs.pr-number }} | ||
| COMMAND: ${{ inputs.command }} | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.