Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
189b5ce
ci: add gemini-quota-gate composite action (RPD safety margin 900, mi…
timerloggedout-spec Aug 7, 2026
ac2361e
ci: add gemini-triage + gemini-invoke + publish-wiki (quota-aware)
timerloggedout-spec Aug 7, 2026
3f74515
ci: add gemini-dispatch + gemini-review (quota-aware, session continu…
timerloggedout-spec Aug 7, 2026
8aef0d1
ci: add gemini-review.yml (session continuation + quota gate RPD 900)
timerloggedout-spec Aug 7, 2026
64a290c
test(smoke): add termux_smoke/connectors suite + TRACKING registry fo…
timerloggedout-spec Aug 7, 2026
438206c
test(smoke): wire connectors suite into termux_smoke.py core path
timerloggedout-spec Aug 7, 2026
76fbb5c
fix(termux-smoke): correct REPO_ROOT parents depth for connectors suite
timerloggedout-spec Aug 7, 2026
75ea254
ci: add agent-jules-on-issues.yml from master (label/@jules + coordin…
timerloggedout-spec Aug 7, 2026
b8450eb
Update .github/workflows/agent-jules-on-issues.yml
timerloggedout-spec Aug 7, 2026
817b6ef
Update .github/workflows/gemini-review.yml
timerloggedout-spec Aug 7, 2026
ffd2dca
Update .github/workflows/publish-wiki.yml
timerloggedout-spec Aug 7, 2026
4646d92
Update .github/workflows/gemini-invoke.yml
timerloggedout-spec Aug 7, 2026
3ed8b21
Update .github/workflows/gemini-triage.yml
timerloggedout-spec Aug 7, 2026
5d2b037
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] Aug 7, 2026
698386f
Merge branch 'master-staging' into feature/workflows-consolidation
timerloggedout-spec Aug 7, 2026
5f87f51
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] Aug 7, 2026
27e0b15
Update .github/workflows/agent-jules-on-issues.yml
timerloggedout-spec Aug 7, 2026
8814878
ci(workflows): plumb pr_number into gemini-review/triage/invoke for c…
timerloggedout-spec Aug 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions .github/actions/gemini-quota-gate/action.yml
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
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Comment on lines +49 to +56

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +49 to +56

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 (actions/cache/restore@v4 at .github/actions/gemini-quota-gate/action.yml:51-56), so each branch counts from zero and the shared daily budget is never actually enforced.
Impact: With several active branches the service can be called far more times per day than the configured limit, which is exactly the quota exhaustion this gate exists to prevent.

Cache scoping mechanism

GitHub Actions cache entries created by a run on branch feature/x are visible only to runs on feature/x (plus runs on the default branch / base branch of the PR). A run on feature/y restores nothing from feature/x, so CURRENT normalizes to 0 at .github/actions/gemini-quota-gate/action.yml:74-78 and each branch gets its own full daily-limit allowance. Every save at :119-125 also writes into the branch-scoped cache, so counts never merge.

Additionally, two runs on the same branch that overlap in time both restore the same value and both write CURRENT+1, losing one increment.

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.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +49 to +56

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 skip=true and the Save quota counter step is skipped (.github/actions/gemini-quota-gate/action.yml:120). That is fine for the counter itself, but note the backup counter is only ever written, never reset, and both counters live in the same cache entry keyed by date; a day rollover creates a fresh (empty) cache so both reset together — intended behaviour, but only because restore-keys is an exact-date prefix. If someone later loosens restore-keys to gemini-quota- the gate would silently import yesterday's counts and refuse to run all day.

Open in Devin Review

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
Comment thread
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
Comment thread
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

@devin-ai-integration devin-ai-integration Bot Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 (.github/actions/gemini-quota-gate/action.yml:49-56 and :119-125). Two workflow runs that start close together both restore the same value and both write CURRENT+1, so concurrent Gemini invocations are undercounted. Also, the exact key (gemini-quota-<date>) is never written — restoration always relies on prefix matching via restore-keys, which returns the most recently created matching cache; this works but means every run creates a new cache entry, so the day's entries compete for the repo cache eviction budget. Given the 900/day safety margin the drift is probably tolerable, but it is worth knowing the gate is best-effort rather than exact.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blocks fix this

@blocksorg blocksorg Bot Aug 7, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 details
See log: /home/user/.kimi-code/logs/kimi-code.log

View on dashboard

shell: bash

- name: Save quota counter
if: always() && steps.check.outputs.skip != 'true'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 if: always() && steps.check.outputs.skip != 'true'. If the check script aborts (e.g. set -eu trips before any output is written), skip is empty, so the condition holds and the cache is saved — possibly persisting a partially written or unchanged counter directory under a fresh key. Gating on steps.check.outputs.skip == 'false' would be tighter.

Open in Devin Review

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 key (gemini-quota-<date>) never matching any saved entry (saves always append -run_id-run_attempt, :124) would break restoration. It does not: restore-keys performs prefix matching and returns the most recently created match, so the previous run's counter is picked up within the same cache scope. The consequence is one unnecessary cache-miss log line per run plus a new cache entry per run (7-day eviction handles cleanup). Separately, note that a run that ends up skipping (skip == 'true') writes no cache entry, which is correct since no increment happened.

Open in Devin Review

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 }}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Loading
Loading