Repository navigation
bot: Cloud Run deploy, sync mode, and limits for an App anyone can install - #36
Merged
Merged
Conversation
…stall Cloud Run's always-free tier covers roughly 18,000 pull requests a month, so the bot can be public without costing anything. - bot/deploy-cloud-run.sh: project in, webhook URL out. Enables the APIs, keeps the App key and webhook secret in Secret Manager, builds with Cloud Build (a Mac is arm64, Cloud Run is amd64), deploys with the flags that matter: concurrency 1 (a review peaks at 146 MB), max-instances 3, 512 MiB. - POLYGO_BOT_SYNC=1: review before answering. Cloud Run stops the CPU when the response goes out, which would freeze the background thread mid-review. - Limits, because an App anyone can install gets pointed anywhere: skip a repository over POLYGO_BOT_MAX_REPO_MB (default 500, asked of the API before anything is fetched) and an installation over POLYGO_BOT_MAX_REVIEWS per ten minutes (default 20). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes the App deployable for $0/month and safe to let strangers install.
Cloud Run. Its always-free tier is 2M requests, 180,000 vCPU-seconds and 360,000 GiB-seconds a month — about 18,000 pull requests at the ~10s a review takes.
bot/deploy-cloud-run.shgoes from a project id to a webhook URL: enables the APIs, puts the App key and webhook secret in Secret Manager (never in the image), builds with Cloud Build (a Mac is arm64, Cloud Run is amd64), deploys, prints the URL and secret to paste into the App settings. Idempotent — run it again to ship a build.The flags are chosen from measurements, not defaults:
--concurrency 1because a review peaks at 146 MB (measured on open-webui: 3,484 keys × 61 locales, 140,961 translations) and two at once would not fit in 512 MiB;--max-instances 3as the ceiling on a busy day;--timeout 300so a long check is not killed.POLYGO_BOT_SYNC=1. Cloud Run stops a container's CPU the moment the response goes out, so the bot's "answer 202, review on a thread" pattern would freeze mid-review. In sync mode the review happens first and its outcome is the response body. The cost: a check over GitHub's ten seconds shows in the delivery log as timed out, while the review still posts — the platform lets the handler finish after GitHub hangs up. Unset on a normal server, where the async path stays.Limits. An App anyone can install is an App anyone can point anywhere:
POLYGO_BOT_MAX_REPO_MB(500): the repository's size is asked of the API before anything is fetched, so a repository the size of a distribution costs one API call instead of the box.POLYGO_BOT_MAX_REVIEWS(20 per installation per 10 minutes): an in-memory limiter, which is the right shape — it forgets on restart, and it still stops the runaway it exists for.Tests: the limiter (share per installation, window expiry, env overrides) and sync mode end to end against a spawned server — a signed
pull_requestwhose installation cannot mint a token still answers202, carrying the outcome rather than a bare "accepted". 12 bot tests, workspace green.🤖 Generated with Claude Code