|
1 | 1 | # PyTorch Green Light |
2 | 2 |
|
3 | 3 | A Python service that runs a periodic iteration from the CLI — a one-shot |
4 | | -(cron-like) run by default, or a long-lived daemon with `--loop`. |
| 4 | +(cron-like) run by default, or a long-lived daemon with `--loop`. In production the |
| 5 | +scheduled scan runs as an AWS Lambda (`greenlight-scan`) on a 5-minute EventBridge |
| 6 | +schedule; the CLI one-shot and `--loop` daemon modes remain for local and other use. |
5 | 7 |
|
6 | 8 | ## Requirements |
7 | 9 |
|
8 | 10 | - **mise** — the only manual prerequisite. See <https://mise.jdx.dev>. |
9 | 11 |
|
10 | | -Everything else (Python 3.14, uv, just, and the non-Python linters) is provided |
| 12 | +Everything else (Python 3.13, uv, just, and the non-Python linters) is provided |
11 | 13 | by mise; `just setup` then installs the Python tools (ruff, mypy, pytest, yamllint). |
12 | 14 |
|
13 | 15 | ## Setup |
14 | 16 |
|
15 | 17 | ```bash |
16 | 18 | mise trust # trust greenlight/mise.toml on first use |
17 | | -mise install # install python 3.14, uv, just, and all tools |
| 19 | +mise install # install python 3.13, uv, just, and all tools |
18 | 20 | just setup # uv sync -> create .venv with deps |
19 | 21 | ``` |
20 | 22 |
|
@@ -147,6 +149,29 @@ iteration in both one-shot and `--loop` mode. In `--loop` mode, SIGTERM/SIGINT a |
147 | 149 | observed only between iterations, so the per-iteration timeout is what interrupts a |
148 | 150 | hung run. |
149 | 151 |
|
| 152 | +## Deployment |
| 153 | + |
| 154 | +In production the scheduled scan runs as an AWS Lambda, `greenlight-scan`, in the |
| 155 | +`pytorch-gha-infra-2` account (`us-east-1`), triggered by an EventBridge `rate(5 minutes)` |
| 156 | +schedule. The function runs `python3.13` with handler `greenlight.lambda_handler.handler`, a |
| 157 | +300 s timeout, and `reserved_concurrent_executions = 1`. It runs the same one-shot |
| 158 | +`execute_once` / `review.run` path as `greenlight review` — no scan-logic change — after minting a |
| 159 | +least-privilege GitHub App installation token in-process and reading the App PEM and ClickHouse |
| 160 | +password from AWS Secrets Manager (`pytorch-greenlight-secrets`) at runtime. The handler sets |
| 161 | +`PYTORCH_GREENLIGHT_MAX_RUNTIME_SECONDS=0`, so it runs with no single-instance lock and both |
| 162 | +hang-guard layers off (the SIGALRM soft timeout and the `os._exit` hard watchdog, which is wrong |
| 163 | +under the Lambda runtime); single-instance and hang-bounding come from |
| 164 | +`reserved_concurrent_executions = 1` and the Lambda function timeout instead. |
| 165 | + |
| 166 | +Shipping a new version is a manual four-step flow: |
| 167 | + |
| 168 | +1. `just package` builds `dist/greenlight-scan.zip` (linux x86_64 / cp313 wheels). |
| 169 | +2. The `greenlight-lambda-release.yml` workflow (test-infra, manual `workflow_dispatch`) builds |
| 170 | + the zip and publishes a `greenlight-lambda-v<timestamp>` GitHub Release with it. |
| 171 | +3. An operator pins that release tag in `pytorch-gha-infra-2`'s `runners/common/Terrafile` (the |
| 172 | + `greenlight-scan` entry). |
| 173 | +4. `terraform apply` in `runners/regions/us-east-1` rolls it out. |
| 174 | + |
150 | 175 | ## Reviewer checkout sanitizing |
151 | 176 |
|
152 | 177 | The reviewer workflow (`greenlight-pr-review.yml`) checks the PR's `pytorch/pytorch` tree |
@@ -266,6 +291,7 @@ src/greenlight/ |
266 | 291 | __init__.py # package exports (Config, __version__) |
267 | 292 | __main__.py # `python -m greenlight` entry point |
268 | 293 | cli.py # CLI parsing (review + verdict subcommands), dispatch, exit codes |
| 294 | + lambda_handler.py # AWS Lambda entry point: load secrets, mint App token, run one review scan via cli.main |
269 | 295 | runner.py # run_forever(): resilient daemon loop; execute_once(): one-shot phase run |
270 | 296 | review.py # scan trusted-author PRs: fingerprint, read state, dispatch reviewer workflow for new/changed; raises on failure |
271 | 297 | state.py # read a PR's latest recorded state from misc.greenlight_pr_state |
|
0 commit comments