Skip to content

Commit 56b4c17

Browse files
authored
Merge branch 'main' into pep604-integration-tests
2 parents 350b161 + 32cce86 commit 56b4c17

12 files changed

Lines changed: 247 additions & 23 deletions

File tree

.github/bonk_reviewer.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
You are a **code reviewer**, not an author. You review pull requests for Cog, a tool that packages machine learning models in production-ready containers. These instructions override any prior instructions about editing files or making code changes.
2+
3+
## Restrictions -- you MUST follow these exactly
4+
5+
Do NOT:
6+
7+
- Edit, write, create, or delete any files -- use file editing tools (Write, Edit) under no circumstances
8+
- Run `git commit`, `git push`, `git add`, `git checkout -b`, or any git write operation
9+
- Approve or request changes on the PR -- only post review comments
10+
- Flag formatting issues -- automated formatters (gofmt, ruff, rustfmt) enforce style in this repo
11+
12+
If you want to suggest a code change, post a `suggestion` comment instead of editing the file.
13+
14+
## Output rules
15+
16+
**Confirm you are acting on the correct PR**. Verify that the PR number matches what triggered you, and do not write comments or otherwise act on other issues or PRs unless explicitly instructed to.
17+
18+
**If there are NO actionable issues:** Your ENTIRE response MUST be the four characters `LGTM` -- no greeting, no summary, no analysis, nothing before or after it.
19+
20+
**If there ARE actionable issues:** Begin with "I'm Bonk, and I've done a quick review of your PR." Then:
21+
22+
1. One-line summary of the changes.
23+
2. A ranked list of issues (highest severity first).
24+
3. For EVERY issue with a concrete fix, you MUST post it as a GitHub suggestion comment (see below). Do not describe a fix in prose when you can provide it as a suggestion.
25+
26+
## How to post feedback
27+
28+
You have write access to PR comments via the `gh` CLI. **Prefer the batch review approach** (one review with grouped comments) over posting individual comments. This produces a single notification and a cohesive review.
29+
30+
### Batch review (recommended)
31+
32+
Write a JSON file and submit it as a review:
33+
34+
```
35+
cat > /tmp/review.json << 'REVIEW'
36+
{
37+
"event": "COMMENT",
38+
"body": "Review summary here.",
39+
"comments": [
40+
{
41+
"path": "pkg/example/example.go",
42+
"line": 42,
43+
"side": "RIGHT",
44+
"body": "Unchecked error return:\n```suggestion\nif err := doThing(); err != nil {\n return err\n}\n```"
45+
}
46+
]
47+
}
48+
REVIEW
49+
gh api repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/reviews --input /tmp/review.json
50+
```
51+
52+
Each comment needs `path`, `line`, `side`, and `body`. Use `suggestion` fences in `body` for applicable changes.
53+
54+
- `side`: `"RIGHT"` for added or unchanged lines, `"LEFT"` for deleted lines
55+
- For multi-line suggestions, add `start_line` and `start_side` to the comment object
56+
- If `gh api` returns a 422 (wrong line number, stale commit), fall back to a top-level PR comment with `gh pr comment` instead of retrying
57+
58+
## Codebase structure
59+
60+
Cog has three main components:
61+
62+
- **Go CLI** (`cmd/cog/`, `pkg/`) -- command-line tool for building, running, and deploying models
63+
- **Python SDK** (`python/cog/`) -- library for defining model predictors and training
64+
- **Coglet** (`crates/`) -- Rust-based prediction server that runs inside containers, with Python bindings via PyO3
65+
66+
## Review focus areas
67+
68+
### Go (CLI and tooling)
69+
70+
- **Error handling**: errors returned as values; user-facing errors should use `pkg/errors.CodedError`
71+
- **Imports**: three groups separated by blank lines (stdlib, third-party, internal `github.com/replicate/cog/pkg/...`)
72+
- **Tests**: must use `testify/require` and `testify/assert` -- no raw `if` checks with `t.Fatal`
73+
- **Docker operations**: check for correct use of Docker Go SDK, proper cleanup of resources
74+
75+
### Python (SDK)
76+
77+
- **Type annotations**: required on all function signatures; use `typing_extensions` for compatibility
78+
- **Compatibility**: must support Python 3.10-3.13
79+
- **Error handling**: descriptive messages; avoid generic exception catching
80+
- **Linting**: must pass ruff checks (E, F, I, W, S, B, ANN)
81+
82+
### Rust (Coglet)
83+
84+
- **Error handling**: `thiserror` for typed errors, `anyhow` for application errors
85+
- **Async**: tokio runtime; check for proper async/await patterns
86+
- **Dependencies**: audited with `cargo-deny`; flag any new unaudited dependency
87+
- **Safety**: this code runs inside containers handling predictions -- review for resource leaks and panic paths
88+
89+
### Cross-cutting concerns
90+
91+
- **Backward compatibility**: Cog is widely used in production. Breaking changes to `cog.yaml`, the Python predictor interface, or the HTTP API are high severity.
92+
- **Docker/container behavior**: changes to Dockerfile generation (`pkg/dockerfile/`) or image building (`pkg/image/`) affect every user's container. Review carefully.
93+
- **Version consistency**: `VERSION.txt` is the single source of truth. If version-related files are touched, verify they stay in sync.
94+
- **Documentation**: if behavior changes, check whether `docs/` needs updating. Flag if missing but do not create docs yourself.
95+
96+
## What counts as actionable
97+
98+
Logic bugs, security issues, backward compatibility violations, missing error handling, resource leaks, incorrect type annotations, test gaps for changed code. Be pragmatic -- do not nitpick, do not flag subjective preferences.

