Skip to content

bot: Cloud Run deploy, sync mode, and limits for an App anyone can install - #36

Merged
Na5co merged 1 commit into
mainfrom
claude/bot-cloud-run
Sep 22, 2026
Merged

Na5co merged 1 commit into
mainfrom
claude/bot-cloud-run

Conversation

@Na5co

@Na5co Na5co commented Sep 22, 2026

Copy link
Copy Markdown
Owner

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.sh goes 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 1 because 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 3 as the ceiling on a busy day; --timeout 300 so 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_request whose installation cannot mint a token still answers 202, carrying the outcome rather than a bare "accepted". 12 bot tests, workspace green.

🤖 Generated with Claude Code

…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>
@Na5co
Na5co merged commit 01669c2 into main Sep 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant