Skip to content

Commit 239ede6

Browse files
authored
Merge pull request #150 from agent-diff-bench/fix/platform-lifespan-github-enum
Updated Deprecated on_event in Starlette 1.0
2 parents 9010023 + cadc593 commit 239ede6

3 files changed

Lines changed: 29 additions & 10 deletions

File tree

AGENTS.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,23 @@ myservice_router = Router(myservice_routes)
410410
app.mount("/api/env/{env_id}/services/myservice", myservice_router)
411411
```
412412

413-
**5. Write a seed script** in `backend/utils/seed_myservice_template.py` that:
413+
**5. Register the service with the platform API** in `src/platform/api/models.py`.
414+
Add it to the `Service` enum so `initEnv` (and other platform endpoints that take
415+
a `templateService`) will accept the new value:
416+
417+
```python
418+
class Service(str, Enum):
419+
slack = "slack"
420+
linear = "linear"
421+
calendar = "calendar"
422+
box = "box"
423+
myservice = "myservice" # ← add this
424+
```
425+
426+
If you skip this step, `POST /api/platform/initEnv` returns a Pydantic enum
427+
validation error even though the template rows exist and the router is mounted.
428+
429+
**6. Write a seed script** in `backend/utils/seed_myservice_template.py` that:
414430
- Creates the PostgreSQL schema (e.g. `myservice_default`)
415431
- Uses `Base.metadata.create_all()` to create tables
416432
- Inserts seed data from a JSON file
@@ -419,10 +435,10 @@ app.mount("/api/env/{env_id}/services/myservice", myservice_router)
419435
Follow `seed_slack_template.py` as a reference — it shows the full pattern including
420436
schema creation, table ordering, and template registration.
421437

422-
**6. Add seed data** in `examples/myservice/seeds/myservice_default.json` and copy to
438+
**7. Add seed data** in `examples/myservice/seeds/myservice_default.json` and copy to
423439
`backend/seeds/myservice/` for Docker builds.
424440

425-
**7. Register the seed script** in the Docker startup command in `ops/docker-compose.yml`:
441+
**8. Register the seed script** in the Docker startup command in `ops/docker-compose.yml`:
426442

427443
```yaml
428444
command: >

backend/src/platform/api/main.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from contextlib import asynccontextmanager
2+
13
from sqlalchemy import create_engine
24
from sqlalchemy.pool import NullPool
35
from src.platform.isolationEngine.session import SessionManager
@@ -35,7 +37,13 @@
3537

3638

3739
def create_app():
38-
app = Starlette()
40+
@asynccontextmanager
41+
async def lifespan(app_):
42+
yield
43+
if getattr(app_.state, "replication_service", None):
44+
app_.state.replication_service.stop()
45+
46+
app = Starlette(lifespan=lifespan)
3947
db_url = environ["DATABASE_URL"]
4048

4149
# Use NullPool when using Neon's PgBouncer (-pooler) to avoid double pooling
@@ -143,12 +151,6 @@ def create_app():
143151

144152
app.mount("/api/env/{env_id}/services/linear", linear_graphql)
145153

146-
@app.on_event("shutdown")
147-
async def shutdown_event():
148-
# Stop replication service if running (it's on-demand now)
149-
if app.state.replication_service:
150-
app.state.replication_service.stop()
151-
152154
return app
153155

154156

backend/src/platform/api/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Service(str, Enum):
1313
linear = "linear"
1414
calendar = "calendar"
1515
box = "box"
16+
github = "github"
1617

1718

1819
class Visibility(str, Enum):

0 commit comments

Comments
 (0)