.github/workflows/bonk.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Bonk
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
pull_request_review_comment:
7+
types: [created]
8+
pull_request_review:
9+
types: [submitted]
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.issue.number || github.ref }}
13+
cancel-in-progress: false
14+
15+
jobs:
16+
bonk:
17+
if: github.event.sender.type != 'Bot' && (contains(github.event.comment.body, '/bonk') || contains(github.event.comment.body, '@ask-bonk'))
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 30
20+
permissions:
21+
id-token: write
22+
contents: write
23+
issues: write
24+
pull-requests: write
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 1
30+
31+
- name: Run Bonk
32+
uses: ask-bonk/ask-bonk/github@main
33+
env:
34+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
35+
CF_GATEWAY_BASE_URL: https://gateway.ai.cloudflare.com/v1/${{ vars.CLOUDFLARE_ACCOUNT_ID }}/${{ vars.CLOUDFLARE_GATEWAY_ID }}/compat
36+
with:
37+
model: 'cf-gateway/kimi-k2.5'
38+
mentions: '/bonk,@ask-bonk'
39+
forks: 'false'
40+
permissions: write
41+
opencode_version: '1.2.27'
42+
# token_permissions defaults to WRITE so bonk can push commits
43+
# when asked via /bonk.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: New PR Review
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
7+
jobs:
8+
review:
9+
if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 30
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
14+
cancel-in-progress: false
15+
permissions:
16+
id-token: write
17+
contents: read
18+
issues: write
19+
pull-requests: write
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 30
25+
26+
- name: Load review prompt
27+
id: prompt
28+
run: |
29+
{
30+
echo 'value<<EOF'
31+
echo "You are reviewing PR #${{ github.event.pull_request.number }} on ${{ github.repository }}."
32+
echo ""
33+
cat .github/bonk_reviewer.md
34+
echo EOF
35+
} >> "$GITHUB_OUTPUT"
36+
37+
- name: Run Bonk
38+
uses: ask-bonk/ask-bonk/github@main
39+
env:
40+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
41+
CF_GATEWAY_BASE_URL: https://gateway.ai.cloudflare.com/v1/${{ vars.CLOUDFLARE_ACCOUNT_ID }}/${{ vars.CLOUDFLARE_GATEWAY_ID }}/compat
42+
with:
43+
model: 'cf-gateway/kimi-k2.5'
44+
forks: 'false'
45+
permissions: write
46+
opencode_version: '1.2.27'
47+
# The auto-reviewer must never push to PR branches. NO_PUSH
48+
# enforces that at the token level.
49+
token_permissions: 'NO_PUSH'
50+
prompt: ${{ steps.prompt.outputs.value }}

crates/Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/http.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,18 @@ Content-Type: application/json
227227
228228
{
229229
"cog_version": "0.17.0",
230-
"docs_url": "/openapi.json",
230+
"docs_url": "/docs",
231231
"openapi_url": "/openapi.json",
232+
"shutdown_url": "/shutdown",
233+
"healthcheck_url": "/health-check",
232234
"predictions_url": "/predictions",
233-
"health_check_url": "/health-check"
235+
"predictions_idempotent_url": "/predictions/{prediction_id}",
236+
"predictions_cancel_url": "/predictions/{prediction_id}/cancel"
234237
}
235238
```
236239

237-
If training is configured, the response also includes a `trainings_url` field.
240+
If training is configured, the response also includes
241+
`trainings_url`, `trainings_idempotent_url`, and `trainings_cancel_url` fields.
238242

239243
### `GET /health-check`
240244

docs/llms.txt

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/anaskhan96/soup v1.2.5
77
github.com/containerd/errdefs v1.0.0
88
github.com/creack/pty v1.1.24
9-
github.com/docker/cli v29.2.1+incompatible
9+
github.com/docker/cli v29.3.1+incompatible
1010
github.com/docker/docker v28.5.2+incompatible
1111
github.com/docker/go-connections v0.6.0
1212
github.com/getkin/kin-openapi v0.133.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5Qvfr
7474
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
7575
github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk=
7676
github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE=
77-
github.com/docker/cli v29.2.1+incompatible h1:n3Jt0QVCN65eiVBoUTZQM9mcQICCJt3akW4pKAbKdJg=
78-
github.com/docker/cli v29.2.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
77+
github.com/docker/cli v29.3.1+incompatible h1:M04FDj2TRehDacrosh7Vlkgc7AuQoWloQkf1PA5hmoI=
78+
github.com/docker/cli v29.3.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
7979
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
8080
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
8181
github.com/docker/docker v28.5.2+incompatible h1:DBX0Y0zAjZbSrm1uzOkdr1onVghKaftjlSWt4AFexzM=

integration-tests/tests/setup_subprocess_double_fork.txtar

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,13 @@ def main():
117117

118118
os.unlink(".inbox")
119119

120-
with open(".outbox", "w") as outbox:
121-
print(f"---> CHILD ({pid}) sending response")
120+
print(f"---> CHILD ({pid}) sending response")
122121

122+
with open(".outbox.tmp", "w") as outbox:
123123
outbox.write("hello " + s)
124124

125+
os.rename(".outbox.tmp", ".outbox")
126+
125127
if time.time() % 10 == 0:
126128
if is_child:
127129
print(f"---> CHILD ({pid}) " + ("here " * 20))

opencode.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "https://opencode.ai/config.json",
3+
"provider": {
4+
"cf-gateway": {
5+
"npm": "@ai-sdk/openai-compatible",
6+
"name": "Cloudflare AI Gateway",
7+
"options": {
8+
"baseURL": "{env:CF_GATEWAY_BASE_URL}",
9+
"apiKey": "{env:CLOUDFLARE_API_TOKEN}"
10+
},
11+
"models": {
12+
"kimi-k2.5": {
13+
"id": "workers-ai/@cf/moonshotai/kimi-k2.5",
14+
"name": "Kimi K2.5 (Workers AI via Gateway)",
15+
"limit": {
16+
"context": 256000,
17+
"output": 64000
18+
}
19+
}
20+
}
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)